androidx.collection.ArrayMap Java Examples

The following examples show how to use androidx.collection.ArrayMap. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RecyclerViewLinearItemDecoration.java    From RecyclerViewDecoration with Apache License 2.0 6 votes vote down vote up
public void setParams(Context context, Param params) {

        this.mContext = context;

        this.mDrawableRid = params.drawableRid;
        this.mColor = params.color;
        this.mThickness = params.thickness;
        this.mDashGap = params.dashGap;
        this.mDashWidth = params.dashWidth;
        this.mPaddingStart = params.paddingStart;
        this.mPaddingEnd = params.paddingEnd;
        this.mFirstLineVisible = params.firstLineVisible;
        this.mLastLineVisible = params.lastLineVisible;
        if (params.ignoreTypes != null && params.ignoreTypes.length != 0) {
            this.mIgnoreTypes = new ArrayMap<>();
            int ignoreTypeSize = params.ignoreTypes.length;
            for (int i = 0; i < ignoreTypeSize; i++) {
                this.mIgnoreTypes.put(params.ignoreTypes[i], params.ignoreTypes[i]);
            }
        }

    }
 
Example #2
Source File: HealthStatsMetricsSerializerTest.java    From Battery-Metrics with MIT License 6 votes vote down vote up
private HealthStatsMetrics createTestMetricsWithoutStats() {
  HealthStatsMetrics metrics = new HealthStatsMetrics();
  metrics.dataType = "test";

  metrics.measurement.put(123, 1000L);
  metrics.measurement.put(345, 1001L);

  metrics.measurements.put(234, new ArrayMap<String, Long>());
  metrics.measurements.get(234).put("measurements", 2000L);
  metrics.measurements.put(345, new ArrayMap<String, Long>());
  metrics.measurements.get(345).put("measurements_second", 3000L);

  metrics.timer.put(345, new HealthStatsMetrics.TimerMetrics(5, 2000));
  metrics.timer.put(123, new HealthStatsMetrics.TimerMetrics(8, 9000));

  ArrayMap<String, HealthStatsMetrics.TimerMetrics> timersValues = new ArrayMap<>();
  timersValues.put("timers", new HealthStatsMetrics.TimerMetrics(6, 3000));
  metrics.timers.put(456, timersValues);

  ArrayMap<String, HealthStatsMetrics.TimerMetrics> secondTimers = new ArrayMap<>();
  timersValues.put("timers_two", new HealthStatsMetrics.TimerMetrics(7, 8000));
  metrics.timers.put(123, timersValues);

  return metrics;
}
 
Example #3
Source File: HealthStatsMetricsTest.java    From Battery-Metrics with MIT License 6 votes vote down vote up
@Test
public void timersToJSON() throws Exception {
  HealthStatsMetrics metrics = new HealthStatsMetrics();
  metrics.timers.put(345, new ArrayMap<String, HealthStatsMetrics.TimerMetrics>());
  metrics.timers.get(345).put("val", new HealthStatsMetrics.TimerMetrics(23, 24));
  JSONObject json = metrics.toJSONObject();
  assertThat(
          json.getJSONObject("timers").getJSONObject("345").getJSONObject("val").getInt("count"))
      .isEqualTo(23);
  assertThat(
          json.getJSONObject("timers")
              .getJSONObject("345")
              .getJSONObject("val")
              .getInt("time_ms"))
      .isEqualTo(24);
}
 
Example #4
Source File: HealthStatsMetricsTest.java    From Battery-Metrics with MIT License 6 votes vote down vote up
@Test
public void testDiff() {
  HealthStatsMetrics a = createTestMetrics();
  HealthStatsMetrics b = createTestMetrics();
  HealthStatsMetrics diff = a.diff(b, null);
  HealthStatsMetrics expectedDiff = new HealthStatsMetrics();
  expectedDiff.dataType = TEST_DATATYPE;
  expectedDiff.measurement.put(123, 0L);
  expectedDiff.measurements.put(234, new ArrayMap<String, Long>());
  expectedDiff.measurements.get(234).put("measurements", 0L);
  expectedDiff.timer.put(345, new HealthStatsMetrics.TimerMetrics(0, 0));
  ArrayMap<String, HealthStatsMetrics.TimerMetrics> timersValues = new ArrayMap<>();
  timersValues.put("timers", new HealthStatsMetrics.TimerMetrics(0, 0));
  expectedDiff.timers.put(456, timersValues);
  ArrayMap<String, HealthStatsMetrics> value = new ArrayMap<>();
  value.put("stats", new HealthStatsMetrics(expectedDiff));
  expectedDiff.stats.put(1234, value);
  assertThat(diff).isEqualTo(expectedDiff);
}
 
