List of usage examples for android.preference PreferenceManager setDefaultValues
public static void setDefaultValues(Context context, @XmlRes int resId, boolean readAgain)
From source file:reddy.preetham.forecast.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { // Initialize the associated SharedPreferences file with default values PreferenceManager.setDefaultValues(this, R.xml.prefs, false); darkTheme = false;// w w w . j ava 2 s. c om SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); if (prefs.getBoolean("darkTheme", false)) { setTheme(R.style.AppTheme_NoActionBar_Dark); darkTheme = true; } // Initiate activity super.onCreate(savedInstanceState); Fabric.with(this, new Crashlytics()); setContentView(R.layout.activity_scrolling); appView = findViewById(R.id.viewApp); progressDialog = new ProgressDialog(MainActivity.this); // Load toolbar Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); if (darkTheme) { toolbar.setPopupTheme(R.style.AppTheme_PopupOverlay_Dark); } // Initialize textboxes todayTemperature = (TextView) findViewById(R.id.todayTemperature); todayDescription = (TextView) findViewById(R.id.todayDescription); todayWind = (TextView) findViewById(R.id.todayWind); todayPressure = (TextView) findViewById(R.id.todayPressure); todayHumidity = (TextView) findViewById(R.id.todayHumidity); todaySunrise = (TextView) findViewById(R.id.todaySunrise); todaySunset = (TextView) findViewById(R.id.todaySunset); lastUpdate = (TextView) findViewById(R.id.lastUpdate); todayIcon = (TextView) findViewById(R.id.todayIcon); weatherFont = Typeface.createFromAsset(this.getAssets(), "fonts/weather.ttf"); todayIcon.setTypeface(weatherFont); // Initialize viewPager viewPager = (ViewPager) findViewById(R.id.viewPager); tabLayout = (TabLayout) findViewById(R.id.tabs); destroyed = false; //changes in branch1 initMappings(); // Preload data from cache preloadWeather(); updateLastUpdateTime(); // Set autoupdater AlarmReceiver.setRecurringAlarm(this); }
From source file:ru.frostdev.weather.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { // Initialize the associated SharedPreferences file with default values PreferenceManager.setDefaultValues(this, R.xml.prefs, false); darkTheme = false;// w ww.j a va2s .co m SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); if (prefs.getBoolean("darkTheme", false)) { setTheme(R.style.AppTheme_NoActionBar_Dark); darkTheme = true; } // Initiate activity super.onCreate(savedInstanceState); setContentView(R.layout.activity_scrolling); appView = findViewById(R.id.viewApp); progressDialog = new ProgressDialog(MainActivity.this); // Load toolbar Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); if (darkTheme) { toolbar.setPopupTheme(R.style.AppTheme_PopupOverlay_Dark); } // Initialize textboxes todayTemperature = (TextView) findViewById(R.id.todayTemperature); todayDescription = (TextView) findViewById(R.id.todayDescription); todayWind = (TextView) findViewById(R.id.todayWind); todayPressure = (TextView) findViewById(R.id.todayPressure); todayHumidity = (TextView) findViewById(R.id.todayHumidity); todaySunrise = (TextView) findViewById(R.id.todaySunrise); todaySunset = (TextView) findViewById(R.id.todaySunset); lastUpdate = (TextView) findViewById(R.id.lastUpdate); todayIcon = (TextView) findViewById(R.id.todayIcon); weatherFont = Typeface.createFromAsset(this.getAssets(), "fonts/weather.ttf"); todayIcon.setTypeface(weatherFont); // Initialize viewPager viewPager = (ViewPager) findViewById(R.id.viewPager); tabLayout = (TabLayout) findViewById(R.id.tabs); destroyed = false; initMappings(); // Preload data from cache preloadWeather(); updateLastUpdateTime(); // Set autoupdater AlarmReceiver.setRecurringAlarm(this); }
From source file:net.chuzarski.crowdednews.activities.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //Start logging Timber.tag("MainActivity"); //Since this app is going to be released quickly, we may have Activity Lifecycle quirks //allow ONLY portrait orientation for now setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); //UI References vWaitIndicator = (ProgressBar) findViewById(R.id.waiting_icon); vList = (ListView) findViewById(R.id.posts_list_view); vOurActionBar = getActionBar();// www . ja v a 2s .c om vNavDrawer = (DrawerLayout) findViewById(R.id.navigation_drawer_layout); vDrawerList = (ListView) findViewById(R.id.navigation_list); abTitle = (TextView) findViewById(getResources().getIdentifier("action_bar_title", "id", "android")); //MISC mNewsSources = new RedditSources(); navEventHandler = new DrawerHandler(); pageLoader = new PageListener(); filterDialog = createFilterDialog(); //Settings PreferenceManager.setDefaultValues(this, R.xml.settings_layout, true); mSettings = PreferenceManager.getDefaultSharedPreferences(this); //setup navigation mDrawerAdapter = new ArrayAdapter<String>(this, R.layout.navigation_list_item, R.id.navigation_item_list, getResources().getStringArray(R.array.news_channels_strings)); vDrawerList.setAdapter(mDrawerAdapter); vDrawerList.setOnItemClickListener(navEventHandler); //setup the listview mAdapter = new PostsAdapter(getApplicationContext()); vList.setAdapter(mAdapter); //multitasking events = EventBus.getDefault(); jobs = CrowdedNewsApplication.getInstance().getJobManager(); events.register(this); //wire event handlers vList.setOnItemClickListener(new ListHandler()); vList.setOnScrollListener(pageLoader); //app Session mSession = new AppSession(); }
From source file:org.libreoffice.ui.LibreOfficeUIActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // initialize document provider factory DocumentProviderFactory.initialize(this); documentProviderFactory = DocumentProviderFactory.getInstance(); PreferenceManager.setDefaultValues(this, R.xml.documentprovider_preferences, false); readPreferences();/*from w w w. j a v a2s. com*/ // init UI and populate with contents from the provider createUI(); switchToDocumentProvider(documentProviderFactory.getDefaultProvider()); }
From source file:de.lespace.apprtc.ConnectChatActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_connect); // Get setting keys. PreferenceManager.setDefaultValues(this, R.xml.preferences, false); sharedPref = PreferenceManager.getDefaultSharedPreferences(this); missingPermissions = new ArrayList(); for (String permission : MANDATORY_PERMISSIONS) { if (checkCallingOrSelfPermission(permission) != PackageManager.PERMISSION_GRANTED) { missingPermissions.add(permission); }//from ww w .j a va 2 s.co m } requestPermission(); //Bring Call2Front when bringToFrontBroadcastReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { Intent intentStart = new Intent(getApplicationContext(), ConnectChatActivity.class); // intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); intent.addFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); intent.addFlags(Intent.FLAG_ACTIVITY_PREVIOUS_IS_TOP); startActivity(intentStart); // newFragment.show(transaction,"loading"); // showDialog(); } }; registerBringToFrontReceiver(); if (checkPlayServices()) { // Start IntentService to register this application with GCM. Intent intent = new Intent(this, RegistrationIntentService.class); startService(intent); } ImageButton connectButton = (ImageButton) findViewById(R.id.connect_button); connectButton.setOnClickListener(connectListener); // If an implicit VIEW intent is launching the app, go directly to that URL. //final Intent intent = getIntent(); Uri wsurl = Uri.parse(Configs.ROOM_URL); //intent.getData(); Log.d(TAG, "connecting to:" + wsurl.toString()); if (wsurl == null) { logAndToast(getString(R.string.missing_wsurl)); Log.e(TAG, "Didn't get any URL in intent!"); setResult(RESULT_CANCELED); finish(); return; } if (from == null || from.length() == 0) { logAndToast(getString(R.string.missing_from)); Log.e(TAG, "Incorrect from in intent!"); setResult(RESULT_CANCELED); finish(); return; } roomConnectionParameters = new AppRTCClient.RoomConnectionParameters(wsurl.toString(), from, false); Log.i(TAG, "creating appRtcClient with roomUri:" + wsurl.toString() + " from:" + from); // Create connection client and connection parameters. appRtcClient = new WebSocketRTCClient(this, new LooperExecutor()); connectToWebsocket(); // ATTENTION: This was auto-generated to implement the App Indexing API. // See https://g.co/AppIndexing/AndroidStudio for more information. }
From source file:de.baumann.hhsmoodle.fragmentsMain.FragmentBrowser.java
@SuppressWarnings("ResultOfMethodCallIgnored") @SuppressLint("SetJavaScriptEnabled") @Override/*from w w w. j av a 2 s.c o m*/ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_screen_browser, container, false); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { WebView.enableSlowWholeDocumentDraw(); } PreferenceManager.setDefaultValues(getActivity(), R.xml.user_settings, false); sharedPref = PreferenceManager.getDefaultSharedPreferences(getActivity()); sharedPref.edit().putString("browserStarted", "true").apply(); customViewContainer = (FrameLayout) rootView.findViewById(R.id.customViewContainer); progressBar = (ProgressBar) rootView.findViewById(R.id.progressBar); viewPager = (ViewPager) getActivity().findViewById(R.id.viewpager); SwipeRefreshLayout swipeView = (SwipeRefreshLayout) rootView.findViewById(R.id.swipe); assert swipeView != null; swipeView.setColorSchemeResources(R.color.colorPrimary, R.color.colorAccent); swipeView.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { mWebView.reload(); } }); mWebView = (WebView) rootView.findViewById(R.id.webView); mWebChromeClient = new myWebChromeClient(); mWebView.setWebChromeClient(mWebChromeClient); imageButton_left = (ImageButton) rootView.findViewById(R.id.imageButton_left); imageButton_right = (ImageButton) rootView.findViewById(R.id.imageButton_right); if (sharedPref.getBoolean("arrow", false)) { imageButton_left.setVisibility(View.VISIBLE); imageButton_right.setVisibility(View.VISIBLE); } else { imageButton_left.setVisibility(View.INVISIBLE); imageButton_right.setVisibility(View.INVISIBLE); } helper_webView.webView_Settings(getActivity(), mWebView); helper_webView.webView_WebViewClient(getActivity(), swipeView, mWebView); mWebView.setDownloadListener(new DownloadListener() { public void onDownloadStart(final String url, String userAgent, final String contentDisposition, final String mimetype, long contentLength) { final String filename = URLUtil.guessFileName(url, contentDisposition, mimetype); Snackbar snackbar = Snackbar .make(mWebView, getString(R.string.toast_download_1) + " " + filename, Snackbar.LENGTH_INDEFINITE) .setAction(getString(R.string.toast_yes), new View.OnClickListener() { @Override public void onClick(View view) { DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url)); request.addRequestHeader("Cookie", CookieManager.getInstance().getCookie(url)); request.allowScanningByMediaScanner(); request.setNotificationVisibility( DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); //Notify client once download is completed! request.setDestinationInExternalPublicDir(newFileDest(), filename); DownloadManager dm = (DownloadManager) getActivity() .getSystemService(DOWNLOAD_SERVICE); dm.enqueue(request); Snackbar.make(mWebView, getString(R.string.toast_download) + " " + filename, Snackbar.LENGTH_LONG).show(); getActivity().registerReceiver(onComplete, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE)); } }); snackbar.show(); } }); String URLtoOpen = sharedPref.getString("loadURL", ""); if (URLtoOpen.isEmpty()) { mWebView.loadUrl( sharedPref.getString("favoriteURL", "https://moodle.huebsch.ka.schule-bw.de/moodle/my/")); } else { mWebView.loadUrl(URLtoOpen); } setHasOptionsMenu(true); return rootView; }
From source file:de.baumann.hhsmoodle.helper.helper_main.java
public static void onClose(final Activity activity) { PreferenceManager.setDefaultValues(activity, R.xml.user_settings, false); sharedPref = PreferenceManager.getDefaultSharedPreferences(activity); final ProgressDialog progressDialog; if (sharedPref.getBoolean("backup_aut", false)) { try {//from w w w . j a v a 2 s. c o m helper_security.encryptBackup(activity, "/bookmarks_DB_v01.db"); } catch (Exception e) { e.printStackTrace(); } try { helper_security.encryptBackup(activity, "/courses_DB_v01.db"); } catch (Exception e) { e.printStackTrace(); } try { helper_security.encryptBackup(activity, "/notes_DB_v01.db"); } catch (Exception e) { e.printStackTrace(); } try { helper_security.encryptBackup(activity, "/random_DB_v01.db"); } catch (Exception e) { e.printStackTrace(); } try { helper_security.encryptBackup(activity, "/subject_DB_v01.db"); } catch (Exception e) { e.printStackTrace(); } try { helper_security.encryptBackup(activity, "/schedule_DB_v01.db"); } catch (Exception e) { e.printStackTrace(); } try { helper_security.encryptBackup(activity, "/todo_DB_v01.db"); } catch (Exception e) { e.printStackTrace(); } progressDialog = new ProgressDialog(activity); progressDialog.setMessage(activity.getString(R.string.app_close)); progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); progressDialog.show(); new Handler().postDelayed(new Runnable() { public void run() { sharedPref.edit().putString("loadURL", "").apply(); helper_security.encryptDatabases(activity); if (progressDialog.isShowing()) { progressDialog.cancel(); } activity.finishAffinity(); } }, 1500); } else { sharedPref.edit().putString("loadURL", "").apply(); helper_security.encryptDatabases(activity); activity.finishAffinity(); } }
From source file:com.example.mobilewebproxy.MainActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); _behindView = new LogBehindView(this, null); _serverController = new ServerController(); setBehindContentView(_behindView);//from w w w . j ava 2 s.com setContentView(R.layout.activity_main); _notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); logView = (TextView) _behindView.findViewById(R.id.log_view); _startButton = (Button) findViewById(R.id.start_button); _downloadedTextView = (TextView) findViewById(R.id.download_counter); _uploadedTextView = (TextView) findViewById(R.id.upload_counter); logView.setText(" ", TextView.BufferType.EDITABLE); logView.setEditableFactory(Editable.Factory.getInstance()); _editable = (Editable) logView.getText(); setTitle("Main"); PreferenceManager.setDefaultValues(getApplicationContext(), R.xml.preferences, false); SettingsActivity.initPrefs(getApplicationContext()); _indicatorView = (ImageView) findViewById(R.id.indicator); _indicatorAnimation = AnimationUtils.loadAnimation(this, R.anim.indicator_rotate); /* see the SlidingMenu documentation for details*/ SlidingMenu slideMenu = getSlidingMenu(); slideMenu.setShadowWidth(R.dimen.shadow_width); slideMenu.setShadowDrawable(R.drawable.shadow); slideMenu.setBehindOffsetRes(R.dimen.slidingmenu_offset); slideMenu.setFadeDegree(0.35f); slideMenu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN); /////////////////////////////////////////////////////////////// getSupportActionBar().setDisplayShowHomeEnabled(true); getSupportActionBar().setHomeButtonEnabled(true); setSlidingActionBarEnabled(true); }
From source file:com.yangtsaosoftware.pebblemessenger.activities.NavigationActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); if (id == R.id.action_settings) { PreferenceManager.setDefaultValues(this, R.xml.preference, true); return true; }// w w w.j a v a2s .co m return super.onOptionsItemSelected(item); }
From source file:org.puder.trs80.MainActivity.java
@Override public void onCreate(Bundle savedInstanceState) { // StrictMode.enableDefaults(); super.onCreate(savedInstanceState); mInstallExecutor = Executors.newSingleThreadExecutor(); RetrostoreApi.get().registerAppInstallListener(new AppInstallListener() { @Override//from w w w . j av a 2 s . c o m public void onInstallApp(App app) { asyncDownloadAndInstallApp(app); } }); PreferenceManager.setDefaultValues(this, R.xml.configuration, false); sharedPrefs = this.getSharedPreferences(SettingsActivity.SHARED_PREF_NAME, Context.MODE_PRIVATE); setContentView(R.layout.main_activity); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); toggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); drawer.setDrawerListener(toggle); NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view); navigationView.setNavigationItemSelectedListener(this); FileManager.Creator fileManagerCreator = FileManager.Creator.get(getResources()); try { configManager = ConfigurationManager.get(getApplicationContext()); romManager = RomManager.init(fileManagerCreator); } catch (IOException e) { Log.e(TAG, "Cannot initialize RomManager / ConfigurationManager.", e); finish(); // Cannot really launch the app if initialization fails. // TODO: Show an error message before exiting. return; } appInstaller = new AppInstaller(configManager, ImageLoader.get(getApplicationContext()), RetrostoreApi.get()); castMessageSender = CastMessageSender.get(); int screenWidthDp = this.getResources().getConfiguration().screenWidthDp; int numColumns = (screenWidthDp == android.content.res.Configuration.SCREEN_WIDTH_DP_UNDEFINED) ? 1 : screenWidthDp / COLUMN_WIDTH_DP; RecyclerView.LayoutManager lm = null; if (numColumns <= 1) { lm = new LinearLayoutManager(this); } else { lm = new GridLayoutManager(this, numColumns); } configurationListViewAdapter = new ConfigurationListViewAdapter(configManager, this, numColumns); configurationListView = (RecyclerView) this.findViewById(R.id.list_configurations); configurationListView.setLayoutManager(lm); configurationListView.setAdapter(configurationListViewAdapter); ItemTouchHelper.Callback callback = new ConfigurationItemTouchHelperCallback(configurationListViewAdapter); ItemTouchHelper itemTouchHelper = new ItemTouchHelper(callback); itemTouchHelper.attachToRecyclerView(configurationListView); }