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.github.michalbednarski.intentslab.browser.ComponentFetcher.java

@Override
void initConfigurationForm(final FetcherOptionsDialog dialog) {
    // Disable development permission checkbox if it's not available
    if (!DEVELOPMENT_PERMISSIONS_SUPPORTED) {
        dialog.findView(R.id.permission_filter_development).setEnabled(false);
    }/*from w w w. j  ava  2 s. com*/

    // Prepare protection preset spinner
    {
        // Find current preset
        int currentPresetId = PROTECTION_PRESETS.length; // "Custom" if nothing found
        if (!testWritePermissionForProviders) {
            for (int i = 0; i < PROTECTION_PRESETS.length; i++) {
                if (protection == PROTECTION_PRESETS[i]) {
                    currentPresetId = i;
                    dialog.findView(R.id.permission_filter_details).setVisibility(View.GONE);
                    break;
                }
            }
        }

        // Fill spinner
        Spinner protectionPresetSpinner = (Spinner) dialog.findView(R.id.permission_filter_spinner);
        Activity activity = dialog.getActivity();
        protectionPresetSpinner
                .setAdapter(new ArrayAdapter<String>(activity, android.R.layout.simple_spinner_item,
                        new String[] { activity.getString(R.string.permission_filter_show_all), // 0
                                activity.getString(R.string.permission_filter_show_exported), // 1
                                activity.getString(R.string.permission_filter_show_obtainable), // 2
                                activity.getString(R.string.permission_filter_world_accessible), // 3
                                activity.getString(R.string.filter_custom) // 4
                        }));
        protectionPresetSpinner.setSelection(currentPresetId);

        // Set up spinner event
        protectionPresetSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                boolean isCustom = position == PROTECTION_PRESETS.length;
                if (!isCustom) {
                    int preset = PROTECTION_PRESETS[position];
                    dialog.setBoxChecked(R.id.permission_filter_world_accessible,
                            (preset & PROTECTION_WORLD_ACCESSIBLE) != 0);
                    dialog.setBoxChecked(R.id.permission_filter_normal, (preset & PROTECTION_NORMAL) != 0);
                    dialog.setBoxChecked(R.id.permission_filter_dangerous,
                            (preset & PROTECTION_DANGEROUS) != 0);
                    dialog.setBoxChecked(R.id.permission_filter_signature,
                            (preset & PROTECTION_SIGNATURE) != 0);
                    dialog.setBoxChecked(R.id.permission_filter_system, (preset & PROTECTION_SYSTEM) != 0);
                    dialog.setBoxChecked(R.id.permission_filter_development,
                            (preset & PROTECTION_DEVELOPMENT) != 0);
                    dialog.setBoxChecked(R.id.permission_filter_unexported,
                            (preset & PROTECTION_UNEXPORTED) != 0);
                    dialog.setBoxChecked(R.id.permission_filter_unknown, (preset & PROTECTION_UNKNOWN) != 0);
                    dialog.setBoxChecked(R.id.read_permission, true);
                }
                dialog.findView(R.id.permission_filter_details)
                        .setVisibility(isCustom ? View.VISIBLE : View.GONE);
            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {
                // Spinner cannot have nothing selected
            }
        });
    }

    // Fill form
    dialog.setBoxChecked(R.id.system_apps, (appType & APP_TYPE_SYSTEM) != 0);
    dialog.setBoxChecked(R.id.user_apps, (appType & APP_TYPE_USER) != 0);

    dialog.setBoxChecked(R.id.activities, (type & PackageManager.GET_ACTIVITIES) != 0);
    dialog.setBoxChecked(R.id.receivers, (type & PackageManager.GET_RECEIVERS) != 0);
    dialog.setBoxChecked(R.id.services, (type & PackageManager.GET_SERVICES) != 0);
    dialog.setBoxChecked(R.id.content_providers, (type & PackageManager.GET_PROVIDERS) != 0);

    dialog.setBoxChecked(R.id.permission_filter_world_accessible,
            (protection & PROTECTION_WORLD_ACCESSIBLE) != 0);
    dialog.setBoxChecked(R.id.permission_filter_normal, (protection & PROTECTION_NORMAL) != 0);
    dialog.setBoxChecked(R.id.permission_filter_dangerous, (protection & PROTECTION_DANGEROUS) != 0);
    dialog.setBoxChecked(R.id.permission_filter_signature, (protection & PROTECTION_SIGNATURE) != 0);
    dialog.setBoxChecked(R.id.permission_filter_system, (protection & PROTECTION_SYSTEM) != 0);
    dialog.setBoxChecked(R.id.permission_filter_development, (protection & PROTECTION_DEVELOPMENT) != 0);
    dialog.setBoxChecked(R.id.permission_filter_unexported, (protection & PROTECTION_UNEXPORTED) != 0);
    dialog.setBoxChecked(R.id.permission_filter_unknown, (protection & PROTECTION_UNKNOWN) != 0);

    dialog.setBoxChecked(testWritePermissionForProviders ? R.id.write_permission : R.id.read_permission, true);
    dialog.setBoxChecked(R.id.only_providers_with_grant_uri_permission,
            includeOnlyProvidersAllowingPermissionGranting);

    dialog.setBoxChecked(R.id.metadata, requireMetaDataSubstring != null);
    dialog.setTextInField(R.id.metadata_substring, requireMetaDataSubstring);

    // Set up sections showing when their checkboxes are checked
    dialog.findView(R.id.content_provider_permission_type)
            .setVisibility(testWritePermissionForProviders ? View.VISIBLE : View.GONE);
    dialog.findView(R.id.content_provider_options)
            .setVisibility((type & PackageManager.GET_PROVIDERS) != 0 ? View.VISIBLE : View.GONE);
    ((CheckBox) dialog.findView(R.id.content_providers))
            .setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                @Override
                public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                    dialog.findView(R.id.content_provider_permission_type)
                            .setVisibility(isChecked ? View.VISIBLE : View.GONE);
                    dialog.findView(R.id.content_provider_options)
                            .setVisibility(isChecked ? View.VISIBLE : View.GONE);
                    if (!isChecked) {
                        dialog.setBoxChecked(R.id.read_permission, true);
                        dialog.setBoxChecked(R.id.only_providers_with_grant_uri_permission, false);
                    }
                }
            });

    dialog.findView(R.id.metadata_details)
            .setVisibility(requireMetaDataSubstring != null ? View.VISIBLE : View.GONE);
    ((CheckBox) dialog.findView(R.id.metadata))
            .setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                @Override
                public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                    dialog.findView(R.id.metadata_details).setVisibility(isChecked ? View.VISIBLE : View.GONE);
                    if (!isChecked) {
                        dialog.setTextInField(R.id.metadata_substring, "");
                    }
                }
            });
}

