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:com.microsoft.onedrive.apiexplorer.ItemFragment.java

/**
 * Creates a folder//  w  w  w. j a v a 2  s .c  o m
 * @param item The parent of the folder to create
 */
private void createFolder(final Item item) {
    final Activity activity = getActivity();
    final EditText newName = new EditText(activity);
    newName.setInputType(InputType.TYPE_CLASS_TEXT);
    newName.setHint(activity.getString(R.string.new_folder_hint));

    final AlertDialog alertDialog = new AlertDialog.Builder(activity).setTitle(R.string.create_folder)
            .setView(newName).setIcon(android.R.drawable.ic_menu_add)
            .setPositiveButton(R.string.create_folder, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(final DialogInterface dialog, final int which) {
                    final ICallback<Item> callback = new DefaultCallback<Item>(activity) {
                        @Override
                        public void success(final Item createdItem) {
                            Toast.makeText(activity,
                                    activity.getString(R.string.created_folder, createdItem.name, item.name),
                                    Toast.LENGTH_LONG).show();
                            refresh();
                            dialog.dismiss();
                        }

                        @Override
                        public void failure(final ClientException error) {
                            super.failure(error);
                            Toast.makeText(activity, activity.getString(R.string.new_folder_error, item.name),
                                    Toast.LENGTH_LONG).show();
                            dialog.dismiss();
                        }
                    };

                    final Item newItem = new Item();
                    newItem.name = newName.getText().toString();
                    newItem.folder = new Folder();

                    ((BaseApplication) activity.getApplication()).getOneDriveClient().getDrive()
                            .getItems(mItemId).getChildren().buildRequest().create(newItem, callback);
                }
            }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(final DialogInterface dialog, final int which) {
                    dialog.cancel();
                }
            }).create();
    alertDialog.show();
}

From source file:com.nextgis.mobile.util.ApkDownloader.java

public static void check(final Activity activity, final boolean showToast) {
    final String token = PreferenceManager.getDefaultSharedPreferences(activity)
            .getString(NGIDUtils.PREF_ACCESS_TOKEN, "");
    if (showToast && TextUtils.isEmpty(token)) {
        Toast.makeText(activity, R.string.error_401, Toast.LENGTH_SHORT).show();
        activity.finish();//  w w  w.  j  ava2 s. c  om
        return;
    }

    NGIDUtils.get(activity, SettingsConstants.APK_VERSION_UPDATE, new NGIDUtils.OnFinish() {
        @Override
        public void onFinish(String data) {
            if (data != null) {
                try {
                    JSONObject json = new JSONObject(data);
                    if (json.getInt("versionCode") <= BuildConfig.VERSION_CODE) {
                        if (showToast) {
                            Toast.makeText(activity, R.string.update_no, Toast.LENGTH_SHORT).show();
                            activity.finish();
                        }
                        return;
                    }

                    // there is new version, create download dialog
                    final String url = json.getString("path");
                    DialogInterface.OnClickListener dcl = new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int button) {
                            if (button == DialogInterface.BUTTON_POSITIVE)
                                new ApkDownloader(activity, showToast).execute(url, token);
                            else if (showToast)
                                activity.finish();
                        }
                    };

                    AlertDialog.Builder adb = new AlertDialog.Builder(activity);
                    String update = String.format(activity.getString(R.string.update_new),
                            json.getString("versionName"));
                    adb.setMessage(update).setTitle(R.string.update_title).setPositiveButton(R.string.yes, dcl)
                            .setNegativeButton(R.string.no, dcl).show();
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        }
    });
}

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

