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.emm.agent.utils.CommonUtils.java

/**
 * Clear application data./*from w w  w. j a  va2  s .  com*/
 * @param context - Application context.
 */
public static void clearAppData(Context context) throws AndroidAgentException {
    try {
        revokePolicy(context);
    } catch (SecurityException e) {
        throw new AndroidAgentException("Error occurred while revoking policy", e);
    } finally {
        Resources resources = context.getResources();
        SharedPreferences mainPref = context.getSharedPreferences(Constants.AGENT_PACKAGE,
                Context.MODE_PRIVATE);
        Editor editor = mainPref.edit();
        editor.putBoolean(Constants.PreferenceFlag.IS_AGREED, false);
        editor.putString(Constants.PreferenceFlag.REG_ID, null);
        editor.putBoolean(Constants.PreferenceFlag.REGISTERED, false);
        editor.putString(Constants.PreferenceFlag.IP, null);
        editor.putString(Constants.PreferenceFlag.NOTIFIER_TYPE, null);
        editor.putString(context.getResources().getString(R.string.shared_pref_sender_id),
                resources.getString(R.string.shared_pref_default_string));
        editor.putString(context.getResources().getString(R.string.shared_pref_eula),
                resources.getString(R.string.shared_pref_default_string));
        editor.putBoolean(Constants.PreferenceFlag.DEVICE_ACTIVE, false);
        editor.commit();
        Preference.clearPreferences(context);
        clearClientCredentials(context);
        context.deleteDatabase(Constants.EMM_DB);
    }
}

From source file:com.crea_si.eviacam.service.EngineControl.java

private void standby() {
    mPowerManagement.unlockFullPower();// w  w  w .  j a  va 2s.  c o m
    mPowerManagement.setSleepEnabled(true); // Enable sleep call
    mServiceNotification.update(ServiceNotification.NOTIFICATION_ACTION_RESUME);

    Resources res = mAccessibilityService.getResources();
    String t = String.format(res.getString(R.string.pointer_stopped_toast),
            Preferences.get().getTimeWithoutDetectionEntryValue());
    EVIACAM.LongToast(mAccessibilityService, t);

    mEngine.standby();
}

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