From source file:jahirfiquitiva.iconshowcase.activities.AltWallpaperViewerActivity.java

private void saveWallpaper(final Activity context, final String wallName, final MaterialDialog downloadDialog,
        final Bitmap result) {
    downloadDialog.setContent(context.getString(R.string.saving_wallpaper));
    new Thread(new Runnable() {
        @Override/*from   ww w.ja va 2 s . c om*/
        public void run() {
            if (mPrefs.getDownloadsFolder() != null) {
                downloadsFolder = new File(mPrefs.getDownloadsFolder());
            } else {
                downloadsFolder = new File(context.getString(R.string.walls_save_location,
                        Environment.getExternalStorageDirectory().getAbsolutePath()));
            }
            //noinspection ResultOfMethodCallIgnored
            downloadsFolder.mkdirs();
            final File destFile = new File(downloadsFolder, wallName + ".png");
            String snackbarText;
            if (!destFile.exists()) {
                try {
                    result.compress(Bitmap.CompressFormat.PNG, 100, new FileOutputStream(destFile));
                    snackbarText = context.getString(R.string.wallpaper_downloaded, destFile.getAbsolutePath());
                } catch (final Exception e) {
                    snackbarText = context.getString(R.string.error);
                }
            } else {
                snackbarText = context.getString(R.string.wallpaper_downloaded, destFile.getAbsolutePath());
            }
            final String finalSnackbarText = snackbarText;
            context.runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    downloadDialog.dismiss();
                    Snackbar longSnackbar = Utils.snackbar(AltWallpaperViewerActivity.this, layout,
                            finalSnackbarText, Snackbar.LENGTH_LONG);
                    ViewGroup snackbarView = (ViewGroup) longSnackbar.getView();
                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
                        snackbarView.setPadding(snackbarView.getPaddingLeft(), snackbarView.getPaddingTop(),
                                snackbarView.getPaddingRight(),
                                Utils.getNavigationBarHeight(AltWallpaperViewerActivity.this));
                    }
                    longSnackbar.show();
                    longSnackbar.setCallback(new Snackbar.Callback() {
                        @Override
                        public void onDismissed(Snackbar snackbar, int event) {
                            super.onDismissed(snackbar, event);
                            reshowFab(fab);
                            setupFullScreen();
                        }
                    });
                }
            });
        }
    }).start();
}

