Example usage for android.content Context getString

List of usage examples for android.content Context getString

Introduction

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

Prototype

@NonNull
public final String getString(@StringRes int resId) 

Source Link

Document

Returns a localized string from the application's package's default string table.

Usage

From source file:com.dycody.android.idealnote.utils.StorageHelper.java

public static boolean deleteExternalStoragePrivateFile(Context mContext, String name) {
    boolean res = false;

    // Checks for external storage availability
    if (!checkStorage()) {
        Toast.makeText(mContext,/*from  w w w .  j a v  a 2  s. com*/
                mContext.getString(com.dycody.android.idealnote.R.string.storage_not_available),
                Toast.LENGTH_SHORT).show();
        return false;
    }

    File file = new File(mContext.getExternalFilesDir(null), name);
    file.delete();

    return true;
}

From source file:it.feio.android.omninotes.utils.StorageManager.java

public static boolean deleteExternalStoragePrivateFile(Context mContext, String name) {
    boolean res = false;

    // Checks for external storage availability
    if (!checkStorage()) {
        Toast.makeText(mContext, mContext.getString(R.string.storage_not_available), Toast.LENGTH_SHORT).show();
        return res;
    }/*w w w  .java2  s  . co m*/

    File file = new File(mContext.getExternalFilesDir(null), name);
    if (file != null) {
        file.delete();
        res = true;
    }

    return res;
}

From source file:com.none.tom.simplerssreader.utils.SharedPrefUtils.java

public static String[] getSubscriptionCategories(final Context context, final boolean edit) {
    final LinkedListMultimap<String, String> subscriptions = getSubscriptions(context);
    final Set<String> categories = new TreeSet<>();

    if (!edit) {//from  w w  w  .  jav a2s  .c  om
        categories.add(context.getString(R.string.all_categories));
    } else {
        categories.add(context.getString(R.string.clear_category));
    }

    for (final String title : subscriptions.asMap().keySet()) {
        categories.add(subscriptions.get(title).get(0));
    }

    return categories.toArray(new String[categories.size()]);
}

From source file:com.example.android.sunshine.app.Utility.java

public static boolean isMetric(Context context) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    return prefs/*ww w .  j  a  v  a2  s .co  m*/
            .getString(context.getString(R.string.pref_units_key),
                    context.getString(R.string.pref_units_metric))
            .equals(context.getString(R.string.pref_units_metric));
}

From source file:com.dycody.android.idealnote.utils.StorageHelper.java

public static boolean delete(Context mContext, String name) {
    boolean res = false;

    // Checks for external storage availability
    if (!checkStorage()) {
        Toast.makeText(mContext,/*from  www .  ja  v a 2s . c o m*/
                mContext.getString(com.dycody.android.idealnote.R.string.storage_not_available),
                Toast.LENGTH_SHORT).show();
        return false;
    }

    File file = new File(name);
    if (file.isFile()) {
        res = file.delete();
    } else if (file.isDirectory()) {
        File[] files = file.listFiles();
        for (File file2 : files) {
            res = delete(mContext, file2.getAbsolutePath());
        }
        res = file.delete();
    }

    return res;
}

From source file:com.dycody.android.idealnote.utils.StorageHelper.java

/**
 * Create a path where we will place our private file on external
 *
 * @param mContext//from  w ww . j  a  va 2 s . c  om
 * @param uri
 * @return
 */
public static File createExternalStoragePrivateFile(Context mContext, Uri uri, String extension) {

    // Checks for external storage availability
    if (!checkStorage()) {
        Toast.makeText(mContext,
                mContext.getString(com.dycody.android.idealnote.R.string.storage_not_available),
                Toast.LENGTH_SHORT).show();
        return null;
    }
    File file = createNewAttachmentFile(mContext, extension);

    InputStream is;
    OutputStream os;
    try {
        is = mContext.getContentResolver().openInputStream(uri);
        os = new FileOutputStream(file);
        copyFile(is, os);
    } catch (IOException e) {
        try {
            is = new FileInputStream(FileHelper.getPath(mContext, uri));
            os = new FileOutputStream(file);
            copyFile(is, os);
            // It's a path!!
        } catch (NullPointerException e1) {
            try {
                is = new FileInputStream(uri.getPath());
                os = new FileOutputStream(file);
                copyFile(is, os);
            } catch (FileNotFoundException e2) {
                Log.e(Constants.TAG, "Error writing " + file, e2);
                file = null;
            }
        } catch (FileNotFoundException e2) {
            Log.e(Constants.TAG, "Error writing " + file, e2);
            file = null;
        }
    }
    return file;
}

From source file:it.feio.android.omninotes.utils.StorageManager.java

