Skip to content

Instantly share code, notes, and snippets.

View mistrydarshan99's full-sized avatar

Darshan Mistry mistrydarshan99

View GitHub Profile
package com.utils;
import android.content.Context;
import android.text.TextUtils;
import android.util.Patterns;
import android.widget.EditText;
/**
* Created by darshan on 2/4/15.
*/
@mistrydarshan99
mistrydarshan99 / SerializeToJson.java
Last active September 1, 2015 09:44 — forked from cmelchior/ SerializeToJson.java
Serialize Realm objects to JSON using GSON
// GSON can parse the data.
//
// Deserialization:
// Note there is a bug in GSON 2.3.1 that can cause it to StackOverflow when working with RealmObjects.
// To work around this, use the ExclusionStrategy below or downgrade to 1.7.1
// See more here: https://code.google.com/p/google-gson/issues/detail?id=440
//
// Serialization:
// <Type>RealmProxy objects are created by the Realm annotation processor. They are used to control
// access to the actual data instead of storing them in fields and it is therefore them we need to register a
@mistrydarshan99
mistrydarshan99 / ExpandableHeightGridView.java
Last active September 16, 2015 08:12 — forked from sakurabird/ExpandableHeightGridView.java
AndroidのScrollViewの中のGridViewのlayout_heightが伸び縮みしないのを独自Viewで克服
package xx.xxx.xx.view;
import android.content.Context;
import android.util.AttributeSet;
import android.view.ViewGroup;
import android.widget.GridView;
/**
* ScrollViewの中のGridViewでも高さを可変にする<br>
* http://stackoverflow.com/questions/8481844/gridview-height-gets-cut
@mistrydarshan99
mistrydarshan99 / WrapGridLayoutManager.java
Last active May 31, 2016 08:23 — forked from ArthurSav/WrapGridLayoutManager.java
GridLayoutManager with working wrap_content.
package com.inperson.android.utils.leastview;
import android.content.Context;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
public class WrappableGridLayoutManager extends GridLayoutManager {
@mistrydarshan99
mistrydarshan99 / ReadAndroidContacts.java
Created September 28, 2015 08:38 — forked from yanivmo/ReadAndroidContacts.java
Read Android contacts
// The flow starts in onReadClick
import android.app.LoaderManager;
import android.content.CursorLoader;
import android.content.Loader;
import android.database.Cursor;
import android.provider.ContactsContract;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.util.Log;
@mistrydarshan99
mistrydarshan99 / PerformancePatterns.md
Created March 5, 2016 06:35 — forked from colabug/PerformancePatterns.md
Performance Patterns Notes
@mistrydarshan99
mistrydarshan99 / ActivityA.java
Created August 24, 2016 09:59
Stackoverflow answer, "Singleton in Android"
package com.example.testSingleton;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.Toast;
public class ActivityA extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
@mistrydarshan99
mistrydarshan99 / SomeFragment.java
Created September 2, 2016 12:36 — forked from joshdholtz/SomeFragment.java
Android Google Maps V2 - MapView in XML
public class SomeFragment extends Fragment {
MapView mapView;
GoogleMap map;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.some_layout, container, false);
@mistrydarshan99
mistrydarshan99 / android_lifecycle_recommendations.md
Created September 21, 2016 13:13 — forked from kaushikgopal/android_lifecycle_recommendations.md
Notes on opportune moments to do "stuff" in the Android Lifecycle
  • In general you want to try and put things in onStart and onStop for logical start and stops.

Activity

onCreate

  • Dagger inject self into graph
  • setContentView(R.layout.xxx)
  • Butterknife.bind(this)
  • RxJava CompositeSubscription.add (if NON UI related work being done)

onStart

@mistrydarshan99
mistrydarshan99 / LocalBroadcastExampleActivity.java
Created October 17, 2016 06:12 — forked from Antarix/LocalBroadcastExampleActivity.java
Simple Example of using LocalBroadcastManager in Android
import android.app.Activity;
import android.app.Service;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.os.IBinder;
import android.support.v4.content.LocalBroadcastManager;