Example usage for android.app Activity getString

List of usage examples for android.app Activity getString

Introduction

In this page you can find the example usage for android.app Activity getString.

Prototype

@NonNull
public final String getString(@StringRes int resId) 

Source Link

Document

Returns a localized string from the application's package's default string table.

Usage

From source file:it.imwatch.nfclottery.dialogs.WinnersListDialog.java

/**
 * Revokes victory to the contact with the ID specified in the
 * {@link #mPendingRevokeId} field.//from   w w w.  jav a2s  .  c om
 */
private void revokeVictory() {
    final Activity activity = getActivity();
    if (mPendingRevokeId < 0) {
        if (activity != null) {
            Toast.makeText(activity, activity.getString(R.string.error_revoke_no_id), Toast.LENGTH_SHORT)
                    .show();
        }
        Log.e(TAG, "Unable to revoke victory for contact #" + mPendingRevokeId + ": invalid ID");
        return;
    }

    int updatedCount = DataHelper.clearWinner(getActivity(), mPendingRevokeId);
    if (updatedCount > 0) {
        if (activity != null) {
            Toast.makeText(activity, activity.getString(R.string.victory_revoked), Toast.LENGTH_SHORT).show();
        }
        Log.i(TAG, "Revoked victory for contact #" + mPendingRevokeId);
    } else {
        if (activity != null) {
            Toast.makeText(activity, activity.getString(R.string.error_revoke_db_err), Toast.LENGTH_SHORT)
                    .show();
        }
        Log.e(TAG, "Unable to revoke victory for contact #" + mPendingRevokeId + ": 0 rows updated");
    }

    mWinnersCursor = updateWinnersCursors();
    mWinnersAdapter.changeCursor(mWinnersCursor);

    endRevokeVictory();
}

From source file:org.totschnig.myexpenses.activity.CommonCommands.java

