List of usage examples for android.preference PreferenceManager setDefaultValues
public static void setDefaultValues(Context context, @XmlRes int resId, boolean readAgain)
From source file:com.koboflo.SettingsActivity.java
@TargetApi(Build.VERSION_CODES.HONEYCOMB) @SuppressLint("NewApi") protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Log.d("Preffffs", "tri"); // setContentView(R.layout.activity_type_prefs); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { getActionBar().setDisplayHomeAsUpEnabled(true); }//www . j a v a 2s . c o m addPreferencesFromResource(R.xml.pref_general); PreferenceManager.setDefaultValues(SettingsActivity.this, R.xml.pref_general, false); }
From source file:de.baumann.weather.helper.SplashActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); getWindow().setStatusBarColor(ContextCompat.getColor(this, R.color.colorPrimaryDark)); }//from www .j a v a2s.c o m setContentView(R.layout.activity_splash); PreferenceManager.setDefaultValues(this, R.xml.user_settings, false); PreferenceManager.setDefaultValues(this, R.xml.user_settings_help, false); final SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this); final String startType = sharedPref.getString("startType", "1"); if (startType.equals("2")) { new Handler().postDelayed(new Runnable() { public void run() { String startURL = sharedPref.getString("favoriteURL", "http://m.wetterdienst.de/"); String startTitle = sharedPref.getString("favoriteTitle", "http://m.wetterdienst.de/"); if (startURL.contains("m.wetterdienst.de")) { Intent intent = new Intent(SplashActivity.this, Screen_Weather.class); intent.putExtra("url", startURL); intent.putExtra("url2", startURL + "stuendlich"); intent.putExtra("url3", startURL + "10-Tage"); intent.putExtra("title", startTitle); startActivity(intent); SplashActivity.this.finish(); overridePendingTransition(R.anim.fadein, R.anim.fadeout); } else { Intent intent = new Intent(SplashActivity.this, Browser.class); intent.putExtra("url", startURL); startActivity(intent); SplashActivity.this.finish(); overridePendingTransition(R.anim.fadein, R.anim.fadeout); } } }, 1000); } else if (startType.equals("1")) { new Handler().postDelayed(new Runnable() { public void run() { Intent mainIntent = new Intent(SplashActivity.this, Screen_Main.class); mainIntent.putExtra("id", "1"); startActivity(mainIntent); SplashActivity.this.finish(); overridePendingTransition(R.anim.fadein, R.anim.fadeout); } }, 1000); } }
From source file:com.physphil.android.unitconverterultimate.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); PreferenceManager.setDefaultValues(this, R.xml.preferences, false); Preferences.getInstance(this).getPreferences().registerOnSharedPreferenceChangeListener(this); mConversions = Conversions.getInstance(); setContentView(R.layout.activity_main); setupToolbar();//from ww w .j a v a 2 s. c o m setToolbarHomeNavigation(true); if (getSupportActionBar() != null) getSupportActionBar().setHomeAsUpIndicator(R.drawable.ic_menu_white_24dp); int conversion = Preferences.getInstance(this).getLastConversion(); setToolbarTitle(mConversions.getById(conversion).getLabelResource()); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawerLayout.setDrawerListener(new DrawerLayout.DrawerListener() { @Override public void onDrawerSlide(View drawerView, float slideOffset) { } @Override public void onDrawerOpened(View drawerView) { hideKeyboard(); } @Override public void onDrawerClosed(View drawerView) { } @Override public void onDrawerStateChanged(int newState) { } }); setupDrawer(conversion); if (savedInstanceState == null) { getSupportFragmentManager().beginTransaction() .replace(R.id.fragment_container, ConversionFragment.newInstance(conversion)).commit(); } }
From source file:net.olejon.spotcommander.WidgetActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Settings//from w w w. jav a2s . c o m PreferenceManager.setDefaultValues(mContext, R.xml.settings, false); // Allow landscape? if (!mTools.allowLandscape()) setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); // Database mDatabase = new MainSQLiteHelper(mContext).getReadableDatabase(); // Intent setResult(RESULT_CANCELED); final Intent intent = getIntent(); if (intent.getExtras() != null) mAppWidgetId = intent.getExtras().getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID); if (mAppWidgetId == AppWidgetManager.INVALID_APPWIDGET_ID) finish(); // Layout setContentView(R.layout.activity_widget); // Toolbar final Toolbar toolbar = (Toolbar) findViewById(R.id.widget_toolbar); toolbar.setNavigationIcon(R.drawable.ic_close_white_24dp); toolbar.setTitle(getString(R.string.widget_title)); setSupportActionBar(toolbar); // Listview mListView = (ListView) findViewById(R.id.widget_list); final View listViewHeader = getLayoutInflater().inflate(R.layout.activity_main_subheader, mListView, false); mListView.addHeaderView(listViewHeader, null, false); final View listViewEmpty = findViewById(R.id.widget_empty); mListView.setEmptyView(listViewEmpty); mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { mTools.setSharedPreferencesLong("WIDGET_" + mAppWidgetId + "_COMPUTER_ID", id); Intent result = new Intent(); result.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mAppWidgetId); setResult(RESULT_OK, result); finish(); } }); listComputers(); }
From source file:com.agateau.equiv.ui.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); NLog.i("");/* w w w.java 2s.c om*/ PreferenceManager.setDefaultValues(this, R.xml.preferences, false); mKernel = Kernel.getInstance(this); setContentView(R.layout.activity_main); setupTabs(); if (sUiState != null) { getSupportActionBar().getTabAt(sUiState.currentTabPosition).select(); } for (Meal meal : mKernel.getDay().getMeals()) { meal.registerListener(this); } updateTitle(); }
From source file:com.schoentoon.connectbot.SettingsActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); getSupportActionBar().setSubtitle("Settings"); getSupportActionBar().setDisplayHomeAsUpEnabled(true); try {//from ww w . j a v a 2s . c o m addPreferencesFromResource(R.xml.preferences); } catch (ClassCastException e) { Log.e(TAG, "Shared preferences are corrupt! Resetting to default values."); SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); // Blow away all the preferences SharedPreferences.Editor editor = preferences.edit(); editor.clear(); editor.commit(); PreferenceManager.setDefaultValues(this, R.xml.preferences, true); // Since they were able to get to the Settings activity, they already agreed to the EULA editor = preferences.edit(); editor.putBoolean(PreferenceConstants.EULA, true); editor.commit(); addPreferencesFromResource(R.xml.preferences); } }
From source file:anakiou.com.picontrol.ui.fragments.MainMenuFragment.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); PreferenceManager.setDefaultValues(getActivity(), R.xml.preferences, false); networkService = NetworkService.get(getActivity().getApplicationContext()); mainMenuRefreshResultReceiver = new MainMenuRefreshResultReceiver(new Handler()); }
From source file:com.duy.pascal.ui.activities.SplashScreenActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); PreferenceManager.setDefaultValues(this, R.xml.pref_settings, false); setContentView(R.layout.activity_splash); if (!permissionGranted()) { requestPermission();//from w ww . j av a 2 s .c om } else { startMainActivity(); } }
From source file:org.jonblack.bluetrack.activities.MainActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main_activity); // Load default preference values. // The defaults are only loaded if they haven't been done before. It will // not overwrite changes. // @see PreferenceManager.setDefaultValues PreferenceManager.setDefaultValues(this, R.xml.preferences, false); // Get the local bluetooth adapter and check if bluetooth is supported. BluetoothAdapter localBtAdapter = BluetoothAdapter.getDefaultAdapter(); if (localBtAdapter == null) { Log.w(TAG, "Bluetooth isn't supported on device."); AlertDialog ad = new AlertDialog.Builder(this).create(); ad.setCancelable(false);/*from www. j a v a2 s . c om*/ Resources r = getResources(); String msg = r.getString(R.string.error_bluetooth_not_supported, r.getString(R.string.app_name)); ad.setMessage(msg); ad.setButton(AlertDialog.BUTTON_POSITIVE, r.getString(R.string.button_exit), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { finish(); dialog.dismiss(); } }); ad.show(); return; } Resources r = getResources(); ActionBar actionBar = getSupportActionBar(); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); ActionBar.Tab tab1 = actionBar.newTab().setText(r.getText(R.string.ab_tab_live_tracking)); tab1.setTag("tracking"); tab1.setTabListener(new TabListener<LiveTrackingFragment>(this, "tracking", LiveTrackingFragment.class)); actionBar.addTab(tab1); ActionBar.Tab tab2 = actionBar.newTab().setText(r.getText(R.string.ab_tab_sessions)); tab2.setTag("session"); tab2.setTabListener(new TabListener<SessionFragment>(this, "session", SessionFragment.class)); actionBar.addTab(tab2); ActionBar.Tab tab3 = actionBar.newTab().setText(r.getText(R.string.ab_tab_devices)); tab3.setTag("devices"); tab3.setTabListener(new TabListener<DevicesFragment>(this, "devices", DevicesFragment.class)); actionBar.addTab(tab3); }
From source file:de.baumann.browser.helper.Activity_intent.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); onNewIntent(getIntent());/*from w w w .j a va 2 s .c om*/ android.content.Intent intent = getIntent(); Uri data = intent.getData(); String domain; if (Uri.parse(data.toString()).getHost().length() == 0) { domain = getString(R.string.app_domain); } else { domain = Uri.parse(data.toString()).getHost(); } if (domain.contains("www.")) { domain = domain.replace("www.", "").toUpperCase(); } String domain2 = domain.substring(0, 1).toUpperCase() + domain.substring(1); PreferenceManager.setDefaultValues(this, R.xml.user_settings, false); PreferenceManager.setDefaultValues(this, R.xml.user_settings_search, false); SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this); sharedPref.edit().putString("add_readLater_link", data.toString()).apply(); sharedPref.edit().putString("add_readLater_domain", domain2).apply(); Random rand = new Random(); int n = rand.nextInt(100000); android.content.Intent iMain = new android.content.Intent(); iMain.setData(data); iMain.setAction(Intent.ACTION_VIEW); iMain.setClassName(Activity_intent.this, "de.baumann.browser.Browser_left"); android.content.Intent iAction = new android.content.Intent(this, Browser_left.class); iAction.setAction("readLater"); android.content.Intent iAction_2 = new android.content.Intent(this, Activity_intent_add.class); iAction_2.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE); PendingIntent piMain = PendingIntent.getActivity(this, n, iMain, 0); PendingIntent piAction = PendingIntent.getActivity(this, n, iAction, 0); PendingIntent piAction_2 = PendingIntent.getActivity(this, n, iAction_2, 0); NotificationCompat.Action action = new NotificationCompat.Action.Builder(R.drawable.format_list_bulleted, getString(R.string.readLater_action), piAction).build(); NotificationCompat.Action action_2 = new NotificationCompat.Action.Builder(R.drawable.format_list_bulleted, getString(R.string.readLater_action2), piAction_2).build(); android.support.v4.app.NotificationCompat.Builder builderSummary = new android.support.v4.app.NotificationCompat.Builder( Activity_intent.this).setAutoCancel(true).setSmallIcon(R.drawable.earth) .setColor(ContextCompat.getColor(Activity_intent.this, R.color.colorPrimary)) .setGroup("Browser").setGroupSummary(true).setContentIntent(piMain); Notification notification = new android.support.v4.app.NotificationCompat.Builder(Activity_intent.this) .setColor(ContextCompat.getColor(Activity_intent.this, R.color.colorPrimary)) .setSmallIcon(R.drawable.earth).setContentTitle(getString(R.string.readLater_title)) .setContentText(data.toString()).setContentIntent(piMain).setAutoCancel(true).setGroup("Browser") .addAction(action).addAction(action_2) .setStyle(new android.support.v4.app.NotificationCompat.BigTextStyle().bigText(data.toString())) .setPriority(Notification.PRIORITY_MAX).setVibrate(new long[0]).build(); NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); notificationManager.notify(n, notification); notificationManager.notify(0, builderSummary.build()); finish(); }