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.rks.musicx.misc.utils.Sleeptimer.java

public static void showSleepTimer(Activity c) {
    View view = LayoutInflater.from(c).inflate(R.layout.sleeptimer, null);
    mcircularSeekBar = (CircularSeekBar) view.findViewById(R.id.timer_circle);
    mSeekArcProgress = (TextView) view.findViewById(R.id.timer_progress);
    final String start = c.getString(R.string.start);
    final String cancel = c.getString(R.string.cancel);
    ateKey = Helper.getATEKey(c);//from   w w  w  . j a v a 2 s  .  c  om
    accentColor = Config.accentColor(c, ateKey);
    int primary = Config.primaryColor(c, ateKey);
    if (Extras.getInstance().getDarkTheme() || Extras.getInstance().getBlackTheme()) {
        mcircularSeekBar.setPointerHaloColor(accentColor);
        mcircularSeekBar.setCircleProgressColor(accentColor);
        mcircularSeekBar.setPointerHaloColor(accentColor);
        mSeekArcProgress.setTextColor(ContextCompat.getColor(c, R.color.white));
    } else {
        mcircularSeekBar.setPointerHaloColor(accentColor);
        mcircularSeekBar.setCircleProgressColor(accentColor);
        mSeekArcProgress.setTextColor(ContextCompat.getColor(c, R.color.colorPrimaryText));
        mcircularSeekBar.setCircleColor(primary);
    }
    mcircularSeekBar.setOnSeekBarChangeListener(new CircularSeekBar.OnCircularSeekBarChangeListener() {
        @Override
        public void onProgressChanged(CircularSeekBar circularSeekBar, int progress, boolean fromUser) {
            String minute;
            if (progress < 10) {
                minute = c.getString(R.string.minute);
            } else {
                minute = c.getString(minutes);
            }
            String temps = String.valueOf(progress) + " " + minute;
            mSeekArcProgress.setText(temps);
        }

        @Override
        public void onStopTrackingTouch(CircularSeekBar seekBar) {

        }

        @Override
        public void onStartTrackingTouch(CircularSeekBar seekBar) {

        }
    });
    MaterialDialog.Builder sleeptimer = new MaterialDialog.Builder(c);
    sleeptimer.title("SleepTimer");
    sleeptimer.positiveText(start);
    sleeptimer.onPositive(new MaterialDialog.SingleButtonCallback() {
        @Override
        public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
            int mins = mcircularSeekBar.getProgress();
            startTimer(view, mins, c);
        }
    });
    sleeptimer.negativeText(cancel);
    sleeptimer.onNegative(new MaterialDialog.SingleButtonCallback() {
        @Override
        public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
            sleeptimer.autoDismiss(true);
        }
    });
    sleeptimer.customView(view, false);
    sleeptimer.show();
}

From source file:com.todoroo.astrid.actfm.ActFmCameraModule.java

public static void showPictureLauncher(final Activity activity, final ClearImageCallback clearImageOption) {
    ArrayList<String> options = new ArrayList<String>();

    final Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    PackageManager pm = activity.getPackageManager();

    final boolean cameraAvailable = pm.queryIntentActivities(cameraIntent, 0).size() > 0;
    if (cameraAvailable)
        options.add(activity.getString(R.string.actfm_picture_camera));
    options.add(activity.getString(R.string.actfm_picture_gallery));

    if (clearImageOption != null)
        options.add(activity.getString(R.string.actfm_picture_clear));

    ArrayAdapter<String> adapter = new ArrayAdapter<String>(activity,
            android.R.layout.simple_spinner_dropdown_item, options.toArray(new String[options.size()]));

    DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() {
        @SuppressWarnings("nls")
        @Override//from  w  w w.ja  va  2  s . co  m
        public void onClick(DialogInterface d, int which) {
            if (which == 0 && cameraAvailable) {
                lastTempFile = getTempFile(activity);
                Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                if (lastTempFile != null) {
                    intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(lastTempFile));
                }
                activity.startActivityForResult(intent, REQUEST_CODE_CAMERA);
            } else if ((which == 1 && cameraAvailable) || (which == 0 && !cameraAvailable)) {
                Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
                intent.setType("image/*");
                activity.startActivityForResult(
                        Intent.createChooser(intent, activity.getString(R.string.actfm_TVA_tag_picture)),
                        REQUEST_CODE_PICTURE);
            } else {
                if (clearImageOption != null)
                    clearImageOption.clearImage();
            }
        }
    };

    // show a menu of available options
    new AlertDialog.Builder(activity).setAdapter(adapter, listener).show().setOwnerActivity(activity);
}

