Skip to content

Instantly share code, notes, and snippets.

@nahba
nahba / ImageScaleActivity
Last active December 19, 2016 09:40
Image Scaling Utility Class
private int mSourceId;
private int mDstWidth;
private int mDstHeight;
onCreate:
========
mSourceId = R.drawable.image;
mDstWidth = getResources().getDimensionPixelSize(R.dimen.destination_width);
mDstHeight = getResources().getDimensionPixelSize(R.dimen.destination_height);
@nahba
nahba / CheckAppVersion
Last active June 9, 2016 04:52
APK Version
private void getVersion(final String apkpath) {
final PackageManager packageManager = getPackageManager();
if(new File(apkpath).exists()) {
PackageInfo packageInfo = packageManager.getPackageArchiveInfo(apkpath, 0);
Log.d(TAG, "PackageVesrionName: " + packageInfo.versionName);
Log.d(TAG, "PackageVersionCode: " + packageInfo.versionCode);
}
}
Passing Path:
@nahba
nahba / DateConversion
Last active June 9, 2016 04:51
Date Format Conversion
//Format
public static final String PLANNED_ = "dd-MMM-yyyy";
public static final String ENTRY_DATE = "dd/MM/yyyy HH:mm:ss";
//Using JodaTime
public String convertTo(final String passedDate, final String oldPattern, final String newPattern) {
String fullName = "";
DateTimeFormatter formatter = DateTimeFormat.forPattern(oldPattern);
DateTime jodaTime = formatter.parseDateTime(passedDate);
formatter = DateTimeFormat.forPattern(newPattern);
@nahba
nahba / Key
Created July 27, 2014 17:17
Hash Map Custom Key
package moc.nahba.diord.utils;
public class Key {
private final int x;//Row
private final int y;//Column
public Key(int x, int y) {
this.x = x;
this.y = y;
}
@nahba
nahba / CustomDialog
Last active June 9, 2016 04:51
Dialog Using Custom Theme
<style name="PauseDialog" parent="@android:style/Theme.Dialog">
<item name="android:windowAnimationStyle">@style/PauseDialogAnimation</item>
</style>
<style name="PauseDialogAnimation">
<item name="android:windowEnterAnimation">@anim/bounce_scale</item>
<item name="android:windowExitAnimation">@anim/bounce_minimize</item>
</style>
<style name="DialogActivity" parent="android:Theme.Dialog">
<item name="android:windowFrame">@null</item>
<item name="android:windowIsFloating">true</item>
@nahba
nahba / BackKeyActivity
Last active June 9, 2016 04:50
Back Key Handling
@Override
public boolean onKeyDown(int keyCode, KeyEvent keyEvent) {
if ((CompatibilityUtil.getSdkVersion() <
android.os.Build.VERSION_CODES.ECLAIR)
&& keyCode == KeyEvent.KEYCODE_BACK
&& keyEvent.getRepeatCount() == 0) {
onBackPressed();
}
return super.onKeyDown(keyCode, keyEvent);
@nahba
nahba / CheckRunningComponent
Last active June 9, 2016 04:50
Check Running Component
@Override
protected void onStart() {
super.onStart();
boolean isRunning = isServiceRunning(BackgroundService.class);
if(isRunning) {
Intent serviceIntent = new Intent(this, BackgroundService.class);
stopService(serviceIntent);
}
}
@nahba
nahba / RadioGrpCheckAdapter
Last active June 9, 2016 04:49
ListView With RadioGroup OnCheckChangedListener
viewHolder.radioGroup.setOnCheckedChangeListener(null); //Most Important Thing To Write O/W Won't Work
if(radioModel.getCheckedId() == 0) {
viewHolder.radioGroup.check(R.id.radioOne);
} else if(radioModel.getCheckedId() == 1) {
viewHolder.radioGroup.check(R.id.radioTwo);
} else if(radioModel.getCheckedId() == 2) {
viewHolder.radioGroup.check(R.id.radioThree);
}
viewHolder.radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
@nahba
nahba / CompareArrayListActivity
Last active June 9, 2016 04:49
Compare Two List - If Any Element Changed Or Not (Record Updated Or Not)
private List<Employee> firstArrayList;
private List<Employee> getFirstArrayList() {
List<Employee> arrayList = new ArrayList<Employee>();
arrayList.add(new Employee(1, "Donut"));
arrayList.add(new Employee(2, "Froyo"));
arrayList.add(new Employee(3, "Eclair"));
arrayList.add(new Employee(4, "Gingerbread"));
arrayList.add(new Employee(5, "HoneyComb"));
arrayList.add(new Employee(6, "IceCream Sandwich"));
arrayList.add(new Employee(7, "Jelly Bean"));
@nahba
nahba / ConversionUtils
Last active June 9, 2016 04:49
Conversions
public class ConversionUtils {
public static int convertHexToDecimal(String hexCode) {
return Integer.parseInt(hexCode, 16);
}
public static String convertDecimalToHex(int decCode) {
return Integer.toHexString(decCode);
}