Skip to content

Instantly share code, notes, and snippets.

// GET DEVICE PROTECTED CONTEXT
Context applicationContext = getApplicationContext();
Context safeContext = ContextCompat.createDeviceProtectedStorageContext(appicationContext);
// MOVE DATA FROM CREDENTIAL TO DEVICE STORAGE
Context.moveSharedPreferencesFrom();
Context.moveDatabaseFrom();
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.directboot">
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
public static boolean areDrawablesIdentical(Drawable drawableA, Drawable drawableB) {
Drawable.ConstantState stateA = drawableA.getConstantState();
Drawable.ConstantState stateB = drawableB.getConstantState();
// If the constant state is identical, they are using the same drawable resource.
// However, the opposite is not necessarily true.
return (stateA != null && stateB != null && stateA.equals(stateB))
|| getBitmap(drawableA).sameAs(getBitmap(drawableB));
}
public static Bitmap getBitmap(Drawable drawable) {
ConstantState constantStateDrawableA = drawableA.getConstantState();
ConstantState constantStateDrawableB = drawableB.getConstantState();
if(constantStateDrawableA.equals(constantStateDrawableB)) {
// do something
} else {
// do something else
}
<RadioButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layoutDirection="rtl"
android:textAlignment="textStart"
android:layout_gravity="start"
android:text="Test label" />
public class GeofencingManager implements ResultCallback<Status>{
private static final String TAG = GeofencingManager.class.getSimpleName();
private GoogleLocationApiManager mGoogleLocationApiManager;
private GeofenceCallback mGeofenceCallback;
private List<Geofence> mGeofenceList = new ArrayList<>();
private PendingIntent mGeofencePendingIntent;
private Context mContext;
public interface GeofenceCallback {
void onGeofenceResultAvailable();
}
Display display = getWindowManager().getDefaultDisplay();
View view = findViewById(R.id.YOUR_VIEW_ID);
view.measure(display.getWidth(), display.getHeight());
view.getMeasuredWidth(); // view width
view.getMeasuredHeight(); //view height
public class GoogleLocationApiManager implements GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener,
ResultCallback<LocationSettingsResult>, LocationListener {
private static final String TAG = GoogleLocationApiManager.class.getSimpleName();
private static final int LOCATION_REQUEST_INTERVAL = 10000;
private static final int LOCATION_REQUEST_FASTEST_INTERVAL = 5000;
private static final int LOCATION_REQUEST_PRIORITY = LocationRequest.PRIORITY_HIGH_ACCURACY;
private GoogleApiClient mGoogleApiClient;
private LocationSettingsRequest.Builder mLocationSettingsRequestBuilder;
<android.support.v7.widget.Toolbar
android:id="@+id/your_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:popupTheme="@style/AppTheme.PopupOverlay" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/your_icon"