From source file:com.yojiokisoft.yumekanow.exception.MyUncaughtExceptionHandler.java

/** 
 * ??????.//from   www  .  ja  va2 s. co  m
 * 
 * @param activity ??Activity?????
 * @param ex
 */
public static void sendBugReport(Activity activity, Throwable ex) {
    try {
        MyLog.writeStackTrace(MyConst.getCaughtBugFilePath(), ex);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }

    sBugReportFile = new File(MyConst.getCaughtBugFilePath());
    if (sBugReportFile == null || !sBugReportFile.exists()) {
        return;
    }

    setVersionName();

    MyDialog.Builder.newInstance(activity).setTitle(activity.getString(R.string.err_dialog_title))
            .setMessage(activity.getString(R.string.err_dialog_msg2))
            .setPositiveLabel(activity.getString(R.string.send)).setPositiveClickListener(mBugDialogOkClicked)
            .setNegativeLabel(activity.getString(R.string.cancel))
            .setNegativeClickListener(mBugDialogCancelClicked).show();
}

From source file:com.example.kuassivi.material_avatar.feature.ChooseAvatarActivity.java

/**
 * Navigate to this Activity//from w w w.ja  v a 2 s  . c  o m
 * <br>Start activity with material transition
 * <br>We use startActivityForResult() method to be able to deliver the chosen avatar on ProfileActivity
 *
 * @param context Activity
 * @param transitionView View
 * @param savedAvatarUrl String
 */
public static void navigate(Activity context, View transitionView, String savedAvatarUrl) {
    Intent intent = new Intent(context, ChooseAvatarActivity.class);
    intent.putExtra(ProfileActivity.Extra.AVATAR_URL, savedAvatarUrl);

    ActivityOptionsCompat optionsCompat = ActivityOptionsCompat.makeSceneTransitionAnimation(context,
            transitionView, context.getString(R.string.transition_name));
    ActivityCompat.startActivityForResult(context, intent, ProfileActivity.REQUEST_AVATAR_SELECTION_CODE,
            optionsCompat.toBundle());
}

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

private static Project loadProjectContent(String projectName, Activity activity)
        throws LoadingProjectException, OutdatedVersionProjectException, CompatibilityProjectException {
    if (project.getName().equals(projectName)) {
        throw new LoadingProjectException(activity.getString(R.string.error_load_project));
    }//w w  w .ja v a 2  s. c o  m

    Project projectToMergeInto = project;
    ProjectManager.getInstance().loadProject(projectName, activity.getApplicationContext());
    Project projectToMergeFrom = ProjectManager.getInstance().getCurrentProject();
    project = projectToMergeInto;
    return projectToMergeFrom;
}

From source file:com.bluewall.picturegame.MainActivity.java

public static void showActivityResultError(Activity activity, int requestCode, int actResp,
        int errorDescription) {
    if (activity == null) {
        Log.e("BaseGameUtils", "*** No Activity. Can't show failure dialog!");
        return;/*www . j  a v  a2s.  c  o  m*/
    }
    Dialog errorDialog;

    switch (actResp) {
    case GamesActivityResultCodes.RESULT_APP_MISCONFIGURED:
        errorDialog = makeSimpleDialog(activity, activity.getString(R.string.app_misconfigured));
        break;
    case GamesActivityResultCodes.RESULT_SIGN_IN_FAILED:
        errorDialog = makeSimpleDialog(activity, activity.getString(R.string.sign_in_failed));
        break;
    case GamesActivityResultCodes.RESULT_LICENSE_FAILED:
        errorDialog = makeSimpleDialog(activity, activity.getString(R.string.license_failed));
        break;
    default:
        // No meaningful Activity response code, so generate default Google
        // Play services dialog
        final int errorCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(activity);
        errorDialog = GooglePlayServicesUtil.getErrorDialog(errorCode, activity, requestCode, null);
        if (errorDialog == null) {
            // get fallback dialog
            Log.e("BaseGamesUtils", "No standard error dialog available. Making fallback dialog.");
            errorDialog = makeSimpleDialog(activity, activity.getString(errorDescription));
        }
    }
    errorDialog.show();
}

