当前位置: 首页>>代码示例>>Java>>正文


Java TrayItem类代码示例

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


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

示例1: importSharedPreferencesWithLogging

import net.grandcentrix.tray.core.TrayItem; //导入依赖的package包/类
/**
 * logging wrapper for:
 * example how to import shared preferences
 */
private void importSharedPreferencesWithLogging() {
    final SharedPreferences sharedPreferences = getContext()
            .getSharedPreferences(SampleActivity.SHARED_PREF_NAME,
                    Context.MODE_MULTI_PROCESS);

    final HashMap<String, ?> allBefore = new HashMap<>(sharedPreferences.getAll());
    Log.v(TAG, allBefore.size() + " items in sharedPreferences: " + allBefore.toString());
    // 2 items in sharedPreferences: {userToken=cf26535a-6949-4728-b595-c6d80c094eff, gcmToken=2ca7e9a0-9114-4d55-8d2d-870b8d49fafe}
    importSharedPreferences();

    final ArrayList<TrayItem> all = new ArrayList<>(getAll());

    Log.v(TAG, "imported " + all.size() + " items: " + all.toString());
    // imported 2 items: [
    // {key: gcm:token, value: 2ca7e9a0-9114-4d55-8d2d-870b8d49fafe, module: imported, created: 14:06:04 05.06.2015, updated: 14:06:04 05.06.2015, migratedKey: gcmToken},
    // {key: user:token, value: cf26535a-6949-4728-b595-c6d80c094eff, module: imported, created: 14:06:04 05.06.2015, updated: 14:06:04 05.06.2015, migratedKey: userToken}
    // ]

    final HashMap<String, ?> allAfter = new HashMap<>(sharedPreferences.getAll());
    Log.v(TAG, allAfter.size() + " items in sharedPreferences: " + allAfter.toString());
    // 0 items in sharedPreferences: {}
}
 
开发者ID:grandcentrix,项目名称:tray,代码行数:27,代码来源:ImportTrayPreferences.java

示例2: get

import net.grandcentrix.tray.core.TrayItem; //导入依赖的package包/类
@Override
@Nullable
public TrayItem get(@NonNull final String key) {
    final Uri uri = mTrayUri.builder()
            .setType(getType())
            .setModule(getModuleName())
            .setKey(key)
            .build();
    final List<TrayItem> prefs = mProviderHelper.queryProviderSafe(uri);
    final int size = prefs.size();
    if (size > 1) {
        TrayLog.w("found more than one item for key '" + key
                + "' in module " + getModuleName() + ". "
                + "This can be caused by using the same name for a device and user specific preference.");
        for (int i = 0; i < prefs.size(); i++) {
            final TrayItem pref = prefs.get(i);
            TrayLog.d("item #" + i + " " + pref);
        }
    }
    return size > 0 ? prefs.get(0) : null;
}
 
开发者ID:grandcentrix,项目名称:tray,代码行数:22,代码来源:ContentProviderStorage.java

示例3: queryProvider

import net.grandcentrix.tray.core.TrayItem; //导入依赖的package包/类
/**
 * sends a query for TrayItems to the provider
 *
 * @param uri path to data
 * @return list of items
 * @throws TrayException when something is wrong with the provider/database
 */
@NonNull
public List<TrayItem> queryProvider(@NonNull final Uri uri) throws TrayException {
    final Cursor cursor;
    try {
        cursor = mContext.getContentResolver().query(uri, null, null, null, null);
    } catch (Throwable e) {
        throw new TrayException("Hard error accessing the ContentProvider", e);
    }

    // Return Preference if found
    if (cursor == null) {
        // When running in here, please check if your ContentProvider has the correct authority
        throw new TrayException("could not access stored data with uri " + uri);
    }

    final ArrayList<TrayItem> list = new ArrayList<>();
    for (boolean hasItem = cursor.moveToFirst(); hasItem; hasItem = cursor.moveToNext()) {
        final TrayItem trayItem = cursorToTrayItem(cursor);
        list.add(trayItem);
    }
    cursor.close();
    return list;
}
 
开发者ID:grandcentrix,项目名称:tray,代码行数:31,代码来源:TrayProviderHelper.java

示例4: cursorToTrayItem

import net.grandcentrix.tray.core.TrayItem; //导入依赖的package包/类
/**
 * converts a {@link Cursor} to a {@link TrayItem}
 * <p>
 * This is not a secondary constructor in {@link TrayItem} because the columns are a
 * implementation detail of the provider package
 *
 * @param cursor (size > 1)
 * @return a {@link TrayItem} filled with data
 */
@NonNull
static TrayItem cursorToTrayItem(final Cursor cursor) {
    final String module = cursor.getString(cursor
            .getColumnIndexOrThrow(TrayContract.Preferences.Columns.MODULE));
    final String key = cursor.getString(cursor
            .getColumnIndexOrThrow(TrayContract.Preferences.Columns.KEY));
    final String migratedKey = cursor.getString(cursor
            .getColumnIndexOrThrow(TrayContract.Preferences.Columns.MIGRATED_KEY));
    final String value = cursor.getString(cursor
            .getColumnIndexOrThrow(TrayContract.Preferences.Columns.VALUE));
    final Date created = new Date(cursor.getLong(cursor
            .getColumnIndexOrThrow(TrayContract.Preferences.Columns.CREATED)));
    final Date updated = new Date(cursor.getLong(cursor
            .getColumnIndexOrThrow(TrayContract.Preferences.Columns.UPDATED)));
    return new TrayItem(module, key, migratedKey, value, created, updated);
}
 
开发者ID:grandcentrix,项目名称:tray,代码行数:26,代码来源:TrayProviderHelper.java

示例5: testUnregister

import net.grandcentrix.tray.core.TrayItem; //导入依赖的package包/类
public void testUnregister() throws Exception {
    final OnTrayPreferenceChangeListener listener = new OnTrayPreferenceChangeListener() {
        @Override
        public void onTrayPreferenceChanged(final Collection<TrayItem> items) {

        }
    };
    final ContentProviderStorage userStorage = checkChangeListener(true, listener);
    assertEquals(1, userStorage.mListeners.size());

    // unregister null should do nothing
    userStorage.unregisterOnTrayPreferenceChangeListener(null);
    assertEquals(1, userStorage.mListeners.size());

    userStorage.unregisterOnTrayPreferenceChangeListener(listener);
    assertEquals(0, userStorage.mListeners.size());
    assertNull(userStorage.mObserver);
    assertNull(userStorage.mObserverThread);

}
 
开发者ID:grandcentrix,项目名称:tray,代码行数:21,代码来源:ChangedListenerTest.java

示例6: testUpdateChanges

import net.grandcentrix.tray.core.TrayItem; //导入依赖的package包/类
public void testUpdateChanges() throws Exception {
    assertTrue(mProviderHelper.persist(MODULE_A, KEY_A, STRING_A));
    final List<TrayItem> list = mProviderHelper
            .queryProvider(getUri(MODULE_A, KEY_A));
    assertNotNull(list);
    assertEquals(1, list.size());
    TrayItem itemA = list.get(0);
    assertNotNull(itemA.created());
    assertNotNull(itemA.updateTime());

    Thread.sleep(10);
    assertTrue(mProviderHelper.persist(MODULE_A, KEY_A, STRING_B));
    final List<TrayItem> list2 = mProviderHelper
            .queryProvider(getUri(MODULE_A, KEY_A));
    assertNotNull(list2);
    assertEquals(1, list2.size());
    TrayItem itemB = list2.get(0);
    //Log.v("", "diff: " + (itemA.updateTime().getTime() - itemB.updateTime().getTime()));
    assertNotSame(itemA.updateTime().getTime(), itemB.updateTime().getTime());
}
 
开发者ID:grandcentrix,项目名称:tray,代码行数:21,代码来源:TrayProviderHelperTest.java

示例7: getAll

import net.grandcentrix.tray.core.TrayItem; //导入依赖的package包/类
public Map<String, ?> getAll() {
    Map<String, Object> newMap = null;
    Collection<TrayItem> itemCollection = appPreferences.getAll();
    if (itemCollection != null && itemCollection.size() > 0) {
        newMap = new HashMap<>();
        for (TrayItem trayItem : itemCollection) {
            Object value = (Object)trayItem.value();
            newMap.put(trayItem.key(), value);
        }
    }
    return newMap;
}
 
开发者ID:draekko-rand,项目名称:traypreferences,代码行数:13,代码来源:TraySharedPreferencesImpl.java

示例8: getNiceString

import net.grandcentrix.tray.core.TrayItem; //导入依赖的package包/类
private List<String> getNiceString(final Collection<TrayItem> items) {
    return Observable.from(items)
            .map(new Func1<TrayItem, String>() {
                @Override
                public String call(final TrayItem trayItem) {
                    return "key: '" + trayItem.key() + "' value '" + trayItem.value() + "'";
                }
            })
            .toList().toBlocking().first();
}
 
开发者ID:grandcentrix,项目名称:tray,代码行数:11,代码来源:SampleActivity.java

示例9: onChange

import net.grandcentrix.tray.core.TrayItem; //导入依赖的package包/类
@Override
public void onChange(final boolean selfChange, Uri uri) {
    if (uri == null) {
        // for sdk version 15 and below we cannot detect which exact data was changed. This will
        // return all data for this module
        uri = mTrayUri.builder().setModule(getModuleName()).build();
    }

    // query only the changed items
    final List<TrayItem> trayItems = mProviderHelper.queryProviderSafe(uri);

    // clone to get around ConcurrentModificationException
    final Set<Map.Entry<OnTrayPreferenceChangeListener, Handler>> entries
            = new HashSet<>(mListeners.entrySet());

    // notify all registered listeners
    for (final Map.Entry<OnTrayPreferenceChangeListener, Handler> entry : entries) {
        final OnTrayPreferenceChangeListener listener = entry.getKey();
        final Handler handler = entry.getValue();
        if (handler != null) {
            // call the listener on the thread where the listener was registered
            handler.post(new Runnable() {
                @Override
                public void run() {
                    listener.onTrayPreferenceChanged(trayItems);
                }
            });
        } else {
            listener.onTrayPreferenceChanged(trayItems);
        }
    }
}
 
开发者ID:grandcentrix,项目名称:tray,代码行数:33,代码来源:ContentProviderStorage.java

示例10: annex

import net.grandcentrix.tray.core.TrayItem; //导入依赖的package包/类
@Override
public void annex(final TrayStorage oldStorage) {
    for (final TrayItem trayItem : oldStorage.getAll()) {
        put(trayItem);
    }
    // ignore result
    oldStorage.wipe();
}
 
开发者ID:grandcentrix,项目名称:tray,代码行数:9,代码来源:ContentProviderStorage.java

示例11: getAll

import net.grandcentrix.tray.core.TrayItem; //导入依赖的package包/类
@NonNull
@Override
public Collection<TrayItem> getAll() {
    final Uri uri = mTrayUri.builder()
            .setType(getType())
            .setModule(getModuleName())
            .build();
    return mProviderHelper.queryProviderSafe(uri);
}
 
开发者ID:grandcentrix,项目名称:tray,代码行数:10,代码来源:ContentProviderStorage.java

示例12: getVersion

import net.grandcentrix.tray.core.TrayItem; //导入依赖的package包/类
@Override
public int getVersion() throws TrayException {
    final Uri internalUri = mTrayUri.builder()
            .setInternal(true)
            .setType(getType())
            .setModule(getModuleName())
            .setKey(VERSION)
            .build();
    final List<TrayItem> trayItems = mProviderHelper.queryProvider(internalUri);
    if (trayItems.size() == 0) {
        // fallback, not found
        return 0;
    }
    return Integer.valueOf(trayItems.get(0).value());
}
 
开发者ID:grandcentrix,项目名称:tray,代码行数:16,代码来源:ContentProviderStorage.java

示例13: queryProviderSafe

import net.grandcentrix.tray.core.TrayItem; //导入依赖的package包/类
/**
 * sends a query for TrayItems to the provider, doesn't throw when the database access couldn't
 * be established
 *
 * @param uri path to data
 * @return list of items, empty when an error occured
 */
@NonNull
public List<TrayItem> queryProviderSafe(@NonNull final Uri uri) {
    try {
        return queryProvider(uri);
    } catch (TrayException e) {
        return new ArrayList<>();
    }
}
 
开发者ID:grandcentrix,项目名称:tray,代码行数:16,代码来源:TrayProviderHelper.java

示例14: annex

import net.grandcentrix.tray.core.TrayItem; //导入依赖的package包/类
@Override
public void annex(final TrayStorage oldStorage) {
    for (final TrayItem trayItem : oldStorage.getAll()) {
        mData.put(trayItem.key(), trayItem);
    }
    oldStorage.wipe();
}
 
开发者ID:grandcentrix,项目名称:tray,代码行数:8,代码来源:MockTrayStorage.java

示例15: testSaveNullAsString

import net.grandcentrix.tray.core.TrayItem; //导入依赖的package包/类
public void testSaveNullAsString() throws Exception {
    assertEquals("default", mPref.getString(KEY, "default"));
    mPref.put(KEY, null);
    final TrayItem pref = mPref.getPref(KEY);
    assertNotNull(pref);
    assertEquals(null, pref.value());
    assertEquals(null, mPref.getString(KEY));
}
 
开发者ID:grandcentrix,项目名称:tray,代码行数:9,代码来源:SaveNull.java


注:本文中的net.grandcentrix.tray.core.TrayItem类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。