public static void onClose(final Activity activity) {
    PreferenceManager.setDefaultValues(activity, R.xml.user_settings, false);
    sharedPref = PreferenceManager.getDefaultSharedPreferences(activity);
    final ProgressDialog progressDialog;

    if (sharedPref.getBoolean("backup_aut", false)) {

        try {/*from   w w  w. j  a  v  a 2 s.  c  o m*/
            helper_security.encryptBackup(activity, "/bookmarks_DB_v01.db");
        } catch (Exception e) {
            e.printStackTrace();
        }
        try {
            helper_security.encryptBackup(activity, "/courses_DB_v01.db");
        } catch (Exception e) {
            e.printStackTrace();
        }
        try {
            helper_security.encryptBackup(activity, "/notes_DB_v01.db");
        } catch (Exception e) {
            e.printStackTrace();
        }
        try {
            helper_security.encryptBackup(activity, "/random_DB_v01.db");
        } catch (Exception e) {
            e.printStackTrace();
        }
        try {
            helper_security.encryptBackup(activity, "/subject_DB_v01.db");
        } catch (Exception e) {
            e.printStackTrace();
        }
        try {
            helper_security.encryptBackup(activity, "/schedule_DB_v01.db");
        } catch (Exception e) {
            e.printStackTrace();
        }
        try {
            helper_security.encryptBackup(activity, "/todo_DB_v01.db");
        } catch (Exception e) {
            e.printStackTrace();
        }

        progressDialog = new ProgressDialog(activity);
        progressDialog.setMessage(activity.getString(R.string.app_close));
        progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
        progressDialog.show();

        new Handler().postDelayed(new Runnable() {
            public void run() {
                sharedPref.edit().putString("loadURL", "").apply();
                helper_security.encryptDatabases(activity);
                if (progressDialog.isShowing()) {
                    progressDialog.cancel();
                }
                activity.finishAffinity();
            }
        }, 1500);

    } else {
        sharedPref.edit().putString("loadURL", "").apply();
        helper_security.encryptDatabases(activity);
        activity.finishAffinity();
    }
}

From source file:de.schramke.android.navdrawer.NavigationDrawer.java

public NavigationDrawer(Activity activity) throws IllegalArgumentException {
    this.activity = activity;
    this.drawerLayout = (DrawerLayout) activity.findViewById(R.id.drawer_layout);
    this.drawerList = (ListView) activity.findViewById(R.id.drawer_list);

    listeners = new HashSet<NavigationDrawerListener>();
    itemListeners = new HashSet<NavigationDrawerItemListener>();
    internListeners = new HashSet<DrawerLayout.DrawerListener>();

    if (activity instanceof NavigationDrawerListener) {
        listeners.add((NavigationDrawerListener) activity);
    }//from  w ww. j av a2s  . com

    if (activity instanceof NavigationDrawerItemListener) {
        itemListeners.add((NavigationDrawerItemListener) activity);
    }

    if (this.drawerLayout == null) {
        final String errerMsg = activity.getString(R.string.exception_drawer_layout);
        throw new IllegalArgumentException(errerMsg);
    }

    if (this.drawerList == null) {
        final String errerMsg = activity.getString(R.string.exception_drawer_list);
        throw new IllegalArgumentException(errerMsg);
    }

    this.drawerLayout.setDrawerListener(this);
    this.drawerList.setOnItemClickListener(this);
    this.drawerList.setOnItemLongClickListener(this);
    this.drawerList.setOnItemSelectedListener(this);
    this.drawerLayout.closeDrawers();

    this.drawerMenu = new android.support.v7.internal.view.menu.MenuBuilder(activity);
    if (activity instanceof NavigationDrawerCreateListener) {
        ((NavigationDrawerCreateListener) activity).onCreateNavigationDrawerMenu(drawerMenu);
    }

    this.drawerList.setAdapter(new NavDrawerAdapter());
}

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

