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:org.geek.utils.ApplicationUtils.java

/**
 * Share a page.//from  w  w w .  j ava  2  s.c  om
 * @param activity The parent activity.
 * @param title The page title.
 * @param url The page url.
 */
public static void sharePage(Activity activity, String title, String url) {
    Intent shareIntent = new Intent(Intent.ACTION_SEND);

    shareIntent.setType("text/plain");
    shareIntent.putExtra(Intent.EXTRA_TEXT, url);
    shareIntent.putExtra(Intent.EXTRA_SUBJECT, title);

    try {
        activity.startActivity(
                Intent.createChooser(shareIntent, activity.getString(R.string.Main_ShareChooserTitle)));
    } catch (android.content.ActivityNotFoundException ex) {
        // if no app handles it, do nothing
    }
}

From source file:com.felkertech.n.ActivityUtils.java

/**
 * Opens the correct intent to start editing the channel.
 *
 * @param activity The activity you're calling this from.
 * @param channelUrl The channel's media url.m
 */// w w w. j  av  a 2 s . com
public static void editChannel(final Activity activity, final String channelUrl) {
    ChannelDatabase cdn = ChannelDatabase.getInstance(activity);
    final JsonChannel jsonChannel = cdn.findChannelByMediaUrl(channelUrl);
    if (channelUrl == null || jsonChannel == null) {
        try {
            Toast.makeText(activity, R.string.toast_error_channel_invalid, Toast.LENGTH_SHORT).show();
        } catch (RuntimeException e) {
            Log.e(TAG, activity.getString(R.string.toast_error_channel_invalid));
        }
        return;
    }
    if (jsonChannel.getPluginSource() != null) {
        // Search through all plugins for one of a given source
        PackageManager pm = activity.getPackageManager();

        try {
            pm.getPackageInfo(jsonChannel.getPluginSource().getPackageName(), PackageManager.GET_ACTIVITIES);
            // Open up this particular activity
            Intent intent = new Intent();
            intent.setComponent(jsonChannel.getPluginSource());
            intent.putExtra(CumulusTvPlugin.INTENT_EXTRA_ACTION, CumulusTvPlugin.INTENT_EDIT);
            Log.d(TAG, "Editing channel " + jsonChannel.toString());
            intent.putExtra(CumulusTvPlugin.INTENT_EXTRA_JSON, jsonChannel.toString());
            activity.startActivity(intent);
        } catch (PackageManager.NameNotFoundException e) {
            new MaterialDialog.Builder(activity)
                    .title(activity.getString(R.string.plugin_not_installed_title,
                            jsonChannel.getPluginSource().getPackageName()))
                    .content(R.string.plugin_not_installed_question).positiveText(R.string.download_app)
                    .negativeText(R.string.open_in_another_plugin)
                    .callback(new MaterialDialog.ButtonCallback() {
                        @Override
                        public void onPositive(MaterialDialog dialog) {
                            super.onPositive(dialog);
                            Intent i = new Intent(Intent.ACTION_VIEW);
                            i.setData(Uri.parse("http://play.google.com/store/apps/details?id="
                                    + jsonChannel.getPluginSource().getPackageName()));
                            activity.startActivity(i);
                        }

                        @Override
                        public void onNegative(MaterialDialog dialog) {
                            super.onNegative(dialog);
                            openPluginPicker(false, channelUrl, activity);
                        }
                    }).show();
            Toast.makeText(activity, activity.getString(R.string.toast_msg_pack_not_installed,
                    jsonChannel.getPluginSource().getPackageName()), Toast.LENGTH_SHORT).show();
            openPluginPicker(false, channelUrl, activity);
        }
    } else {
        if (DEBUG) {
            Log.d(TAG, "No specified source");
        }
        openPluginPicker(false, channelUrl, activity);
    }
}

From source file:com.jetheis.android.makeitrain.fragment.OrientationDialogFragment.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    final Activity activity = getActivity();

    final CharSequence[] orientations = { activity.getString(R.string.orientation_left),
            activity.getString(R.string.orientation_right) };

    int currentOrientation = Arrays.asList(orientations).indexOf(mCurrentOrientation);

    AlertDialog.Builder orientationBuilder = new AlertDialog.Builder(activity);
    orientationBuilder.setTitle(R.string.choose_an_orientation);
    orientationBuilder.setSingleChoiceItems(orientations, currentOrientation,
            new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int item) {
                    mOnOrientationChosenListener.onOrientationChosen(orientations[item].toString());
                    dialog.dismiss();/*  w  w  w. j ava2 s  .  c o  m*/
                }

            });

    return orientationBuilder.create();
}

