Last active
December 11, 2015 01:28
-
-
Save tsmsogn/4523396 to your computer and use it in GitHub Desktop.
Android: Snippets
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
| 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)); | |
| } |
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
| boolean isEmailValid(CharSequence email) { | |
| return android.util.Patterns.EMAIL_ADDRESS.matcher(email).matches(); | |
| } |
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
| LayoutInflater layoutInflater = (LayoutInflater) this.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); | |
| View view = layoutInflater.inflate(R.layout.sample, null); |
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
| ArrayAdapter<CharSequence> list = ArrayAdapter.createFromResource(context, R.array.locations, R.layout.sherlock_spinner_item); |
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
| 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; | |
| } |
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
| textView3.setMovementMethod(LinkMovementMethod.getInstance()); | |
| textView3.setFocusable(false); |
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
| 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(); | |
| } |
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
| 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