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.brkc.traffic.ui.image.ImageListFragment.java

private void initList(String resultStr) {
    result = new VehicleResult[0];
    try {/*from   www. j av  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);
        JSONArray rows = jsonObject.getJSONArray(rowsKey);
        if (rows.length() > total) {
            total = rows.length();
        }

        result = new VehicleResult[total];
        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();
    }
    Log.d(TAG, "?" + result.length);
}

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

private GraphView makeGraphView() {
    MainActivity mainActivity = MainContext.INSTANCE.getMainActivity();
    Resources resources = mainActivity.getResources();
    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();
}

From source file:com.example.android.notepad.CMNotesProvider.java

@Override
public Uri insert(Uri uri, ContentValues initialValues) {
    // Validate the requested uri
    if (sUriMatcher.match(uri) != NOTES) {
        throw new IllegalArgumentException("Unknown URI " + uri);
    }/*w w  w  .j a v a 2  s  .  c  o  m*/

    ContentValues values;
    if (initialValues != null) {
        values = new ContentValues(initialValues);
    } else {
        values = new ContentValues();
    }

    Long now = Long.valueOf(System.currentTimeMillis());

    // Make sure that the fields are all set
    if (values.containsKey(NotePad.Notes.CREATED_DATE) == false) {
        values.put(NotePad.Notes.CREATED_DATE, now);
    }

    if (values.containsKey(NotePad.Notes.MODIFIED_DATE) == false) {
        values.put(NotePad.Notes.MODIFIED_DATE, now);
    }

    if (values.containsKey(NotePad.Notes.TITLE) == false) {
        Resources r = Resources.getSystem();
        values.put(NotePad.Notes.TITLE, r.getString(android.R.string.untitled));
    }

    if (values.containsKey(NotePad.Notes.NOTE) == false) {
        values.put(NotePad.Notes.NOTE, "");
    }

    CMAdapter cmadapter = new CMAdapter();
    // for the moment, use time for the key
    String key = System.currentTimeMillis() + "";
    String new_key = cmadapter.updateValue(key, values);
    if (new_key != null) {
        System.out.println("Set key: " + key + ", got key: " + new_key);
        Uri noteUri = ContentUris.withAppendedId(NotePad.Notes.CONTENT_URI, Long.parseLong(new_key));
        getContext().getContentResolver().notifyChange(noteUri, null);
        return noteUri;
    }

    //        SQLiteDatabase db = mOpenHelper.getWritableDatabase();
    //        long rowId = db.insert(NOTES_TABLE_NAME, Notes.NOTE, values);
    //        if (rowId > 0) {
    //      Uri noteUri = ContentUris.withAppendedId(NotePad.Notes.CONTENT_URI, rowId);
    //            getContext().getContentResolver().notifyChange(noteUri, null);
    //      return noteUri;
    //        }

    throw new SQLException("Failed to insert row into " + uri);
}

From source file:com.android.deskclock.alarms.AlarmNotifications.java

public static void showAlarmNotification(Service service, AlarmInstance instance) {
    LogUtils.v("Displaying alarm notification for alarm instance: " + instance.mId);

    Resources resources = service.getResources();
    NotificationCompat.Builder notification = new NotificationCompat.Builder(service)
            .setContentTitle(instance.getLabelOrDefault(service))
            .setContentText(AlarmUtils.getFormattedTime(service, instance.getAlarmTime()))
            .setSmallIcon(R.drawable.stat_notify_alarm).setOngoing(true).setAutoCancel(false)
            .setDefaults(NotificationCompat.DEFAULT_LIGHTS).setWhen(0)
            .setCategory(NotificationCompat.CATEGORY_ALARM).setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
            .setLocalOnly(true);//from   www  .  ja  v a  2s. c  o m

    // Setup Snooze Action
    Intent snoozeIntent = AlarmStateManager.createStateChangeIntent(service, AlarmStateManager.ALARM_SNOOZE_TAG,
            instance, AlarmInstance.SNOOZE_STATE);
    snoozeIntent.putExtra(AlarmStateManager.FROM_NOTIFICATION_EXTRA, true);
    PendingIntent snoozePendingIntent = PendingIntent.getService(service, instance.hashCode(), snoozeIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    notification.addAction(R.drawable.ic_snooze_24dp, resources.getString(R.string.alarm_alert_snooze_text),
            snoozePendingIntent);

    // Setup Dismiss Action
    Intent dismissIntent = AlarmStateManager.createStateChangeIntent(service,
            AlarmStateManager.ALARM_DISMISS_TAG, instance, AlarmInstance.DISMISSED_STATE);
    dismissIntent.putExtra(AlarmStateManager.FROM_NOTIFICATION_EXTRA, true);
    PendingIntent dismissPendingIntent = PendingIntent.getService(service, instance.hashCode(), dismissIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    notification.addAction(R.drawable.ic_alarm_off_24dp, resources.getString(R.string.alarm_alert_dismiss_text),
            dismissPendingIntent);

    // Setup Content Action
    Intent contentIntent = AlarmInstance.createIntent(service, AlarmActivity.class, instance.mId);
    notification.setContentIntent(PendingIntent.getActivity(service, instance.hashCode(), contentIntent,
            PendingIntent.FLAG_UPDATE_CURRENT));

    // Setup fullscreen intent
    Intent fullScreenIntent = AlarmInstance.createIntent(service, AlarmActivity.class, instance.mId);
    // set action, so we can be different then content pending intent
    fullScreenIntent.setAction("fullscreen_activity");
    fullScreenIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NO_USER_ACTION);
    notification.setFullScreenIntent(PendingIntent.getActivity(service, instance.hashCode(), fullScreenIntent,
            PendingIntent.FLAG_UPDATE_CURRENT), true);
    notification.setPriority(NotificationCompat.PRIORITY_MAX);

    clearNotification(service, instance);
    service.startForeground(instance.hashCode(), notification.build());
}

From source file:com.scigames.slidereview.MenuActivity.java

private void displayProfile() {
    setContentView(R.layout.menu_page);/* w w w.ja  v  a 2  s  . com*/
    Log.d(TAG, "...setContentView");

    //display name and profile info
    Resources res = getResources();
    greets = (TextView) findViewById(R.id.student_name);
    greets.setText(String.format(res.getString(R.string.profile_name), firstNameIn, lastNameIn));
    setTextViewFont(Museo700Regular, greets);
    Log.d(TAG, "...Profile Info");

    reviewBtn = (Button) findViewById(R.id.btn_review);
    reviewBtn.setOnClickListener(mReview);
    setButtonFont(ExistenceLightOtf, reviewBtn);

    infoDialog = new AlertDialog.Builder(MenuActivity.this).create();
    infoDialog.setTitle("Debug Info");
    infoDialog.setButton(RESULT_OK, "OK", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            // Write your code here to execute after dialog closed
        }
    });

    if (debug) {
        //      infoDialog.setTitle("studentId");
        //      infoDialog.setMessage(studentIdIn);
        //      infoDialog.show();
    }

    task.setOnResultsListener(this);
    task.cancel(true);
    task = new SciGamesHttpPoster(MenuActivity.this, baseDbURL + "/pull/return_profile.php");
    task.setOnResultsListener(MenuActivity.this);

    //download photo
    ImageView profilePhoto = (ImageView) findViewById(R.id.profile_image);
    profilePhoto.setTag(photoUrl);
    profilePhoto.setScaleX(1.4f);
    profilePhoto.setScaleY(1.4f);
    profilePhoto.setX(120f);
    profilePhoto.setY(123f);
    photoTask.cancel(true);
    photoTask = new DownloadProfilePhoto(MenuActivity.this, photoUrl);
    //AsyncTask<ImageView, Void, Bitmap> pPhoto = 
    photoTask.execute(profilePhoto);
}

