Java Code Examples for androidx.preference.PreferenceManager#setDefaultValues()
The following examples show how to use
androidx.preference.PreferenceManager#setDefaultValues() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TopFragment.java From InviZible with GNU General Public License v3.0 | 6 votes |
private void actionModulesNotInstalled() { if (getActivity() == null) { return; } PreferenceManager.setDefaultValues(getActivity(), R.xml.preferences_common, true); PreferenceManager.setDefaultValues(getActivity(), R.xml.preferences_dnscrypt, true); PreferenceManager.setDefaultValues(getActivity(), R.xml.preferences_dnscrypt_servers, true); PreferenceManager.setDefaultValues(getActivity(), R.xml.preferences_fast, true); PreferenceManager.setDefaultValues(getActivity(), R.xml.preferences_tor, true); PreferenceManager.setDefaultValues(getActivity(), R.xml.preferences_i2pd, true); //For core update purposes new PrefManager(getActivity()).setStrPref("DNSCryptVersion", DNSCryptVersion); new PrefManager(getActivity()).setStrPref("TorVersion", TorVersion); new PrefManager(getActivity()).setStrPref("ITPDVersion", ITPDVersion); new PrefManager(getActivity()).setStrPref("DNSCrypt Servers", ""); SharedPreferences sPref = PreferenceManager.getDefaultSharedPreferences(getActivity()); SharedPreferences.Editor editor = sPref.edit(); editor.putBoolean("pref_common_tor_tethering", false); editor.putBoolean("pref_common_itpd_tethering", false); editor.apply(); startInstallation(); }
Example 2
Source File: MainActivity.java From Android-Developer-Fundamentals-Version-2 with GNU General Public License v3.0 | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Toolbar toolbar = findViewById(R.id.toolbar); setSupportActionBar(toolbar); FloatingActionButton fab = findViewById(R.id.fab); fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent intent = new Intent(MainActivity.this, OrderActivity.class); intent.putExtra(EXTRA_MESSAGE, mOrderMessage); startActivity(intent); } }); PreferenceManager.setDefaultValues(this, R.xml.sync_preferences, false); PreferenceManager.setDefaultValues(this, R.xml.general_preferences, false); PreferenceManager.setDefaultValues(this, R.xml.notification_preferences, false); SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); String marketPref = sharedPreferences.getString("sync_frequency", "-1"); displayToast(marketPref); }
Example 3
Source File: MainActivity.java From Android-Developer-Fundamentals-Version-2 with GNU General Public License v3.0 | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Toolbar toolbar = findViewById(R.id.toolbar); setSupportActionBar(toolbar); FloatingActionButton fab = findViewById(R.id.fab); fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent intent = new Intent(MainActivity.this, OrderActivity.class); intent.putExtra(EXTRA_MESSAGE, mOrderMessage); startActivity(intent); } }); PreferenceManager.setDefaultValues(this, R.xml.sync_preferences, false); PreferenceManager.setDefaultValues(this, R.xml.general_preferences, false); PreferenceManager.setDefaultValues(this, R.xml.notification_preferences, false); SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); String marketPref = sharedPreferences.getString("sync_frequency", "-1"); String deliveryMethod = sharedPreferences.getString("delivery_list", "Same day messenger service"); displayToast("Market is " + marketPref + " and delivery method is " + deliveryMethod); }
Example 4
Source File: Daedalus.java From Daedalus with GNU General Public License v3.0 | 6 votes |
private void initData() { PreferenceManager.setDefaultValues(this, R.xml.perf_settings, false); prefs = PreferenceManager.getDefaultSharedPreferences(this); if (getExternalFilesDir(null) != null) { rulePath = getExternalFilesDir(null).getPath() + "/rules/"; logPath = getExternalFilesDir(null).getPath() + "/logs/"; configPath = getExternalFilesDir(null).getPath() + "/config.json"; initDirectory(rulePath); initDirectory(logPath); } if (configPath != null) { configurations = Configurations.load(new File(configPath)); } else { configurations = new Configurations(); } }
Example 5
Source File: AppearancePreferencesFragment.java From Field-Book with GNU General Public License v2.0 | 5 votes |
@Override public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { prefMgr = getPreferenceManager(); prefMgr.setSharedPreferencesName("Settings"); setPreferencesFromResource(R.xml.preferences_appearance, rootKey); PreferenceManager.setDefaultValues(getActivity(), R.xml.preferences_appearance, true); ((PreferencesActivity) this.getActivity()).getSupportActionBar().setTitle(getString(R.string.preferences_appearance_title)); }
Example 6
Source File: FragmentSettings.java From privatelocation with GNU General Public License v3.0 | 5 votes |
@Override public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { addPreferencesFromResource(R.xml.preferences); setHasOptionsMenu(true); context = getContext(); sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); //this static call will reset default values only on the first ever read PreferenceManager.setDefaultValues(context, R.xml.preferences, false); cbRandomize = findPreference("RANDOMIZE_LOCATION"); }
Example 7
Source File: RepositoryTest.java From WiFiAnalyzer with GNU General Public License v3.0 | 5 votes |
@Test public void testInitializeDefaultValues() { // execute fixture.initializeDefaultValues(); // validate verifyStatic(PreferenceManager.class); PreferenceManager.setDefaultValues(context, R.xml.settings, false); }
Example 8
Source File: LoginActivity.java From tindroid with Apache License 2.0 | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_login); PreferenceManager.setDefaultValues(this, R.xml.login_preferences, false); final Toolbar toolbar = findViewById(R.id.toolbar); setSupportActionBar(toolbar); // Handle clicks on the '<-' arrow in the toolbar. toolbar.setNavigationOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { getSupportFragmentManager().popBackStack(); } }); BaseDb db = BaseDb.getInstance(); if (db.isReady()) { // We already have a configured account. All good. Launch ContactsActivity and stop. Intent intent = new Intent(this, ChatsActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent); finish(); return; } // Check if we need full authentication or just credentials. showFragment(db.isCredValidationRequired() ? FRAGMENT_CREDENTIALS : FRAGMENT_LOGIN, null, false); }
Example 9
Source File: MainActivity.java From zapp with MIT License | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); PreferenceManager.setDefaultValues(this, R.xml.preferences, false); ActivityMainBinding binding = ActivityMainBinding.inflate(getLayoutInflater()); setContentView(binding.getRoot()); viewPager = binding.viewPager; searchView = binding.search; navigationView = binding.navView; drawerLayout = binding.layoutDrawer; setSupportActionBar(binding.toolbar); ActionBar actionbar = getSupportActionBar(); actionbar.setDisplayHomeAsUpEnabled(true); actionbar.setHomeAsUpIndicator(R.drawable.ic_menu_white_24dp); viewPager.setAdapter(new MainPageAdapter(getSupportFragmentManager())); viewPager.addOnPageChangeListener(this); searchView.setOnQueryTextListener(this); SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); searchView.setIconified(false); searchView.setIconifiedByDefault(false); searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName())); searchView.clearFocus(); searchView.setOnQueryTextFocusChangeListener(this::onSearchQueryTextFocusChangeListener); navigationView.setNavigationItemSelectedListener(this::onNavigationItemSelected); onPageSelected(viewPager.getCurrentItem()); handleIntent(getIntent()); }
Example 10
Source File: NotificationSettingsActivity.java From an2linuxclient with GNU General Public License v3.0 | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); PreferenceManager.setDefaultValues(this, R.xml.notification_preferences, false); getSupportFragmentManager().beginTransaction() .replace(android.R.id.content, new SettingsFragment()) .commit(); }
Example 11
Source File: MainSettingsActivity.java From an2linuxclient with GNU General Public License v3.0 | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); PreferenceManager.setDefaultValues(this, R.xml.main_preferences, false); getSupportFragmentManager().beginTransaction() .replace(android.R.id.content, new SettingsFragment()) .commit(); }
Example 12
Source File: VinylCastApplication.java From vinyl-cast with MIT License | 5 votes |
@Override public void onCreate() { super.onCreate(); // This static call will reset default values only on the first ever read. Also according // to StrictMode, it's slow due to disk reads on Main Thread. PreferenceManager.setDefaultValues(getBaseContext(), R.xml.preferences, false); // get Cast session manager here in Application as according to StrictMode it's slow due to // performing disk reads on Main Thread and only needs to be fetched once anyway. castSessionManager = CastContext.getSharedInstance(this).getSessionManager(); NativeAudioEngine.create(); }
Example 13
Source File: NotificationSettingsActivity.java From an2linuxclient with GNU General Public License v3.0 | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); PreferenceManager.setDefaultValues(this, R.xml.notification_preferences, false); getSupportFragmentManager().beginTransaction() .replace(android.R.id.content, new SettingsFragment()) .commit(); }
Example 14
Source File: MainSettingsActivity.java From an2linuxclient with GNU General Public License v3.0 | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); PreferenceManager.setDefaultValues(this, R.xml.main_preferences, false); getSupportFragmentManager().beginTransaction() .replace(android.R.id.content, new SettingsFragment()) .commit(); }
Example 15
Source File: SettingsFragment.java From odyssey with GNU General Public License v3.0 | 4 votes |
/** * Create the preferences from an xml resource file */ @Override public void onCreatePreferences(Bundle bundle, String s) { addPreferencesFromResource(R.xml.odyssey_main_settings); PreferenceManager.setDefaultValues(getActivity(), R.xml.odyssey_main_settings, false); }
Example 16
Source File: ArtworkSettingsFragment.java From odyssey with GNU General Public License v3.0 | 4 votes |
/** * Create the preferences from an xml resource file */ @Override public void onCreatePreferences(Bundle bundle, String s) { addPreferencesFromResource(R.xml.odyssey_artwork_settings); PreferenceManager.setDefaultValues(getActivity(), R.xml.odyssey_artwork_settings, false); }
Example 17
Source File: RemoteActivity.java From Kore with Apache License 2.0 | 4 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Set default values for the preferences PreferenceManager.setDefaultValues(this, R.xml.preferences, false); setContentView(R.layout.activity_remote); ButterKnife.bind(this); hostManager = HostManager.getInstance(this); // Check if we have any hosts setup if (hostManager.getHostInfo() == null) { final Intent intent = new Intent(this, AddHostActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent); finish(); return; } // Set up the drawer. navigationDrawerFragment = (NavigationDrawerFragment) getSupportFragmentManager() .findFragmentById(R.id.navigation_drawer); navigationDrawerFragment.setUp(R.id.navigation_drawer, (DrawerLayout) findViewById(R.id.drawer_layout)); // Set up pager and fragments TabsAdapter tabsAdapter = new TabsAdapter(this, getSupportFragmentManager()) .addTab(NowPlayingFragment.class, null, R.string.now_playing, NOWPLAYING_FRAGMENT_ID) .addTab(RemoteFragment.class, null, R.string.remote, REMOTE_FRAGMENT_ID) .addTab(PlaylistFragment.class, null, R.string.playlist, PLAYLIST_FRAGMENT_ID); viewPager.setAdapter(tabsAdapter); pageIndicator.setViewPager(viewPager); pageIndicator.setOnPageChangeListener(defaultOnPageChangeListener); viewPager.setCurrentItem(1); viewPager.setOffscreenPageLimit(2); setupActionBar(); // Periodic Check of Kodi version hostManager.checkAndUpdateKodiVersion(); // If we should start playing something // // Setup system bars and content padding // setupSystemBarsColors(); // // Set the padding of views. // // Only set top and right, to allow bottom to overlap in each fragment // UIUtils.setPaddingForSystemBars(this, viewPager, true, true, false); // UIUtils.setPaddingForSystemBars(this, pageIndicator, true, true, false); //noinspection unchecked pendingShare = (Future<Boolean>) getLastCustomNonConfigurationInstance(); }
Example 18
Source File: Repository.java From WiFiAnalyzer with GNU General Public License v3.0 | 4 votes |
void initializeDefaultValues() { PreferenceManager.setDefaultValues(context, R.xml.settings, false); }
Example 19
Source File: MainActivity.java From Intra with Apache License 2.0 | 4 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Sync old settings into new preferences if necessary. PersistentState.syncLegacyState(this); // Start an asynchronous fetch of remote configuration info from Firebase. RemoteConfig.update(); // Export defaults into preferences. See https://developer.android.com/guide/topics/ui/settings#Defaults PreferenceManager.setDefaultValues(this, R.xml.preferences, false); // Registers this class as a listener for user preference changes. PreferenceManager.getDefaultSharedPreferences(this). registerOnSharedPreferenceChangeListener(this); // Enable SVG support on very old versions of Android. AppCompatDelegate.setCompatVectorFromResourcesEnabled(true); setContentView(R.layout.activity_main); // Set up the toolbar Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); // Set up the drawer toggle DrawerLayout drawerLayout = (DrawerLayout) findViewById(R.id.activity_main); drawerToggle = new ActionBarDrawerToggle( this, /* host Activity */ drawerLayout, /* DrawerLayout object */ toolbar, R.string.drawer_open, /* "open drawer" description */ R.string.drawer_close /* "close drawer" description */ ); drawerLayout.addDrawerListener(drawerToggle); getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setHomeButtonEnabled(true); drawerToggle.setToolbarNavigationClickListener(new View.OnClickListener() { @Override public void onClick(View v) { chooseView(R.id.frame_main); } }); // Set up the drawer NavigationView drawer = (NavigationView) findViewById(R.id.drawer); drawer.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() { @Override public boolean onNavigationItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.up: case R.id.home: chooseView(R.id.frame_main); return true; case R.id.settings: chooseView(R.id.settings); return true; case R.id.support: openUrl("https://support.getintra.org/"); return true; case R.id.privacy: openUrl("https://getintra.org/privacy"); return true; case R.id.tos: openUrl("https://jigsaw.google.com/jigsaw-tos.html"); return true; case R.id.source_code: openUrl("https://github.com/Jigsaw-Code/intra"); return true; default: return false; } } }); // Set up the recycler recyclerView = (RecyclerView) findViewById(R.id.recycler); recyclerView.setHasFixedSize(true); layoutManager = new LinearLayoutManager(this); recyclerView.setLayoutManager(layoutManager); adapter = new RecyclerAdapter(this); adapter.reset(getHistory()); recyclerView.setAdapter(adapter); // Register broadcast receiver IntentFilter intentFilter = new IntentFilter(InternalNames.RESULT.name()); intentFilter.addAction(InternalNames.DNS_STATUS.name()); LocalBroadcastManager.getInstance(this).registerReceiver(messageReceiver, intentFilter); prepareHyperlinks(this, findViewById(R.id.activity_main)); // Autostart if necessary maybeAutostart(); }