Skip to content

Instantly share code, notes, and snippets.

@lsurvila
lsurvila / drawable-v21.xml
Last active June 12, 2018 13:56
Button with round borders
<ripple
xmlns:android="http://schemas.android.com/apk/res/android"
android:color="?android:attr/colorControlHighlight"
>
<item android:id="@android:id/mask">
<shape android:shape="rectangle">
<solid android:color="#327DDF"/>
<corners android:radius="4dp"/>
</shape>
</item>
@lsurvila
lsurvila / CustomMatchers.java
Last active May 2, 2017 16:12 — forked from frankiesardo/CustomMatchers.java
Espresso & Brioche
/**
* Custom Espresso matchers. Includes image drawable matching.
*/
public class CustomMatchers {
public static Matcher<View> withBackground(final int resourceId) {
return new TypeSafeMatcher<View>() {
@Override
public boolean matchesSafely(View view) {
return sameBitmap(view.getContext(), view.getBackground(), resourceId);
Genymotion emulators are already rooted and with SU installed
To fix "adb server version (<server-version>) doesn't match this client (<client-version>); killing...":
Change SDK location https://stackoverflow.com/questions/30757191/adb-and-genymotion-error-adb-server-is-out-of-date-killing-cannot-bind-tc
To find current SDK location:
https://stackoverflow.com/questions/34532063/finding-android-sdk-on-mac-and-adding-to-path
System apps reside in:
/system/app/<AppName>/<AppName>.apk
@lsurvila
lsurvila / .gitignore
Last active February 14, 2017 20:03
.gitignore for Android
# Local configuration file (sdk path, etc)
local.properties
# Windows thumbnail db
Thumbs.db
# OSX files
.DS_Store
*.pydevproject
@lsurvila
lsurvila / DownloadFileWithRetrofit2RxJava.java
Last active August 12, 2024 07:37
Download file with Retrofit 2, OkHttp, Okio and RxJava
import com.squareup.okhttp.ResponseBody;
import okio.BufferedSink;
import okio.Okio;
import retrofit.Response;
import retrofit.http.GET;
import retrofit.http.Query;
import rx.Observable;
interface ApiService {
@lsurvila
lsurvila / gist:f41dba734fa62780017c
Created October 19, 2015 21:03 — forked from pid/gist:5974342
```brew update``` and ```brew doctor```is stalling/hangs ::: SOLUTION
First, I don't know why.....but my solution at the moment
cd /usr/local
$ git remote -v
origin https://github.com/mxcl/homebrew.git (fetch)
origin https://github.com/mxcl/homebrew.git (push)
$ brew doctor -d
# hangs,stalling, no respond
@lsurvila
lsurvila / EllipsizingTextView.java
Last active September 16, 2015 11:48
Fixes ellipsizing behaviour on certain cases when text has \n in it.
import java.util.ArrayList;
import java.util.List;
import android.content.Context;
import android.graphics.Canvas;
import android.text.Layout;
import android.text.Layout.Alignment;
import android.text.StaticLayout;
import android.text.TextUtils.TruncateAt;
import android.util.AttributeSet;
@lsurvila
lsurvila / DataBindingAndFonts.java
Created September 3, 2015 20:46
Binds font file to TextView using Data Binding API
// from https://plus.google.com/u/0/+LisaWrayZeitouni/posts/LTr5tX5M9mb
@BindingAdapter({"bind:font"})
public static void setFont(TextView textView, String fontName){
textView.setTypeface(Typeface.createFromAsset(textView.getContext().getAssets(), "fonts/" + fontName));
}
<TextView
app:font="@{`Source-Sans-Pro-Regular.ttf`}"
android:layout_width="wrap_content"
@lsurvila
lsurvila / DownloadTransformImagesAndPutThemAsMarkersOnMapWithGlide.java
Last active November 7, 2020 20:04
Downloads/transforms images with Glide and puts them on Google Map as markers (images will be cached automatically).
private Bitmap defaultPin;
private GoogleMap googleMap;
private List<MapItem> items;
private void putItemsOnMap() {
for (MapItem item : items) {
// wrap google map marker with target, also set marker's pin with default pin bitmap, coordinates, etc, so it still be shown on map while real one is downloaded/transformed
MarkerTarget marker = new MarkerTarget(googleMap.addMarker(new MarkerOptions().position(new LatLng(item.getLatitude(), item.getLongitude())).title(item.getName()).icon(BitmapDescriptorFactory.fromBitmap(defaultPin))));
Glide.with(this)
.load(item.getPinImageUrl())
@lsurvila
lsurvila / FilterListInsideResponse.java
Last active February 7, 2019 04:17
An example how to iterate and filter through list which is inside object, retrieved from server/etc with RxJava
public Observable<SomeResponse> downloadAndFilterListInResponse() {
return mSomeRetrofitApi.downloadSomeData() // get response from server/etc
// start iterating through list in response object
.flatMap(response -> Observable.from(response.getListWeWantToFilterOut())
// NOTE: this is inner sequence, gets result from Observable.from
.filter(item -> item != null) // filters out items that are null
.toList() // all items combined into list again
.take(100) // take only first 100 items, rest will be ignored
.map(items -> { // now we need to 'map' list into response
response.setListWeWantToFilterOut(items); // overwrite list in object with filtered list