List of usage examples for android.preference PreferenceManager setDefaultValues
public static void setDefaultValues(Context context, @XmlRes int resId, boolean readAgain)
From source file:net.issarlk.androbunny.AndrobunnyApp.java
public void onCreate() { // Initialization of ACRA ACRA.init(this); this.uiThread = Thread.currentThread(); //Get layout inflater layoutInflater = LayoutInflater.from(this); super.onCreate(); //Get density Androbunny.it().setScale(this.getResources().getDisplayMetrics().density); Log.d(TAG, "Starting Inkbunny APP"); //Load default values from the xml into preferences. PreferenceManager.setDefaultValues(this, R.xml.preference, false); //Get preference manager for further use. Preference.it().setSharedPreferences(PreferenceManager.getDefaultSharedPreferences(this)); //Set SID in API if saved in preferences if (Preference.it().has("sid")) { API.it().getSID().set(Preference.it().getString("sid")); }/*w w w . j av a 2s. com*/ if (Preference.it().has("ratingsmask")) { API.it().setRatingsmask(Preference.it().getString("ratingsmask")); } else if (API.it().getSID().get() != null) { //The user is logged in, but we don't have her ratingsmask. //She needs to log in again... log her out API.it().logout(); } //Check for update this.worker.execute(new Updater()); //Start cache cleaner thread new CacheCleaner().run(); //Check in the background whether we are logged in or not. final String username = Preference.it().getString("username"); worker.execute(new Runnable() { @Override public void run() { ABUser.it().checkLoggedInAs(username); } }); }
From source file:arc.noaa.weather.activities.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { // Initialize the associated SharedPreferences file with default values PreferenceManager.setDefaultValues(this, R.xml.prefs, false); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); setTheme(theme = getTheme(prefs.getString("theme", "fresh"))); boolean darkTheme = theme == R.style.AppTheme_NoActionBar_Dark || theme == R.style.AppTheme_NoActionBar_Classic_Dark; // 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);//w ww .j av a 2s. co m 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:nz.al4.airclock.MainActivity.java
private void getPreferences() { PreferenceManager.setDefaultValues(this, R.xml.preferences, false); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); // Must set time zones before the hour and minute String originTimeZone = prefs.getString("originTimeZone", null); if (originTimeZone != null) { DateTimeZone zone = DateTimeZone.forOffsetHours(Integer.parseInt(originTimeZone)); this.mOriginDate.setZone(zone); }//from w w w .j a v a 2s . co m String originDate = prefs.getString("takeOffDate", null); if (originDate != null) { this.mOriginDate.setYear(DatePreference.getYear(originDate)); this.mOriginDate.setMonthOfYear(DatePreference.getMonth(originDate)); this.mOriginDate.setDayOfMonth(DatePreference.getDay(originDate)); } else { Log.i("prefs", "takeOffDate is null"); } String originTime = prefs.getString("takeOffTime", null); if (originTime != null) { this.mOriginDate.setHourOfDay(TimePreference.getHour(originTime)); this.mOriginDate.setMinuteOfHour(TimePreference.getMinute(originTime)); } else { Log.i("prefs", "takeOffTime is null"); } String destTimeZone = prefs.getString("destTimeZone", null); if (destTimeZone != null) { DateTimeZone zone = DateTimeZone.forOffsetHours(Integer.parseInt(destTimeZone)); this.mDestDate.setZone(zone); } String destDate = prefs.getString("landingDate", null); if (destDate != null) { this.mDestDate.setYear(DatePreference.getYear(destDate)); this.mDestDate.setMonthOfYear(DatePreference.getMonth(destDate)); this.mDestDate.setDayOfMonth(DatePreference.getDay(destDate)); } else { Log.i("prefs", "landingDate is null"); } String destTime = prefs.getString("landingTime", null); if (destTime != null) { this.mDestDate.setHourOfDay(TimePreference.getHour(destTime)); this.mDestDate.setMinuteOfHour(TimePreference.getMinute(destTime)); } else { Log.i("prefs", "landingTime is null"); } mDirection = prefs.getString("calc_direction", "auto"); Log.e("mainfoo", mDirection); setTextViews(); mClockFragment.direction = mDirection; mClockFragment.originTime = mOriginDate.toDateTime(); mClockFragment.destTime = mDestDate.toDateTime(); }
From source file:org.hfoss.posit.web.Communicator.java
public Communicator(Context _context) { mContext = _context;/*from w w w. j ava 2s . c o m*/ mTotalTime = 0; mStart = 0; mHttpParams = new BasicHttpParams(); SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme("http", new PlainSocketFactory(), 80)); mConnectionManager = new ThreadSafeClientConnManager(mHttpParams, registry); mHttpClient = new DefaultHttpClient(mConnectionManager, mHttpParams); PreferenceManager.setDefaultValues(mContext, R.xml.posit_preferences, false); applicationPreferences = PreferenceManager.getDefaultSharedPreferences(mContext); setApplicationAttributes(applicationPreferences.getString("AUTHKEY", ""), applicationPreferences.getString("SERVER_ADDRESS", server), applicationPreferences.getInt("PROJECT_ID", projectId)); TelephonyManager manager = (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE); imei = manager.getDeviceId(); }
From source file:net.homelinux.penecoptero.android.citybikes.app.MainActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main);/*from w ww. j a v a 2 s.c o m*/ PreferenceManager.setDefaultValues(this, R.xml.preferences, false); mapView = (MapView) findViewById(R.id.mapview); mSlidingDrawer = (StationSlidingDrawer) findViewById(R.id.drawer); infoLayer = (InfoLayer) findViewById(R.id.info_layer); scale = getResources().getDisplayMetrics().density; //Log.i("CityBikes","ON CREATEEEEEEEEE!!!!!"); infoLayerPopulator = new Handler() { @Override public void handleMessage(Message msg) { if (msg.what == InfoLayer.POPULATE) { infoLayer.inflateStation(stations.getCurrent()); } if (msg.what == CityBikes.BOOKMARK_CHANGE) { int id = msg.arg1; boolean bookmarked; if (msg.arg2 == 0) { bookmarked = false; } else { bookmarked = true; } StationOverlay station = stations.getById(id); try { BookmarkManager bm = new BookmarkManager(getApplicationContext()); bm.setBookmarked(station.getStation(), !bookmarked); } catch (Exception e) { Log.i("CityBikes", "Error bookmarking station"); e.printStackTrace(); } if (!view_all) { view_near(); } mapView.postInvalidate(); } } }; infoLayer.setHandler(infoLayerPopulator); RelativeLayout.LayoutParams zoomControlsLayoutParams = new RelativeLayout.LayoutParams( android.view.ViewGroup.LayoutParams.WRAP_CONTENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT); zoomControlsLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_TOP); zoomControlsLayoutParams.addRule(RelativeLayout.CENTER_HORIZONTAL); mapView.addView(mapView.getZoomControls(), zoomControlsLayoutParams); modeButton = (ToggleButton) findViewById(R.id.mode_button); modeButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { changeMode(!getBike); } }); applyMapViewLongPressListener(mapView); settings = getSharedPreferences(CityBikes.PREFERENCES_NAME, 0); List<Overlay> mapOverlays = mapView.getOverlays(); locator = new Locator(this, new Handler() { @Override public void handleMessage(Message msg) { if (msg.what == Locator.LOCATION_CHANGED) { GeoPoint point = new GeoPoint(msg.arg1, msg.arg2); hOverlay.moveCenter(point); mapView.getController().animateTo(point); mDbHelper.setCenter(point); // Location has changed try { mDbHelper.updateDistances(point); infoLayer.update(); if (!view_all) { view_near(); } } catch (Exception e) { } ; } } }); hOverlay = new HomeOverlay(locator.getCurrentGeoPoint(), new Handler() { @Override public void handleMessage(Message msg) { if (msg.what == HomeOverlay.MOTION_CIRCLE_STOP) { try { if (!view_all) { view_near(); } mapView.postInvalidate(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } } }); stations = new StationOverlayList(mapOverlays, new Handler() { @Override public void handleMessage(Message msg) { //Log.i("CityBikes","Message: "+Integer.toString(msg.what)+" "+Integer.toString(msg.arg1)); if (msg.what == StationOverlay.TOUCHED && msg.arg1 != -1) { // One station has been touched stations.setCurrent(msg.arg1, getBike); infoLayer.inflateStation(stations.getCurrent()); //Log.i("CityBikes","Station touched: "+Integer.toString(msg.arg1)); } } }); stations.addOverlay(hOverlay); mNDBAdapter = new NetworksDBAdapter(getApplicationContext()); mDbHelper = new StationsDBAdapter(this, mapView, new Handler() { @Override public void handleMessage(Message msg) { switch (msg.what) { case StationsDBAdapter.FETCH: break; case StationsDBAdapter.UPDATE_MAP: progressDialog.dismiss(); SharedPreferences.Editor editor = settings.edit(); editor.putBoolean("reload_network", false); editor.commit(); case StationsDBAdapter.UPDATE_DATABASE: StationOverlay current = stations.getCurrent(); if (current == null) { infoLayer.inflateMessage(getString(R.string.no_bikes_around)); } if (current != null) { infoLayer.inflateStation(current); if (view_all) view_all(); else view_near(); } else { } mapView.invalidate(); infoLayer.update(); ////Log.i("openBicing", "Database updated"); break; case StationsDBAdapter.NETWORK_ERROR: ////Log.i("openBicing", "Network error, last update from " + mDbHelper.getLastUpdated()); Toast toast = Toast.makeText(getApplicationContext(), getString(R.string.network_error) + " " + mDbHelper.getLastUpdated(), Toast.LENGTH_LONG); toast.show(); break; } } }, stations); mDbHelper.setCenter(locator.getCurrentGeoPoint()); mSlidingDrawer.setHandler(new Handler() { @Override public void handleMessage(Message msg) { switch (msg.what) { case StationSlidingDrawer.ITEMCLICKED: StationOverlay clicked = (StationOverlay) msg.obj; stations.setCurrent(msg.arg1, getBike); Message tmp = new Message(); tmp.what = InfoLayer.POPULATE; tmp.arg1 = msg.arg1; infoLayerPopulator.dispatchMessage(tmp); mapView.getController().animateTo(clicked.getCenter()); } } }); if (savedInstanceState != null) { locator.unlockCenter(); hOverlay.setRadius(savedInstanceState.getInt("homeRadius")); this.view_all = savedInstanceState.getBoolean("view_all"); } else { updateHome(); } try { mDbHelper.loadStations(); if (savedInstanceState == null) { String strUpdated = mDbHelper.getLastUpdated(); Boolean dirty = settings.getBoolean("reload_network", false); if (strUpdated == null || dirty) { this.fillData(view_all); } else { Toast toast = Toast.makeText(this.getApplicationContext(), "Last Updated: " + mDbHelper.getLastUpdated(), Toast.LENGTH_LONG); toast.show(); Calendar cal = Calendar.getInstance(); long now = cal.getTime().getTime(); if (Math.abs(now - mDbHelper.getLastUpdatedTime()) > 60000 * 5) this.fillData(view_all); } } } catch (Exception e) { ////Log.i("openBicing", "SHIT ... SUCKS"); } ; if (view_all) view_all(); else view_near(); ////Log.i("openBicing", "CREATE!"); }
From source file:com.abhijitvalluri.android.fitnotifications.AppChoicesActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_app_selector); LAUNCH_ACTIVITY_ANIM_BUNDLE = ActivityOptions .makeCustomAnimation(AppChoicesActivity.this, R.transition.left_in, R.transition.left_out) .toBundle();// w ww . j a va 2s.c o m mPackageManager = getPackageManager(); mAppSelectionsStore = AppSelectionsStore.get(this); mRecyclerView = (RecyclerView) findViewById(R.id.app_selections_recycler_view); mLoadingView = (TextView) findViewById(R.id.app_list_loading_text_view); mProgressBar = (ProgressBar) findViewById(R.id.progressBar); mRecyclerView.setLayoutManager(new LinearLayoutManager(this)); PreferenceManager.setDefaultValues(this, R.xml.main_settings, false); mPreferences = PreferenceManager.getDefaultSharedPreferences(this); mShowOnlyEnabledApps = mPreferences.getBoolean(getString(R.string.show_enabled_apps_key), false); if (savedInstanceState != null && getSetupStatus(savedInstanceState)) { mAppSelections = savedInstanceState.getParcelableArrayList(STATE_APP_SELECTIONS); Parcelable listState = savedInstanceState.getParcelable(STATE_RECYCLER_VIEW); if (mShowOnlyEnabledApps) { List<AppSelection> appSelectionsSubList = new ArrayList<>(); for (AppSelection appSelection : mAppSelections) { if (appSelection.isSelected()) { appSelectionsSubList.add(appSelection); } } mAdapter = new ActivityAdapter(appSelectionsSubList); } else { mAdapter = new ActivityAdapter(mAppSelections); } mRecyclerView.setAdapter(mAdapter); mRecyclerView.getLayoutManager().onRestoreInstanceState(listState); mSetupComplete = getSetupStatus(savedInstanceState); } else { mLoadingView.setText(getString(R.string.app_list_loading_text)); mRecyclerView.setVisibility(View.GONE); mLoadingView.setVisibility(View.VISIBLE); mProgressBar.setVisibility(View.VISIBLE); new AppListSetup().execute(); } }
From source file:eu.istvank.apps.lenslog.activities.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); getSupportFragmentManager().addOnBackStackChangedListener(this); PreferenceManager.setDefaultValues(this, R.xml.preferences, false); if (getIntent().hasExtra(NotifySchedulingService.NOTIFICATION_WORN)) { //TODO: save date in intent so that we can retrieve whether it still applies for the current date DateTime utcDateTime = DateTime.today(TimeZone.getTimeZone("UTC")); long utcDateLong = utcDateTime.getMilliseconds(TimeZone.getTimeZone("UTC")); boolean isWorn = getIntent().getExtras().getBoolean(NotifySchedulingService.NOTIFICATION_WORN); onUpdateWorn(utcDateLong, isWorn); // cancel notification NotificationManager notificationManager = (NotificationManager) this .getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.cancel(NotifySchedulingService.NOTIFICATION_ID); }/*from w w w . jav a2 s.com*/ mToolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(mToolbar); // Read in the flag indicating whether or not the user has demonstrated awareness of the // drawer. See PREF_USER_LEARNED_DRAWER for details. SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this); // check if the user has already accepted the privacy policy boolean privacyPolicyAccepted = sp.getBoolean(PREF_USER_ACCEPTED_PRIVACY_POLICY, false); if (!privacyPolicyAccepted) { HelpUtils.showPrivacyPolicy(this, true); } mUserLearnedDrawer = sp.getBoolean(PREF_USER_LEARNED_DRAWER, false); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawerLayout.setStatusBarBackgroundColor(getTitleColor()); mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START); mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, mToolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close) { @Override public void onDrawerClosed(View drawerView) { invalidateOptionsMenu(); // calls onPrepareOptionsMenu() } @Override public void onDrawerOpened(View drawerView) { super.onDrawerOpened(drawerView); if (!mUserLearnedDrawer) { // The user manually opened the drawer; store this flag to prevent auto-showing // the navigation drawer automatically in the future. mUserLearnedDrawer = true; SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(MainActivity.this); sp.edit().putBoolean(PREF_USER_LEARNED_DRAWER, true).apply(); } invalidateOptionsMenu(); // calls onPrepareOptionsMenu() } }; mDrawerLayout.setDrawerListener(mDrawerToggle); getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setHomeButtonEnabled(true); mNavigationDrawerFragment = (NavigationDrawerFragment) getSupportFragmentManager() .findFragmentById(R.id.navigation_drawer); mNavigationDrawerFragment.setUp(this, R.id.navigation_drawer, mDrawerLayout); // If the user hasn't 'learned' about the drawer, open it to introduce them to the drawer, // per the navigation drawer design guidelines. if (!mUserLearnedDrawer) { mDrawerLayout.openDrawer(findViewById(R.id.navigation_drawer)); } if (savedInstanceState != null) { // probably configuration change mBackEnabled = savedInstanceState.getBoolean(STATE_BACK_ENABLED); setBackEnabled(mBackEnabled); } else { // app freshly started, show calendar fragment onNavigationDrawerItemSelected(NavigationDrawerFragment.SECTION_CALENDAR); } mDrawerLayout.post(new Runnable() { @Override public void run() { mDrawerToggle.syncState(); } }); mTitle = getTitle(); }
From source file:edu.mit.mobile.android.demomode.DemoMode.java
/** Called when the activity is first created. */ @Override// www . j av a2 s .c om public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mGridView = (GridView) findViewById(R.id.grid); getSupportLoaderManager().initLoader(0, null, this); mAdapter = new LauncherItemAdapter(this, R.layout.launcher_item, null); mGridView.setAdapter(mAdapter); mGridView.setOnItemClickListener(this); mGridView.setOnItemLongClickListener(this); mAllApps = (GridView) findViewById(R.id.all_apps); loadApplications(true); mDrawer = (SlidingDrawer) findViewById(R.id.slidingDrawer1); mAllApps.setAdapter(new ApplicationsAdapter(this, mApplications)); mAllApps.setOnItemClickListener(this); mAllApps.setOnItemLongClickListener(this); mPrefs = PreferenceManager.getDefaultSharedPreferences(this); PreferenceManager.setDefaultValues(this, R.xml.preferences, false); mPassword = mPrefs.getString(Preferences.KEY_PASSWORD, null); mLocked = mPrefs.getBoolean(Preferences.KEY_LOCKED, false); updateLocked(); }
From source file:org.xbmc.kore.ui.RemoteActivity.java
@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.inject(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);//ww w . j a v a2 s .co m finish(); } // 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(); // 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); }
From source file:com.example.ali.topcoderandroid.Activities.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // Initializing Toolbar and setting it as the actionbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar);/* ww w. j a v a 2s. c o m*/ //This will make our app properly initialized with default settings when first loaded. PreferenceManager.setDefaultValues(this, R.xml.preferences, false); drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); setDrawerListener(drawerLayout); coordinatorLayout = (CoordinatorLayout) findViewById(R.id.main_content); if (savedInstanceState == null) { FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); recyclerViewFragment = new RecyclerViewFragment(); transaction.replace(R.id.recyclerview_fragment_container, recyclerViewFragment); transaction.commit(); } //Initializing NavigationView navigationView = (NavigationView) findViewById(R.id.navigation_view); preferredChallengeType = ChallengeType.getPreferred(context); setNavigation(navigationView, preferredChallengeType); }