List of usage examples for android.content SharedPreferences contains
boolean contains(String key);
From source file:com.apptentive.android.sdk.module.engagement.interaction.fragment.MessageCenterFragment.java
private void setup(View rootView, boolean isInitialViewCreation) { boolean addedAnInteractiveCard = false; messageCenterRecyclerView = (MessageCenterRecyclerView) rootView .findViewById(R.id.message_center_recycler_view); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { messageCenterRecyclerView.setNestedScrollingEnabled(true); }/* ww w . j a va2 s . c om*/ LinearLayoutManager layoutManager = new LinearLayoutManager(this.getContext()); layoutManager.setOrientation(LinearLayoutManager.VERTICAL); messageCenterRecyclerView.setLayoutManager(layoutManager); fab = rootView.findViewById(R.id.composing_fab); fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { forceShowKeyboard = true; addComposingCard(); } }); messageCenterRecyclerViewAdapter = new MessageCenterRecyclerViewAdapter(this, this, interaction, listItems); if (isInitialViewCreation) { List<MessageCenterListItem> items = ApptentiveInternal.getInstance().getMessageManager() .getMessageCenterListItems(); if (items != null) { // Get message list from DB, and use this as the starting point for the listItems array. prepareMessages(items); } String contextMessageBody = interaction.getContextualMessageBody(); if (contextMessageBody != null) { // Clear any pending composing message to present an empty composing area clearPendingComposingMessage(); messagingActionHandler.sendEmptyMessage(MSG_REMOVE_STATUS); messagingActionHandler.sendMessage(messagingActionHandler.obtainMessage(MSG_ADD_CONTEXT_MESSAGE, new ContextMessage(contextMessageBody))); // If checkAddWhoCardIfRequired returns true, it will add WhoCard, otherwise add composing card if (!checkAddWhoCardIfRequired()) { addedAnInteractiveCard = true; forceShowKeyboard = false; addComposingCard(); } } /* Add who card with pending contents ** Pending contents would be saved if the user was in composing Who card mode and exited through back button */ else if (pendingWhoCardName != null || pendingWhoCardEmail != null || pendingWhoCardAvatarFile != null) { addedAnInteractiveCard = true; addWhoCard(pendingWhoCardMode); } else if (!checkAddWhoCardIfRequired()) { /* If there are no items in the list, then it means that the Greeting will be added, but nothing else. * In that case, show the Composer, because Message Center hasn't been opened before. * If Who Card is required, show Who Card first. */ if (listItems.size() == 0) { addedAnInteractiveCard = true; addComposingCard(); } else { // Finally check if status message need to be restored addExpectationStatusIfNeeded(); } } } else { // Need to account for an input view that was added before orientation change, etc. if (listItems != null) { for (MessageCenterListItem item : listItems) { if (item.getListItemType() == MESSAGE_COMPOSER || item.getListItemType() == WHO_CARD) { addedAnInteractiveCard = true; } } } } messageCenterRecyclerView.setAdapter(messageCenterRecyclerViewAdapter); // Calculate FAB y-offset fabPaddingPixels = calculateFabPadding(rootView.getContext()); if (!addedAnInteractiveCard) { showFab(); } // Retrieve any saved attachments final SharedPreferences prefs = ApptentiveInternal.getInstance().getSharedPrefs(); if (prefs.contains(Constants.PREF_KEY_MESSAGE_CENTER_PENDING_COMPOSING_ATTACHMENTS)) { JSONArray savedAttachmentsJsonArray = null; try { savedAttachmentsJsonArray = new JSONArray( prefs.getString(Constants.PREF_KEY_MESSAGE_CENTER_PENDING_COMPOSING_ATTACHMENTS, "")); } catch (JSONException e) { e.printStackTrace(); } if (savedAttachmentsJsonArray != null && savedAttachmentsJsonArray.length() > 0) { if (pendingAttachments == null) { pendingAttachments = new ArrayList<ImageItem>(); } else { pendingAttachments.clear(); } for (int i = 0; i < savedAttachmentsJsonArray.length(); i++) { try { JSONObject savedAttachmentJson = savedAttachmentsJsonArray.getJSONObject(i); if (savedAttachmentJson != null) { pendingAttachments.add(new ImageItem(savedAttachmentJson)); } } catch (JSONException e) { continue; } } } // Stored pending attachments have been restored, remove it from the persistent storage SharedPreferences.Editor editor = prefs.edit(); editor.remove(Constants.PREF_KEY_MESSAGE_CENTER_PENDING_COMPOSING_ATTACHMENTS).apply(); } updateMessageSentStates(); }
From source file:com.goftagram.telegram.ui.Components.EmojiView.java
public void loadRecents() { String str;//from w ww .j av a 2 s . c o m SharedPreferences preferences = getContext().getSharedPreferences("emoji", Activity.MODE_PRIVATE); try { emojiUseHistory.clear(); if (preferences.contains("emojis")) { str = preferences.getString("emojis", ""); if (str != null && str.length() > 0) { String[] args = str.split(","); for (String arg : args) { String[] args2 = arg.split("="); long value = Long.parseLong(args2[0]); String string = ""; for (int a = 0; a < 4; a++) { char ch = (char) value; string = String.valueOf(ch) + string; value >>= 16; if (value == 0) { break; } } if (string.length() > 0) { emojiUseHistory.put(string, Integer.parseInt(args2[1])); } } } preferences.edit().remove("emojis").commit(); saveRecentEmoji(); } else { str = preferences.getString("emojis2", ""); if (str != null && str.length() > 0) { String[] args = str.split(","); for (String arg : args) { String[] args2 = arg.split("="); emojiUseHistory.put(args2[0], Integer.parseInt(args2[1])); } } } if (emojiUseHistory.isEmpty()) { String[] newRecent = new String[] { "\uD83D\uDE02", "\uD83D\uDE18", "\u2764", "\uD83D\uDE0D", "\uD83D\uDE0A", "\uD83D\uDE01", "\uD83D\uDC4D", "\u263A", "\uD83D\uDE14", "\uD83D\uDE04", "\uD83D\uDE2D", "\uD83D\uDC8B", "\uD83D\uDE12", "\uD83D\uDE33", "\uD83D\uDE1C", "\uD83D\uDE48", "\uD83D\uDE09", "\uD83D\uDE03", "\uD83D\uDE22", "\uD83D\uDE1D", "\uD83D\uDE31", "\uD83D\uDE21", "\uD83D\uDE0F", "\uD83D\uDE1E", "\uD83D\uDE05", "\uD83D\uDE1A", "\uD83D\uDE4A", "\uD83D\uDE0C", "\uD83D\uDE00", "\uD83D\uDE0B", "\uD83D\uDE06", "\uD83D\uDC4C", "\uD83D\uDE10", "\uD83D\uDE15" }; for (int i = 0; i < newRecent.length; i++) { emojiUseHistory.put(newRecent[i], newRecent.length - i); } saveRecentEmoji(); } sortEmoji(); adapters.get(0).notifyDataSetChanged(); } catch (Exception e) { FileLog.e("tmessages", e); } try { str = preferences.getString("color", ""); if (str != null && str.length() > 0) { String[] args = str.split(","); for (String arg : args) { String[] args2 = arg.split("="); emojiColor.put(args2[0], args2[1]); } } } catch (Exception e) { FileLog.e("tmessages", e); } if (showStickers) { try { stickersUseHistory.clear(); str = preferences.getString("stickers", ""); if (str != null && str.length() > 0) { String[] args = str.split(","); for (String arg : args) { String[] args2 = arg.split("="); stickersUseHistory.put(Long.parseLong(args2[0]), Integer.parseInt(args2[1])); } } sortStickers(); updateStickerTabs(); } catch (Exception e) { FileLog.e("tmessages", e); } } }
From source file:com.xorcode.andtweet.AndTweetService.java
/** * Examine changed preferences and behave accordingly * Clear all (including static) members, that depend on preferences * and need to be reread.../*from ww w. j a va 2 s . com*/ */ private boolean examinePreferences() { boolean ok = true; // Check when preferences were changed long preferencesChangeTimeNew = MyPreferences.getDefaultSharedPreferences() .getLong(MyPreferences.KEY_PREFERENCES_CHANGE_TIME, 0); long preferencesExamineTimeNew = java.lang.System.currentTimeMillis(); if (preferencesChangeTimeNew > preferencesExamineTime) { MyLog.d(TAG, "Examine at=" + preferencesExamineTimeNew + " Preferences changed at=" + preferencesChangeTimeNew); } else if (preferencesChangeTimeNew > preferencesChangeTime) { MyLog.d(TAG, "Preferences changed at=" + preferencesChangeTimeNew); } else if (preferencesChangeTimeNew == preferencesChangeTime) { MyLog.d(TAG, "Preferences didn't change, still at=" + preferencesChangeTimeNew); } else { Log.e(TAG, "Preferences change time error, time=" + preferencesChangeTimeNew); } preferencesChangeTime = preferencesChangeTimeNew; preferencesExamineTime = preferencesExamineTimeNew; getServiceSp().edit().putLong(MyPreferences.KEY_PREFERENCES_EXAMINE_TIME, preferencesExamineTime).commit(); // Forget and reload preferences... MyPreferences.forget(); MyPreferences.initialize(this, this); // Stop existing alarm in any case ok = cancelRepeatingAlarm(); SharedPreferences sp = MyPreferences.getDefaultSharedPreferences(); if (sp.contains("automatic_updates") && sp.getBoolean("automatic_updates", false)) { /** * Schedule Automatic updates according to the preferences. */ ok = scheduleRepeatingAlarm(); } return ok; }
From source file:org.telegram.ui.Components.EmojiView.java
public void loadRecents() { String str;/*from w ww . j a va2 s . co m*/ SharedPreferences preferences = getContext().getSharedPreferences("emoji", Activity.MODE_PRIVATE); try { emojiUseHistory.clear(); if (preferences.contains("emojis")) { str = preferences.getString("emojis", ""); if (str != null && str.length() > 0) { String[] args = str.split(","); for (String arg : args) { String[] args2 = arg.split("="); long value = Long.parseLong(args2[0]); String string = ""; for (int a = 0; a < 4; a++) { char ch = (char) value; string = String.valueOf(ch) + string; value >>= 16; if (value == 0) { break; } } if (string.length() > 0) { emojiUseHistory.put(string, Integer.parseInt(args2[1])); } } } preferences.edit().remove("emojis").commit(); saveRecentEmoji(); } else { str = preferences.getString("emojis2", ""); if (str != null && str.length() > 0) { String[] args = str.split(","); for (String arg : args) { String[] args2 = arg.split("="); emojiUseHistory.put(args2[0], Integer.parseInt(args2[1])); } } } if (emojiUseHistory.isEmpty()) { String[] newRecent = new String[] { "\uD83D\uDE02", "\uD83D\uDE18", "\u2764", "\uD83D\uDE0D", "\uD83D\uDE0A", "\uD83D\uDE01", "\uD83D\uDC4D", "\u263A", "\uD83D\uDE14", "\uD83D\uDE04", "\uD83D\uDE2D", "\uD83D\uDC8B", "\uD83D\uDE12", "\uD83D\uDE33", "\uD83D\uDE1C", "\uD83D\uDE48", "\uD83D\uDE09", "\uD83D\uDE03", "\uD83D\uDE22", "\uD83D\uDE1D", "\uD83D\uDE31", "\uD83D\uDE21", "\uD83D\uDE0F", "\uD83D\uDE1E", "\uD83D\uDE05", "\uD83D\uDE1A", "\uD83D\uDE4A", "\uD83D\uDE0C", "\uD83D\uDE00", "\uD83D\uDE0B", "\uD83D\uDE06", "\uD83D\uDC4C", "\uD83D\uDE10", "\uD83D\uDE15" }; for (int i = 0; i < newRecent.length; i++) { emojiUseHistory.put(newRecent[i], newRecent.length - i); } saveRecentEmoji(); } sortEmoji(); adapters.get(0).notifyDataSetChanged(); } catch (Exception e) { FileLog.e("tmessages", e); } try { str = preferences.getString("color", ""); if (str != null && str.length() > 0) { String[] args = str.split(","); for (String arg : args) { String[] args2 = arg.split("="); emojiColor.put(args2[0], args2[1]); } } } catch (Exception e) { FileLog.e("tmessages", e); } if (showStickers) { try { stickersUseHistory.clear(); str = preferences.getString("stickers", ""); if (str != null && str.length() > 0) { String[] args = str.split(","); for (String arg : args) { String[] args2 = arg.split("="); stickersUseHistory.put(Long.parseLong(args2[0]), Integer.parseInt(args2[1])); } } stickerSetsUseCount.clear(); str = preferences.getString("sets", ""); if (str != null && str.length() > 0) { String[] args = str.split(","); for (String arg : args) { String[] args2 = arg.split("="); stickerSetsUseCount.put(Long.parseLong(args2[0]), Integer.parseInt(args2[1])); } } sortStickers(); updateStickerTabs(); } catch (Exception e) { FileLog.e("tmessages", e); } } }
From source file:com.irccloud.android.IRCCloudApplicationBase.java
@Override public void onCreate() { super.onCreate(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) TrustKit.initializeWithNetworkSecurityConfiguration(getApplicationContext(), R.xml.network_security_config); Fabric.with(this, new Crashlytics()); Crashlytics.log(Log.INFO, "IRCCloud", "Crashlytics Initialized"); FlowManager.init(this); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); if (Build.VERSION.SDK_INT >= 19) EmojiCompat.init(/*w w w. j ava2 s .com*/ new BundledEmojiCompatConfig(this).setReplaceAll(!prefs.getBoolean("preferSystemEmoji", true))); /*EmojiCompat.init(new FontRequestEmojiCompatConfig(getApplicationContext(), new FontRequest( "com.google.android.gms.fonts", "com.google.android.gms", "Noto Color Emoji Compat", R.array.com_google_android_gms_fonts_certs)) .setReplaceAll(!prefs.getBoolean("preferSystemEmoji", true)) .registerInitCallback(new EmojiCompat.InitCallback() { @Override public void onInitialized() { super.onInitialized(); EventsList.getInstance().clearCaches(); conn.notifyHandlers(NetworkConnection.EVENT_FONT_DOWNLOADED, null); } }));*/ NetworkConnection.getInstance().registerForConnectivity(); //Disable HTTP keep-alive for our app, as some versions of Android will return an empty response System.setProperty("http.keepAlive", "false"); //Allocate all the shared objects at launch conn = NetworkConnection.getInstance(); ColorFormatter.init(); if (prefs.contains("notify")) { SharedPreferences.Editor editor = prefs.edit(); editor.putString("notify_type", prefs.getBoolean("notify", true) ? "1" : "0"); editor.remove("notify"); editor.commit(); } if (prefs.contains("notify_sound")) { SharedPreferences.Editor editor = prefs.edit(); if (!prefs.getBoolean("notify_sound", true)) editor.putString("notify_ringtone", ""); editor.remove("notify_sound"); editor.commit(); } if (prefs.contains("notify_lights")) { SharedPreferences.Editor editor = prefs.edit(); if (!prefs.getBoolean("notify_lights", true)) editor.putString("notify_led_color", "0"); editor.remove("notify_lights"); editor.commit(); } if (!prefs.getBoolean("ringtone_migrated", false)) { if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) { String notification_uri = prefs.getString("notify_ringtone", ""); if (notification_uri.startsWith("content://media/external/audio/media/")) { Cursor c = getContentResolver().query(Uri.parse(notification_uri), new String[] { MediaStore.Audio.Media.TITLE }, null, null, null); if (c != null && c.moveToFirst()) { if (c.getString(0).equals("IRCCloud")) { Log.d("IRCCloud", "Migrating notification ringtone setting: " + notification_uri); SharedPreferences.Editor editor = prefs.edit(); editor.remove("notify_ringtone"); editor.commit(); } } if (c != null && !c.isClosed()) { c.close(); } } File path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_NOTIFICATIONS); File file = new File(path, "IRCCloud.mp3"); if (file.exists()) { file.delete(); } try { getContentResolver().delete(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, MediaStore.Audio.Media.TITLE + " = 'IRCCloud'", null); } catch (Exception e) { // Ringtone not in media DB } } try { String notification_uri = prefs.getString("notify_ringtone", ""); if (notification_uri.startsWith("content://media/")) { Cursor c = getContentResolver().query(Uri.parse(notification_uri), new String[] { MediaStore.Audio.Media.TITLE }, null, null, null); if (c != null && c.moveToFirst()) { if (c.getString(0).equals("IRCCloud")) { Log.d("IRCCloud", "Migrating notification ringtone setting: " + notification_uri); SharedPreferences.Editor editor = prefs.edit(); editor.remove("notify_ringtone"); editor.commit(); } } if (c != null && !c.isClosed()) { c.close(); } } } catch (Exception e) { //We might not have permission to query the media DB } try { getContentResolver().delete(MediaStore.Audio.Media.INTERNAL_CONTENT_URI, MediaStore.Audio.Media.TITLE + " = 'IRCCloud'", null); } catch (Exception e) { // Ringtone not in media DB e.printStackTrace(); } File file = new File(getFilesDir(), "IRCCloud.mp3"); if (file.exists()) { file.delete(); } SharedPreferences.Editor editor = prefs.edit(); editor.putBoolean("ringtone_migrated", true); editor.commit(); } if (prefs.contains("notify_pebble")) { try { int pebbleVersion = getPackageManager().getPackageInfo("com.getpebble.android", 0).versionCode; if (pebbleVersion >= 553 && Build.VERSION.SDK_INT >= 18) { SharedPreferences.Editor editor = prefs.edit(); editor.remove("notify_pebble"); editor.commit(); } } catch (Exception e) { } } if (prefs.contains("acra.enable")) { SharedPreferences.Editor editor = prefs.edit(); editor.remove("acra.enable"); editor.commit(); } if (prefs.contains("notifications_json")) { SharedPreferences.Editor editor = prefs.edit(); editor.remove("notifications_json"); editor.remove("networks_json"); editor.remove("lastseeneids_json"); editor.remove("dismissedeids_json"); editor.commit(); } prefs = getSharedPreferences("prefs", 0); if (prefs.getString("host", "www.irccloud.com").equals("www.irccloud.com") && !prefs.contains("path") && prefs.contains("session_key")) { Crashlytics.log(Log.INFO, "IRCCloud", "Migrating path from session key"); SharedPreferences.Editor editor = prefs.edit(); editor.putString("path", "/websocket/" + prefs.getString("session_key", "").charAt(0)); editor.commit(); } if (prefs.contains("host") && prefs.getString("host", "").equals("www.irccloud.com")) { Crashlytics.log(Log.INFO, "IRCCloud", "Migrating host"); SharedPreferences.Editor editor = prefs.edit(); editor.putString("host", "api.irccloud.com"); editor.commit(); } if (prefs.contains("gcm_app_version")) { SharedPreferences.Editor editor = prefs.edit(); editor.remove("gcm_app_version"); editor.remove("gcm_app_build"); editor.remove("gcm_registered"); editor.remove("gcm_reg_id"); editor.commit(); } NetworkConnection.IRCCLOUD_HOST = prefs.getString("host", BuildConfig.HOST); NetworkConnection.IRCCLOUD_PATH = prefs.getString("path", "/"); /*try { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { if (0 != (getApplicationInfo().flags &= ApplicationInfo.FLAG_DEBUGGABLE)) WebView.setWebContentsDebuggingEnabled(true); } } catch (Exception e) { }*/ /*FontRequest request = new FontRequest( "com.google.android.gms.fonts", "com.google.android.gms", "Dekko", R.array.com_google_android_gms_fonts_certs); FontsContractCompat.requestFont(getApplicationContext(), request, new FontsContractCompat.FontRequestCallback() { @Override public void onTypefaceRetrieved(Typeface typeface) { csFont = typeface; EventsList.getInstance().clearCaches(); NetworkConnection.getInstance().notifyHandlers(NetworkConnection.EVENT_FONT_DOWNLOADED, null); } }, getFontsHandler());*/ Crashlytics.log(Log.INFO, "IRCCloud", "App Initialized"); }
From source file:com.android.screenspeak.controller.GestureControllerApp.java
private String actionFromGesture(int gesture) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mService); switch (gesture) { case AccessibilityService.GESTURE_SWIPE_UP: return prefs.getString(mService.getString(R.string.pref_shortcut_up_key), mService.getString(R.string.pref_shortcut_up_default)); case AccessibilityService.GESTURE_SWIPE_DOWN: return prefs.getString(mService.getString(R.string.pref_shortcut_down_key), mService.getString(R.string.pref_shortcut_down_default)); case AccessibilityService.GESTURE_SWIPE_LEFT: if (isScreenLayoutRTL()) { return prefs.getString(mService.getString(R.string.pref_shortcut_right_key), mService.getString(R.string.pref_shortcut_right_default)); } else {/*from w w w .j av a 2 s. c o m*/ return prefs.getString(mService.getString(R.string.pref_shortcut_left_key), mService.getString(R.string.pref_shortcut_left_default)); } case AccessibilityService.GESTURE_SWIPE_RIGHT: if (isScreenLayoutRTL()) { return prefs.getString(mService.getString(R.string.pref_shortcut_left_key), mService.getString(R.string.pref_shortcut_left_default)); } else { return prefs.getString(mService.getString(R.string.pref_shortcut_right_key), mService.getString(R.string.pref_shortcut_right_default)); } case AccessibilityService.GESTURE_SWIPE_UP_AND_DOWN: { if (prefs.contains(mService.getString(R.string.pref_shortcut_up_and_down_key))) { return prefs.getString(mService.getString(R.string.pref_shortcut_up_and_down_key), mService.getString(R.string.pref_shortcut_up_and_down_default)); } if (prefs.contains(mService.getString(R.string.pref_two_part_vertical_gestures_key))) { String pref = prefs.getString(mService.getString(R.string.pref_two_part_vertical_gestures_key), mService.getString(R.string.value_two_part_vertical_gestures_jump)); if (pref.equals(mService.getString(R.string.value_two_part_vertical_gestures_jump))) { return mService.getString(R.string.shortcut_value_first_in_screen); } if (pref.equals(mService.getString(R.string.value_two_part_vertical_gestures_cycle))) { return mService.getString(R.string.shortcut_value_previous_granularity); } } return mService.getString(R.string.pref_shortcut_up_and_down_default); } case AccessibilityService.GESTURE_SWIPE_DOWN_AND_UP: { if (prefs.contains(mService.getString(R.string.pref_shortcut_down_and_up_key))) { return prefs.getString(mService.getString(R.string.pref_shortcut_down_and_up_key), mService.getString(R.string.pref_shortcut_down_and_up_default)); } if (prefs.contains(mService.getString(R.string.pref_two_part_vertical_gestures_key))) { String pref = prefs.getString(mService.getString(R.string.pref_two_part_vertical_gestures_key), mService.getString(R.string.value_two_part_vertical_gestures_jump)); if (pref.equals(mService.getString(R.string.value_two_part_vertical_gestures_jump))) { return mService.getString(R.string.shortcut_value_last_in_screen); } if (pref.equals(mService.getString(R.string.value_two_part_vertical_gestures_cycle))) { return mService.getString(R.string.shortcut_value_next_granularity); } } return mService.getString(R.string.pref_shortcut_down_and_up_default); } case AccessibilityService.GESTURE_SWIPE_LEFT_AND_RIGHT: return prefs.getString(mService.getString(R.string.pref_shortcut_left_and_right_key), mService.getString(R.string.pref_shortcut_left_and_right_default)); case AccessibilityService.GESTURE_SWIPE_RIGHT_AND_LEFT: return prefs.getString(mService.getString(R.string.pref_shortcut_right_and_left_key), mService.getString(R.string.pref_shortcut_right_and_left_default)); case AccessibilityService.GESTURE_SWIPE_UP_AND_LEFT: return prefs.getString(mService.getString(R.string.pref_shortcut_up_and_left_key), mService.getString(R.string.pref_shortcut_up_and_left_default)); case AccessibilityService.GESTURE_SWIPE_UP_AND_RIGHT: return prefs.getString(mService.getString(R.string.pref_shortcut_up_and_right_key), mService.getString(R.string.pref_shortcut_up_and_right_default)); case AccessibilityService.GESTURE_SWIPE_DOWN_AND_LEFT: return prefs.getString(mService.getString(R.string.pref_shortcut_down_and_left_key), mService.getString(R.string.pref_shortcut_down_and_left_default)); case AccessibilityService.GESTURE_SWIPE_DOWN_AND_RIGHT: return prefs.getString(mService.getString(R.string.pref_shortcut_down_and_right_key), mService.getString(R.string.pref_shortcut_down_and_right_default)); case AccessibilityService.GESTURE_SWIPE_RIGHT_AND_DOWN: return prefs.getString(mService.getString(R.string.pref_shortcut_right_and_down_key), mService.getString(R.string.pref_shortcut_right_and_down_default)); case AccessibilityService.GESTURE_SWIPE_RIGHT_AND_UP: return prefs.getString(mService.getString(R.string.pref_shortcut_right_and_up_key), mService.getString(R.string.pref_shortcut_right_and_up_default)); case AccessibilityService.GESTURE_SWIPE_LEFT_AND_DOWN: return prefs.getString(mService.getString(R.string.pref_shortcut_left_and_down_key), mService.getString(R.string.pref_shortcut_left_and_down_default)); case AccessibilityService.GESTURE_SWIPE_LEFT_AND_UP: return prefs.getString(mService.getString(R.string.pref_shortcut_left_and_up_key), mService.getString(R.string.pref_shortcut_left_and_up_default)); default: return mService.getString(R.string.shortcut_value_unassigned); } }
From source file:com.android.talkback.controller.GestureControllerApp.java
private String actionFromGesture(int gesture) { SharedPreferences prefs = SharedPreferencesUtils.getSharedPreferences(mService); switch (gesture) { case AccessibilityService.GESTURE_SWIPE_UP: return prefs.getString(mService.getString(R.string.pref_shortcut_up_key), mService.getString(R.string.pref_shortcut_up_default)); case AccessibilityService.GESTURE_SWIPE_DOWN: return prefs.getString(mService.getString(R.string.pref_shortcut_down_key), mService.getString(R.string.pref_shortcut_down_default)); case AccessibilityService.GESTURE_SWIPE_LEFT: if (mService.isScreenLayoutRTL()) { return prefs.getString(mService.getString(R.string.pref_shortcut_right_key), mService.getString(R.string.pref_shortcut_right_default)); } else {/*from w ww . j a v a2 s .com*/ return prefs.getString(mService.getString(R.string.pref_shortcut_left_key), mService.getString(R.string.pref_shortcut_left_default)); } case AccessibilityService.GESTURE_SWIPE_RIGHT: if (mService.isScreenLayoutRTL()) { return prefs.getString(mService.getString(R.string.pref_shortcut_left_key), mService.getString(R.string.pref_shortcut_left_default)); } else { return prefs.getString(mService.getString(R.string.pref_shortcut_right_key), mService.getString(R.string.pref_shortcut_right_default)); } case AccessibilityService.GESTURE_SWIPE_UP_AND_DOWN: { if (prefs.contains(mService.getString(R.string.pref_shortcut_up_and_down_key))) { return prefs.getString(mService.getString(R.string.pref_shortcut_up_and_down_key), mService.getString(R.string.pref_shortcut_up_and_down_default)); } if (prefs.contains(mService.getString(R.string.pref_two_part_vertical_gestures_key))) { String pref = prefs.getString(mService.getString(R.string.pref_two_part_vertical_gestures_key), mService.getString(R.string.value_two_part_vertical_gestures_jump)); if (pref.equals(mService.getString(R.string.value_two_part_vertical_gestures_jump))) { return mService.getString(R.string.shortcut_value_first_in_screen); } if (pref.equals(mService.getString(R.string.value_two_part_vertical_gestures_cycle))) { return mService.getString(R.string.shortcut_value_previous_granularity); } } return mService.getString(R.string.pref_shortcut_up_and_down_default); } case AccessibilityService.GESTURE_SWIPE_DOWN_AND_UP: { if (prefs.contains(mService.getString(R.string.pref_shortcut_down_and_up_key))) { return prefs.getString(mService.getString(R.string.pref_shortcut_down_and_up_key), mService.getString(R.string.pref_shortcut_down_and_up_default)); } if (prefs.contains(mService.getString(R.string.pref_two_part_vertical_gestures_key))) { String pref = prefs.getString(mService.getString(R.string.pref_two_part_vertical_gestures_key), mService.getString(R.string.value_two_part_vertical_gestures_jump)); if (pref.equals(mService.getString(R.string.value_two_part_vertical_gestures_jump))) { return mService.getString(R.string.shortcut_value_last_in_screen); } if (pref.equals(mService.getString(R.string.value_two_part_vertical_gestures_cycle))) { return mService.getString(R.string.shortcut_value_next_granularity); } } return mService.getString(R.string.pref_shortcut_down_and_up_default); } case AccessibilityService.GESTURE_SWIPE_LEFT_AND_RIGHT: return prefs.getString(mService.getString(R.string.pref_shortcut_left_and_right_key), mService.getString(R.string.pref_shortcut_left_and_right_default)); case AccessibilityService.GESTURE_SWIPE_RIGHT_AND_LEFT: return prefs.getString(mService.getString(R.string.pref_shortcut_right_and_left_key), mService.getString(R.string.pref_shortcut_right_and_left_default)); case AccessibilityService.GESTURE_SWIPE_UP_AND_LEFT: return prefs.getString(mService.getString(R.string.pref_shortcut_up_and_left_key), mService.getString(R.string.pref_shortcut_up_and_left_default)); case AccessibilityService.GESTURE_SWIPE_UP_AND_RIGHT: return prefs.getString(mService.getString(R.string.pref_shortcut_up_and_right_key), mService.getString(R.string.pref_shortcut_up_and_right_default)); case AccessibilityService.GESTURE_SWIPE_DOWN_AND_LEFT: return prefs.getString(mService.getString(R.string.pref_shortcut_down_and_left_key), mService.getString(R.string.pref_shortcut_down_and_left_default)); case AccessibilityService.GESTURE_SWIPE_DOWN_AND_RIGHT: return prefs.getString(mService.getString(R.string.pref_shortcut_down_and_right_key), mService.getString(R.string.pref_shortcut_down_and_right_default)); case AccessibilityService.GESTURE_SWIPE_RIGHT_AND_DOWN: return prefs.getString(mService.getString(R.string.pref_shortcut_right_and_down_key), mService.getString(R.string.pref_shortcut_right_and_down_default)); case AccessibilityService.GESTURE_SWIPE_RIGHT_AND_UP: return prefs.getString(mService.getString(R.string.pref_shortcut_right_and_up_key), mService.getString(R.string.pref_shortcut_right_and_up_default)); case AccessibilityService.GESTURE_SWIPE_LEFT_AND_DOWN: return prefs.getString(mService.getString(R.string.pref_shortcut_left_and_down_key), mService.getString(R.string.pref_shortcut_left_and_down_default)); case AccessibilityService.GESTURE_SWIPE_LEFT_AND_UP: return prefs.getString(mService.getString(R.string.pref_shortcut_left_and_up_key), mService.getString(R.string.pref_shortcut_left_and_up_default)); default: return mService.getString(R.string.shortcut_value_unassigned); } }
From source file:com.almalence.opencam.ApplicationScreen.java
@Override public boolean getExpoPreviewPref() { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mainContext); if (true == prefs.contains(ApplicationScreen.sExpoPreviewModePref)) { return prefs.getBoolean(ApplicationScreen.sExpoPreviewModePref, true); } else/*from w ww .j a va 2 s . c o m*/ return true; }
From source file:org.runnerup.view.MainLayout.java
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); setContentView(R.layout.main);/* w w w . j a v a 2 s.c o m*/ int versionCode = 0; UpgradeState upgradeState = UpgradeState.UNKNOWN; SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(this); Editor editor = pref.edit(); try { PackageInfo pInfo = getPackageManager().getPackageInfo(getPackageName(), 0); versionCode = pInfo.versionCode; int version = pref.getInt("app-version", -1); if (version == -1) { upgradeState = UpgradeState.NEW; } else if (versionCode == version) { upgradeState = UpgradeState.SAME; } else if (versionCode > version) { upgradeState = UpgradeState.UPGRADE; } else if (versionCode < version) { upgradeState = UpgradeState.DOWNGRADE; } } catch (NameNotFoundException e) { e.printStackTrace(); } editor.putInt("app-version", versionCode); boolean km = Formatter.getUseKilometers(getResources(), pref, editor); if (upgradeState == UpgradeState.NEW) { editor.putString(getResources().getString(R.string.pref_autolap), Double.toString(km ? Formatter.km_meters : Formatter.mi_meters)); } editor.commit(); // clear basicTargetType between application startup/shutdown pref.edit().remove(getString(R.string.pref_basic_target_type)).commit(); Log.e(getClass().getName(), "app-version: " + versionCode + ", upgradeState: " + upgradeState + ", km: " + km); // convert pref_mute to pref_mute_bool Resources res = getResources(); try { if (pref.contains(res.getString(R.string.pref_mute))) { String v = pref.getString(res.getString(R.string.pref_mute), "no"); editor.putBoolean(res.getString(R.string.pref_mute_bool), v.equalsIgnoreCase("yes")); editor.remove(res.getString(R.string.pref_mute)); editor.commit(); } } catch (Exception e) { } PreferenceManager.setDefaultValues(this, R.xml.settings, false); PreferenceManager.setDefaultValues(this, R.xml.audio_cue_settings, true); TabHost tabHost = getTabHost(); // The activity TabHost tabHost.addTab(tabHost.newTabSpec("Start") .setIndicator(getString(R.string.Start), myGetDrawable(R.drawable.ic_tab_main)) .setContent(new Intent(this, StartActivity.class))); tabHost.addTab(tabHost.newTabSpec("Feed") .setIndicator(getString(R.string.feed), myGetDrawable(R.drawable.ic_tab_feed)) .setContent(new Intent(this, FeedActivity.class))); tabHost.addTab(tabHost.newTabSpec("History") .setIndicator(getString(R.string.History), myGetDrawable(R.drawable.ic_tab_history)) .setContent(new Intent(this, HistoryActivity.class))); tabHost.addTab(tabHost.newTabSpec("Settings") .setIndicator(getString(R.string.Settings), myGetDrawable(R.drawable.ic_tab_setup)) .setContent(new Intent(this, SettingsActivity.class))); tabHost.setCurrentTab(0); WidgetUtil.addLegacyOverflowButton(getWindow()); if (upgradeState == UpgradeState.UPGRADE) { whatsNew(); } //GPS is essential, always nag user if not granted requestGpsPermissions(this, tabHost.getCurrentView()); //Import workouts/schemes. No permission needed handleBundled(getApplicationContext().getAssets(), "bundled", getFilesDir().getPath() + "/.."); // if we were called from an intent-filter because user opened "runnerup.db.export", load it final Uri data = getIntent().getData(); if (data != null) { if (SettingsActivity.requestReadStoragePermissions(MainLayout.this)) { String filePath = null; if ("content".equals(data.getScheme())) { Cursor cursor = this.getContentResolver().query(data, new String[] { android.provider.MediaStore.Images.ImageColumns.DATA }, null, null, null); cursor.moveToFirst(); filePath = cursor.getString(0); cursor.close(); } else { filePath = data.getPath(); } Log.i(getClass().getSimpleName(), "Importing database from " + filePath); DBHelper.importDatabase(MainLayout.this, filePath); } else { Toast.makeText(this, "Storage permission not granted in Android settings, db is not imported.", Toast.LENGTH_SHORT).show(); } } }
From source file:com.apptentive.android.sdk.module.messagecenter.view.MessageCenterActivityContent.java
@Override public void onComposingViewCreated() { EngagementModule.engageInternal(viewActivity, interaction, MessageCenterInteraction.EVENT_NAME_COMPOSE_OPEN); messageEditText = messageCenterListAdapter.getEditTextInComposing(); SharedPreferences prefs = viewActivity.getSharedPreferences(Constants.PREF_NAME, Context.MODE_PRIVATE); // Restore composing text editing state, such as cursor position, after rotation if (composingViewSavedState != null) { messageEditText.onRestoreInstanceState(composingViewSavedState); composingViewSavedState = null;//w ww. ja v a2 s .com SharedPreferences.Editor editor = prefs.edit(); editor.remove(Constants.PREF_KEY_MESSAGE_CENTER_PENDING_COMPOSING_MESSAGE).commit(); } // Restore composing text if (prefs.contains(Constants.PREF_KEY_MESSAGE_CENTER_PENDING_COMPOSING_MESSAGE)) { String messageText = prefs.getString(Constants.PREF_KEY_MESSAGE_CENTER_PENDING_COMPOSING_MESSAGE, null); if (messageText != null) { messageEditText.setText(messageText); } // Stored pending composing text has been restored, remove it from the persistent storage SharedPreferences.Editor editor = prefs.edit(); editor.remove(Constants.PREF_KEY_MESSAGE_CENTER_PENDING_COMPOSING_MESSAGE).commit(); } // Restore composing attachments if (prefs.contains(Constants.PREF_KEY_MESSAGE_CENTER_PENDING_COMPOSING_ATTACHMENTS)) { JSONArray jArray = null; try { jArray = new JSONArray( prefs.getString(Constants.PREF_KEY_MESSAGE_CENTER_PENDING_COMPOSING_ATTACHMENTS, "")); } catch (JSONException e) { e.printStackTrace(); } if (jArray != null && jArray.length() > 0) { if (savedAttachmentstList == null) { savedAttachmentstList = new ArrayList<ImageItem>(); } for (int i = 0; i < jArray.length(); i++) { try { JSONObject json = jArray.getJSONObject(i); if (json != null) { savedAttachmentstList.add(new ImageItem(json)); } } catch (JSONException e) { continue; } } } // Stored pending attachemnts have been restored, remove it from the persistent storage SharedPreferences.Editor editor = prefs.edit(); editor.remove(Constants.PREF_KEY_MESSAGE_CENTER_PENDING_COMPOSING_ATTACHMENTS).commit(); } if (savedAttachmentstList != null) { restoreSavedAttachmentsToComposer(savedAttachmentstList); savedAttachmentstList = null; } messageCenterListView.setPadding(0, 0, 0, 0); }