From source file:com.hippo.ehviewer.ui.CommonOperations.java

public static void addToFavorites(final Activity activity, final GalleryInfo galleryInfo,
        final EhClient.Callback<Void> listener) {
    int slot = Settings.getDefaultFavSlot();
    if (slot >= -1 && slot <= 9) {
        doAddToFavorites(activity, galleryInfo, slot, listener);
    } else {//from ww  w  .j  a  v a 2 s  .  c  om
        String[] items = new String[11];
        items[0] = activity.getString(R.string.local_favorites);
        String[] favCat = Settings.getFavCat();
        System.arraycopy(favCat, 0, items, 1, 10);
        new ListCheckBoxDialogBuilder(activity, items, new ListCheckBoxDialogBuilder.OnItemClickListener() {
            @Override
            public void onItemClick(ListCheckBoxDialogBuilder builder, AlertDialog dialog, int position) {
                int slot = position - 1;
                doAddToFavorites(activity, galleryInfo, slot, listener);
                if (builder.isChecked()) {
                    Settings.putDefaultFavSlot(slot);
                } else {
                    Settings.putDefaultFavSlot(Settings.INVALID_DEFAULT_FAV_SLOT);
                }
            }
        }, activity.getString(R.string.remember_favorite_collection), false)
                .setTitle(R.string.add_favorites_dialog_title).show();
    }
}

From source file:Main.java

/**
 * For use in sample code only. Checks if the sample was set up correctly,
 * including changing the package name to a non-Google package name and
 * replacing the placeholder IDs. Shows alert dialogs to notify about problems.
 * DO NOT call this method from a production app, it's meant only for samples!
 * @param resIds the resource IDs to check for placeholders
 * @return true if sample is set up correctly; false otherwise.
 */// ww w .j av a2 s  .c o  m
public static boolean verifySampleSetup(Activity activity, int... resIds) {
    StringBuilder problems = new StringBuilder();
    boolean problemFound = false;
    problems.append("The following set up problems were found:\n\n");

    // Did the developer forget to change the package name?
    if (activity.getPackageName().startsWith("com.google.example.games")) {
        problemFound = true;
        problems.append("- Package name cannot be com.google.*. You need to change the "
                + "sample's package name to your own package.").append("\n");
    }

    for (int i : resIds) {
        if (activity.getString(i).toLowerCase().contains("replaceme")) {
            problemFound = true;
            problems.append(
                    "- You must replace all " + "placeholder IDs in the ids.xml file by your project's IDs.")
                    .append("\n");
            break;
        }
    }

    if (problemFound) {
        problems.append("\n\nThese problems may prevent the app from working properly.");
        showAlert(activity, problems.toString());
        return false;
    }

    return true;
}

From source file:eu.trentorise.smartcampus.portfolio.PMHelper.java

private static void showShareDisclaimer(final Portfolio exp, final Activity ctx) {
    WebView wv = new WebView(ctx);
    wv.loadData(ctx.getString(R.string.disclaimer_share), "text/html; charset=UTF-8", "utf-8");
    AlertDialog.Builder builder = new AlertDialog.Builder(ctx);
    builder.setTitle(android.R.string.dialog_alert_title).setView(wv)
            .setOnCancelListener(new DialogInterface.OnCancelListener() {

                @Override//from w ww . jav a2  s .c  o  m
                public void onCancel(DialogInterface dialog) {
                    callshare(exp, ctx);
                }
            }).setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    callshare(exp, ctx);
                }
            });
    builder.create().show();
}

From source file:com.quarterfull.newsAndroid.LoginDialogFragment.java

public static void ShowAlertDialog(String title, String text, Activity activity) {
    // Linkify the message
    final SpannableString s = new SpannableString(text);
    Linkify.addLinks(s, Linkify.ALL);/*from  ww w .  j av a  2 s .co m*/

    AlertDialog aDialog = new AlertDialog.Builder(activity).setTitle(title).setMessage(s)
            .setPositiveButton(activity.getString(android.R.string.ok), null).create();
    aDialog.show();

    // Make the textview clickable. Must be called after show()
    ((TextView) aDialog.findViewById(android.R.id.message)).setMovementMethod(LinkMovementMethod.getInstance());
}