Skip to content

Instantly share code, notes, and snippets.

@a-v-ebrahimi
a-v-ebrahimi / AnimationHelepr
Created April 21, 2012 02:11
android animation helper for viewflipper
//flip1.setInAnimation(AnimationHelper
// .inFromRightAnimation(300));
// flip1.setOutAnimation(AnimationHelper
// .outToLeftAnimation(300));
package com.euphratesmedia.commonroutines;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.Animation;
import android.view.animation.TranslateAnimation;
@a-v-ebrahimi
a-v-ebrahimi / gist:2487014
Created April 25, 2012 06:08
Android: show progress dialog
private ProgressDialog myProgressDialog;
...
myProgressDialog = ProgressDialog.show(actRSS.this,
"Please wait...", "Loading Data...", true);
...
myProgressDialog.dismiss();
@a-v-ebrahimi
a-v-ebrahimi / multithread_blocks
Created August 8, 2012 14:16
iOS : Multithread block + UI
dispatch_async( dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
// Add code here to do background processing
//
//
dispatch_async( dispatch_get_main_queue(), ^{
// Add code here to update the UI/send notifications based on the
// results of the background processing
});
});
@a-v-ebrahimi
a-v-ebrahimi / autoselectimage
Created November 29, 2012 11:32
iOS : Auto select image for Retina 4
#define isPhone568 ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone && [UIScreen mainScreen].bounds.size.height == 568)
#define iPhone568ImageNamed(image) (isPhone568 ? [NSString stringWithFormat:@"%@-568h.%@", [image stringByDeletingPathExtension], [image pathExtension]] : image)
#define iPhone568Image(image) ([UIImage imageNamed:iPhone568ImageNamed(image)])
@a-v-ebrahimi
a-v-ebrahimi / ios_show_alert
Created March 2, 2014 11:52
iOS : Show alert
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"title"
message:@"prompt"
delegate:self
cancelButtonTitle:@"Cancel"
otherButtonTitles:@"Ok", nil ];
alert.tag = 10;
[alert show];
@a-v-ebrahimi
a-v-ebrahimi / exec_honey
Created June 8, 2014 21:19
Android:Execute AsyncTask Honeycomb
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
my_task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void[])null);
else
my_task.execute((Void[])null);
@a-v-ebrahimi
a-v-ebrahimi / check_google_play_services
Created July 2, 2014 12:57
Check Google Play Services Is Available
private void checkGooglePlayServicesIsAvailable() {
int errorCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
if (errorCode != ConnectionResult.SUCCESS) {
GooglePlayServicesUtil.getErrorDialog(errorCode, this, 0).show();
}
}
@a-v-ebrahimi
a-v-ebrahimi / spinner_with_icons
Last active April 2, 2020 08:50
Android Spinner with icons
final Item[] items = {
new Item("Email", android.R.drawable.ic_menu_add),
new Item("Facebook", android.R.drawable.ic_menu_delete),
new Item("...", 0),//no icon for this one
};
ListAdapter adapter = new ArrayAdapter<Item>(
this,
android.R.layout.select_dialog_item,
android.R.id.text1,
@a-v-ebrahimi
a-v-ebrahimi / gist:22b55e9eb8087c9c85d1
Created September 1, 2014 05:00
Check if user is elevated (UAC)
// copied from :
// http://stackoverflow.com/a/17492949/305135
public static class UacHelper
{
private const string uacRegistryKey = "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System";
private const string uacRegistryValue = "EnableLUA";
private static uint STANDARD_RIGHTS_READ = 0x00020000;
private static uint TOKEN_QUERY = 0x0008;
@a-v-ebrahimi
a-v-ebrahimi / gist:283c723b7eae8b42730e
Created February 9, 2015 07:46
Convert LinkedTreeMap key-value pair into JSON
public static JSONObject convertKeyValueToJSON(LinkedTreeMap<String, Object> ltm) {
JSONObject jo=new JSONObject();
Object[] objs = ltm.entrySet().toArray();
for (int l=0;l<objs.length;l++)
{
Map.Entry o= (Map.Entry) objs[l];
try {
if (o.getValue() instanceof LinkedTreeMap)
jo.put(o.getKey().toString(),convertKeyValueToJSON((LinkedTreeMap<String, Object>) o.getValue()));
else