This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* This function runs some actions after some delay | |
* | |
* @param delayInMilliSeconds the time delay in ms | |
* @param runnable the action to perform after the delay | |
* @return the Handler object, with which one can cancel this action. | |
*/ | |
public static Handler runDelayedAction(int delayInMilliSeconds, Runnable runnable) { | |
final Handler handler = new Handler(); | |
handler.postDelayed(runnable, delayInMilliSeconds); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Check if the app is debug version or not. | |
* This is done by checking "debuggable" attribute set in AndroidManifest.xml. | |
* <p/> | |
* Android Studio/ADT automatically sets this debuggable attribute to true, when not exporting | |
* a signed package. | |
* | |
* @param context | |
* @return | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
final String key1 = "EMAIL"; | |
final String key2 = "ACCESS_TOKEN"; | |
mSomeButton.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View v) { | |
Intent intent = getPackageManager().getLaunchIntentForPackage("com.abc.secondapp"); | |
if(intent != null) { | |
Bundle extras = new Bundle(); | |
extras.putString(key1, "SomeEmail@gmail.com"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* This function captures any Android views to a bitmap shapshot | |
* and save it to a file path | |
* and optionally open it with android pciture viewer | |
*/ | |
public void CaptureView(View view, String filePath, boolean bOpen) { | |
view.setDrawingCacheEnabled(true); | |
Bitmap b = view.getDrawingCache(); | |
try { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
AsyncTask.execute(new Runnable() { | |
@Override | |
public void run() { | |
//DoSth() | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Example usage: | |
// new GetJsonTask().execute("https://api.stackexchange.com/2.2/info?site=stackoverflow&key=app key"); | |
class GetJsonTask extends AsyncTask<String, Void, String> { | |
private Exception exception; | |
protected String doInBackground(String... urls) { | |
try { | |
Request request = new Request.Builder() | |
.url(urls[0]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static Activity getForegroundActivity(){ | |
Activity activity = null; | |
try { | |
Class activityThreadClass = Class.forName("android.app.ActivityThread"); | |
Object activityThread = activityThreadClass.getMethod("currentActivityThread").invoke(null); | |
Field activitiesField = activityThreadClass.getDeclaredField("mActivities"); | |
activitiesField.setAccessible(true); | |
Map<Object, Object> activities = (Map<Object, Object>) activitiesField.get(activityThread); | |
if(activities == null) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Get version number from build.gradle | |
* You might also use BuildConfig.VERSION_CODE to see if this works | |
* @return version code integer | |
*/ | |
public static int getAppVersionCode() { | |
if (context == null) return -1; | |
PackageManager packageManager = context.getPackageManager(); | |
int versionCode = -1; | |
try { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static string SerializeObject<T> (T objectToSerialize) | |
{ | |
XmlSerializer xmlSerializer = new XmlSerializer (objectToSerialize.GetType ()); | |
using (StringWriter textWriter = new StringWriter ()) { | |
xmlSerializer.Serialize (textWriter, objectToSerialize); | |
return textWriter.ToString (); | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var React = require('react'); | |
var Foo = require('Foo'); | |
/** | |
* General component description, for instance use below description | |
* | |
* The button component represents generic button UI control with | |
* an image and a title sting. | |
* | |
* props: |
OlderNewer