Skip to content

Instantly share code, notes, and snippets.

@filipesperandio
Last active October 11, 2016 14:50
Show Gist options
  • Save filipesperandio/8a5bd1a4a05128f5b1751ba62a8fc607 to your computer and use it in GitHub Desktop.
Save filipesperandio/8a5bd1a4a05128f5b1751ba62a8fc607 to your computer and use it in GitHub Desktop.
Android Gists
public void show() {
LayoutInflater li = LayoutInflater.from(activity);
final View promptsView = li.inflate(R.layout.YOUR_DIALOG_LAYOUT, null);
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(activity);
alertDialogBuilder.setView(promptsView);
final EditText userInput = (EditText) promptsView.findViewById(R.id.YOUR_INPUT_FIELD);
alertDialogBuilder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
...
}
});
alertDialogBuilder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
...
}
});
alertDialogBuilder.setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
toggleKeyboard();
}
});
alertDialogBuilder.show();
userInput.requestFocus();
toggleKeyboard();
}
protected void toggleKeyboard() {
((InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE))
.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
}
Intent install = new Intent(Intent.ACTION_INSTALL_PACKAGE);
install.setDataAndType(Uri.fromFile(new File(apkLocation)), "application/vnd.android.package-archive");
install.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
install.putExtra(Intent.EXTRA_RETURN_RESULT, true);
// No effect on non-system apps
// https://code.google.com/p/android/issues/detail?id=42253
install.putExtra(Intent.EXTRA_NOT_UNKNOWN_SOURCE, true);
startActivity(install);
static {
RxAndroidPlugins rxAndroidPlugins = RxAndroidPlugins.getInstance();
rxAndroidPlugins.reset();
rxAndroidPlugins.registerSchedulersHook(new RxAndroidSchedulersHook() {
@Override
public Scheduler getMainThreadScheduler() {
return Schedulers.immediate();
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment