List of usage examples for android.content SharedPreferences getLong
long getLong(String key, long defValue);
From source file:org.dpadgett.timer.CountdownFragment.java
private void restoreState() { final SharedPreferences prefs = getContext().getSharedPreferences("Countdown", Context.MODE_PRIVATE); timingState = new CountdownState((CountdownTextView) timerLayout.findViewById(R.id.countdownTimer), prefs); if (prefs.contains("countdownInputs")) { long countdownInputs = prefs.getLong("countdownInputs", 0L); countdownInputs /= 1000;/* ww w.jav a 2 s . co m*/ countdownSeconds.setValue((int) (countdownInputs % 60)); countdownInputs /= 60; countdownMinutes.setValue((int) (countdownInputs % 60)); countdownInputs /= 60; countdownHours.setValue((int) (countdownInputs % 100)); inputMode = !timingState.isRunning(); if (!inputMode) { // countdown view final LinearLayout inputs = (LinearLayout) rootView.findViewById(R.id.inputsLayout); final Button startButton = (Button) rootView.findViewById(R.id.startButton); inputs.removeAllViews(); inputs.addView(timerLayout); startButton.setText(getContext().getString(R.string.countdown_button_cancel)); // timing thread will auto start itself } } alarmSelector.restoreState(); }
From source file:com.piusvelte.cloudset.android.CloudSetMain.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); GooglePlayServicesUtil.getOpenSourceSoftwareLicenseInfo(getApplicationContext()); setContentView(R.layout.activity_main); final ActionBar actionBar = getActionBar(); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); sectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager()); viewPager = (ViewPager) findViewById(R.id.pager); viewPager.setAdapter(sectionsPagerAdapter); viewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { @Override//www .j a v a2s .c o m public void onPageSelected(int position) { actionBar.setSelectedNavigationItem(position); } }); for (int i = 0; i < sectionsPagerAdapter.getCount(); i++) { actionBar.addTab(actionBar.newTab().setText(sectionsPagerAdapter.getPageTitle(i)).setTabListener(this)); } SharedPreferences sp = getSharedPreferences(getString(R.string.app_name), MODE_PRIVATE); account = sp.getString(PREFERENCE_ACCOUNT_NAME, null); deviceId = sp.getLong(PREFERENCE_DEVICE_ID, INVALID_DEVICE_ID); setCurrentTab(); // create the loader for registration, deregistration, and loading // devices LoaderManager loaderManager = getSupportLoaderManager(); loaderManager.initLoader(0, null, this); if (savedInstanceState != null && savedInstanceState.containsKey(EXTRA_LOADER_IDS)) { loaderIds = savedInstanceState.getIntegerArrayList(EXTRA_LOADER_IDS); } else { loaderIds = new ArrayList<Integer>(); } for (int i = 0, s = loaderIds.size(); i < s; i++) { // reconnect to additional loaders for deregistering additional // devices loaderManager.initLoader(loaderIds.get(i), null, this); } }
From source file:ru.orangesoftware.financisto2.activity.FlowzrSyncActivity.java
protected void restoreUIFromPref() { SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); lastSyncLocalTimestamp = preferences.getLong(FlowzrSyncOptions.PROPERTY_LAST_SYNC_TIMESTAMP, 0); AccountManager accountManager = AccountManager.get(getApplicationContext()); Account[] accounts = accountManager.getAccountsByType("com.google"); for (Account account : accounts) { if (preferences.getString(FlowzrSyncOptions.PROPERTY_USE_CREDENTIAL, "").equals(account.name)) { useCredential = account;/*w w w .j av a 2 s .c o m*/ } } TextView tv = (TextView) findViewById(R.id.sync_was); tv.setText(getString(R.string.flowzr_sync_was) + " " + new Date(lastSyncLocalTimestamp).toLocaleString()); }
From source file:org.lunci.dumbthing.account.LinkFacebook.java
@Override public void unlink() { if (BuildConfig.DEBUG) { Log.i(TAG, "unlinkFacebook"); }//from w ww.ja v a 2 s . c o m callUnlinkConfirmDialog(R.string.unlink_facebook_warning, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { final SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(getActivity()); try { Session session = Session.getActiveSession(); if (session == null) { final String token = pref.getString(Keys.Preference_Facebook_AccessToken, ""); final long expire = pref.getLong(Keys.Preference_Facebook_AccessToken_Expire, 0); final Date expDate = new Date(); expDate.setTime(expire); final long lastRefresh = pref.getLong(Keys.Preference_Facebook_Last_Refresh_Date, 0); final Date lastDate = new Date(); lastDate.setTime(lastRefresh); final Set<String> permissions = pref.getStringSet(Keys.Preference_Facebook_Permissions, null); final List<String> permissionList = new ArrayList<>(); permissionList.addAll(permissions); // final Set<String> declinedPermissions=pref.getStringSet(Keys.Preference_Facebook_Declined_Permissions, null); final String source = pref.getString(Keys.Preference_Facebook_AccessToken_Source, ""); final AccessTokenSource tokenSource = AccessTokenSource.valueOf(source); final AccessToken accessToken = AccessToken.createFromExistingAccessToken(token, expDate, lastDate, tokenSource, permissionList); session = Session.openActiveSessionWithAccessToken(getActivity(), accessToken, null); } if (session != null) session.closeAndClearTokenInformation(); else { Log.w(TAG, "Unable to retrieve session"); } } catch (NullPointerException ex) { ex.printStackTrace(); } finally { final SharedPreferences.Editor editor = pref.edit(); editor.putBoolean(Keys.Preference_Facebook_Linked, false).commit(); mButtonContainer.updateLinked(false); } } }); }
From source file:com.anjalimacwan.fragment.NoteListFragment.java
@Override public void onStart() { super.onStart(); LocalBroadcastManager.getInstance(getActivity()).registerReceiver(receiver, filter); // Floating action button FloatingActionButton floatingActionButton = (FloatingActionButton) getActivity() .findViewById(R.id.button_floating_action); floatingActionButton.setImageResource(R.drawable.ic_action_new); if (getActivity().findViewById(R.id.layoutMain).getTag().equals("main-layout-large")) floatingActionButton.hide();//from w w w. j a va2 s .c o m SharedPreferences prefMain = getActivity().getPreferences(Context.MODE_PRIVATE); if (getId() == R.id.noteViewEdit && prefMain.getLong("draft-name", 0) == 0) { floatingActionButton.show(); floatingActionButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Bundle bundle = new Bundle(); bundle.putString("filename", "new"); Fragment fragment = new NoteEditFragment(); fragment.setArguments(bundle); // Add NoteEditFragment getFragmentManager().beginTransaction().replace(R.id.noteViewEdit, fragment, "NoteEditFragment") .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_CLOSE).commit(); } }); } }
From source file:org.apache.cordova.plugins.FacebookConnect.java
/** * Cordova interface to initialize the appId * * @param args//from w w w .j av a 2 s .c o m * @param callbackId * @return PluginResult * @throws JSONException */ public PluginResult initWithAppId(final JSONArray args, final String callbackId) throws JSONException { Log.d(CLASS, "initWithAppId()"); JSONObject params = args.getJSONObject(0); PluginResult pluginResult = new PluginResult(PluginResult.Status.NO_RESULT); JSONObject result = new JSONObject(); this.appId = params.getString("appId"); Facebook facebook = this.getFacebook(); result.put("appId", this.appId); // Check for any stored session update Facebook session information SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this.cordova.getContext()); String accessToken = prefs.getString("access_token", null); Long accessExpires = prefs.getLong("access_expires", 0); if (accessToken != null) facebook.setAccessToken(accessToken); if (accessExpires != 0) facebook.setAccessExpires(accessExpires); result.put("accessToken", accessToken); result.put("expirationDate", accessExpires); pluginResult = new PluginResult(PluginResult.Status.OK, result); this.success(pluginResult, callbackId); return pluginResult; }
From source file:de.incoherent.suseconferenceclient.activities.HomeActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_home); mDialog = null;/*from w w w .j a va 2s . c o m*/ if (savedInstanceState == null) { SharedPreferences settings = getSharedPreferences("SUSEConferences", 0); mConferenceId = settings.getLong("active_conference", -1); } else { mConferenceId = savedInstanceState.getLong("conferenceId"); mVenueId = savedInstanceState.getLong("venueId"); } if (mConferenceId == -1) { Log.d("SUSEConferences", "Conference ID is -1"); if (!hasInternet()) { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setMessage("Please enable internet access and try again."); builder.setCancelable(false); builder.setPositiveButton("OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { HomeActivity.this.finish(); } }); builder.show(); } else { loadConferences(); } } else { if (savedInstanceState != null) setView(false); else setView(true); } }
From source file:com.amsterdam.marktbureau.makkelijkemarkt.MarktenFragment.java
/** * Inflate the markten_fragment layout containing the markten listview * @param inflater LayoutInflator//from w ww . j a v a 2s .c o m * @param container ViewGroup * @param savedInstanceState Bundle * @return View */ @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // get the markten fragment View mainView = inflater.inflate(R.layout.markten_fragment, container, false); // bind the elements to the view ButterKnife.bind(this, mainView); // create an adapter for the markten listview mMarktenAdapter = new SimpleCursorAdapter(getContext(), R.layout.markten_list_item, null, new String[] { MakkelijkeMarktProvider.Markt.COL_NAAM }, new int[] { R.id.markt_naam }, 0); // attach the adapter to the markten listview mMarktenListView.setAdapter(mMarktenAdapter); if (savedInstanceState == null) { // check time in hours since last fetched the markten SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(getContext()); long diffInHours = getResources() .getInteger(R.integer.makkelijkemarkt_api_markten_fetch_interval_hours); if (settings.contains(getContext().getString(R.string.sharedpreferences_key_markten_last_fetched))) { long lastFetchTimestamp = settings .getLong(getContext().getString(R.string.sharedpreferences_key_markten_last_fetched), 0); long differenceMs = new Date().getTime() - lastFetchTimestamp; diffInHours = TimeUnit.MILLISECONDS.toHours(differenceMs); } // update the local markten by reloading them from the api (with an http client containing // an interceptor that will modify the response to transform the aanwezigeopties object // into an array of strings) if (diffInHours >= getResources() .getInteger(R.integer.makkelijkemarkt_api_markten_fetch_interval_hours)) { // show the progressbar mMarktenProgressBar.setVisibility(View.VISIBLE); ApiGetMarkten getMarkten = new ApiGetMarkten(getContext()); getMarkten.addAanwezigeOptiesInterceptor(); getMarkten.enqueue(this); } } // inititate loading the markten from the database getLoaderManager().initLoader(MARKTEN_LOADER, null, this); return mainView; }
From source file:com.trellmor.berrymotes.sync.SubredditEmoteDownloader.java
public SubredditEmoteDownloader(Context context, EmoteDownloader emoteDownloader, String subreddit) { mContext = context;/* w ww . j a va 2 s.c om*/ mEmoteDownloader = emoteDownloader; mSubreddit = subreddit; SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context); mDownloadNSFW = settings.getBoolean(SettingsActivity.KEY_SYNC_NSFW, false); mLastModified = new Date(settings.getLong(SettingsActivity.KEY_SYNC_LAST_MODIFIED + mSubreddit, 0)); mBaseDir = mContext.getExternalFilesDir(null); mContentResolver = mContext.getContentResolver(); mSyncResult = new SyncResult(); }
From source file:org.apache.cordova.plugins.FacebookConnect.java
/** * Cordova interface to perform a login/* w ww . j av a 2 s.co m*/ * * @param args * @param callbackId * @return PluginResult * @throws JSONException * @throws MalformedURLException * @throws IOException */ public PluginResult login(final JSONArray args, final String callbackId) throws JSONException, MalformedURLException, IOException { Log.d(CLASS, "login() :" + args.toString()); JSONObject params = args.getJSONObject(0); PluginResult pluginResult = new PluginResult(PluginResult.Status.NO_RESULT); if (params.has("appId")) this.appId = params.getString("appId"); Facebook facebook = this.getFacebook(); // Check for any stored session update Facebook session information SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this.cordova.getContext()); String accessToken = prefs.getString("access_token", null); Long accessExpires = prefs.getLong("access_expires", 0); if (accessToken != null) facebook.setAccessToken(accessToken); if (accessExpires != 0) facebook.setAccessExpires(accessExpires); if (!this.getFacebook().isSessionValid()) { JSONArray permissionsArray = (JSONArray) params.get("permissions"); final String[] permissions = new String[permissionsArray.length()]; for (int i = 0; i < permissionsArray.length(); i++) { permissions[i] = permissionsArray.getString(i); } final FacebookConnect me = this; this.authorizeDialogListener = new AuthorizeDialogListener(me, callbackId); this.cordova.setActivityResultCallback(this); Runnable runnable = new Runnable() { public void run() { me.getFacebook().authorize(me.cordova.getActivity(), permissions, me.authorizeDialogListener); }; }; pluginResult.setKeepCallback(true); this.cordova.getActivity().runOnUiThread(runnable); } else { JSONObject result = new JSONObject(facebook.request("/me")); result.put("accessToken", accessToken); result.put("expirationDate", accessExpires); Log.d(CLASS, "login::result " + result.toString()); pluginResult = new PluginResult(PluginResult.Status.OK, result); } return pluginResult; }