List of usage examples for android.app Activity getString
@NonNull public final String getString(@StringRes int resId)
From source file:org.totschnig.myexpenses.dialog.ExportDialogFragment.java
@Override public void onClick(DialogInterface dialog, int which) { Bundle args = getArguments();//ww w . jav a 2s . co m Long accountId = args != null ? args.getLong("accountId") : null; Intent i; Activity ctx = getActivity(); AlertDialog dlg = (AlertDialog) dialog; String format = ((RadioGroup) dlg.findViewById(R.id.format)).getCheckedRadioButtonId() == R.id.csv ? "CSV" : "QIF"; String dateFormat = ((EditText) dlg.findViewById(R.id.date_format)).getText().toString(); MyApplication.getInstance().getSettings().edit().putString(MyApplication.PREFKEY_EXPORT_FORMAT, format) .putString(PREFKEY_EXPORT_DATE_FORMAT, dateFormat).commit(); boolean deleteP = ((CheckBox) dlg.findViewById(R.id.export_delete)).isChecked(); boolean notYetExportedP = ((CheckBox) dlg.findViewById(R.id.export_not_yet_exported)).isChecked(); if (Utils.isExternalStorageAvailable()) { if (accountId == null) Feature.RESET_ALL.recordUsage(); i = new Intent(ctx, Export.class).putExtra(KEY_ROWID, accountId).putExtra("format", format) .putExtra("deleteP", deleteP).putExtra("notYetExportedP", notYetExportedP) .putExtra("dateFormat", dateFormat); ctx.startActivityForResult(i, 0); } else { Toast.makeText(ctx, ctx.getString(R.string.external_storage_unavailable), Toast.LENGTH_LONG).show(); } }
From source file:org.pixmob.feedme.ui.EntriesFragment.java
private void authenticateAccount(String accountName) { Log.i(TAG, "Authenticating account: " + accountName); final Activity a = getActivity(); final AccountManager am = (AccountManager) a.getSystemService(Context.ACCOUNT_SERVICE); final Account account = new Account(accountName, GOOGLE_ACCOUNT); am.getAuthToken(account, "reader", null, a, new AccountManagerCallback<Bundle>() { @Override//from w w w . j a v a 2 s . c o m public void run(AccountManagerFuture<Bundle> resultContainer) { String authToken = null; final Bundle result; try { result = resultContainer.getResult(); authToken = result.getString(AccountManager.KEY_AUTHTOKEN); } catch (IOException e) { Log.w(TAG, "I/O error while authenticating account " + account.name, e); } catch (OperationCanceledException e) { Log.w(TAG, "Authentication was canceled for account " + account.name, e); } catch (AuthenticatorException e) { Log.w(TAG, "Authentication failed for account " + account.name, e); } if (authToken == null) { Toast.makeText(a, a.getString(R.string.authentication_failed), Toast.LENGTH_SHORT).show(); } else { Log.i(TAG, "Authentication done"); onAuthenticationDone(account.name, authToken); } } }, null); }
From source file:nya.miku.wishmaster.http.cloudflare.CloudflareUIHandler.java
/** * ?-? Cloudflare.// w w w . j a va 2 s. c o m * * @param e ? {@link CloudflareException} * @param chan * @param activity ?, ? ( ? ? ), * ? ? WebView ? Anti DDOS ? javascript. * ??? ? UI ({@link Activity#runOnUiThread(Runnable)}) * @param cfTask ?? * @param callback ? {@link Callback} */ static void handleCloudflare(final CloudflareException e, final HttpChanModule chan, final Activity activity, final CancellableTask cfTask, final InteractiveException.Callback callback) { if (cfTask.isCancelled()) return; if (!e.isRecaptcha()) { // ? anti DDOS if (!CloudflareChecker.getInstance().isAvaibleAntiDDOS()) { //? ? ?? , ? ? ? // ?, ? ChanModule, // ? ? () cloudflare ? ? // ? ? ? ? ? CloudflareChecker while (!CloudflareChecker.getInstance().isAvaibleAntiDDOS()) Thread.yield(); if (!cfTask.isCancelled()) activity.runOnUiThread(new Runnable() { @Override public void run() { callback.onSuccess(); } }); return; } Cookie cfCookie = CloudflareChecker.getInstance().checkAntiDDOS(e, chan.getHttpClient(), cfTask, activity); if (cfCookie != null) { chan.saveCookie(cfCookie); if (!cfTask.isCancelled()) { activity.runOnUiThread(new Runnable() { @Override public void run() { callback.onSuccess(); } }); } } else if (!cfTask.isCancelled()) { activity.runOnUiThread(new Runnable() { @Override public void run() { callback.onError(activity.getString(R.string.error_cloudflare_antiddos)); } }); } } else { // ? final Recaptcha recaptcha; try { recaptcha = CloudflareChecker.getInstance().getRecaptcha(e, chan.getHttpClient(), cfTask); } catch (RecaptchaException recaptchaException) { if (!cfTask.isCancelled()) activity.runOnUiThread(new Runnable() { @Override public void run() { callback.onError(activity.getString(R.string.error_cloudflare_get_captcha)); } }); return; } if (!cfTask.isCancelled()) activity.runOnUiThread(new Runnable() { @SuppressLint("InflateParams") @Override public void run() { Context dialogContext = Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB ? new ContextThemeWrapper(activity, R.style.Neutron_Medium) : activity; View view = LayoutInflater.from(dialogContext).inflate(R.layout.dialog_cloudflare_captcha, null); ImageView captchaView = (ImageView) view.findViewById(R.id.dialog_captcha_view); final EditText captchaField = (EditText) view.findViewById(R.id.dialog_captcha_field); captchaView.setImageBitmap(recaptcha.bitmap); DialogInterface.OnClickListener process = new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (cfTask.isCancelled()) return; PriorityThreadFactory.LOW_PRIORITY_FACTORY.newThread(new Runnable() { @Override public void run() { String answer = captchaField.getText().toString(); Cookie cfCookie = CloudflareChecker.getInstance().checkRecaptcha(e, (ExtendedHttpClient) chan.getHttpClient(), cfTask, recaptcha.challenge, answer); if (cfCookie != null) { chan.saveCookie(cfCookie); if (!cfTask.isCancelled()) { activity.runOnUiThread(new Runnable() { @Override public void run() { callback.onSuccess(); } }); } } else { // (?, , ) handleCloudflare(e, chan, activity, cfTask, callback); } } }).start(); } }; DialogInterface.OnCancelListener onCancel = new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { callback.onError(activity.getString(R.string.error_cloudflare_cancelled)); } }; if (cfTask.isCancelled()) return; final AlertDialog recaptchaDialog = new AlertDialog.Builder(dialogContext).setView(view) .setPositiveButton(R.string.dialog_cloudflare_captcha_check, process) .setOnCancelListener(onCancel).create(); recaptchaDialog.getWindow() .setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE); recaptchaDialog.setCanceledOnTouchOutside(false); recaptchaDialog.show(); captchaView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { recaptchaDialog.dismiss(); if (cfTask.isCancelled()) return; PriorityThreadFactory.LOW_PRIORITY_FACTORY.newThread(new Runnable() { @Override public void run() { handleCloudflare(e, chan, activity, cfTask, callback); } }).start(); } }); } }); } }
From source file:im.neon.activity.CommonActivityUtils.java
/** * Display a toast message according to the end call reason. * * @param aCallingActivity calling activity * @param aCallEndReason define the reason of the end call *///from w w w . j av a 2s . com public static void processEndCallInfo(Activity aCallingActivity, int aCallEndReason) { if (null != aCallingActivity) { if (IMXCall.END_CALL_REASON_UNDEFINED != aCallEndReason) { switch (aCallEndReason) { case IMXCall.END_CALL_REASON_PEER_HANG_UP: if (aCallingActivity instanceof InComingCallActivity) { CommonActivityUtils.displayToastOnUiThread(aCallingActivity, aCallingActivity.getString(R.string.call_error_peer_cancelled_call)); } else { // let VectorCallActivity manage its } break; case IMXCall.END_CALL_REASON_PEER_HANG_UP_ELSEWHERE: CommonActivityUtils.displayToastOnUiThread(aCallingActivity, aCallingActivity.getString(R.string.call_error_peer_hangup_elsewhere)); break; default: break; } } } }
From source file:org.catnut.fragment.TweetFragment.java
@Override public void onAttach(Activity activity) { super.onAttach(activity); Bundle args = getArguments();/*from ww w . j av a 2 s . c o m*/ if (args.containsKey(Constants.JSON)) { try { mJson = new JSONObject(args.getString(Constants.JSON)); mId = mJson.optLong(Constants.ID); } catch (JSONException e) { Log.e(TAG, "malformed json!", e); Toast.makeText(activity, activity.getString(R.string.malformed_json), Toast.LENGTH_LONG).show(); // getActivity().onBackPressed(); } } else { mId = args.getLong(Constants.ID); } mSelection = new StringBuilder(Status.TYPE).append("=").append(Status.COMMENT).append(" and ") .append(Status.TO_WHICH_TWEET).append("=").append(mId).toString(); }
From source file:com.android.launcher3.Utilities.java
private static void showIconPack(final Activity activity, final ShortcutInfo shortcutInfo) { final ArrayList<String> names = Utilities.getAvailableIconPackName(); final ArrayList<Bitmap> icons = Utilities.getAvailableIconPackImage(); ListAdapter adapter = new ArrayAdapterWithIcon(activity, names, icons); new AlertDialog.Builder(activity).setTitle(activity.getString(R.string.alert_choose_app)) .setAdapter(adapter, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int item) { showIconInPack(activity, names.get(item), shortcutInfo); }//from w w w. j ava 2s . c o m }).show(); }
From source file:com.hijacker.MainActivity.java
static void checkForUpdate(final Activity activity, final boolean showMessages) { //Can be called from any thread, blocks until the job is finished Runnable runnable = new Runnable() { @Override/* www .j a va 2 s . c o m*/ public void run() { progress.setIndeterminate(false); } }; if (showMessages) { runInHandler(new Runnable() { @Override public void run() { progress.setIndeterminate(true); } }); } Socket socket = connect(); if (socket == null) { if (showMessages) { runInHandler(runnable); Snackbar.make(rootView, activity.getString(R.string.server_error), Snackbar.LENGTH_SHORT).show(); } return; } try { PrintWriter in = new PrintWriter(socket.getOutputStream()); BufferedReader out = new BufferedReader(new InputStreamReader(socket.getInputStream())); in.print(REQ_VERSION + '\n'); in.flush(); int latestCode = Integer.parseInt(out.readLine()); String latestName = out.readLine(); String latestLink = out.readLine(); in.print(REQ_EXIT + '\n'); in.flush(); in.close(); out.close(); socket.close(); if (latestCode > versionCode) { final UpdateConfirmDialog dialog = new UpdateConfirmDialog(); dialog.newVersionCode = latestCode; dialog.newVersionName = latestName; dialog.link = latestLink; runInHandler(new Runnable() { @Override public void run() { dialog.show(activity.getFragmentManager(), "UpdateConfirmDialog"); } }); } else { if (showMessages) Snackbar.make(rootView, activity.getString(R.string.already_on_latest), Snackbar.LENGTH_SHORT) .show(); } } catch (IOException | NumberFormatException e) { Log.e("HIJACKER/update", e.toString()); if (showMessages) Snackbar.make(rootView, activity.getString(R.string.unknown_error), Snackbar.LENGTH_SHORT).show(); } finally { if (showMessages) runInHandler(runnable); } }
From source file:it.imwatch.nfclottery.dialogs.InsertContactDialog.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { // Use the Builder class for convenient dialog construction final Activity activity = getActivity(); if (activity == null) { Log.e(TAG, "Not attached to Activity: cannot build dialog"); return null; }//from ww w .j av a 2s. c o m AlertDialog.Builder builder = new AlertDialog.Builder(activity); // Get the layout inflater LayoutInflater inflater = LayoutInflater.from(activity); final View rootView = inflater.inflate(R.layout.dialog_insert, null); if (rootView == null) { Log.e(TAG, "Cannot inflate the dialog layout!"); return null; } mErrorAnimTranslateY = getResources().getDimensionPixelSize(R.dimen.error_anim_translate_y); mEmailErrorTextView = (TextView) rootView.findViewById(R.id.lbl_email_error); mNameErrorTextView = (TextView) rootView.findViewById(R.id.lbl_name_error); // Restore instance state (if any) if (savedInstanceState != null) { mNameErrorState = savedInstanceState.getInt(EXTRA_NAME_ERROR, 0); mEmailErrorState = savedInstanceState.getInt(EXTRA_EMAIL_ERROR, 0); if (mNameErrorState == 1) showNameError(); if (mEmailErrorState == 1) { showEmailError(activity.getString(R.string.error_emailinput_invalid), 1); } else if (mEmailErrorState == 2) { showEmailError(activity.getString(R.string.error_emailinput_duplicate), 2); } } mEmailEditText = (EditText) rootView.findViewById(R.id.txt_edit_email); mNameEditText = (EditText) rootView.findViewById(R.id.txt_edit_name); mOrganizationEditText = (EditText) rootView.findViewById(R.id.txt_edit_organization); mTitleEditText = (EditText) rootView.findViewById(R.id.txt_edit_title); // Add the check for a valid email address and names mEmailEditText.setOnFocusChangeListener(mFocusWatcher); mNameEditText.setOnFocusChangeListener(mFocusWatcher); // Add the check for a valid email during typing mEmailEditText.addTextChangedListener(mEmailTypingWatcher); // Inflate and set the layout for the dialog // Pass null as the parent view because its going in the dialog layout builder.setView(rootView).setPositiveButton(android.R.string.ok, null) .setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { final Dialog thisDialog = InsertContactDialog.this.getDialog(); if (thisDialog != null) { thisDialog.cancel(); } else { Log.w(TAG, "Can't get the Dialog instance."); } } }); // Create the AlertDialog object and return it AlertDialog alertDialog = builder.create(); alertDialog.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface dialog) { final AlertDialog alertDialog = (AlertDialog) dialog; // Disable the positive button. It will be enabled only when there is a valid email final Button button = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE); if (button != null) { button.setEnabled(false); button.setOnClickListener(new DontAutoCloseDialogListener(alertDialog)); } else { Log.w(TAG, "Can't get the dialog positive button."); } alertDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE); } }); return alertDialog; }
From source file:com.android.launcher3.Utilities.java
private static void showIconInPack(final Activity activity, String packName, final ShortcutInfo shortcutInfo) { String packNamePackage = null; for (AppInfo app : AllAppsList.data) { if (app.title.equals(packName)) { packNamePackage = app.getTargetComponent().getPackageName(); }/* w w w . ja va 2s.c o m*/ } items.clear(); icons.clear(); final HashMap<String, Bitmap> map = new HashMap<>(getIconPack(packNamePackage)); ListAdapter adapter = new ArrayAdapterWithIcon(activity, items, icons); new AlertDialog.Builder(activity).setTitle(activity.getString(R.string.alert_choose_app)) .setAdapter(adapter, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int item) { saveBitmapPref(activity, shortcutInfo.getTargetComponent().getPackageName(), icons.get(item)); //Launcher.getLauncherAppState().reloadWorkspace(); } }).show(); }