Codota Logo
SharePreferencesUtils
Code IndexAdd Codota to your IDE (free)

How to use
SharePreferencesUtils
in
jsc.kit.component.utils

Best Java code snippets using jsc.kit.component.utils.SharePreferencesUtils (Showing top 20 results out of 315)

  • Add the Codota plugin to your IDE and get smart completions
private void myMethod () {
Point p =
  • Codota Iconnew Point(x, y)
  • Codota Iconnew Point()
  • Codota IconMouseEvent e;e.getPoint()
  • Smart code suggestions by Codota
}
origin: JustinRoom/JSCKit

public static SharePreferencesUtils getInstance() {
  if (instance == null) {
    synchronized (SharePreferencesUtils.class) {
      if (instance == null)
        instance = new SharePreferencesUtils();
    }
  }
  return instance;
}
origin: JustinRoom/JSCKit

public int getInt(String key, Integer defValue) {
  checkIsInit();
  return sharedPreferences.getInt(key, defValue);
}
origin: JustinRoom/JSCKit

  @Override
  public void onCustomClick(@NonNull View view) {
    int count = SharePreferencesUtils.getInstance().getInt(key, 0) + 1;
    SharePreferencesUtils.getInstance().saveInt(key, count);
    loadVersionInfo();
  }
})
origin: JustinRoom/JSCKit

@Override
public void onActivityStarted(Activity activity) {
  mFinalCount++;
  Log.e(TAG, "onActivityStarted: " + activity.getClass().getSimpleName() + ">>>" + mFinalCount);
  if (mFinalCount == 1 && canShowAdvertisement(activity.getClass())) {
    //如果是PhotoActivity时,在开启相机或者打开相册返回时不显示广告
    //onActivityResult(int requestCode, int resultCode, Intent data)在onActivityStarted(Activity activity)方法前调用,
    //所以不能在onActivityResult(int requestCode, int resultCode, Intent data)中设置enableAdvertisement = true
    if (activity instanceof PhotoActivity && !((PhotoActivity) activity).enableAdvertisement){
      ((PhotoActivity) activity).enableAdvertisement = true;
      return;
    }
    //说明从后台回到了前台
    long lastShowAdvertisementTimeStamp = SharePreferencesUtils.getInstance().getLong(Configration.SP_ADVERTISEMENT_LAST_SHOW_TIME, 0L);
    long curTime = System.currentTimeMillis();
    if ((curTime - lastShowAdvertisementTimeStamp > ADVERTISEMENT_INTERNAL_TIME)) {
      SharePreferencesUtils.getInstance().saveLong(Configration.SP_ADVERTISEMENT_LAST_SHOW_TIME, curTime);
      activity.startActivity(new Intent(activity, AdvertisementViewActivity.class));
    }
  }
}
origin: JustinRoom/JSCKit

private void showGuidePopupWindow(final String key) {
  final int showCount = SharePreferencesUtils.getInstance().getInt(key, 0);
  if (showCount < 3) {
    ImageView imageView = new ImageView(this);
origin: JustinRoom/JSCKit

  @Override
  public void onCustomClick(@NonNull View view) {
    int count = SharePreferencesUtils.getInstance().getInt(key, 0) + 1;
    SharePreferencesUtils.getInstance().saveInt(key, count);
    Intent mIntent = new Intent();
    mIntent.setClass(MainActivity.this, CustomToastActivity.class);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
      mIntent.putExtra("transition", TransitionEnum.SLIDE.getLabel());
      startActivity(mIntent, ActivityOptions.makeSceneTransitionAnimation(MainActivity.this).toBundle());
    } else {
      startActivity(mIntent);
    }
  }
})
origin: JustinRoom/JSCKit

@Override
public void onCreate() {
  Log.e(TAG, "onCreate()");
  super.onCreate();
  InstanceManager.getInstance().init(this);
  //初始化SharedPreferences工具
  SharePreferencesUtils.getInstance().init(this, "share_data");
  //注册activity生命周期监听
  if (BuildConfig.enableAdvertisementFeature) {
    registerActivityLifecycleCallbacks(activityLifecycleCallbacks);
    //启动界面不显示广告页
    addToAdvertisementFilter(LaunchActivity.class);
    addToAdvertisementFilter(AdvertisementViewActivity.class);
  }
}
origin: JustinRoom/JSCKit

/**
 * 后台下载广告图片。下载图片存放在当前应用的cache文件夹下,不需要SD的读写权限
 */
private void downloadPictureIfNecessary(){
  File directory = new File(Environment.getExternalStorageDirectory(), Environment.DIRECTORY_PICTURES);
  String[] splits = url.split(File.separator);
  String fileName = "advertisement" + File.separator + splits[splits.length - 1];
  File pic = new File(directory, fileName);
  SharePreferencesUtils.getInstance().saveString(Configration.SP_ADVERTISEMENT_PICTURE, pic.getPath());
  if (!pic.exists()){
    DownloadEntity entity = new DownloadEntity();
    entity.setUrl(url);
    entity.setDestinationDirectory(directory);
    entity.setSubPath(fileName);
    entity.setTitle("Download advertisement picture");
    entity.setDesc("");
    entity.setMimeType("image/jpeg");
    fileDownloader.downloadFile(entity);
  }
}
origin: JustinRoom/JSCKit

String picPathName = SharePreferencesUtils.getInstance().getString(Configration.SP_ADVERTISEMENT_PICTURE);
if (new File(picPathName).exists())
  loadPicture(new File(picPathName));
origin: JustinRoom/JSCKit

private void showGuideDialog(final String key) {
  final int showCount = SharePreferencesUtils.getInstance().getInt(key, 0);
  if (showCount >= 3)
    return;
origin: JustinRoom/JSCKit

private void showGuidePopupView(final String key) {
  final int showCount = SharePreferencesUtils.getInstance().getInt(key, 0);
  if (showCount >= 3)
    return;
origin: JustinRoom/JSCKit

public Float getFloat(String key, Float... defValue) {
  checkIsInit();
  if (defValue.length > 0)
    return sharedPreferences.getFloat(key, defValue[0]);
  else
    return sharedPreferences.getFloat(key, 0.0f);
}
origin: JustinRoom/JSCKit

public String getString(String key, String... defValue) {
  checkIsInit();
  if (defValue.length > 0)
    return sharedPreferences.getString(key, defValue[0]);
  else
    return sharedPreferences.getString(key, "");
}
origin: JustinRoom/JSCKit

public Boolean getBoolean(String key, Boolean... defValue) {
  checkIsInit();
  if (defValue.length > 0)
    return sharedPreferences.getBoolean(key, defValue[0]);
  else
    return sharedPreferences.getBoolean(key, false);
}
origin: JustinRoom/JSCKit

public Long getLong(String key, Long... defValue) {
  checkIsInit();
  if (defValue.length > 0)
    return sharedPreferences.getLong(key, defValue[0]);
  else
    return sharedPreferences.getLong(key, 0L);
}
origin: JustinRoom/JSCKit

public void saveLong(String key, Long value) {
  checkIsInit();
  sharedPreferences.edit().putLong(key, value).apply();
}
origin: JustinRoom/JSCKit

public void saveBoolean(String key, Boolean value) {
  checkIsInit();
  sharedPreferences.edit().putBoolean(key, value).apply();
}
origin: JustinRoom/JSCKit

public void saveString(String key, String value) {
  checkIsInit();
  sharedPreferences.edit().putString(key, value).apply();
}
origin: JustinRoom/JSCKit

public void delete(String key) {
  checkIsInit();
  sharedPreferences.edit().remove(key).apply();
}
origin: JustinRoom/JSCKit

public void saveFloat(String key, Float value) {
  checkIsInit();
  sharedPreferences.edit().putFloat(key, value).apply();
}
jsc.kit.component.utilsSharePreferencesUtils

Javadoc


Email:1006368252@qq.com
QQ:1006368252
https://github.com/JustinRoom/JSCKit

Most used methods

  • <init>
  • checkIsInit
  • getInstance
  • getInt
  • getLong
  • getString
  • init
  • saveInt
  • saveLong
  • saveString

Popular in Java

  • Making http post requests using okhttp
  • getContentResolver (Context)
  • scheduleAtFixedRate (Timer)
    Schedules the specified task for repeated fixed-rate execution, beginning after the specified delay.
  • getOriginalFilename (MultipartFile)
    Return the original filename in the client's filesystem.This may contain path information depending
  • Window (java.awt)
    A Window object is a top-level window with no borders and no menubar. The default layout for a windo
  • BufferedWriter (java.io)
    Wraps an existing Writer and buffers the output. Expensive interaction with the underlying reader is
  • PrintWriter (java.io)
    Prints formatted representations of objects to a text-output stream. This class implements all of th
  • MessageDigest (java.security)
    Uses a one-way hash function to turn an arbitrary number of bytes into a fixed-length byte sequence.
  • Format (java.text)
    The base class for all formats. This is an abstract base class which specifies the protocol for clas
  • Collections (java.util)
    This class consists exclusively of static methods that operate on or return collections. It contains
Codota Logo
  • Products

    Search for Java codeSearch for JavaScript codeEnterprise
  • IDE Plugins

    IntelliJ IDEAWebStormAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogCodota Academy Plugin user guide Terms of usePrivacy policyJava Code IndexJavascript Code Index
Get Codota for your IDE now