static boolean dispatchCommand(Activity ctx, int command, Object tag) {
    Intent i;/*  w ww  .j  a  v a  2  s  .c  o  m*/
    switch (command) {
    case R.id.RATE_COMMAND:
        i = new Intent(Intent.ACTION_VIEW);
        i.setData(Uri.parse(MyApplication.getMarketSelfUri()));
        if (Utils.isIntentAvailable(ctx, i)) {
            ctx.startActivity(i);
        } else {
            Toast.makeText(ctx, R.string.error_accessing_market, Toast.LENGTH_LONG).show();
        }
        return true;
    case R.id.SETTINGS_COMMAND:
        i = new Intent(ctx, MyPreferenceActivity.class);
        i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        if (tag != null) {
            i.putExtra(MyPreferenceActivity.KEY_OPEN_PREF_KEY, (String) tag);
        }
        ctx.startActivityForResult(i, ProtectedFragmentActivity.PREFERENCES_REQUEST);
        return true;
    case R.id.FEEDBACK_COMMAND:
        i = new Intent(android.content.Intent.ACTION_SEND);
        i.setType("plain/text");
        i.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] { MyApplication.FEEDBACK_EMAIL });
        i.putExtra(android.content.Intent.EXTRA_SUBJECT, "[" + ctx.getString(R.string.app_name) + "] Feedback");
        i.putExtra(android.content.Intent.EXTRA_TEXT,
                getVersionInfo(ctx) + "\n" + ctx.getString(R.string.feedback_email_message));
        if (!Utils.isIntentAvailable(ctx, i)) {
            Toast.makeText(ctx, R.string.no_app_handling_email_available, Toast.LENGTH_LONG).show();
        } else {
            ctx.startActivity(i);
        }
        break;
    case R.id.CONTRIB_INFO_COMMAND:
        CommonCommands.showContribInfoDialog((FragmentActivity) ctx, -1);
        return true;
    case R.id.WEB_COMMAND:
        i = new Intent(Intent.ACTION_VIEW);
        i.setData(Uri.parse(ctx.getString(R.string.website)));
        ctx.startActivity(i);
        return true;
    case R.id.HELP_COMMAND:
        i = new Intent(ctx, Help.class);
        i.putExtra(HelpDialogFragment.KEY_VARIANT,
                tag != null ? (Enum<?>) tag : ((ProtectedFragmentActivity) ctx).helpVariant);
        //for result is needed since it allows us to inspect the calling activity
        ctx.startActivityForResult(i, 0);
        return true;
    case R.id.REQUEST_LICENCE_COMMAND:
        String androidId = Settings.Secure.getString(ctx.getContentResolver(), Settings.Secure.ANDROID_ID);
        i = new Intent(android.content.Intent.ACTION_SEND);
        i.setType("plain/text");
        i.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] { MyApplication.FEEDBACK_EMAIL });
        i.putExtra(android.content.Intent.EXTRA_SUBJECT,
                "[" + ctx.getString(R.string.app_name) + "] " + ctx.getString(R.string.contrib_key));
        String extraText = ctx.getString(R.string.request_licence_mail_head, androidId);
        if (tag != null) {
            extraText += " \n\n[" + ctx.getString(R.string.paypal_transaction_id) + ": " + tag + "]";
        }
        i.putExtra(android.content.Intent.EXTRA_TEXT, extraText);
        if (!Utils.isIntentAvailable(ctx, i)) {
            Toast.makeText(ctx, R.string.no_app_handling_email_available, Toast.LENGTH_LONG).show();
        } else {
            ctx.startActivity(i);
        }
        return true;
    case R.id.VERIFY_LICENCE_COMMAND:
        HashLicenceHandler licenceHandler = (HashLicenceHandler) MyApplication.getInstance()
                .getLicenceHandler();
        LicenceHandler.LicenceStatus licenceStatus = licenceHandler.verifyLicenceKey();
        if (licenceStatus != null) {
            Toast.makeText(ctx,
                    Utils.concatResStrings(ctx, " ", R.string.licence_validation_success,
                            (licenceStatus == LicenceHandler.LicenceStatus.EXTENDED
                                    ? R.string.licence_validation_extended
                                    : R.string.licence_validation_premium)),
                    Toast.LENGTH_LONG).show();
        } else {
            Toast.makeText(ctx, R.string.licence_validation_failure, Toast.LENGTH_LONG).show();
        }
        licenceHandler.invalidate();
        return true;
    case android.R.id.home:
        ctx.setResult(FragmentActivity.RESULT_CANCELED);
        ctx.finish();
        return true;
    }
    return false;
}

From source file:com.google.android.apps.flexbox.FlexItemEditFragment.java

@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        setStyle(DialogFragment.STYLE_NORMAL, android.R.style.Theme_Material_Light_Dialog);
    } else {/*from  w w w .  j av a2s.co  m*/
        setStyle(DialogFragment.STYLE_NORMAL, android.R.style.Theme_Dialog);
    }
    Bundle args = getArguments();
    mFlexItem = args.getParcelable(FLEX_ITEM_KEY);

    Activity activity = getActivity();
    ALIGN_SELF_AUTO = activity.getString(R.string.auto);
    ALIGN_SELF_FLEX_START = activity.getString(R.string.flex_start);
    ALIGN_SELF_FLEX_END = activity.getString(R.string.flex_end);
    ALIGN_SELF_CENTER = activity.getString(R.string.center);
    ALIGN_SELF_BASELINE = activity.getString(R.string.baseline);
    ALIGN_SELF_STRETCH = activity.getString(R.string.stretch);
}

From source file:de.baumann.hhsmoodle.helper.helper_webView.java