Example #5
Source File: HealthStatsMetricsTest.java    From Battery-Metrics with MIT License 6 votes vote down vote up
@Test
public void testSum() {
  HealthStatsMetrics a = createTestMetrics();
  HealthStatsMetrics b = createTestMetrics();
  HealthStatsMetrics sum = a.sum(b, null);
  HealthStatsMetrics expectedSum = new HealthStatsMetrics();
  expectedSum.dataType = TEST_DATATYPE;
  expectedSum.measurement.put(123, 2000L);
  expectedSum.measurements.put(234, new ArrayMap<String, Long>());
  expectedSum.measurements.get(234).put("measurements", 4000L);
  expectedSum.timer.put(345, new HealthStatsMetrics.TimerMetrics(10, 4000));
  ArrayMap<String, HealthStatsMetrics.TimerMetrics> timersValues = new ArrayMap<>();
  timersValues.put("timers", new HealthStatsMetrics.TimerMetrics(12, 6000));
  expectedSum.timers.put(456, timersValues);
  ArrayMap<String, HealthStatsMetrics> value = new ArrayMap<>();
  value.put("stats", new HealthStatsMetrics(expectedSum));
  expectedSum.stats.put(1234, value);
  assertThat(sum).isEqualTo(expectedSum);
}
 
Example #6
Source File: HealthStatsMetricsTest.java    From Battery-Metrics with MIT License 6 votes vote down vote up
@Test
public void testSumArrayMaps() {
  ArrayMap<String, Long> a = new ArrayMap<>();
  a.put("a", 1L);
  a.put("c", 2L);

  ArrayMap<String, Long> b = new ArrayMap<>();
  b.put("b", 1L);
  b.put("c", 3L);

  ArrayMap<String, Long> sum = HealthStatsMetrics.opArrayMaps(OP_SUM, a, b);
  assertThat(sum.get("a")).isEqualTo(1);
  assertThat(sum.get("b")).isEqualTo(1);
  assertThat(sum.get("c")).isEqualTo(5);
  assertThat(sum.size()).isEqualTo(3);
}
 
Example #7
Source File: HealthStatsMetrics.java    From Battery-Metrics with MIT License 6 votes vote down vote up
private void addStats(JSONObject output) throws JSONException {
  JSONObject statsObj = new JSONObject();
  for (int i = 0, count = stats.size(); i < count; i++) {
    JSONObject valueOutput = new JSONObject();
    ArrayMap<String, HealthStatsMetrics> value = stats.valueAt(i);
    for (int j = 0, valueCount = value.size(); j < valueCount; j++) {
      JSONObject v = value.valueAt(j).toJSONObject();
      if (v.length() > 0) {
        valueOutput.put(value.keyAt(j), v);
      }
    }
    if (valueOutput.length() > 0) {
      statsObj.put(getKeyName(stats.keyAt(i)), valueOutput);
    }
  }

  if (statsObj.length() > 0) {
    output.put("stats", statsObj);
  }
}
 
Example #8
Source File: HealthStatsMetrics.java    From Battery-Metrics with MIT License 6 votes vote down vote up
private void addTimers(JSONObject output) throws JSONException {
  JSONObject timersObj = new JSONObject();
  for (int i = 0, count = timers.size(); i < count; i++) {
    JSONObject valueOutput = new JSONObject();
    ArrayMap<String, TimerMetrics> value = timers.valueAt(i);
    for (int j = 0, valueCount = value.size(); j < valueCount; j++) {
      TimerMetrics v = value.valueAt(j);
      if (v.count != 0 || v.timeMs != 0) {
        valueOutput.put(value.keyAt(j), v.toJSONObject());
      }
    }
    if (valueOutput.length() > 0) {
      timersObj.put(getKeyName(timers.keyAt(i)), valueOutput);
    }
  }
  if (timersObj.length() > 0) {
    output.put("timers", timersObj);
  }
}
 
