List of usage examples for android.app Activity finish
public void finish()
From source file:com.remobile.file.FileUtils.java
public void initialize() { this.filesystems = new ArrayList<Filesystem>(); String tempRoot = null;// w w w.ja v a 2 s . c om String persistentRoot = null; Activity activity = cordova.getActivity(); String packageName = activity.getPackageName(); String location = "internal"; tempRoot = activity.getCacheDir().getAbsolutePath(); if ("internal".equalsIgnoreCase(location)) { persistentRoot = activity.getFilesDir().getAbsolutePath() + "/files/"; this.configured = true; } else if ("compatibility".equalsIgnoreCase(location)) { /* * Fall-back to compatibility mode -- this is the logic implemented in * earlier versions of this plugin, and should be maintained here so * that apps which were originally deployed with older versions of the * plugin can continue to provide access to files stored under those * versions. */ if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { persistentRoot = Environment.getExternalStorageDirectory().getAbsolutePath(); tempRoot = Environment.getExternalStorageDirectory().getAbsolutePath() + "/Android/data/" + packageName + "/cache/"; } else { persistentRoot = "/data/data/" + packageName; } this.configured = true; } if (this.configured) { // Create the directories if they don't exist. File tmpRootFile = new File(tempRoot); File persistentRootFile = new File(persistentRoot); tmpRootFile.mkdirs(); persistentRootFile.mkdirs(); // Register initial filesystems // Note: The temporary and persistent filesystems need to be the first two // registered, so that they will match window.TEMPORARY and window.PERSISTENT, // per spec. this.registerFilesystem( new LocalFilesystem("temporary", this.getContext(), this.getResourceApi(), tmpRootFile)); this.registerFilesystem(new LocalFilesystem("persistent", this.getContext(), this.getResourceApi(), persistentRootFile)); this.registerFilesystem(new ContentFilesystem(this.getContext(), this.getResourceApi())); this.registerFilesystem(new AssetFilesystem(this.getContext().getAssets(), this.getResourceApi())); registerExtraFileSystems(getExtraFileSystemsPreference(activity), getAvailableFileSystems(activity)); // Initialize static plugin reference for deprecated getEntry method if (filePlugin == null) { FileUtils.filePlugin = this; } } else { Log.e(LOG_TAG, "File plugin configuration error: Please set AndroidPersistentFileLocation in config.xml to one of \"internal\" (for new applications) or \"compatibility\" (for compatibility with previous versions)"); activity.finish(); } }
From source file:org.uab.deic.uabdroid.solutions.unit3.FormFragment.java
@Override public void onActivityCreated(Bundle _savedInstanceState) { super.onActivityCreated(_savedInstanceState); // As we are in a fragment, we need the parent activity instance in order to have access // to the activity's SharedPreferences and the layout Views final Activity parentActivity = getActivity(); SharedPreferences activityPreferences = parentActivity.getPreferences(Context.MODE_PRIVATE); mEditTextName = (EditText) parentActivity.findViewById(R.id.edittext_form_name); mEditTextDeveloper = (EditText) parentActivity.findViewById(R.id.edittext_form_developer); mDatePickerDate = (DatePicker) parentActivity.findViewById(R.id.datepicker_form_date); mEditTextURL = (EditText) parentActivity.findViewById(R.id.edittext_form_url); // if the last run of the activity wasn't finished using the Accept or Cancel buttons // then we must restore the state if (activityPreferences.getBoolean(FormAppActivity.STATE_NOT_SAVED, false)) { // Restore the name mEditTextName.setText(activityPreferences.getString(FormAppActivity.FORM_FIELD_NAME, "")); // Restore the developer name mEditTextDeveloper.setText(activityPreferences.getString(FormAppActivity.FORM_FIELD_DEVELOPER, "")); // Restore the calendar. The default values are extracted from Calendar, which is // instantiated with the current date Calendar calendar = Calendar.getInstance(); int day = activityPreferences.getInt(FormAppActivity.FORM_FIELD_DAY, calendar.get(Calendar.DAY_OF_MONTH)); int month = activityPreferences.getInt(FormAppActivity.FORM_FIELD_MONTH, calendar.get(Calendar.MONTH) + 1); int year = activityPreferences.getInt(FormAppActivity.FORM_FIELD_YEAR, calendar.get(Calendar.YEAR)); mDatePickerDate.updateDate(year, month, day); // Restore the URL mEditTextURL.setText(activityPreferences.getString(FormAppActivity.FORM_FIELD_URL, "")); // Finally, we restore the state of STATE_NOT_SAVED to false SharedPreferences.Editor editor = activityPreferences.edit(); editor.putBoolean(FormAppActivity.STATE_NOT_SAVED, false); editor.commit();/*from w ww . jav a2s .c om*/ } Button cleanButton = (Button) parentActivity.findViewById(R.id.button_form_clean); cleanButton.setOnClickListener(new OnClickListener() { // When the button is clicked, we erase the content of the controls // o reset them to the default value @Override public void onClick(View v) { mEditTextName.setText(""); mEditTextDeveloper.setText(""); Calendar calendar = Calendar.getInstance(); mDatePickerDate.updateDate(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH) + 1, calendar.get(Calendar.DAY_OF_MONTH)); mEditTextURL.setText(""); } }); Button acceptButton = (Button) parentActivity.findViewById(R.id.button_form_accept); acceptButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.DAY_OF_MONTH, mDatePickerDate.getDayOfMonth()); calendar.set(Calendar.MONTH, mDatePickerDate.getMonth() - 1); calendar.set(Calendar.YEAR, mDatePickerDate.getYear()); String name = mEditTextName.getText().toString(); String developer = mEditTextDeveloper.getText().toString(); String url = mEditTextURL.getText().toString(); Intent intent = new Intent(parentActivity, ResultsActivity.class); // Store the data in the intent bundle intent.putExtra("name", name); intent.putExtra("developer", name); intent.putExtra("date", mDatePickerDate.getDayOfMonth() + "/" + mDatePickerDate.getMonth() + "/" + mDatePickerDate.getYear()); intent.putExtra("url", name); // Store the data for the App Singleton MyApplication.getInstance().setData(AppData.getInstance(name, developer, calendar, url)); // Store the data in the database DatabaseAdapter databaseAdapter = new DatabaseAdapter(parentActivity); databaseAdapter.open(); databaseAdapter.insertApp(name, developer, calendar, url); databaseAdapter.close(); // Indicating that the activity is finished by the use of the button ((FormAppActivity) parentActivity).setButtonPressed(); startActivity(intent); // As we have finished with this activity, we finalized it so // the user never returns to it when the back button is pressed parentActivity.finish(); } }); Button cancelButton = (Button) parentActivity.findViewById(R.id.button_form_cancel); cancelButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // Finishing the activity by the use of the button ((FormAppActivity) parentActivity).setButtonPressed(); parentActivity.finish(); } }); }
From source file:im.vector.fragments.VectorSettingsPreferencesFragment.java
private void displayTextSizeSelection(final Activity activity) { AlertDialog.Builder builder = new AlertDialog.Builder(activity); LayoutInflater inflater = activity.getLayoutInflater(); View layout = inflater.inflate(R.layout.text_size_selection, null); builder.setTitle(R.string.font_size); builder.setView(layout);/* w w w . j av a 2 s.co m*/ builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { } }); builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { } }); final AlertDialog dialog = builder.create(); dialog.show(); LinearLayout linearLayout = layout.findViewById(R.id.text_selection_group_view); int childCount = linearLayout.getChildCount(); String scaleText = VectorApp.getFontScale(); for (int i = 0; i < childCount; i++) { View v = linearLayout.getChildAt(i); if (v instanceof CheckedTextView) { final CheckedTextView checkedTextView = (CheckedTextView) v; checkedTextView.setChecked(TextUtils.equals(checkedTextView.getText(), scaleText)); checkedTextView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { dialog.dismiss(); VectorApp.updateFontScale(checkedTextView.getText().toString()); activity.startActivity(activity.getIntent()); activity.finish(); } }); } } }
From source file:carnero.cgeo.original.libs.Base.java
public void goHome(Activity activity) { final Intent intent = new Intent(activity, main.class); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); activity.startActivity(intent);/*w w w . ja va 2 s . c o m*/ activity.finish(); }
From source file:carnero.cgeo.cgBase.java
public void goHome(Activity activity) { final Intent intent = new Intent(activity, cgeo.class); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); activity.startActivity(intent);/*from w w w . ja va 2 s . co m*/ activity.finish(); }
From source file:org.quantumbadger.redreader.reddit.prepared.RedditPreparedPost.java
public static void onActionMenuItemSelected(final RedditPreparedPost post, final Activity activity, final Action action) { switch (action) { case UPVOTE:/*from w w w. j a va 2s . c o m*/ post.action(activity, RedditAPI.RedditAction.UPVOTE); break; case DOWNVOTE: post.action(activity, RedditAPI.RedditAction.DOWNVOTE); break; case UNVOTE: post.action(activity, RedditAPI.RedditAction.UNVOTE); break; case SAVE: post.action(activity, RedditAPI.RedditAction.SAVE); break; case UNSAVE: post.action(activity, RedditAPI.RedditAction.UNSAVE); break; case HIDE: post.action(activity, RedditAPI.RedditAction.HIDE); break; case UNHIDE: post.action(activity, RedditAPI.RedditAction.UNHIDE); break; case DELETE: new AlertDialog.Builder(activity).setTitle(R.string.accounts_delete).setMessage(R.string.delete_confirm) .setPositiveButton(R.string.action_delete, new DialogInterface.OnClickListener() { public void onClick(final DialogInterface dialog, final int which) { post.action(activity, RedditAPI.RedditAction.DELETE); } }).setNegativeButton(R.string.dialog_cancel, null).show(); break; case REPORT: new AlertDialog.Builder(activity).setTitle(R.string.action_report) .setMessage(R.string.action_report_sure) .setPositiveButton(R.string.action_report, new DialogInterface.OnClickListener() { public void onClick(final DialogInterface dialog, final int which) { post.action(activity, RedditAPI.RedditAction.REPORT); // TODO update the view to show the result // TODO don't forget, this also hides } }).setNegativeButton(R.string.dialog_cancel, null).show(); break; case EXTERNAL: { final Intent intent = new Intent(Intent.ACTION_VIEW); String url = (activity instanceof WebViewActivity) ? ((WebViewActivity) activity).getCurrentUrl() : post.url; intent.setData(Uri.parse(url)); activity.startActivity(intent); break; } case SELFTEXT_LINKS: { final HashSet<String> linksInComment = LinkHandler .computeAllLinks(StringEscapeUtils.unescapeHtml4(post.src.selftext)); if (linksInComment.isEmpty()) { General.quickToast(activity, R.string.error_toast_no_urls_in_self); } else { final String[] linksArr = linksInComment.toArray(new String[linksInComment.size()]); final AlertDialog.Builder builder = new AlertDialog.Builder(activity); builder.setItems(linksArr, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { LinkHandler.onLinkClicked(activity, linksArr[which], false, post.src); dialog.dismiss(); } }); final AlertDialog alert = builder.create(); alert.setTitle(R.string.action_selftext_links); alert.setCanceledOnTouchOutside(true); alert.show(); } break; } case SAVE_IMAGE: { final RedditAccount anon = RedditAccountManager.getAnon(); LinkHandler.getImageInfo(activity, post.url, Constants.Priority.IMAGE_VIEW, 0, new GetImageInfoListener() { @Override public void onFailure(final RequestFailureType type, final Throwable t, final StatusLine status, final String readableMessage) { final RRError error = General.getGeneralErrorForFailure(activity, type, t, status, post.url); General.showResultDialog(activity, error); } @Override public void onSuccess(final ImgurAPI.ImageInfo info) { CacheManager.getInstance(activity) .makeRequest(new CacheRequest(General.uriFromString(info.urlOriginal), anon, null, Constants.Priority.IMAGE_VIEW, 0, CacheRequest.DownloadType.IF_NECESSARY, Constants.FileType.IMAGE, false, false, false, activity) { @Override protected void onCallbackException(Throwable t) { BugReportActivity.handleGlobalError(context, t); } @Override protected void onDownloadNecessary() { General.quickToast(context, R.string.download_downloading); } @Override protected void onDownloadStarted() { } @Override protected void onFailure(RequestFailureType type, Throwable t, StatusLine status, String readableMessage) { final RRError error = General.getGeneralErrorForFailure(context, type, t, status, url.toString()); General.showResultDialog(activity, error); } @Override protected void onProgress(boolean authorizationInProgress, long bytesRead, long totalBytes) { } @Override protected void onSuccess(CacheManager.ReadableCacheFile cacheFile, long timestamp, UUID session, boolean fromCache, String mimetype) { File dst = new File( Environment.getExternalStoragePublicDirectory( Environment.DIRECTORY_PICTURES), General.uriFromString(info.urlOriginal).getPath()); if (dst.exists()) { int count = 0; while (dst.exists()) { count++; dst = new File( Environment.getExternalStoragePublicDirectory( Environment.DIRECTORY_PICTURES), count + "_" + General.uriFromString(info.urlOriginal) .getPath().substring(1)); } } try { final InputStream cacheFileInputStream = cacheFile.getInputStream(); if (cacheFileInputStream == null) { notifyFailure(RequestFailureType.CACHE_MISS, null, null, "Could not find cached image"); return; } General.copyFile(cacheFileInputStream, dst); } catch (IOException e) { notifyFailure(RequestFailureType.STORAGE, e, null, "Could not copy file"); return; } activity.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.parse("file://" + dst.getAbsolutePath()))); General.quickToast(context, context.getString(R.string.action_save_image_success) + " " + dst.getAbsolutePath()); } }); } @Override public void onNotAnImage() { General.quickToast(activity, R.string.selected_link_is_not_image); } }); break; } case SHARE: { final Intent mailer = new Intent(Intent.ACTION_SEND); mailer.setType("text/plain"); mailer.putExtra(Intent.EXTRA_SUBJECT, post.title); mailer.putExtra(Intent.EXTRA_TEXT, post.url); activity.startActivity(Intent.createChooser(mailer, activity.getString(R.string.action_share))); break; } case SHARE_COMMENTS: { final Intent mailer = new Intent(Intent.ACTION_SEND); mailer.setType("text/plain"); mailer.putExtra(Intent.EXTRA_SUBJECT, "Comments for " + post.title); mailer.putExtra(Intent.EXTRA_TEXT, Constants.Reddit.getUri(Constants.Reddit.PATH_COMMENTS + post.idAlone).toString()); activity.startActivity( Intent.createChooser(mailer, activity.getString(R.string.action_share_comments))); break; } case COPY: { ClipboardManager manager = (ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE); manager.setText(post.url); break; } case GOTO_SUBREDDIT: { try { final Intent intent = new Intent(activity, PostListingActivity.class); intent.setData(SubredditPostListURL.getSubreddit(post.src.subreddit).generateJsonUri()); activity.startActivityForResult(intent, 1); } catch (RedditSubreddit.InvalidSubredditNameException e) { Toast.makeText(activity, R.string.invalid_subreddit_name, Toast.LENGTH_LONG).show(); } break; } case USER_PROFILE: LinkHandler.onLinkClicked(activity, new UserProfileURL(post.src.author).toString()); break; case PROPERTIES: PostPropertiesDialog.newInstance(post.src).show(activity.getFragmentManager(), null); break; case COMMENTS: ((RedditPostView.PostSelectionListener) activity).onPostCommentsSelected(post); break; case LINK: ((RedditPostView.PostSelectionListener) activity).onPostSelected(post); break; case COMMENTS_SWITCH: if (!(activity instanceof MainActivity)) activity.finish(); ((RedditPostView.PostSelectionListener) activity).onPostCommentsSelected(post); break; case LINK_SWITCH: if (!(activity instanceof MainActivity)) activity.finish(); ((RedditPostView.PostSelectionListener) activity).onPostSelected(post); break; case ACTION_MENU: showActionMenu(activity, post); break; case REPLY: final Intent intent = new Intent(activity, CommentReplyActivity.class); intent.putExtra("parentIdAndType", post.idAndType); activity.startActivity(intent); break; } }