當前位置: 首頁>>代碼示例>>Java>>正文


Java SharedPreferences.getLong方法代碼示例

本文整理匯總了Java中android.content.SharedPreferences.getLong方法的典型用法代碼示例。如果您正苦於以下問題:Java SharedPreferences.getLong方法的具體用法?Java SharedPreferences.getLong怎麽用?Java SharedPreferences.getLong使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.content.SharedPreferences的用法示例。


在下文中一共展示了SharedPreferences.getLong方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: get

import android.content.SharedPreferences; //導入方法依賴的package包/類
/**
 * 得到保存數據的方法,我們根據默認值得到保存的數據的具體類型,然後調用相對於的方法獲取值
 */
public static Object get(Context context, String key, Object defaultObject) {
    SharedPreferences sp = context.getSharedPreferences(FILE_NAME,
            Context.MODE_PRIVATE);

    if (defaultObject instanceof String) {
        return sp.getString(key, (String) defaultObject);
    } else if (defaultObject instanceof Integer) {
        return sp.getInt(key, (Integer) defaultObject);
    } else if (defaultObject instanceof Boolean) {
        return sp.getBoolean(key, (Boolean) defaultObject);
    } else if (defaultObject instanceof Float) {
        return sp.getFloat(key, (Float) defaultObject);
    } else if (defaultObject instanceof Long) {
        return sp.getLong(key, (Long) defaultObject);
    }

    return null;
}
 
開發者ID:Loofer,項目名稱:Watermark,代碼行數:22,代碼來源:SPUtils.java

示例2: getLastNotificationTimeInMillis

import android.content.SharedPreferences; //導入方法依賴的package包/類
/**
 * Returns the last time that a notification was shown (in UNIX time)
 *
 * @param context Used to access SharedPreferences
 * @return UNIX time of when the last notification was shown
 */
public static long getLastNotificationTimeInMillis(Context context) {
    /* Key for accessing the time at which Sunshine last displayed a notification */
    String lastNotificationKey = context.getString(R.string.pref_last_notification);

    /* As usual, we use the default SharedPreferences to access the user's preferences */
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);

    /*
     * Here, we retrieve the time in milliseconds when the last notification was shown. If
     * SharedPreferences doesn't have a value for lastNotificationKey, we return 0. The reason
     * we return 0 is because we compare the value returned from this method to the current
     * system time. If the difference between the last notification time and the current time
     * is greater than one day, we will show a notification again. When we compare the two
     * values, we subtract the last notification time from the current system time. If the
     * time of the last notification was 0, the difference will always be greater than the
     * number of milliseconds in a day and we will show another notification.
     */
    long lastNotificationTime = sp.getLong(lastNotificationKey, 0);

    return lastNotificationTime;
}
 
開發者ID:fjoglar,項目名稱:android-dev-challenge,代碼行數:28,代碼來源:SunshinePreferences.java

示例3: getPreferedApnIdFromPreferences

import android.content.SharedPreferences; //導入方法依賴的package包/類
private static long getPreferedApnIdFromPreferences(Context context, SharedPreferences prefs) {
	long id = prefs.getLong(Constants.PREF_PREFERRED_APN_ID, -1L);
	if (id == -1L) return id;
	
	// verify that there is still APN with such id
	ContentResolver resolver = context.getContentResolver();
       Cursor cursor = resolver.query(CURRENT_APNS, new String[] {COLUMN_ID}, COLUMN_ID + "=" + id, null, null);
       try {
       	cursor.moveToFirst();
       	if (!cursor.isAfterLast()){
       		// yes! it is still there
       		return id;
       	} else {
       		// no such APN anymore, return "not found"
       		return -1;
       	}
       } finally {
       	if (cursor != null) cursor.close();
       }
}
 
開發者ID:sdrausty,項目名稱:buildAPKsApps,代碼行數:21,代碼來源:ApnControl.java

示例4: get

