Skip to content

Instantly share code, notes, and snippets.

@Rexee
Rexee / doze_mode_adb_commands.sh
Created February 19, 2020 07:24 — forked from y-polek/doze_mode_adb_commands.sh
adb commands to test Doze mode
#! /bin/zsh
# Buttery powered state
adb shell dumpsys battery | grep powered
# Unplug battery
adb shell dumpsys battery unplug
# Reset battery
adb shell dumpsys battery reset
@Rexee
Rexee / SpinnerCommon.java
Last active April 25, 2016 15:50
Easy spinner arrays management
public class SpinnerCommon<T> {
public Spinner mSpinner;
public SpinnerAdapter<T> mAdapter;
public SpinnerCommon(Spinner spinner) {
this(spinner, new ArrayList<T>(), new SpinnerAdapter<T>() {
}, false, android.R.layout.simple_spinner_item, android.R.layout.simple_spinner_dropdown_item);
}
public SpinnerCommon(Spinner spinner, List<T> objects) {
@Rexee
Rexee / Palette.java
Last active April 25, 2016 15:41
Using "Palette"
final int bgColor = getResources().getColor(R.color.colorPrimary);
ImageLoader.getInstance().displayImage(user.getImageUrl(), header, new SimpleImageLoadingListener() {
@Override
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
if (VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) {
Palette.from(loadedImage).generate(new PaletteAsyncListener() {
@SuppressLint("NewApi")
@Override
@Rexee
Rexee / build.gradle
Last active April 25, 2016 15:41
Common imports
buildscript {
dependencies {
classpath "io.realm:realm-gradle-plugin:0.88.3"
}
}
apply plugin: 'realm-android'
compile 'com.jakewharton:butterknife:7.0.1'
compile 'com.squareup.retrofit2:retrofit:2.0.1'
@Rexee
Rexee / RealmList.java
Last active August 3, 2018 01:38
Parceler and RealmList
@Parcel(implementations = { CountryRealmProxy.class },
value = Parcel.Serialization.FIELD,
analyze = { Country.class })
public class Country extends RealmObject {
@ParcelPropertyConverter(RealmListParcelConverter.class)
public RealmList<RealmString> languages;
}
public class RealmListParcelConverter
implements TypeRangeParcelConverter<RealmList<? extends RealmObject>,
@Rexee
Rexee / S.java
Last active April 25, 2016 16:05
Simple looger
public class S {
public static final String TAG = "DBG";
public static void L(Context c, Object o) {
String txt = o.toString();
Toast.makeText(c, txt, Toast.LENGTH_LONG).show();
Log.d(TAG, txt);
}
public static void L(String s, Object... args) {
@Rexee
Rexee / Recycler.java
Last active May 27, 2016 09:55
RecyclerView + RecyclerView.Adapter in one class
public class Recycler<T, VH extends RecyclerViewHolder> {
public RecyclerView mRecyclerView;
public RecyclerAdapter<T, VH> mAdapter;
public LinearLayoutManager mLinearLayoutManager;
public Recycler(RecyclerView recyclerView, int layoutItemResId, RecyclerAdapter<T, VH> adapter, boolean divider, boolean vertical) {
mRecyclerView = recyclerView;
Context context = mRecyclerView.getContext();
if (vertical) {
mLinearLayoutManager = new LinearLayoutManager(context);
@Rexee
Rexee / SimpleAdapter.java
Last active April 25, 2016 15:45
SimpleAdapter
String[] texts = {"sometext 1", "sometext 2", "sometext 3"};
ArrayList<Map<String, Object>> data = new ArrayList<Map<String, Object>>(texts.length);
Map<String, Object> m;
for (int i = 0; i < texts.length; i++) {
m = new HashMap<String, Object>();
m.put("TEXT", texts[i]);
data.add(m);
}
@Rexee
Rexee / BaseAdapter.java
Last active April 25, 2016 15:44
BaseAdapter
public class RankedMostPlayedAdapter extends BaseAdapter {
private LayoutInflater mInflater;
private List<StatsRanked> mStatsRanked;
private AQuery aq;
public RankedMostPlayedAdapter(Context context, List<StatsRanked> mStatsRanked) {
this.mStatsRanked = mStatsRanked;
mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
aq = new AQuery(context);