Skip to content

Instantly share code, notes, and snippets.

View omegasoft7's full-sized avatar
🎯

Farhad Sanaei omegasoft7

🎯
  • Germany, Hamburg
View GitHub Profile
@omegasoft7
omegasoft7 / Take Pictures and save
Created January 9, 2015 13:18
Take picture and save it
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);
@omegasoft7
omegasoft7 / Java to JavaScript.txt
Created December 19, 2014 15:33
Connect Java and JavaScript. Call a java method on Javascript codes that are running in webview
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(..))
// //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
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();
}
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);
}
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;
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();
@omegasoft7
omegasoft7 / MakeOrientationWithoutDestroying.java
Last active August 29, 2015 14:11
Make orientation without destroy and reload activity
//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) {
@omegasoft7
omegasoft7 / getPixcelsByDP.java
Last active August 29, 2015 14:11
Calculate Pixcels by getting DP
// this will calculate and return Pixel value by getting DP value
public static int getDPbyPixcel(int pix) {
return (int) (pix * HYGlobal.density + 0.5f);
}