Skip to content

Commit

Permalink
add shared preference module
Browse files Browse the repository at this point in the history
  • Loading branch information
huzongyao committed Feb 26, 2019
1 parent d999875 commit 78d8d74
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 3 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ A Weex android framework just based like weex playground based on weex sdk
* Add imagePicker module to pick some images
* Add qrCode module to scan and generate QR code

### 自定义模块说明
* imagePicker 从图库选择图片或者拍照
* qrCode 生成二维码或者打开扫码页面
* preference 对名为wxPreference的SharedPreference进行增删改查

### About Me
* GitHub: [http://huzongyao.github.io/](http://huzongyao.github.io/)
* ITEye博客:[http://hzy3774.iteye.com/](http://hzy3774.iteye.com/)
Expand Down
6 changes: 3 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ android {
applicationId "com.hzy.weex.frame"
minSdkVersion 15
targetSdkVersion 28
versionCode 1_00_01
versionName "1.0.1"
versionCode 1_00_02
versionName "1.0.2"
ndk {
abiFilters 'armeabi-v7a'
}
Expand Down Expand Up @@ -66,7 +66,7 @@ dependencies {
implementation 'com.taobao.android:weex_sdk:0.20.0.2'
implementation 'cn.bingoogolapple:bga-qrcode-zxing:1.3.6'
implementation 'com.squareup.okhttp3:okhttp:3.12.1'
implementation 'com.blankj:utilcode:1.23.4'
implementation 'com.blankj:utilcode:1.23.5'
implementation 'com.github.bumptech.glide:glide:4.8.0'
implementation 'com.github.bumptech.glide:okhttp3-integration:4.8.0'
implementation('com.alibaba:arouter-api:1.4.1') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.hzy.weex.frame.weex.module.component.RichText;
import com.hzy.weex.frame.weex.module.imgpicker.ImagePickerModule;
import com.hzy.weex.frame.weex.module.location.GeolocationModule;
import com.hzy.weex.frame.weex.module.prefrence.SharedPreferenceModule;
import com.hzy.weex.frame.weex.module.qrcode.QRCodeModule;
import com.taobao.weex.WXSDKEngine;

Expand All @@ -15,7 +16,10 @@ public static void initialize() {
WXSDKEngine.registerModule("imagePicker", ImagePickerModule.class);
// 覆盖原来的WXNavigatorModule, 防止intent category和别人的一样
WXSDKEngine.registerModule("navigator", ExNavigatorModule.class);
// 二维码相关模块
WXSDKEngine.registerModule("qrCode", QRCodeModule.class);
// SharedPreference相关模块
WXSDKEngine.registerModule("preference", SharedPreferenceModule.class);
} catch (Exception e) {
e.printStackTrace();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.hzy.weex.frame.weex.module.prefrence;

import android.content.Context;

import com.blankj.utilcode.util.SPUtils;
import com.taobao.weex.annotation.JSMethod;
import com.taobao.weex.common.WXModule;

public class SharedPreferenceModule extends WXModule {

private final SPUtils mSPUtils;

public SharedPreferenceModule() {
mSPUtils = SPUtils.getInstance("wxPreference", Context.MODE_PRIVATE);
}

@JSMethod
@SuppressWarnings("unused")
public void put(String key, String value) {
mSPUtils.put(key, value);
}

@JSMethod
@SuppressWarnings("unused")
public String get(String key) {
return mSPUtils.getString(key);
}

@JSMethod
@SuppressWarnings("unused")
public void clear() {
mSPUtils.clear();
}

@JSMethod
@SuppressWarnings("unused")
public void remove(String key) {
mSPUtils.remove(key);
}
}

0 comments on commit 78d8d74

Please sign in to comment.