Example #9
Source File: HealthStatsMetrics.java    From Battery-Metrics with MIT License 6 votes vote down vote up
private void addMeasurements(JSONObject output) throws JSONException {
  JSONObject measurementsObj = new JSONObject();
  for (int i = 0, count = measurements.size(); i < count; i++) {
    ArrayMap<String, Long> value = measurements.valueAt(i);
    JSONObject valueOutput = new JSONObject();
    for (int j = 0, valueSize = value.size(); j < valueSize; j++) {
      long v = value.valueAt(j);
      if (v != 0) {
        valueOutput.put(value.keyAt(j), v);
      }
    }

    if (valueOutput.length() > 0) {
      measurementsObj.put(getKeyName(measurements.keyAt(i)), valueOutput);
    }
  }
  if (measurementsObj.length() > 0) {
    output.put("measurements", measurementsObj);
  }
}
 
Example #10
Source File: InitialMigration.java    From zephyr with MIT License 6 votes vote down vote up
@Override
public void migrate(@NonNull SharedPreferences sharedPreferences) {
    boolean didUpgradeFromV1 = sharedPreferences.contains(PreferenceKeys.PREF_V1_FIRST_RUN);

    SharedPreferences.Editor editor = sharedPreferences.edit();
    if (didUpgradeFromV1) {
        Map<String, Boolean> notificationPreferencesToMigrate = new ArrayMap<>();
        for (String key : sharedPreferences.getAll().keySet()) {
            if (key.startsWith(PreferenceKeys.PREF_V1_APP_NOTIF_BASE)) {
                String packageName = key.substring(key.indexOf('-') + 1);
                boolean enabled = sharedPreferences.getBoolean(key, true);
                notificationPreferencesToMigrate.put(packageName, enabled);
            }
        }
        editor.clear();
        editor.putString(PreferenceKeys.PREF_NOTIFICATION_PREF_MIGRATIONS_TO_COMPLETE, new Gson().toJson(notificationPreferencesToMigrate));
    }

    editor.putBoolean(PreferenceKeys.PREF_DID_UPGRADE_FROM_V1, didUpgradeFromV1);
    editor.apply();
}
 
Example #11
Source File: ServiceDetailFragment.java    From BonjourBrowser with Apache License 2.0 6 votes vote down vote up
private void updateIPRecords(BonjourService service) {
    ArrayMap<String, String> metaInfo = new ArrayMap<>();
    for (InetAddress inetAddress : service.getInetAddresses()) {
        if (inetAddress instanceof Inet4Address) {
            metaInfo.put("Address IPv4", service.getInet4Address().getHostAddress() + ":" + service.getPort());
        }
        else {
            metaInfo.put("Address IPv6", service.getInet6Address().getHostAddress() + ":" + service.getPort());
        }
    }
    mAdapter.swapIPRecords(metaInfo);
    mAdapter.notifyDataSetChanged();
    if (isAdded()) {
        ((ServiceDetailListener)getActivity()).onServiceUpdated(mService);
    }
}
 
Example #12
Source File: HighlightGuideView.java    From QuickDevFramework with Apache License 2.0 6 votes vote down vote up
/**
 * 添加目标引导控件
 *
 * @param targetView 目标View,如果没有目标则传入null
 * @param guideView 图片资源Drawable
 * @param width 引导图片宽度
 * @param height 引导图片高度
 * @param relativeX 引导图片相对目标View左上角横向距离
 * @param relativeY 引导图片相对目标View左上角纵向距离
 * */
public HighlightGuideView addGuideView(View targetView, View guideView, int width, int height, int relativeX, int relativeY) {
    if (targetView != null && !mGuideViewsMap.containsKey(targetView.hashCode())) {
        return this;
    }
    LayoutParams lp = new LayoutParams(width, height);
    guideView.setLayoutParams(lp);
    
    Map<String, Integer> paramsMap = new ArrayMap<>();
    paramsMap.put("x", relativeX);
    paramsMap.put("y", relativeY);
    mGuideRelativePosMap.put(guideView.hashCode(), paramsMap);

    if (targetView != null) {
        mGuideViewsMap.get(targetView.hashCode()).add(guideView);
    }
    else {
        if (!mGuideViewsMap.containsKey(NO_TARGET_GUIDE_ID)) {
            mGuideViewsMap.put(NO_TARGET_GUIDE_ID, new ArrayList<View>());
        }
        mGuideViewsMap.get(NO_TARGET_GUIDE_ID).add(guideView);
    }
    this.addView(guideView);
    return this;
}
 
