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 / ScrollView
Created January 15, 2015 08:18
What we can do to make ScrollView to fill Parent
Sometimes ScrollView doesn't fill parent 100%. in this case simply just add:
android:fillViewport="true"
to scrollview and that is it. :)
@omegasoft7
omegasoft7 / Logger.java
Created January 14, 2015 14:36
This is best logger for Android EVER
public class Logger {
//Variables------------------------------------------------------------------------
private static boolean LOGGING_ENABLED = true;
private static final int STACK_TRACE_LEVELS_UP = 5;
private static String TAG = "YourTag";
@omegasoft7
omegasoft7 / IsAppDebuggable.java
Created January 12, 2015 08:03
Check if the app is debuggable
/**
* 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) {
@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 / SetID to View Programmatically
Created January 9, 2015 09:52
SetID to a View Programmatically
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:
@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;