import android.content.SharedPreferences; //導入方法依賴的package包/類
public static Object get(String fileName, Context context, String key, Object defaultObject) {
    SharedPreferences sp = SharedPreferencesImpl.getSharedPreferences(context, getFileName(fileName),
            Context.MODE_PRIVATE);

    if (defaultObject instanceof String) {
        return sp.getString(key, (String) defaultObject);
    } else if (defaultObject instanceof Integer) {
        return sp.getInt(key, (Integer) defaultObject);
    } else if (defaultObject instanceof Boolean) {
        return sp.getBoolean(key, (Boolean) defaultObject);
    } else if (defaultObject instanceof Float) {
        return sp.getFloat(key, (Float) defaultObject);
    } else if (defaultObject instanceof Long) {
        return sp.getLong(key, (Long) defaultObject);
    } else if (null == defaultObject) {
        return sp.getString(key, null);
    }

    return null;
}
 
開發者ID:miLLlulei,項目名稱:Accessibility,代碼行數:21,代碼來源:SPUtils.java

示例5: needUpdateCDBRequest

import android.content.SharedPreferences; //導入方法依賴的package包/類
/**
 * define if CDB request need repeat
 * @param context
 * @return
 */

static boolean needUpdateCDBRequest(Context context)
{
    SharedPreferences preferences = HelperFunctions.getWebTrekkSharedPreference(context);

    if (preferences.contains(LAST_CBD_REQUEST_DATE)) {
        long dates = preferences.getLong(LAST_CBD_REQUEST_DATE, 0);

        return dates < getCurrentDateCounter();
    }else
        return false;
}
 
開發者ID:Webtrekk,項目名稱:webtrekk-android-sdk,代碼行數:18,代碼來源:WebtrekkUserParameters.java

示例6: isRegisteredOnServer

import android.content.SharedPreferences; //導入方法依賴的package包/類
/**
 * Checks whether the device was successfully registered in the server side.
 *
 * @param context Current context
 * @return True if registration was successful, false otherwise
 */
public static boolean isRegisteredOnServer(Context context, String gcmKey) {
    final SharedPreferences prefs = context.getSharedPreferences(
            PREFERENCES, Context.MODE_PRIVATE);
    // Find registration threshold
    Calendar cal = Calendar.getInstance();
    cal.add(Calendar.DATE, -1);
    long yesterdayTS = cal.getTimeInMillis();
    long regTS = prefs.getLong(PROPERTY_REGISTERED_TS, 0);

    gcmKey = gcmKey == null ? "" : gcmKey;

    if (regTS > yesterdayTS) {
        LOGV(TAG, "GCM registration current. regTS=" + regTS + " yesterdayTS=" + yesterdayTS);

        final String registeredGcmKey = prefs.getString(PROPERTY_GCM_KEY, "");
        if (registeredGcmKey.equals(gcmKey)) {
            LOGD(TAG, "GCM registration is valid and for the correct gcm key: "
                    + AccountUtils.sanitizeGcmKey(registeredGcmKey));
            return true;
        }
        LOGD(TAG, "GCM registration is for DIFFERENT gcm key "
                + AccountUtils.sanitizeGcmKey(registeredGcmKey) + ". We were expecting "
                + AccountUtils.sanitizeGcmKey(gcmKey));
        return false;
    } else {
        LOGV(TAG, "GCM registration expired. regTS=" + regTS + " yesterdayTS=" + yesterdayTS);
        return false;
    }
}
 
開發者ID:dreaminglion,項目名稱:iosched-reader,代碼行數:36,代碼來源:ServerUtilities.java

示例7: RestoreState

import android.content.SharedPreferences; //導入方法依賴的package包/類
private void RestoreState() {
    try {
        SharedPreferences mPrefs = getActivity().getPreferences(Activity.MODE_PRIVATE);

        ActNewFlight.fPaused = mPrefs.getBoolean(m_KeysIsPaused, false);
        ActNewFlight.dtPauseTime = mPrefs.getLong(m_KeysPausedTime, 0);
        ActNewFlight.dtTimeOfLastPause = mPrefs.getLong(m_KeysTimeOfLastPause, 0);
        ActNewFlight.accumulatedNight = (double) mPrefs.getFloat(m_KeysAccumulatedNight, (float) 0.0);
    } catch (Exception e) {
        Log.e(MFBConstants.LOG_TAG, Log.getStackTraceString(e));
    }
}
 
開發者ID:ericberman,項目名稱:MyFlightbookAndroid,代碼行數:13,代碼來源:ActNewFlight.java

示例8: get

import android.content.SharedPreferences; //導入方法依賴的package包/類
private Object get(SharedPreferences sp, String key, Object defaultObject) {
    String type = defaultObject.getClass().getSimpleName();
    if ("String".equals(type)) {
        return sp.getString(key, (String) defaultObject);
    } else if ("Integer".equals(type)) {
        return sp.getInt(key, (Integer) defaultObject);
    } else if ("Boolean".equals(type)) {
        return sp.getBoolean(key, (Boolean) defaultObject);
    } else if ("Float".equals(type)) {
        return sp.getFloat(key, (Float) defaultObject);
    } else if ("Long".equals(type)) {
        return sp.getLong(key, (Long) defaultObject);
    }
    return null;
}
 
開發者ID:BaoBaoJianqiang,項目名稱:HybridForAndroid,代碼行數:16,代碼來源:SpUtils.java

示例9: isModified

import android.content.SharedPreferences; //導入方法依賴的package包/類
private static boolean isModified(Context context, File archive, long currentCrc) {
    SharedPreferences prefs = getMultiDexPreferences(context);
    return (prefs.getLong("timestamp", -1) == getTimeStamp(archive) && prefs.getLong(KEY_CRC, -1) == currentCrc) ? false : true;
}
 
開發者ID:JackChan1999,項目名稱:letv,代碼行數:5,代碼來源:MultiDexExtractor.java

示例10: getLong

import android.content.SharedPreferences; //導入方法依賴的package包/類
public long getLong(Context context, String key, long defValue) {
    SharedPreferences sp = context.getSharedPreferences(FILE_NAME, Context.MODE_PRIVATE);
    return sp.getLong(key, defValue);
}
 
開發者ID:jopenbox,項目名稱:android-lite-utils,代碼行數:5,代碼來源:SPUtils.java

示例11: getLastUpdate

import android.content.SharedPreferences; //導入方法依賴的package包/類
private long getLastUpdate(Context context) {
    SharedPreferences sharedPref = context.getSharedPreferences("app_preferences", Context.MODE_PRIVATE);
    return sharedPref.getLong("update_time", 0);
}
 
開發者ID:chashmeetsingh,項目名稱:TrackIt-Android,代碼行數:5,代碼來源:DataHelper.java

示例12: setNextAlarm

import android.content.SharedPreferences; //導入方法依賴的package包/類
public static void setNextAlarm(Context context) {
    // Prepare alarm
    Intent diaryAlertIntent = new Intent(context, AlarmHandler.class);
    diaryAlertIntent.setAction(AlarmHandler.DIARY_ALERT);
    PendingIntent alarmIntent = PendingIntent.getBroadcast(context, 0, diaryAlertIntent, 0);
    AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);

    // Get alarm time
    SharedPreferences sharedPreferences = context.getSharedPreferences(
            MainActivity.PREFERENCES, Context.MODE_PRIVATE);
    long diaryReminderTime = sharedPreferences.getLong(
            SettingsFragment.KEY_PREF_DIARY_ALERT_TIME, ~0);

    if (diaryReminderTime != ~0 ) {
        Calendar diaryAlertTime = Calendar.getInstance();
        diaryAlertTime.setTimeInMillis(diaryReminderTime);
        // Get a calendar for today and set the time to the alarm time
        Calendar alarmCalendar = Calendar.getInstance();
        alarmCalendar.setTimeInMillis(System.currentTimeMillis());
        alarmCalendar.set(Calendar.HOUR_OF_DAY, diaryAlertTime.get(Calendar.HOUR_OF_DAY));
        alarmCalendar.set(Calendar.MINUTE, diaryAlertTime.get(Calendar.MINUTE));

        // Compare with current time to see if the next alarm is today or tomorrow
        Calendar nowCalendar = Calendar.getInstance();
        nowCalendar.setTimeInMillis(System.currentTimeMillis());

        long alarmTime = alarmCalendar.getTimeInMillis();
        // If alarm time is earlier in the day...
        if( alarmCalendar.getTimeInMillis() <= nowCalendar.getTimeInMillis() ){
            // ...then check if we already had today's
            long lastDiaryReminderTime = sharedPreferences.getLong(AlarmHandler.LAST_DIARY_NOTIFICATION_PREF, ~0);
            if (lastDiaryReminderTime != ~0 && lastDiaryReminderTime != 0) {
                Calendar lastAlertTime = Calendar.getInstance();
                lastAlertTime.setTimeInMillis(lastDiaryReminderTime);
                // If last alert was in same year and day of year...
                if (lastAlertTime.get(Calendar.YEAR) == nowCalendar.get(Calendar.YEAR) &&
                        lastAlertTime.get(Calendar.DAY_OF_YEAR) == nowCalendar.get(Calendar.DAY_OF_YEAR)) {
                    // ...set for tomorrow by adding one day
                    alarmTime = alarmTime + AlarmManager.INTERVAL_DAY;
                }
                // Otherwise, leave as is because we haven't done one today and it will trigger immediately
            }
            else {
                // don't know when the last one was so set for tomorrow by adding one day
                alarmTime = alarmTime + AlarmManager.INTERVAL_DAY;
            }
        }
        // Otherwise leave as is and it will trigger later today

        // Create the alarm
        if (android.os.Build.VERSION.SDK_INT < 19) {
            alarmManager.set(AlarmManager.RTC_WAKEUP, alarmTime, alarmIntent);
        } else {
            alarmManager.setExact(AlarmManager.RTC_WAKEUP, alarmTime, alarmIntent);
        }
    }
}
 
開發者ID:jgevans,項目名稱:TherapyGuide,代碼行數:58,代碼來源:AlarmSetter.java

示例13: getGeneratedDelay

import android.content.SharedPreferences; //導入方法依賴的package包/類
/**
 * Returns the delay used to generate the last alarm.  If no previous alarm was generated,
 * return the base delay.
 */
public long getGeneratedDelay() {
    SharedPreferences preferences = getSharedPreferences();
    return preferences.getLong(PREFERENCE_DELAY, mBaseMilliseconds);
}
 
開發者ID:rkshuai,項目名稱:chromium-for-android-56-debug-video,代碼行數:9,代碼來源:ExponentialBackoffScheduler.java

示例14: getFirstStartupDate

import android.content.SharedPreferences; //導入方法依賴的package包/類
private static long getFirstStartupDate(Context context) {
    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
    return sharedPreferences.getLong(PREF_FIRST_STARTUP_DATE, 0);
}
 
開發者ID:elimu-ai,項目名稱:start-guide,代碼行數:5,代碼來源:StartPrefsHelper.java

示例15: getLong

import android.content.SharedPreferences; //導入方法依賴的package包/類
/**
 * 獲取long值
 *
 * @param context  上下文
 * @param key      鍵
 * @param defValue 默認值
 * @return 保存的值
 */
public static long getLong(Context context, String key, long defValue) {
    SharedPreferences sp = getSp(context);
    return sp.getLong(key, defValue);
}
 
開發者ID:markchylshow,項目名稱:Shopping_car_Demo,代碼行數:13,代碼來源:SPUtils.java


注:本文中的android.content.SharedPreferences.getLong方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。