Skip to content

Instantly share code, notes, and snippets.

@lenamuit
lenamuit / MyParcelable.java
Created July 21, 2014 15:23
MyParcelable
public class MyParcelable implements Parcelable {
private int mData;
public int describeContents() {
return 0;
}
public void writeToParcel(Parcel out, int flags) {
out.writeInt(mData);
}
@lenamuit
lenamuit / Java-keytool-command.md
Last active December 30, 2023 12:15
Java Keytool command

Java Keytool Commands for Creating and Importing

These commands allow you to generate a new Java Keytool keystore file, create a CSR, and import certificates. Any root or intermediate certificates will need to be imported before importing the primary certificate for your domain.

Generate a Java keystore and key pair

keytool -genkey -alias mydomain -keyalg RSA -keystore keystore.jks -keysize 2048

Generate a certificate signing request (CSR) for an existing Java keystore

// Add code to print out the key hash
try {
PackageInfo info = getPackageManager().getPackageInfo(
"yourpackage.name",
PackageManager.GET_SIGNATURES);
for (Signature signature : info.signatures) {
MessageDigest md = MessageDigest.getInstance("SHA");
md.update(signature.toByteArray());
Log.d("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
}
@lenamuit
lenamuit / Json2Map.java
Created July 28, 2014 16:08
Json To Map
Type mapType = new TypeToken<Map<String, String>>(){}.getType();
Map<String, String> errorResponse = new Gson().fromJson(json, mapType);
// Replace 'dependencies' in your build.gradle file with the following
// or add these to whatever other dependencies you have.
dependencies {
compile 'com.android.support:support-v4:13.0.+'
compile 'com.google.android.gms:play-services:3.1.36+'
compile('com.google.api-client:google-api-client:1.4.1-beta') {
exclude group: 'com.google.android.google-play-services'
}
compile 'com.google.http-client:google-http-client-gson:1.15.0-rc'
//Link reference https://github.com/nbadal/android-gif-encoder
public byte[] generateGIF() {
ArrayList<Bitmap> bitmaps = adapter.getBitmapArray();
ByteArrayOutputStream bos = new ByteArrayOutputStream();
AnimatedGifEncoder encoder = new AnimatedGifEncoder();
encoder.start(bos);
for (Bitmap bitmap : bitmaps) {
encoder.addFrame(bitmap);
}
encoder.finish();
@lenamuit
lenamuit / build.gradle
Last active August 29, 2015 14:06 — forked from jmpinit/build.gradle
Gradle file for OpenCv library
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.6.+'
}
}
apply plugin: 'android-library'
@lenamuit
lenamuit / init_jni.sh
Created September 10, 2014 01:59
init jni
$ javah -d jni -classpath /Applications/Android\ Studio.app/sdk/platforms/android-19/android.jar:../../build/intermediates/classes/debug com.namlh.ndkexample.MainActivity
public static final int dpToPx(float dp, Resources res) {
return (int) TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_DIP,
dp,
res.getDisplayMetrics());
}
@lenamuit
lenamuit / pick_image.java
Created November 27, 2014 08:37
Create image picker: resize and scale output.
Intent galleryIntent = new Intent(Intent.ACTION_PICK,android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
galleryIntent.setType("image/*");
galleryIntent.putExtra("crop", "true");
galleryIntent.putExtra(MediaStore.EXTRA_OUTPUT, getTempUri());
galleryIntent.putExtra("aspectX", 1);
galleryIntent.putExtra("aspectY", 1);
galleryIntent.putExtra("outputX", 512);
galleryIntent.putExtra("outputY", 512);
galleryIntent.putExtra("scaleUpIfNeeded", true);
galleryIntent.putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString());