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.android.browser.DownloadHandler.java

private static void onDownloadNoStreamImpl(Activity activity, String url, String userAgent,
        String contentDisposition, String mimetype, String referer, boolean privateBrowsing) {

    String filename = URLUtil.guessFileName(url, contentDisposition, mimetype);

    // Check to see if we have an SDCard
    String status = Environment.getExternalStorageState();
    if (!status.equals(Environment.MEDIA_MOUNTED)) {
        int title;
        String msg;//  w  w w. j  a  va  2  s . co  m

        // Check to see if the SDCard is busy, same as the music app
        if (status.equals(Environment.MEDIA_SHARED)) {
            msg = activity.getString(R.string.download_sdcard_busy_dlg_msg);
            title = R.string.download_sdcard_busy_dlg_title;
        } else {
            msg = activity.getString(R.string.download_no_sdcard_dlg_msg, filename);
            title = R.string.download_no_sdcard_dlg_title;
        }

        new AlertDialog.Builder(activity).setTitle(title).setIconAttribute(android.R.attr.alertDialogIcon)
                .setMessage(msg).setPositiveButton(R.string.ok, null).show();
        return;
    }

    // java.net.URI is a lot stricter than KURL so we have to encode some
    // extra characters. Fix for b 2538060 and b 1634719
    WebAddress webAddress;
    try {
        webAddress = new WebAddress(url);
        webAddress.setPath(encodePath(webAddress.getPath()));
    } catch (Exception e) {
        // This only happens for very bad urls, we want to chatch the
        // exception here
        Log.e(LOGTAG, "Exception trying to parse url:" + url);
        return;
    }

    String addressString = webAddress.toString();
    Uri uri = Uri.parse(addressString);
    final DownloadManager.Request request;
    try {
        request = new DownloadManager.Request(uri);
    } catch (IllegalArgumentException e) {
        Toast.makeText(activity, R.string.cannot_download, Toast.LENGTH_SHORT).show();
        return;
    }
    request.setMimeType(mimetype);
    // set downloaded file destination to /sdcard/Download.
    // or, should it be set to one of several Environment.DIRECTORY* dirs depending on mimetype?
    try {
        request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, filename);
    } catch (IllegalStateException ex) {
        // This only happens when directory Downloads can't be created or it isn't a directory
        // this is most commonly due to temporary problems with sdcard so show appropriate string
        Log.w(LOGTAG, "Exception trying to create Download dir:", ex);
        Toast.makeText(activity, R.string.download_sdcard_busy_dlg_title, Toast.LENGTH_SHORT).show();
        return;
    }
    // let this downloaded file be scanned by MediaScanner - so that it can
    // show up in Gallery app, for example.
    request.allowScanningByMediaScanner();
    request.setDescription(webAddress.getHost());
    // XXX: Have to use the old url since the cookies were stored using the
    // old percent-encoded url.
    String cookies = CookieManager.getInstance().getCookie(url, privateBrowsing);
    request.addRequestHeader("cookie", cookies);
    request.addRequestHeader("User-Agent", userAgent);
    if (!TextUtils.isEmpty(referer)) {
        request.addRequestHeader("Referer", referer);
    }
    request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
    if (mimetype == null) {
        if (TextUtils.isEmpty(addressString)) {
            return;
        }
        // We must have long pressed on a link or image to download it. We
        // are not sure of the mimetype in this case, so do a head request
        new FetchUrlMimeType(activity, request, addressString, cookies, userAgent).start();
    } else {
        final DownloadManager manager = (DownloadManager) activity.getSystemService(Context.DOWNLOAD_SERVICE);
        new Thread("Browser download") {
            public void run() {
                manager.enqueue(request);
            }
        }.start();
    }
    Toast.makeText(activity, R.string.download_pending, Toast.LENGTH_SHORT).show();
}

From source file:com.sabaibrowser.DownloadHandler.java

