Example usage for android.content.res Resources getString

List of usage examples for android.content.res Resources getString

Introduction

In this page you can find the example usage for android.content.res Resources getString.

Prototype

@NonNull
public String getString(@StringRes int id) throws NotFoundException 

Source Link

Document

Return the string value associated with a particular resource ID.

Usage

From source file:com.scigames.slidegame.Registration5EmailActivity.java

/** Called with the activity is first created. */
@Override/*from w w w . j  a v  a  2 s . c om*/
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Log.d(TAG, "super.OnCreate");

    Intent i = getIntent();
    Log.d(TAG, "getIntent");
    firstNameIn = i.getStringExtra("fName");
    lastNameIn = i.getStringExtra("lName");
    studentIdIn = i.getStringExtra("studentId");
    visitIdIn = i.getStringExtra("visitId");
    Log.d(TAG, "...getStringExtra");

    // Inflate our UI from its XML layout description.
    setContentView(R.layout.registration5_email);
    Log.d(TAG, "...setContentView");

    email = (EditText) findViewById(R.id.email);
    /* to hide the keyboard on launch, then open when tap in firstname field */
    email.setInputType(InputType.TYPE_NULL);
    email.setOnTouchListener(new View.OnTouchListener() {
        public boolean onTouch(View v, MotionEvent event) {
            email.setInputType(InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS);
            email.onTouchEvent(event); // call native handler
            return true; // consume touch even
        }
    });

    Log.d(TAG, "...instantiateEditTexts");

    //display name in greeting sentence
    Resources res = getResources();
    TextView greets = (TextView) findViewById(R.id.greeting);
    greets.setText(String.format(res.getString(R.string.greeting), firstNameIn, lastNameIn));
    Log.d(TAG, greets.toString());
    Log.d(TAG, "...Greetings");

    // Hook up button presses to the appropriate event handler.
    ((Button) findViewById(R.id.back)).setOnClickListener(mBackListener);
    ((Button) findViewById(R.id.continue_button)).setOnClickListener(mContinueButtonListener);
    Log.d(TAG, "...instantiateButtons");

    //set listener
    task.setOnResultsListener(this);
}

From source file:com.google.wolff.androidhunt.Hunt.java

/** Loads player progress. */
public void restore(Resources res, Context context) {
    SharedPreferences sharedPref = context.getSharedPreferences(res.getString(R.string.preference_file_key),
            Context.MODE_PRIVATE);

    for (String tag : tags.keySet()) {
        Boolean val = sharedPref.getBoolean(tag, false);
        tagsFound.put(tag, val);
    }//from   w w  w . ja v  a  2s  .  c  o m

    hasSeenIntro = sharedPref.getBoolean(HAS_SEEN_INTRO_KEY, false);
}

From source file:com.google.wolff.androidhunt.Hunt.java

/**
 * Saves the player's progress./*w  ww .ja v a2s. c o m*/
 *
 * @param res
 * @param context
 */
public void save(Resources res, Context context) {
    SharedPreferences sharedPref = context.getSharedPreferences(res.getString(R.string.preference_file_key),
            Context.MODE_PRIVATE);

    Editor editor = sharedPref.edit();

    for (String key : tagsFound.keySet()) {
        editor.putBoolean(key, tagsFound.get(key));
    }

    editor.putBoolean(HAS_SEEN_INTRO_KEY, hasSeenIntro);

    editor.commit();

}

From source file:com.brkc.traffic.ui.image.ImageGridFragment.java

private void initList(String resultStr) {
    result = new VehicleResult[0];
    try {//from  w  w  w  . j  a v a  2  s.c  o m
        JSONObject jsonObject = new JSONObject(resultStr);
        Resources res = getResources();
        String totalKey = res.getString(R.string.vehicle_query_result_total);
        String rowsKey = res.getString(R.string.vehicle_query_result_rows);
        String noKey = res.getString(R.string.vehicle_query_result_plate_no);
        String colorKey = res.getString(R.string.vehicle_query_result_plate_color);
        String timeKey = res.getString(R.string.vehicle_query_result_pass_time);
        String crossKey = res.getString(R.string.vehicle_query_result_cross);
        String thumbKey = res.getString(R.string.vehicle_query_result_thumb);
        String imageKey = res.getString(R.string.vehicle_query_result_image);

        int total = jsonObject.getInt(totalKey);
        result = new VehicleResult[total];

        JSONArray rows = jsonObject.getJSONArray(rowsKey);
        for (int i = 0; i < total; i++) {
            JSONObject row = rows.getJSONObject(i);
            String plateNo = row.getString(noKey);
            String plateColor = row.getString(colorKey);
            String cross = row.getString(crossKey);
            String time = row.getString(timeKey);
            String thumb = row.getString(thumbKey);
            String image = row.getString(imageKey);
            VehicleResult item = new VehicleResult(i, plateNo, plateColor, cross, time, thumb, image);
            result[i] = item;
        }
    } catch (JSONException e) {
        e.printStackTrace();
    }
}

