List of usage examples for android.preference PreferenceManager setDefaultValues
public static void setDefaultValues(Context context, @XmlRes int resId, boolean readAgain)
From source file:me.albertonicoletti.latex.activities.EditorActivity.java
/** * Initializes the preferences./*from w w w . ja v a 2 s.co m*/ * Sets the default output directory and images directory the first time the app is launched. */ private void initPreferences() { String outputPath = SettingsActivity.DEFAULT_OUTPUT_FOLDER; String imagesPath = SettingsActivity.DEFAULT_IMAGES_FOLDER; SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); PreferenceManager.setDefaultValues(this, R.xml.preferences, false); SharedPreferences.Editor prefsEdit = prefs.edit(); String currentOutputFolder = prefs.getString(SettingsActivity.OUTPUT_FOLDER, null); if (currentOutputFolder == null || currentOutputFolder.equals("")) { prefsEdit.putString(SettingsActivity.OUTPUT_FOLDER, outputPath); } String currentImageFolder = prefs.getString(SettingsActivity.IMAGES_FOLDER, null); if (currentImageFolder == null || currentImageFolder.equals("")) { prefsEdit.putString(SettingsActivity.IMAGES_FOLDER, imagesPath); } prefsEdit.apply(); // Creates the folders if they not exists final String imagesFolderPath = PreferenceHelper.getImageFolder(getApplicationContext()); final String outputFolderPath = PreferenceHelper.getOutputFolder(getApplicationContext()); File imagesFolder = new File(imagesFolderPath); if (!imagesFolder.exists()) { FilesUtils.newDirectory(imagesFolderPath); } final File outputFolder = new File(outputFolderPath); if (!outputFolder.exists()) { FilesUtils.newDirectory(outputFolderPath); } }
From source file:com.nextgis.forestinspector.activity.MainActivity.java
protected void createNormalView() { PreferenceManager.setDefaultValues(this, R.xml.preferences, false); setContentView(R.layout.activity_main); setToolbar(R.id.main_toolbar);/*from w w w . j a v a2 s . com*/ setTitle(getText(R.string.app_name)); // Create the adapter that will return a fragment for each of the three // primary sections of the activity. mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager()); // Set up the ViewPager with the sections adapter. mViewPager = (ViewPager) findViewById(R.id.pager); mViewPager.setAdapter(mSectionsPagerAdapter); TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs); tabLayout.setupWithViewPager(mViewPager); if (tabLayout.getTabCount() < mSectionsPagerAdapter.getCount()) { // For each of the sections in the app, add a tab to the action bar. for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) { // Create a tab with text corresponding to the page title defined by // the adapter. Also specify this Activity object, which implements // the TabListener interface, as the callback (listener) for when // this tab is selected. tabLayout.addTab(tabLayout.newTab().setText(mSectionsPagerAdapter.getPageTitle(i))); } } }
From source file:in.co.scsonline.rafaqatrasool.jkssbnotifier.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //ads code start AdView mAdView = (AdView) findViewById(R.id.adView); if (ConnectionUtils.isOnline(MainActivity.this)) { mAdView = (AdView) findViewById(R.id.adView); AdRequest adRequest = new AdRequest.Builder().build(); mAdView.loadAd(adRequest);/* w w w. j av a 2 s . co m*/ } else { mAdView.setVisibility(View.GONE); } //ads code end //callback for rate this app dialog RateThisApp.Config config = new RateThisApp.Config(3, 3); RateThisApp.init(config); /*//analytics code start // Obtain the shared Tracker instance. Analytics application = (Analytics) getApplication(); mTracker = application.getDefaultTracker(); //analytics code end*/ //background update check code start new UpdateRunnable(this, new Handler()).start();//using https://github.com/danielemaddaluno/Android-Update-Checker/ //background update check code end PreferenceManager.setDefaultValues(this, R.xml.settings, false);//set the default values that are provided in xml mTitle = mDrawerTitle = getTitle(); navigationTitles = getResources().getStringArray(R.array.navigation_titles_array); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawerList = (ListView) findViewById(R.id.left_drawer); mDrawerList.setChoiceMode(ListView.CHOICE_MODE_SINGLE); // set a custom shadow that overlays the main content when the drawer opens mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START); // set up the drawer's list view with items and click listener drawerListAdapter = new MyListAdapter(); mDrawerList.setAdapter(drawerListAdapter); mDrawerList.setOnItemClickListener(new DrawerItemClickListener()); // enable ActionBar app icon to behave as action to toggle nav drawer getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setHomeButtonEnabled(true); // ActionBarDrawerToggle ties together the the proper interactions // between the sliding drawer and the action bar app icon mDrawerToggle = new ActionBarDrawerToggle(this, /* host Activity */ mDrawerLayout, /* DrawerLayout object */ // R.drawable.ic_drawer, /* nav drawer image to replace 'Up' caret */ R.string.drawer_open, /* "open drawer" description for accessibility */ R.string.drawer_close /* "close drawer" description for accessibility */ ) { public void onDrawerClosed(View view) { getSupportActionBar().setTitle(mTitle); invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu() } public void onDrawerOpened(View drawerView) { getSupportActionBar().setTitle(mDrawerTitle); invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu() drawerListAdapter.notifyDataSetChanged();//refresh the drawer list } }; mDrawerLayout.setDrawerListener(mDrawerToggle); if (savedInstanceState == null) { selectItem(0); } }
From source file:de.bno.snakingnumbers.MainMenu.java
private void createDefaultSettings() { PreferenceManager.setDefaultValues(this, R.xml.preferences, false); }
From source file:org.traccar.client.MainFragment.java
private void initPreferences() { PreferenceManager.setDefaultValues(getActivity(), R.xml.preferences, false); if (!sharedPreferences.contains(KEY_DEVICE)) { String id = String.valueOf(new Random().nextInt(900000) + 100000); sharedPreferences.edit().putString(KEY_DEVICE, id).apply(); ((EditTextPreference) findPreference(KEY_DEVICE)).setText(id); }/*from w w w . j a va2 s . com*/ findPreference(KEY_DEVICE).setSummary(sharedPreferences.getString(KEY_DEVICE, null)); }
From source file:gov.nasa.arc.geocam.geocam.GeoCamMobile.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Log.d(DEBUG_ID, "GeoCamMobile::onCreate called"); // This call initializes the default values for all the // preference fields. It won't overwrite any changes that the // user made. We make this call every time the app starts in // case the user has upgraded and there are new preference // fields that need to be initialized. PreferenceManager.setDefaultValues(this, R.xml.preferences, true); // Generate a UID for this phone if there isn't one already SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this); if (settings.getString(SETTINGS_UNIQUE_ID, "").equals("")) { settings.edit().putString(SETTINGS_UNIQUE_ID, GpsDbAdapter.generateId("")).commit(); }//from w w w .j a v a 2 s . c o m buildView(); mLocationReceiver = new LocationReceiver(); mLocationProvider = "unknown"; mForeground = new ForegroundTracker(this); TextView locationProviderText = ((TextView) findViewById(R.id.main_location_provider_textview)); locationProviderText.setText(mLocationProvider); TextView locationStatusText = ((TextView) findViewById(R.id.main_location_status_textview)); locationStatusText.setText("unknown"); // can't set this properly until first status update startGeoCamService(); }
From source file:org.lyricue.android.Lyricue.java
void getPrefs() { Log.i(TAG, "getPrefs"); if (progressLoad != null) progressLoad.dismiss();/*from ww w . j ava 2s. c o m*/ progressLoad = ProgressDialog.show(this, "", "Loading Preferences..", true); PreferenceManager.setDefaultValues(this, R.xml.preferences, false); new GetPrefsTask().execute(this); }
From source file:com.scooter1556.sms.android.service.MediaService.java
@RequiresApi(api = Build.VERSION_CODES.O) @Override/* ww w . jav a 2 s . c o m*/ public void onCreate() { super.onCreate(); Log.d(TAG, "onCreate()"); restService = RESTService.getInstance(); // Retrieve preferences if they exist SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); // Load default settings PreferenceManager.setDefaultValues(this, R.xml.preferences, false); // Initialise database ConnectionDatabase db = new ConnectionDatabase(this); // Check connection long id = sharedPreferences.getLong("Connection", -1); if (id >= 0) { Connection connection = db.getConnection(id); restService.setConnection(connection); isConnected = true; } else { isConnected = false; } queueManager = new QueueManager(getApplicationContext(), new QueueManager.MetadataUpdateListener() { @Override public void onMetadataChanged(MediaMetadataCompat metadata) { Log.d(TAG, "onMetadataChanged()"); mediaSession.setMetadata(metadata); } @Override public void onMetadataRetrieveError() { Log.d(TAG, "onMetadataRetrieveError()"); playbackManager.updatePlaybackState(getString(R.string.error_no_metadata)); } @Override public void onCurrentQueueIndexUpdated(int queueIndex) { Log.d(TAG, "onCurrentQueueIndexUpdated(" + queueIndex + ")"); playbackManager.handlePlayRequest(); } @Override public void onQueueUpdated(List<MediaSessionCompat.QueueItem> newQueue) { Log.d(TAG, "onQueueUpdated()"); mediaSession.setQueue(newQueue); mediaSession.setQueueTitle("Now Playing"); } }); // Initialise playback manager playbackManager = PlaybackManager.getInstance(); playbackManager.initialise(getApplicationContext(), this, queueManager); // Start a new Media Session mediaSession = new MediaSessionCompat(this, MediaService.class.getSimpleName()); mediaSession.setCallback(playbackManager.getMediaSessionCallback()); mediaSession.setFlags( MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS | MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS | MediaSessionCompat.FLAG_HANDLES_QUEUE_COMMANDS); Context context = getApplicationContext(); Intent intent = new Intent(context, NowPlayingActivity.class); PendingIntent pendingIntent = PendingIntent.getActivity(context, 99, intent, PendingIntent.FLAG_UPDATE_CURRENT); mediaSession.setSessionActivity(pendingIntent); mediaSessionExtras = new Bundle(); AutoUtils.setSlotReservationFlags(mediaSessionExtras, true, true, true); mediaSession.setExtras(mediaSessionExtras); setSessionToken(mediaSession.getSessionToken()); try { mediaNotificationManager = new MediaNotificationManager(this); } catch (RemoteException e) { throw new IllegalStateException("Could not create a MediaNotificationManager", e); } if (!TVUtils.isTvUiMode(this)) { castSessionManager = CastContext.getSharedInstance(this).getSessionManager(); castSessionManagerListener = new CastSessionManagerListener(); castSessionManager.addSessionManagerListener(castSessionManagerListener, CastSession.class); } mediaRouter = MediaRouter.getInstance(getApplicationContext()); registerCarConnectionReceiver(); // Register connectivity receiver IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION); this.registerReceiver(connectivityChangeReceiver, intentFilter); }
From source file:me.willowcheng.makerthings.ui.OpenHABMainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { Log.d(TAG, "onCreate()"); // Check if we are in development mode perPreferences = getSharedPreferences("pref", this.MODE_PRIVATE); isDeveloper = false;/*from w ww .ja v a 2s . c o m*/ // Set default values, false means do it one time during the very first launch PreferenceManager.setDefaultValues(this, R.xml.preferences, false); // Set non-persistent HABDroid version preference to current version from application package try { Log.d(TAG, "App version = " + getPackageManager().getPackageInfo(getPackageName(), 0).versionName); PreferenceManager.getDefaultSharedPreferences(this).edit().putString(Constants.PREFERENCE_APPVERSION, getPackageManager().getPackageInfo(getPackageName(), 0).versionName).commit(); } catch (PackageManager.NameNotFoundException e1) { if (e1 != null) Log.d(TAG, e1.getMessage()); } checkDiscoveryPermissions(); checkVoiceRecognition(); // initialize loopj async http client mAsyncHttpClient = new MyAsyncHttpClient(this); // Set the theme to one from preferences mSettings = PreferenceManager.getDefaultSharedPreferences(this); // Disable screen timeout if set in preferences if (mSettings.getBoolean(Constants.PREFERENCE_SCREENTIMEROFF, false)) { getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); } // Fetch openHAB service type name from strings.xml openHABServiceType = getString(R.string.openhab_service_type); // Get username/password from preferences openHABUsername = mSettings.getString(Constants.PREFERENCE_USERNAME, null); openHABPassword = mSettings.getString(Constants.PREFERENCE_PASSWORD, null); mAsyncHttpClient.setBasicAuth(openHABUsername, openHABPassword, true); mAsyncHttpClient.setTimeout(30000); if (!isDeveloper) Util.initCrittercism(getApplicationContext(), "5117659f59e1bd4ba9000004"); Util.setActivityTheme(this); super.onCreate(savedInstanceState); if (!isDeveloper) ((HABDroid) getApplication()).getTracker(HABDroid.TrackerName.APP_TRACKER); setContentView(R.layout.activity_main); Toolbar toolbar = (Toolbar) findViewById(R.id.openhab_toolbar); setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); // ProgressBar layout params inside the toolbar have to be done programmatically // because it doesn't work through layout file :-( mProgressBar = (SwipeRefreshLayout) findViewById(R.id.toolbar_progress_bar); mProgressBar.setColorSchemeColors(getResources().getColor(R.color.theme_accent)); mProgressBar.setEnabled(false); mProgressBar.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { mProgressBar.setRefreshing(false); } }); // mProgressBar.setLayoutParams(new Toolbar.LayoutParams(Gravity.RIGHT)); startProgressIndicator(); gcmRegisterBackground(); // Enable app icon in action bar work as 'home' // this.getActionBar().setHomeButtonEnabled(true); pager = (OpenHABViewPager) findViewById(R.id.pager); pager.setScrollDurationFactor(2.5); pager.setOffscreenPageLimit(1); pagerAdapter = new OpenHABFragmentPagerAdapter(getSupportFragmentManager()); pagerAdapter.setColumnsNumber(getResources().getInteger(R.integer.pager_columns)); pagerAdapter.setOpenHABUsername(openHABUsername); pagerAdapter.setOpenHABPassword(openHABPassword); pager.setAdapter(pagerAdapter); pager.setOnPageChangeListener(pagerAdapter); MemorizingTrustManager.setResponder(this); // pager.setPageMargin(1); // pager.setPageMarginDrawable(android.R.color.darker_gray); // Check if we have openHAB page url in saved instance state? if (savedInstanceState != null) { openHABBaseUrl = savedInstanceState.getString("openHABBaseUrl"); sitemapRootUrl = savedInstanceState.getString("sitemapRootUrl"); mStartedWithNetworkConnectivityInfo = savedInstanceState .getParcelable("startedWithNetworkConnectivityInfo"); mOpenHABVersion = savedInstanceState.getInt("openHABVersion"); mSitemapList = savedInstanceState.getParcelableArrayList("sitemapList"); } mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawerList = (ListView) findViewById(R.id.left_drawer); mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, toolbar, R.string.app_name, R.string.app_name) { public void onDrawerClosed(View view) { Log.d(TAG, "onDrawerClosed"); getSupportActionBar().setTitle(pagerAdapter.getPageTitle(pager.getCurrentItem())); } public void onDrawerOpened(View drawerView) { Log.d(TAG, "onDrawerOpened"); getSupportActionBar().setTitle("Makerthings"); loadSitemapList(OpenHABMainActivity.this.openHABBaseUrl); } }; mDrawerLayout.setDrawerListener(mDrawerToggle); mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START); if (mSitemapList == null) mSitemapList = new ArrayList<OpenHABSitemap>(); mDrawerItemList = new ArrayList<OpenHABDrawerItem>(); mDrawerAdapter = new OpenHABDrawerAdapter(this, R.layout.openhabdrawer_sitemap_item, mDrawerItemList); mDrawerAdapter.setOpenHABUsername(openHABUsername); mDrawerAdapter.setOpenHABPassword(openHABPassword); mDrawerList.setAdapter(mDrawerAdapter); mDrawerList.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, int item, long l) { Log.d(TAG, "Drawer selected item " + String.valueOf(item)); if (mDrawerItemList != null && mDrawerItemList.get(item) .getItemType() == OpenHABDrawerItem.DrawerItemType.SITEMAP_ITEM) { Log.d(TAG, "This is sitemap " + mDrawerItemList.get(item).getSiteMap().getLink()); mDrawerLayout.closeDrawers(); openSitemap(mDrawerItemList.get(item).getSiteMap().getHomepageLink()); } else { Log.d(TAG, "This is not sitemap"); if (mDrawerItemList.get(item).getTag() == DRAWER_NOTIFICATIONS) { Log.d(TAG, "Notifications selected"); mDrawerLayout.closeDrawers(); OpenHABMainActivity.this.openNotifications(); } else if (mDrawerItemList.get(item).getTag() == DRAWER_BINDINGS) { Log.d(TAG, "Bindings selected"); mDrawerLayout.closeDrawers(); OpenHABMainActivity.this.openBindings(); } else if (mDrawerItemList.get(item).getTag() == DRAWER_INBOX) { Log.d(TAG, "Inbox selected"); mDrawerLayout.closeDrawers(); OpenHABMainActivity.this.openDiscoveryInbox(); } } } }); loadDrawerItems(); getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setHomeButtonEnabled(true); if (getIntent() != null) { Log.d(TAG, "Intent != null"); if (getIntent().getAction() != null) { Log.d(TAG, "Intent action = " + getIntent().getAction()); if (getIntent().getAction().equals("android.nfc.action.NDEF_DISCOVERED")) { Log.d(TAG, "This is NFC action"); if (getIntent().getDataString() != null) { Log.d(TAG, "NFC data = " + getIntent().getDataString()); mNfcData = getIntent().getDataString(); } } else if (getIntent().getAction().equals("org.openhab.notification.selected")) { onNotificationSelected(getIntent()); } else if (getIntent().getAction().equals("android.intent.action.VIEW")) { Log.d(TAG, "This is URL Action"); String URL = getIntent().getDataString(); mNfcData = URL; } } } /** * If we are 4.4 we can use fullscreen mode and Daydream features */ supportsKitKat = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT; boolean fullScreen = mSettings.getBoolean("default_openhab_fullscreen", false); if (supportsKitKat && fullScreen) { registerReceiver(dreamReceiver, new IntentFilter("android.intent.action.DREAMING_STARTED")); registerReceiver(dreamReceiver, new IntentFilter("android.intent.action.DREAMING_STOPPED")); checkFullscreen(); } }
From source file:org.odk.collect.android.application.Collect.java
@Override public void onCreate() { singleton = this; // // set up logging defaults for apache http component stack // Log log;/*w w w . java2 s.c om*/ // log = LogFactory.getLog("org.opendatakit.httpclientandroidlib"); // log.enableError(true); // log.enableWarn(true); // log.enableInfo(true); // log.enableDebug(true); // log = LogFactory.getLog("org.opendatakit.httpclientandroidlib.wire"); // log.enableError(true); // log.enableWarn(false); // log.enableInfo(false); // log.enableDebug(false); PreferenceManager.setDefaultValues(this, R.xml.preferences, false); super.onCreate(); PropertyManager mgr = new PropertyManager(this); mActivityLogger = new ActivityLogger(mgr.getSingularProperty(PropertyManager.DEVICE_ID_PROPERTY)); }