Example #13
Source File: ErrorPage.java    From focus-android with Mozilla Public License 2.0 5 votes vote down vote up
public static void loadErrorPage(final WebView webView, final String desiredURL, final int errorCode) {
    final Pair<Integer, Integer> errorResourceIDs = errorDescriptionMap.get(errorCode);

    if (errorResourceIDs == null) {
        throw new IllegalArgumentException("Cannot load error description for unsupported errorcode=" + errorCode);
    }

    // This is quite hacky: ideally we'd just load the css file directly using a '<link rel="stylesheet"'.
    // However WebView thinks it's still loading the original page, which can be an https:// page.
    // If mixed content blocking is enabled (which is probably what we want in Focus), then webkit
    // will block file:///android_res/ links from being loaded - which blocks our css from being loaded.
    // We could hack around that by enabling mixed content when loading an error page (and reenabling it
    // once that's loaded), but doing that correctly and reliably isn't particularly simple. Loading
    // the css data and stuffing it into our html is much simpler, especially since we're already doing
    // string substitutions.
    // As an added bonus: file:/// URIs are broken if the app-ID != app package, see:
    // https://code.google.com/p/android/issues/detail?id=211768 (this breaks loading css via file:///
    // references when running debug builds, and probably klar too) - which means this wouldn't
    // be possible even if we hacked around the mixed content issues.
    final String cssString = HtmlLoader.loadResourceFile(webView.getContext(), R.raw.errorpage_style, null);

    final Map<String, String> substitutionMap = new ArrayMap<>();

    final Resources resources = webView.getContext().getResources();

    substitutionMap.put("%page-title%", resources.getString(R.string.errorpage_title));
    substitutionMap.put("%button%", resources.getString(R.string.errorpage_refresh));

    substitutionMap.put("%messageShort%", resources.getString(errorResourceIDs.first));
    substitutionMap.put("%messageLong%", resources.getString(errorResourceIDs.second, desiredURL));

    substitutionMap.put("%css%", cssString);

    final String errorPage = HtmlLoader.loadResourceFile(webView.getContext(), R.raw.errorpage, substitutionMap);

    // We could load the raw html file directly into the webview using a file:///android_res/
    // URI - however we'd then need to do some JS hacking to do our String substitutions. Moreover
    // we'd have to deal with the mixed-content issues detailed above in that case.
    webView.loadDataWithBaseURL(desiredURL, errorPage, "text/html", "UTF8", desiredURL);
}
 
Example #14
Source File: HealthStatsMetricsTest.java    From Battery-Metrics with MIT License 5 votes vote down vote up
@Test
public void jsonConversionSkipsEmptyHealthStats() throws Exception {
  HealthStatsMetrics metrics = new HealthStatsMetrics();
  metrics.stats.put(123, new ArrayMap<String, HealthStatsMetrics>());
  HealthStatsMetrics inner = new HealthStatsMetrics();
  metrics.stats.get(123).put("abc", inner);
  assertThat(metrics.toJSONObject().length()).isEqualTo(0);
}
 
Example #15
Source File: HealthStatsMetrics.java    From Battery-Metrics with MIT License 5 votes vote down vote up
/** Kind of a hack to avoid a lot of boilerplate; icky but it works */
private static <V> Object opValues(int op, V a, @Nullable V b) {
  if (a instanceof Long) {
    return (Long) a + (b == null ? 0 : (op * (Long) b));
  }

  if (a instanceof TimerMetrics) {
    TimerMetrics timerMetricsA = (TimerMetrics) a;
    TimerMetrics timerMetricsB = (TimerMetrics) b;

    if (b == null) {
      return new TimerMetrics(timerMetricsA);
    }

    TimerMetrics timerMetrics = new TimerMetrics();
    timerMetrics.count = timerMetricsA.count + op * timerMetricsB.count;
    timerMetrics.timeMs = timerMetricsA.timeMs + op * timerMetricsB.timeMs;
    return timerMetrics;
  }

  if (a instanceof HealthStatsMetrics) {
    if (op == OP_SUM) {
      return ((HealthStatsMetrics) a).sum((HealthStatsMetrics) b, null);
    } else {
      return ((HealthStatsMetrics) a).diff((HealthStatsMetrics) b, null);
    }
  }

  if (a instanceof ArrayMap) {
    return opArrayMaps(op, (ArrayMap) a, (ArrayMap) b);
  }

  throw new IllegalArgumentException("Handling unsupported values");
}
 