From source file:com.connectutb.xfuel.FuelPlanner.java

public FuelPlanner(Activity context, String aircraft, String orig, String dest, boolean metar, String rules,
        String units, ProgressBar loading) {
    /* Assign variables */
    this.context = context;
    this.httppost = new HttpPost(context.getResources().getString(R.string.post_url));
    this.httpclient = new DefaultHttpClient();
    this.aircraft = aircraft;
    this.orig = orig;
    this.dest = dest;
    this.bMetar = metar;
    if (metar) {/*from   w  ww  .  ja va  2s .c  om*/
        this.metar = "YES";
    } else {
        this.metar = "NO";
    }
    this.rules = rules;
    this.units = units;
    /** API license information */
    this.account = context.getString(R.string.account);
    this.license = context.getString(R.string.license);
    this.email = context.getString(R.string.email);

    this.loading = loading;

    settings = PreferenceManager.getDefaultSharedPreferences(context);
}

From source file:com.forrestguice.suntimeswidget.AlarmDialog.java

/**
 * @param savedInstanceState a Bundle containing dialog state
 * @return an AlarmDialog ready to be shown
 *///from   w w  w.j av  a  2s. com
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    final Activity myParent = getActivity();
    LayoutInflater inflater = myParent.getLayoutInflater();
    @SuppressLint("InflateParams")
    View dialogContent = inflater.inflate(R.layout.layout_dialog_schedalarm, null);

    Resources r = getResources();
    int padding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 16, r.getDisplayMetrics());

    AlertDialog.Builder builder = new AlertDialog.Builder(myParent);
    builder.setView(dialogContent, 0, padding, 0, 0);
    builder.setTitle(myParent.getString(R.string.schedalarm_dialog_title));

    AlertDialog dialog = builder.create();
    dialog.setCanceledOnTouchOutside(false);

    dialog.setButton(AlertDialog.BUTTON_NEGATIVE, myParent.getString(R.string.schedalarm_dialog_cancel),
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();

                    if (onCanceled != null) {
                        onCanceled.onClick(dialog, which);
                    }
                }
            });

    dialog.setButton(AlertDialog.BUTTON_POSITIVE, myParent.getString(R.string.schedalarm_dialog_ok),
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    saveSettings(myParent);
                    dialog.dismiss();

                    if (onAccepted != null) {
                        onAccepted.onClick(dialog, which);
                    }
                }
            });

    initViews(myParent, dialogContent);
    if (savedInstanceState != null) {
        //Log.d("DEBUG", "AlarmDialog onCreate (restoreState)");
        loadSettings(savedInstanceState);

    } else {
        //Log.d("DEBUG", "AlarmDialog onCreate (newState)");
        loadSettings(myParent);
    }
    return dialog;
}

From source file:br.com.viniciuscr.notification2android.mediaPlayer.MusicUtils.java

static void updateNowPlaying(Activity a) {
    View nowPlayingView = a.findViewById(R.id.nowplaying);
    if (nowPlayingView == null) {
        return;/*from  ww w  . ja v a  2  s .  c o m*/
    }
    boolean withtabs = false;
    Intent intent = a.getIntent();
    if (intent != null) {
        withtabs = intent.getBooleanExtra("withtabs", false);
    }
    //tinha um true == Music...
    if (MusicUtils.sService != null && MusicUtils.sService.getAudioId() != -1) {
        TextView title = (TextView) nowPlayingView.findViewById(R.id.title);
        TextView artist = (TextView) nowPlayingView.findViewById(R.id.artist);
        title.setText(MusicUtils.sService.getTrackName());
        String artistName = MusicUtils.sService.getArtistName();
        if (MediaStore.UNKNOWN_STRING.equals(artistName)) {
            artistName = a.getString(R.string.unknown_artist_name);
        }
        artist.setText(artistName);
        //mNowPlayingView.setOnFocusChangeListener(mFocuser);
        //mNowPlayingView.setOnClickListener(this);
        nowPlayingView.setVisibility(View.VISIBLE);
        nowPlayingView.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {
                // Context c = v.getContext();
                // c.startActivity(new Intent(c, MediaPlaybackActivity.class));
            }
        });
        return;
    }
    nowPlayingView.setVisibility(View.GONE);
}

From source file:com.forrestguice.suntimeswidget.TimeZoneDialog.java