private static void onDownloadNoStreamImpl(Activity activity, String url, String userAgent,
        String contentDisposition, String mimetype, String referer, boolean privateBrowsing) {

    String filename = URLUtil.guessFileName(url, contentDisposition, mimetype);

    // Check to see if we have an SDCard
    String status = Environment.getExternalStorageState();
    if (!status.equals(Environment.MEDIA_MOUNTED)) {
        int title;
        String msg;/*from  w ww . j a  v a 2 s  . co  m*/

        // Check to see if the SDCard is busy, same as the music app
        if (status.equals(Environment.MEDIA_SHARED)) {
            msg = activity.getString(R.string.download_sdcard_busy_dlg_msg);
            title = R.string.download_sdcard_busy_dlg_title;
        } else {
            msg = activity.getString(R.string.download_no_sdcard_dlg_msg, filename);
            title = R.string.download_no_sdcard_dlg_title;
        }

        new AlertDialog.Builder(activity).setTitle(title).setIconAttribute(android.R.attr.alertDialogIcon)
                .setMessage(msg).setPositiveButton(R.string.ok, null).show();
        return;
    }

    // java.net.URI is a lot stricter than KURL so we have to encode some
    // extra characters. Fix for b 2538060 and b 1634719
    WebAddress webAddress;
    try {
        webAddress = new WebAddress(url);
        webAddress.setPath(encodePath(webAddress.getPath()));
    } catch (Exception e) {
        // This only happens for very bad urls, we want to chatch the
        // exception here
        Log.e(LOGTAG, "Exception trying to parse url:" + url);
        return;
    }

    String addressString = webAddress.toString();
    Uri uri = Uri.parse(addressString);
    final DownloadManager.Request request;
    try {
        request = new DownloadManager.Request(uri);
    } catch (IllegalArgumentException e) {
        Toast.makeText(activity, R.string.cannot_download, Toast.LENGTH_SHORT).show();
        return;
    }
    request.setMimeType(mimetype);
    // set downloaded file destination to /sdcard/Download.
    // or, should it be set to one of several Environment.DIRECTORY* dirs depending on mimetype?
    try {
        request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, filename);
    } catch (IllegalStateException ex) {
        // This only happens when directory Downloads can't be created or it isn't a directory
        // this is most commonly due to temporary problems with sdcard so show appropriate string
        Log.w(LOGTAG, "Exception trying to create Download dir:", ex);
        Toast.makeText(activity, R.string.download_sdcard_busy_dlg_title, Toast.LENGTH_SHORT).show();
        return;
    }
    // let this downloaded file be scanned by MediaScanner - so that it can
    // show up in Gallery app, for example.
    request.allowScanningByMediaScanner();
    request.setDescription(webAddress.getHost());
    // XXX: Have to use the old url since the cookies were stored using the
    // old percent-encoded url.
    String cookies = privateBrowsing ? "" : CookieManager.getInstance().getCookie(url);
    request.addRequestHeader("cookie", cookies);
    request.addRequestHeader("User-Agent", userAgent);
    if (!TextUtils.isEmpty(referer)) {
        request.addRequestHeader("Referer", referer);
    }
    request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
    if (mimetype == null) {
        if (TextUtils.isEmpty(addressString)) {
            return;
        }
        // We must have long pressed on a link or image to download it. We
        // are not sure of the mimetype in this case, so do a head request
        new FetchUrlMimeType(activity, request, addressString, cookies, userAgent).start();
    } else {
        final DownloadManager manager = (DownloadManager) activity.getSystemService(Context.DOWNLOAD_SERVICE);
        new Thread("Browser download") {
            public void run() {
                manager.enqueue(request);
            }
        }.start();
    }
    Toast.makeText(activity, R.string.download_pending, Toast.LENGTH_SHORT).show();
}

From source file:io.digibyte.tools.animation.BRAnimator.java

