Skip to content

Instantly share code, notes, and snippets.

View cmelchior's full-sized avatar

Christian Melchior cmelchior

View GitHub Profile
@cmelchior
cmelchior / download_apk.sh
Created February 20, 2014 09:37
Bash script for pulling APK's from Non-rooted android devices
#!/bin/sh
if test $# -lt 1 ; then
echo "Usage: download_apk.sh <GooglePlayPackageName>"
exit 1
fi
PACKAGE=$1
APK_PATH=`adb shell pm list packages -f -3 | grep $PACKAGE | cut -d'=' -f 1 | cut -c9-`
echo "Pulling $APK_PATH from device"
echo `adb pull ${APK_PATH} ./${PACKAGE}.apk`
@cmelchior
cmelchior / material_design_colors.xml
Last active August 29, 2015 14:03
Material design colors reference sheet, credit: Marcel Ulbrich
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Name this file “colors.xml” -->
<!-- Then place it in your project's “res/values/” folder. -->
<!-- Created by Marcel Ulbrich -->
<!-- google.com/+MarcelUlbrich -->
<!-- Updated 2014-12-09 to reflect Google's latest changes -->
<color name="red_050">#FFEBEE</color> <!-- Use with black text -->
<color name="red_100">#FFCDD2</color> <!-- Use with black text -->
@cmelchior
cmelchior / AndroidManifest.xml
Last active December 25, 2015 13:59
Adding support for ".res-auto" in ContentProvider authorities in AndroidManifest.xml. This replaces ".res-auto" with the current package name, making it possible to install multiple build variants on the same devices without getting [INSTALL_FAILED_CONFLICTING_PROVIDER]
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.trifork.example"
android:installLocation="auto"
android:versionName="@string/client_info" >
<!-- ... -->
<application
android:hardwareAccelerated="true"
@cmelchior
cmelchior / LoggingAstVisitor.java
Created May 4, 2016 06:31
Helper class for writing Lint Checks for Android
/*
* Copyright 2016 Realm Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@cmelchior
cmelchior / LogCat
Last active April 3, 2017 19:48
Debugging Progress Listeners
04-03 15:44:04.233 8911-8947/io.realm.test E/ProgressUpdate: /data/data/io.realm.test/cache/junit-1429296718/custom-admin-user/tests/tests -> downloaded: 0,downloadable: 0,uploaded: 0,uploadable: 0, is_fresh 0
04-03 15:44:04.237 8911-8947/io.realm.test E/ProgressUpdate: /data/data/io.realm.test/cache/junit-1429296718/custom-admin-user/tests/tests -> downloaded: 0,downloadable: 0,uploaded: 0,uploadable: 0, is_fresh 0
04-03 15:44:04.276 8911-8947/io.realm.test E/ProgressUpdate: /data/data/io.realm.test/cache/junit-1429296718/custom-admin-user/tests/tests -> downloaded: 0,downloadable: 0,uploaded: 0,uploadable: 8844, is_fresh 0
04-03 15:44:04.279 8911-8947/io.realm.test E/ProgressUpdate: /data/data/io.realm.test/cache/junit-1429296718/custom-admin-user/tests/tests -> downloaded: 0,downloadable: 0,uploaded: 0,uploadable: 9187, is_fresh 0
04-03 15:44:04.289 8911-8947/io.realm.test E/ProgressUpdate: /data/data/io.realm.test/cache/junit-1429296718/custom-admin-user/tests/tests -> downloaded: 0,downloadable: 0,upload
@cmelchior
cmelchior / BarListParcelConverter.java
Last active August 29, 2019 09:46
Using Parceler 1.0.3 with Realm
// Specific class for a RealmList<Bar> field
public class BarListParcelConverter extends RealmListParcelConverter<Bar> {
@Override
public void itemToParcel(Bar input, Parcel parcel) {
parcel.writeParcelable(Parcels.wrap(input), 0);
}
@Override
public Bar itemFromParcel(Parcel parcel) {
@cmelchior
cmelchior / Example.java
Created May 3, 2016 15:10
Example of using Realm.waitForChange()/Realm.stopWaitForChange()
// Create a background thread
RealmThread t = new RealmThread(realmConfig, new RealmRunnable() {
@Override
public void run(Realm realm) {
do {
// Do some work once, and every time the Realm changes
} while (realm.waitForChange())
}
});
@cmelchior
cmelchior / HelperMethods.java
Created March 17, 2017 10:54
Load new Realm file from assets when a migration is required
public Realm loadAssetFileOnMigration() {
// TODO Don't re-create this every time
RealmConfiguration config = new RealmConfiguration.Builder()
.schemaVersion(2) // Bumping the schema because new app
.build();
Realm realm;
try {
realm = Realm.getInstance(config);
@cmelchior
cmelchior / PrimaryKeyFactory.java
Created April 7, 2017 12:01
Helper class for creating auto increment keys for Realm model classes
/*
* Copyright 2017 Realm Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
/**
* Class connecting the Realm lifecycle to that of LiveData objects.
* Realm will remain open for as long as any LiveData objects are being observed.
*/
abstract class LiveRealmData<T: RealmModel>(val config: RealmConfiguration) : LiveData<RealmResults<T>>() {
private val listener = RealmChangeListener<RealmResults<T>> { results -> value = results }
private lateinit var realm: Realm
private var results: RealmResults<T>? = null