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:org.wso2.iot.agent.utils.CommonUtils.java

public static AppRestriction getAppRuntimePermissionTypeAndList(Operation operation,
        ResultPayload resultBuilder, Resources resources) throws AndroidAgentException {
    AppRestriction appRestriction = new AppRestriction();
    JSONArray restrictedApps = null;//w ww .j ava2s .  c o  m
    try {
        JSONObject payload = new JSONObject(operation.getPayLoad().toString());
        appRestriction.setRestrictionType((String) payload.get(Constants.AppRuntimePermission.PERMISSION_TYPE));
        if (!payload.isNull(Constants.AppRuntimePermission.PERMITTED_APPS)) {
            restrictedApps = payload.getJSONArray(Constants.AppRuntimePermission.PERMITTED_APPS);
        }
    } 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 (restrictedApps != null) {
        for (int i = 0; i < restrictedApps.length(); i++) {
            try {
                restrictedPackages.add((String) ((JSONObject) restrictedApps.get(i))
                        .get(Constants.AppRestriction.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.android.settings.sim.SimBootReceiver.java

private void createNotification(Context context) {
    final Resources resources = context.getResources();

    NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
            .setSmallIcon(R.drawable.ic_sim_card_alert_white_48dp)
            .setColor(resources.getColor(R.color.sim_noitification))
            .setContentTitle(resources.getString(R.string.sim_notification_title))
            .setContentText(resources.getString(R.string.sim_notification_summary));
    Intent resultIntent = new Intent(context, SimSettingsActivity.class);
    resultIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    PendingIntent resultPendingIntent = PendingIntent.getActivity(context, 0, resultIntent,
            PendingIntent.FLAG_CANCEL_CURRENT);
    builder.setContentIntent(resultPendingIntent);
    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(NOTIFICATION_ID, builder.build());
}

From source file:com.battlelancer.seriesguide.extensions.ExtensionManager.java

/**
 * Queries the {@link android.content.pm.PackageManager} for any installed {@link
 * com.battlelancer.seriesguide.api.SeriesGuideExtension} extensions. Their info is extracted
 * into {@link com.battlelancer.seriesguide.extensions.ExtensionManager.Extension} objects.
 *///from   ww w . ja v  a 2  s  . c  om
public List<Extension> queryAllAvailableExtensions() {
    Intent queryIntent = new Intent(SeriesGuideExtension.ACTION_SERIESGUIDE_EXTENSION);
    PackageManager pm = mContext.getPackageManager();
    List<ResolveInfo> resolveInfos = pm.queryIntentServices(queryIntent, PackageManager.GET_META_DATA);

    List<Extension> extensions = new ArrayList<>();
    for (ResolveInfo info : resolveInfos) {
        Extension extension = new Extension();
        // get label, icon and component name
        extension.label = info.loadLabel(pm).toString();
        extension.icon = info.loadIcon(pm);
        extension.componentName = new ComponentName(info.serviceInfo.packageName, info.serviceInfo.name);
        // get description
        Context packageContext;
        try {
            packageContext = mContext.createPackageContext(extension.componentName.getPackageName(), 0);
            Resources packageRes = packageContext.getResources();
            extension.description = packageRes.getString(info.serviceInfo.descriptionRes);
        } catch (SecurityException | PackageManager.NameNotFoundException | Resources.NotFoundException e) {
            Timber.e(e, "Reading description for extension " + extension.componentName + " failed");
            extension.description = "";
        }
        // get (optional) settings activity
        Bundle metaData = info.serviceInfo.metaData;
        if (metaData != null) {
            String settingsActivity = metaData.getString("settingsActivity");
            if (!TextUtils.isEmpty(settingsActivity)) {
                extension.settingsActivity = ComponentName
                        .unflattenFromString(info.serviceInfo.packageName + "/" + settingsActivity);
            }
        }

        Timber.d("queryAllAvailableExtensions: found extension " + extension.label + " "
                + extension.componentName);
        extensions.add(extension);
    }

    return extensions;
}

From source file:com.nttec.everychan.chans.makaba.MakabaJsonMapper.java

static BoardModel mapBoardModel(JSONObject source, boolean fromMobileBoardsList, Resources resources)
        throws JSONException {
    BoardModel model = defaultBoardModel(source.getString(fromMobileBoardsList ? "id" : "Board"), resources);

    if (fromMobileBoardsList) {
        model.boardDescription = source.getString("name");
        model.boardCategory = source.getString("category");

        model.defaultUserName = getStringSafe(source, "default_name", "?");
        model.bumpLimit = getIntSafe(source, "bump_limit", 500);
        model.lastPage = getIntSafe(source, "pages", 10) - 1;
    } else {// w w w. j a va  2 s.c o  m
        model.boardDescription = source.getString("BoardName");
        model.boardCategory = null;

        model.defaultUserName = "?";
        model.bumpLimit = 500;
        try {
            model.lastPage = source.getJSONArray("pages").length() - 1;
        } catch (Exception e) {
            model.lastPage = 9;
        }
    }

    try {
        JSONArray iconsArray = source.getJSONArray("icons");
        if (iconsArray.length() > 0) {
            String[] icons = new String[iconsArray.length() + 1];
            icons[0] = resources.getString(R.string.makaba_no_icon);
            for (int i = 0; i < iconsArray.length(); ++i) {
                icons[iconsArray.getJSONObject(i).getInt("num")] = iconsArray.getJSONObject(i)
                        .getString("name");
            }
            for (int i = 0; i < icons.length; ++i) {
                if (icons[i] == null)
                    throw new Exception();
            }
            model.allowIcons = true;
            model.iconDescriptions = icons;
        }
    } catch (Exception e) {
        /*  , ?,  ??   ?,   ?  */ }

    return model;
}

From source file:com.eleybourn.bookcatalogue.goodreads.GoodreadsRegister.java

public void setupViews() {
    final Resources res = this.getResources();
    /* GR Reg Link */
    TextView register = (TextView) findViewById(R.id.goodreads_url);
    register.setOnClickListener(new OnClickListener() {
        @Override/*from  ww  w .  j a  va  2 s. co  m*/
        public void onClick(View v) {
            String url = res.getString(R.string.goodreads_url);
            Uri uri = Uri.parse(url);
            Intent loadweb = new Intent(Intent.ACTION_VIEW, uri);
            startActivity(loadweb);
            return;
        }
    });

    /* Auth button */
    Button devkeyLink = (Button) findViewById(R.id.authorize);
    devkeyLink.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            requestAuthorizationInBackground(GoodreadsRegister.this);
            return;
        }
    });

    /* Forget credentials */
    boolean hasCred = GoodreadsManager.hasCredentials();
    View blurb = findViewById(R.id.forget_blurb);
    Button blurb_button = (Button) findViewById(R.id.forget);
    if (hasCred) {
        blurb.setVisibility(View.VISIBLE);
        blurb_button.setVisibility(View.VISIBLE);
        blurb_button.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                GoodreadsManager.forgetCredentials();
            }
        });
    } else {
        blurb.setVisibility(View.GONE);
        blurb_button.setVisibility(View.GONE);
    }
}

From source file:com.example.android.AudioArchive.model.MusicProvider.java

private MediaBrowserCompat.MediaItem createBrowsableMediaItemForRoot(Resources resources) {
    MediaDescriptionCompat description = new MediaDescriptionCompat.Builder()
            .setMediaId(MEDIA_ID_MUSICS_BY_GENRE).setTitle(resources.getString(R.string.browse_genres))
            .setSubtitle(resources.getString(R.string.browse_genre_subtitle))
            .setIconUri(Uri.parse("android.resource://" + "com.example.android.uamp/drawable/ic_by_genre"))
            .build();/*w ww . j ava  2s .c  o m*/
    return new MediaBrowserCompat.MediaItem(description, MediaBrowserCompat.MediaItem.FLAG_BROWSABLE);
}

From source file:org.dvbviewer.controller.ui.fragments.TaskList.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setHasOptionsMenu(true);/* www  .j  av a2  s  .c om*/
    setRetainInstance(true);
    Resources r = getResources();
    sAdapter = new CategoryAdapter(getSherlockActivity());

    TaskAdapter system = new TaskAdapter(getSherlockActivity());
    system.addItem(new Task(r.getString(R.string.WOL), WOL_COMMAND));
    system.addItem(new Task(r.getString(R.string.Standby), "Standby"));
    system.addItem(new Task(r.getString(R.string.Hibernate), "Hibernate"));
    system.addItem(new Task(r.getString(R.string.Shutdown), "Shutdown"));

    TaskAdapter epg = new TaskAdapter(getSherlockActivity());
    epg.addItem(new Task(r.getString(R.string.EPGStart), "EPGStart"));
    epg.addItem(new Task(r.getString(R.string.EPGStop), "EPGStop"));
    epg.addItem(new Task(r.getString(R.string.AutoTimer), "AutoTimer"));

    TaskAdapter rec = new TaskAdapter(getSherlockActivity());
    rec.addItem(new Task(r.getString(R.string.RefreshDB), "RefreshDB"));
    rec.addItem(new Task(r.getString(R.string.CleanupDB), "CleanupDB"));
    rec.addItem(new Task(r.getString(R.string.RebuildRecordedHistory), "RebuildRecordedHistory"));
    rec.addItem(new Task(r.getString(R.string.ClearRecordingHistory), "ClearRecordingHistory"));
    rec.addItem(new Task(r.getString(R.string.ClearRecordingStats), "ClearRecordingStats"));

    TaskAdapter media = new TaskAdapter(getSherlockActivity());
    media.addItem(new Task(r.getString(R.string.UpdateMediaLibrary), "UpdateVideoDB"));
    media.addItem(new Task(r.getString(R.string.CleanupPhotoDB), "CleanupPhotoDB"));
    media.addItem(new Task(r.getString(R.string.CleanupVideoDB), "CleanupVideoDB"));
    media.addItem(new Task(r.getString(R.string.RebuildVideoDB), "RebuildVideoDB"));
    media.addItem(new Task(r.getString(R.string.RebuildAudioDB), "RebuildAudioDB"));
    media.addItem(new Task(r.getString(R.string.RebuildPhotoDB), "RebuildPhotoDB"));
    media.addItem(new Task(r.getString(R.string.ClearAudioStats), "ClearAudioStats"));
    media.addItem(new Task(r.getString(R.string.ClearVideoStats), "ClearVideoStats"));
    media.addItem(new Task(r.getString(R.string.ClearPhotoStats), "ClearPhotoStats"));

    sAdapter.addSection("System", system);
    sAdapter.addSection("EPG", epg);
    sAdapter.addSection("Aufnahmen", rec);
    sAdapter.addSection("Mediadateien", media);
    // mAdapter = new TaskAdapter(getActivity());

}

From source file:com.example.hp.smartstor.CloudMusicManager.uamp.model.MusicProvider.java

private MediaBrowserCompat.MediaItem createBrowsableMediaItemForRoot(Resources resources) {
    MediaDescriptionCompat description = new MediaDescriptionCompat.Builder()
            .setMediaId(MEDIA_ID_MUSICS_BY_GENRE).setTitle(resources.getString(R.string.browse_genres))
            .setSubtitle(resources.getString(R.string.browse_genre_subtitle))
            .setIconUri(Uri.parse("android.resource://" + "com.example.hp.smartstor/drawable/ic_by_genre"))
            .build();//from  w w w.j av a  2s  .  com
    return new MediaBrowserCompat.MediaItem(description, MediaBrowserCompat.MediaItem.FLAG_BROWSABLE);
}

From source file:com.bdevlin.apps.ui.activity.core.HelpActivity.java

private void initFragments() {
    mFragments = new ArrayList<>();
    Resources res = getResources();

    String[] helpTitles = res.getStringArray(R.array.help_screens);

    int[] helpKeys = res.getIntArray(R.array.help_keys);
    int length = helpTitles.length;

    String message = String.format(res.getString(R.string.welcome_messages), "Help", length);
    CharSequence styledText = Html.fromHtml(message);

    if (helpKeys.length != length) {
        if (DEBUG)
            Log.e(TAG, "Mismatch between keys length " + helpKeys.length + " and titles " + length);
        length = Math.min(length, helpKeys.length);
    }//from w  ww  .  j  a v a2 s. c o m

    for (int i = 0; i < length; i++) {
        HelpListFragment fragment = new HelpListFragment();

        Bundle args = new Bundle();
        int index = helpKeys[i];
        String idKey = "help" + index;
        int contentId = res.getIdentifier(idKey, "string", getPackageName());
        CharSequence content = getText(contentId);
        args.putCharSequence(HelpListFragment.CONTENT, content);
        args.putString(HelpListFragment.TITLE, helpTitles[index]);
        args.putCharSequence(HelpListFragment.MESSAGE, styledText);

        fragment.setArguments(args);
        mFragments.add(fragment);
    }

    // few magic numbers for good luck...
    mQueryIndex = new HashMap<ListQuery, Integer>();

    mQueryIndex.put(ListQuery.inbox, 1);
    mQueryIndex.put(ListQuery.dueToday, 2);
    mQueryIndex.put(ListQuery.dueNextWeek, 2);
    mQueryIndex.put(ListQuery.dueNextMonth, 2);
    mQueryIndex.put(ListQuery.nextTasks, 3);
    mQueryIndex.put(ListQuery.project, 4);
    mQueryIndex.put(ListQuery.context, 5);
    mQueryIndex.put(ListQuery.custom, 6);
    mQueryIndex.put(ListQuery.tickler, 7);
}

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

public void onResultsSucceeded(String[] serverResponseStrings, JSONObject serverResponseJSON)
        throws JSONException {

    //download photo
    ImageView profilePhoto = (ImageView) findViewById(R.id.imageView1);
    profilePhoto.setTag(photoUrl);/*w ww . j ava 2  s . co  m*/

    photoTask.cancel(true);
    photoTask = new DownloadProfilePhoto(ProfileActivity.this, photoUrl);
    //AsyncTask<ImageView, Void, Bitmap> pPhoto = 
    photoTask.execute(profilePhoto);

    //update all text fields
    Resources res = getResources();
    TextView greets = (TextView) findViewById(R.id.greeting);
    greets.setText(String.format(res.getString(R.string.greeting), serverResponseStrings[2],
            serverResponseStrings[3]));

    TextView fname = (TextView) findViewById(R.id.first_name);
    fname.setText(String.format(res.getString(R.string.profile_first_name), serverResponseStrings[2]));

    TextView lname = (TextView) findViewById(R.id.last_name);
    lname.setText(String.format(res.getString(R.string.profile_last_name), serverResponseStrings[3]));

    TextView school = (TextView) findViewById(R.id.school_name);
    school.setText(String.format(res.getString(R.string.profile_school_name), "from DB"));

    TextView teacher = (TextView) findViewById(R.id.teacher_name);
    teacher.setText(String.format(res.getString(R.string.profile_teacher_name), "from DB"));

    TextView classid = (TextView) findViewById(R.id.class_id);
    classid.setText(String.format(res.getString(R.string.profile_classid), serverResponseStrings[7]));

    TextView mmass = (TextView) findViewById(R.id.mass);
    mmass.setText(String.format(res.getString(R.string.profile_mass), serverResponseStrings[5]));

    TextView memail = (TextView) findViewById(R.id.email);
    memail.setText(String.format(res.getString(R.string.profile_email), serverResponseStrings[6]));

    TextView mpass = (TextView) findViewById(R.id.password);
    mpass.setText(String.format(res.getString(R.string.profile_password), serverResponseStrings[8]));

    TextView mRfid = (TextView) findViewById(R.id.rfid);
    mRfid.setText(String.format(res.getString(R.string.profile_rfid), serverResponseStrings[9]));

    Log.d(TAG, "...Profile Info");

}