From source file:ca.mudar.snoozy.receiver.PowerConnectionReceiver.java

private void notify(Context context, boolean isConnectedPower, boolean hasVibration, boolean hasSound,
        int notifyCount) {
    final Resources res = context.getResources();

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
            .setSmallIcon(R.drawable.ic_notify).setContentTitle(res.getString(R.string.notify_content_title))
            .setAutoCancel(true);//from  w  w w. ja  v  a2 s  . c o  m

    if (notifyCount == 1) {
        final int resContentTextSingle = (isConnectedPower ? R.string.notify_content_text_single_on
                : R.string.notify_content_text_single_off);
        mBuilder.setContentText(res.getString(resContentTextSingle));
    } else {
        mBuilder.setNumber(notifyCount).setContentText(res.getString(R.string.notify_content_text_multi));
    }

    if (hasVibration && hasSound) {
        mBuilder.setDefaults(Notification.DEFAULT_VIBRATE | Notification.DEFAULT_SOUND);
    } else if (hasVibration) {
        mBuilder.setDefaults(Notification.DEFAULT_VIBRATE);
    } else if (hasSound) {
        mBuilder.setDefaults(Notification.DEFAULT_SOUND);
    }

    // Creates an explicit intent for an Activity in your app
    Intent resultIntent = new Intent(context, MainActivity.class);
    final Bundle extras = new Bundle();
    extras.putBoolean(Const.IntentExtras.INCREMENT_NOTIFY_GROUP, true);
    extras.putBoolean(Const.IntentExtras.RESET_NOTIFY_NUMBER, true);
    resultIntent.putExtras(extras);
    resultIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP
            | Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
    mBuilder.setContentIntent(
            PendingIntent.getActivity(context, 0, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT));

    Intent receiverIntent = new Intent(context, PowerConnectionReceiver.class);
    receiverIntent.setAction(Const.IntentActions.NOTIFY_DELETE);
    PendingIntent deleteIntent = PendingIntent.getBroadcast(context, Const.RequestCodes.RESET_NOTIFY_NUMBER,
            receiverIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    mBuilder.setDeleteIntent(deleteIntent);

    NotificationManager mNotificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);

    // NOTIFY_ID allows updates to the notification later on.
    mNotificationManager.notify(Const.NOTIFY_ID, mBuilder.build());
}

From source file:com.fairphone.updater.UpdaterService.java

public void startDownloadLatest() {
    Resources resources = getApplicationContext().getResources();

    // set the download for the latest version on the download manager
    Request request = createDownloadRequest(resources.getString(R.string.downloadUrl),
            resources.getString(R.string.versionFilename) + resources.getString(R.string.versionFilename_zip));
    mLatestFileDownloadId = mDownloadManager.enqueue(request);
}

From source file:com.scigames.registration.Registration5EmailActivity.java

/** Called with the activity is first created. */
@Override//from www. ja  va  2  s  .c  o  m
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Log.d(TAG, "super.OnCreate");

    Intent i = getIntent();
    Log.d(TAG, "getIntent");
    firstNameIn = i.getStringExtra("fName");
    lastNameIn = i.getStringExtra("lName");
    studentIdIn = i.getStringExtra("studentId");
    visitIdIn = i.getStringExtra("visitId");
    Log.d(TAG, "...getStringExtra");

    // Inflate our UI from its XML layout description.
    setContentView(R.layout.registration5_email);
    Log.d(TAG, "...setContentView");

    email = (EditText) findViewById(R.id.email);
    /* to hide the keyboard on launch, then open when tap in firstname field */
    // email.setInputType(InputType.TYPE_NULL);
    email.setOnTouchListener(new View.OnTouchListener() {
        public boolean onTouch(View v, MotionEvent event) {
            //email.setInputType(InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS);
            email.setInputType(InputType.TYPE_TEXT_VARIATION_WEB_EMAIL_ADDRESS);
            email.setInputType(InputType.TYPE_TEXT_VARIATION_URI);
            email.onTouchEvent(event); // call native handler
            return true; // consume touch even
        }
    });

    Log.d(TAG, "...instantiateEditTexts");

    //display name in greeting sentence
    Resources res = getResources();
    TextView greets = (TextView) findViewById(R.id.greeting);
    greets.setText(String.format(res.getString(R.string.greeting), firstNameIn, lastNameIn));
    Log.d(TAG, greets.toString());
    Log.d(TAG, "...Greetings");

    // Hook up button presses to the appropriate event handler.
    //((Button) findViewById(R.id.back)).setOnClickListener(mBackListener);
    ((Button) findViewById(R.id.continue_button)).setOnClickListener(mContinueButtonListener);
    Log.d(TAG, "...instantiateButtons");

    //set listener
    task.setOnResultsListener(this);
}

