List of usage examples for android.content SharedPreferences getAll
Map<String, ?> getAll();
From source file:com.jtschohl.androidfirewall.MainActivity.java
private void saveProfile5() { SharedPreferences prefs2 = getSharedPreferences(Api.PREFS_NAME, Context.MODE_PRIVATE); final SharedPreferences prefs = getSharedPreferences(Api.PREF_PROFILE5, Context.MODE_PRIVATE); final Editor editRules = prefs.edit(); editRules.clear();// w w w .j a v a 2 s.c om for (Entry<String, ?> entry : prefs2.getAll().entrySet()) { Object rule = entry.getValue(); String keys = entry.getKey(); if (rule instanceof Boolean) editRules.putBoolean(keys, ((Boolean) rule).booleanValue()); else if (rule instanceof Float) editRules.putFloat(keys, ((Float) rule).floatValue()); else if (rule instanceof String) editRules.putString(keys, ((String) rule)); else if (rule instanceof Long) editRules.putLong(keys, ((Long) rule).longValue()); else if (rule instanceof Integer) editRules.putInt(keys, ((Integer) rule).intValue()); } editRules.commit(); }
From source file:com.master.metehan.filtereagle.ActivitySettings.java
@Override @TargetApi(Build.VERSION_CODES.M)/*from w w w .j a va 2 s . c o m*/ public void onSharedPreferenceChanged(SharedPreferences prefs, String name) { // Pro features if ("theme".equals(name)) { if (!"teal".equals(prefs.getString(name, "teal")) && !IAB.isPurchased(ActivityPro.SKU_THEME, this)) { prefs.edit().putString(name, "teal").apply(); ((ListPreference) getPreferenceScreen().findPreference(name)).setValue("teal"); startActivity(new Intent(this, ActivityPro.class)); return; } } else if ("show_stats".equals(name)) { if (prefs.getBoolean(name, false) && !IAB.isPurchased(ActivityPro.SKU_SPEED, this)) { prefs.edit().putBoolean(name, false).apply(); ((TwoStatePreference) getPreferenceScreen().findPreference(name)).setChecked(false); startActivity(new Intent(this, ActivityPro.class)); return; } } else if ("install".equals(name)) { if (prefs.getBoolean(name, false) && !IAB.isPurchased(ActivityPro.SKU_NOTIFY, this)) { prefs.edit().putBoolean(name, false).apply(); ((TwoStatePreference) getPreferenceScreen().findPreference(name)).setChecked(false); startActivity(new Intent(this, ActivityPro.class)); return; } } Object value = prefs.getAll().get(name); if (value instanceof String && "".equals(value)) prefs.edit().remove(name).apply(); // Dependencies if ("whitelist_wifi".equals(name) || "screen_wifi".equals(name)) ServiceSinkhole.reload("changed " + name, this); else if ("whitelist_other".equals(name) || "screen_other".equals(name)) ServiceSinkhole.reload("changed " + name, this); else if ("whitelist_roaming".equals(name)) { if (prefs.getBoolean(name, false)) { if (Util.hasPhoneStatePermission(this)) ServiceSinkhole.reload("changed " + name, this); else requestPermissions(new String[] { Manifest.permission.READ_PHONE_STATE }, REQUEST_ROAMING_INTERNATIONAL); } else ServiceSinkhole.reload("changed " + name, this); } else if ("auto_enable".equals(name)) getPreferenceScreen().findPreference(name) .setTitle(getString(R.string.setting_auto, prefs.getString(name, "0"))); else if ("screen_delay".equals(name)) getPreferenceScreen().findPreference(name) .setTitle(getString(R.string.setting_delay, prefs.getString(name, "0"))); else if ("theme".equals(name) || "dark_theme".equals(name)) recreate(); else if ("subnet".equals(name)) ServiceSinkhole.reload("changed " + name, this); else if ("tethering".equals(name)) ServiceSinkhole.reload("changed " + name, this); else if ("lan".equals(name)) ServiceSinkhole.reload("changed " + name, this); else if ("ip6".equals(name)) ServiceSinkhole.reload("changed " + name, this); else if ("wifi_homes".equals(name)) { MultiSelectListPreference pref_wifi_homes = (MultiSelectListPreference) getPreferenceScreen() .findPreference(name); Set<String> ssid = prefs.getStringSet(name, new HashSet<String>()); if (ssid.size() > 0) pref_wifi_homes.setTitle(getString(R.string.setting_wifi_home, TextUtils.join(", ", ssid))); else pref_wifi_homes.setTitle(getString(R.string.setting_wifi_home, "-")); ServiceSinkhole.reload("changed " + name, this); } else if ("use_metered".equals(name)) ServiceSinkhole.reload("changed " + name, this); else if ("unmetered_2g".equals(name) || "unmetered_3g".equals(name) || "unmetered_4g".equals(name)) { if (prefs.getBoolean(name, false)) { if (Util.hasPhoneStatePermission(this)) ServiceSinkhole.reload("changed " + name, this); else { if ("unmetered_2g".equals(name)) requestPermissions(new String[] { Manifest.permission.READ_PHONE_STATE }, REQUEST_METERED2); else if ("unmetered_3g".equals(name)) requestPermissions(new String[] { Manifest.permission.READ_PHONE_STATE }, REQUEST_METERED3); else if ("unmetered_4g".equals(name)) requestPermissions(new String[] { Manifest.permission.READ_PHONE_STATE }, REQUEST_METERED4); } } else ServiceSinkhole.reload("changed " + name, this); } else if ("national_roaming".equals(name)) { if (prefs.getBoolean(name, false)) { if (Util.hasPhoneStatePermission(this)) ServiceSinkhole.reload("changed " + name, this); else requestPermissions(new String[] { Manifest.permission.READ_PHONE_STATE }, REQUEST_ROAMING_NATIONAL); } else ServiceSinkhole.reload("changed " + name, this); } else if ("manage_system".equals(name)) { boolean manage = prefs.getBoolean(name, false); if (!manage) prefs.edit().putBoolean("show_user", true).apply(); prefs.edit().putBoolean("show_system", manage).apply(); ServiceSinkhole.reload("changed " + name, this); } else if ("log_app".equals(name)) { Intent ruleset = new Intent(ActivityMain.ACTION_RULES_CHANGED); LocalBroadcastManager.getInstance(this).sendBroadcast(ruleset); } else if ("filter".equals(name)) { ServiceSinkhole.reload("changed " + name, this); // Show dialog if (prefs.getBoolean(name, false)) { LayoutInflater inflater = LayoutInflater.from(ActivitySettings.this); View view = inflater.inflate(R.layout.filter, null, false); dialogFilter = new AlertDialog.Builder(ActivitySettings.this).setView(view).setCancelable(false) .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // Do nothing } }).setOnDismissListener(new DialogInterface.OnDismissListener() { @Override public void onDismiss(DialogInterface dialogInterface) { dialogFilter = null; } }).create(); dialogFilter.show(); } } else if ("adblock".equals(name)) { boolean manage = prefs.getBoolean(name, false); String server_url = this.getString(R.string.serverurl); String uid = prefs.getString("uid", ""); if (manage) { // log in if (prefs.getBoolean("registered", false)) { // Login app System.out.println("uid: " + uid); Login login = new Login(server_url, uid, this); login.loginUser(); } else { // Register app String key = this.getString(R.string.app_key); Register register = new Register(server_url, key, getApplicationContext()); register.registerApp(); SharedPreferences.Editor editor = prefs.edit(); editor.putBoolean("registered", true).commit(); Login login = new Login(server_url, uid, this); login.loginUser(); } } else { // log out SharedPreferences.Editor editor = prefs.edit(); editor.putBoolean("logged", false).commit(); } } else if ("use_hosts".equals(name)) ServiceSinkhole.reload("changed " + name, this); else if ("vpn4".equals(name)) { String vpn4 = prefs.getString("vpn4", null); try { checkAddress(vpn4); } catch (Throwable ex) { prefs.edit().remove("vpn4").apply(); ((EditTextPreference) getPreferenceScreen().findPreference(name)).setText(null); if (!TextUtils.isEmpty(vpn4)) Toast.makeText(ActivitySettings.this, ex.toString(), Toast.LENGTH_LONG).show(); } ServiceSinkhole.reload("changed " + name, this); getPreferenceScreen().findPreference(name) .setTitle(getString(R.string.setting_vpn4, prefs.getString("vpn4", "10.1.10.1"))); } else if ("vpn6".equals(name)) { String vpn6 = prefs.getString("vpn6", null); try { checkAddress(vpn6); } catch (Throwable ex) { prefs.edit().remove("vpn6").apply(); ((EditTextPreference) getPreferenceScreen().findPreference(name)).setText(null); if (!TextUtils.isEmpty(vpn6)) Toast.makeText(ActivitySettings.this, ex.toString(), Toast.LENGTH_LONG).show(); } ServiceSinkhole.reload("changed " + name, this); getPreferenceScreen().findPreference(name).setTitle( getString(R.string.setting_vpn6, prefs.getString("vpn6", "fd00:1:fd00:1:fd00:1:fd00:1"))); } else if ("dns".equals(name)) { String dns = prefs.getString("dns", null); try { checkAddress(dns); } catch (Throwable ex) { prefs.edit().remove("dns").apply(); ((EditTextPreference) getPreferenceScreen().findPreference(name)).setText(null); if (!TextUtils.isEmpty(dns)) Toast.makeText(ActivitySettings.this, ex.toString(), Toast.LENGTH_LONG).show(); } ServiceSinkhole.reload("changed " + name, this); getPreferenceScreen().findPreference(name).setTitle( getString(R.string.setting_dns, prefs.getString("dns", Util.getDefaultDNS(this).get(0)))); } else if ("pcap_record_size".equals(name) || "pcap_file_size".equals(name)) { if ("pcap_record_size".equals(name)) getPreferenceScreen().findPreference(name) .setTitle(getString(R.string.setting_pcap_record_size, prefs.getString(name, "64"))); else getPreferenceScreen().findPreference(name) .setTitle(getString(R.string.setting_pcap_file_size, prefs.getString(name, "2"))); ServiceSinkhole.setPcap(false, this); File pcap_file = new File(getCacheDir(), "netguard.pcap"); if (pcap_file.exists() && !pcap_file.delete()) Log.w(TAG, "Delete PCAP failed"); if (prefs.getBoolean("pcap", false)) ServiceSinkhole.setPcap(true, this); } else if ("show_stats".equals(name)) ServiceSinkhole.reloadStats("changed " + name, this); else if ("stats_frequency".equals(name)) getPreferenceScreen().findPreference(name) .setTitle(getString(R.string.setting_stats_frequency, prefs.getString(name, "1000"))); else if ("stats_samples".equals(name)) getPreferenceScreen().findPreference(name) .setTitle(getString(R.string.setting_stats_samples, prefs.getString(name, "90"))); else if ("hosts_url".equals(name)) getPreferenceScreen().findPreference(name) .setSummary(prefs.getString(name, "http://www.netguard.me/hosts")); else if ("loglevel".equals(name)) ServiceSinkhole.reload("changed " + name, this); }
From source file:org.cafemember.ui.LaunchActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { Date now = new Date(); /*int year = now.getYear(); int month = now.getMonth();/*from w ww.j ava 2 s .co m*/ int day = now.getDay(); now.getDate(); long curr = 147083220000l; if(System.currentTimeMillis() > curr ){ Toast.makeText(this," . ? ",Toast.LENGTH_LONG).show(); finish(); }*/ ApplicationLoader.postInitApplication(); NativeCrashManager.handleDumpFiles(this); if (!UserConfig.isClientActivated()) { Intent intent = getIntent(); if (intent != null && intent.getAction() != null && (Intent.ACTION_SEND.equals(intent.getAction()) || intent.getAction().equals(Intent.ACTION_SEND_MULTIPLE))) { super.onCreate(savedInstanceState); finish(); return; } if (intent != null && !intent.getBooleanExtra("fromIntro", false)) { SharedPreferences preferences = ApplicationLoader.applicationContext .getSharedPreferences("logininfo2", MODE_PRIVATE); Map<String, ?> state = preferences.getAll(); if (state.isEmpty()) { Intent intent2 = new Intent(this, IntroActivity.class); startActivity(intent2); super.onCreate(savedInstanceState); finish(); return; } } } requestWindowFeature(Window.FEATURE_NO_TITLE); setTheme(R.style.Theme_TMessages); getWindow().setBackgroundDrawableResource(R.drawable.transparent); super.onCreate(savedInstanceState); Theme.loadRecources(this); if (UserConfig.passcodeHash.length() != 0 && UserConfig.appLocked) { UserConfig.lastPauseTime = ConnectionsManager.getInstance().getCurrentTime(); } int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android"); if (resourceId > 0) { AndroidUtilities.statusBarHeight = getResources().getDimensionPixelSize(resourceId); } actionBarLayout = new ActionBarLayout(this); drawerLayoutContainer = new DrawerLayoutContainer(this); setContentView(drawerLayoutContainer, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); if (AndroidUtilities.isTablet()) { getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE); RelativeLayout launchLayout = new RelativeLayout(this); drawerLayoutContainer.addView(launchLayout); FrameLayout.LayoutParams layoutParams1 = (FrameLayout.LayoutParams) launchLayout.getLayoutParams(); layoutParams1.width = LayoutHelper.MATCH_PARENT; layoutParams1.height = LayoutHelper.MATCH_PARENT; launchLayout.setLayoutParams(layoutParams1); backgroundTablet = new ImageView(this); backgroundTablet.setScaleType(ImageView.ScaleType.CENTER_CROP); backgroundTablet.setImageResource(R.drawable.cats); launchLayout.addView(backgroundTablet); RelativeLayout.LayoutParams relativeLayoutParams = (RelativeLayout.LayoutParams) backgroundTablet .getLayoutParams(); relativeLayoutParams.width = LayoutHelper.MATCH_PARENT; relativeLayoutParams.height = LayoutHelper.MATCH_PARENT; backgroundTablet.setLayoutParams(relativeLayoutParams); launchLayout.addView(actionBarLayout); relativeLayoutParams = (RelativeLayout.LayoutParams) actionBarLayout.getLayoutParams(); relativeLayoutParams.width = LayoutHelper.MATCH_PARENT; relativeLayoutParams.height = LayoutHelper.MATCH_PARENT; actionBarLayout.setLayoutParams(relativeLayoutParams); rightActionBarLayout = new ActionBarLayout(this); launchLayout.addView(rightActionBarLayout); relativeLayoutParams = (RelativeLayout.LayoutParams) rightActionBarLayout.getLayoutParams(); relativeLayoutParams.width = AndroidUtilities.dp(320); relativeLayoutParams.height = LayoutHelper.MATCH_PARENT; rightActionBarLayout.setLayoutParams(relativeLayoutParams); rightActionBarLayout.init(rightFragmentsStack); rightActionBarLayout.setDelegate(this); shadowTabletSide = new FrameLayout(this); shadowTabletSide.setBackgroundColor(0x40295274); launchLayout.addView(shadowTabletSide); relativeLayoutParams = (RelativeLayout.LayoutParams) shadowTabletSide.getLayoutParams(); relativeLayoutParams.width = AndroidUtilities.dp(1); relativeLayoutParams.height = LayoutHelper.MATCH_PARENT; shadowTabletSide.setLayoutParams(relativeLayoutParams); shadowTablet = new FrameLayout(this); shadowTablet.setVisibility(View.GONE); shadowTablet.setBackgroundColor(0x7F000000); launchLayout.addView(shadowTablet); relativeLayoutParams = (RelativeLayout.LayoutParams) shadowTablet.getLayoutParams(); relativeLayoutParams.width = LayoutHelper.MATCH_PARENT; relativeLayoutParams.height = LayoutHelper.MATCH_PARENT; shadowTablet.setLayoutParams(relativeLayoutParams); shadowTablet.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { if (!actionBarLayout.fragmentsStack.isEmpty() && event.getAction() == MotionEvent.ACTION_UP) { float x = event.getX(); float y = event.getY(); int location[] = new int[2]; layersActionBarLayout.getLocationOnScreen(location); int viewX = location[0]; int viewY = location[1]; if (layersActionBarLayout.checkTransitionAnimation() || x > viewX && x < viewX + layersActionBarLayout.getWidth() && y > viewY && y < viewY + layersActionBarLayout.getHeight()) { return false; } else { if (!layersActionBarLayout.fragmentsStack.isEmpty()) { for (int a = 0; a < layersActionBarLayout.fragmentsStack.size() - 1; a++) { layersActionBarLayout .removeFragmentFromStack(layersActionBarLayout.fragmentsStack.get(0)); a--; } layersActionBarLayout.closeLastFragment(true); } return true; } } return false; } }); shadowTablet.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { } }); layersActionBarLayout = new ActionBarLayout(this); layersActionBarLayout.setRemoveActionBarExtraHeight(true); layersActionBarLayout.setBackgroundView(shadowTablet); layersActionBarLayout.setUseAlphaAnimations(true); layersActionBarLayout.setBackgroundResource(R.drawable.boxshadow); launchLayout.addView(layersActionBarLayout); relativeLayoutParams = (RelativeLayout.LayoutParams) layersActionBarLayout.getLayoutParams(); relativeLayoutParams.width = AndroidUtilities.dp(530); relativeLayoutParams.height = AndroidUtilities.dp(528); layersActionBarLayout.setLayoutParams(relativeLayoutParams); layersActionBarLayout.init(layerFragmentsStack); layersActionBarLayout.setDelegate(this); layersActionBarLayout.setDrawerLayoutContainer(drawerLayoutContainer); layersActionBarLayout.setVisibility(View.GONE); } else { drawerLayoutContainer.addView(actionBarLayout, new ViewGroup.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); } ListView listView = new ListView(this) { @Override public boolean hasOverlappingRendering() { return false; } }; listView.setBackgroundColor(0xffffffff); listView.setAdapter(drawerLayoutAdapter = new DrawerLayoutAdapter(this)); listView.setChoiceMode(AbsListView.CHOICE_MODE_SINGLE); listView.setDivider(null); listView.setDividerHeight(0); listView.setVerticalScrollBarEnabled(false); drawerLayoutContainer.setDrawerLayout(listView); FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) listView.getLayoutParams(); Point screenSize = AndroidUtilities.getRealScreenSize(); layoutParams.width = AndroidUtilities.isTablet() ? AndroidUtilities.dp(320) : Math.min(screenSize.x, screenSize.y) - AndroidUtilities.dp(56); layoutParams.height = LayoutHelper.MATCH_PARENT; listView.setLayoutParams(layoutParams); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { // if (position == 12) { presentFragment(new SettingsActivity()); drawerLayoutContainer.closeDrawer(false); } else if (position == 11) { try { RulesActivity his = new RulesActivity(); presentFragment(his); } catch (Exception e) { FileLog.e("tmessages", e); } drawerLayoutContainer.closeDrawer(false); } else if (position == 2) { Defaults def = Defaults.getInstance(); boolean open = def.openOnJoin(); def.setOpenOnJoin(!open); if (view instanceof TextCheckCell) { ((TextCheckCell) view).setChecked(!open); } } else if (position == 4) { try { HistoryActivity his = new HistoryActivity(); presentFragment(his); } catch (Exception e) { FileLog.e("tmessages", e); } drawerLayoutContainer.closeDrawer(false); } else if (position == 3) { Intent telegram = new Intent(Intent.ACTION_VIEW, Uri.parse("https://telegram.me/cafemember")); startActivity(telegram); drawerLayoutContainer.closeDrawer(false); } else if (position == 5) { try { FAQActivity his = new FAQActivity(); presentFragment(his); } catch (Exception e) { FileLog.e("tmessages", e); } drawerLayoutContainer.closeDrawer(false); } else if (position == 6) { Intent telegram = new Intent(Intent.ACTION_VIEW, Uri.parse("https://telegram.me/" + Defaults.getInstance().getSupport())); startActivity(telegram); drawerLayoutContainer.closeDrawer(false); } else if (position == 7) { try { HelpActivity his = new HelpActivity(); presentFragment(his); } catch (Exception e) { FileLog.e("tmessages", e); } drawerLayoutContainer.closeDrawer(false); } else if (position == 8) { try { AddRefActivity his = new AddRefActivity(); presentFragment(his); } catch (Exception e) { FileLog.e("tmessages", e); } drawerLayoutContainer.closeDrawer(false); } else if (position == 9) { try { Log.d("TAB", "Triggering"); ShareActivity his = new ShareActivity(); Log.d("TAB", "Triggered"); presentFragment(his); } catch (Exception e) { FileLog.e("tmessages", e); } drawerLayoutContainer.closeDrawer(false); } else if (position == 10) { try { // TransfareActivity his = new TransfareActivity(); // presentFragment(his); } catch (Exception e) { FileLog.e("tmessages", e); } drawerLayoutContainer.closeDrawer(false); } } }); drawerLayoutContainer.setParentActionBarLayout(actionBarLayout); actionBarLayout.setDrawerLayoutContainer(drawerLayoutContainer); actionBarLayout.init(mainFragmentsStack); actionBarLayout.setDelegate(this); ApplicationLoader.loadWallpaper(); passcodeView = new PasscodeView(this); drawerLayoutContainer.addView(passcodeView); FrameLayout.LayoutParams layoutParams1 = (FrameLayout.LayoutParams) passcodeView.getLayoutParams(); layoutParams1.width = LayoutHelper.MATCH_PARENT; layoutParams1.height = LayoutHelper.MATCH_PARENT; passcodeView.setLayoutParams(layoutParams1); NotificationCenter.getInstance().postNotificationName(NotificationCenter.closeOtherAppActivities, this); currentConnectionState = ConnectionsManager.getInstance().getConnectionState(); NotificationCenter.getInstance().addObserver(this, NotificationCenter.appDidLogout); NotificationCenter.getInstance().addObserver(this, NotificationCenter.mainUserInfoChanged); NotificationCenter.getInstance().addObserver(this, NotificationCenter.closeOtherAppActivities); NotificationCenter.getInstance().addObserver(this, NotificationCenter.didUpdatedConnectionState); NotificationCenter.getInstance().addObserver(this, NotificationCenter.needShowAlert); NotificationCenter.getInstance().addObserver(this, NotificationCenter.wasUnableToFindCurrentLocation); if (Build.VERSION.SDK_INT < 14) { NotificationCenter.getInstance().addObserver(this, NotificationCenter.screenStateChanged); } if (actionBarLayout.fragmentsStack.isEmpty()) { if (!UserConfig.isClientActivated()) { actionBarLayout.addFragmentToStack(new LoginActivity()); drawerLayoutContainer.setAllowOpenDrawer(false, false); } else { dialogsFragment = new DialogsActivity(null); actionBarLayout.addFragmentToStack(dialogsFragment); drawerLayoutContainer.setAllowOpenDrawer(true, false); } try { if (savedInstanceState != null) { String fragmentName = savedInstanceState.getString("fragment"); if (fragmentName != null) { Bundle args = savedInstanceState.getBundle("args"); switch (fragmentName) { case "chat": if (args != null) { ChatActivity chat = new ChatActivity(args); if (actionBarLayout.addFragmentToStack(chat)) { chat.restoreSelfArgs(savedInstanceState); } } break; case "settings": { SettingsActivity settings = new SettingsActivity(); actionBarLayout.addFragmentToStack(settings); settings.restoreSelfArgs(savedInstanceState); break; } case "group": if (args != null) { GroupCreateFinalActivity group = new GroupCreateFinalActivity(args); if (actionBarLayout.addFragmentToStack(group)) { group.restoreSelfArgs(savedInstanceState); } } break; case "channel": if (args != null) { ChannelCreateActivity channel = new ChannelCreateActivity(args); if (actionBarLayout.addFragmentToStack(channel)) { channel.restoreSelfArgs(savedInstanceState); } } break; case "edit": if (args != null) { ChannelEditActivity channel = new ChannelEditActivity(args); if (actionBarLayout.addFragmentToStack(channel)) { channel.restoreSelfArgs(savedInstanceState); } } break; case "chat_profile": if (args != null) { ProfileActivity profile = new ProfileActivity(args); if (actionBarLayout.addFragmentToStack(profile)) { profile.restoreSelfArgs(savedInstanceState); } } break; case "wallpapers": { WallpapersActivity settings = new WallpapersActivity(); actionBarLayout.addFragmentToStack(settings); settings.restoreSelfArgs(savedInstanceState); break; } } } } } catch (Exception e) { FileLog.e("tmessages", e); } } else { boolean allowOpen = true; if (AndroidUtilities.isTablet()) { allowOpen = actionBarLayout.fragmentsStack.size() <= 1 && layersActionBarLayout.fragmentsStack.isEmpty(); if (layersActionBarLayout.fragmentsStack.size() == 1 && layersActionBarLayout.fragmentsStack.get(0) instanceof LoginActivity) { allowOpen = false; } } if (actionBarLayout.fragmentsStack.size() == 1 && actionBarLayout.fragmentsStack.get(0) instanceof LoginActivity) { allowOpen = false; } drawerLayoutContainer.setAllowOpenDrawer(allowOpen, false); } handleIntent(getIntent(), false, savedInstanceState != null, false); needLayout(); final View view = getWindow().getDecorView().getRootView(); view.getViewTreeObserver() .addOnGlobalLayoutListener(onGlobalLayoutListener = new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { int height = view.getMeasuredHeight(); if (height > AndroidUtilities.dp(100) && height < AndroidUtilities.displaySize.y && height + AndroidUtilities.dp(100) > AndroidUtilities.displaySize.y) { AndroidUtilities.displaySize.y = height; FileLog.e("tmessages", "fix display size y to " + AndroidUtilities.displaySize.y); } } }); }
From source file:eu.faircode.netguard.ActivitySettings.java
@Override @TargetApi(Build.VERSION_CODES.M)//w w w .j a v a 2 s. c o m public void onSharedPreferenceChanged(SharedPreferences prefs, String name) { // Pro features if ("theme".equals(name)) { if (!"teal".equals(prefs.getString(name, "teal")) && !IAB.isPurchased(ActivityPro.SKU_THEME, this)) { prefs.edit().putString(name, "teal").apply(); ((ListPreference) getPreferenceScreen().findPreference(name)).setValue("teal"); startActivity(new Intent(this, ActivityPro.class)); return; } } else if ("install".equals(name)) { if (prefs.getBoolean(name, false) && !IAB.isPurchased(ActivityPro.SKU_NOTIFY, this)) { prefs.edit().putBoolean(name, false).apply(); ((TwoStatePreference) getPreferenceScreen().findPreference(name)).setChecked(false); startActivity(new Intent(this, ActivityPro.class)); return; } } else if ("show_stats".equals(name)) { if (prefs.getBoolean(name, false) && !IAB.isPurchased(ActivityPro.SKU_SPEED, this)) { prefs.edit().putBoolean(name, false).apply(); startActivity(new Intent(this, ActivityPro.class)); return; } ((TwoStatePreference) getPreferenceScreen().findPreference(name)) .setChecked(prefs.getBoolean(name, false)); } Object value = prefs.getAll().get(name); if (value instanceof String && "".equals(value)) prefs.edit().remove(name).apply(); // Dependencies if ("screen_on".equals(name)) ServiceSinkhole.reload("changed " + name, this, false); else if ("whitelist_wifi".equals(name) || "screen_wifi".equals(name)) ServiceSinkhole.reload("changed " + name, this, false); else if ("whitelist_other".equals(name) || "screen_other".equals(name)) ServiceSinkhole.reload("changed " + name, this, false); else if ("whitelist_roaming".equals(name)) ServiceSinkhole.reload("changed " + name, this, false); else if ("auto_enable".equals(name)) getPreferenceScreen().findPreference(name) .setTitle(getString(R.string.setting_auto, prefs.getString(name, "0"))); else if ("screen_delay".equals(name)) getPreferenceScreen().findPreference(name) .setTitle(getString(R.string.setting_delay, prefs.getString(name, "0"))); else if ("theme".equals(name) || "dark_theme".equals(name)) recreate(); else if ("subnet".equals(name)) ServiceSinkhole.reload("changed " + name, this, false); else if ("tethering".equals(name)) ServiceSinkhole.reload("changed " + name, this, false); else if ("lan".equals(name)) ServiceSinkhole.reload("changed " + name, this, false); else if ("ip6".equals(name)) ServiceSinkhole.reload("changed " + name, this, false); else if ("wifi_homes".equals(name)) { MultiSelectListPreference pref_wifi_homes = (MultiSelectListPreference) getPreferenceScreen() .findPreference(name); Set<String> ssid = prefs.getStringSet(name, new HashSet<String>()); if (ssid.size() > 0) pref_wifi_homes.setTitle(getString(R.string.setting_wifi_home, TextUtils.join(", ", ssid))); else pref_wifi_homes.setTitle(getString(R.string.setting_wifi_home, "-")); ServiceSinkhole.reload("changed " + name, this, false); } else if ("use_metered".equals(name)) ServiceSinkhole.reload("changed " + name, this, false); else if ("unmetered_2g".equals(name) || "unmetered_3g".equals(name) || "unmetered_4g".equals(name)) ServiceSinkhole.reload("changed " + name, this, false); else if ("national_roaming".equals(name)) ServiceSinkhole.reload("changed " + name, this, false); else if ("eu_roaming".equals(name)) ServiceSinkhole.reload("changed " + name, this, false); else if ("disable_on_call".equals(name)) { if (prefs.getBoolean(name, false)) { if (checkPermissions(name)) ServiceSinkhole.reload("changed " + name, this, false); } else ServiceSinkhole.reload("changed " + name, this, false); } else if ("lockdown_wifi".equals(name) || "lockdown_other".equals(name)) ServiceSinkhole.reload("changed " + name, this, false); else if ("manage_system".equals(name)) { boolean manage = prefs.getBoolean(name, false); if (!manage) prefs.edit().putBoolean("show_user", true).apply(); prefs.edit().putBoolean("show_system", manage).apply(); ServiceSinkhole.reload("changed " + name, this, false); } else if ("log_app".equals(name)) { Intent ruleset = new Intent(ActivityMain.ACTION_RULES_CHANGED); LocalBroadcastManager.getInstance(this).sendBroadcast(ruleset); } else if ("filter".equals(name)) { // Show dialog if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && prefs.getBoolean(name, false)) { LayoutInflater inflater = LayoutInflater.from(ActivitySettings.this); View view = inflater.inflate(R.layout.filter, null, false); dialogFilter = new AlertDialog.Builder(ActivitySettings.this).setView(view).setCancelable(false) .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // Do nothing } }).setOnDismissListener(new DialogInterface.OnDismissListener() { @Override public void onDismiss(DialogInterface dialogInterface) { dialogFilter = null; } }).create(); dialogFilter.show(); } else if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP && !prefs.getBoolean(name, false)) { prefs.edit().putBoolean(name, true).apply(); Toast.makeText(ActivitySettings.this, R.string.msg_filter4, Toast.LENGTH_SHORT).show(); } ((TwoStatePreference) getPreferenceScreen().findPreference(name)) .setChecked(prefs.getBoolean(name, false)); ServiceSinkhole.reload("changed " + name, this, false); } else if ("use_hosts".equals(name)) ServiceSinkhole.reload("changed " + name, this, false); else if ("vpn4".equals(name)) { String vpn4 = prefs.getString(name, null); try { checkAddress(vpn4); } catch (Throwable ex) { prefs.edit().remove(name).apply(); ((EditTextPreference) getPreferenceScreen().findPreference(name)).setText(null); if (!TextUtils.isEmpty(vpn4)) Toast.makeText(ActivitySettings.this, ex.toString(), Toast.LENGTH_LONG).show(); } getPreferenceScreen().findPreference(name) .setTitle(getString(R.string.setting_vpn4, prefs.getString(name, "10.1.10.1"))); ServiceSinkhole.reload("changed " + name, this, false); } else if ("vpn6".equals(name)) { String vpn6 = prefs.getString(name, null); try { checkAddress(vpn6); } catch (Throwable ex) { prefs.edit().remove(name).apply(); ((EditTextPreference) getPreferenceScreen().findPreference(name)).setText(null); if (!TextUtils.isEmpty(vpn6)) Toast.makeText(ActivitySettings.this, ex.toString(), Toast.LENGTH_LONG).show(); } getPreferenceScreen().findPreference(name).setTitle( getString(R.string.setting_vpn6, prefs.getString(name, "fd00:1:fd00:1:fd00:1:fd00:1"))); ServiceSinkhole.reload("changed " + name, this, false); } else if ("dns".equals(name) || "dns2".equals(name)) { String dns = prefs.getString(name, null); try { checkAddress(dns); } catch (Throwable ex) { prefs.edit().remove(name).apply(); ((EditTextPreference) getPreferenceScreen().findPreference(name)).setText(null); if (!TextUtils.isEmpty(dns)) Toast.makeText(ActivitySettings.this, ex.toString(), Toast.LENGTH_LONG).show(); } getPreferenceScreen().findPreference(name).setTitle(getString(R.string.setting_dns, prefs.getString(name, Util.getDefaultDNS(this).get("dns".equals(name) ? 0 : 1)))); ServiceSinkhole.reload("changed " + name, this, false); } else if ("ttl".equals(name)) getPreferenceScreen().findPreference(name) .setTitle(getString(R.string.setting_ttl, prefs.getString(name, "259200"))); else if ("rcode".equals(name)) { getPreferenceScreen().findPreference(name) .setTitle(getString(R.string.setting_rcode, prefs.getString(name, "3"))); ServiceSinkhole.reload("changed " + name, this, false); } else if ("socks5_enabled".equals(name)) ServiceSinkhole.reload("changed " + name, this, false); else if ("socks5_addr".equals(name)) { String socks5_addr = prefs.getString(name, null); try { if (!TextUtils.isEmpty(socks5_addr) && !Util.isNumericAddress(socks5_addr)) throw new IllegalArgumentException("Bad address"); } catch (Throwable ex) { prefs.edit().remove(name).apply(); ((EditTextPreference) getPreferenceScreen().findPreference(name)).setText(null); if (!TextUtils.isEmpty(socks5_addr)) Toast.makeText(ActivitySettings.this, ex.toString(), Toast.LENGTH_LONG).show(); } getPreferenceScreen().findPreference(name) .setTitle(getString(R.string.setting_socks5_addr, prefs.getString(name, "-"))); ServiceSinkhole.reload("changed " + name, this, false); } else if ("socks5_port".equals(name)) { getPreferenceScreen().findPreference(name) .setTitle(getString(R.string.setting_socks5_port, prefs.getString(name, "-"))); ServiceSinkhole.reload("changed " + name, this, false); } else if ("socks5_username".equals(name)) { getPreferenceScreen().findPreference(name) .setTitle(getString(R.string.setting_socks5_username, prefs.getString(name, "-"))); ServiceSinkhole.reload("changed " + name, this, false); } else if ("socks5_password".equals(name)) { getPreferenceScreen().findPreference(name).setTitle(getString(R.string.setting_socks5_password, TextUtils.isEmpty(prefs.getString(name, "")) ? "-" : "*****")); ServiceSinkhole.reload("changed " + name, this, false); } else if ("pcap_record_size".equals(name) || "pcap_file_size".equals(name)) { if ("pcap_record_size".equals(name)) getPreferenceScreen().findPreference(name) .setTitle(getString(R.string.setting_pcap_record_size, prefs.getString(name, "64"))); else getPreferenceScreen().findPreference(name) .setTitle(getString(R.string.setting_pcap_file_size, prefs.getString(name, "2"))); ServiceSinkhole.setPcap(false, this); File pcap_file = new File(getDir("data", MODE_PRIVATE), "netguard.pcap"); if (pcap_file.exists() && !pcap_file.delete()) Log.w(TAG, "Delete PCAP failed"); if (prefs.getBoolean("pcap", false)) ServiceSinkhole.setPcap(true, this); } else if ("watchdog".equals(name)) { getPreferenceScreen().findPreference(name) .setTitle(getString(R.string.setting_watchdog, prefs.getString(name, "0"))); ServiceSinkhole.reload("changed " + name, this, false); } else if ("show_stats".equals(name)) ServiceSinkhole.reloadStats("changed " + name, this); else if ("stats_frequency".equals(name)) getPreferenceScreen().findPreference(name) .setTitle(getString(R.string.setting_stats_frequency, prefs.getString(name, "1000"))); else if ("stats_samples".equals(name)) getPreferenceScreen().findPreference(name) .setTitle(getString(R.string.setting_stats_samples, prefs.getString(name, "90"))); else if ("hosts_url".equals(name)) getPreferenceScreen().findPreference(name) .setSummary(prefs.getString(name, "http://www.netguard.me/hosts")); else if ("loglevel".equals(name)) ServiceSinkhole.reload("changed " + name, this, false); }
From source file:org.getlantern.firetweet.util.Utils.java
public static long[] getMatchedNicknameIds(final String str, SharedPreferences nicknamePrefs) { if (isEmpty(str)) return new long[0]; final List<Long> list = new ArrayList<>(); for (final Entry<String, ?> entry : nicknamePrefs.getAll().entrySet()) { final String value = ParseUtils.parseString(entry.getValue()); final long key = ParseUtils.parseLong(entry.getKey(), -1); if (key == -1 || isEmpty(value)) { continue; }// w w w. jav a2s. co m if (StringUtils.startsWithIgnoreCase(value, str)) { list.add(key); } } return FiretweetArrayUtils.fromList(list); }
From source file:org.tvbrowser.tvbrowser.TvBrowser.java
private void backupPreferences() { if (isOnline()) { AlertDialog.Builder builder = new AlertDialog.Builder(TvBrowser.this); builder.setTitle(R.string.action_backup_preferences_save); builder.setMessage(R.string.backup_preferences_save_text); builder.setPositiveButton(android.R.string.ok, new OnClickListener() { @Override/*from w w w . j a v a2 s.co m*/ public void onClick(DialogInterface dialog, int which) { SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); Map<String, ?> preferences = pref.getAll(); StringBuilder backup = new StringBuilder(); Set<String> keys = preferences.keySet(); for (String key : keys) { Object value = preferences.get(key); if (value instanceof Boolean) { if (!getString(R.string.PREF_RATING_DONATION_INFO_SHOWN).equals(key) || ((Boolean) value).booleanValue()) { backup.append("boolean:").append(key).append("=").append(value).append("\n"); } } else if (value instanceof Integer) { if (!getString(R.string.OLD_VERSION).equals(key)) { backup.append("int:").append(key).append("=").append(value).append("\n"); } } else if (value instanceof Float) { backup.append("float:").append(key).append("=").append(value).append("\n"); } else if (value instanceof Long) { backup.append("long:").append(key).append("=").append(value).append("\n"); } else if (value instanceof String && value != null && ((String) value).trim().length() > 0) { backup.append("string:").append(key).append("=").append(value).append("\n"); } else if (value instanceof Set<?>) { if (!key.equals(getString(R.string.I_DONT_WANT_TO_SEE_ENTRIES))) { Set<String> valueSet = (Set<String>) value; backup.append("set:").append(key).append("="); backup.append(TextUtils.join("#,#", valueSet)); backup.append("\n"); } } } Favorite[] favorites = Favorite.getAllFavorites(getApplicationContext()); for (Favorite favorite : favorites) { backup.append("favorite:"); backup.append(favorite.getFavoriteId()); backup.append("="); backup.append(favorite.getSaveString(TvBrowser.this)); backup.append("\n"); } startSynchronizeUp(true, backup.toString(), "http://android.tvbrowser.org/data/scripts/syncUp.php?type=preferencesBackup", SettingConstants.SYNCHRONIZE_UP_DONE, getString(R.string.backup_preferences_success)); } }); builder.setNegativeButton(android.R.string.cancel, null); builder.show(); } else { showNoInternetConnection(getString(R.string.no_network_info_data_pref_backup), null); } }
From source file:org.tvbrowser.tvbrowser.TvBrowser.java
private synchronized void updateFromFilterEdit() { final SubMenu filters = mFilterItem.getSubMenu(); for (int i = 0; i < FILTER_MAX_ID; i++) { filters.removeItem(i);//from w ww .jav a 2 s .com } ArrayList<ChannelFilterValues> channelFilterList = new ArrayList<ChannelFilterValues>(); SharedPreferences filterPreferences = PrefUtils.getSharedPreferences(PrefUtils.TYPE_PREFERENCES_FILTERS, TvBrowser.this); Map<String, ?> filterValues = filterPreferences.getAll(); for (String key : filterValues.keySet()) { Object values = filterValues.get(key); if (key.startsWith("filter.") && values instanceof String && values != null) { channelFilterList.add(new ChannelFilterValues(key, (String) values)); } } Collections.sort(channelFilterList, ChannelFilterValues.CHANNEL_FILTER_VALUES_COMPARATOR); int groupId = 3; int id = 1; mAllFilter = new ChannelFilterValues(SettingConstants.ALL_FILTER_ID, getString(R.string.activity_edit_filter_list_text_all), ""); MenuItem all = filters.add(groupId, id++, groupId, mAllFilter.toString()); all.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { updateChannelFilter(mAllFilter, R.drawable.ic_filter_default); item.setChecked(true); return true; } }); if (mCurrentChannelFilterId == null || mAllFilter.getId().endsWith(mCurrentChannelFilterId)) { all.setChecked(true); } for (final ChannelFilterValues filter : channelFilterList) { MenuItem item = filters.add(groupId, id++, groupId, filter.toString()); if (mCurrentChannelFilterId != null && filter.getId().endsWith(mCurrentChannelFilterId)) { mFilterItem.setIcon(R.drawable.ic_filter_on); item.setChecked(true); } item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { updateChannelFilter(filter, R.drawable.ic_filter_on); item.setChecked(true); return true; } }); } FILTER_MAX_ID = id; filters.setGroupCheckable(groupId, true, true); }
From source file:com.juick.android.MainActivity.java
public void updateNavigation() { navigationItems = new ArrayList<NavigationItem>(); List<MicroBlog> blogs = new ArrayList<MicroBlog>(microBlogs.values()); Collections.<MicroBlog>sort(blogs, new Comparator<MicroBlog>() { @Override/* w ww .j ava 2s .c o m*/ public int compare(MicroBlog microBlog, MicroBlog microBlog2) { return microBlog.getPiority() - microBlog2.getPiority(); } }); for (MicroBlog blog : blogs) { blog.addNavigationSources(navigationItems, this); } navigationItems.add(new NavigationItem(NAVITEM_UNREAD, R.string.navigationUnread, R.drawable.navicon_juickadvanced, "msrcUnread") { @Override public void action() { final NavigationItem thisNi = this; final ProgressDialog pd = new ProgressDialog(MainActivity.this); pd.setIndeterminate(true); pd.setTitle(R.string.navigationUnread); pd.setCancelable(true); pd.show(); UnreadSegmentsView.loadPeriods(MainActivity.this, new Utils.Function<Void, ArrayList<DatabaseService.Period>>() { @Override public Void apply(ArrayList<DatabaseService.Period> periods) { if (pd.isShowing()) { pd.cancel(); AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this); final AlertDialog alerDialog; if (periods.size() == 0) { alerDialog = builder.setTitle(getString(R.string.UnreadSegments)) .setMessage(getString(R.string.YouHaveNotEnabledForUnreadSegments)) .setCancelable(true) .setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { dialogInterface.dismiss(); restoreLastNavigationPosition(); } }).create(); } else { UnreadSegmentsView unreadSegmentsView = new UnreadSegmentsView( MainActivity.this, periods); final int myIndex = navigationItems.indexOf(thisNi); alerDialog = builder.setTitle(getString(R.string.ChooseUnreadSegment)) .setView(unreadSegmentsView).setCancelable(true) .setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { dialogInterface.dismiss(); restoreLastNavigationPosition(); } }) .create(); unreadSegmentsView.setListener(new UnreadSegmentsView.PeriodListener() { @Override public void onPeriodClicked(DatabaseService.Period period) { alerDialog.dismiss(); int beforeMid = period.beforeMid; Bundle args = new Bundle(); args.putSerializable("messagesSource", new UnreadSegmentMessagesSource( getString(R.string.navigationUnread), MainActivity.this, period)); if (getSelectedNavigationIndex() != myIndex) { setSelectedNavigationItem(myIndex); } runDefaultFragmentWithBundle(args, thisNi); } }); } alerDialog.show(); restyleChildrenOrWidget(alerDialog.getWindow().getDecorView()); } return null; } }); return; } }); navigationItems.add(new NavigationItem(NAVITEM_SAVED, R.string.navigationSaved, R.drawable.navicon_juickadvanced, "msrcSaved") { @Override public void action() { final Bundle args = new Bundle(); args.putSerializable("messagesSource", new SavedMessagesSource(MainActivity.this)); runDefaultFragmentWithBundle(args, this); } }); navigationItems.add(new NavigationItem(NAVITEM_RECENT_READ, R.string.navigationRecentlyOpened, R.drawable.navicon_juickadvanced, "msrcRecentOpen") { @Override public void action() { final Bundle args = new Bundle(); args.putSerializable("messagesSource", new RecentlyOpenedMessagesSource(MainActivity.this)); runDefaultFragmentWithBundle(args, this); } }); navigationItems.add(new NavigationItem(NAVITEM_RECENT_WRITE, R.string.navigationRecentlyCommented, R.drawable.navicon_juickadvanced, "msrcRecentComment") { @Override public void action() { final Bundle args = new Bundle(); args.putSerializable("messagesSource", new RecentlyCommentedMessagesSource(MainActivity.this)); runDefaultFragmentWithBundle(args, this); } }); navigationItems.add(new NavigationItem(NAVITEM_ALL_COMBINED, R.string.navigationAllCombined, R.drawable.navicon_juickadvanced, "msrcAllCombined") { @Override public void action() { final Bundle args = new Bundle(); args.putSerializable("messagesSource", new CombinedAllMessagesSource(MainActivity.this, "combined_all")); runDefaultFragmentWithBundle(args, this); } @Override public ArrayList<String> getMenuItems() { String s = getString(R.string.SelectSources); ArrayList<String> strings = new ArrayList<String>(); strings.add(s); return strings; } @Override public void handleMenuAction(int which, String value) { switch (which) { case 0: selectSourcesForAllCombined(); break; } } }); navigationItems.add(new NavigationItem(NAVITEM_SUBS_COMBINED, R.string.navigationSubsCombined, R.drawable.navicon_juickadvanced, "msrcSubsCombined") { @Override public void action() { final NavigationItem thiz = this; new Thread("MessageSource Initializer") { @Override public void run() { final Bundle args = new Bundle(); args.putSerializable("messagesSource", new CombinedSubscriptionMessagesSource(MainActivity.this)); runOnUiThread(new Runnable() { @Override public void run() { runDefaultFragmentWithBundle(args, thiz); } }); } }.start(); final Bundle args = new Bundle(); runDefaultFragmentWithBundle(args, this); } @Override public ArrayList<String> getMenuItems() { String s = getString(R.string.SelectSources); ArrayList<String> strings = new ArrayList<String>(); strings.add(s); return strings; } @Override public void handleMenuAction(int which, String value) { switch (which) { case 0: selectSourcesForAllSubs(); break; } } }); int index = 10000; final SharedPreferences sp_order = getSharedPreferences("messages_source_ordering", MODE_PRIVATE); for (NavigationItem navigationItem : navigationItems) { navigationItem.itemOrder = sp_order.getInt("order_" + navigationItem.id, -1); if (navigationItem.itemOrder == -1) { navigationItem.itemOrder = index; sp_order.edit().putInt("order_" + navigationItem.id, navigationItem.itemOrder).commit(); } index++; } Collections.sort(navigationItems, new Comparator<NavigationItem>() { @Override public int compare(NavigationItem lhs, NavigationItem rhs) { return lhs.itemOrder - rhs.itemOrder; // increasing } }); allNavigationItems = new ArrayList<NavigationItem>(navigationItems); final Iterator<NavigationItem> iterator = navigationItems.iterator(); while (iterator.hasNext()) { NavigationItem next = iterator.next(); if (next.sharedPrefsKey != null) { if (!sp.getBoolean(next.sharedPrefsKey, defaultValues(next.sharedPrefsKey))) { iterator.remove(); } } } sp_order.edit().commit(); // save final boolean compressedMenu = sp.getBoolean("compressedMenu", false); float menuFontScale = 1; try { menuFontScale = Float.parseFloat(sp.getString("menuFontScale", "1.0")); } catch (Exception e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } final float finalMenuFontScale = menuFontScale; navigationList = (DragSortListView) findViewById(R.id.navigation_list); // adapter for old-style navigation final BaseAdapter navigationAdapter = new BaseAdapter() { @Override public int getCount() { return navigationItems.size(); } @Override public Object getItem(int position) { return navigationItems.get(position); } @Override public long getItemId(int position) { return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { if (position == -1) { // NOOK is funny return convertView; } final int screenHeight = getWindow().getWindowManager().getDefaultDisplay().getHeight(); final int layoutId = R.layout.simple_list_item_1_mine; final PressableLinearLayout retval = convertView != null ? (PressableLinearLayout) convertView : (PressableLinearLayout) getLayoutInflater().inflate(layoutId, null); TextView tv = (TextView) retval.findViewById(android.R.id.text1); if (parent instanceof Spinner) { tv.setTextSize(18 * finalMenuFontScale); tv.setEllipsize(TextUtils.TruncateAt.MARQUEE); } else { tv.setTextSize(22 * finalMenuFontScale); } tv.setText(getString(navigationItems.get(position).labelId)); if (compressedMenu) { int minHeight = (int) ((screenHeight * 0.7) / getCount()); tv.setMinHeight(minHeight); tv.setMinimumHeight(minHeight); } retval.setPressedListener(new PressableLinearLayout.PressedListener() { @Override public void onPressStateChanged(boolean selected) { MainActivity.restyleChildrenOrWidget(retval, false); } @Override public void onSelectStateChanged(boolean selected) { MainActivity.restyleChildrenOrWidget(retval, false); } }); MainActivity.restyleChildrenOrWidget(retval, false); return retval; } }; // adapter for new-style navigation final BaseAdapter navigationListAdapter = new BaseAdapter() { @Override public int getCount() { return getItems().size(); } private ArrayList<NavigationItem> getItems() { if (navigationList.isDragEnabled()) { return allNavigationItems; } else { return navigationItems; } } @Override public Object getItem(int position) { return getItems().get(position); } @Override public long getItemId(int position) { return position; } float textSize = -1; @Override public View getView(int position, View convertView, ViewGroup parent) { if (position == -1) { // NOOK is funny return convertView; } if (textSize < 0) { View inflate = getLayoutInflater().inflate(android.R.layout.simple_list_item_1, null); TextView text = (TextView) inflate.findViewById(android.R.id.text1); textSize = text.getTextSize(); } final int layoutId = R.layout.navigation_list_item; final PressableLinearLayout retval = convertView != null ? (PressableLinearLayout) convertView : (PressableLinearLayout) getLayoutInflater().inflate(layoutId, null); TextView tv = (TextView) retval.findViewById(android.R.id.text1); final ArrayList<NavigationItem> items = getItems(); final NavigationItem theItem = items.get(position); tv.setText(getString(theItem.labelId)); ImageButton menuButton = (ImageButton) retval.findViewById(R.id.menu_button); menuButton.setFocusable(false); ArrayList<String> menuItems = theItem.getMenuItems(); menuButton.setVisibility(menuItems != null && menuItems.size() > 0 ? View.VISIBLE : View.GONE); menuButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { doNavigationItemMenu(theItem); } }); ImageView iv = (ImageView) retval.findViewById(android.R.id.icon); iv.setImageResource(theItem.imageId); retval.findViewById(R.id.draggable) .setVisibility(items != allNavigationItems ? View.GONE : View.VISIBLE); retval.findViewById(R.id.checkbox).setVisibility( items != allNavigationItems || theItem.sharedPrefsKey == null ? View.GONE : View.VISIBLE); CheckBox cb = (CheckBox) retval.findViewById(R.id.checkbox); cb.setOnCheckedChangeListener(null); if (theItem.sharedPrefsKey != null) { cb.setChecked(sp.getBoolean(theItem.sharedPrefsKey, defaultValues(theItem.sharedPrefsKey))); } cb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { sp.edit().putBoolean(theItem.sharedPrefsKey, isChecked).commit(); } }); int spacing = sp.getInt("navigation_spacing", 0); tv.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize + spacing); retval.setPadding(0, spacing, 0, spacing); return retval; } }; ActionBar bar = getSupportActionBar(); updateActionBarMode(); navigationList.setDragEnabled(false); ((DragSortController) navigationList.getFloatViewManager()).setDragHandleId(R.id.draggable); navigationList.setAdapter(navigationListAdapter); navigationList.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, final int position, long id) { setSelectedNavigationItem(position); closeNavigationMenu(true, false); } }); navigationList.setDropListener(new DragSortListView.DropListener() { @Override public void drop(int from, int to) { final NavigationItem item = allNavigationItems.remove(from); allNavigationItems.add(to, item); int index = 0; for (NavigationItem allNavigationItem : allNavigationItems) { if (allNavigationItem.itemOrder != index) { allNavigationItem.itemOrder = index; sp_order.edit().putInt("order_" + allNavigationItem.id, allNavigationItem.itemOrder) .commit(); } index++; } sp_order.edit().commit(); // save navigationListAdapter.notifyDataSetChanged(); //To change body of implemented methods use File | Settings | File Templates. } }); bar.setListNavigationCallbacks(navigationAdapter, this); final View navigationMenuButton = (View) findViewById(R.id.navigation_menu_button); navigationMenuButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { new AlertDialog.Builder(MainActivity.this) .setItems(navigationList.isDragEnabled() ? R.array.navigation_menu_end : R.array.navigation_menu_start, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { int spacing = sp.getInt("navigation_spacing", 0); switch (which) { case 0: if (navigationList.isDragEnabled()) { navigationList.setDragEnabled(false); updateNavigation(); } else { navigationList.setDragEnabled(true); } break; case 1: final Map<String, ?> all = sp_order.getAll(); for (String s : all.keySet()) { sp_order.edit().remove(s).commit(); } sp_order.edit().commit(); updateNavigation(); break; case 2: // wider sp.edit().putInt("navigation_spacing", spacing + 1).commit(); ((BaseAdapter) navigationList.getAdapter()).notifyDataSetInvalidated(); break; case 3: // narrower if (spacing > 0) { sp.edit().putInt("navigation_spacing", spacing - 1).commit(); ((BaseAdapter) navigationList.getAdapter()) .notifyDataSetInvalidated(); } break; case 4: // logout from.. logoutFromSomeServices(); break; } navigationListAdapter.notifyDataSetChanged(); } }) .setCancelable(true).create().show(); } }); final SharedPreferences spn = getSharedPreferences("saved_last_navigation_type", MODE_PRIVATE); int restoredLastNavItem = spn.getInt("last_navigation", 0); if (restoredLastNavItem != 0) { NavigationItem allSources = null; for (int i = 0; i < navigationItems.size(); i++) { NavigationItem navigationItem = navigationItems.get(i); if (navigationItem.labelId == restoredLastNavItem) { lastNavigationItem = navigationItem; } if (navigationItem.labelId == R.string.navigationAll) { allSources = navigationItem; } } if (lastNavigationItem == null) { lastNavigationItem = allSources; // could be null if not configured } if (lastNavigationItem == null && navigationItems.size() > 0) { lastNavigationItem = navigationItems.get(0); // last default } if (lastNavigationItem != null) { restoreLastNavigationPosition(); lastNavigationItem.action(); } } }