public static void openScanner(Activity app, int requestID) {
    try {// w ww  . j av a2  s. c o m
        if (app == null)
            return;

        // Check if the camera permission is granted
        if (ContextCompat.checkSelfPermission(app,
                Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
            // Should we show an explanation?
            if (ActivityCompat.shouldShowRequestPermissionRationale(app, Manifest.permission.CAMERA)) {
                BRDialog.showCustomDialog(app, app.getString(R.string.Send_cameraUnavailabeTitle_android),
                        app.getString(R.string.Send_cameraUnavailabeMessage_android),
                        app.getString(R.string.AccessibilityLabels_close), null,
                        new BRDialogView.BROnClickListener() {
                            @Override
                            public void onClick(BRDialogView brDialogView) {
                                brDialogView.dismiss();
                            }
                        }, null, null, 0);
            } else {
                // No explanation needed, we can request the permission.
                ActivityCompat.requestPermissions(app, new String[] { Manifest.permission.CAMERA },
                        BRConstants.CAMERA_REQUEST_ID);
            }
        } else {
            // Permission is granted, open camera
            Intent intent = new Intent(app, ScanQRActivity.class);
            app.startActivityForResult(intent, requestID);
            app.overridePendingTransition(R.anim.fade_up, R.anim.fade_down);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

}

From source file:com.shareyourproxy.IntentLauncher.java

/**
 * Launch an Intent chooser dialog for a Proxy User to select a method of sharing a profile
 * link. The link is an http address to a User's group channels.
 *
 * @param event message data, http link/* ww w  . ja  v  a2s  . c  o  m*/
 */
public static void launchShareLinkIntent(Activity activity, ShareLinkEvent event) {
    Intent[] copyAndPaste = new Intent[] { getClipboardIntent(event.message) };
    Intent chooser = createChooser(getShareLinkIntent(event.message),
            activity.getString(R.string.dialog_sharelink_title)).putExtra(EXTRA_INITIAL_INTENTS, copyAndPaste);

    activity.startActivity(chooser);
}

From source file:com.shareyourproxy.IntentLauncher.java

/**
 * View Invite friends/*from  w  w  w . ja  v a  2s  . co m*/
 *
 * @param activity context
 */
public static void launchInviteFriendIntent(Activity activity) {
    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setType("text/plain");
    intent.putExtra(Intent.EXTRA_SUBJECT, activity.getString(R.string.share_your_proxy));
    intent.putExtra(Intent.EXTRA_TEXT, activity.getString(R.string.invite_friend_content));
    if (intent.resolveActivity(activity.getPackageManager()) != null) {
        activity.startActivity(createChooser(intent, activity.getString(R.string.invite_a_friend)));
    }
}

From source file:org.catrobat.catroid.utils.UtilMerge.java

private static boolean checkMergeConflicts(Project featureA, Project featureB, Activity activity) {
    boolean fail = false;
    boolean first = true;
    String msg = "";

    for (Sprite spriteA : featureA.getSpriteList().subList(1, featureA.getSpriteList().size())) {
        for (Sprite spriteB : featureB.getSpriteList().subList(1, featureB.getSpriteList().size())) {
            if (spriteA.getName().equalsIgnoreCase(spriteB.getName())) {

                if (first) {
                    first = false;/*  w ww .  java  2s  .  c  om*/
                    msg += activity.getString(R.string.error_merge_duplicate_names) + "\n\n";
                    msg += activity.getString(R.string.sprite) + ":\n";
                }
                msg += "    " + spriteA.getName() + "\n";
            }
        }
    }

    if (!first) {
        first = true;
        msg += "\n";
    }

    for (UserVariable variableA : featureA.getDataContainer().getProjectVariables()) {
        for (UserVariable variableB : featureB.getDataContainer().getProjectVariables()) {
            if (variableA.getName().equalsIgnoreCase(variableB.getName())) {
                if (first) {
                    first = false;
                    msg += activity.getString(R.string.variable) + ":\n";
                }
                msg += "    " + variableA.getName() + "\n";
            }
        }
    }

    if (!first) {
        first = true;
        msg += "\n";
    }

    List<String> mergeToBroadcastNames = getAllBroadcastNames(featureA);
    List<String> mergeFromBroadcastNames = getAllBroadcastNames(featureB);

    if (!mergeToBroadcastNames.isEmpty()) {
        for (String nameTo : mergeToBroadcastNames) {
            for (String nameFrom : mergeFromBroadcastNames) {
                if (nameTo.equals(nameFrom)) {
                    if (first) {
                        first = false;
                        msg += activity.getString(R.string.broadcast) + ":\n";
                    }
                    msg += "    " + nameTo + "\n";
                }
            }
        }
    }

    if (!first) {
        first = true;
        msg += "\n";
    }

    for (UserList listA : featureA.getDataContainer().getProjectLists()) {
        for (UserList listB : featureB.getDataContainer().getProjectLists()) {
            if (listA.getName().equals(listB.getName())) {
                if (first) {
                    first = false;
                    msg += activity.getString(R.string.project_list) + ":\n";
                }
                msg += "    " + listA.getName() + "\n";
            }
        }
    }

    if (!msg.isEmpty()) {
        Utils.showErrorDialog(activity, msg, R.string.merge_conflict);
        fail = true;
    }
    return fail;
}

From source file:com.iStudy.Study.Renren.Util.java

/**
 * ??????//from  w w w .  ja va2s.  c  o m
 * 
 * @param activity ?Activity
 * @param title   ?
 * @param text   ?
 * @param listener ?
 */
public static void showOptionWindow(Activity activity, String title, String text, OnOptionListener listener) {
    AlertDialog dialog = new AlertDialog.Builder(activity).create();
    if (title != null) {
        dialog.setTitle(title);
    }

    if (text != null) {
        dialog.setMessage(text);
    }

    final OnOptionListener oListener = listener;
    dialog.setButton(AlertDialog.BUTTON_POSITIVE, activity.getString(R.string.renren_sdk_submit),
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    oListener.onOK();
                }
            });
    dialog.setButton(AlertDialog.BUTTON_NEGATIVE, activity.getString(R.string.renren_sdk_cancel),
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    oListener.onCancel();
                }
            });
    dialog.show();
}