From source file:com.todoroo.astrid.sync.SyncProviderPreferences.java

/**
 *
 * @param resource//from   w  ww  .  j av a  2 s  .co  m
 *            if null, updates all resources
 */
@Override
public void updatePreferences(Preference preference, Object value) {
    final Resources r = getResources();

    // interval
    if (r.getString(getUtilities().getSyncIntervalKey()).equals(preference.getKey())) {
        int index = AndroidUtilities.indexOf(r.getStringArray(R.array.sync_SPr_interval_values),
                (String) value);
        if (index <= 0)
            preference.setSummary(R.string.sync_SPr_interval_desc_disabled);
        else
            preference.setSummary(r.getString(R.string.sync_SPr_interval_desc,
                    r.getStringArray(R.array.sync_SPr_interval_entries)[index]));
    }

    // status
    else if (r.getString(R.string.sync_SPr_status_key).equals(preference.getKey())) {
        boolean loggedIn = getUtilities().isLoggedIn();
        String status;
        //String subtitle = ""; //$NON-NLS-1$

        // ! logged in - display message, click -> sync
        if (!loggedIn) {
            status = r.getString(R.string.sync_status_loggedout);
            statusColor = Color.rgb(19, 132, 165);
        }
        // sync is occurring
        else if (getUtilities().isOngoing()) {
            status = r.getString(R.string.sync_status_ongoing);
            statusColor = Color.rgb(0, 0, 100);
        }
        // last sync had errors
        else if (getUtilities().getLastError() != null || getUtilities().getLastAttemptedSyncDate() != 0) {
            // last sync was failure
            if (getUtilities().getLastAttemptedSyncDate() != 0) {
                status = r.getString(R.string.sync_status_failed, DateUtilities.getDateStringWithTime(
                        SyncProviderPreferences.this, new Date(getUtilities().getLastAttemptedSyncDate())));
                statusColor = Color.rgb(100, 0, 0);

                if (getUtilities().getLastSyncDate() > 0) {
                    //                        subtitle = r.getString(R.string.sync_status_failed_subtitle,
                    //                                DateUtilities.getDateStringWithTime(SyncProviderPreferences.this,
                    //                                        new Date(getUtilities().getLastSyncDate())));
                }
            } else {
                long lastSyncDate = getUtilities().getLastSyncDate();
                String dateString = lastSyncDate > 0
                        ? DateUtilities.getDateStringWithTime(SyncProviderPreferences.this,
                                new Date(lastSyncDate))
                        : ""; //$NON-NLS-1$
                status = r.getString(R.string.sync_status_errors, dateString);
                statusColor = Color.rgb(100, 100, 0);
            }
        } else if (getUtilities().getLastSyncDate() > 0) {
            status = r.getString(R.string.sync_status_success, DateUtilities.getDateStringWithTime(
                    SyncProviderPreferences.this, new Date(getUtilities().getLastSyncDate())));
            statusColor = Color.rgb(0, 100, 0);
        } else {
            status = r.getString(R.string.sync_status_never);
            statusColor = Color.rgb(0, 0, 100);
        }
        preference.setTitle(R.string.sync_SPr_sync);
        preference.setSummary(r.getString(R.string.sync_SPr_status_subtitle, status));

        preference.setOnPreferenceClickListener(new OnPreferenceClickListener() {
            public boolean onPreferenceClick(Preference p) {
                startSync();
                return true;
            }
        });

        View view = findViewById(R.id.status);
        if (view != null)
            view.setBackgroundColor(statusColor);
    } else if (r.getString(R.string.sync_SPr_key_last_error).equals(preference.getKey())) {
        if (getUtilities().getLastError() != null) {
            // Display error
            final String service = getTitle().toString();
            final String lastErrorFull = getUtilities().getLastError();
            final String lastErrorDisplay = adjustErrorForDisplay(r, lastErrorFull, service);
            preference.setTitle(R.string.sync_SPr_last_error);
            preference.setSummary(R.string.sync_SPr_last_error_subtitle);

            preference.setOnPreferenceClickListener(new OnPreferenceClickListener() {
                @Override
                @SuppressWarnings("nls")
                public boolean onPreferenceClick(Preference pref) {
                    // Show last error
                    new AlertDialog.Builder(SyncProviderPreferences.this).setTitle(R.string.sync_SPr_last_error)
                            .setMessage(lastErrorDisplay)
                            .setPositiveButton(R.string.sync_SPr_send_report, new OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    Intent emailIntent = new Intent(Intent.ACTION_SEND);
                                    emailIntent.setType("plain/text")
                                            .putExtra(Intent.EXTRA_EMAIL,
                                                    new String[] { "android-bugs@astrid.com" })
                                            .putExtra(Intent.EXTRA_SUBJECT, service + " Sync Error")
                                            .putExtra(Intent.EXTRA_TEXT, lastErrorFull);
                                    startActivity(Intent.createChooser(emailIntent,
                                            r.getString(R.string.sync_SPr_send_report)));
                                }
                            }).setNegativeButton(R.string.DLG_close, null).create().show();
                    return true;
                }
            });

        } else {
            PreferenceCategory statusCategory = (PreferenceCategory) findPreference(
                    r.getString(R.string.sync_SPr_group_status));
            statusCategory.removePreference(findPreference(r.getString(R.string.sync_SPr_key_last_error)));
        }
    }
    // log out button
    else if (r.getString(R.string.sync_SPr_forget_key).equals(preference.getKey())) {
        boolean loggedIn = getUtilities().isLoggedIn();
        preference.setOnPreferenceClickListener(new OnPreferenceClickListener() {
            public boolean onPreferenceClick(Preference p) {
                DialogUtilities.okCancelDialog(SyncProviderPreferences.this,
                        r.getString(R.string.sync_forget_confirm), new OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                logOut();
                                initializePreference(getPreferenceScreen());
                            }
                        }, null);
                return true;
            }
        });
        if (!loggedIn) {
            PreferenceCategory category = (PreferenceCategory) findPreference(
                    r.getString(R.string.sync_SPr_key_options));
            category.removePreference(preference);
        }

    }
}