Example #16
Source File: HealthStatsMetricsSerializerTest.java    From Battery-Metrics with MIT License 5 votes vote down vote up
@Override
protected HealthStatsMetrics createInitializedInstance() {
  HealthStatsMetrics metrics = createTestMetricsWithoutStats();
  ArrayMap<String, HealthStatsMetrics> value = new ArrayMap<>();
  value.put("stats", createTestMetricsWithoutStats());
  value.put("moreStats", createTestMetricsWithoutStats());
  metrics.stats.put(1234, value);

  ArrayMap<String, HealthStatsMetrics> secondValue = new ArrayMap<>();
  value.put("stats_2", createTestMetricsWithoutStats());
  metrics.stats.put(3456, secondValue);

  return metrics;
}
 
Example #17
Source File: WebSocketBizRouter.java    From AndroidGodEye with Apache License 2.0 5 votes vote down vote up
WebSocketBizRouter() {
    mRouterMap = new ArrayMap<>();
    mRouterMap.put("clientOnline", new WebSocketClientOnlineProcessor());
    mRouterMap.put("appInfo", new WebSocketAppinfoProcessor());
    mRouterMap.put("methodCanary", new WebSocketMethodCanaryProcessor());
    mRouterMap.put("reinstallBlock", new WebSocketChangeBlockConfigProcessor());
}
 
Example #18
Source File: TrackerList.java    From tracker-control-android with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Retrieves information for all apps
 *
 * @return A cursor pointing to the data. Caller must close the cursor.
 * Cursor should have app name and leak summation based on a sort type
 */
public synchronized Pair<Map<Integer, Integer>, Integer> getTrackerCountsAndTotal() {
    Map<Integer, Set<Tracker>> trackers = new ArrayMap<>();

    Cursor cursor = databaseHelper.getHosts();

    if (cursor.moveToFirst()) {
        do {
            int uid = cursor.getInt(cursor.getColumnIndex("uid"));
            Set<Tracker> observed = trackers.get(uid);
            if (observed == null) {
                observed = new HashSet<>();
                trackers.put(uid, observed);
            }

            // Add tracker
            String hostname = cursor.getString(cursor.getColumnIndex("daddr"));
            Tracker tracker = findTracker(hostname);
            if (tracker != null)
                observed.add(tracker);
        } while (cursor.moveToNext());
    }
    cursor.close();

    // Reduce to counts
    Integer totalTracker = 0;
    Map<Integer, Integer> trackerCounts = new ArrayMap<>();
    for (Map.Entry<Integer, Set<Tracker>> entry : trackers.entrySet()) {
        trackerCounts.put(entry.getKey(), entry.getValue().size());
        totalTracker += entry.getValue().size();
    }

    return new Pair<>(trackerCounts, totalTracker);
}
 
Example #19
Source File: LocalizedContent.java    From focus-android with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * Load the content for focus:about
 */
private static void loadAbout(@NonNull final IWebView webView, Context context) {
    final Resources resources = Locales.getLocalizedResources(context);

    final Map<String, String> substitutionMap = new ArrayMap<>();
    final String appName = context.getResources().getString(R.string.app_name);
    final String learnMoreURL = SupportUtils.INSTANCE.getManifestoURL();

    String aboutVersion = "";
    try {
        final String engineIndicator = AppConstants.INSTANCE.isGeckoBuild() ?
                " \uD83E\uDD8E " + BuildConfig.MOZ_APP_VERSION + "-" + BuildConfig.MOZ_APP_BUILDID : "";
        final PackageInfo packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);

        aboutVersion = String.format("%s (Build #%s)", packageInfo.versionName, packageInfo.versionCode + engineIndicator);
    } catch (PackageManager.NameNotFoundException e) {
        // Nothing to do if we can't find the package name.
    }
    substitutionMap.put("%about-version%", aboutVersion);

    final String aboutContent = resources.getString(R.string.about_content, appName, learnMoreURL);
    substitutionMap.put("%about-content%", aboutContent);

    final String wordmark = HtmlLoader.loadPngAsDataURI(context, R.drawable.wordmark);
    substitutionMap.put("%wordmark%", wordmark);

    putLayoutDirectionIntoMap(substitutionMap, context);

    final String data = HtmlLoader.loadResourceFile(context, R.raw.about, substitutionMap);

    webView.loadData("file:///android_res/raw/about.html", data, "text/html", "UTF-8", URL_ABOUT);
}
 
