List of usage examples for android.app Activity finish
public void finish()
From source file:com.salmannazir.filemanager.businesslogic.EventHandler.java
public static void requestStoragePermission(final Activity mContext) { if (ActivityCompat.shouldShowRequestPermissionRationale(mContext, Manifest.permission.WRITE_EXTERNAL_STORAGE)) { new MaterialDialog.Builder(mContext).title("Storage Access Required") .content("Please grant storage access to operate").positiveText("Grant Permission") .onPositive(new MaterialDialog.SingleButtonCallback() { @Override/*from w w w.j ava 2s.c o m*/ public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) { // TODO ActivityCompat.requestPermissions(mContext, new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE }, Constants.REQUEST_STORAGE_PERMISSION); dialog.dismiss(); } }).negativeText("Cancel").onNegative(new MaterialDialog.SingleButtonCallback() { @Override public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) { mContext.finish(); } }).cancelable(false).show(); // Provide an additional rationale to the user if the permission was not granted // and the user would benefit from additional context for the use of the permission. // For example, if the request has been denied previously. } else { // Contact permissions have not been granted yet. Request them directly. ActivityCompat.requestPermissions(mContext, new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE }, Constants.REQUEST_STORAGE_PERMISSION); } }
From source file:nz.Intelx.DroidNetLogin.DroidNetLoginActivity.java
public void alert(String msg, Activity a) { final Activity act = a; final AlertDialog builder = new AlertDialog.Builder(a).setMessage(Html.fromHtml(msg)).setCancelable(false) .setNegativeButton("OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { if (act != null) act.finish(); else dialog.cancel(); }/*from w w w . j a v a 2 s . co m*/ }).show(); ((TextView) builder.findViewById(android.R.id.message)).setMovementMethod(LinkMovementMethod.getInstance()); }
From source file:uk.ac.horizon.artcodes.activity.ExperienceEditActivity.java
public void saveExperience(View view) { final Experience experience = getExperience(); final boolean isNew = experience.getId() == null; final Activity activity = this; final ProgressDialog dialog = ProgressDialog.show(activity, getResources().getString(R.string.saving_progress_dialog_title), getResources().getString(R.string.saving_progress_dialog_message), true); getAccount().saveExperience(experience, new Account.AccountProcessCallback() { @Override//from w w w . j av a 2 s . co m public void accountProcessCallback(boolean success, Experience savedExperience) { dialog.dismiss(); if (success) { if (isNew) { Intent intent = ExperienceActivity.intent(activity, savedExperience); startActivity(intent); activity.finish(); } else { NavUtils.navigateUpTo(activity, ExperienceActivity.intent(activity, experience)); } } else { runOnUiThread(new Runnable() { @Override public void run() { new AlertDialog.Builder(activity).setTitle(R.string.saving_error_title) .setMessage(R.string.saving_error_message).setPositiveButton( R.string.saving_error_button, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }) .show(); } }); } } }); }
From source file:felixwiemuth.lincal.ui.CalendarViewFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.calendar_view, container, false); TextView titleView = (TextView) rootView.findViewById(R.id.cal_title); TextView authorView = (TextView) rootView.findViewById(R.id.cal_author); notificationsEnabled = (CheckBox) rootView.findViewById(R.id.notifications_enabled); textViewEarliestNotificationTime = (TextView) rootView .findViewById(R.id.setting_earliest_notification_time); earliestNotificationTimeEnabled = (CheckBox) rootView .findViewById(R.id.setting_earliest_notification_time_enabled); entryDisplayModeDate = (Spinner) rootView.findViewById(R.id.setting_entry_display_mode_date); entryDisplayModeDescription = (Spinner) rootView.findViewById(R.id.setting_entry_display_mode_description); buttonRemoveCalendar = (Button) rootView.findViewById(R.id.button_remove_cal); if (calendar == null) { titleView.setText(R.string.cal_title_error_loading); notificationsEnabled.setEnabled(false); earliestNotificationTimeEnabled.setEnabled(false); entryDisplayModeDate.setEnabled(false); entryDisplayModeDescription.setEnabled(false); } else {// w ww .j a va 2 s .com titleView.setText(calendar.getTitle()); authorView.setText(calendar.getAuthor()); entryList = (RecyclerView) rootView.findViewById(R.id.entry_list_recycler_view); SimpleItemRecyclerViewAdapter adapter = new SimpleItemRecyclerViewAdapter(); entryList.setAdapter(adapter); ((TextView) rootView.findViewById(R.id.cal_descr)).setText(calendar.getDescription()); ((TextView) rootView.findViewById(R.id.cal_version)).setText(calendar.getVersion()); ((TextView) rootView.findViewById(R.id.cal_date)).setText(calendar.getDateStr()); if (calendar.hasForceEntryDisplayModeDate()) { entryDisplayModeDate.setEnabled(false); } if (calendar.hasForceEntryDisplayModeDescription()) { entryDisplayModeDescription.setEnabled(false); } } ArrayAdapter<CharSequence> spinnerAdapter = ArrayAdapter.createFromResource(getContext(), R.array.setting_entry_display_mode_options, android.R.layout.simple_spinner_item); spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); entryDisplayModeDate.setAdapter(spinnerAdapter); entryDisplayModeDescription.setAdapter(spinnerAdapter); loadSettings(); // loading settings before adding listeners prevents them from firing due to initialization (e.g. Spinner) if (calendar != null) { // Set listeners final View.OnClickListener saveSettingsListener = new View.OnClickListener() { @Override public void onClick(View v) { saveSettings(); NotificationService.runWithCalendar(getContext(), Calendars.getInstance(getContext()).getConfigByPos(calendarPos).getId()); //TODO reconsider when to call } }; notificationsEnabled.setOnClickListener(saveSettingsListener); textViewEarliestNotificationTime.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { loadSettings(); // update earliestNotificationTime DialogFragment dialogFragment = new TimePickerFragment(); Bundle arguments = new Bundle(); arguments.putInt("hour", earliestNotificationTime.getHour()); arguments.putInt("minute", earliestNotificationTime.getMinute()); arguments.putInt("calendarPos", calendarPos); dialogFragment.setArguments(arguments); dialogFragment.show(getFragmentManager(), "timePicker"); } }); earliestNotificationTimeEnabled.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { saveSettingsListener.onClick(v); // have to update the displayed notification times (only show when enabled) entryList.getAdapter().notifyDataSetChanged(); } }); //TODO implement // onScreenOnEnabled = (CheckBox) rootView.findViewById(R.id.setting_show_notification_on_screen_on); // onScreenOnEnabled.setOnClickListener(saveSettingsListener); entryDisplayModeDate.setOnItemSelectedListener(new AdapterViewOnItemSelectedListener( entryDisplayModeDate.getSelectedItemPosition(), saveSettingsListener)); entryDisplayModeDescription.setOnItemSelectedListener(new AdapterViewOnItemSelectedListener( entryDisplayModeDescription.getSelectedItemPosition(), saveSettingsListener)); } buttonRemoveCalendar.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { AlertDialog.Builder builder = new AlertDialog.Builder(getContext()); builder.setTitle(R.string.dialog_remove_cal_title).setMessage(R.string.dialog_remove_cal_msg) .setNegativeButton(R.string.dialog_no, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { } }).setPositiveButton(R.string.dialog_yes, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // First remove this fragment, so that it cannot be used anymore getActivity().getSupportFragmentManager().beginTransaction() .remove(CalendarViewFragment.this).commit(); Calendars calendars = Calendars.getInstance(getContext()); calendars.removeCalendarByPos(getContext(), calendarPos); // Notify calendar list that the calendar with the given position was removed and return to calendar list in case of CalendarViewActivity Activity hostActivity = getActivity(); if (hostActivity instanceof CalendarListActivity) { ((CalendarListActivity) hostActivity).notifyCalendarRemoved(calendarPos); } else if (hostActivity instanceof CalendarViewActivity) { Intent resultData = new Intent(); resultData.putExtra(CalendarListActivity.EXTRA_RESULT_CAL_REMOVED, calendarPos); hostActivity.setResult(Activity.RESULT_OK, resultData); hostActivity.finish(); } else { throw new RuntimeException( "CalendarViewFragment may only be contained in either CalendarListActivity or CalendarViewActivity."); } } }); builder.show(); } }); return rootView; }
From source file:br.com.viniciuscr.notification2android.mediaPlayer.MusicUtils.java
static void activateTab(Activity a, int id) { Intent intent = new Intent(Intent.ACTION_PICK); switch (id) { case R.id.artisttab: intent.setDataAndType(Uri.EMPTY, "vnd.android.cursor.dir/artistalbum"); break;/*from ww w . j ava2s .c o m*/ case R.id.albumtab: intent.setDataAndType(Uri.EMPTY, "vnd.android.cursor.dir/album"); break; case R.id.songtab: intent.setDataAndType(Uri.EMPTY, "vnd.android.cursor.dir/track"); break; case R.id.playlisttab: intent.setDataAndType(Uri.EMPTY, MediaStore.Audio.Playlists.CONTENT_TYPE); break; case R.id.nowplaying: // intent = new Intent(a, MediaPlaybackActivity.class); // a.startActivity(intent); // fall through and return default: return; } intent.putExtra("withtabs", true); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); a.startActivity(intent); a.finish(); a.overridePendingTransition(0, 0); }
From source file:com.android.launcher3.Utilities.java
private static void applyChange(Activity context) { context.finish(); context.startActivity(new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_LAUNCHER) .addCategory(Intent.CATEGORY_DEFAULT).addCategory(Intent.CATEGORY_HOME)); }
From source file:com.ota.updates.activities.MainActivity.java
private Boolean checkRomIsCompatible() { boolean doesRomSupportApp = Utils.doesPropExist(PROP_MANIFEST); if (!doesRomSupportApp) { final Activity activity = this; final Resources resources = getResources(); String title = resources.getString(R.string.no_support_title); String message = resources.getString(R.string.no_support_message); String findOutMore = resources.getString(R.string.no_support_find_out_more); AlertDialog.Builder alert = new AlertDialog.Builder(mContext); alert.setTitle(title);/* w w w. j a v a 2 s . c o m*/ alert.setMessage(message); alert.setCancelable(false); alert.setPositiveButton(findOutMore, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { String findOutMoreLink = resources.getString(R.string.no_support_find_out_more_link); Utils.openWebsite(mContext, findOutMoreLink); activity.finish(); // This is very bad. But I need to end the app here } }); alert.show(); } return doesRomSupportApp; }
From source file:com.owncloud.android.ui.preview.PreviewMediaFragment.java
/** * Finishes the preview/* w w w . j a va2 s.c o m*/ */ private void finish() { Activity container = getActivity(); if (container instanceof FileDisplayActivity) { // double pane FragmentTransaction transaction = getActivity().getSupportFragmentManager().beginTransaction(); transaction.replace(R.id.file_details_container, new FileDetailFragment(null, null), FileDetailFragment.FTAG); // empty FileDetailFragment transaction.commit(); ((FileFragment.ContainerActivity) container).onFileStateChanged(); } else { container.finish(); } }
From source file:paulscode.android.mupen64plusae.persistent.UserPrefs.java
public void changeLocale(final Activity activity) { // Get the index of the current locale final int currentIndex = ArrayUtils.indexOf(mLocaleCodes, mLocaleCode); // Populate and show the language menu Builder builder = new Builder(activity); builder.setTitle(R.string.menuItem_localeOverride); builder.setSingleChoiceItems(mLocaleNames, currentIndex, new DialogInterface.OnClickListener() { @Override//from w w w . ja v a 2s. co m public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); if (which >= 0 && which != currentIndex) { mPreferences.edit().putString(KEY_LOCALE_OVERRIDE, mLocaleCodes[which]).commit(); activity.finish(); activity.startActivity(activity.getIntent()); } } }); builder.create().show(); }
From source file:org.sufficientlysecure.keychain.ui.CreateSecurityTokenImportResetFragment.java
@Override public void onQueuedOperationSuccess(ImportKeyResult result) { long[] masterKeyIds = result.getImportedMasterKeyIds(); if (masterKeyIds.length == 0) { super.onCryptoOperationError(result); return;/* w ww. jav a2s . c om*/ } // null-protected from Queueing*Fragment Activity activity = getActivity(); Intent viewKeyIntent = new Intent(activity, ViewKeyActivity.class); // use the imported masterKeyId, not the one from the token, because // that one might* just have been a subkey of the imported key viewKeyIntent.setData(KeyRings.buildGenericKeyRingUri(masterKeyIds[0])); viewKeyIntent.putExtra(ViewKeyActivity.EXTRA_DISPLAY_RESULT, result); viewKeyIntent.putExtra(ViewKeyActivity.EXTRA_SECURITY_TOKEN_AID, mTokenAid); viewKeyIntent.putExtra(ViewKeyActivity.EXTRA_SECURITY_TOKEN_VERSION, mTokenVersion); viewKeyIntent.putExtra(ViewKeyActivity.EXTRA_SECURITY_TOKEN_USER_ID, mTokenUserId); viewKeyIntent.putExtra(ViewKeyActivity.EXTRA_SECURITY_TOKEN_FINGERPRINTS, mTokenFingerprints); if (activity instanceof CreateKeyActivity) { ((CreateKeyActivity) activity).finishWithFirstTimeHandling(viewKeyIntent); } else { activity.startActivity(viewKeyIntent); activity.finish(); } }