public static void webView_WebViewClient(final Activity from, final SwipeRefreshLayout swipeRefreshLayout,
        final WebView webView) {

    webView.setWebViewClient(new WebViewClient() {

        ProgressDialog progressDialog;/*  w  ww  .  ja va2  s .c  o  m*/
        int numb;

        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);

            ViewPager viewPager = (ViewPager) from.findViewById(R.id.viewpager);
            SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(from);
            sharedPref.edit().putString("loadURL", webView.getUrl()).apply();

            if (viewPager.getCurrentItem() == 0) {
                if (url != null) {
                    from.setTitle(webView.getTitle());
                }
            }

            if (url != null && url.contains("moodle.huebsch.ka.schule-bw.de/moodle/")
                    && url.contains("/login/")) {

                if (viewPager.getCurrentItem() == 0 && numb != 1) {
                    progressDialog = new ProgressDialog(from);
                    progressDialog.setTitle(from.getString(R.string.login_title));
                    progressDialog.setMessage(from.getString(R.string.login_text));
                    progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
                    progressDialog.setButton(DialogInterface.BUTTON_NEGATIVE,
                            from.getString(R.string.toast_settings), new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    helper_main.switchToActivity(from, Activity_settings.class, true);
                                }
                            });
                    progressDialog.show();
                    numb = 1;
                    progressDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
                        @Override
                        public void onCancel(DialogInterface dialog) {
                            numb = 0;
                        }
                    });
                }

            } else if (progressDialog != null && progressDialog.isShowing()) {
                progressDialog.cancel();
                numb = 0;
            }

            swipeRefreshLayout.setRefreshing(false);

            class_SecurePreferences sharedPrefSec = new class_SecurePreferences(from, "sharedPrefSec",
                    "Ywn-YM.XK$b:/:&CsL8;=L,y4", true);
            String username = sharedPrefSec.getString("username");
            String password = sharedPrefSec.getString("password");

            final String js = "javascript:" + "document.getElementById('password').value = '" + password + "';"
                    + "document.getElementById('username').value = '" + username + "';"
                    + "var ans = document.getElementsByName('answer');"
                    + "document.getElementById('loginbtn').click()";

            if (Build.VERSION.SDK_INT >= 19) {
                view.evaluateJavascript(js, new ValueCallback<String>() {
                    @Override
                    public void onReceiveValue(String s) {

                    }
                });
            } else {
                view.loadUrl(js);
            }
        }

        @SuppressWarnings("deprecation")
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            final Uri uri = Uri.parse(url);
            return handleUri(uri);
        }

        @TargetApi(Build.VERSION_CODES.N)
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
            final Uri uri = request.getUrl();
            return handleUri(uri);
        }

        private boolean handleUri(final Uri uri) {
            Log.i(TAG, "Uri =" + uri);
            final String url = uri.toString();
            // Based on some condition you need to determine if you are going to load the url
            // in your web view itself or in a browser.
            // You can use `host` or `scheme` or any part of the `uri` to decide.

            if (url.startsWith("http"))
                return false;//open web links as usual
            //try to find browse activity to handle uri
            Uri parsedUri = Uri.parse(url);
            PackageManager packageManager = from.getPackageManager();
            Intent browseIntent = new Intent(Intent.ACTION_VIEW).setData(parsedUri);
            if (browseIntent.resolveActivity(packageManager) != null) {
                from.startActivity(browseIntent);
                return true;
            }
            //if not activity found, try to parse intent://
            if (url.startsWith("intent:")) {
                try {
                    Intent intent = Intent.parseUri(url, Intent.URI_INTENT_SCHEME);
                    if (intent.resolveActivity(from.getPackageManager()) != null) {
                        from.startActivity(intent);
                        return true;
                    }
                    //try to find fallback url
                    String fallbackUrl = intent.getStringExtra("browser_fallback_url");
                    if (fallbackUrl != null) {
                        webView.loadUrl(fallbackUrl);
                        return true;
                    }
                    //invite to install
                    Intent marketIntent = new Intent(Intent.ACTION_VIEW)
                            .setData(Uri.parse("market://details?id=" + intent.getPackage()));
                    if (marketIntent.resolveActivity(packageManager) != null) {
                        from.startActivity(marketIntent);
                        return true;
                    }
                } catch (URISyntaxException e) {
                    //not an intent uri
                }
            }
            return true;//do nothing in other cases
        }
    });
}