Example #20
Source File: ServiceDetailFragment.java    From BonjourBrowser with Apache License 2.0 5 votes vote down vote up
private void updateTXTRecords(BonjourService service) {
    ArrayMap<String, String> metaInfo = new ArrayMap<>();
    metaInfo.putAll(service.getTxtRecords());
    mAdapter.swapTXTRecords(metaInfo);
    mAdapter.notifyDataSetChanged();
    if (isAdded()) {
        ((ServiceDetailListener)getActivity()).onServiceUpdated(mService);
    }
}
 
Example #21
Source File: LocalizedContent.java    From focus-android with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * Load the content for focus:rights
 */
private static void loadRights(@NonNull final IWebView webView, Context context) {
    final Resources resources = Locales.getLocalizedResources(context);

    final Map<String, String> substitutionMap = new ArrayMap<>();

    final String appName = context.getResources().getString(R.string.app_name);
    final String mplUrl = "https://www.mozilla.org/en-US/MPL/";
    final String trademarkPolicyUrl = "https://www.mozilla.org/foundation/trademarks/policy/";
    final String gplUrl = "gpl.html";
    final String trackingProtectionUrl = "https://wiki.mozilla.org/Security/Tracking_protection#Lists";
    final String licensesUrl = "licenses.html";

    final String content1 = resources.getString(R.string.your_rights_content1, appName);
    substitutionMap.put("%your-rights-content1%", content1);

    final String content2 = resources.getString(R.string.your_rights_content2, appName, mplUrl);
    substitutionMap.put("%your-rights-content2%", content2);

    final String content3 = resources.getString(R.string.your_rights_content3, appName, trademarkPolicyUrl);
    substitutionMap.put("%your-rights-content3%", content3);

    final String content4 = resources.getString(R.string.your_rights_content4, appName, licensesUrl);
    substitutionMap.put("%your-rights-content4%", content4);

    final String content5 = resources.getString(R.string.your_rights_content5, appName, gplUrl, trackingProtectionUrl);
    substitutionMap.put("%your-rights-content5%", content5);

    putLayoutDirectionIntoMap(substitutionMap, context);

    final String data = HtmlLoader.loadResourceFile(context, R.raw.rights, substitutionMap);
    webView.loadData("file:///android_asset/rights.html", data, "text/html", "UTF-8", URL_RIGHTS);
}
 
Example #22
Source File: UrlMatcher.java    From focus-android with Mozilla Public License 2.0 5 votes vote down vote up
private static Map<String, String> loadDefaultPrefMap(final Context context) {
    Map<String, String> tempMap = new ArrayMap<>();

    tempMap.put(context.getString(R.string.pref_key_privacy_block_ads), "Advertising");
    tempMap.put(context.getString(R.string.pref_key_privacy_block_analytics), "Analytics");
    tempMap.put(context.getString(R.string.pref_key_privacy_block_social), "Social");
    tempMap.put(context.getString(R.string.pref_key_privacy_block_other), "Content");
    tempMap.put(context.getString(R.string.pref_key_privacy_block_cryptomining), "Cryptomining");
    tempMap.put(context.getString(R.string.pref_key_privacy_block_fingerprinting), "Fingerprinting");

    // This is a "fake" category - webfont handling is independent of the blocklists
    tempMap.put(context.getString(R.string.pref_key_performance_block_webfonts), WEBFONTS);

    return Collections.unmodifiableMap(tempMap);
}
 
Example #23
Source File: Parcelables.java    From particle-android with Apache License 2.0 5 votes vote down vote up
public static <T extends Serializable> Map<String, T> readSerializableMap(Parcel parcel) {
    Map<String, T> map = new ArrayMap<>();
    Bundle bundle = parcel.readBundle(Parcelables.class.getClassLoader());
    for (String key : bundle.keySet()) {
        @SuppressWarnings("unchecked")
        T serializable = (T) bundle.getSerializable(key);
        map.put(key, serializable);
    }
    return map;
}
 
