• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

Java DefaultWXStorage类的典型用法和代码示例

java 2次浏览

本文整理汇总了Java中com.taobao.weex.appfram.storage.DefaultWXStorage的典型用法代码示例。如果您正苦于以下问题:Java DefaultWXStorage类的具体用法?Java DefaultWXStorage怎么用?Java DefaultWXStorage使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。

DefaultWXStorage类属于com.taobao.weex.appfram.storage包,在下文中一共展示了DefaultWXStorage类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: fetch

点赞 2

import com.taobao.weex.appfram.storage.DefaultWXStorage; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public void fetch(@Nullable final OnLoadListener listener) {
    if (listener == null) {
        return;
    }

    if (mStorageAdapter == null) {
        listener.onLoad(Collections.<StorageInfo>emptyList());
        return;
    }

    if (!(mStorageAdapter instanceof DefaultWXStorage)) {
        listener.onLoad(Collections.<StorageInfo>emptyList());
        return;
    }

    if (isDestroy()) {
        listener.onLoad(Collections.<StorageInfo>emptyList());
        return;
    }

    mExecutor.execute(new Runnable() {
        @Override
        public void run() {
            final List<StorageInfo> resultList = new ArrayList<>();
            WXSQLiteOpenHelper helper = null;
            Cursor c = null;
            try {
                Constructor<WXSQLiteOpenHelper> constructor = WXSQLiteOpenHelper.class.getDeclaredConstructor(Context.class);
                constructor.setAccessible(true);
                helper = constructor.newInstance(mContext);

                Method method = WXSQLiteOpenHelper.class.getDeclaredMethod("getDatabase");
                method.setAccessible(true);
                SQLiteDatabase db = (SQLiteDatabase) method.invoke(helper);

                c = db.query("default_wx_storage", new String[]{"key", "value", "timestamp"}, null, null, null, null, null);

                if (isDebug) {
                    Log.d("weex-analyzer", "start dump weex storage");
                }

                while (c.moveToNext()) {
                    StorageInfo info = new StorageInfo();
                    info.key = c.getString(c.getColumnIndex("key"));
                    info.value = c.getString(c.getColumnIndex("value"));
                    info.timestamp = c.getString(c.getColumnIndex("timestamp"));
                    if (isDebug) {
                        Log.d("weex-analyzer", "weex storage[" + info.key + " | " + info.value + "]");
                    }
                    resultList.add(info);
                }

                if (isDebug) {
                    Log.d("weex-analyzer", "end dump weex storage");
                }

                //we may be killed by user
                if (mHandler != null) {
                    mHandler.post(new Runnable() {
                        @Override
                        public void run() {
                            listener.onLoad(resultList);
                        }
                    });
                }

            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                if (c != null) {
                    c.close();
                }
                if (helper != null) {
                    helper.closeDatabase();
                }
            }
        }
    });
}
 

开发者ID:weexteam,
项目名称:weex-analyzer-android,
代码行数:81,
代码来源:StorageHacker.java

示例2: remove

点赞 2

import com.taobao.weex.appfram.storage.DefaultWXStorage; //导入依赖的package包/类
public void remove(@Nullable final String key, @Nullable final OnRemoveListener listener) {
    if (listener == null || TextUtils.isEmpty(key)) {
        return;
    }

    if (mStorageAdapter == null) {
        listener.onRemoved(false);
        return;
    }

    if (!(mStorageAdapter instanceof DefaultWXStorage)) {
        listener.onRemoved(false);
        return;
    }

    if (isDestroy()) {
        listener.onRemoved(false);
        return;
    }

    mExecutor.execute(new Runnable() {
        @Override
        public void run() {
            try {
                DefaultWXStorage storage = (DefaultWXStorage) mStorageAdapter;
                Method method = storage.getClass().getDeclaredMethod("performRemoveItem", String.class);
                if (method != null) {
                    method.setAccessible(true);
                    final boolean result = (boolean) method.invoke(storage, key);
                    if (mHandler != null) {
                        mHandler.post(new Runnable() {
                            @Override
                            public void run() {
                                listener.onRemoved(result);
                            }
                        });
                        method.setAccessible(false);
                    }
                }

            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
}
 

开发者ID:weexteam,
项目名称:weex-analyzer-android,
代码行数:47,
代码来源:StorageHacker.java


版权声明:本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。
喜欢 (0)