List of usage examples for android.preference PreferenceManager setDefaultValues
public static void setDefaultValues(Context context, @XmlRes int resId, boolean readAgain)
From source file:com.google.corp.productivity.specialprojects.android.samples.fft.AnalyzeActivity.java
@Override public void onCreate(Bundle savedInstanceState) { // Debug.startMethodTracing("calc"); super.onCreate(savedInstanceState); setContentView(R.layout.main);//from w w w . j av a 2 s.c o m DPRatio = getResources().getDisplayMetrics().density; final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024); Log.i(TAG, " max mem = " + maxMemory + "k"); // set and get preferences in PreferenceActivity PreferenceManager.setDefaultValues(this, R.xml.preferences, false); // Set variable according to the preferences updatePreferenceSaved(); textRMSChar = new char[getString(R.string.textview_RMS_text).length()]; textCurChar = new char[getString(R.string.textview_cur_text).length()]; textRecChar = new char[getString(R.string.textview_rec_text).length()]; textPeakChar = new char[getString(R.string.textview_peak_text).length()]; graphView = (AnalyzeView) findViewById(R.id.plot); // travel Views, and attach ClickListener to the views that contain android:tag="select" visit((ViewGroup) graphView.getRootView(), new Visit() { @Override public void exec(View view) { view.setOnLongClickListener(AnalyzeActivity.this); view.setOnClickListener(AnalyzeActivity.this); ((TextView) view).setFreezesText(true); } }, "select"); Resources res = getResources(); getAudioSourceNameFromIdPrepare(res); listItemTextSize = res.getDimension(R.dimen.button_text_fontsize); listItemTitleTextSize = res.getDimension(R.dimen.button_text_small_fontsize); /// initialize pop up window items list // http://www.codeofaninja.com/2013/04/show-listview-as-drop-down-android.html popupMenuSampleRate = popupMenuCreate(validateAudioRates(res.getStringArray(R.array.sample_rates)), R.id.button_sample_rate); popupMenuFFTLen = popupMenuCreate(res.getStringArray(R.array.fft_len), R.id.button_fftlen); popupMenuAverage = popupMenuCreate(res.getStringArray(R.array.fft_ave_num), R.id.button_average); mDetector = new GestureDetectorCompat(this, new AnalyzerGestureListener()); setTextViewFontSize(); }
From source file:com.javielinux.utils.LinksUtils.java
static public String shortURL(Context context, String link) { link = largeLink(link);// ww w. j a v a 2s. com PreferenceManager.setDefaultValues(context, R.xml.preferences, false); SharedPreferences preference = PreferenceManager.getDefaultSharedPreferences(context); int s = (Integer.parseInt(preference.getString("prf_service_shorter", "1"))); if (s == 1) { // bit.ly String user = "tweettopics"; String key = "R_ba0652e93e7c9c527c016447d2e29091"; if (!PreferenceUtils.getUsernameBitly(context).equals("") && !PreferenceUtils.getKeyBitly(context).equals("")) { user = PreferenceUtils.getUsernameBitly(context); key = PreferenceUtils.getKeyBitly(context); } String url = "http://api.bit.ly/v3/shorten?login=" + user + "&apiKey=" + key + "&format=json&longUrl=" + URLEncoder.encode(link); HttpGet request = new HttpGet(url); HttpClient client = new DefaultHttpClient(); HttpResponse httpResponse; try { httpResponse = client.execute(request); String xml = EntityUtils.toString(httpResponse.getEntity()); JSONObject jsonObject = new JSONObject(xml); if (jsonObject.getString("status_txt").equals("OK")) { return jsonObject.getJSONObject("data").getString("url"); } } catch (Exception e) { e.printStackTrace(); } } else { // karmacracy // http://kcy.me/api/?u=javielinux&key=nyk1tjr20x&format=json&url=http://www.javielinux.com String user = PreferenceUtils.getUsernameKarmacracy(context); String key = PreferenceUtils.getKeyKarmacracy(context); String url = "http://kcy.me/api/?u=" + user + "&key=" + key + "&format=json&url=" + URLEncoder.encode(link); HttpGet request = new HttpGet(url); HttpClient client = new DefaultHttpClient(); HttpResponse httpResponse; try { httpResponse = client.execute(request); String xml = EntityUtils.toString(httpResponse.getEntity()); JSONObject jsonObject = new JSONObject(xml); if (jsonObject.getString("status_txt").equals("OK")) { return jsonObject.getJSONObject("data").getString("url"); } } catch (Exception e) { e.printStackTrace(); } } return null; }
From source file:com.shadowmaps.example.GpsTestActivity.java
/** Called when the activity is first created. */ @Override//from w ww .ja v a 2s . c o m public void onCreate(Bundle savedInstanceState) { setTheme(com.actionbarsherlock.R.style.Theme_Sherlock); super.onCreate(savedInstanceState); sInstance = this; // Set the default values from the XML file if this is the first // execution of the app PreferenceManager.setDefaultValues(this, R.xml.preferences, false); recording = false; mService = (LocationManager) getSystemService(Context.LOCATION_SERVICE); mProvider = mService.getProvider(LocationManager.GPS_PROVIDER); if (mProvider == null) { Log.e(TAG, "Unable to get GPS_PROVIDER"); Toast.makeText(this, getString(R.string.gps_not_supported), Toast.LENGTH_SHORT).show(); finish(); return; } mService.addGpsStatusListener(this); mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE); // Request use of spinner for showing indeterminate progress, to show // the user something is going on during long-running operations requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); // If we have a large screen, show all the fragments in one layout if (GpsTestUtil.isLargeScreen(this)) { setContentView(R.layout.activity_main_large_screen); mIsLargeScreen = true; } else { setContentView(R.layout.activity_main); } initActionBar(savedInstanceState); SharedPreferences settings = Application.getPrefs(); double tempMinTime = Double.valueOf(settings.getString(getString(R.string.pref_key_gps_min_time), getString(R.string.pref_gps_min_time_default_sec))); minTime = (long) (tempMinTime * SECONDS_TO_MILLISECONDS); minDistance = Float.valueOf(settings.getString(getString(R.string.pref_key_gps_min_distance), getString(R.string.pref_gps_min_distance_default_meters))); if (settings.getBoolean(getString(R.string.pref_key_auto_start_gps), true)) { gpsStart(); } if (!isShadowServiceRunning(ShadowMapsService.class)) { final String STARTUP_EXTRA = "com.shadowmaps.example.start"; Intent i = new Intent(this, ShadowMapsService.class); i.putExtra(STARTUP_EXTRA, true); startService(i); Log.v("SERVICE", "Starting ShadowService in activity onCreate"); } }
From source file:com.cs528.style.style.weather.WeatherActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { // Initialize the associated SharedPreferences file with default values PreferenceManager.setDefaultValues(this, R.xml.prefs, false); darkTheme = false;/*from w w w. j a v a2 s . 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); getLayoutInflater().inflate(R.layout.activity_scrolling, frameLayout); progressDialog = new ProgressDialog(WeatherActivity.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); // todayIcon = (TextView) findViewById(R.id.todayIcon); topIcon = (TextView) findViewById(R.id.topIcon); bottomIcon = (TextView) findViewById(R.id.bottomIcon); hatIcon = (TextView) findViewById(R.id.hatIcon); shoeIcon = (TextView) findViewById(R.id.shoeIcon); weatherFont = Typeface.createFromAsset(this.getAssets(), "fonts/weather.ttf"); clothFont = Typeface.createFromAsset(this.getAssets(), "fonts/cloth.ttf"); // todayIcon.setTypeface(weatherFont); topIcon.setTypeface(clothFont); bottomIcon.setTypeface(clothFont); shoeIcon.setTypeface(clothFont); hatIcon.setTypeface(clothFont); topIcon.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { scheduleAndWeatherFilter(); Intent intent = new Intent(WeatherActivity.this, GalleryActivity.class); intent.putExtra("clothes", result.toArray()); startActivity(intent); } }); // Initialize viewPagerg viewPager = (ViewPager) findViewById(R.id.viewPager); tabLayout = (TabLayout) findViewById(R.id.tabs); destroyed = false; initMappings(); // Preload data from cache preloadWeather(); // Set autoupdater AlarmReceiver.setRecurringAlarm(this); }
From source file:com.concavenp.artistrymuse.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // If the application has not run before then initialize the preference settings with default values if (savedInstanceState == null) { // These are the "general" preferences (its all this app has) PreferenceManager.setDefaultValues(this, R.xml.pref_general, false); }// ww w . j a va2s . c o m // Force the scroll view to fill the area, dunno why this is not the default. NestedScrollView scrollView = findViewById(R.id.nest_scrollview); scrollView.setFillViewport(true); // Get the ViewPager and set it's PagerAdapter so that it can display items ViewPager viewPager = findViewById(R.id.viewpager); mFragmentAdapter = new ArtistryFragmentPagerAdapter(this, getSupportFragmentManager()); viewPager.setAdapter(mFragmentAdapter); viewPager.setOffscreenPageLimit(mFragmentAdapter.getCount()); viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { // Do nothing } @Override public void onPageSelected(int position) { // Save off the tab position tabPosition = position; // Perform animations (if needed) animateFab(position); // Close the keyboard if it is open View view = getCurrentFocus(); if (view != null) { InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(view.getWindowToken(), 0); } } @Override public void onPageScrollStateChanged(int state) { // Do nothing } }); // Give the TabLayout the ViewPager tabLayout = findViewById(R.id.tabs); tabLayout.setupWithViewPager(viewPager); tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() { @Override public void onTabSelected(TabLayout.Tab tab) { animateFab(tab.getPosition()); } @Override public void onTabUnselected(TabLayout.Tab tab) { // Do nothing } @Override public void onTabReselected(TabLayout.Tab tab) { // Do nothing } }); // Setup the support for creating a menu (ActionBar functionality) Toolbar toolbar = findViewById(R.id.toolbar); setSupportActionBar(toolbar); // Setup the FAB for creating a new user project (only visible in the gallery tab) fabCreateProject = findViewById(R.id.fabCreateProject); fabCreateProject.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { // Notify 'this' of the Create New Project selection onInteractionSelection(null, null, StorageDataType.PROJECTS, UserInteractionType.EDIT); } }); // Logon button Button loginButton = findViewById(R.id.login_button); loginButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { onLoginInteraction(); } }); // Default will be hidden fabCreateProject.hide(); // Save off the flipper for use in deciding which view to show mFlipper = findViewById(R.id.activity_main_ViewFlipper); // Set the flip view accordingly checkLoginFlipState(); // Start the sign-in activity if nobody is logged in yet if (getUid().isEmpty()) { onLoginInteraction(); } }
From source file:com.inmobi.ultrapush.AnalyzeActivity.java
@Override public void onCreate(Bundle savedInstanceState) { // Debug.startMethodTracing("calc"); super.onCreate(savedInstanceState); setContentView(R.layout.main);//w w w . java 2 s .c o m DPRatio = getResources().getDisplayMetrics().density; final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024); Log.i(TAG, " max mem = " + maxMemory + "k"); // set and get preferences in PreferenceActivity PreferenceManager.setDefaultValues(this, R.xml.preferences, false); // Set variable according to the preferences updatePreferenceSaved(); textRMSChar = new char[getString(R.string.textview_RMS_text).length()]; textCurChar = new char[getString(R.string.textview_cur_text).length()]; textRecChar = new char[getString(R.string.textview_rec_text).length()]; textPeakChar = new char[getString(R.string.textview_peak_text).length()]; graphView = (AnalyzeView) findViewById(R.id.plot); // travel Views, and attach ClickListener to the views that contain android:tag="select" visit((ViewGroup) graphView.getRootView(), new Visit() { @Override public void exec(View view) { view.setOnLongClickListener(AnalyzeActivity.this); view.setOnClickListener(AnalyzeActivity.this); ((TextView) view).setFreezesText(true); } }, "select"); Resources res = getResources(); getAudioSourceNameFromIdPrepare(res); listItemTextSize = res.getDimension(R.dimen.button_text_fontsize); listItemTitleTextSize = res.getDimension(R.dimen.button_text_small_fontsize); /// initialize pop up window items list // http://www.codeofaninja.com/2013/04/show-listview-as-drop-down-android.html popupMenuSampleRate = popupMenuCreate(validateAudioRates(res.getStringArray(R.array.sample_rates)), R.id.button_sample_rate); popupMenuFFTLen = popupMenuCreate(res.getStringArray(R.array.fft_len), R.id.button_fftlen); popupMenuAverage = popupMenuCreate(res.getStringArray(R.array.fft_ave_num), R.id.button_average); mDetector = new GestureDetectorCompat(this, new AnalyzerGestureListener()); setTextViewFontSize(); }
From source file:com.mantz_it.rfanalyzer.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); this.savedInstanceState = savedInstanceState; // Set default Settings on first run: PreferenceManager.setDefaultValues(this, R.xml.preferences, false); // Get reference to the shared preferences: preferences = PreferenceManager.getDefaultSharedPreferences(this); // Overwrite defaults for file paths in the preferences: String extStorage = Environment.getExternalStorageDirectory().getAbsolutePath(); // get the path to the ext. storage // File Source file: String defaultFile = getString(R.string.pref_filesource_file_default); if (preferences.getString(getString(R.string.pref_filesource_file), "").equals(defaultFile)) preferences.edit().putString(getString(R.string.pref_filesource_file), extStorage + "/" + defaultFile) .apply();//w w w . ja v a 2s .c o m // Log file: defaultFile = getString(R.string.pref_logfile_default); if (preferences.getString(getString(R.string.pref_logfile), "").equals(defaultFile)) preferences.edit().putString(getString(R.string.pref_logfile), extStorage + "/" + defaultFile).apply(); // Start logging if enabled: if (preferences.getBoolean(getString(R.string.pref_logging), false)) { if (ContextCompat.checkSelfPermission(this, "android.permission.WRITE_EXTERNAL_STORAGE") == PackageManager.PERMISSION_GRANTED) { try { File logfile = new File(preferences.getString(getString(R.string.pref_logfile), "")); logfile.getParentFile().mkdir(); // Create folder logcat = Runtime.getRuntime().exec("logcat -f " + logfile); Log.i("MainActivity", "onCreate: started logcat (" + logcat.toString() + ") to " + logfile); } catch (Exception e) { Log.e("MainActivity", "onCreate: Failed to start logging!"); } } else { preferences.edit().putBoolean(getString(R.string.pref_logging), false).apply(); Log.i(LOGTAG, "onCreate: deactivate logging because of missing storage permission."); } } // Get version name: try { versionName = getPackageManager().getPackageInfo(getPackageName(), 0).versionName; Log.i(LOGTAG, "This is RF Analyzer " + versionName + " by Dennis Mantz."); } catch (PackageManager.NameNotFoundException e) { Log.e(LOGTAG, "onCreate: Cannot read version name: " + e.getMessage()); } // Get references to the GUI components: fl_analyzerFrame = (FrameLayout) findViewById(R.id.fl_analyzerFrame); // Create a analyzer surface: analyzerSurface = new AnalyzerSurface(this, this); analyzerSurface.setVerticalScrollEnabled(preferences.getBoolean(getString(R.string.pref_scrollDB), true)); analyzerSurface.setVerticalZoomEnabled(preferences.getBoolean(getString(R.string.pref_zoomDB), true)); analyzerSurface.setDecoupledAxis(preferences.getBoolean(getString(R.string.pref_decoupledAxis), false)); analyzerSurface.setDisplayRelativeFrequencies( preferences.getBoolean(getString(R.string.pref_relativeFrequencies), false)); analyzerSurface.setWaterfallColorMapType( Integer.valueOf(preferences.getString(getString(R.string.pref_colorMapType), "4"))); analyzerSurface.setFftDrawingType( Integer.valueOf(preferences.getString(getString(R.string.pref_fftDrawingType), "2"))); analyzerSurface.setFftRatio( Float.valueOf(preferences.getString(getString(R.string.pref_spectrumWaterfallRatio), "0.5"))); analyzerSurface.setFontSize(Integer.valueOf(preferences.getString(getString(R.string.pref_fontSize), "2"))); analyzerSurface.setShowDebugInformation( preferences.getBoolean(getString(R.string.pref_showDebugInformation), false)); // Put the analyzer surface in the analyzer frame of the layout: fl_analyzerFrame.addView(analyzerSurface); // Restore / Initialize the running state and the demodulator mode: if (savedInstanceState != null) { running = savedInstanceState.getBoolean(getString(R.string.save_state_running)); demodulationMode = savedInstanceState.getInt(getString(R.string.save_state_demodulatorMode)); /* BUGFIX / WORKAROUND: * The RTL2832U driver will not allow to close the socket and immediately start the driver * again to reconnect after an orientation change / app kill + restart. * It will report back in onActivityResult() with a -1 (not specified). * * Work-around: * 1) We won't restart the Analyzer if the current source is set to a local RTL-SDR instance: * 2) Delay the restart of the Analyzer after the driver was shut down correctly... */ if (running && Integer.valueOf( preferences.getString(getString(R.string.pref_sourceType), "1")) == RTLSDR_SOURCE && !preferences.getBoolean(getString(R.string.pref_rtlsdr_externalServer), false)) { // 1) don't start Analyzer immediately running = false; // Just inform the user about what is going on (why does this take so long? ...) Toast.makeText(MainActivity.this, "Stopping and restarting RTL2832U driver...", Toast.LENGTH_SHORT) .show(); // 2) Delayed start of the Analyzer: Thread timer = new Thread() { @Override public void run() { try { Thread.sleep(1500); startAnalyzer(); } catch (InterruptedException e) { Log.e(LOGTAG, "onCreate: (timer thread): Interrupted while sleeping."); } } }; timer.start(); } } else { // Set running to true if autostart is enabled (this will start the analyzer in onStart() ) running = preferences.getBoolean((getString(R.string.pref_autostart)), false); } // Set the hardware volume keys to work on the music audio stream: setVolumeControlStream(AudioManager.STREAM_MUSIC); }
From source file:ir.actfun.toofan.activities.NowWeatherPage.java
@Override protected void onCreate(Bundle savedInstanceState) { // Initialize the associated SharedPreferences file with default values PreferenceManager.setDefaultValues(this, R.xml.prefs, false); darkTheme = false;//from ww w.ja va 2 s .c o m SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); if (prefs.getString("theme", "fresh").equals("dark")) { setTheme(R.style.AppTheme_NoActionBar_Dark); darkTheme = true; } else if (prefs.getString("theme", "fresh").equals("transparent")) { setTheme(R.style.AppTheme_NoActionBar_transparent); } // Initiate activity super.onCreate(savedInstanceState); setContentView(R.layout.activity_scrolling); appView = findViewById(R.id.viewApp); progressDialog = new ProgressDialog(NowWeatherPage.this); // Load toolbar Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); if (darkTheme) { toolbar.setPopupTheme(R.style.AppTheme_PopupOverlay_Dark); } // Initialize textboxes setContentView(R.layout.nowweather_layout); weatherFont = Typeface.createFromAsset(getApplicationContext().getAssets(), "fonts/weathericons-regular-webfont.ttf"); YoYo.with(Techniques.ZoomIn).duration(2000).playOn(findViewById(R.id.weather_icon)); YoYo.with(Techniques.ZoomIn).duration(2000).playOn(findViewById(R.id.city_field)); YoYo.with(Techniques.ZoomIn).duration(2000).playOn(findViewById(R.id.current_temperature_field)); YoYo.with(Techniques.ZoomIn).duration(2200).playOn(findViewById(R.id.details_field)); YoYo.with(Techniques.ZoomIn).duration(2400).playOn(findViewById(R.id.humidity_field)); YoYo.with(Techniques.ZoomIn).duration(2800).playOn(findViewById(R.id.pressure_field)); YoYo.with(Techniques.ZoomIn).duration(2600).playOn(findViewById(R.id.wind_field)); YoYo.with(Techniques.ZoomIn).duration(3000).playOn(findViewById(R.id.updated_field)); quote_writer = (TextView) findViewById(R.id.quote_writer); quote_text2 = (TextView) findViewById(R.id.quote_text2); quote_text = (TextView) findViewById(R.id.quote_text); cityField = (TextView) findViewById(R.id.city_field); lastUpdate = (TextView) findViewById(R.id.updated_field); todayDescription = (TextView) findViewById(R.id.details_field); todayTemperature = (TextView) findViewById(R.id.current_temperature_field); todayHumidity = (TextView) findViewById(R.id.humidity_field); todayPressure = (TextView) findViewById(R.id.pressure_field); todayWind = (TextView) findViewById(R.id.wind_field); todayIcon = (TextView) findViewById(R.id.weather_icon); todayIcon.setTypeface(weatherFont); // Preload data from cache preloadWeather(); updateLastUpdateTime(); // Set autoupdater AlarmReceiver.setRecurringAlarm(this); //Getting the quote from Ganjoor QuoteGenerator.placeIdTask asyncTask = new QuoteGenerator.placeIdTask(new QuoteGenerator.AsyncResponse() { public void processFinish(String m1, String m2, String author) { quote_text.setText(m1); quote_text2.setText(m2); quote_writer.setText(author); } }); asyncTask.execute("25.180000", "89.530000"); // asyncTask.execute("Latitude", "Longitude") YoYo.with(Techniques.FadeIn).duration(10000).playOn(findViewById(R.id.quote_text)); YoYo.with(Techniques.FadeIn).duration(10000).playOn(findViewById(R.id.quote_text2)); YoYo.with(Techniques.FadeOut).duration(5000).playOn(findViewById(R.id.quote_writer)); //End of OnCreate Method. }
From source file:com.radicaldynamic.groupinform.application.Collect.java
@Override public void onCreate() { singleton = this; PreferenceManager.setDefaultValues(this, R.xml.preferences, false); super.onCreate(); }