This file contains hidden or 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
Sometimes ScrollView doesn't fill parent 100%. in this case simply just add: | |
android:fillViewport="true" | |
to scrollview and that is it. :) |
This file contains hidden or 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 class Logger { | |
//Variables------------------------------------------------------------------------ | |
private static boolean LOGGING_ENABLED = true; | |
private static final int STACK_TRACE_LEVELS_UP = 5; | |
private static String TAG = "YourTag"; |
This file contains hidden or 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
/** | |
* Returns true if the application is debuggable. | |
* | |
* @return true if the application is debuggable. | |
*/ | |
static boolean isDebuggable() { | |
PackageManager pm = mApplication.getPackageManager(); | |
try { | |
return ((pm.getApplicationInfo(mApplication.getPackageName(), 0).flags & ApplicationInfo.FLAG_DEBUGGABLE) > 0); | |
} catch (NameNotFoundException e) { |
This file contains hidden or 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
btn01.setOnClickListener(new OnClickListener() { | |
@Override | |
public void onClick(View v) { | |
Intent imageIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); | |
File imagesFolder = new File(Environment.getExternalStorageDirectory(), "MyImages"); | |
imagesFolder.mkdirs(); // <---- | |
File image = new File(imagesFolder, "image_001.jpg"); | |
Uri uriSavedImage = Uri.fromFile(image); | |
imageIntent.putExtra(MediaStore.EXTRA_OUTPUT, uriSavedImage); |
This file contains hidden or 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
Google finally realized the need of generating unique IDs for programmatically created views... | |
From API level 17 and above, you can call | |
View.generateViewId() | |
Then use View.setId(int). | |
In case you need it for targets lower than level 17, here is its internal implementation in View.java you can use directly in your project, put it in your util class or somewhere: |
This file contains hidden or 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
There is a hack: | |
Bind some Java object so that it can be called from Javascript with WebView: | |
addJavascriptInterface(javaObjectCallback, "JavaCallback") | |
Force execute javascript within an existing page by | |
WebView.loadUrl("javascript: var result = window.YourJSLibrary.callSomeFunction(); | |
window.JavaCallback.returnResult(result)"); | |
(in this case your java class JavaObjectCallback should have a method returnResult(..)) |
This file contains hidden or 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
// //show after fully load of layers | |
ViewTreeObserver vto = myview.getViewTreeObserver(); | |
vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() { | |
@SuppressLint("NewApi") | |
@Override | |
public void onGlobalLayout() { | |
//Do needs after load interface here |
This file contains hidden or 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 final String PATTERN_EMAIL = "^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\])|(([a-zA-Z\\-0-9]+\\.)+[a-zA-Z]{2,}))$"; | |
public static boolean isValidEmailAddress(String email) { | |
Pattern pattern = Pattern.compile(PATTERN_EMAIL); | |
return pattern.matcher(email).matches(); | |
} |
This file contains hidden or 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 int colorFromIOS(double r, double g, double b, double a) { | |
int red = (int) (r * 255); | |
int green = (int) (g * 255); | |
int blue = (int) (b * 255); | |
int alpha = (int) (a * 255); | |
return Color.argb(alpha, red, green, blue); | |
} |
This file contains hidden or 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 class DateDiff { | |
public long seconds; | |
public long minutes; | |
public long hours; | |
public long days; | |
public DateDiff(long seconds, long minutes, long hours, long days) { | |
this.seconds = seconds; | |
this.days = days; | |
this.minutes = minutes; |