From source file:org.creativecommons.thelist.fragments.GalleryFragment.java

@Override
public void onAttach(Activity activity) {
    super.onAttach(activity);

    try {/*  w  w  w .  j  a v  a  2 s .co  m*/
        mCallback = (GalleryListener) activity;
    } catch (ClassCastException e) {
        throw new ClassCastException(
                activity.toString() + activity.getString(R.string.gallery_callback_exception_message));
    }
}

From source file:org.creativecommons.thelist.fragments.AccountFragment.java

@Override
public void onAttach(Activity activity) {
    super.onAttach(activity);

    try {/*w  ww . j a  v a2 s.  c om*/
        mCallback = (AuthListener) activity;
    } catch (ClassCastException e) {
        throw new ClassCastException(
                activity.toString() + activity.getString(R.string.login_callback_exception_message));
    }
}

From source file:de.baumann.browser.helper.helper_main.java

public static void openFilePicker(final Activity activity, final View view, final String startDir) {

    new ChooserDialog().with(activity).withStartFile(startDir).withChosenListener(new ChooserDialog.Result() {
        @Override/*from  w  w  w . ja v a2  s.  com*/
        public void onChoosePath(final File pathFile) {

            final String fileExtension = pathFile.getAbsolutePath()
                    .substring(pathFile.getAbsolutePath().lastIndexOf("."));
            final String fileName = pathFile.getAbsolutePath()
                    .substring(pathFile.getAbsolutePath().lastIndexOf("/") + 1);
            final String fileNameWE = fileName.substring(0, fileName.lastIndexOf("."));

            final CharSequence[] options = { activity.getString(R.string.choose_menu_1),
                    activity.getString(R.string.choose_menu_2), activity.getString(R.string.choose_menu_3),
                    activity.getString(R.string.choose_menu_4) };

            final AlertDialog.Builder dialog = new AlertDialog.Builder(activity);
            dialog.setPositiveButton(R.string.toast_cancel, new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int whichButton) {
                    dialog.cancel();
                }
            });
            dialog.setItems(options, new DialogInterface.OnClickListener() {
                @SuppressWarnings("ResultOfMethodCallIgnored")
                @Override
                public void onClick(DialogInterface dialog, int item) {
                    if (options[item].equals(activity.getString(R.string.choose_menu_1))) {

                        String text = (activity.getString(R.string.toast_extension) + ": " + fileExtension);

                        switch (fileExtension) {
                        case ".gif":
                        case ".bmp":
                        case ".tiff":
                        case ".svg":
                        case ".png":
                        case ".jpg":
                        case ".jpeg":
                            helper_main.openFile(activity, pathFile, "image/*", view);
                            break;
                        case ".m3u8":
                        case ".mp3":
                        case ".wma":
                        case ".midi":
                        case ".wav":
                        case ".aac":
                        case ".aif":
                        case ".amp3":
                        case ".weba":
                            helper_main.openFile(activity, pathFile, "audio/*", view);
                            break;
                        case ".mpeg":
                        case ".mp4":
                        case ".ogg":
                        case ".webm":
                        case ".qt":
                        case ".3gp":
                        case ".3g2":
                        case ".avi":
                        case ".f4v":
                        case ".flv":
                        case ".h261":
                        case ".h263":
                        case ".h264":
                        case ".asf":
                        case ".wmv":
                            helper_main.openFile(activity, pathFile, "video/*", view);
                            break;
                        case ".rtx":
                        case ".csv":
                        case ".txt":
                        case ".vcs":
                        case ".vcf":
                        case ".css":
                        case ".ics":
                        case ".conf":
                        case ".config":
                        case ".java":
                            helper_main.openFile(activity, pathFile, "text/*", view);
                            break;
                        case ".html":
                            helper_main.openFile(activity, pathFile, "text/html", view);
                            break;
                        case ".apk":
                            helper_main.openFile(activity, pathFile, "application/vnd.android.package-archive",
                                    view);
                            break;
                        case ".pdf":
                            helper_main.openFile(activity, pathFile, "application/pdf", view);
                            break;
                        case ".doc":
                            helper_main.openFile(activity, pathFile, "application/msword", view);
                            break;
                        case ".xls":
                            helper_main.openFile(activity, pathFile, "application/vnd.ms-excel", view);
                            break;
                        case ".ppt":
                            helper_main.openFile(activity, pathFile, "application/vnd.ms-powerpoint", view);
                            break;
                        case ".docx":
                            helper_main.openFile(activity, pathFile,
                                    "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
                                    view);
                            break;
                        case ".pptx":
                            helper_main.openFile(activity, pathFile,
                                    "application/vnd.openxmlformats-officedocument.presentationml.presentation",
                                    view);
                            break;
                        case ".xlsx":
                            helper_main.openFile(activity, pathFile,
                                    "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", view);
                            break;
                        case ".odt":
                            helper_main.openFile(activity, pathFile, "application/vnd.oasis.opendocument.text",
                                    view);
                            break;
                        case ".ods":
                            helper_main.openFile(activity, pathFile,
                                    "application/vnd.oasis.opendocument.spreadsheet", view);
                            break;
                        case ".odp":
                            helper_main.openFile(activity, pathFile,
                                    "application/vnd.oasis.opendocument.presentation", view);
                            break;
                        case ".zip":
                            helper_main.openFile(activity, pathFile, "application/zip", view);
                            break;
                        case ".rar":
                            helper_main.openFile(activity, pathFile, "application/x-rar-compressed", view);
                            break;
                        case ".epub":
                            helper_main.openFile(activity, pathFile, "application/epub+zip", view);
                            break;
                        case ".cbz":
                            helper_main.openFile(activity, pathFile, "application/x-cbz", view);
                            break;
                        case ".cbr":
                            helper_main.openFile(activity, pathFile, "application/x-cbr", view);
                            break;
                        case ".fb2":
                            helper_main.openFile(activity, pathFile, "application/x-fb2", view);
                            break;
                        case ".rtf":
                            helper_main.openFile(activity, pathFile, "application/rtf", view);
                            break;
                        case ".opml":
                            helper_main.openFile(activity, pathFile, "application/opml", view);
                            break;

                        default:
                            Toast.makeText(activity, text, Toast.LENGTH_SHORT).show();
                            break;
                        }

                        String dir = pathFile.getParentFile().getAbsolutePath();
                        helper_main.openFilePicker(activity, view, dir);
                    }
                    if (options[item].equals(activity.getString(R.string.choose_menu_2))) {

                        if (pathFile.exists()) {
                            Intent sharingIntent = new Intent(Intent.ACTION_SEND);
                            sharingIntent.setType("image/png");
                            sharingIntent.putExtra(Intent.EXTRA_SUBJECT, fileName);
                            sharingIntent.putExtra(Intent.EXTRA_TEXT, fileName);
                            Uri bmpUri = Uri.fromFile(pathFile);
                            sharingIntent.putExtra(Intent.EXTRA_STREAM, bmpUri);
                            activity.startActivity(Intent.createChooser(sharingIntent,
                                    (activity.getString(R.string.app_share_file))));
                        }
                        String dir = pathFile.getParentFile().getAbsolutePath();
                        helper_main.openFilePicker(activity, view, dir);
                    }
                    if (options[item].equals(activity.getString(R.string.choose_menu_4))) {
                        final AlertDialog.Builder dialog2 = new AlertDialog.Builder(activity);

                        dialog2.setMessage(activity.getString(R.string.choose_delete));
                        dialog2.setPositiveButton(R.string.toast_yes, new DialogInterface.OnClickListener() {

                            public void onClick(DialogInterface dialog, int whichButton) {
                                pathFile.delete();
                                new Handler().postDelayed(new Runnable() {
                                    public void run() {
                                        String dir = pathFile.getParentFile().getAbsolutePath();
                                        helper_main.openFilePicker(activity, view, dir);
                                    }
                                }, 500);
                            }
                        });
                        dialog2.setNegativeButton(R.string.toast_cancel, new DialogInterface.OnClickListener() {

                            public void onClick(DialogInterface dialog, int whichButton) {
                                dialog.cancel();
                            }
                        });
                        dialog2.setOnCancelListener(new DialogInterface.OnCancelListener() {
                            @Override
                            public void onCancel(DialogInterface dialog) {
                                // dialog dismiss without button press
                                String dir = pathFile.getParentFile().getAbsolutePath();
                                helper_main.openFilePicker(activity, view, dir);
                            }
                        });
                        dialog2.show();
                    }
                    if (options[item].equals(activity.getString(R.string.choose_menu_3))) {

                        AlertDialog.Builder builder = new AlertDialog.Builder(activity);
                        View dialogView = View.inflate(activity, R.layout.dialog_edit_file, null);

                        final EditText edit_title = (EditText) dialogView.findViewById(R.id.pass_title);

                        builder.setView(dialogView);
                        builder.setTitle(R.string.choose_title);
                        builder.setPositiveButton(R.string.toast_yes, new DialogInterface.OnClickListener() {

                            public void onClick(DialogInterface dialog, int whichButton) {

                                String inputTag = edit_title.getText().toString().trim();

                                File dir = pathFile.getParentFile();
                                File to = new File(dir, inputTag + fileExtension);

                                pathFile.renameTo(to);
                                pathFile.delete();

                                new Handler().postDelayed(new Runnable() {
                                    public void run() {
                                        String dir = pathFile.getParentFile().getAbsolutePath();
                                        helper_main.openFilePicker(activity, view, dir);
                                    }
                                }, 500);
                            }
                        });
                        builder.setNegativeButton(R.string.toast_cancel, new DialogInterface.OnClickListener() {

                            public void onClick(DialogInterface dialog, int whichButton) {
                                dialog.cancel();
                            }
                        });
                        builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
                            @Override
                            public void onCancel(DialogInterface dialog) {
                                // dialog dismiss without button press
                                String dir = pathFile.getParentFile().getAbsolutePath();
                                helper_main.openFilePicker(activity, view, dir);
                            }
                        });

                        final AlertDialog dialog2 = builder.create();
                        // Display the custom alert dialog on interface
                        dialog2.show();
                        helper_editText.showKeyboard(activity, edit_title, 0, fileNameWE,
                                activity.getString(R.string.choose_hint));
                    }
                }
            });
            dialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
                @Override
                public void onCancel(DialogInterface dialog) {
                    // dialog dismiss without button press
                    String dir = pathFile.getParentFile().getAbsolutePath();
                    helper_main.openFilePicker(activity, view, dir);
                }
            });
            dialog.show();
        }
    }).build().show();
}

From source file:org.creativecommons.thelist.misc.UploadFragment.java

@Override
public void onAttach(Activity activity) {
    super.onAttach(activity);
    try {/*from   w  w w.j ava2s  . c om*/
        mCallback = (UploadListener) activity;
    } catch (ClassCastException e) {
        throw new ClassCastException(
                activity.toString() + activity.getString(R.string.confirm_callback_exception_message));
    }
}

From source file:org.creativecommons.thelist.fragments.NavigationDrawerFragment.java

@Override
public void onAttach(Activity activity) {
    super.onAttach(activity);

    try {/*from w w  w .  j  ava  2s .co m*/
        mCallback = (NavigationDrawerListener) activity;
    } catch (ClassCastException e) {
        throw new ClassCastException(
                activity.toString() + activity.getString(R.string.R_string_drawer_callback_exception_message));
    }
}