/**
 * Create a path where we will place our private file on external
 * /*  w w w  .j a  v a 2s.c o m*/
 * @param mContext
 * @param uri
 * @return
 */
public static File createExternalStoragePrivateFile(Context mContext, Uri uri, String extension) {

    // Checks for external storage availability
    if (!checkStorage()) {
        Toast.makeText(mContext, mContext.getString(R.string.storage_not_available), Toast.LENGTH_SHORT).show();
        return null;
    }
    File file = createNewAttachmentFile(mContext, extension);

    InputStream is;
    OutputStream os;
    try {
        is = mContext.getContentResolver().openInputStream(uri);
        os = new FileOutputStream(file);
        copyFile(is, os);
    } catch (IOException e) {
        try {
            //            InputStream is = new FileInputStream(uri.getPath());
            is = new FileInputStream(FileHelper.getPath(mContext, uri));
            os = new FileOutputStream(file);
            copyFile(is, os);
            // It's a path!!
        } catch (NullPointerException e1) {
            try {
                is = new FileInputStream(uri.getPath());
                os = new FileOutputStream(file);
                copyFile(is, os);
            } catch (FileNotFoundException e2) {
                Log.e(Constants.TAG, "Error writing " + file, e2);
                file = null;
            }
        } catch (FileNotFoundException e2) {
            Log.e(Constants.TAG, "Error writing " + file, e2);
            file = null;
        }
    }
    return file;
}

From source file:it.feio.android.omninotes.utils.StorageManager.java

public static boolean delete(Context mContext, String name) {
    boolean res = false;

    // Checks for external storage availability
    if (!checkStorage()) {
        Toast.makeText(mContext, mContext.getString(R.string.storage_not_available), Toast.LENGTH_SHORT).show();
        return res;
    }//from w w w . jav a 2s . co  m

    File file = new File(name);
    if (file != null) {
        if (file.isFile()) {
            res = file.delete();
        } else if (file.isDirectory()) {
            File[] files = file.listFiles();
            for (File file2 : files) {
                res = delete(mContext, file2.getAbsolutePath());
            }
            res = file.delete();
        }
    }

    return res;
}

From source file:com.cat.external.util.OtherUtils.java

/**
 * @param context if null, use the default format
 *                (Mozilla/5.0 (Linux; U; Android %s) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 %sSafari/534.30).
 * @return// w w w .java 2 s . c  o  m
 */
@SuppressLint("DefaultLocale")
public static String getUserAgent(Context context) {
    String webUserAgent = null;
    if (context != null) {
        try {
            @SuppressWarnings("rawtypes")
            Class sysResCls = Class.forName("com.android.internal.R$string");
            Field webUserAgentField = sysResCls.getDeclaredField("web_user_agent");
            Integer resId = (Integer) webUserAgentField.get(null);
            webUserAgent = context.getString(resId);
        } catch (Throwable ignored) {
        }
    }
    if (TextUtils.isEmpty(webUserAgent)) {
        webUserAgent = "Mozilla/5.0 (Linux; U; Android %s) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 %sSafari/533.1";
    }

    Locale locale = Locale.getDefault();
    StringBuffer buffer = new StringBuffer();
    // Add version
    final String version = Build.VERSION.RELEASE;
    if (version.length() > 0) {
        buffer.append(version);
    } else {
        // default to "1.0"
        buffer.append("1.0");
    }
    buffer.append("; ");
    final String language = locale.getLanguage();
    if (language != null) {
        buffer.append(language.toLowerCase());
        final String country = locale.getCountry();
        if (country != null) {
            buffer.append("-");
            buffer.append(country.toLowerCase());
        }
    } else {
        // default to "en"
        buffer.append("en");
    }
    // add the model for the release build
    if ("REL".equals(Build.VERSION.CODENAME)) {
        final String model = Build.MODEL;
        if (model.length() > 0) {
            buffer.append("; ");
            buffer.append(model);
        }
    }
    final String id = Build.ID;
    if (id.length() > 0) {
        buffer.append(" Build/");
        buffer.append(id);
    }
    return String.format(webUserAgent, buffer, "Mobile ");
}

From source file:com.dnielfe.manager.utils.SimpleUtils.java

public static void savetoClipBoard(final Context co, String dir1) {
    android.content.ClipboardManager clipboard = (android.content.ClipboardManager) co
            .getSystemService(Context.CLIPBOARD_SERVICE);
    android.content.ClipData clip = android.content.ClipData.newPlainText("Copied Text", dir1);
    clipboard.setPrimaryClip(clip);//from  w  w w . j ava  2  s  .  c  o m
    Toast.makeText(co, "'" + dir1 + "' " + co.getString(R.string.copiedtoclipboard), Toast.LENGTH_SHORT).show();
}