List of usage examples for android.content SharedPreferences getBoolean
boolean getBoolean(String key, boolean defValue);
From source file:com.kircherelectronics.gyroscopeexplorer.activity.filter.Orientation.java
private boolean getPrefCalibratedGyroscopeEnabled() { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); return prefs.getBoolean(ConfigActivity.CALIBRATED_GYROSCOPE_ENABLED_KEY, true); }
From source file:com.kircherelectronics.gyroscopeexplorer.activity.filter.Orientation.java
private boolean getPrefMeanFilterSmoothingEnabled() { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); return prefs.getBoolean(ConfigActivity.MEAN_FILTER_SMOOTHING_ENABLED_KEY, false); }
From source file:com.quarterfull.newsAndroid.reader.HttpJsonRequest.java
private HttpJsonRequest(Context context) { client = new OkHttpClient(); // set location of the keystore MemorizingTrustManager.setKeyStoreFile("private", "sslkeys.bks"); // register MemorizingTrustManager for HTTPS try {/* w w w . ja v a2s .c o m*/ SSLContext sc = SSLContext.getInstance("TLS"); sc.init(null, MemorizingTrustManager.getInstanceList(context), new java.security.SecureRandom()); // enables TLSv1.1/1.2 for Jelly Bean Devices TLSSocketFactory tlsSocketFactory = new TLSSocketFactory(sc); client.setSslSocketFactory(tlsSocketFactory); } catch (KeyManagementException | NoSuchAlgorithmException e) { e.printStackTrace(); } client.setConnectTimeout(10000, TimeUnit.MILLISECONDS); client.setReadTimeout(120, TimeUnit.SECONDS); // disable hostname verification, when preference is set // (this still shows a certification dialog, which requires user interaction!) SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context); if (sp.getBoolean(SettingsActivity.CB_DISABLE_HOSTNAME_VERIFICATION_STRING, false)) client.setHostnameVerifier(new HostnameVerifier() { @Override public boolean verify(String hostname, SSLSession session) { return true; } }); imageClient = client.clone(); client.interceptors().add(new AuthorizationInterceptor()); setCredentials(sp.getString(SettingsActivity.EDT_USERNAME_STRING, null), sp.getString(SettingsActivity.EDT_PASSWORD_STRING, null), sp.getString(SettingsActivity.EDT_OWNCLOUDROOTPATH_STRING, null)); }
From source file:de.ub0r.android.websms.connector.smspilotru.ConnectorSMSpilotRu.java
/** * {@inheritDoc}/*ww w . j a v a 2s . c o m*/ */ @Override public ConnectorSpec updateSpec(final Context context, final ConnectorSpec connectorSpec) { final SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(context); if (p.getBoolean(Preferences.PREFS_ENABLED, false)) { if (p.getString(Preferences.PREFS_APIKEY, "").length() > 0) { connectorSpec.setReady(); } else { connectorSpec.setStatus(ConnectorSpec.STATUS_ENABLED); } } else { connectorSpec.setStatus(ConnectorSpec.STATUS_INACTIVE); } return connectorSpec; }
From source file:com.bodeme.easycloud.syncadapter.DavSyncAdapter.java
@Override public void onPerformSync(Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) {/*from w w w . j a v a 2 s .c om*/ Log.i(TAG, "Performing sync for authority " + authority); // set class loader for iCal4j ResourceLoader Thread.currentThread().setContextClassLoader(getContext().getClassLoader()); // create httpClient, if necessary httpClientLock.writeLock().lock(); if (httpClient == null) { Log.d(TAG, "Creating new DavHttpClient"); SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(getContext()); httpClient = DavHttpClient.create(settings.getBoolean(Constants.SETTING_DISABLE_COMPRESSION, false), settings.getBoolean(Constants.SETTING_NETWORK_LOGGING, false), !settings.getBoolean(Constants.IGNORE_SSL_ERRORS, false)); } // prevent httpClient shutdown until we're ready by holding a read lock // acquiring read lock before releasing write lock will downgrade the write lock to a read lock httpClientLock.readLock().lock(); httpClientLock.writeLock().unlock(); try { // get local <-> remote collection pairs Map<LocalCollection<?>, RemoteCollection<?>> syncCollections = getSyncPairs(account, provider); if (syncCollections == null) Log.i(TAG, "Nothing to synchronize"); else try { for (Map.Entry<LocalCollection<?>, RemoteCollection<?>> entry : syncCollections.entrySet()) new SyncManager(entry.getKey(), entry.getValue()) .synchronize(extras.containsKey(ContentResolver.SYNC_EXTRAS_MANUAL), syncResult); } catch (DavException ex) { syncResult.stats.numParseExceptions++; Log.e(TAG, "Invalid DAV response", ex); } catch (HttpException ex) { if (ex.getCode() == HttpStatus.SC_UNAUTHORIZED) { Log.e(TAG, "HTTP Unauthorized " + ex.getCode(), ex); syncResult.stats.numAuthExceptions++; } else if (ex.isClientError()) { Log.e(TAG, "Hard HTTP error " + ex.getCode(), ex); syncResult.stats.numParseExceptions++; } else { Log.w(TAG, "Soft HTTP error " + ex.getCode() + " (Android will try again later)", ex); syncResult.stats.numIoExceptions++; } } catch (LocalStorageException ex) { syncResult.databaseError = true; Log.e(TAG, "Local storage (content provider) exception", ex); } catch (IOException ex) { syncResult.stats.numIoExceptions++; Log.e(TAG, "I/O error (Android will try again later)", ex); } } finally { // allow httpClient shutdown httpClientLock.readLock().unlock(); } Log.i(TAG, "Sync complete for " + authority); }
From source file:kkook.team.projectswitch.gcm.TestActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_test_gcm); mRegistrationProgressBar = (ProgressBar) findViewById(R.id.registrationProgressBar); mRegistrationBroadcastReceiver = new BroadcastReceiver() { @Override/*w w w. j ava 2 s. c om*/ public void onReceive(Context context, Intent intent) { mRegistrationProgressBar.setVisibility(ProgressBar.GONE); SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); boolean sentToken = sharedPreferences.getBoolean(QuickstartPreferences.SENT_TOKEN_TO_SERVER, false); if (sentToken) { mInformationTextView.setText( "Token retrieved and sent to server! You can now use gcmsender to send downstream messages to this app."); ((Button) findViewById(R.id.btnSend)).setVisibility(View.VISIBLE); ((EditText) findViewById(R.id.etMessage)).setVisibility(View.VISIBLE); } else { mInformationTextView.setText( "An error occurred while either fetching the InstanceID token, sending the fetched token to the server or subscribing to the PubSub topic. Please try running the sample again."); } } }; mInformationTextView = (TextView) findViewById(R.id.informationTextView); if (checkPlayServices()) { // Start IntentService to register this application with GCM. Intent intent = new Intent(this, RegistrationIntentService.class); startService(intent); ((Button) findViewById(R.id.btnSend)).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { new Thread(runSender).start(); } }); } }
From source file:dk.moerks.ratebeermobile.Rate.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.rate);//from ww w .jav a2 s. co m Bundle extras = getIntent().getExtras(); if (extras != null) { beername = extras.getString("BEERNAME"); beerid = extras.getString("BEERID"); } rateCharleftText = (TextView) findViewById(R.id.rate_label_charleft); rateCharleftText.setText(getText(R.string.rate_charleft) + " 75"); EditText rateComment = (EditText) findViewById(R.id.rate_value_comments); rateComment.addTextChangedListener(new TextWatcher() { public void afterTextChanged(Editable s) { } public void beforeTextChanged(CharSequence s, int start, int count, int after) { } public void onTextChanged(CharSequence s, int start, int before, int count) { int charNumber = s.length(); int resultNumber = 75 - charNumber; if (resultNumber > 0) { rateCharleftText.setText(getText(R.string.rate_charleft) + " " + resultNumber); } else { rateCharleftText.setText(""); } } }); TextView beernameText = (TextView) findViewById(R.id.rate_label_beername); beernameText.setText(beername); Button rateButton = (Button) findViewById(R.id.rate_button); rateButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { EditText comment = (EditText) findViewById(R.id.rate_value_comments); final String commentString = comment.getText().toString(); if (commentString.length() > 74) { Spinner aromaText = (Spinner) findViewById(R.id.rate_value_aroma); Spinner appearanceText = (Spinner) findViewById(R.id.rate_value_appearance); Spinner flavorText = (Spinner) findViewById(R.id.rate_value_flavor); Spinner palateText = (Spinner) findViewById(R.id.rate_value_palate); Spinner overallText = (Spinner) findViewById(R.id.rate_value_overall); final String aromaString = (String) aromaText.getSelectedItem(); final String appearanceString = (String) appearanceText.getSelectedItem(); final String flavorString = (String) flavorText.getSelectedItem(); final String palateString = (String) palateText.getSelectedItem(); final String overallString = (String) overallText.getSelectedItem(); String totalScore = calculateTotalScore(aromaString, appearanceString, flavorString, palateString, overallString); List<NameValuePair> parameters = new ArrayList<NameValuePair>(); parameters.add(new BasicNameValuePair("BeerID", beerid)); parameters.add(new BasicNameValuePair("aroma", aromaString)); parameters.add(new BasicNameValuePair("appearance", appearanceString)); parameters.add(new BasicNameValuePair("flavor", flavorString)); parameters.add(new BasicNameValuePair("palate", palateString)); parameters.add(new BasicNameValuePair("overall", overallString)); parameters.add(new BasicNameValuePair("totalscore", totalScore)); parameters.add(new BasicNameValuePair("Comments", commentString)); new SaveRatingTask(Rate.this).execute(parameters.toArray(new NameValuePair[] {})); SharedPreferences prefs = getSharedPreferences(Settings.PREFERENCETAG, 0); if (prefs.getBoolean("rb_twitter_ratings", false)) { new PostTwitterStatusTask(Rate.this).execute(buildTwitterMessage(totalScore)); } finish(); } else { Toast.makeText(Rate.this, R.string.toast_minimum_length, Toast.LENGTH_LONG).show(); } } private String buildTwitterMessage(String score) { return getString(R.string.twitter_rating_message, beername, score, getUserId()); } private String calculateTotalScore(String aromaString, String appearanceString, String flavorString, String palateString, String overallString) { int aroma = Integer.parseInt(aromaString); int appearance = Integer.parseInt(appearanceString); int flavor = Integer.parseInt(flavorString); int palate = Integer.parseInt(palateString); int overall = Integer.parseInt(overallString); int total = (aroma + appearance + flavor + palate + overall); float totalscore = ((float) total) / 10; String result = "" + totalscore; return result; } }); }
From source file:de.steveliedtke.gcm.example.gcm.GCMIntentService.java
@Override protected void onMessage(final Context context, final Intent intent) { Log.w("GCM-Message", "Received message"); final String payload = intent.getStringExtra("payload"); Log.d("GCM-Message", "dmControl: payload = " + payload); try {//from ww w. j a v a 2s .co m SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context); Log.i("GCM-Message", "PAYLOAD: " + payload); if (settings.getBoolean("notification_preference", true)) { this.displayNotification(context, payload, settings.getBoolean("vibration_preference", true), settings.getBoolean("permanent_notification_preference", false)); } } catch (JSONException e) { Log.e("GCM-Message", "JSON-Exception occured!"); } }
From source file:at.bitfire.davdroid.mirakel.syncadapter.DavSyncAdapter.java
@Override public void onPerformSync(Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) {/*www . j av a 2 s.co m*/ Log.i(TAG, "Performing sync for authority " + authority); // set class loader for iCal4j ResourceLoader Thread.currentThread().setContextClassLoader(getContext().getClassLoader()); // create httpClient, if necessary httpClientLock.writeLock().lock(); if (httpClient == null) { Log.d(TAG, "Creating new DavHttpClient"); SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(getContext()); httpClient = DavHttpClient.create(settings.getBoolean(Constants.SETTING_DISABLE_COMPRESSION, false), settings.getBoolean(Constants.SETTING_NETWORK_LOGGING, false)); } // prevent httpClient shutdown until we're ready by holding a read lock // acquiring read lock before releasing write lock will downgrade the write lock to a read lock httpClientLock.readLock().lock(); httpClientLock.writeLock().unlock(); // TODO use VCard 4.0 if possible AccountSettings accountSettings = new AccountSettings(getContext(), account); Log.d(TAG, "Server supports VCard version " + accountSettings.getAddressBookVCardVersion()); try { // get local <-> remote collection pairs Map<LocalCollection<?>, RemoteCollection<?>> syncCollections = getSyncPairs(account, provider); if (syncCollections == null) Log.i(TAG, "Nothing to synchronize"); else try { for (Map.Entry<LocalCollection<?>, RemoteCollection<?>> entry : syncCollections.entrySet()) new SyncManager(entry.getKey(), entry.getValue()) .synchronize(extras.containsKey(ContentResolver.SYNC_EXTRAS_MANUAL), syncResult); } catch (DavException ex) { syncResult.stats.numParseExceptions++; Log.e(TAG, "Invalid DAV response", ex); } catch (HttpException ex) { if (ex.getCode() == HttpStatus.SC_UNAUTHORIZED) { Log.e(TAG, "HTTP Unauthorized " + ex.getCode(), ex); syncResult.stats.numAuthExceptions++; } else if (ex.isClientError()) { Log.e(TAG, "Hard HTTP error " + ex.getCode(), ex); syncResult.stats.numParseExceptions++; } else { Log.w(TAG, "Soft HTTP error " + ex.getCode() + " (Android will try again later)", ex); syncResult.stats.numIoExceptions++; } } catch (LocalStorageException ex) { syncResult.databaseError = true; Log.e(TAG, "Local storage (content provider) exception", ex); } catch (IOException ex) { syncResult.stats.numIoExceptions++; Log.e(TAG, "I/O error (Android will try again later)", ex); } } finally { // allow httpClient shutdown httpClientLock.readLock().unlock(); } Log.i(TAG, "Sync complete for " + authority); }
From source file:com.google.android.apps.chrometophone.GCMIntentService.java
@Override public void onMessage(Context context, Intent intent) { Bundle extras = intent.getExtras();/*from w w w .j av a 2 s . co m*/ if (extras != null) { String url = (String) extras.get("url"); String title = (String) extras.get("title"); String sel = (String) extras.get("sel"); String debug = (String) extras.get("debug"); if (debug != null) { // server-controlled debug - the server wants to know // we received the message, and when. This is not user-controllable, // we don't want extra traffic on the server or phone. Server may // turn this on for a small percentage of requests or for users // who report issues. DefaultHttpClient client = new DefaultHttpClient(); HttpGet get = new HttpGet(AppEngineClient.BASE_URL + "/debug?id=" + extras.get("collapse_key")); // No auth - the purpose is only to generate a log/confirm delivery // (to avoid overhead of getting the token) try { client.execute(get); } catch (ClientProtocolException e) { // ignore } catch (IOException e) { // ignore } } if (title != null && url != null && url.startsWith("http")) { SharedPreferences settings = Prefs.get(context); Intent launchIntent = LauncherUtils.getLaunchIntent(context, title, url, sel); // Notify and optionally start activity if (settings.getBoolean("launchBrowserOrMaps", true) && launchIntent != null) { LauncherUtils.playNotificationSound(context); LauncherUtils.sendIntentToApp(context, launchIntent); } else { LauncherUtils.generateNotification(context, url, title, launchIntent); } // Record history (for link/maps only) if (launchIntent != null && launchIntent.getAction().equals(Intent.ACTION_VIEW)) { HistoryDatabase.get(context).insertHistory(title, url); } } } }