@NonNull
@Override/*w  w w.j ava 2  s .com*/
public Dialog onCreateDialog(final Bundle savedInstanceState) {
    super.onCreateDialog(savedInstanceState);

    final Activity myParent = getActivity();
    LayoutInflater inflater = myParent.getLayoutInflater();
    @SuppressLint("InflateParams")
    View dialogContent = inflater.inflate(R.layout.layout_dialog_timezone, null);

    Resources r = getResources();
    int padding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 16, r.getDisplayMetrics());

    AlertDialog.Builder builder = new AlertDialog.Builder(myParent);
    builder.setView(dialogContent, 0, padding, 0, 0);

    builder.setTitle(myParent.getString(R.string.timezone_dialog_title));

    AlertDialog dialog = builder.create();
    dialog.setCanceledOnTouchOutside(false);

    dialog.setButton(AlertDialog.BUTTON_NEGATIVE, myParent.getString(R.string.timezone_dialog_cancel),
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();

                    if (onCanceled != null) {
                        onCanceled.onClick(dialog, which);
                    }
                }
            });

    dialog.setButton(AlertDialog.BUTTON_POSITIVE, myParent.getString(R.string.timezone_dialog_ok),
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    saveSettings(myParent);
                    dialog.dismiss();

                    if (onAccepted != null) {
                        onAccepted.onClick(dialog, which);
                    }
                }
            });
    /**dialog.setOnShowListener(new DialogInterface.OnShowListener()
    {
    @Override
    public void onShow(DialogInterface dialogInterface) {}
    });*/
    /**dialog.setOnDismissListener(new DialogInterface.OnDismissListener()
    {
    @Override
    public void onDismiss(DialogInterface dialogInterface) {}
    });*/

    initViews(myParent, dialogContent);
    WidgetTimezones.TimeZoneSort sortZonesBy = AppSettings.loadTimeZoneSortPref(myParent);
    WidgetTimezones.TimeZonesLoadTask loadTask = new WidgetTimezones.TimeZonesLoadTask(myParent) {
        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            spinner_timezone.setAdapter(
                    new WidgetTimezones.TimeZoneItemAdapter(myParent, R.layout.layout_listitem_timezone));
        }

        @Override
        protected void onPostExecute(WidgetTimezones.TimeZoneItemAdapter result) {
            super.onPostExecute(result);
            spinner_timezone_adapter = result;
            spinner_timezone.setAdapter(spinner_timezone_adapter);
            WidgetTimezones.selectTimeZone(spinner_timezone, spinner_timezone_adapter, customTimezoneID);
        }
    };

    if (savedInstanceState != null) {
        // saved dialog state; restore it
        //Log.d("DEBUG", "TimeZoneDialog onCreate (restoreState)");
        loadSettings(savedInstanceState);

    } else {
        // no saved dialog state; load from preferences
        //Log.d("DEBUG", "TimeZoneDialog onCreate (newState)");
        loadSettings(myParent);
    }
    loadTask.execute(sortZonesBy);
    return dialog;
}

From source file:jackpal.androidterm.TermPreferences.java

private void doFilePicker() {
    AlertDialog.Builder bld = new AlertDialog.Builder(this);
    bld.setIcon(android.R.drawable.ic_dialog_info);
    bld.setMessage(this.getString(R.string.font_file_error));
    bld.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            dialog.dismiss();//from  ww  w.j  a va2  s  . co m
            Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
            intent.addCategory(Intent.CATEGORY_OPENABLE);
            intent.setType("application/octet-stream");
            startActivityForResult(intent, REQUEST_FONT_PICKER);
        }
    });
    bld.setNegativeButton(this.getString(android.R.string.no), null);
    final Activity activity = this;
    bld.setNeutralButton(this.getString(R.string.entry_fontfile_default),
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    dialog.dismiss();
                    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(activity);
                    sp.edit().putString(FONT_FILENAME, activity.getString(R.string.entry_fontfile_default))
                            .apply();
                }
            });
    bld.create().show();
}

From source file:it.feio.android.omninotes.BaseActivity.java

/**
 * Method to validate security password to protect notes.
 * It uses an interface callback.//  ww  w.  ja  v  a  2s  .  c o m
 */