@SuppressLint("SetJavaScriptEnabled")
public static void webView_Settings(final Activity from, final WebView webView) {

    SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(from);
    String fontSizeST = sharedPref.getString("font", "100");
    int fontSize = Integer.parseInt(fontSizeST);

    webView.getSettings().setAppCachePath(from.getApplicationContext().getCacheDir().getAbsolutePath());
    webView.getSettings().setAppCacheEnabled(true);
    webView.getSettings().setMixedContentMode(MIXED_CONTENT_COMPATIBILITY_MODE);
    webView.getSettings().setAllowFileAccess(true);
    webView.getSettings().setAllowContentAccess(true);
    webView.getSettings().setBuiltInZoomControls(true);
    webView.getSettings().setDisplayZoomControls(false);
    webView.getSettings().setDomStorageEnabled(true);
    webView.getSettings().setTextZoom(fontSize);
    webView.getSettings().setLayoutAlgorithm(WebSettings.LayoutAlgorithm.TEXT_AUTOSIZING);
    webView.getSettings().setUseWideViewPort(true);
    webView.getSettings().setLoadWithOverviewMode(true);

    from.registerForContextMenu(webView);

    if (sharedPref.getString("nav", "2").equals("1") || sharedPref.getString("nav", "2").equals("3")) {
        helper_webView.webView_Touch(from, webView);
    }//from w w  w  . j a  v a  2  s. c  om

    if (sharedPref.getString("cookie", "1").equals("2") || sharedPref.getString("cookie", "1").equals("3")) {
        CookieManager cookieManager = CookieManager.getInstance();
        cookieManager.setAcceptThirdPartyCookies(webView, true);
    } else {
        CookieManager cookieManager = CookieManager.getInstance();
        cookieManager.setAcceptThirdPartyCookies(webView, false);
    }

    if (sharedPref.getString("started", "").equals("yes")) {
        if (sharedPref.getString("java_string", "True").equals(from.getString(R.string.app_yes))) {
            webView.getSettings().setJavaScriptEnabled(true);
            sharedPref.edit().putString("java_string", from.getString(R.string.app_yes)).apply();
        } else {
            webView.getSettings().setJavaScriptEnabled(false);
            sharedPref.edit().putString("java_string", from.getString(R.string.app_no)).apply();
        }

        if (sharedPref.getString("pictures_string", "True").equals(from.getString(R.string.app_yes))) {
            webView.getSettings().setLoadsImagesAutomatically(true);
            sharedPref.edit().putString("pictures_string", from.getString(R.string.app_yes)).apply();
        } else {
            webView.getSettings().setLoadsImagesAutomatically(false);
            sharedPref.edit().putString("pictures_string", from.getString(R.string.app_no)).apply();
        }

        if (sharedPref.getString("loc_string", "True").equals(from.getString(R.string.app_yes))) {
            webView.getSettings().setGeolocationEnabled(true);
            helper_main.grantPermissionsLoc(from);
            sharedPref.edit().putString("loc_string", from.getString(R.string.app_yes)).apply();
        } else {
            webView.getSettings().setGeolocationEnabled(false);
            sharedPref.edit().putString("loc_string", from.getString(R.string.app_no)).apply();
        }

        if (sharedPref.getString("cookie_string", "True").equals(from.getString(R.string.app_yes))) {
            CookieManager cookieManager = CookieManager.getInstance();
            cookieManager.setAcceptCookie(true);
            sharedPref.edit().putString("cookie_string", from.getString(R.string.app_yes)).apply();
        } else {
            CookieManager cookieManager = CookieManager.getInstance();
            cookieManager.setAcceptCookie(false);
            sharedPref.edit().putString("cookie_string", from.getString(R.string.app_no)).apply();
        }
    } else {
        if (sharedPref.getBoolean("java", false)) {
            webView.getSettings().setJavaScriptEnabled(true);
            sharedPref.edit().putString("java_string", from.getString(R.string.app_yes)).apply();
        } else {
            webView.getSettings().setJavaScriptEnabled(false);
            sharedPref.edit().putString("java_string", from.getString(R.string.app_no)).apply();
        }

        if (sharedPref.getBoolean("pictures", false)) {
            webView.getSettings().setLoadsImagesAutomatically(true);
            sharedPref.edit().putString("pictures_string", from.getString(R.string.app_yes)).apply();
        } else {
            webView.getSettings().setLoadsImagesAutomatically(false);
            sharedPref.edit().putString("pictures_string", from.getString(R.string.app_no)).apply();
        }

        if (sharedPref.getBoolean("loc", false)) {
            webView.getSettings().setGeolocationEnabled(true);
            helper_main.grantPermissionsLoc(from);
            sharedPref.edit().putString("loc_string", from.getString(R.string.app_yes)).apply();
        } else {
            webView.getSettings().setGeolocationEnabled(false);
            sharedPref.edit().putString("loc_string", from.getString(R.string.app_no)).apply();
        }

        if (sharedPref.getString("cookie", "1").equals("1")
                || sharedPref.getString("cookie", "1").equals("3")) {
            CookieManager cookieManager = CookieManager.getInstance();
            cookieManager.setAcceptCookie(true);
            sharedPref.edit().putString("cookie_string", from.getString(R.string.app_yes)).apply();
        } else {
            CookieManager cookieManager = CookieManager.getInstance();
            cookieManager.setAcceptCookie(false);
            sharedPref.edit().putString("cookie_string", from.getString(R.string.app_no)).apply();
        }
    }
}

From source file:net.tjado.passwdsafe.PasswdSafeOpenFileFragment.java

public void resetOverflowButton(final Activity activity) {
    final String overflowDescription = activity.getString(R.string.abc_action_menu_overflow_description);
    final ViewGroup decorView = (ViewGroup) activity.getWindow().getDecorView();
    final ViewTreeObserver viewTreeObserver = decorView.getViewTreeObserver();
    viewTreeObserver.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @Override/*from w  w  w.  j  a v a  2 s  .c om*/
        public void onGlobalLayout() {
            final ArrayList<View> outViews = new ArrayList<View>();
            decorView.findViewsWithText(outViews, overflowDescription,
                    View.FIND_VIEWS_WITH_CONTENT_DESCRIPTION);
            if (outViews.isEmpty()) {
                return;
            }
            AppCompatImageView overflow = (AppCompatImageView) outViews.get(0);

            overflow.setImageDrawable(itsOriginalDrawable);
            removeOnGlobalLayoutListener(decorView, this);
        }
    });
}