From source file:com.lee.sdk.utils.Utils.java

/**
 * ????//  w ww  .j  ava2s  . co  m
 * 
 * @param activity ?Activity???
 * @param nameId ????
 * @param iconId ??
 * @param appendFlags ????IntentFlag
 */
public static void addShortcut(Activity activity, int nameId, int iconId, int appendFlags) {
    Intent shortcut = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");

    // ????
    shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, activity.getString(nameId));
    shortcut.putExtra("duplicate", false); // ????

    // ?Activity???
    ComponentName comp = new ComponentName(activity.getPackageName(), activity.getClass().getName());
    Intent intent = new Intent(Intent.ACTION_MAIN).setComponent(comp);
    if (appendFlags != 0) {
        intent.addFlags(appendFlags);
    }
    shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, intent);

    // ??
    ShortcutIconResource iconRes = Intent.ShortcutIconResource.fromContext(activity, iconId);
    shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconRes);

    activity.sendBroadcast(shortcut);
}

From source file:la.xiong.mylibrary.EasyPermissions.java

public static void requestPermissions(final Object object, int dialogType, final int requestCode,
        int positiveButton, int negativeButton, boolean isAppDialog, final String... perms) {

    checkCallingObjectSuitability(object);

    boolean shouldShowRationale = false;
    for (String perm : perms) {
        shouldShowRationale = shouldShowRationale || shouldShowRequestPermissionRationale(object, perm);
    }/*from  www .j  a  v a 2 s.  c o  m*/

    if (shouldShowRationale) {
        Activity activity = getActivity(object);
        if (null == activity) {
            return;
        }
        //appdialog
        if (isAppDialog == true) {
            if (object instanceof PermissionWithDialogCallbacks) {
                ((PermissionWithDialogCallbacks) object).onDialog(requestCode, dialogType,
                        new DialogCallback() {

                            @Override
                            public void onGranted() {
                                executePermissionsRequest(object, perms, requestCode);
                            }
                        });
            }
        } else {
            showRationaleDialogFragment(activity.getFragmentManager(),
                    activity.getString(R.string.title_rationale_dialog), positiveButton, negativeButton,
                    requestCode, perms);
        }

    } else {
        executePermissionsRequest(object, perms, requestCode);
    }
}

From source file:com.github.yuqilin.qmediaplayerapp.util.Permissions.java

private static Dialog createSettingsDialogCompat(final Activity activity, int mode) {
    int titleId = 0, textId = 0;
    String action = Settings.ACTION_MANAGE_WRITE_SETTINGS;
    switch (mode) {
    case PERMISSION_SYSTEM_RINGTONE:
        titleId = R.string.allow_settings_access_ringtone_title;
        textId = R.string.allow_settings_access_ringtone_description;
        break;//  w w  w  .  j a v  a 2 s . com
    case PERMISSION_SYSTEM_BRIGHTNESS:
        titleId = R.string.allow_settings_access_brightness_title;
        textId = R.string.allow_settings_access_brightness_description;
        break;
    case PERMISSION_SYSTEM_DRAW_OVRLAYS:
        titleId = R.string.allow_draw_overlays_title;
        textId = R.string.allow_sdraw_overlays_description;
        action = Settings.ACTION_MANAGE_OVERLAY_PERMISSION;
        break;
    }
    final String finalAction = action;
    AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(activity).setTitle(activity.getString(titleId))
            .setMessage(activity.getString(textId)).setIcon(android.R.drawable.ic_dialog_alert)
            .setPositiveButton(activity.getString(R.string.permission_ask_again),
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int whichButton) {
                            SharedPreferences settings = PreferenceManager
                                    .getDefaultSharedPreferences(activity);
                            Intent i = new Intent(finalAction);
                            i.setData(Uri.parse("package:" + activity.getPackageName()));
                            try {
                                activity.startActivity(i);
                            } catch (Exception ex) {
                            }
                            SharedPreferences.Editor editor = settings.edit();
                            editor.putBoolean("user_declined_settings_access", true);
                            Util.commitPreferences(editor);
                        }
                    });
    return dialogBuilder.show();
}

From source file:com.mobicage.rogerthat.util.ui.UIUtils.java