public static void requestPassword(final Activity mActivity, final PasswordValidator mPasswordValidator) {

    // Inflate layout
    LayoutInflater inflater = mActivity.getLayoutInflater();
    final View v = inflater.inflate(R.layout.password_request_dialog_layout, null);
    final EditText passwordEditText = (EditText) v.findViewById(R.id.password_request);

    MaterialDialog dialog = new MaterialDialog.Builder(mActivity).autoDismiss(false)
            .title(R.string.insert_security_password).customView(v, false).positiveText(R.string.ok)
            .callback(new MaterialDialog.ButtonCallback() {
                @Override
                public void onPositive(MaterialDialog dialog) {
                    // When positive button is pressed password correctness is checked
                    String oldPassword = mActivity
                            .getSharedPreferences(Constants.PREFS_NAME, MODE_MULTI_PROCESS)
                            .getString(Constants.PREF_PASSWORD, "");
                    String password = passwordEditText.getText().toString();
                    // The check is done on password's hash stored in preferences
                    boolean result = Security.md5(password).equals(oldPassword);

                    // In case password is ok dialog is dismissed and result sent to callback
                    if (result) {
                        KeyboardUtils.hideKeyboard(passwordEditText);
                        dialog.dismiss();
                        mPasswordValidator.onPasswordValidated(true);
                        // If password is wrong the auth flow is not interrupted and simply a message is shown
                    } else {
                        passwordEditText.setError(mActivity.getString(R.string.wrong_password));
                    }
                }
            }).build();

    dialog.setOnCancelListener(dialog1 -> {
        KeyboardUtils.hideKeyboard(passwordEditText);
        dialog1.dismiss();
        mPasswordValidator.onPasswordValidated(false);
    });

    dialog.show();

    // Force focus and shows soft keyboard
    new Handler().postDelayed(() -> KeyboardUtils.showKeyboard(passwordEditText), 100);
}

From source file:paulscode.android.mupen64plusae.jni.CoreFragment.java

@Override
public void onFailure(final int errorCode) {
    final Activity activity = getActivity();
    if (activity != null) {
        // Messages match return codes from mupen64plus-ui-console/main.c
        String message = null;//www  .  j av a2 s  .  com

        if (errorCode != 0) {
            switch (errorCode) {
            case 1:
                message = activity.getString(R.string.toast_nativeMainFailure01);
                break;
            case 2:
                message = activity.getString(R.string.toast_nativeMainFailure02);
                break;
            case 3:
                message = activity.getString(R.string.toast_nativeMainFailure03);
                break;
            case 4:
                message = activity.getString(R.string.toast_nativeMainFailure04);
                break;
            case 5:
                message = activity.getString(R.string.toast_nativeMainFailure05);
                break;
            case 6:
                message = activity.getString(R.string.toast_nativeMainFailure06);
                break;
            case 7:
                message = activity.getString(R.string.toast_nativeMainFailure07);
                break;
            case 8:
                message = activity.getString(R.string.toast_nativeMainFailure08);
                break;
            case 9:
                message = activity.getString(R.string.toast_nativeMainFailure09);
                break;
            case 10:
                message = activity.getString(R.string.toast_nativeMainFailure10);
                break;
            case 11:
                message = activity.getString(R.string.toast_nativeMainFailure11);
                break;
            case 12:
                message = activity.getString(R.string.toast_nativeMainFailure12);
                break;
            case 13:
                message = activity.getString(R.string.toast_nativeMainFailure13);
                break;
            default:
                message = activity.getString(R.string.toast_nativeMainFailureUnknown);
                break;
            }
            Log.e("CoreFragment", "Launch failure: " + message);
        }

        final String finalMessage = message;

        activity.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                Notifier.showToast(activity, finalMessage);
            }
        });
    }
}

From source file:com.google.samples.apps.topeka.fragment.SignInFragment.java

private void performSignInWithTransition(View v) {
    final Activity activity = getActivity();
    if (v == null || ApiLevelHelper.isLowerThan(Build.VERSION_CODES.LOLLIPOP)) {
        // Don't run a transition if the passed view is null
        CategorySelectionActivity.start(activity, mPlayer);
        activity.finish();/*from w w w  . j  a  va 2 s  .c om*/
        return;
    }

    if (ApiLevelHelper.isAtLeast(Build.VERSION_CODES.LOLLIPOP)) {
        activity.getWindow().getSharedElementExitTransition().addListener(new TransitionListenerAdapter() {
            @Override
            public void onTransitionEnd(Transition transition) {
                activity.finish();
            }
        });

        final Pair[] pairs = TransitionHelper.createSafeTransitionParticipants(activity, true,
                new Pair<>(v, activity.getString(R.string.transition_avatar)));
        @SuppressWarnings("unchecked")
        ActivityOptionsCompat activityOptions = ActivityOptionsCompat.makeSceneTransitionAnimation(activity,
                pairs);
        CategorySelectionActivity.start(activity, mPlayer, activityOptions);
    }
}