public static AppRestriction getAppRestrictionTypeAndList(Operation operation, ResultPayload resultBuilder,
        Resources resources) throws AndroidAgentException {
    AppRestriction appRestriction = new AppRestriction();
    JSONArray restrictedApps = null;//  w  w w . jav a2  s  .co  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)) {
            restrictedApps = 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 (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.aimfire.gallery.service.SamplesDownloader.java

@Override
protected void onHandleIntent(Intent intent) {
    if (BuildConfig.DEBUG)
        Log.d(TAG, "onHandleIntent");

    Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);

    Resources res = getResources();
    String httpDir = res.getString(R.string.samples_link_dir_name);

    /*/*from   w  w  w  .j  a v  a  2s. c om*/
     * to avoid hitting file access limits in google drive, we duplicated samples
     * to 10 accounts. the links are stored in samples[1-10].lnk
     */
    Random rand = new Random();
    int n = rand.nextInt(10) + 1;
    if (BuildConfig.DEBUG)
        Log.d(TAG, "onHandleIntent: sample link file #" + n);

    String samplesLinkFilename = res.getString(R.string.samples_link_file_name) + Integer.toString(n) + "."
            + MainConsts.LINK_EXTENSION;

    String url = "https://" + res.getString(R.string.app_domain) + "/" + httpDir + "/" + samplesLinkFilename;

    String saveLinkFilename = res.getString(R.string.samples_link_file_name) + "." + MainConsts.LINK_EXTENSION;
    String path = MainConsts.MEDIA_3D_ROOT_PATH + saveLinkFilename;

    /*
     * download the link file
     */
    DownloadFileTask dft = new DownloadFileTask(this, url, path);
    dft.execute();

    boolean isSuccess = false;

    /*
     * wait for the asynctask to be done
     */
    try {
        isSuccess = dft.get();
    } catch (InterruptedException e) {
        return;
    } catch (ExecutionException e) {
        return;
    }

    /*
     * parse the link file and decide which ones (if any) need to be downloaded
     */
    if (isSuccess) {
        if (BuildConfig.DEBUG)
            Log.d(TAG, "onHandleIntent: download link file success");
        parseLinkFile(path);
    } else {
        if (BuildConfig.DEBUG)
            Log.d(TAG, "onHandleIntent: unable to download link file");
    }
}

From source file:com.insthub.BeeFramework.model.BaseModel.java

public void callback(String url, JSONObject jo, AjaxStatus status) {
    if (null == jo) {
        //            ToastView toast = new ToastView(mContext,"");
        //            toast.setGravity(Gravity.CENTER, 0, 0);
        //            toast.show();
        return;//from  ww  w  .j a va  2s.  c  o  m
    }
    try {
        STATUS responseStatus = new STATUS();
        responseStatus.fromJson(jo.optJSONObject("status"));
        if (responseStatus.succeed != ErrorCodeConst.ResponseSucceed) {
            if (responseStatus.error_code == ErrorCodeConst.InvalidSession) {
                ToastView toast = new ToastView(mContext, mContext.getString(R.string.session_expires_tips));
                toast.setGravity(Gravity.CENTER, 0, 0);
                toast.show();
                E0_ProfileFragment.isRefresh = true;
                Intent intent = new Intent(mContext, A0_SigninActivity.class);
                mContext.startActivity(intent);

                shared = mContext.getSharedPreferences("userInfo", 0);
                editor = shared.edit();

                editor.putString("uid", "");
                editor.putString("sid", "");
                editor.commit();
                SESSION.getInstance().uid = shared.getString("uid", "");
                SESSION.getInstance().sid = shared.getString("sid", "");

            }

        }

        Resources resource = mContext.getResources();
        String way = resource.getString(R.string.delivery);
        String col = resource.getString(R.string.collected);
        String und = resource.getString(R.string.understock);
        String been = resource.getString(R.string.been_used);
        String sub = resource.getString(R.string.submit_the_parameter_error);
        String fai = resource.getString(R.string.failed);
        String pur = resource.getString(R.string.error_10008);
        String noi = resource.getString(R.string.no_shipping_information);
        String error = resource.getString(R.string.username_or_password_error);
        if (responseStatus.error_code == ErrorCodeConst.SelectedDeliverMethod) {
            ToastView toast = new ToastView(mContext, way);
            toast.setGravity(Gravity.CENTER, 0, 0);
            toast.show();
        }

        if (responseStatus.error_code == ErrorCodeConst.AlreadyCollected) {
            //Toast.makeText(mContext, "??", Toast.LENGTH_SHORT).show();
            ToastView toast = new ToastView(mContext, col);
            toast.setGravity(Gravity.CENTER, 0, 0);
            toast.show();
        }

        if (responseStatus.error_code == ErrorCodeConst.InventoryShortage) {
            ToastView toast = new ToastView(mContext, und);
            toast.setGravity(Gravity.CENTER, 0, 0);
            toast.show();
        }

        if (responseStatus.error_code == ErrorCodeConst.UserOrEmailExist) {
            ToastView toast = new ToastView(mContext, been);
            toast.setGravity(Gravity.CENTER, 0, 0);
            toast.show();
        }

        if (responseStatus.error_code == ErrorCodeConst.InvalidParameter) {
            ToastView toast = new ToastView(mContext, sub);
            toast.setGravity(Gravity.CENTER, 0, 0);
            toast.show();
        }

        if (responseStatus.error_code == ErrorCodeConst.ProcessFailed) {
            ToastView toast = new ToastView(mContext, fai);
            toast.setGravity(Gravity.CENTER, 0, 0);
            toast.show();
        }

        if (responseStatus.error_code == ErrorCodeConst.BuyFailed) {
            ToastView toast = new ToastView(mContext, pur);
            toast.setGravity(Gravity.CENTER, 0, 0);
            toast.show();
        }

        if (responseStatus.error_code == ErrorCodeConst.NoShippingInformation) {
            ToastView toast = new ToastView(mContext, noi);
            toast.setGravity(Gravity.CENTER, 0, 0);
            toast.show();
        }
        if (responseStatus.error_code == ErrorCodeConst.InvalidUsernameOrPassword) {
            ToastView toast = new ToastView(mContext, error);
            toast.setGravity(Gravity.CENTER, 0, 0);
            toast.show();
        }
        if (responseStatus.error_code == ErrorCodeConst.UserOrEmailExist) {
            ToastView toast = new ToastView(mContext, resource.getString(R.string.been_used));
            toast.setGravity(Gravity.CENTER, 0, 0);
            toast.show();
        }
    } catch (JSONException e) {

    }

}

From source file:com.gotraveling.insthub.BeeFramework.model.BaseModel.java

public void callback(String url, JSONObject jo, AjaxStatus status) {
    if (null == jo) {
        ToastView toast = new ToastView(mContext, "");
        toast.setGravity(Gravity.CENTER, 0, 0);
        toast.show();/*from  w  ww.j  a v  a2  s  . c o  m*/
        return;
    }
    try {
        STATUS responseStatus = new STATUS();
        responseStatus.fromJson(jo.optJSONObject("status"));
        if (responseStatus.succeed != ErrorCodeConst.ResponseSucceed) {
            if (responseStatus.error_code == ErrorCodeConst.InvalidSession) {
                ToastView toast = new ToastView(mContext, mContext.getString(R.string.session_expires_tips));
                toast.setGravity(Gravity.CENTER, 0, 0);
                toast.show();
                E0_ProfileFragment.isRefresh = true;
                Intent intent = new Intent(mContext, A0_SigninActivity.class);
                mContext.startActivity(intent);

                shared = mContext.getSharedPreferences("userInfo", 0);
                editor = shared.edit();

                editor.putString("uid", "");
                editor.putString("sid", "");
                editor.commit();
                SESSION.getInstance().uid = shared.getString("uid", "");
                SESSION.getInstance().sid = shared.getString("sid", "");

            }

        }

        Resources resource = mContext.getResources();
        String way = resource.getString(R.string.delivery);
        String col = resource.getString(R.string.collected);
        String und = resource.getString(R.string.understock);
        String been = resource.getString(R.string.been_used);
        String sub = resource.getString(R.string.submit_the_parameter_error);
        String fai = resource.getString(R.string.failed);
        String pur = resource.getString(R.string.error_10008);
        String noi = resource.getString(R.string.no_shipping_information);
        String error = resource.getString(R.string.username_or_password_error);
        if (responseStatus.error_code == ErrorCodeConst.SelectedDeliverMethod) {
            ToastView toast = new ToastView(mContext, way);
            toast.setGravity(Gravity.CENTER, 0, 0);
            toast.show();
        }

        if (responseStatus.error_code == ErrorCodeConst.AlreadyCollected) {
            //Toast.makeText(mContext, "??", Toast.LENGTH_SHORT).show();
            ToastView toast = new ToastView(mContext, col);
            toast.setGravity(Gravity.CENTER, 0, 0);
            toast.show();
        }

        if (responseStatus.error_code == ErrorCodeConst.InventoryShortage) {
            ToastView toast = new ToastView(mContext, und);
            toast.setGravity(Gravity.CENTER, 0, 0);
            toast.show();
        }

        if (responseStatus.error_code == ErrorCodeConst.UserOrEmailExist) {
            ToastView toast = new ToastView(mContext, been);
            toast.setGravity(Gravity.CENTER, 0, 0);
            toast.show();
        }

        if (responseStatus.error_code == ErrorCodeConst.InvalidParameter) {
            ToastView toast = new ToastView(mContext, sub);
            toast.setGravity(Gravity.CENTER, 0, 0);
            toast.show();
        }

        if (responseStatus.error_code == ErrorCodeConst.ProcessFailed) {
            ToastView toast = new ToastView(mContext, fai);
            toast.setGravity(Gravity.CENTER, 0, 0);
            toast.show();
        }

        if (responseStatus.error_code == ErrorCodeConst.BuyFailed) {
            ToastView toast = new ToastView(mContext, pur);
            toast.setGravity(Gravity.CENTER, 0, 0);
            toast.show();
        }

        if (responseStatus.error_code == ErrorCodeConst.NoShippingInformation) {
            ToastView toast = new ToastView(mContext, noi);
            toast.setGravity(Gravity.CENTER, 0, 0);
            toast.show();
        }
        if (responseStatus.error_code == ErrorCodeConst.InvalidUsernameOrPassword) {
            ToastView toast = new ToastView(mContext, error);
            toast.setGravity(Gravity.CENTER, 0, 0);
            toast.show();
        }
        if (responseStatus.error_code == ErrorCodeConst.UserOrEmailExist) {
            ToastView toast = new ToastView(mContext, resource.getString(R.string.been_used));
            toast.setGravity(Gravity.CENTER, 0, 0);
            toast.show();
        }
    } catch (JSONException e) {

    }

}

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

private boolean initStorage() {
    try {//  w w  w .  ja  v a  2 s  .c o  m
        if (!Media.IsMediaMounted()) {
            Log.i(LOG_TAG, "External storage not mounted; trying again later.");
            return false;
        }
        _storagePath = Media.InitStorage(this, DIRECTORY_NAME, false);
    } catch (Exception e) {
        final Resources res = getResources();
        Notifications.NotifyError(this, NOTIFY_ID, false, res.getString(R.string.fail_ticker),
                res.getString(R.string.fail_title), e.getMessage());
        Log.e(LOG_TAG, "Couldn't init storage: " + e);
    }

    return _storagePath != null;
}

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

private void checkUploads() {
    Log.i(LOG_TAG, "Checking for images to upload to the server");
    if (!initStorage())
        return;/*w  w  w  .  j  ava 2s .  c o 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 upload check: not configured, or disabled");
        return;
    }

    // Enumerate files that don't end in .temp, and aren't .nomedia
    for (File f : _storagePath.listFiles()) {
        if (f.getName().endsWith(CaptureService.TEMP_EXTENSION))
            continue;
        if (f.getName().equals(Media.NO_MEDIA))
            continue;

        try {
            Log.i(LOG_TAG, "Uploading " + f.getName());

            // Upload it to its home on the server.
            HashMap<String, String> params = new HashMap<String, String>();
            params.put("auth", authToken);

            String baseUrl = Settings.GetBaseUrl();
            String result = HttpMultipartUpload.Upload(new URL(baseUrl + "upload.php"), f, "uploadedfile",
                    params, getBaseContext());

            if (result != null) {
                final Resources res = getResources();
                String notificationMsg = res.getString(R.string.upload_detail);

                // Verify that we got a proper result, because the server
                // might have failed to process, too.
                try {
                    JSONObject root = new JSONObject(result);
                    String success = root.optString("success");
                    if (success.equals(""))
                        throw new IOException("Bad server answer: " + root.optString("message"));

                    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;
                }

                if (settings.getUploadNotifications()) {
                    // See if we can find the original image path.
                    ProcessedImages processed = ProcessedImages.GetSingleton(this);
                    String fullPath = processed.getFullPath(f.getName());

                    // Copy the file so we can use it as a notification. It's okay if we
                    // overwrite another because we're overwriting notifications too.
                    final File thumb = new File(
                            _tempThumbPath.getAbsolutePath().concat(File.separator).concat("tempthumb.jpg"));
                    Media.FileCopy(f, thumb);

                    Notifications.NotifyUpload(this, NOTIFY_ID, true, res.getString(R.string.upload_ticker),
                            res.getString(R.string.upload_title), notificationMsg, fullPath,
                            thumb.getAbsolutePath());
                }
            } else {
                // Result was null, meaning there was a 0 size image to upload... Do we want to do anything more here?
            }

            // Upload was successful, so delete the image.
            Log.i(LOG_TAG, "Deleting successfully uploaded " + f.getName());
            f.delete();
        } catch (final IOException ex) {
            if (settings.getVerbose()) {
                final Resources res = getResources();
                Notifications.NotifyError(getBaseContext(), NOTIFY_ID, false,
                        res.getString(R.string.fail_ticker), res.getString(R.string.fail_title),
                        res.getString(R.string.fail_upload));
            }
            Log.w(LOG_TAG, "Upload failed", ex);
        }
    }
    Log.i(LOG_TAG, "Upload check complete");
}

From source file:com.vrem.wifianalyzer.wifi.channelgraph.ChannelGraphView.java

private GraphView makeGraphView(@NonNull MainActivity mainActivity, int graphMaximumY) {
    Resources resources = mainActivity.getResources();
    return new GraphViewBuilder(mainActivity, getNumX(), graphMaximumY)
            .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.fairphone.updater.UpdaterService.java

private Request createDownloadRequest(String url, String fileName) {

    Request request = new Request(Uri.parse(url));
    Environment.getExternalStoragePublicDirectory(
            Environment.getExternalStorageDirectory() + VersionParserHelper.UPDATER_FOLDER).mkdirs();

    request.setDestinationInExternalPublicDir(VersionParserHelper.UPDATER_FOLDER, fileName);
    request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI);
    request.setAllowedOverRoaming(false);

    Resources resources = getApplicationContext().getResources();
    request.setTitle(resources.getString(R.string.downloadUpdateTitle));

    return request;
}