From source file:org.wso2.iot.agent.utils.CommonUtils.java

public static AppRestriction getAppRestrictionTypeAndList(Operation operation, ResultPayload resultBuilder,
        Resources resources) throws AndroidAgentException {
    AppRestriction appRestriction = new AppRestriction();
    JSONArray permittedApps = null;/*from   w ww .  j  a  v a  2 s. c  o m*/
    try {
        JSONObject payload = new JSONObject(operation.getPayLoad().toString());
        appRestriction.setRestrictionType((String) payload.get(Constants.AppRestriction.RESTRICTION_TYPE));
        if (!payload.isNull(Constants.AppRestriction.RESTRICTED_APPLICATIONS)) {
            permittedApps = payload.getJSONArray(Constants.AppRestriction.RESTRICTED_APPLICATIONS);
        }
    } catch (JSONException e) {
        if (resources != null && resultBuilder != null) {
            operation.setStatus(resources.getString(R.string.operation_value_error));
            resultBuilder.build(operation);
        }
        throw new AndroidAgentException("Invalid JSON format.", e);
    }

    List<String> restrictedPackages = new ArrayList<>();

    if (permittedApps != null) {
        for (int i = 0; i < permittedApps.length(); i++) {
            try {
                restrictedPackages.add((String) ((JSONObject) permittedApps.get(i))
                        .get(Constants.AppRuntimePermission.PACKAGE_NAME));
            } catch (JSONException e) {
                if (resources != null && resultBuilder != null) {
                    operation.setStatus(resources.getString(R.string.operation_value_error));
                    resultBuilder.build(operation);
                }
                throw new AndroidAgentException("Invalid JSON format", e);
            }
        }
    }

    appRestriction.setRestrictedList(restrictedPackages);
    return appRestriction;
}

From source file:com.aqnote.app.wifianalyzer.wifi.graph.channel.ChannelGraphView.java

private GraphView makeGraphView() {
    Resources resources = MainContext.INSTANCE.getResources();
    MainActivity mainActivity = MainContext.INSTANCE.getMainActivity();
    return new GraphViewBuilder(mainActivity, getNumX())
            .setLabelFormatter(new ChannelAxisLabel(wiFiBand, wiFiChannelPair))
            .setVerticalTitle(resources.getString(R.string.graph_axis_y))
            .setHorizontalTitle(resources.getString(R.string.graph_channel_axis_x)).build();
}