Skip to content

Instantly share code, notes, and snippets.

@tsmsogn
Last active December 11, 2015 01:28
Show Gist options
  • Select an option

  • Save tsmsogn/4523396 to your computer and use it in GitHub Desktop.

Select an option

Save tsmsogn/4523396 to your computer and use it in GitHub Desktop.
Android: Snippets
Bundle bundle = getIntent().getExtras();
if (bundle != null) {
color = bundle.getString("color");
String comment = bundle.getString("comment");
created = bundle.getLong("created");
position = bundle.getInt("position");
if (comment != null) {
mEditText1.setText(comment);
}
mTextView1.setText(DateFormat.format("yyyy/MM/dd", created));
}
boolean isEmailValid(CharSequence email) {
return android.util.Patterns.EMAIL_ADDRESS.matcher(email).matches();
}
LayoutInflater layoutInflater = (LayoutInflater) this.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = layoutInflater.inflate(R.layout.sample, null);
ArrayAdapter<CharSequence> list = ArrayAdapter.createFromResource(context, R.array.locations, R.layout.sherlock_spinner_item);
private Bitmap getBitmapFromUri(Uri uri) throws IOException {
ParcelFileDescriptor parcelFileDescriptor =
getContentResolver().openFileDescriptor(uri, "r");
FileDescriptor fileDescriptor = parcelFileDescriptor.getFileDescriptor();
Bitmap image = BitmapFactory.decodeFileDescriptor(fileDescriptor);
parcelFileDescriptor.close();
return image;
}
textView3.setMovementMethod(LinkMovementMethod.getInstance());
textView3.setFocusable(false);
int statusCode = GooglePlayServicesUtil
.isGooglePlayServicesAvailable(getApplicationContext());
if (statusCode == ConnectionResult.SUCCESS) {
Log.v(TAG, "" + statusCode);
} else if (statusCode == ConnectionResult.SERVICE_MISSING
|| statusCode == ConnectionResult.SERVICE_VERSION_UPDATE_REQUIRED
|| statusCode == ConnectionResult.SERVICE_DISABLED) {
Log.v(TAG, "" + statusCode);
Dialog dialog = GooglePlayServicesUtil.getErrorDialog(statusCode,
this, 1);
dialog.show();
}
Handler handler = new Handler();
Message message = Message.obtain(handler, new Runnable() {
public void run() {
InputMethodManager manager = (InputMethodManager) mContext
.getSystemService(mContext.INPUT_METHOD_SERVICE);
manager.showSoftInput(mAmountEditText,
InputMethodManager.SHOW_FORCED);
}
});
handler.sendMessageDelayed(message, 200);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment