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.google.android.gms.common.internal.zzt.java

@Nullable
public static String a(final Context context, final int n) {
    final String s = null;
    final Resources resources = context.getResources();
    String s2 = s;/*  w  ww . ja v  a 2  s. c  o m*/
    switch (n) {
    default: {
        Log.e("GoogleApiAvailability",
                new StringBuilder(33).append("Unexpected error code ").append(n).toString());
        s2 = s;
        return s2;
    }
    case 20: {
        Log.e("GoogleApiAvailability",
                "The current user profile is restricted and could not use authenticated features.");
        s2 = a(context, "common_google_play_services_restricted_profile_title");
        return s2;
    }
    case 17: {
        Log.e("GoogleApiAvailability", "The specified account could not be signed in.");
        s2 = a(context, "common_google_play_services_sign_in_failed_title");
        return s2;
    }
    case 16: {
        Log.e("GoogleApiAvailability",
                "One of the API components you attempted to connect to is not available.");
        s2 = s;
        return s2;
    }
    case 11: {
        Log.e("GoogleApiAvailability", "The application is not licensed to the user.");
        s2 = s;
        return s2;
    }
    case 5: {
        Log.e("GoogleApiAvailability",
                "An invalid account was specified when connecting. Please provide a valid account.");
        s2 = a(context, "common_google_play_services_invalid_account_title");
        return s2;
    }
    case 10: {
        Log.e("GoogleApiAvailability", "Developer error occurred. Please see logs for detailed information");
        s2 = s;
        return s2;
    }
    case 8: {
        Log.e("GoogleApiAvailability", "Internal error occurred. Please see logs for detailed information");
        s2 = s;
        return s2;
    }
    case 7: {
        Log.e("GoogleApiAvailability", "Network error occurred. Please retry request later.");
        s2 = a(context, "common_google_play_services_network_error_title");
        return s2;
    }
    case 9: {
        Log.e("GoogleApiAvailability", "Google Play services is invalid. Cannot recover.");
        s2 = s;
        return s2;
    }
    case 2: {
        s2 = resources.getString(R$string.common_google_play_services_update_title);
        return s2;
    }
    case 3: {
        s2 = resources.getString(R$string.common_google_play_services_enable_title);
        return s2;
    }
    case 1: {
        s2 = resources.getString(R$string.common_google_play_services_install_title);
    }
    case 4:
    case 6:
    case 18: {
        return s2;
    }
    }
}

From source file:org.witness.ssc.xfer.utils.PublishingUtils.java

public PublishingUtils(Resources res, DBUtils dbutils) {

    this.res = res;
    this.dbutils = dbutils;
    folder = new File(Environment.getExternalStorageDirectory() + res.getString(R.string.rootSDcardFolder));

}

From source file:net.kayateia.lifestream.StreamService.java

private void checkNewImages() {
    Log.i(LOG_TAG, "Checking for new images on server");
    if (!initStorage())
        return;/*from  w  w w. java 2 s  . co  m*/

    // Retrieve our auth token and user parameters. If they're not there, we can't do anything.
    Settings settings = new Settings(this);
    String authToken = settings.getAuthToken();
    if (authToken.isEmpty() || !settings.getEnabled()) {
        Log.i(LOG_TAG, "Not doing download check: not configured, or disabled");
        return;
    }

    // Allow a week back to make sure we didn't miss some due to crashes/race conditions/etc.
    int lastCheck = settings.getLastCheckInt() - (60 * 60 * 24 * 7);
    if (lastCheck < 0)
        lastCheck = ((int) ((new Date()).getTime() / 1000)) - (60 * 60 * 24 * 7);

    final Resources res = getResources();
    final StreamService us = this;
    MediaScannerWrapper scanner = new MediaScannerWrapper(this) {
        @Override
        protected void scanned(String path, Uri uri) {
            // The user directory will be the last path component. We can hash
            // that and make a unique notification ID. This isn't guaranteed to be
            // unique, but for our test purposes, it should work.

            // Convolution: Java has it. This pulls the last component of the path, and then
            // further pulls the "Lifestream_" prefix to get the actual user name.
            File pathFile = new File(path);
            File withoutFilenameFile = pathFile.getParentFile();
            String withoutParentDir = withoutFilenameFile.getParent();
            String userDir = path.substring(withoutParentDir.length() + 1,
                    withoutFilenameFile.getPath().length());
            userDir = userDir.substring(USERDIR_PREFIX.length());

            // Make a hash of it.
            int hash = userDir.hashCode() % 100000;
            int notifyId = NOTIFY_ID + 100 + hash;

            Notifications.NotifyDownload(us, notifyId, true, res.getString(R.string.download_ticker),
                    /*res.getString(R.string.download_title)*/ "From " + userDir, getMessage(path), uri);
        }
    };
    try {
        HashMap<String, String> params = new HashMap<String, String>();
        params.put("auth", authToken);
        params.put("date", "" + lastCheck);

        // Save the current time as a cutoff for future checks. We do it here so as
        // to be conservative when setting the cutoff for the next check.
        Date newLastCheck = new Date();

        String notificationMsg = res.getString(R.string.download_detail);

        String baseUrl = Settings.GetBaseUrl();
        URL url = new URL(baseUrl + "check-images.php");
        String result = HttpMultipartUpload.DownloadString(url, params, this);
        String[] users, files, paths;
        try {
            JSONObject root = new JSONObject(result);
            JSONArray images = root.getJSONArray("images");
            users = new String[images.length()];
            files = new String[images.length()];
            paths = new String[images.length()];

            for (int i = 0; i < images.length(); ++i) {
                JSONObject obj = images.getJSONObject(i);
                users[i] = obj.getString("user");
                files[i] = obj.getString("file");
                paths[i] = obj.getString("path");
            }

            String nmsg = root.optString("message");
            if (!nmsg.equals(""))
                notificationMsg = nmsg;
        } catch (JSONException e) {
            if (settings.getVerbose()) {
                Notifications.NotifyError(this, NOTIFY_ID, true, res.getString(R.string.fail_ticker),
                        res.getString(R.string.fail_title), res.getString(R.string.fail_download));
            }
            Log.w(LOG_TAG, "Can't parse download response: " + result);
            return;
        }

        // We'll just save the last one so that it will open the top image in the stack.
        String galleryPath = null;
        for (int i = 0; i < users.length; ++i) {
            // We're expecting here: user, image name, relative URL path
            String user = users[i];
            String imageName = files[i];
            String urlPath = paths[i];

            // Turn the file.jpg into file_user.jpg.
            // http://stackoverflow.com/questions/4545937/java-splitting-the-filename-into-a-base-and-extension
            String[] fileParts = imageName.split("\\.(?=[^\\.]+$)");
            String localFileName = fileParts[0] + "_" + user + "." + fileParts[1];
            String localPath = getStorageForUser(user).concat(File.separator).concat(localFileName);

            // Does it exist already?
            File localFile = new File(localPath);
            if (localFile.exists()) {
                Log.i(LOG_TAG, "Skipping " + urlPath + " because it already exists");
            } else {
                Log.i(LOG_TAG, "Download file: " + urlPath + " to " + localFileName);
                URL dlurl = new URL(baseUrl + urlPath);
                HttpMultipartUpload.DownloadFile(dlurl, localFile, null, this);
                scanner.addFile(localFile.getAbsolutePath(), notificationMsg);
                galleryPath = localFile.getAbsolutePath();
            }
        }
        scanner.scan();
        Log.i(LOG_TAG, "Download check complete");

        // Success! Update the last check time.
        settings.setLastCheck(newLastCheck);
        settings.commit();
    } catch (IOException e) {
        if (settings.getVerbose()) {
            Notifications.NotifyError(this, NOTIFY_ID, true, res.getString(R.string.fail_ticker),
                    res.getString(R.string.fail_title), res.getString(R.string.fail_download));
        }
        Log.w(LOG_TAG, "Download failed", e);
    }
}

From source file:cc.flydev.launcher.Folder.java

/**
 * Used to inflate the Workspace from XML.
 *
 * @param context The application's context.
 * @param attrs The attribtues set containing the Workspace's customization values.
 *///from w  w  w . j a  v a  2 s .c  o m
public Folder(Context context, AttributeSet attrs) {
    super(context, attrs);

    LauncherAppState app = LauncherAppState.getInstance();
    DeviceProfile grid = app.getDynamicGrid().getDeviceProfile();
    setAlwaysDrawnWithCacheEnabled(false);
    mInflater = LayoutInflater.from(context);
    mIconCache = app.getIconCache();

    Resources res = getResources();
    mMaxCountX = (int) grid.numColumns;
    mMaxCountY = (int) grid.numRows;
    mMaxNumItems = mMaxCountX * mMaxCountY;

    mInputMethodManager = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);

    mExpandDuration = res.getInteger(R.integer.config_folderAnimDuration);

    if (sDefaultFolderName == null) {
        sDefaultFolderName = res.getString(R.string.folder_name);
    }
    if (sHintText == null) {
        sHintText = res.getString(R.string.folder_hint_text);
    }
    mLauncher = (Launcher) context;
    // We need this view to be focusable in touch mode so that when text editing of the folder
    // name is complete, we have something to focus on, thus hiding the cursor and giving
    // reliable behvior when clicking the text field (since it will always gain focus on click).
    setFocusableInTouchMode(true);
}

From source file:com.google.android.apps.santatracker.map.SantaMapActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // App Measurement
    mMeasurement = FirebaseAnalytics.getInstance(this);
    MeasurementManager.recordScreenView(mMeasurement, getString(R.string.analytics_screen_tracker));

    // [ANALYTICS SCREEN]: Tracker
    AnalyticsManager.sendScreenView(R.string.analytics_screen_tracker);

    // Needs to be called before setting the content view
    supportRequestWindowFeature(Window.FEATURE_ACTION_BAR_OVERLAY);

    setContentView(R.layout.activity_map);

    // Set up timer to remove screen lock
    resetScreenTimer();/*from  w  w w.jav a2s  . co  m*/

    mAccessibilityManager = (AccessibilityManager) getSystemService(ACCESSIBILITY_SERVICE);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    ActionBar actionBar = getSupportActionBar();
    Resources resources = getResources();
    if (actionBar != null) {
        // set visibility flags *AFTER* values have been set,
        // otherwise nothing is displayed on Galaxy devices
        actionBar.setDisplayHomeAsUpEnabled(true);
        actionBar.setHomeButtonEnabled(true);
        actionBar.setDisplayShowTitleEnabled(false);
    }

    LOST_CONTACT_STRING = resources.getString(R.string.lost_contact_with_santa);
    ANNOUNCE_ARRIVED_AT = resources.getString(R.string.santa_is_now_arriving_in_x);
    ARRIVING_IN = resources.getString(R.string.arriving_in);
    DEPARTING_IN = resources.getString(R.string.departing_in);
    NO_NEXT_DESTINATION = resources.getString(R.string.no_next_destination);
    CURRENT_LOCATION = resources.getString(R.string.current_location);
    NEXT_LOCATION = resources.getString(R.string.next_destination);

    // Concatenate String for 'travel to' announcement
    StringBuilder sb = new StringBuilder();
    sb.append(resources.getString(R.string.in_transit));
    sb.append(" ");
    sb.append(resources.getString(R.string.next_destination));
    sb.append(" %s");
    ANNOUNCE_TRAVEL_TO = sb.toString();
    sb.setLength(0);

    // Get all fragments
    mMapFragment = (SantaMapFragment) getSupportFragmentManager().findFragmentById(R.id.fragment_map);

    mButtonTop = (ImageButton) findViewById(R.id.top);
    mButtonTop.setOnClickListener(mOnClickListener);
    mRecyclerView = (RecyclerView) findViewById(R.id.stream);
    mSupportStreetView = Intents.canHandleStreetView(this);
    mRecyclerView.setHasFixedSize(true);
    mLayoutManager = new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false);
    mRecyclerView.setLayoutManager(mLayoutManager);
    mRecyclerView.addItemDecoration(new SeparatorDecoration(this));
    mRecyclerView.addOnScrollListener(mOnScrollListener);
    mAdapter = new CardAdapter(getApplicationContext(), mCardAdapterListener);
    mAdapter.setHasStableIds(true);
    mRecyclerView.setAdapter(mAdapter);

    if (NotificationDataCastManager.checkGooglePlayServices(this)) {
        mCastManager = SantaApplication.getCastManager(this);
    }

    // Santacam button
    mSantaCamButton = (SantaCamButton) findViewById(R.id.santacam);
    mSantaCamButton.setOnClickListener(mOnClickListener);
    if (mMapFragment.isInSantaCam()) {
        mSantaCamButton.setVisibility(View.GONE);
    }

    View bottomSheet = findViewById(R.id.bottom_sheet);
    if (bottomSheet != null) {
        mBottomSheetBehavior = (BottomSheetBehavior) ((CoordinatorLayout.LayoutParams) bottomSheet
                .getLayoutParams()).getBehavior();
        mBottomSheetBehavior.setBottomSheetListener(mBottomSheetListener);
    }

    findViewById(R.id.main_touchinterceptor).setOnTouchListener(mInterceptorListener);
}

From source file:com.hichinaschool.flashcards.libanki.Collection.java

public HashMap<String, String> _renderQA(Object[] data, List<String> args) {
    // data is [cid, nid, mid, did, ord, tags, flds]
    // unpack fields and create dict
    String[] flist = Utils.splitFields((String) data[6]);
    Map<String, String> fields = new HashMap<String, String>();
    long modelId = (Long) data[2];
    JSONObject model = mModels.get(modelId);
    Map<String, Pair<Integer, JSONObject>> fmap = mModels.fieldMap(model);
    for (String fname : fmap.keySet()) {
        fields.put(fname, flist[fmap.get(fname).first]);
    }/*from   www . ja  va 2s. c  om*/
    fields.put("Tags", ((String) data[5]).trim());
    try {
        fields.put("Type", (String) model.get("name"));
        fields.put("Deck", mDecks.name((Long) data[3]));
        JSONObject template;
        if (model.getInt("type") == Sched.MODEL_STD) {
            template = model.getJSONArray("tmpls").getJSONObject((Integer) data[4]);
        } else {
            template = model.getJSONArray("tmpls").getJSONObject(0);
        }
        fields.put("Card", template.getString("name"));
        fields.put("c" + (((Integer) data[4]) + 1), "1");

        // render q & a
        HashMap<String, String> d = new HashMap<String, String>();
        try {
            d.put("id", Long.toString((Long) data[0]));
            String qfmt = template.getString("qfmt");
            String afmt = template.getString("afmt");
            String html;
            String format;

            // runFilter mungeFields for type "q"
            Models.fieldParser fparser = new Models.fieldParser(fields);
            Matcher m = fClozePattern.matcher(qfmt);
            format = m.replaceFirst(String.format(Locale.US, "{{cq:%d:", ((Integer) data[4]) + 1));
            m = fAltClozePattern.matcher(format);
            format = m.replaceFirst(String.format(Locale.US, "<%%cq:%d:", ((Integer) data[4]) + 1));
            html = mModels.getCmpldTemplate(format).execute(fparser);
            html = (String) AnkiDroidApp.getHooks().runFilter("mungeQA", html, "q", fields, model, data, this);
            d.put("q", html);
            // empty cloze?
            if (model.getInt("type") == Sched.MODEL_CLOZE) {
                if (getModels()._availClozeOrds(model, (String) data[6], false).size() == 0) {
                    d.put("q", "Please edit this note and add some cloze deletions.");
                }
            }
            fields.put("FrontSide", mMedia.stripAudio(d.get("q")));

            // runFilter mungeFields for type "a"
            fparser = new Models.fieldParser(fields);
            m = fClozePattern.matcher(afmt);
            format = m.replaceFirst(String.format(Locale.US, "{{ca:%d:", ((Integer) data[4]) + 1));
            m = fAltClozePattern.matcher(format);
            format = m.replaceFirst(String.format(Locale.US, "<%%ca:%d:", ((Integer) data[4]) + 1));
            html = mModels.getCmpldTemplate(format).execute(fparser);
            html = (String) AnkiDroidApp.getHooks().runFilter("mungeQA", html, "a", fields, model, data, this);
            d.put("a", html);
            // empty cloze?
            if (model.getInt("type") == Sched.MODEL_CLOZE) {
                if (getModels()._availClozeOrds(model, (String) data[6], false).size() == 0) {
                    d.put("q",
                            AnkiDroidApp.getAppResources().getString(
                                    com.hichinaschool.flashcards.anki.R.string.empty_cloze_warning,
                                    "<a href=" + HELP_SITE + "#cloze>"
                                            + AnkiDroidApp.getAppResources().getString(
                                                    com.hichinaschool.flashcards.anki.R.string.help_cloze)
                                            + "</a>"));
                }
            }
        } catch (MustacheException e) {
            Resources res = AnkiDroidApp.getAppResources();

            String templateError = String.format(TEMPLATE_ERROR, res.getString(R.string.template_error),
                    res.getString(R.string.template_error_detail), e.getMessage(),
                    res.getString(R.string.note_type), model.getString("name"),
                    res.getString(R.string.card_type), template.getString("name"),
                    res.getString(R.string.template_error_fix));
            d.put("q", templateError);
            d.put("a", templateError);
        }

        return d;
    } catch (JSONException e) {
        throw new RuntimeException(e);
    }
}

From source file:com.nit.libanki.Collection.java

public HashMap<String, String> _renderQA(Object[] data, List<String> args) {
    // data is [cid, nid, mid, did, ord, tags, flds]
    // unpack fields and create dict
    String[] flist = Utils.splitFields((String) data[6]);
    Map<String, String> fields = new HashMap<String, String>();
    long modelId = (Long) data[2];
    JSONObject model = mModels.get(modelId);
    Map<String, Pair<Integer, JSONObject>> fmap = mModels.fieldMap(model);
    for (String fname : fmap.keySet()) {
        fields.put(fname, flist[fmap.get(fname).first]);
    }// w  ww.j  a v  a  2 s  .  c  o  m
    fields.put("Tags", ((String) data[5]).trim());
    try {
        fields.put("Type", (String) model.get("name"));
        fields.put("Deck", mDecks.name((Long) data[3]));
        JSONObject template;
        if (model.getInt("type") == Sched.MODEL_STD) {
            template = model.getJSONArray("tmpls").getJSONObject((Integer) data[4]);
        } else {
            template = model.getJSONArray("tmpls").getJSONObject(0);
        }
        fields.put("Card", template.getString("name"));
        fields.put("c" + (((Integer) data[4]) + 1), "1");

        // render q & a
        HashMap<String, String> d = new HashMap<String, String>();
        try {
            d.put("id", Long.toString((Long) data[0]));
            String qfmt = template.getString("qfmt");
            String afmt = template.getString("afmt");
            String html;
            String format;

            // runFilter mungeFields for type "q"
            Models.fieldParser fparser = new Models.fieldParser(fields);
            Matcher m = fClozePattern.matcher(qfmt);
            format = m.replaceFirst(String.format(Locale.US, "{{cq:%d:", ((Integer) data[4]) + 1));
            m = fAltClozePattern.matcher(format);
            format = m.replaceFirst(String.format(Locale.US, "<%%cq:%d:", ((Integer) data[4]) + 1));
            html = mModels.getCmpldTemplate(format).execute(fparser);
            html = (String) AnkiDroidApp.getHooks().runFilter("mungeQA", html, "q", fields, model, data, this);
            d.put("q", html);
            // empty cloze?
            if (model.getInt("type") == Sched.MODEL_CLOZE) {
                if (getModels()._availClozeOrds(model, (String) data[6], false).size() == 0) {
                    d.put("q", "Please edit this note and add some cloze deletions.");
                }
            }
            fields.put("FrontSide", mMedia.stripAudio(d.get("q")));

            // runFilter mungeFields for type "a"
            fparser = new Models.fieldParser(fields);
            m = fClozePattern.matcher(afmt);
            format = m.replaceFirst(String.format(Locale.US, "{{ca:%d:", ((Integer) data[4]) + 1));
            m = fAltClozePattern.matcher(format);
            format = m.replaceFirst(String.format(Locale.US, "<%%ca:%d:", ((Integer) data[4]) + 1));
            html = mModels.getCmpldTemplate(format).execute(fparser);
            html = (String) AnkiDroidApp.getHooks().runFilter("mungeQA", html, "a", fields, model, data, this);
            d.put("a", html);
            // empty cloze?
            if (model.getInt("type") == Sched.MODEL_CLOZE) {
                if (getModels()._availClozeOrds(model, (String) data[6], false).size() == 0) {
                    d.put("q",
                            AnkiDroidApp.getAppResources()
                                    .getString(com.nit.vicky.R.string.empty_cloze_warning,
                                            "<a href="
                                                    + HELP_SITE + "#cloze>" + AnkiDroidApp.getAppResources()
                                                            .getString(com.nit.vicky.R.string.help_cloze)
                                                    + "</a>"));
                }
            }
        } catch (MustacheException e) {
            Resources res = AnkiDroidApp.getAppResources();

            String templateError = String.format(TEMPLATE_ERROR, res.getString(R.string.template_error),
                    res.getString(R.string.template_error_detail), e.getMessage(),
                    res.getString(R.string.note_type), model.getString("name"),
                    res.getString(R.string.card_type), template.getString("name"),
                    res.getString(R.string.template_error_fix));
            d.put("q", templateError);
            d.put("a", templateError);
        }

        return d;
    } catch (JSONException e) {
        throw new RuntimeException(e);
    }
}

From source file:com.hichinaschool.flashcards.libanki.Collection.java

/** Undo menu item name, or "" if undo unavailable. */
public String undoName(Resources res) {
    if (mUndo.size() > 0) {
        int undoType = ((Integer) mUndo.getLast()[0]).intValue();
        if (undoType >= 0 && undoType < fUndoNames.length) {
            return res.getString(fUndoNames[undoType]);
        }/*www  .j a va2s . co  m*/
    }
    return "";
}

From source file:com.aidy.launcher3.ui.folder.Folder.java

/**
 * Used to inflate the Workspace from XML.
 * /*  www  .j  av a2  s  . c om*/
 * @param context
 *            The application's context.
 * @param attrs
 *            The attribtues set containing the Workspace's customization
 *            values.
 */
public Folder(Context context, AttributeSet attrs) {
    super(context, attrs);

    LauncherAppState app = LauncherAppState.getInstance();
    DeviceProfile grid = app.getDynamicGrid().getDeviceProfile();
    setAlwaysDrawnWithCacheEnabled(false);
    mInflater = LayoutInflater.from(context);
    mIconCache = app.getIconCache();

    Resources res = getResources();
    mMaxCountX = (int) grid.numColumns;
    mMaxCountY = (int) grid.numRows;
    mMaxNumItems = mMaxCountX * mMaxCountY;

    mInputMethodManager = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);

    mExpandDuration = res.getInteger(R.integer.config_folderAnimDuration);

    if (sDefaultFolderName == null) {
        sDefaultFolderName = res.getString(R.string.folder_name);
    }
    if (sHintText == null) {
        sHintText = res.getString(R.string.folder_hint_text);
    }
    mLauncher = (Launcher) context;
    // We need this view to be focusable in touch mode so that when text
    // editing of the folder
    // name is complete, we have something to focus on, thus hiding the
    // cursor and giving
    // reliable behvior when clicking the text field (since it will always
    // gain focus on click).
    setFocusableInTouchMode(true);
}

From source file:com.mibr.android.intelligentreminder.INeedToo.java

public String getHeading() {
    String trialVersionBlurb = "";
    if (this.isTestVersion()) {
        trialVersionBlurb = "(Trial)";
    }/*from  ww  w .j  a v  a  2  s .  c  o  m*/
    Resources res = getResources();
    return String.format(res.getString(R.string.app_title), trialVersionBlurb);
}