本文整理匯總了Java中android.app.Activity.getSharedPreferences方法的典型用法代碼示例。如果您正苦於以下問題:Java Activity.getSharedPreferences方法的具體用法?Java Activity.getSharedPreferences怎麽用?Java Activity.getSharedPreferences使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.app.Activity
的用法示例。
在下文中一共展示了Activity.getSharedPreferences方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: save
import android.app.Activity; //導入方法依賴的package包/類
public static void save(Activity activity, Mat cameraMatrix, Mat distCoeff) {
SharedPreferences sharedPref = activity.getSharedPreferences(activity.getString(R.string.sharedprefrences_key), Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPref.edit();
double[] cameraMatrixArray = new double[CAMERA_MATRIX_ROWS * CAMERA_MATRIX_COLS];
cameraMatrix.get(0, 0, cameraMatrixArray);
for (int i = 0; i < CAMERA_MATRIX_ROWS; i++) {
for (int j = 0; j < CAMERA_MATRIX_COLS; j++) {
Integer id = i * CAMERA_MATRIX_ROWS + j;
editor.putFloat(activity.getString(R.string.sharedpreferences_camera_matrix_key) + id.toString(), (float)cameraMatrixArray[id]);
}
}
double[] distortionCoefficientsArray = new double[DISTORTION_COEFFICIENTS_SIZE];
distCoeff.get(0, 0, distortionCoefficientsArray);
for (Integer i = 0; i < DISTORTION_COEFFICIENTS_SIZE ; i++) {
editor.putFloat(activity.getString(R.string.sharedpreferences_distortion_coefficients_key) + i.toString(), (float)distortionCoefficientsArray[i]);
}
editor.commit();
Log.d(TAG, "Saved camera matrix: " + cameraMatrix.dump());
Log.d(TAG, "Saved distortion coefficients: " + distCoeff.dump());
}
示例2: tryLoad
import android.app.Activity; //導入方法依賴的package包/類
public static boolean tryLoad(Activity activity, Mat cameraMatrix, Mat distCoeff) {
SharedPreferences sharedPref = activity.getSharedPreferences(activity.getString(R.string.sharedprefrences_key), Context.MODE_PRIVATE);
if (sharedPref.getFloat(activity.getString(R.string.sharedpreferences_camera_matrix_key) + 0, -1) == -1) {
Log.d(TAG, "No previous calibration results found");
return false;
}
double[] cameraMatrixArray = new double[CAMERA_MATRIX_ROWS * CAMERA_MATRIX_COLS];
for (int i = 0; i < CAMERA_MATRIX_ROWS; i++) {
for (int j = 0; j < CAMERA_MATRIX_COLS; j++) {
Integer id = i * CAMERA_MATRIX_ROWS + j;
cameraMatrixArray[id] = sharedPref.getFloat(activity.getString(R.string.sharedpreferences_camera_matrix_key) + id.toString(), -1);
}
}
cameraMatrix.put(0, 0, cameraMatrixArray);
Log.d(TAG, "Loaded camera matrix: " + cameraMatrix.dump());
double[] distortionCoefficientsArray = new double[DISTORTION_COEFFICIENTS_SIZE];
for (Integer i = 0; i < DISTORTION_COEFFICIENTS_SIZE ; i++) {
distortionCoefficientsArray[i] = sharedPref.getFloat(activity.getString(R.string.sharedpreferences_distortion_coefficients_key) + i.toString(), -1);
}
distCoeff.put(0, 0, distortionCoefficientsArray);
Log.d(TAG, "Loaded distortion coefficients: " + distCoeff.dump());
return true;
}
示例3: with
import android.app.Activity; //導入方法依賴的package包/類
/**
* 外部靜態調用
*
* @param activity
* @return
*/
public static EmotionKeyboard with(Activity activity) {
EmotionKeyboard emotionInputDetector = new EmotionKeyboard();
emotionInputDetector.mActivity = activity;
emotionInputDetector.mInputManager = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
emotionInputDetector.sp = activity.getSharedPreferences(SHARE_PREFERENCE_NAME, Context.MODE_PRIVATE);
return emotionInputDetector;
}
示例4: SetThings
import android.app.Activity; //導入方法依賴的package包/類
public SetThings(Activity activity) {
//set all variables
sharedPreferences = activity.getSharedPreferences(activity.getResources().getText(R.string.sharedprefs_id).toString(), Context.MODE_PRIVATE);
editor = sharedPreferences.edit();
editor.apply();
Dark = sharedPreferences.getBoolean("isDark", false);
setup = sharedPreferences.getBoolean("isSetup", false);
exceptions = new Exceptions();
SDK_INT = Build.VERSION.SDK_INT;
//noinspection deprecation
titleText = activity.getResources().getColor(Dark ? android.R.color.primary_text_dark : android.R.color.primary_text_light);
//noinspection deprecation,deprecation
drawerItem = Dark ? activity.getResources().getColorStateList(R.color.drawer_item_dark) : activity.getResources().getColorStateList(R.color.drawer_item_light);
// activity.setTheme(SetupActivity.class == activity.getClass() || NoRootSystemSettingsActivity.class == activity.getClass() ? Dark ? R.style.DARK : R.style.AppTheme : Dark ? R.style.DARK_NoAppBar : R.style.AppTheme_NoActionBar);
activity.setTheme(Dark ? R.style.DARK : R.style.AppTheme);
style = Dark ? R.style.DARK_NoAppBar : R.style.AppTheme_NoActionBar; //is dark mode on?
pages = new ArrayList<Integer>() {{ //all (currently used) fragments
add(R.id.nav_home);
add(R.id.nav_statusbar);
add(R.id.nav_demo_mode);
add(R.id.nav_about);
add(R.id.nav_settings);
add(R.id.nav_misc);
add(R.id.nav_quick_settings);
add(R.id.nav_touchwiz);
}};
currentActivity = activity;
context = currentActivity; //kinda pointless...
}
示例5: with
import android.app.Activity; //導入方法依賴的package包/類
public static AppRate with(Activity activity) {
AppRate instance = new AppRate(activity);
instance.text = "Enjoying the app? Spread the word!";//activity.getString(R.string.dra_rate_app);
instance.settings = activity.getSharedPreferences(PREFS_NAME, 0);
instance.editor = instance.settings.edit();
return instance;
}
示例6: saveSDCardUri
import android.app.Activity; //導入方法依賴的package包/類
public static void saveSDCardUri(Activity activity, String uri) {
SharedPreferences preferenceSD;
preferenceSD = activity.getSharedPreferences("sdUri", Context.MODE_PRIVATE);
preferenceSD.edit()
.clear()
.apply();
preferenceSD.edit()
.putString("selectedSD", uri)
.apply();
}
示例7: writeXposedSP
import android.app.Activity; //導入方法依賴的package包/類
private static void writeXposedSP(Activity thisActivity){
SharedPreferences a = thisActivity.getSharedPreferences(thisActivity.getPackageName() + "_preferences", MODE_WORLD_READABLE);
SharedPreferences b = thisActivity.getSharedPreferences("xposed", MODE_WORLD_READABLE);
SharedPreferences.Editor be = b.edit();
be.putString("package_settings",a.getString("package_settings",""));
be.putString("xposed_mode",a.getString("xposed_mode","0"));
be.putBoolean("enable_debug",a.getBoolean("enable_debug",false));
be.commit(); //防止係統銷毀來不及保存怎麽樣
}
示例8: getLoginPwd
import android.app.Activity; //導入方法依賴的package包/類
private KeyValueBean getLoginPwd(Activity activity){
SharedPreferences prefs = activity.getSharedPreferences(
"org.mrpdaemon.android.encdroidmc", activity.MODE_PRIVATE);
//boolean linked = prefs.getBoolean("linked",false);
String ak = prefs.getString("accessKey","");
String as = prefs.getString("accessSecret","");
return (new KeyValueBean(ak,as));
}
示例9: setLastInt
import android.app.Activity; //導入方法依賴的package包/類
private static void setLastInt(Activity activity, int lastInt) {
SharedPreferences preferenceName;
preferenceName = activity.getSharedPreferences("int", Context.MODE_PRIVATE);
preferenceName.edit()
.clear()
.apply();
preferenceName.edit()
.putInt("lastInt", lastInt)
.apply();
}
示例10: with
import android.app.Activity; //導入方法依賴的package包/類
public static AppRate with(Activity activity, ViewGroup viewGroup) {
AppRate instance = new AppRate(activity, viewGroup);
instance.text = "Enjoying the app? Spread the word!";//activity.getString(R.string.dra_rate_app);
instance.settings = activity.getSharedPreferences(PREFS_NAME, 0);
instance.editor = instance.settings.edit();
return instance;
}
示例11: StorageImpl
import android.app.Activity; //導入方法依賴的package包/類
StorageImpl(Activity activity) {
prefs = activity.getSharedPreferences("main", Context.MODE_PRIVATE);
}
示例12: provideSharedPreferences
import android.app.Activity; //導入方法依賴的package包/類
@ActivityScope
@Provides
SharedPreferences provideSharedPreferences(Activity activity) {
return activity.getSharedPreferences("db", MODE_PRIVATE);
}
示例13: onResume
import android.app.Activity; //導入方法依賴的package包/類
@Override
public boolean onResume(Activity activity) {
if (api != null && api.getSession() != null && api.getSession().authenticationSuccessful()) {
try {
// MANDATORY call to complete auth.
// Sets the access token on the session
api.getSession().finishAuthentication();
AccessTokenPair tokens = api.getSession().getAccessTokenPair();
// Provide your own storeKeys to persist the access token pair
// A typical way to store tokens is using SharedPreferences
//storeKeys(tokens.key, tokens.secret);
SharedPreferences prefs = activity.getSharedPreferences(
"org.mrpdaemon.android.encdroidmc", activity.MODE_PRIVATE);
Editor edit = prefs.edit();
edit.putBoolean("linked", true);
edit.putString("accessKey", tokens.key);
edit.putString("accessSecret", tokens.secret);
// userName = mApi.accountInfo().displayName;
// apiThread.start();
// apiThread.join();
//
// edit.putString(PREF_USER_NAME, userName);
edit.commit();
KeyValueBean loginPwd = getLoginPwd(activity);
AccessTokenPair atp = new AccessTokenPair(loginPwd.getKey(),loginPwd.getValue());
api.getSession().setAccessTokenPair(atp);
return true;
} catch (Exception e) {
Log.i("DbAuthLog", "Error authenticating", e);
e.printStackTrace();
}
}
return false;
}
示例14: GiraffePlayer
import android.app.Activity; //導入方法依賴的package包/類
public GiraffePlayer(final Activity activity) {
log = LogUtil.getInstance();
/*通過sharepreference得到屏幕參數*/
SharedPreferences sharedPreferences= activity.getSharedPreferences("screeninfo",
Activity.MODE_PRIVATE);
mWidthPixels =sharedPreferences.getInt("widthPixels", 0);
mHeightPixels =sharedPreferences.getInt("heightPixels",0);
try {
IjkMediaPlayer.loadLibrariesOnce(null);
IjkMediaPlayer.native_profileBegin("libijkplayer.so");
playerSupport=true;
} catch (Throwable e) {
log.e("GiraffePlayer", "loadLibraries error"+e);
}
this.activity=activity;
$=new Query(activity);
/*初始化控件*/
initViews();
/*聲音*/
voiceThread = new VoiceThread();
voiceThread.start();
/*初始化屏幕監聽*/
orientationEventListener = new OrientationEventListener(activity) {
@Override
public void onOrientationChanged(int orientation) {
if (orientation >= 0 && orientation <= 30 || orientation >= 330 || (orientation >= 150 && orientation <= 210)) {
//豎屏
if (portrait) {
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
orientationEventListener.disable();
}
} else if ((orientation >= 90 && orientation <= 120) || (orientation >= 240 && orientation <= 300)) {
if (!portrait) {
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
orientationEventListener.disable();
}
}
}
};
portrait=true;
initHeight=activity.findViewById(R.id.app_video_box).getLayoutParams().height;
if (!playerSupport) {
showStatus(activity.getResources().getString(R.string.not_support));
}
/*初始化隱藏顯示控件列表*/
initViewList();
}
示例15: getSDCardUri
import android.app.Activity; //導入方法依賴的package包/類
static String getSDCardUri(Activity activity) {
SharedPreferences preferenceSD = activity.getSharedPreferences("sdUri", Context.MODE_PRIVATE);
return preferenceSD.getString("selectedSD", "");
}