From source file:net.tjado.passwdsafe.PasswdSafeOpenFileFragment.java

public void setOverflowButton(final Activity activity) {
    final String overflowDescription = activity.getString(R.string.abc_action_menu_overflow_description);
    final ViewGroup decorView = (ViewGroup) activity.getWindow().getDecorView();
    final ViewTreeObserver viewTreeObserver = decorView.getViewTreeObserver();
    viewTreeObserver.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @Override//from w w w.ja  v  a2 s.  c  om
        public void onGlobalLayout() {
            final ArrayList<View> outViews = new ArrayList<View>();
            decorView.findViewsWithText(outViews, overflowDescription,
                    View.FIND_VIEWS_WITH_CONTENT_DESCRIPTION);
            if (outViews.isEmpty()) {
                return;
            }
            AppCompatImageView overflow = (AppCompatImageView) outViews.get(0);

            itsOriginalDrawable = overflow.getDrawable();

            overflow.setImageDrawable(PasswdSafeUtil.scaleImage(
                    activity.getResources().getDrawable(R.drawable.icon_yubico), 0.09f, getResources()));
            overflow.setColorFilter(activity.getResources().getColor(R.color.menu_icon_color));
            removeOnGlobalLayoutListener(decorView, this);
        }
    });
}

From source file:com.android.launcher3.Utilities.java

public static void openStatusBar(Activity activity) {
    if (Utilities.doCheckPROVersion(activity)) {

    } else {/*  w  ww  .j av  a 2  s.c o  m*/
        Toast.makeText(activity, activity.getString(R.string.not_allow), Toast.LENGTH_LONG).show();
    }
}

From source file:com.microsoft.onedrive.apiexplorer.ItemFragment.java

/**
 * Downloads this item//from w w  w.  jav a 2 s .  co  m
 * @param item The item to download
 */
private void download(final Item item) {
    final Activity activity = getActivity();
    final DownloadManager downloadManager = (DownloadManager) activity
            .getSystemService(Context.DOWNLOAD_SERVICE);
    final String downloadUrl = item.getRawObject().get("@content.downloadUrl").getAsString();
    final DownloadManager.Request request = new DownloadManager.Request(Uri.parse(downloadUrl));
    request.setTitle(item.name);
    request.setDescription(activity.getString(R.string.file_from_onedrive));
    request.allowScanningByMediaScanner();
    if (item.file != null) {
        request.setMimeType(item.file.mimeType);
    }
    request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
    downloadManager.enqueue(request);
    Toast.makeText(activity, activity.getString(R.string.starting_download_message), Toast.LENGTH_LONG).show();
}

From source file:com.gigigo.vuforia.core.sdkimagerecognition.cloudrecognition.CloudRecognition.java

public void showErrorMessage(int errorCode, double errorTime, boolean finishActivityOnError) {
    //you can change for show or hidden the vuforia error messages
    if (bShowErrorMessages) {
        if (errorTime < (mLastErrorTime + 5.0) || errorCode == mlastErrorCode)
            return;

        mlastErrorCode = errorCode;/*  w  w  w  .  j a  v  a  2 s.c om*/
        mFinishActivityOnError = finishActivityOnError;

        final Activity activity = this.mActivity;

        this.mActivity.runOnUiThread(new Runnable() {
            public void run() {
                if (mErrorDialog != null) {
                    mErrorDialog.dismiss();
                }

                // Generates an Alert Dialog to show the error message
                AlertDialog.Builder builder = new AlertDialog.Builder(activity);
                builder.setMessage(getStatusDescString(CloudRecognition.this.mlastErrorCode))
                        .setTitle(getStatusTitleString(CloudRecognition.this.mlastErrorCode))
                        .setCancelable(false).setIcon(0).setPositiveButton(
                                activity.getString(R.string.button_OK), new DialogInterface.OnClickListener() {
                                    public void onClick(DialogInterface dialog, int id) {
                                        if (mFinishActivityOnError) {
                                            activity.finish();
                                        } else {
                                            dialog.dismiss();
                                        }
                                    }
                                });

                mErrorDialog = builder.create();
                mErrorDialog.show();
            }
        });
    }
}