List of usage examples for android.content SharedPreferences getBoolean
boolean getBoolean(String key, boolean defValue);
From source file:com.creapple.tms.mobiledriverconsole.utils.MDCUtils.java
/** * Retrieve boolean information into SharedPreferences * @param context/*from w w w .j av a 2s. c om*/ * @param key * @param dftValue * @return */ public static boolean getValue(Context context, String key, boolean dftValue) { SharedPreferences pref = context.getSharedPreferences(Constants.SHARED_PREFERENCES_NAME, Activity.MODE_PRIVATE); try { return pref.getBoolean(key, dftValue); } catch (Exception e) { return dftValue; } }
From source file:cn.whereyougo.framework.utils.PackageManagerUtil.java
/** * ????//from w w w . j a va2s .c o m * * @param mContext * * @param TagClass * ??? * @param iconResId * ?? * @param iconName * ?? */ public static void addShortCut2Desktop(Context mContext, Class<?> TagClass, int iconResId, String iconName) { SharedPreferences sp = mContext.getSharedPreferences("appinfo", Context.MODE_PRIVATE); if (!sp.getBoolean("shortcut_flag_icon", false)) { sp.edit().putBoolean("shortcut_flag_icon", true).commit(); LogUtil.d("shortcut", "first create successfull"); } else { LogUtil.d("shortcut", "no created"); return; } String ACTION_ADD_SHORTCUT = "com.android.launcher.action.INSTALL_SHORTCUT"; Intent intent = new Intent(); intent.setClass(mContext, TagClass); intent.setAction("android.intent.action.MAIN"); intent.addCategory("android.intent.category.LAUNCHER"); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); Intent addShortcut = new Intent(ACTION_ADD_SHORTCUT); Parcelable icon = Intent.ShortcutIconResource.fromContext(mContext, iconResId);// ??? addShortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, iconName);// ?? addShortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, intent);// ?? addShortcut.putExtra("duplicate", false);// ???? addShortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon);// ?? mContext.sendBroadcast(addShortcut);// ?? }
From source file:de.schaeuffelhut.android.openvpn.Preferences.java
public static boolean getVpnDnsEnabled(Context context, File configFile) { SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); return sharedPreferences.getBoolean(Preferences.KEY_VPN_DNS_ENABLE(configFile), false); }
From source file:de.schaeuffelhut.android.openvpn.Preferences.java
public static boolean getLogStdoutEnable(Context context, File configFile) { SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); return sharedPreferences.getBoolean(Preferences.KEY_CONFIG_LOG_STDOUT_ENABLE(configFile), false); }
From source file:de.schaeuffelhut.android.openvpn.Preferences.java
public static boolean getIntendedState(Context context, File configFile) { SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); return sharedPreferences.getBoolean(Preferences.KEY_CONFIG_INTENDED_STATE(configFile), false); }
From source file:de.schaeuffelhut.android.openvpn.Preferences.java
public static boolean getFixHtcRoutes(Context context) { SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); return sharedPreferences.getBoolean(Preferences.KEY_FIX_HTC_ROUTES, false); }
From source file:com.yairkukielka.feedhungry.EntryListFragment.java
/** * Get only unread articles setting from preferences * /* w w w .j a v a2 s . co m*/ * @param context * context * @return true if only unread articles */ public static Boolean getPrefOnlyUnread(Context context) { if (context != null) { SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(context); return sharedPref.getBoolean(PreferencesActivity.KEY_ONLY_UNREAD, false); } return null; }
From source file:com.wifi.brainbreaker.mydemo.spydroid.api.RequestHandler.java
/** * The implementation of all the possible requests is here * -> "sounds": returns a list of available sounds on the phone * -> "screen": returns the screen state (whether the app. is on the foreground or not) * -> "play": plays a sound on the phone * -> "set": update Spydroid's configuration * -> "get": returns Spydroid's configuration (framerate, bitrate...) * -> "state": returns a JSON containing information about the state of the application * -> "battery": returns an approximation of the battery level on the phone * -> "buzz": makes the phone buuz //from ww w. j a va2 s .c o m * -> "volume": sets or gets the volume * @throws JSONException * @throws IllegalAccessException * @throws IllegalArgumentException **/ static private void exec(JSONObject object, StringBuilder response) throws JSONException, IllegalArgumentException, IllegalAccessException { SpydroidApplication application = SpydroidApplication.getInstance(); Context context = application.getApplicationContext(); String action = object.getString("action"); // Returns a list of available sounds on the phone if (action.equals("sounds")) { Field[] raws = R.raw.class.getFields(); response.append("["); for (int i = 0; i < raws.length - 1; i++) { response.append("\"" + raws[i].getName() + "\","); } response.append("\"" + raws[raws.length - 1].getName() + "\"]"); } // Returns the screen state (whether the app. is on the foreground or not) else if (action.equals("screen")) { response.append(application.applicationForeground ? "\"1\"" : "\"0\""); } // Plays a sound on the phone else if (action.equals("play")) { Field[] raws = R.raw.class.getFields(); for (int i = 0; i < raws.length; i++) { if (raws[i].getName().equals(object.getString("name"))) { mSoundPool.load(application, raws[i].getInt(null), 0); } } response.append("[]"); } // Returns Spydroid's configuration (framerate, bitrate...) else if (action.equals("get")) { final SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context); response.append("{\"streamAudio\":" + settings.getBoolean("stream_audio", false) + ","); response.append("\"audioEncoder\":\"" + (application.audioEncoder == SessionBuilder.AUDIO_AMRNB ? "AMR-NB" : "AAC") + "\","); response.append("\"streamVideo\":" + settings.getBoolean("stream_video", true) + ","); response.append("\"videoEncoder\":\"" + (application.videoEncoder == SessionBuilder.VIDEO_H263 ? "H.263" : "H.264") + "\","); response.append("\"videoResolution\":\"" + application.videoQuality.resX + "x" + application.videoQuality.resY + "\","); response.append("\"videoFramerate\":\"" + application.videoQuality.framerate + " fps\","); response.append("\"videoBitrate\":\"" + application.videoQuality.bitrate / 1000 + " kbps\"}"); } // Update Spydroid's configuration else if (action.equals("set")) { final JSONObject settings = object.getJSONObject("settings"); final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); final Editor editor = prefs.edit(); editor.putBoolean("stream_video", settings.getBoolean("stream_video")); application.videoQuality = VideoQuality.parseQuality(settings.getString("video_quality")); editor.putInt("video_resX", application.videoQuality.resX); editor.putInt("video_resY", application.videoQuality.resY); editor.putString("video_framerate", String.valueOf(application.videoQuality.framerate)); editor.putString("video_bitrate", String.valueOf(application.videoQuality.bitrate / 1000)); editor.putString("video_encoder", settings.getString("video_encoder").equals("H.263") ? "2" : "1"); editor.putBoolean("stream_audio", settings.getBoolean("stream_audio")); editor.putString("audio_encoder", settings.getString("audio_encoder").equals("AMR-NB") ? "3" : "5"); editor.commit(); response.append("[]"); } // Returns a JSON containing information about the state of the application else if (action.equals("state")) { Exception exception = application.lastCaughtException; response.append("{"); if (exception != null) { // Used to display the message on the user interface String lastError = exception.getMessage(); // Useful to display additional information to the user depending on the error StackTraceElement[] stack = exception.getStackTrace(); StringBuilder builder = new StringBuilder( exception.getClass().getName() + " : " + lastError + "||"); for (int i = 0; i < stack.length; i++) builder.append("at " + stack[i].getClassName() + "." + stack[i].getMethodName() + " (" + stack[i].getFileName() + ":" + stack[i].getLineNumber() + ")||"); response.append("\"lastError\":\"" + (lastError != null ? lastError : "unknown error") + "\","); response.append("\"lastStackTrace\":\"" + builder.toString() + "\","); } response.append("\"activityPaused\":\"" + (application.applicationForeground ? "1" : "0") + "\""); response.append("}"); } else if (action.equals("clear")) { application.lastCaughtException = null; response.append("[]"); } // Returns an approximation of the battery level else if (action.equals("battery")) { response.append("\"" + application.batteryLevel + "\""); } // Makes the phone vibrates for 300ms else if (action.equals("buzz")) { Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE); vibrator.vibrate(300); response.append("[]"); } // Sets or gets the system's volume else if (action.equals("volume")) { AudioManager audio = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); if (object.has("set")) { audio.setStreamVolume(AudioManager.STREAM_MUSIC, object.getInt("set"), AudioManager.FLAG_REMOVE_SOUND_AND_VIBRATE); response.append("[]"); } else { int max = audio.getStreamMaxVolume(AudioManager.STREAM_MUSIC); int current = audio.getStreamVolume(AudioManager.STREAM_MUSIC); response.append("{\"max\":" + max + ",\"current\":" + current + "}"); } } }
From source file:cn.count.easydriver366.base.AppSettings.java
static public void restore_login_from_device(Context context) { SharedPreferences prefs = context.getSharedPreferences(AppSettings.AppTile + "_login", Context.MODE_PRIVATE); userid = prefs.getInt("userid", -1); isLogin = prefs.getBoolean("isLogin", false); username = prefs.getString("username", ""); update_time = prefs.getInt("update_time", 4 * 60 * 60); }
From source file:com.alphabetbloc.accessmrs.utilities.NetworkUtils.java
public static SSLContext createSslContext() throws GeneralSecurityException, IOException { // TrustStore KeyStore trustStore = FileUtils.loadSslStore(FileUtils.MY_TRUSTSTORE); if (trustStore == null) throw new IOException("Access denied. Ensure credential storage is available."); MyTrustManager myTrustManager = new MyTrustManager(trustStore); TrustManager[] tms = new TrustManager[] { myTrustManager }; // KeyStore/*from w w w .j a v a 2s .c o m*/ KeyManager[] kms = null; SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(App.getApp()); boolean useClientAuth = prefs.getBoolean(App.getApp().getString(R.string.key_client_auth), false); if (useClientAuth) { KeyStore keyStore = FileUtils.loadSslStore(FileUtils.MY_KEYSTORE); if (keyStore == null) throw new IOException("Access denied. Ensure credential storage is available."); KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm()); kmf.init(keyStore, EncryptionUtil.getPassword().toCharArray()); kms = kmf.getKeyManagers(); } SSLContext context = SSLContext.getInstance("TLS"); context.init(kms, tms, null); return context; }