public static void showErrorDialog(final Activity activity, Intent intent) {
    final String errorMessage = intent.getStringExtra(ERROR_MESSAGE);
    if (TextUtils.isEmptyOrWhitespace(errorMessage)) {
        activity.finish();//from   w  ww. ja  v a 2  s.  c  o m
        UIUtils.showErrorToast(activity, activity.getString(R.string.scanner_communication_failure));
    } else {
        final String errorCaption = intent.getStringExtra(ERROR_CAPTION);
        final String errorAction = intent.getStringExtra(ERROR_ACTION);
        final String errorTitle = intent.getStringExtra(ERROR_TITLE);

        SafeDialogClick positiveButtonListener = new SafeDialogClick() {
            @Override
            public void safeOnClick(DialogInterface dialog, int id) {
                dialog.dismiss();
                activity.finish();
            }
        };
        SafeDialogClick negativeButtonListener = null;
        if (!TextUtils.isEmptyOrWhitespace(errorCaption) && !TextUtils.isEmptyOrWhitespace(errorAction)) {
            negativeButtonListener = new SafeDialogClick() {
                @Override
                public void safeOnClick(DialogInterface dialog, int id) {
                    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(errorAction));
                    dialog.dismiss();
                    activity.finish();
                    activity.startActivity(intent);
                }
            };
        }
        UIUtils.showDialog(activity, errorTitle, errorMessage, positiveButtonListener, errorCaption,
                negativeButtonListener);
    }
}

From source file:org.epstudios.epcoding.ProcedureListActivity.java

private void saveCodeSelectionErrorMessage() {
    Activity activity = this;
    Toast toast = Toast.makeText(this, activity.getString(R.string.save_code_selection_error_message),
            Toast.LENGTH_SHORT);// ww  w  .j  a  va  2 s.  co m
    toast.show();
}

From source file:org.videolan.vlc.util.Permissions.java

private static Dialog createSettingsDialogCompat(final Activity activity, int mode) {
    int titleId = 0, textId = 0;
    String action = Settings.ACTION_MANAGE_WRITE_SETTINGS;
    switch (mode) {
    case PERMISSION_SYSTEM_RINGTONE:
        titleId = R.string.allow_settings_access_ringtone_title;
        textId = R.string.allow_settings_access_ringtone_description;
        break;/*from  www .ja v  a2s.  c  o  m*/
    case PERMISSION_SYSTEM_BRIGHTNESS:
        titleId = R.string.allow_settings_access_brightness_title;
        textId = R.string.allow_settings_access_brightness_description;
        break;
    case PERMISSION_SYSTEM_DRAW_OVRLAYS:
        titleId = R.string.allow_draw_overlays_title;
        textId = R.string.allow_sdraw_overlays_description;
        action = Settings.ACTION_MANAGE_OVERLAY_PERMISSION;
        break;
    }
    final String finalAction = action;
    AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(activity).setTitle(activity.getString(titleId))
            .setMessage(activity.getString(textId)).setIcon(android.R.drawable.ic_dialog_alert)
            .setPositiveButton(activity.getString(R.string.permission_ask_again),
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int whichButton) {
                            SharedPreferences settings = PreferenceManager
                                    .getDefaultSharedPreferences(activity);
                            Intent i = new Intent(finalAction);
                            i.setData(Uri.parse("package:" + activity.getPackageName()));
                            try {
                                activity.startActivity(i);
                            } catch (Exception ex) {
                            }
                            SharedPreferences.Editor editor = settings.edit();
                            editor.putBoolean("user_declined_settings_access", true);
                            editor.apply();
                        }
                    });
    return dialogBuilder.show();
}

From source file:com.concavenp.artistrymuse.fragments.adapter.ArtistryFragmentPagerAdapter.java

public ArtistryFragmentPagerAdapter(Activity activity, FragmentManager fm) {

    super(fm);//  www .j ava  2s.  c  o  m

    // Initialize the tabs
    tabs = new Pair[] {
            new Pair(activity.getString(R.string.main_tab_following),
                    new Pair(FollowingFragment.class, FollowingFragment.newInstance())),
            new Pair(activity.getString(R.string.main_tab_favorites),
                    new Pair(FavoritesFragment.class, FavoritesFragment.newInstance())),
            new Pair(activity.getString(R.string.main_tab_search),
                    new Pair(SearchFragment.class, SearchFragment.newInstance())),
            new Pair(activity.getString(R.string.main_tab_gallery),
                    new Pair(GalleryFragment.class, GalleryFragment.newInstance())) };

}