List of usage examples for android.content SharedPreferences getBoolean
boolean getBoolean(String key, boolean defValue);
From source file:fr.cph.chicago.fragment.BikeFragment.java
@Override public final boolean onOptionsItemSelected(final MenuItem item) { switch (item.getItemId()) { case R.id.action_refresh: SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(mActivity); boolean loadBike = sharedPref.getBoolean("divvy_bike", true); if (loadBike) { MenuItem menuItem = item; menuItem.setActionView(R.layout.progressbar); menuItem.expandActionView(); new DivvyAsyncTask().execute(); Bundle bundle = mActivity.getIntent().getExtras(); List<BikeStation> bikeStations = bundle.getParcelableArrayList("bikeStations"); if (bikeStations == null) { mActivity.startRefreshAnimation(); mActivity.new LoadData().execute(); }//from w ww . j a v a 2s.co m } Util.trackAction(mActivity, R.string.analytics_category_ui, R.string.analytics_action_press, R.string.analytics_action_refresh_bike, 0); return false; } return super.onOptionsItemSelected(item); }
From source file:de.j4velin.wifiAutoOff.Locations.java
@Override protected void onResume() { super.onResume(); SharedPreferences prefs = getSharedPreferences(getPackageName() + "_preferences", Context.MODE_MULTI_PROCESS); findViewById(R.id.timeoutwarning).setVisibility(prefs.getBoolean("off_no_network", true) && prefs.getInt("no_network_timeout", Receiver.TIMEOUT_NO_NETWORK) < 5 ? View.VISIBLE : View.GONE); }
From source file:fr.cph.chicago.fragment.BikeFragment.java
@Override public final View onCreateView(final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState) { mRootView = inflater.inflate(R.layout.fragment_bike, container, false); if (!mActivity.isFinishing()) { mLoadingLayout = (RelativeLayout) mRootView.findViewById(R.id.loading_relativeLayout); mDesactivatedLayout = (RelativeLayout) mRootView.findViewById(R.id.desactivated_layout); mListView = (ListView) mRootView.findViewById(R.id.bike_list); mFilterView = (TextView) mRootView.findViewById(R.id.bike_filter); if (Util.isNetworkAvailable()) { SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(mActivity); boolean loadBike = sharedPref.getBoolean("divvy_bike", true); if (loadBike) { if (mBikeStations == null || mBikeStations.size() != 0) { loadList();/*w ww.j a v a 2 s . c om*/ } else { mLoadingLayout.setVisibility(RelativeLayout.VISIBLE); mListView.setVisibility(ListView.INVISIBLE); mFilterView.setVisibility(TextView.INVISIBLE); new WaitForRefreshData().execute(); } } else { mDesactivatedLayout.setVisibility(RelativeLayout.VISIBLE); mFilterView.setVisibility(TextView.INVISIBLE); } } else { Toast.makeText(ChicagoTracker.getAppContext(), "No network connection detected!", Toast.LENGTH_SHORT).show(); } } return mRootView; }
From source file:com.jefftharris.passwdsafe.sync.dropbox.DropboxCoreProvider.java
/** Migrate from previous Dropbox */ private void doMigration() { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); boolean migrate = prefs.getBoolean(PREF_MIGRATE_TOKEN, true); if (migrate) { PasswdSafeUtil.dbginfo(TAG, "doMigration"); SharedPreferences.Editor editor = prefs.edit(); try {//from w ww . jav a 2s . co m Context appctx = getContext().getApplicationContext(); String accts = appctx.getSharedPreferences("dropbox-credentials", Context.MODE_PRIVATE) .getString("accounts", null); if (accts != null) { JSONArray jsonAccounts = new JSONArray(accts); if (jsonAccounts.length() > 0) { JSONObject acct = jsonAccounts.getJSONObject(0); String userId = acct.getString("userId"); PasswdSafeUtil.dbginfo(TAG, "migrate user: %s", userId); editor.putString(PREF_USER_ID, userId); } } } catch (Exception e) { Log.e(TAG, "Error migrating token", e); } editor.putBoolean(PREF_MIGRATE_TOKEN, false); editor.apply(); SyncDb syncDb = SyncDb.acquire(); try { SQLiteDatabase db = syncDb.getDb(); for (DbProvider provider : SyncDb.getProviders(db)) { if (provider.itsType != ProviderType.DROPBOX) { continue; } String dirpfx = "/Apps/PasswdSafe Sync"; for (DbFile dbfile : SyncDb.getFiles(provider.itsId, db)) { SyncDb.updateRemoteFile(dbfile.itsId, (dirpfx + dbfile.itsRemoteId).toLowerCase(), dbfile.itsRemoteTitle, dirpfx + dbfile.itsRemoteFolder, dbfile.itsRemoteModDate, dbfile.itsRemoteHash, db); } } } catch (SQLException e) { Log.e(TAG, "Error migrating files", e); } finally { syncDb.release(); } NotifUtils.showNotif(NotifUtils.Type.DROPBOX_MIGRATED, getContext()); } }
From source file:com.github.naofum.gogakudroid.AsyncDownload.java
@Override protected String doInBackground(String[] koza) { File fileTmp = new File("tmp"); try {//ww w. j a v a 2 s. co m fc = new FfmpegController(owner, fileTmp); } catch (IOException e) { e.printStackTrace(); return owner.getString(R.string.init_error); } SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(owner); String type = sharedPref.getString("type", "m4a"); isSkip = sharedPref.getBoolean("skip_file", false); progressDialog.setMax(koza.length); String url = null; for (int i = 0; i < koza.length; i++) { // file index of this week if (MainActivity.ENGLISH.containsKey(koza[i])) { url = "http://cgi2.nhk.or.jp/gogaku/st/xml/english/" + koza[i] + "/listdataflv.xml"; } else if (koza[i].contains("levelup_")) { url = "http://cgi2.nhk.or.jp/gogaku/st/xml/" + koza[i].substring("levelup_".length()) + "/levelup/listdataflv.xml"; } else { url = "http://cgi2.nhk.or.jp/gogaku/st/xml/" + koza[i] + "/kouza/listdataflv.xml"; } try { HttpGet httpGet = new HttpGet(url); DefaultHttpClient httpClient = new DefaultHttpClient(); httpGet.setHeader("Connection", "Keep-Alive"); HttpResponse response = httpClient.execute(httpGet); int status = response.getStatusLine().getStatusCode(); if (status != HttpStatus.SC_OK) { throw new Exception(""); } else { receiveStr = EntityUtils.toString(response.getEntity(), "UTF-8"); } } catch (Exception e) { e.printStackTrace(); return owner.getString(R.string.conn_error); } XmlPullParser xmlPullParser = Xml.newPullParser(); try { xmlPullParser.setInput(new StringReader(receiveStr)); } catch (XmlPullParserException e) { Log.d(TAG, e.toString()); return owner.getString(R.string.parse_error); } try { String kouza; String hdate; String file; String nendo; int eventType; eventType = xmlPullParser.getEventType(); while (eventType != XmlPullParser.END_DOCUMENT) { if (eventType == XmlPullParser.START_TAG) { if (xmlPullParser.getName().equals("music")) { kouza = xmlPullParser.getAttributeValue(null, "kouza"); hdate = xmlPullParser.getAttributeValue(null, "hdate"); file = xmlPullParser.getAttributeValue(null, "file"); nendo = xmlPullParser.getAttributeValue(null, "nendo"); lastKouza = kouza; download(koza[i], kouza, hdate, file, nendo, type); publishProgress(i); } } eventType = xmlPullParser.next(); } } catch (Exception e) { Log.d(TAG, e.toString()); return owner.getString(R.string.parse_error); } } return lastMessage; }
From source file:com.rothconsulting.android.websms.connector.coopmobile.ConnectorCoopMobile.java
/** * {@inheritDoc}/* w w w.j a v a 2s.c om*/ */ @Override public final ConnectorSpec updateSpec(final Context context, final ConnectorSpec connectorSpec) { this.log("Start updateSpec"); final SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(context); if (p.getBoolean(Preferences.PREFS_ENABLED, false)) { if (p.getString(Preferences.PREFS_USER, "").length() > 0 && p.getString(Preferences.PREFS_PASSWORD, "") // . .length() > 0) { connectorSpec.setReady(); } else { connectorSpec.setStatus(ConnectorSpec.STATUS_ENABLED); } } else { connectorSpec.setStatus(ConnectorSpec.STATUS_INACTIVE); } this.log("End updateSpec"); return connectorSpec; }
From source file:com.markupartist.sthlmtraveling.FavoritesFragment.java
/** * Converts old favorites to the new journey table. *//*from w w w . j a v a 2 s. com*/ private void maybeInitListAdapter() { // This for legacy resons. SharedPreferences localSettings = getActivity().getPreferences(FragmentActivity.MODE_PRIVATE); boolean isFavoritesConvertedLegacy = localSettings.getBoolean("converted_favorites", false); // This is the new settings. SharedPreferences settings = getActivity().getSharedPreferences("sthlmtraveling", FragmentActivity.MODE_PRIVATE); boolean isFavoritesConverted = settings.getBoolean("converted_favorites", false); if (isFavoritesConvertedLegacy || isFavoritesConverted) { initListAdapter(); return; } Toast.makeText(getActivity(), "Converting Favorites...", Toast.LENGTH_SHORT).show(); }
From source file:com.trellmor.berrymotes.sync.EmoteDownloader.java
private void initLogging() { // reset the default context (which may already have been initialized) // since we want to reconfigure it LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory(); lc.reset();/*w w w .j av a 2 s .com*/ // Log to logcat BasicLogcatConfigurator.configureDefaultContext(); // If logging is enabled in settings, also log to file SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(mContext); if (settings.getBoolean(SettingsActivity.KEY_LOG, false)) { PatternLayoutEncoder encoder = new PatternLayoutEncoder(); encoder.setContext(lc); encoder.setPattern("%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n"); encoder.start(); FileAppender<ILoggingEvent> fileAppender = new FileAppender<ILoggingEvent>(); fileAppender.setContext(lc); fileAppender.setFile(new File(mContext.getFilesDir(), LOG_FILE_NAME).getAbsolutePath()); fileAppender.setEncoder(encoder); fileAppender.start(); ch.qos.logback.classic.Logger root = (ch.qos.logback.classic.Logger) LoggerFactory .getLogger(Logger.ROOT_LOGGER_NAME); root.addAppender(fileAppender); } }
From source file:it.gmariotti.android.apps.dashclock.extensions.battery.BatteryExtension.java
/** * Read preference/*from w ww . j a va2 s .co m*/ */ private void readPreferences() { // Get preference value. SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this); //prefChannelID = sp.getString(PREF_CHANNEL_ID, prefChannelID); prefFieldID = sp.getString(PREF_FIELD_ID, prefFieldID); prefFieldName = sp.getBoolean(PREF_FIELD_NAME, true); prefFieldDate = sp.getBoolean(PREF_FIELD_DATE, true); prefFieldTime = sp.getBoolean(PREF_FIELD_TIME, true); // SharedPreferences.Editor editor = sp.edit(); // editor.putString(PREF_LOGIN, "ala ma kota"); // editor.commit(); }
From source file:it.gulch.linuxday.android.services.AlarmIntentService.java
private void notifyEvent(Intent intent) { long eventId = Long.parseLong(intent.getDataString()); Event event = eventManager.get(eventId); if (event == null) { return;//from w w w .ja v a2 s . com } // NotificationManager notificationManager = (NotificationManager) getSystemService(Context // .NOTIFICATION_SERVICE); // PendingIntent eventPendingIntent = // TaskStackBuilder.create(this).addNextIntent(new Intent(this, // MainActivity.class)).addNextIntent( // new Intent(this, EventDetailsActivity.class).setData(Uri.parse(String.valueOf(event // .getId())))) // .getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); PendingIntent eventPendingIntent = TaskStackBuilder.create(this) .addNextIntent(new Intent(this, MainActivity.class)) .addNextIntent(new Intent(this, EventDetailsActivity.class) .setData(Uri.parse(String.valueOf(event.getId())))) .getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); int defaultFlags = Notification.DEFAULT_SOUND; SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); if (sharedPreferences.getBoolean(SettingsFragment.KEY_PREF_NOTIFICATIONS_VIBRATE, false)) { defaultFlags |= Notification.DEFAULT_VIBRATE; } String trackName = event.getTrack().getTitle(); CharSequence bigText; String contentText; if (CollectionUtils.isEmpty(event.getPeople())) { contentText = trackName; bigText = event.getSubtitle(); } else { String personsSummary = StringUtils.join(event.getPeople(), ", "); contentText = String.format("%1$s - %2$s", trackName, personsSummary); String subTitle = event.getSubtitle(); SpannableString spannableBigText; if (TextUtils.isEmpty(subTitle)) { spannableBigText = new SpannableString(personsSummary); } else { spannableBigText = new SpannableString(String.format("%1$s\n%2$s", subTitle, personsSummary)); } // Set the persons summary in italic spannableBigText.setSpan(new StyleSpan(Typeface.ITALIC), +spannableBigText.length() - personsSummary.length(), spannableBigText.length(), +Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); bigText = spannableBigText; } String roomName = event.getTrack().getRoom().getName(); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_launcher).setWhen(event.getStartDate().getTime()) .setContentTitle(event.getTitle()).setContentText(contentText) .setStyle(new NotificationCompat.BigTextStyle().bigText(bigText).setSummaryText(trackName)) .setContentInfo(roomName).setContentIntent(eventPendingIntent).setAutoCancel(true) .setDefaults(defaultFlags).setPriority(NotificationCompat.PRIORITY_HIGH); // Blink the LED with FOSDEM color if enabled in the options if (sharedPreferences.getBoolean(SettingsFragment.KEY_PREF_NOTIFICATIONS_LED, false)) { notificationBuilder.setLights(getResources().getColor(R.color.maincolor), 1000, 5000); } /*// Android Wear extensions NotificationCompat.WearableExtender wearableExtender = new NotificationCompat.WearableExtender(); // Add an optional action button to show the room map image int roomImageResId = getResources() .getIdentifier(StringUtils.roomNameToResourceName(roomName), "drawable", getPackageName()); if(roomImageResId != 0) { // The room name is the unique Id of a RoomImageDialogActivity Intent mapIntent = new Intent(this, RoomImageDialogActivity.class).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK) .setData(Uri.parse(roomName)); mapIntent.putExtra(RoomImageDialogActivity.EXTRA_ROOM_NAME, roomName); mapIntent.putExtra(RoomImageDialogActivity.EXTRA_ROOM_IMAGE_RESOURCE_ID, roomImageResId); PendingIntent mapPendingIntent = PendingIntent.getActivity(this, 0, mapIntent, PendingIntent.FLAG_UPDATE_CURRENT); CharSequence mapTitle = getString(R.string.room_map); notificationBuilder .addAction(new NotificationCompat.Action(R.drawable.ic_action_place, mapTitle, mapPendingIntent)); // Use bigger action icon for wearable notification wearableExtender.addAction( new NotificationCompat.Action(R.drawable.ic_place_white_wear, mapTitle, mapPendingIntent)); } notificationBuilder.extend(wearableExtender);*/ NotificationManagerCompat.from(this).notify((int) eventId, notificationBuilder.build()); }