From source file:com.upnext.blekit.BLEKit.java

/**
 * Checks whether Bluetooth LE is available on the device and Bluetooth turned on.
 *
 * If BLE is not supported, then a dialog with appropriate message is shown.
 * If BLE is supported, but Bluetooth is not turned on then a dialog with message is shown and an option to go directly to settings and turn Bluetooth on.
 *
 * A good place to invoke this method would be onResume() in your Activity.
 *
 * @param activity Activity/*from   w  w w.  java 2 s  .  c  o m*/
 * @return false if BLE is not supported or Bluetooth not turned on; otherwise true
 */
public static boolean checkAvailability(Activity activity) {
    if (!activity.getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) {
        showErrorDialog(activity.getString(R.string.blekit_ble_unsupported), activity, true);
    } else {
        if (((BluetoothManager) activity.getSystemService(Context.BLUETOOTH_SERVICE)).getAdapter()
                .isEnabled()) {
            return true;
        }
        showErrorDialog(activity.getString(R.string.blekit_bt_not_on), activity, false);
    }
    return false;
}

From source file:org.liberty.android.fantastischmemo.utils.AMGUIUtility.java

public static void doProgressTask(final Activity activity, final String progressTitle,
        final String progressMessage, final ProgressTask task) {
    final ProgressDialog mProgressDialog = ProgressDialog.show(activity, progressTitle, progressMessage, true);
    final Handler handler = new Handler();
    new Thread() {
        public void run() {
            try {
                task.doHeavyTask();/*from  w ww.ja  v a 2s  . c  om*/
                handler.post(new Runnable() {
                    public void run() {
                        task.doUITask();
                        mProgressDialog.dismiss();
                    }
                });
            } catch (final Exception e) {
                handler.post(new Runnable() {
                    public void run() {
                        mProgressDialog.dismiss();
                        displayException(activity, activity.getString(R.string.exception_text),
                                activity.getString(R.string.exception_message), e);
                        Log.e(TAG, "Error running progress task", e);
                    }
                });
            }
        }
    }.start();
}

From source file:dentex.youtube.downloader.utils.Utils.java

public static void notifyFfmpegNotInstalled(final Activity act) {
    Utils.logger("w", "FFmpeg not installed/enabled", DEBUG_TAG);
    BugSenseHandler.leaveBreadcrumb("notifyFfmpegNotInstalled");
    AlertDialog.Builder adb = new AlertDialog.Builder(act);
    adb.setTitle(act.getString(R.string.ffmpeg_not_enabled_title));
    adb.setMessage(act.getString(R.string.ffmpeg_not_enabled_msg));

    adb.setPositiveButton("OK", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            act.startActivity(new Intent(act, SettingsActivity.class));
        }//from w  w  w .j  a  va 2  s. c  o  m
    });

    adb.setNegativeButton(act.getString(R.string.dialogs_negative), new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            // cancel
        }
    });

    if (!act.isFinishing()) {
        adb.show();
    }
}