Java 类com.facebook.device.yearclass.YearClass 实例源码

项目:device-year-class    文件:MainActivity.java   
@Override
protected Integer doInBackground(Void... voids) {
  int yearClass = YearClass.CLASS_UNKNOWN;
  SharedPreferences prefs = getSharedPreferences(PREF_FILE, 0);
  if (prefs.contains(PREF_NAME)) {
    yearClass = prefs.getInt(PREF_NAME, YearClass.CLASS_UNKNOWN);
  }
  //Try again if device was previously unknown.
  if (yearClass == YearClass.CLASS_UNKNOWN) {
    yearClass = YearClass.get(getApplicationContext());
    SharedPreferences.Editor editor = prefs.edit();
    editor.putInt(PREF_NAME, yearClass);
    editor.apply();
  }
  return yearClass;
}
项目:react-native-device-year-class    文件:DeviceYearClass.java   
/**
 * Function to be shared to React-native, it returns the
 * year this Android device was considered high-end.
 *
 * @return { Promise } yearClass
 */
@ReactMethod
public void getYearClass(Promise promise) {
    try {
        int yearClass;
        yearClass = YearClass.get(getCurrentActivity());
        promise.resolve(yearClass);
    } catch (Exception e) {
        promise.reject(e);
    }
}
项目:pola-android    文件:MainActivity.java   
@Override
public int getDeviceYear() {
    return YearClass.get(getApplication());
}