Example #24
Source File: DiscoveryManager.java    From zephyr with MIT License 5 votes vote down vote up
public DiscoveryManager(@NonNull Gson gson,
                        @NonNull ILogger logger,
                        @NonNull IPreferenceManager preferenceManager) {
    mGson = gson;
    mLogger = logger;
    mPreferenceManager = preferenceManager;

    HandlerThread mPacketHandlerThread = new HandlerThread(LOG_TAG);
    mPacketHandlerThread.start();
    mPacketHandler = new Handler(mPacketHandlerThread.getLooper());
    mDiscoveryRunnable = getDiscoveryRunnable();

    mDiscoveredServers = new ArrayMap<>();
    mDiscoveredServersLiveData = new MutableLiveData<>();
}
 
Example #25
Source File: Parcelables.java    From particle-android with Apache License 2.0 5 votes vote down vote up
public static <T extends Parcelable> Map<String, T> readParcelableMap(Parcel parcel) {
    Map<String, T> map = new ArrayMap<>();
    Bundle bundle = parcel.readBundle(Parcelables.class.getClassLoader());
    for (String key : bundle.keySet()) {
        T parcelable = bundle.getParcelable(key);
        map.put(key, parcelable);
    }
    return map;
}
 
Example #26
Source File: Parcelables.java    From particle-android with Apache License 2.0 5 votes vote down vote up
public static Map<String, String> readStringMap(Parcel parcel) {
    Map<String, String> map = new ArrayMap<>();
    Bundle bundle = parcel.readBundle(Parcelables.class.getClassLoader());
    for (String key : bundle.keySet()) {
        map.put(key, bundle.getString(key));
    }
    return map;
}
 
Example #27
Source File: ThumbnailLoader.java    From Jockey with Apache License 2.0 5 votes vote down vote up
ThumbnailLoader(Context context) {
    mContext = context;
    mThumbnailResolution = context.getResources().getDimensionPixelSize(R.dimen.list_thumbnail_size);

    long maxMemoryBytes = Runtime.getRuntime().maxMemory();
    // estimate 4 bytes per pixel
    long estimatedImageSizeBytes = mThumbnailResolution * mThumbnailResolution * 4;
    mMaxCacheElements = (int) (maxMemoryBytes / estimatedImageSizeBytes) / 10;

    mCache = new ArrayMap<>();
    mWeakCache = new ArrayMap<>();
}
 
Example #28
Source File: EditableSongSection.java    From Jockey with Apache License 2.0 5 votes vote down vote up
private void buildIdMap() {
    mIds.clear();
    Map<Song, Integer> occurrences = new ArrayMap<>();
    for (Song song : mData) {
        Integer count = occurrences.get(song);
        if (count == null) {
            count = 0;
        }

        int id = (int) (song.getSongId() * Math.pow(7, count));
        mIds.add(id);
        occurrences.put(song, ++count);
    }
}
 
Example #29
Source File: LocalPlaylistStore.java    From Jockey with Apache License 2.0 5 votes vote down vote up
public LocalPlaylistStore(Context context, MusicStore musicStore,
                          PlayCountStore playCountStore) {
    mContext = context;
    mMusicStore = musicStore;
    mPlayCountStore = playCountStore;
    mPlaylistContents = new ArrayMap<>();
    mLoadingState = BehaviorSubject.create(false);

    MediaStoreUtil.waitForPermission()
            .subscribe(permission -> bindRefreshListener(), throwable -> {
                Timber.e(throwable, "Failed to bind refresh listener");
            });
}
 
Example #30
Source File: AuthorizationException.java    From AppAuth-Android with Apache License 2.0 5 votes vote down vote up
private static Map<String, AuthorizationException> exceptionMapByString(
        AuthorizationException... exceptions) {
    ArrayMap<String, AuthorizationException> map =
            new ArrayMap<>(exceptions != null ? exceptions.length : 0);

    if (exceptions != null) {
        for (AuthorizationException ex : exceptions) {
            if (ex.error != null) {
                map.put(ex.error, ex);
            }
        }
    }

    return Collections.unmodifiableMap(map);
}