List of usage examples for android.content SharedPreferences getInt
int getInt(String key, int defValue);
From source file:com.farmerbb.notepad.fragment.NoteViewFragment.java
@TargetApi(Build.VERSION_CODES.LOLLIPOP) @Override/*from w w w.j av a2s. c o m*/ public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); // Set values setRetainInstance(true); setHasOptionsMenu(true); // Get filename of saved note filename = getArguments().getString("filename"); // Change window title String title; try { title = listener.loadNoteTitle(filename); } catch (IOException e) { title = getResources().getString(R.string.view_note); } getActivity().setTitle(title); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { Bitmap bitmap = ((BitmapDrawable) ContextCompat.getDrawable(getActivity(), R.drawable.ic_recents_logo)) .getBitmap(); ActivityManager.TaskDescription taskDescription = new ActivityManager.TaskDescription(title, bitmap, ContextCompat.getColor(getActivity(), R.color.primary)); getActivity().setTaskDescription(taskDescription); } // Show the Up button in the action bar. ((AppCompatActivity) getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(true); // Animate elevation change if (getActivity().findViewById(R.id.layoutMain).getTag().equals("main-layout-large") && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { LinearLayout noteViewEdit = getActivity().findViewById(R.id.noteViewEdit); LinearLayout noteList = getActivity().findViewById(R.id.noteList); noteList.animate().z(0f); if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) noteViewEdit.animate() .z(getResources().getDimensionPixelSize(R.dimen.note_view_edit_elevation_land)); else noteViewEdit.animate().z(getResources().getDimensionPixelSize(R.dimen.note_view_edit_elevation)); } // Set up content view TextView noteContents = getActivity().findViewById(R.id.textView); markdownView = getActivity().findViewById(R.id.markdownView); // Apply theme SharedPreferences pref = getActivity().getSharedPreferences(getActivity().getPackageName() + "_preferences", Context.MODE_PRIVATE); ScrollView scrollView = getActivity().findViewById(R.id.scrollView); String theme = pref.getString("theme", "light-sans"); int textSize = -1; int textColor = -1; String fontFamily = null; if (theme.contains("light")) { if (noteContents != null) { noteContents.setTextColor(ContextCompat.getColor(getActivity(), R.color.text_color_primary)); noteContents.setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.window_background)); } if (markdownView != null) { markdownView.setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.window_background)); textColor = ContextCompat.getColor(getActivity(), R.color.text_color_primary); } scrollView.setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.window_background)); } if (theme.contains("dark")) { if (noteContents != null) { noteContents.setTextColor(ContextCompat.getColor(getActivity(), R.color.text_color_primary_dark)); noteContents .setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.window_background_dark)); } if (markdownView != null) { markdownView .setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.window_background_dark)); textColor = ContextCompat.getColor(getActivity(), R.color.text_color_primary_dark); } scrollView.setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.window_background_dark)); } if (theme.contains("sans")) { if (noteContents != null) noteContents.setTypeface(Typeface.SANS_SERIF); if (markdownView != null) fontFamily = "sans-serif"; } if (theme.contains("serif")) { if (noteContents != null) noteContents.setTypeface(Typeface.SERIF); if (markdownView != null) fontFamily = "serif"; } if (theme.contains("monospace")) { if (noteContents != null) noteContents.setTypeface(Typeface.MONOSPACE); if (markdownView != null) fontFamily = "monospace"; } switch (pref.getString("font_size", "normal")) { case "smallest": textSize = 12; break; case "small": textSize = 14; break; case "normal": textSize = 16; break; case "large": textSize = 18; break; case "largest": textSize = 20; break; } if (noteContents != null) noteContents.setTextSize(textSize); String css = ""; if (markdownView != null) { String topBottom = " " + Float.toString(getResources().getDimension(R.dimen.padding_top_bottom) / getResources().getDisplayMetrics().density) + "px"; String leftRight = " " + Float.toString(getResources().getDimension(R.dimen.padding_left_right) / getResources().getDisplayMetrics().density) + "px"; String fontSize = " " + Integer.toString(textSize) + "px"; String fontColor = " #" + StringUtils.remove(Integer.toHexString(textColor), "ff"); String linkColor = " #" + StringUtils.remove( Integer.toHexString(new TextView(getActivity()).getLinkTextColors().getDefaultColor()), "ff"); css = "body { " + "margin:" + topBottom + topBottom + leftRight + leftRight + "; " + "font-family:" + fontFamily + "; " + "font-size:" + fontSize + "; " + "color:" + fontColor + "; " + "}" + "a { " + "color:" + linkColor + "; " + "}"; markdownView.getSettings().setJavaScriptEnabled(false); markdownView.getSettings().setLoadsImagesAutomatically(false); markdownView.setWebViewClient(new WebViewClient() { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) try { startActivity(intent); } catch (ActivityNotFoundException | FileUriExposedException e) { /* Gracefully fail */ } else try { startActivity(intent); } catch (ActivityNotFoundException e) { /* Gracefully fail */ } return true; } }); } // Load note contents try { contentsOnLoad = listener.loadNote(filename); } catch (IOException e) { showToast(R.string.error_loading_note); // Add NoteListFragment or WelcomeFragment Fragment fragment; if (getActivity().findViewById(R.id.layoutMain).getTag().equals("main-layout-normal")) fragment = new NoteListFragment(); else fragment = new WelcomeFragment(); getFragmentManager().beginTransaction().replace(R.id.noteViewEdit, fragment, "NoteListFragment") .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN).commit(); } // Set TextView contents if (noteContents != null) noteContents.setText(contentsOnLoad); if (markdownView != null) markdownView.loadMarkdown(contentsOnLoad, "data:text/css;base64," + Base64.encodeToString(css.getBytes(), Base64.DEFAULT)); // Show a toast message if this is the user's first time viewing a note final SharedPreferences sharedPref = getActivity().getPreferences(Context.MODE_PRIVATE); firstLoad = sharedPref.getInt("first-load", 0); if (firstLoad == 0) { // Show dialog with info DialogFragment firstLoad = new FirstViewDialogFragment(); firstLoad.show(getFragmentManager(), "firstloadfragment"); // Set first-load preference to 1; we don't need to show the dialog anymore SharedPreferences.Editor editor = sharedPref.edit(); editor.putInt("first-load", 1); editor.apply(); } // Detect single and double-taps using GestureDetector final GestureDetector detector = new GestureDetector(getActivity(), new GestureDetector.OnGestureListener() { @Override public boolean onSingleTapUp(MotionEvent e) { return false; } @Override public void onShowPress(MotionEvent e) { } @Override public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) { return false; } @Override public void onLongPress(MotionEvent e) { } @Override public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { return false; } @Override public boolean onDown(MotionEvent e) { return false; } }); detector.setOnDoubleTapListener(new GestureDetector.OnDoubleTapListener() { @Override public boolean onDoubleTap(MotionEvent e) { if (sharedPref.getBoolean("show_double_tap_message", true)) { SharedPreferences.Editor editor = sharedPref.edit(); editor.putBoolean("show_double_tap_message", false); editor.apply(); } Bundle bundle = new Bundle(); bundle.putString("filename", filename); Fragment fragment = new NoteEditFragment(); fragment.setArguments(bundle); getFragmentManager().beginTransaction().replace(R.id.noteViewEdit, fragment, "NoteEditFragment") .commit(); return false; } @Override public boolean onDoubleTapEvent(MotionEvent e) { return false; } @Override public boolean onSingleTapConfirmed(MotionEvent e) { if (sharedPref.getBoolean("show_double_tap_message", true) && showMessage) { showToastLong(R.string.double_tap); showMessage = false; } return false; } }); if (noteContents != null) noteContents.setOnTouchListener((v, event) -> { detector.onTouchEvent(event); return false; }); if (markdownView != null) markdownView.setOnTouchListener((v, event) -> { detector.onTouchEvent(event); return false; }); }
From source file:com.ihelpoo.app.api.ApiClient.java
/** * ?//ww w . j a v a 2 s. c o m * * @param Tweet-uid & msg & image * @return * @throws AppException */ public static Result pubTweet(AppContext appContext, Tweet tweet) throws AppException { SharedPreferences preferences = appContext.getSharedPreferences(NavWelcome.GLOBAL_CONFIG, AppContext.MODE_PRIVATE); int targetSchool = preferences.getInt(NavWelcome.CHOOSE_SCHOOL, NavWelcome.DEFAULT_SCHOOL); Map<String, Object> params = new HashMap<String, Object>(); params.put("uid", tweet.getAuthorId()); params.put("msg", tweet.getBody()); params.put("reward", tweet.getReward()); params.put("target_school", targetSchool); Map<String, File> files = new HashMap<String, File>(); if (tweet.getImageFile() != null) files.put("img", tweet.getImageFile()); try { return http_post(appContext, URLs.TWEET_PUB, params, files); } catch (Exception e) { if (e instanceof AppException) throw (AppException) e; throw AppException.network(e); } }
From source file:com.anjalimacwan.fragment.NoteViewFragment.java
@SuppressLint("SetJavaScriptEnabled") @TargetApi(Build.VERSION_CODES.LOLLIPOP) @Override/* w ww . j a va 2 s .c o m*/ public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); // Set values setRetainInstance(true); setHasOptionsMenu(true); // Get filename of saved note filename = getArguments().getString("filename"); // Change window title String title; try { title = listener.loadNoteTitle(filename); } catch (IOException e) { title = getResources().getString(R.string.view_note); } getActivity().setTitle(title); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { ActivityManager.TaskDescription taskDescription = new ActivityManager.TaskDescription(title, null, ContextCompat.getColor(getActivity(), R.color.primary)); getActivity().setTaskDescription(taskDescription); } // Show the Up button in the action bar. ((AppCompatActivity) getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(true); // Animate elevation change if (getActivity().findViewById(R.id.layoutMain).getTag().equals("main-layout-large") && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { LinearLayout noteViewEdit = (LinearLayout) getActivity().findViewById(R.id.noteViewEdit); LinearLayout noteList = (LinearLayout) getActivity().findViewById(R.id.noteList); noteList.animate().z(0f); if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) noteViewEdit.animate() .z(getResources().getDimensionPixelSize(R.dimen.note_view_edit_elevation_land)); else noteViewEdit.animate().z(getResources().getDimensionPixelSize(R.dimen.note_view_edit_elevation)); } // Set up content view TextView noteContents = (TextView) getActivity().findViewById(R.id.textView); markdownView = (MarkdownView) getActivity().findViewById(R.id.markdownView); // Apply theme SharedPreferences pref = getActivity().getSharedPreferences(getActivity().getPackageName() + "_preferences", Context.MODE_PRIVATE); ScrollView scrollView = (ScrollView) getActivity().findViewById(R.id.scrollView); String theme = pref.getString("theme", "light-sans"); int textSize = -1; int textColor = -1; String fontFamily = null; if (theme.contains("light")) { if (noteContents != null) { noteContents.setTextColor(ContextCompat.getColor(getActivity(), R.color.text_color_primary)); noteContents.setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.window_background)); } if (markdownView != null) { markdownView.setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.window_background)); textColor = ContextCompat.getColor(getActivity(), R.color.text_color_primary); } scrollView.setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.window_background)); } if (theme.contains("dark")) { if (noteContents != null) { noteContents.setTextColor(ContextCompat.getColor(getActivity(), R.color.text_color_primary_dark)); noteContents .setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.window_background_dark)); } if (markdownView != null) { markdownView .setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.window_background_dark)); textColor = ContextCompat.getColor(getActivity(), R.color.text_color_primary_dark); } scrollView.setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.window_background_dark)); } if (theme.contains("sans")) { if (noteContents != null) noteContents.setTypeface(Typeface.SANS_SERIF); if (markdownView != null) fontFamily = "sans-serif"; } if (theme.contains("serif")) { if (noteContents != null) noteContents.setTypeface(Typeface.SERIF); if (markdownView != null) fontFamily = "serif"; } if (theme.contains("monospace")) { if (noteContents != null) noteContents.setTypeface(Typeface.MONOSPACE); if (markdownView != null) fontFamily = "monospace"; } switch (pref.getString("font_size", "normal")) { case "smallest": textSize = 12; break; case "small": textSize = 14; break; case "normal": textSize = 16; break; case "large": textSize = 18; break; case "largest": textSize = 20; break; } if (noteContents != null) noteContents.setTextSize(textSize); if (markdownView != null) { String topBottom = " " + Float.toString(getResources().getDimension(R.dimen.padding_top_bottom) / getResources().getDisplayMetrics().density) + "px"; String leftRight = " " + Float.toString(getResources().getDimension(R.dimen.padding_left_right) / getResources().getDisplayMetrics().density) + "px"; String fontSize = " " + Integer.toString(textSize) + "px"; String fontColor = " #" + StringUtils.remove(Integer.toHexString(textColor), "ff"); final String css = "body { " + "margin:" + topBottom + topBottom + leftRight + leftRight + "; " + "font-family:" + fontFamily + "; " + "font-size:" + fontSize + "; " + "color:" + fontColor + "; " + "}"; final String js = "var styleNode = document.createElement('style');\n" + "styleNode.type = \"text/css\";\n" + "var styleText = document.createTextNode('" + css + "');\n" + "styleNode.appendChild(styleText);\n" + "document.getElementsByTagName('head')[0].appendChild(styleNode);\n"; markdownView.getSettings().setJavaScriptEnabled(true); markdownView.getSettings().setLoadsImagesAutomatically(false); markdownView.setWebViewClient(new WebViewClient() { @TargetApi(Build.VERSION_CODES.N) @Override public void onLoadResource(WebView view, String url) { view.stopLoading(); Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) try { startActivity(intent); } catch (ActivityNotFoundException | FileUriExposedException e) { /* Gracefully fail */ } else try { startActivity(intent); } catch (ActivityNotFoundException e) { /* Gracefully fail */ } } @Override public void onPageFinished(WebView view, String url) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) view.evaluateJavascript(js, null); else view.loadUrl("javascript:" + js); } }); } // Load note contents try { contentsOnLoad = listener.loadNote(filename); } catch (IOException e) { showToast(R.string.error_loading_note); // Add NoteListFragment or WelcomeFragment Fragment fragment; if (getActivity().findViewById(R.id.layoutMain).getTag().equals("main-layout-normal")) fragment = new NoteListFragment(); else fragment = new WelcomeFragment(); getFragmentManager().beginTransaction().replace(R.id.noteViewEdit, fragment, "NoteListFragment") .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN).commit(); } // Set TextView contents if (noteContents != null) noteContents.setText(contentsOnLoad); if (markdownView != null) markdownView.loadMarkdown(contentsOnLoad); // Show a toast message if this is the user's first time viewing a note final SharedPreferences sharedPref = getActivity().getPreferences(Context.MODE_PRIVATE); firstLoad = sharedPref.getInt("first-load", 0); if (firstLoad == 0) { // Show dialog with info DialogFragment firstLoad = new FirstViewDialogFragment(); firstLoad.show(getFragmentManager(), "firstloadfragment"); // Set first-load preference to 1; we don't need to show the dialog anymore SharedPreferences.Editor editor = sharedPref.edit(); editor.putInt("first-load", 1); editor.apply(); } // Detect single and double-taps using GestureDetector final GestureDetector detector = new GestureDetector(getActivity(), new GestureDetector.OnGestureListener() { @Override public boolean onSingleTapUp(MotionEvent e) { return false; } @Override public void onShowPress(MotionEvent e) { } @Override public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) { return false; } @Override public void onLongPress(MotionEvent e) { } @Override public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { return false; } @Override public boolean onDown(MotionEvent e) { return false; } }); detector.setOnDoubleTapListener(new GestureDetector.OnDoubleTapListener() { @Override public boolean onDoubleTap(MotionEvent e) { if (sharedPref.getBoolean("show_double_tap_message", true)) { SharedPreferences.Editor editor = sharedPref.edit(); editor.putBoolean("show_double_tap_message", false); editor.apply(); } Bundle bundle = new Bundle(); bundle.putString("filename", filename); Fragment fragment = new NoteEditFragment(); fragment.setArguments(bundle); getFragmentManager().beginTransaction().replace(R.id.noteViewEdit, fragment, "NoteEditFragment") .commit(); return false; } @Override public boolean onDoubleTapEvent(MotionEvent e) { return false; } @Override public boolean onSingleTapConfirmed(MotionEvent e) { if (sharedPref.getBoolean("show_double_tap_message", true) && showMessage) { showToastLong(R.string.double_tap); showMessage = false; } return false; } }); if (noteContents != null) noteContents.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { detector.onTouchEvent(event); return false; } }); if (markdownView != null) markdownView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { detector.onTouchEvent(event); return false; } }); }
From source file:com.farmerbb.notepad.activity.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { // Set action bar elevation getSupportActionBar().setElevation(getResources().getDimensionPixelSize(R.dimen.action_bar_elevation)); }/*from w w w . j a v a 2 s .com*/ // Show dialog if this is the user's first time running Notepad SharedPreferences prefMain = getPreferences(Context.MODE_PRIVATE); if (prefMain.getInt("first-run", 0) == 0) { // Show welcome dialog if (getSupportFragmentManager().findFragmentByTag("firstrunfragment") == null) { DialogFragment firstRun = new FirstRunDialogFragment(); firstRun.show(getSupportFragmentManager(), "firstrunfragment"); } } else { // The following code is only present to support existing users of Notepad on Google Play // and can be removed if using this source code for a different app // Convert old preferences to new ones SharedPreferences pref = getSharedPreferences(getPackageName() + "_preferences", Context.MODE_PRIVATE); if (prefMain.getInt("sort-by", -1) == 0) { SharedPreferences.Editor editor = pref.edit(); SharedPreferences.Editor editorMain = prefMain.edit(); editor.putString("sort_by", "date"); editorMain.putInt("sort-by", -1); editor.apply(); editorMain.apply(); } else if (prefMain.getInt("sort-by", -1) == 1) { SharedPreferences.Editor editor = pref.edit(); SharedPreferences.Editor editorMain = prefMain.edit(); editor.putString("sort_by", "name"); editorMain.putInt("sort-by", -1); editor.apply(); editorMain.apply(); } if (pref.getString("font_size", "null").equals("null")) { SharedPreferences.Editor editor = pref.edit(); editor.putString("font_size", "large"); editor.apply(); } // Rename any saved drafts from 1.3.x File oldDraft = new File(getFilesDir() + File.separator + "draft"); File newDraft = new File(getFilesDir() + File.separator + String.valueOf(System.currentTimeMillis())); if (oldDraft.exists()) oldDraft.renameTo(newDraft); } // Begin a new FragmentTransaction FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); // This fragment shows NoteListFragment as a sidebar (only seen in tablet mode landscape) if (!(getSupportFragmentManager().findFragmentById(R.id.noteList) instanceof NoteListFragment)) transaction.replace(R.id.noteList, new NoteListFragment(), "NoteListFragment"); // This fragment shows NoteListFragment in the main screen area (only seen on phones and tablet mode portrait), // but only if it doesn't already contain NoteViewFragment or NoteEditFragment. // If NoteListFragment is already showing in the sidebar, use WelcomeFragment instead if (!((getSupportFragmentManager().findFragmentById(R.id.noteViewEdit) instanceof NoteEditFragment) || (getSupportFragmentManager().findFragmentById(R.id.noteViewEdit) instanceof NoteViewFragment))) { if ((getSupportFragmentManager().findFragmentById(R.id.noteViewEdit) == null && findViewById(R.id.layoutMain).getTag().equals("main-layout-large")) || ((getSupportFragmentManager() .findFragmentById(R.id.noteViewEdit) instanceof NoteListFragment) && findViewById(R.id.layoutMain).getTag().equals("main-layout-large"))) transaction.replace(R.id.noteViewEdit, new WelcomeFragment(), "NoteListFragment"); else if (findViewById(R.id.layoutMain).getTag().equals("main-layout-normal")) transaction.replace(R.id.noteViewEdit, new NoteListFragment(), "NoteListFragment"); } // Commit fragment transaction transaction.commit(); if (savedInstanceState != null) { ArrayList<String> filesToExportList = savedInstanceState.getStringArrayList("files_to_export"); if (filesToExportList != null) filesToExport = filesToExportList.toArray(); ArrayList<String> filesToDeleteList = savedInstanceState.getStringArrayList("files_to_delete"); if (filesToDeleteList != null) filesToDelete = filesToDeleteList.toArray(); ArrayList<String> savedCab = savedInstanceState.getStringArrayList("cab"); if (savedCab != null) { inCabMode = true; cab = savedCab; } } }
From source file:com.dattasmoon.pebble.plugin.NotificationService.java
private void loadPrefs() { if (Constants.IS_LOGGABLE) { Log.i(Constants.LOG_TAG, "I am loading preferences"); }//from ww w .ja v a2 s . c o m SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this); SharedPreferences sharedPreferences = getSharedPreferences(Constants.LOG_TAG, MODE_MULTI_PROCESS | MODE_PRIVATE); //if old preferences exist, convert them. if (sharedPreferences.contains(Constants.LOG_TAG + ".mode")) { SharedPreferences.Editor editor = sharedPref.edit(); editor.putInt(Constants.PREFERENCE_MODE, sharedPreferences.getInt(Constants.LOG_TAG + ".mode", Constants.Mode.OFF.ordinal())); editor.putString(Constants.PREFERENCE_PACKAGE_LIST, sharedPreferences.getString(Constants.LOG_TAG + ".packageList", "")); editor.putBoolean(Constants.PREFERENCE_NOTIFICATIONS_ONLY, sharedPreferences.getBoolean(Constants.LOG_TAG + ".notificationsOnly", true)); editor.putBoolean(Constants.PREFERENCE_NOTIFICATION_EXTRA, sharedPreferences.getBoolean(Constants.LOG_TAG + ".fetchNotificationExtras", false)); editor.commit(); //clear out all old preferences editor = sharedPreferences.edit(); editor.clear(); editor.commit(); if (Constants.IS_LOGGABLE) { Log.i(Constants.LOG_TAG, "Converted preferences to new format. Old ones should be completely gone."); } } mode = Mode.values()[sharedPref.getInt(Constants.PREFERENCE_MODE, Mode.OFF.ordinal())]; if (Constants.IS_LOGGABLE) { Log.i(Constants.LOG_TAG, "Service package list is: " + sharedPref.getString(Constants.PREFERENCE_PACKAGE_LIST, "")); } packages = sharedPref.getString(Constants.PREFERENCE_PACKAGE_LIST, "").split(","); notifications_only = sharedPref.getBoolean(Constants.PREFERENCE_NOTIFICATIONS_ONLY, true); no_ongoing_notifs = sharedPref.getBoolean(Constants.PREFERENCE_NO_ONGOING_NOTIF, false); min_notification_wait = sharedPref.getInt(Constants.PREFERENCE_MIN_NOTIFICATION_WAIT, 0) * 1000; notification_extras = sharedPref.getBoolean(Constants.PREFERENCE_NOTIFICATION_EXTRA, false); notifScreenOn = sharedPref.getBoolean(Constants.PREFERENCE_NOTIF_SCREEN_ON, true); quiet_hours = sharedPref.getBoolean(Constants.PREFERENCE_QUIET_HOURS, false); try { converts = new JSONArray(sharedPref.getString(Constants.PREFERENCE_CONVERTS, "[]")); } catch (JSONException e) { converts = new JSONArray(); } try { ignores = new JSONArray(sharedPref.getString(Constants.PREFERENCE_IGNORE, "[]")); } catch (JSONException e) { ignores = new JSONArray(); } try { pkg_renames = new JSONArray(sharedPref.getString(Constants.PREFERENCE_PKG_RENAMES, "[]")); } catch (JSONException e) { pkg_renames = new JSONArray(); } //we only need to pull this if quiet hours are enabled. Save the cycles for the cpu! (haha) if (quiet_hours) { String[] pieces = sharedPref.getString(Constants.PREFERENCE_QUIET_HOURS_BEFORE, "00:00").split(":"); quiet_hours_before = new Date(0, 0, 0, Integer.parseInt(pieces[0]), Integer.parseInt(pieces[1])); pieces = sharedPref.getString(Constants.PREFERENCE_QUIET_HOURS_AFTER, "23:59").split(":"); quiet_hours_after = new Date(0, 0, 0, Integer.parseInt(pieces[0]), Integer.parseInt(pieces[1])); } lastChange = watchFile.lastModified(); }
From source file:com.pitchedapps.primenumbercalculator.Calculator.java
License:asdf
public void themeEngine() { SharedPreferences themes = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); themeDisplay = themes.getInt("theme_display", 0xFFFFFFFF); themeDisplayText = themes.getInt("theme_display_text", 0xFF000000); themeDisplayInput = ColorUtils.setAlphaComponent(themeDisplayText, 138); //8A transparency themeDisplayResult = ColorUtils.setAlphaComponent(themeDisplayText, 108); //6C transparency themeClearAccent = themes.getInt("theme_clear_accent", 0xFF00BCD4); themeNumpad = themes.getInt("theme_numpad", 0xFF434343); themeNumpadText = themes.getInt("theme_numpad_text", 0xFFFFFFFF); themeAdvancedNumpad = themes.getInt("theme_advanced_numpad", 0xFF1DE9B6); themeAdvancedNumpadText = ColorUtils .setAlphaComponent(themes.getInt("theme_advanced_numpad_text", 0xFF000000), 145); //91 transparency //adds black "cache" color with alpha depending on themeNumpad mPadViewPager.setBackgroundColor(ColorUtils.setAlphaComponent( ContextCompat.getColor(this, android.R.color.black), (new ColorDrawable(themeNumpad)).getAlpha())); mDisplayView.setBackgroundColor(themeDisplay); findViewById(R.id.pad_numeric).setBackgroundColor(themeNumpad); findViewById(R.id.root_layout).setBackgroundColor(themeAdvancedNumpad); mInputEditText.setTextColor(themeDisplayInput); mResultEditText.setTextColor(themeDisplayResult); getWindow().setStatusBarColor(themeClearAccent); //numpad section ((Button) findViewById(R.id.del)).setTextColor(themeNumpadText); ((Button) findViewById(R.id.clr)).setTextColor(themeNumpadText); ((Button) findViewById(R.id.eq)).setTextColor(themeNumpadText); ((Button) findViewById(R.id.digit_0)).setTextColor(themeNumpadText); ((Button) findViewById(R.id.digit_1)).setTextColor(themeNumpadText); ((Button) findViewById(R.id.digit_2)).setTextColor(themeNumpadText); ((Button) findViewById(R.id.digit_3)).setTextColor(themeNumpadText); ((Button) findViewById(R.id.digit_4)).setTextColor(themeNumpadText); ((Button) findViewById(R.id.digit_5)).setTextColor(themeNumpadText); ((Button) findViewById(R.id.digit_6)).setTextColor(themeNumpadText); ((Button) findViewById(R.id.digit_7)).setTextColor(themeNumpadText); ((Button) findViewById(R.id.digit_8)).setTextColor(themeNumpadText); ((Button) findViewById(R.id.digit_9)).setTextColor(themeNumpadText); //settings/advancedpad section ((Button) findViewById(R.id.advanced_themes)).setTextColor(themeAdvancedNumpadText); ((Button) findViewById(R.id.advanced_clear_list)).setTextColor(themeAdvancedNumpadText); ((Button) findViewById(R.id.advanced_help)).setTextColor(themeAdvancedNumpadText); ((Button) findViewById(R.id.advanced_contact_me)).setTextColor(themeAdvancedNumpadText); ((Button) findViewById(R.id.advanced_rate_app)).setTextColor(themeAdvancedNumpadText); ((Button) findViewById(R.id.advanced_share_app)).setTextColor(themeAdvancedNumpadText); ((Button) findViewById(R.id.advanced_about_dev)).setTextColor(themeAdvancedNumpadText); ((Button) findViewById(R.id.advanced_other_apps)).setTextColor(themeAdvancedNumpadText); ((Button) findViewById(R.id.advanced_google_plus)).setTextColor(themeAdvancedNumpadText); ((Button) findViewById(R.id.advanced_source)).setTextColor(themeAdvancedNumpadText); ((Button) findViewById(R.id.advanced_credits)).setTextColor(themeAdvancedNumpadText); ((Button) findViewById(R.id.advanced_donate)).setTextColor(themeAdvancedNumpadText); //donations theming done in donations fragment //help section ((TextView) findViewById(R.id.help_text)).setTextColor(themeAdvancedNumpadText); ((TextView) findViewById(R.id.help_version_number)).setTextColor(themeAdvancedNumpadText); ((TextView) findViewById(R.id.back_help)).setTextColor(themeAdvancedNumpadText); //credit back, rest are themed in the built in theme engine in the Library of Everything ((TextView) findViewById(R.id.back_credits)).setTextColor(themeAdvancedNumpadText); }
From source file:github.daneren2005.dsub.service.OfflineMusicService.java
@Override public void setStarred(List<Entry> entries, List<Entry> artists, List<Entry> albums, boolean starred, ProgressListener progressListener, Context context) throws Exception { SharedPreferences prefs = Util.getPreferences(context); String cacheLocn = prefs.getString(Constants.PREFERENCES_KEY_CACHE_LOCATION, null); SharedPreferences offline = Util.getOfflineSync(context); int stars = offline.getInt(Constants.OFFLINE_STAR_COUNT, 0); stars++;// w w w. j a va2 s. co m SharedPreferences.Editor offlineEditor = offline.edit(); String id = entries.get(0).getId(); if (id.indexOf(cacheLocn) != -1) { String searchCriteria = Util.parseOfflineIDSearch(context, id, cacheLocn); offlineEditor.putString(Constants.OFFLINE_STAR_SEARCH + stars, searchCriteria); offlineEditor.remove(Constants.OFFLINE_STAR_ID + stars); } else { offlineEditor.putString(Constants.OFFLINE_STAR_ID + stars, id); offlineEditor.remove(Constants.OFFLINE_STAR_SEARCH + stars); } offlineEditor.putBoolean(Constants.OFFLINE_STAR_SETTING + stars, starred); offlineEditor.putInt(Constants.OFFLINE_STAR_COUNT, stars); offlineEditor.commit(); }
From source file:com.makerfaireorlando.makerfaireorlando.MainActivity.java
/** * Gets the current registration ID for application on GCM service. * <p>// ww w.ja va2 s. co m * If result is empty, the app needs to register. * * @return registration ID, or empty string if there is no existing * registration ID. */ private String getRegistrationId(Context context) { final SharedPreferences prefs = getGCMPreferences(context); String registrationId = prefs.getString(PROPERTY_REG_ID, ""); if (registrationId.isEmpty()) { Log.i(TAG, "Registration not found."); return ""; } // Check if app was updated; if so, it must clear the registration ID // since the existing regID is not guaranteed to work with the new // app version. int registeredVersion = prefs.getInt(PROPERTY_APP_VERSION, Integer.MIN_VALUE); int currentVersion = getAppVersion(context); if (registeredVersion != currentVersion) { Log.i(TAG, "App version changed."); return ""; } return registrationId; }
From source file:com.teinproductions.tein.papyrosprogress.MainActivity.java
private void checkNotificationsAsked() { @SuppressWarnings("deprecation") final SharedPreferences oldSharedPref = getSharedPreferences(Constants.SHARED_PREFERENCES, MODE_PRIVATE); final SharedPreferences defaultSharedPref = PreferenceManager.getDefaultSharedPreferences(this); if (oldSharedPref.contains(Constants.NOTIFICATION_ASKED_PREFERENCE)) { // The old preferences have to be copied over to the new default shared preferences SharedPreferences.Editor editor = defaultSharedPref.edit(); editor.putBoolean(Constants.NOTIFICATION_PREFERENCE, oldSharedPref.getBoolean(Constants.NOTIFICATION_PREFERENCE, true)); editor.putInt(Constants.CACHED_BLOG_AMOUNT, oldSharedPref.getInt(Constants.CACHED_BLOG_AMOUNT, 0)); for (int id : AbstractProgressWidget.getAppWidgetLargeIds(this, AppWidgetManager.getInstance(this))) { editor.putInt(Constants.TEXT_SIZE_PREFERENCE + id, oldSharedPref.getInt(Constants.TEXT_SIZE_PREFERENCE + id, 24)); editor.putString(Constants.MILESTONE_WIDGET_PREFERENCE + id, oldSharedPref.getString(Constants.MILESTONE_WIDGET_PREFERENCE + id, "Version 0.1")); }/*from ww w . ja va 2 s . c o m*/ for (int id : AbstractProgressWidget.getAppWidgetSmallIds(this, AppWidgetManager.getInstance(this))) { editor.putInt(Constants.TEXT_SIZE_PREFERENCE + id, oldSharedPref.getInt(Constants.TEXT_SIZE_PREFERENCE + id, 24)); editor.putString(Constants.MILESTONE_WIDGET_PREFERENCE + id, oldSharedPref.getString(Constants.MILESTONE_WIDGET_PREFERENCE + id, "Version 0.1")); } editor.apply(); // Clear the old shared preferences oldSharedPref.edit().clear().apply(); } else if (!defaultSharedPref.contains(Constants.NOTIFICATION_PREFERENCE)) { new AlertDialog.Builder(this).setTitle(getString(R.string.notifications)) .setMessage(getString(R.string.notification_dialog_message)) .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { defaultSharedPref.edit().putBoolean(Constants.NOTIFICATION_PREFERENCE, true).apply(); AlarmUtils.setAlarm(MainActivity.this); invalidateOptionsMenu(); } }).setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { defaultSharedPref.edit().putBoolean(Constants.NOTIFICATION_PREFERENCE, false).apply(); AlarmUtils.reconsiderSettingAlarm(MainActivity.this); invalidateOptionsMenu(); } }).create().show(); } }
From source file:github.daneren2005.dsub.service.OfflineMusicService.java
@Override public void scrobble(String id, boolean submission, Context context, ProgressListener progressListener) throws Exception { if (!submission) { return;/*from w ww . ja va 2s. c o m*/ } SharedPreferences prefs = Util.getPreferences(context); String cacheLocn = prefs.getString(Constants.PREFERENCES_KEY_CACHE_LOCATION, null); SharedPreferences offline = Util.getOfflineSync(context); int scrobbles = offline.getInt(Constants.OFFLINE_SCROBBLE_COUNT, 0); scrobbles++; SharedPreferences.Editor offlineEditor = offline.edit(); if (id.indexOf(cacheLocn) != -1) { Pair<Integer, String> cachedSongId = SongDBHandler.getHandler(context).getIdFromPath(id); if (cachedSongId != null) { offlineEditor.putString(Constants.OFFLINE_SCROBBLE_ID + scrobbles, cachedSongId.getSecond()); offlineEditor.remove(Constants.OFFLINE_SCROBBLE_SEARCH + scrobbles); } else { String scrobbleSearchCriteria = Util.parseOfflineIDSearch(context, id, cacheLocn); offlineEditor.putString(Constants.OFFLINE_SCROBBLE_SEARCH + scrobbles, scrobbleSearchCriteria); offlineEditor.remove(Constants.OFFLINE_SCROBBLE_ID + scrobbles); } } else { offlineEditor.putString(Constants.OFFLINE_SCROBBLE_ID + scrobbles, id); offlineEditor.remove(Constants.OFFLINE_SCROBBLE_SEARCH + scrobbles); } offlineEditor.putLong(Constants.OFFLINE_SCROBBLE_TIME + scrobbles, System.currentTimeMillis()); offlineEditor.putInt(Constants.OFFLINE_SCROBBLE_COUNT, scrobbles); offlineEditor.commit(); }