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
// this will calculate and return Pixel value by getting DP value | |
public static int getDPbyPixcel(int pix) { | |
return (int) (pix * HYGlobal.density + 0.5f); | |
} |
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
//ON Activity | |
@Override | |
public void onConfigurationChanged(Configuration newConfig) { | |
super.onConfigurationChanged(newConfig); | |
if(newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) { | |
//Landscape orientation | |
} else if(newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) { |
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 void logOut(String string) { | |
if (string.length() > 3000) { | |
int length = string.length(); | |
String str = string; | |
while (length > 3000) { | |
Log.w("MYAPP", str.substring(0, 3000)); | |
str = str.substring(3000); | |
length = str.length(); |
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; |
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 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
// //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
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
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
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); |
OlderNewer