From source file:org.runnerup.export.RunnerUpLiveSynchronizer.java

RunnerUpLiveSynchronizer(Context context) {
    this.context = context;

    Resources res = context.getResources();
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    postUrl = prefs.getString(res.getString(R.string.pref_runneruplive_serveradress), POST_URL);
    formatter = new Formatter(context);
}

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

private void displayProfile() {
    setContentView(R.layout.menu_page);/*from   w ww  . j  a  v a 2s  .com*/
    Log.d(TAG, "...setContentView");

    //display name and profile info
    Resources res = getResources();
    greets = (TextView) findViewById(R.id.student_name);
    greets.setText(String.format(res.getString(R.string.profile_name), firstNameIn, lastNameIn));
    setTextViewFont(Museo700Regular, greets);
    Log.d(TAG, "...Profile Info");

    playBtn = (Button) findViewById(R.id.btn_play);
    playBtn.setOnClickListener(mPlay);
    setButtonFont(ExistenceLightOtf, playBtn);

    infoDialog = new AlertDialog.Builder(MenuActivity.this).create();
    infoDialog.setTitle("Debug Info");
    infoDialog.setButton(RESULT_OK, "OK", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            // Write your code here to execute after dialog closed
        }
    });

    if (debug) {
        //      infoDialog.setTitle("studentId");
        //      infoDialog.setMessage(studentIdIn);
        //      infoDialog.show();
    }

    task.setOnResultsListener(this);
    task.cancel(true);
    task = new SciGamesHttpPoster(MenuActivity.this, baseDbURL + "/pull/return_profile.php");
    task.setOnResultsListener(MenuActivity.this);

    //download photo
    ImageView profilePhoto = (ImageView) findViewById(R.id.profile_image);
    profilePhoto.setTag(photoUrl);
    profilePhoto.setScaleX(1.4f);
    profilePhoto.setScaleY(1.4f);
    profilePhoto.setX(120f);
    profilePhoto.setY(123f);
    photoTask.cancel(true);
    photoTask = new DownloadProfilePhoto(MenuActivity.this, photoUrl);
    //AsyncTask<ImageView, Void, Bitmap> pPhoto = 
    photoTask.execute(profilePhoto);
}

