Last active
August 29, 2015 14:23
-
-
Save richard1122/ba71d2577b1e606a4bc9 to your computer and use it in GitHub Desktop.
Android snippet
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
/** | |
* get device id, if not available get Build.SERIAL. | |
* http://stackoverflow.com/questions/16078269/android-unique-serial-number | |
* @param context | |
* @return a string indicate a unique device | |
*/ | |
public static String getDeviceID(final Context context) { | |
final String deviceID = ((TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE)).getDeviceId(); | |
if (deviceID != null) | |
return deviceID; | |
else | |
return Build.SERIAL; | |
} |
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
TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 10, mContext.getResources().getDisplayMetrics()); |
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 class BitmapUtils { | |
public static Bitmap drawableToBitmap(final Drawable d) { | |
if (d instanceof BitmapDrawable) | |
return ((BitmapDrawable) d).getBitmap(); | |
if (d instanceof ColorDrawable) //TODO: working to support color drawable | |
return null; | |
final Bitmap bitmap = Bitmap.createBitmap(d.getIntrinsicWidth(), d.getIntrinsicHeight(), Bitmap.Config.ARGB_8888); | |
Canvas canvas = new Canvas(bitmap); | |
d.setBounds(0, 0, canvas.getWidth(), canvas.getHeight()); | |
d.draw(canvas); | |
return bitmap; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment