/** * Drives the selection of the AgeSet Kit for a Player Character when relevant changes (change to * an AgeSet) are made to a Player Character. * * <p>Triggered when one of the Facets to which AgeSetKitFacet listens fires a * DataFacetChangeEvent to indicate a CDOMObject was added to a Player Character. * * @param dfce The DataFacetChangeEvent containing the information about the change * @see * pcgen.cdom.facet.event.DataFacetChangeListener#dataAdded(pcgen.cdom.facet.event.DataFacetChangeEvent) */ @Override public void dataAdded(DataFacetChangeEvent<CharID, Integer> dfce) { CharID id = dfce.getCharID(); AgeSet ageSet = ageSetFacet.get(id); PlayerCharacter pc = trackingFacet.getPC(id); // TODO Is ageSet null check necessary? if (ageSet == null || pc.isImporting()) { return; } int ageSetIndex = ageSetFacet.getAgeSetIndex(id); /* * TODO The method of storing what AgeSets have had kit selections made * should be converted to store the actual AgeSet rather than the index, * in order to reduce the number of calls to ageSetFacet.getAgeSetIndex. * This (of course) drives the move of the AgeSets for which a kit * selection has been made into a Facet. It is possible that the * CacheInfo of AgeSetKitFacet is actually a good place to store that * information (or it may be implicit with the information already * stored there??) */ if (!pc.hasMadeKitSelectionForAgeSet(ageSetIndex)) { CacheInfo cache = getConstructingClassInfo(id); List<Kit> kits = cache.get(ageSet); if (kits != null) { // Need to do selection BioSet bioSet = bioSetFacet.get(id); for (TransitionChoice<Kit> kit : ageSet.getKits()) { Collection<? extends Kit> choice = kit.driveChoice(pc); cache.put(ageSet, choice); kit.act(choice, bioSet, pc); } } pc.setHasMadeKitSelectionForAgeSet(ageSetIndex, true); } }
public static void removeDataBaseCache(String classMethodString) { Realm realm = Realm.getInstance(sContext); CacheInfo info = realm.where(CacheInfo.class).equalTo("key", classMethodString).findFirst(); if (info != null) { info.removeFromRealm(); } realm.close(); }
@Test public void lastVerifiedOnlyExtract() { final DateTime now = DateTime.now(); NestedAttributesMap attributes = new NestedAttributesMap(P_ATTRIBUTES, Maps.<String, Object>newHashMap()); attributes.child(CacheInfo.CACHE).set(CacheInfo.LAST_VERIFIED, now.toDate()); Asset asset = mock(Asset.class); when(asset.attributes()).thenReturn(attributes); CacheInfo cacheInfo = CacheInfo.extractFromAsset(asset); assertThat(cacheInfo, notNullValue()); assertThat(cacheInfo.getLastVerified(), equalTo(now)); }
/** Returns a <code>CacheConfigRequest</code>. */ public static CacheConfigRequest create(CacheInfo c, int attCode, int v) { CacheConfigRequest m = new CacheConfigRequest(); m.attributeCode = (byte) attCode; m.newValue = v; m.cacheId = c.getId(); return m; }
@Test public void nothingToExtract() { NestedAttributesMap attributes = new NestedAttributesMap(P_ATTRIBUTES, Maps.<String, Object>newHashMap()); Asset asset = mock(Asset.class); when(asset.attributes()).thenReturn(attributes); CacheInfo cacheInfo = CacheInfo.extractFromAsset(asset); assertThat(cacheInfo, nullValue()); }
@Test public void cacheTokenOnlyExtract() { final String cacheToken = "foo-bar"; NestedAttributesMap attributes = new NestedAttributesMap(P_ATTRIBUTES, Maps.<String, Object>newHashMap()); attributes.child(CacheInfo.CACHE).set(CacheInfo.CACHE_TOKEN, cacheToken); Asset asset = mock(Asset.class); when(asset.attributes()).thenReturn(attributes); CacheInfo cacheInfo = CacheInfo.extractFromAsset(asset); assertThat(cacheInfo, nullValue()); }
@Override public void onGetStatsCompleted(PackageStats pStats, boolean succeeded) throws RemoteException { // System.out.println("ongetstatscompleted"); long cacheSize = pStats.cacheSize; if (cacheSize > 0) { // System.out.println("cache: "+ cacheSize); CacheInfo cacheInfo = new CacheInfo(); Drawable icon = mInfo.applicationInfo.loadIcon(packageManager); cacheInfo.icon = icon; String appName = mInfo.applicationInfo.loadLabel(packageManager).toString(); cacheInfo.appName = appName; cacheInfo.cacheSize = cacheSize; String packageName = mInfo.applicationInfo.packageName; cacheInfo.pkgName = packageName; mCacheList.add(cacheInfo); if (mAdapter != null) { mAdapter.notifyDataSetChanged(); } } // System.out.println("no cache"); }
@Test public void lastVerifiedAndCacheTokenApply() { final DateTime now = DateTime.now(); final String cacheToken = "foo-bar"; NestedAttributesMap attributes = new NestedAttributesMap(P_ATTRIBUTES, Maps.<String, Object>newHashMap()); Asset asset = mock(Asset.class); when(asset.attributes()).thenReturn(attributes); CacheInfo cacheInfo = new CacheInfo(now, cacheToken); CacheInfo.applyToAsset(asset, cacheInfo); assertThat( asset.attributes().child(CacheInfo.CACHE).get(CacheInfo.LAST_VERIFIED, Date.class), equalTo(now.toDate())); assertThat( asset.attributes().child(CacheInfo.CACHE).get(CacheInfo.CACHE_TOKEN, String.class), equalTo(cacheToken)); }
/** * @param url * @param context * @param requireNewTask set this to true if context is not an Activity * @param bypassParser * @param useExternalBrowser */ public static void launchBrowser( Context context, String url, String threadUrl, boolean requireNewTask, boolean bypassParser, boolean useExternalBrowser, boolean saveHistory) { try { if (saveHistory) { Browser.updateVisitedHistory(context.getContentResolver(), url, true); } } catch (Exception ex) { if (Constants.LOGGING) Log.i(TAG, "Browser.updateVisitedHistory error", ex); } Uri uri = Uri.parse(url); if (!bypassParser) { if (Util.isRedditUri(uri)) { String path = uri.getPath(); Matcher matcher = COMMENT_LINK.matcher(path); if (matcher.matches()) { if (matcher.group(3) != null || matcher.group(2) != null) { CacheInfo.invalidateCachedThread(context); Intent intent = new Intent(context, CommentsListActivity.class); intent.setData(uri); intent.putExtra(Constants.EXTRA_NUM_COMMENTS, Constants.DEFAULT_COMMENT_DOWNLOAD_LIMIT); if (requireNewTask) intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); Activity ac = (Activity) context; ac.startActivityForResult(intent, 0); return; } } matcher = REDDIT_LINK.matcher(path); if (matcher.matches()) { CacheInfo.invalidateCachedSubreddit(context); Intent intent = new Intent(context, ThreadsListActivity.class); intent.setData(uri); if (requireNewTask) intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); Activity ac = (Activity) context; ac.startActivityForResult(intent, 0); return; } matcher = USER_LINK.matcher(path); if (matcher.matches()) { Intent intent = new Intent(context, ProfileActivity.class); intent.setData(uri); if (requireNewTask) intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); Activity ac = (Activity) context; ac.startActivityForResult(intent, 0); return; } } else if (Util.isRedditShortenedUri(uri)) { String path = uri.getPath(); if (path.equals("") || path.equals("/")) { CacheInfo.invalidateCachedSubreddit(context); Intent intent = new Intent(context, ThreadsListActivity.class); intent.setData(uri); if (requireNewTask) intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); Activity ac = (Activity) context; ac.startActivityForResult(intent, 0); } else { // Assume it points to a thread aka CommentsList CacheInfo.invalidateCachedThread(context); Intent intent = new Intent(context, CommentsListActivity.class); intent.setData(uri); intent.putExtra(Constants.EXTRA_NUM_COMMENTS, Constants.DEFAULT_COMMENT_DOWNLOAD_LIMIT); if (requireNewTask) intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); Activity ac = (Activity) context; ac.startActivityForResult(intent, 0); } return; } } uri = Util.optimizeMobileUri(uri); // Some URLs should always be opened externally, if BrowserActivity doesn't support their // content. if (Util.isYoutubeUri(uri) || Util.isAndroidMarketUri(uri)) useExternalBrowser = true; if (useExternalBrowser) { Intent browser = new Intent(Intent.ACTION_VIEW, uri); browser.putExtra(Browser.EXTRA_APPLICATION_ID, context.getPackageName()); if (requireNewTask) browser.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); Activity ac = (Activity) context; ac.startActivityForResult(browser, 0); } else { Intent browser = new Intent(context, BrowserActivity.class); browser.setData(uri); if (threadUrl != null) browser.putExtra(Constants.EXTRA_THREAD_URL, threadUrl); if (requireNewTask) browser.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); Activity ac = (Activity) context; ac.startActivityForResult(browser, 0); } }
public static void doLogout(RedditSettings settings, HttpClient client, Context context) { clearCookies(settings, client, context); CacheInfo.invalidateAllCaches(context); settings.setUsername(null); }