From source file:org.runnerup.export.RunnerUpLive.java

RunnerUpLive(Context context) {
    this.context = context;

    Resources res = context.getResources();
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    postUrl = prefs.getString(res.getString(R.string.pref_runneruplive_serveradress), POST_URL);
    formatter = new Formatter(context);
}

From source file:com.android.mtkex.chips.BaseRecipientAdapter.java

public static List<DirectorySearchParams> setupOtherDirectories(Context context, Cursor directoryCursor,
        Account account) {//from  w  ww.j  av a  2 s  .  co  m
    Log.d(TAG, "[setupOtherDirectories]"); /// M: MTK debug log
    final PackageManager packageManager = context.getPackageManager();
    final List<DirectorySearchParams> paramsList = new ArrayList<DirectorySearchParams>();
    DirectorySearchParams preferredDirectory = null;
    while (directoryCursor.moveToNext()) {
        final long id = directoryCursor.getLong(DirectoryListQuery.ID);

        // Skip the local invisible directory, because the default directory already includes
        // all local results.
        if (id == Directory.LOCAL_INVISIBLE) {
            continue;
        }

        final DirectorySearchParams params = new DirectorySearchParams();
        final String packageName = directoryCursor.getString(DirectoryListQuery.PACKAGE_NAME);
        final int resourceId = directoryCursor.getInt(DirectoryListQuery.TYPE_RESOURCE_ID);
        params.directoryId = id;
        params.displayName = directoryCursor.getString(DirectoryListQuery.DISPLAY_NAME);
        params.accountName = directoryCursor.getString(DirectoryListQuery.ACCOUNT_NAME);
        params.accountType = directoryCursor.getString(DirectoryListQuery.ACCOUNT_TYPE);
        if (packageName != null && resourceId != 0) {
            try {
                final Resources resources = packageManager.getResourcesForApplication(packageName);
                params.directoryType = resources.getString(resourceId);
                if (params.directoryType == null) {
                    Log.e(TAG, "Cannot resolve directory name: " + resourceId + "@" + packageName);
                }
            } catch (NameNotFoundException e) {
                Log.e(TAG, "Cannot resolve directory name: " + resourceId + "@" + packageName, e);
            }
        }

        // If an account has been provided and we found a directory that
        // corresponds to that account, place that directory second, directly
        // underneath the local contacts.
        /// M: Add a condition to make sure no directories would be missed for account with multiple directories
        if (preferredDirectory == null && account != null && account.name.equals(params.accountName)
                && account.type.equals(params.accountType)) {
            preferredDirectory = params;
        } else {
            paramsList.add(params);
        }
    }

    if (preferredDirectory != null) {
        paramsList.add(1, preferredDirectory);
    }

    return paramsList;
}

From source file:com.f16gaming.pathofexilestatistics.PoeEntry.java

public AlertDialog getInfoDialog(Activity activity, Resources res) {
    AlertDialog.Builder builder = new AlertDialog.Builder(activity);
    LayoutInflater inflater = activity.getLayoutInflater();
    View view = inflater.inflate(R.layout.info, null);
    String nameFormat = res.getString(R.string.info_name);
    String accountFormat = res.getString(R.string.info_account);
    String rankFormat = res.getString(R.string.info_rank);
    String levelFormat = res.getString(R.string.info_level);
    String classFormat = res.getString(R.string.info_class);
    String experienceFormat = res.getString(R.string.info_experience);
    ((TextView) view.findViewById(R.id.info_name)).setText(String.format(nameFormat, name));
    ((TextView) view.findViewById(R.id.info_account)).setText(String.format(accountFormat, account));
    ((TextView) view.findViewById(R.id.info_rank)).setText(String.format(rankFormat, rank));
    ((TextView) view.findViewById(R.id.info_level)).setText(String.format(levelFormat, level));
    ((TextView) view.findViewById(R.id.info_class)).setText(String.format(classFormat, className));
    ((TextView) view.findViewById(R.id.info_experience)).setText(String.format(experienceFormat, experience));

    TextView status = (TextView) view.findViewById(R.id.info_status);
    status.setText(online ? R.string.online : R.string.offline);
    status.setTextColor(online ? res.getColor(R.color.online) : res.getColor(R.color.offline));

    builder.setTitle(R.string.info_title).setView(view).setPositiveButton(android.R.string.ok,
            new DialogInterface.OnClickListener() {
                @Override// w w  w  .ja va2s. c  o  m
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            });
    return builder.create();
}