Example usage for android.support.v4.util SimpleArrayMap SimpleArrayMap

List of usage examples for android.support.v4.util SimpleArrayMap SimpleArrayMap

Introduction

In this page you can find the example usage for android.support.v4.util SimpleArrayMap SimpleArrayMap.

Prototype

public SimpleArrayMap(SimpleArrayMap simpleArrayMap) 

Source Link

Usage

From source file:com.google.blockly.utils.SimpleArraySet.java

public SimpleArraySet(int initialCapacity) {
    this.mMap = new SimpleArrayMap<>(initialCapacity);
}

From source file:com.facebook.litho.internal.ArraySet.java

public ArraySet(int capacity) {
    mMap = new SimpleArrayMap<>(capacity);
}

From source file:com.appsimobile.appsii.module.apps.AppPageData.java

AppPageData(@Nullable List<? extends AppEntry> allApps, List<HistoryItem> recentApps, List<AppTag> tags) {
    mAllApps = new ArrayList<>();
    if (allApps != null) {
        mAllApps.addAll(allApps);//from   www .  j av a  2  s  . c om
    }
    mRecentApps = recentApps;
    mAppTags = tags;

    SimpleArrayMap<ComponentName, AppEntry> appEntriesByComponent;
    if (allApps != null) {
        int N = allApps.size();
        appEntriesByComponent = new SimpleArrayMap<>(N);
        for (int i = 0; i < N; i++) {
            AppEntry app = allApps.get(i);
            appEntriesByComponent.put(app.getComponentName(), app);
        }
    } else {
        appEntriesByComponent = new SimpleArrayMap<>(0);
    }

    long recentAppsTagId = recentAppsTagId(tags);
    long allAppsTagId = allAppsTagId(tags);

    mAppsPerTag.put(allAppsTagId, mAllApps);

    List<AppEntry> recentAppEntries = new ArrayList<>(recentApps.size());
    for (int i = 0; i < recentApps.size(); i++) {
        HistoryItem item = recentApps.get(i);
        AppEntry e = appEntriesByComponent.get(item.componentName);
        if (e != null) {
            recentAppEntries.add(e);
        }
    }

    mAppsPerTag.put(recentAppsTagId, recentAppEntries);
}

From source file:io.kristal.pubsubplugin.PubSubReceiver.java

/**
 * Creates and return a PubSubReceiver for the specified CobaltFragment registered to the specified channel.
 * @param fragment the CobaltFragment containing the WebView to which send messages.
 * @param callback the callback to call to forward messages from the specified channel.
 * @param channel  the channel from which the messages will come from.
 *//*from w  w w . j  av  a2  s . co m*/
public PubSubReceiver(CobaltFragment fragment, String callback, String channel) {
    fragmentReference = new WeakReference<CobaltFragment>(fragment);
    callbackForChannel = new SimpleArrayMap<>(1);
    callbackForChannel.put(channel, callback);
}

From source file:com.firebase.jobdispatcher.GooglePlayReceiver.java

@Nullable
private JobParameters prepareJob(Intent intent) {
    Bundle data = intent.getExtras();//ww  w.j a va  2  s  . co m
    if (data == null) {
        Log.e(TAG, ERROR_NO_DATA);
        return null;
    }

    // get the callback first. If we don't have this we can't talk back to the backend.
    JobCallback callback = callbackExtractor.extractCallback(data);
    if (callback == null) {
        Log.i(TAG, "no callback found");
        return null;
    }

    Bundle extras = data.getBundle(GooglePlayJobWriter.REQUEST_PARAM_EXTRAS);
    if (extras == null) {
        Log.i(TAG, "no 'extras' bundle found");
        sendResultSafely(callback, JobService.RESULT_FAIL_NORETRY);
        return null;
    }

    JobInvocation job = prefixedCoder.decode(extras);
    if (job == null) {
        Log.i(TAG, "unable to decode job from extras");
        sendResultSafely(callback, JobService.RESULT_FAIL_NORETRY);
        return null;
    }

    // repack the extras
    job.getExtras().putAll(extras);

    synchronized (this) {
        SimpleArrayMap<String, JobCallback> map = callbacks.get(job.getService());
        if (map == null) {
            map = new SimpleArrayMap<>(1);
            callbacks.put(job.getService(), map);
        }

        map.put(job.getTag(), callback);
    }

    return job;
}

From source file:com.appsimobile.appsii.timezonepicker.TimeZoneData.java

void loadTzs(Context context) {
    mTimeZones = new ArrayList<>();
    HashSet<String> processedTimeZones = loadTzsInZoneTab(context);
    String[] tzIds = TimeZone.getAvailableIDs();

    if (DEBUG) {// w ww .ja  va  2  s  .  c o m
        Log.e(TAG, "Available time zones: " + tzIds.length);
    }

    for (String tzId : tzIds) {
        if (processedTimeZones.contains(tzId)) {
            continue;
        }

        /*
         * Dropping non-GMT tzs without a country code. They are not really
         * needed and they are dups but missing proper country codes. e.g.
         * WET CET MST7MDT PST8PDT Asia/Khandyga Asia/Ust-Nera EST
         */
        if (!tzId.startsWith("Etc/GMT")) {
            continue;
        }

        final TimeZone tz = TimeZone.getTimeZone(tzId);
        if (tz == null) {
            Log.e(TAG, "Timezone not found: " + tzId);
            continue;
        }

        TimeZoneInfo tzInfo = new TimeZoneInfo(tz, null);

        if (getIdenticalTimeZoneInTheCountry(tzInfo) == -1) {
            if (DEBUG) {
                Log.e(TAG, "# Adding time zone from getAvailId: " + tzInfo.toString());
            }
            mTimeZones.add(tzInfo);
        } else {
            if (DEBUG) {
                Log.e(TAG, "# Dropping identical time zone from getAvailId: " + tzInfo.toString());
            }
            continue;
        }
        //
        // TODO check for dups
        // checkForNameDups(tz, tzInfo.mCountry, false /* dls */,
        // TimeZone.SHORT, groupIdx, !found);
        // checkForNameDups(tz, tzInfo.mCountry, false /* dls */,
        // TimeZone.LONG, groupIdx, !found);
        // if (tz.useDaylightTime()) {
        // checkForNameDups(tz, tzInfo.mCountry, true /* dls */,
        // TimeZone.SHORT, groupIdx,
        // !found);
        // checkForNameDups(tz, tzInfo.mCountry, true /* dls */,
        // TimeZone.LONG, groupIdx,
        // !found);
        // }
    }

    // Don't change the order of mTimeZones after this sort
    Collections.sort(mTimeZones);

    mTimeZonesByCountry = new LinkedHashMap<>();
    mTimeZonesByOffsets = new SparseArray<>(mHasTimeZonesInHrOffset.length);
    int N = mTimeZones.size();
    mTimeZonesById = new SimpleArrayMap<>(N);
    for (int i = 0; i < N; i++) {
        TimeZoneInfo tz = mTimeZones.get(i);
        // /////////////////////
        // Lookup map for id -> tz
        mTimeZonesById.put(tz.mTzId, tz);
    }
    populateDisplayNameOverrides(mTimeZonesById, mContext.getResources());

    Date date = new Date(mTimeMillis);
    Locale defaultLocal = Locale.getDefault();

    int idx = 0;
    for (int i = 0; i < N; i++) {
        TimeZoneInfo tz = mTimeZones.get(i);
        // /////////////////////
        // Populate display name
        if (tz.mDisplayName == null) {
            tz.mDisplayName = tz.mTz.getDisplayName(tz.mTz.inDaylightTime(date), TimeZone.LONG, defaultLocal);
        }

        // /////////////////////
        // Grouping tz's by country for search by country
        IntList group = mTimeZonesByCountry.get(tz.mCountry);
        if (group == null) {
            group = new IntList();
            mTimeZonesByCountry.put(tz.mCountry, group);
        }

        group.add(idx);

        // /////////////////////
        // Grouping tz's by GMT offsets
        indexByOffsets(idx, tz);

        // Skip all the GMT+xx:xx style display names from search
        if (!tz.mDisplayName.endsWith(":00")) {
            mTimeZoneNames.add(tz.mDisplayName);
        } else if (DEBUG) {
            Log.e(TAG, "# Hiding from pretty name search: " + tz.mDisplayName);
        }

        idx++;
    }

    // printTimeZones();
}

From source file:com.appsimobile.appsii.module.apps.AppPageLoader.java

private void loadTaggedApps(List<? extends AppEntry> allApps, AppPageData result) {
    if (allApps == null || allApps.isEmpty())
        return;/*from   w  w  w . ja  va 2  s  . c o  m*/

    Cursor cursor = mContext.getContentResolver().query(AppsContract.TaggedAppColumns.CONTENT_URI,
            AppQuery.PROJECTION, AppQuery.WHERE_NOT_DELETED, null, AppQuery.ORDER);

    int appsSize = allApps.size();
    SimpleArrayMap<ComponentName, AppEntry> entriesByComponent = new SimpleArrayMap<>(appsSize);
    for (int i = 0; i < appsSize; i++) {
        AppEntry app = allApps.get(i);
        entriesByComponent.put(app.getComponentName(), app);
    }

    while (cursor.moveToNext()) {
        String shortComponentName = cursor.getString(AppQuery.COMPONENT_NAME);
        ComponentName componentName = ComponentName.unflattenFromString(shortComponentName);

        // find the app entry from all apps. If it does not exists, the component
        // was changed or uninstalled. In that case, ignore it.
        AppEntry appEntry = entriesByComponent.get(componentName);
        if (appEntry == null)
            continue;

        // now create the tagged-app object. This holds the details of the
        // tagged instance
        TaggedApp taggedApp = new TaggedApp();
        long tagId = cursor.getLong(AppQuery.TAG_ID);
        String tagName = cursor.getString(AppQuery.TAG_NAME);

        taggedApp.mComponentName = componentName;
        taggedApp.mId = cursor.getLong(AppQuery._ID);
        taggedApp.mTagName = tagName;
        taggedApp.mTagId = tagId;
        taggedApp.mAppEntry = appEntry;

        addItemToLongSparseArray(result.mAppsPerTag, tagId, appEntry);
        addItemToMapList(result.mTagsPerComponent, componentName, taggedApp);

    }

    cursor.close();
}

From source file:net.sf.diningout.app.ui.RestaurantsActivity.java

@Override
public void onLoadFinished(Loader<EasyCursor> loader, EasyCursor c) {
    if (mMap == null) {
        return;/*from  w  w w .j  av a 2  s .  c  o m*/
    }
    /* (re-)add restaurant markers */
    mMap.clear();
    if (mMarkers != null) {
        mMarkers.clear();
    }
    MarkerOptions options = null;
    double nearestDistance = Double.MAX_VALUE; // first marker will be closer
    LatLng nearestPosition = null;
    while (c.moveToNext()) {
        if (options == null) {
            options = new MarkerOptions();
        }
        LatLng position = new LatLng(c.getDouble(Restaurants.LATITUDE), c.getDouble(Restaurants.LONGITUDE));
        float rating = c.getFloat(Restaurants.RATING);
        double distance = Math.sqrt(c.getDouble(Restaurants.DISTANCE));
        boolean miles = Keys.isDistanceUnit(MILE);
        String snippet = rating > 0.0f
                ? getString(miles ? R.string.rating_mi : R.string.rating_km, rating, distance)
                : getString(miles ? R.string.mi : R.string.km, distance);
        Marker marker = mMap
                .addMarker(options.position(position).title(c.getString(Restaurants.NAME)).snippet(snippet));
        if (mMarkers == null) {
            mMarkers = new SimpleArrayMap<>(c.getCount());
        }
        mMarkers.put(marker, c.getLong(_ID));
        if (distance < nearestDistance) {
            nearestDistance = distance;
            nearestPosition = position;
        }
    }
    /* move the camera to include at least one marker, if necessary */
    if (mMoveToMyLocation) {
        if (nearestPosition != null) {
            GoogleMaps.animateCameraToIncludePosition(this, mMap, nearestPosition, 1000L);
        }
        mMoveToMyLocation = false;
    }
}

From source file:com.appsimobile.appsii.module.weather.WeatherLoadingService.java

void doSync(String defaultUnit, String extraWoeid, SyncResult result) {

    if (defaultUnit == null)
        throw new IllegalArgumentException("defaultUnit == null");

    NetworkInfo netInfo = mConnectivityManager.getActiveNetworkInfo();

    boolean online = netInfo != null && netInfo.isConnected();

    if (BuildConfig.DEBUG)
        Log.d("WeatherLoadingService", "Handling sync");

    if (BuildConfig.DEBUG)
        Log.d("WeatherLoadingService", "Checking online");
    if (!online) {
        bailOut("No network connection");
        result.stats.numIoExceptions++;//from   w w  w.ja va2  s .  c om
        return;
    }
    boolean syncWhenRoaming = mPreferenceHelper.getSyncWhenRoaming();
    if (netInfo.isRoaming() && !syncWhenRoaming) {
        bailOut("Not syncing because of roaming connection");
        result.stats.numIoExceptions++;
        return;
    }

    if (BuildConfig.DEBUG)
        Log.d("WeatherLoadingService", "- Checking online");

    if (BuildConfig.DEBUG)
        Log.d("WeatherLoadingService", "get woeids");
    String[] woeids = mConfigurationHelper.getWeatherWidgetWoeids(WeatherFragment.PREFERENCE_WEATHER_WOEID);
    if (BuildConfig.DEBUG)
        Log.d("WeatherLoadingService", "- get woeids");

    if (BuildConfig.DEBUG)
        Log.d("WeatherLoadingService", "extra woeids");
    if (extraWoeid != null) {
        int length = woeids.length;

        String[] temp = new String[length + 1];
        System.arraycopy(woeids, 0, temp, 0, length);
        temp[length] = extraWoeid;
        woeids = temp;
    }
    if (BuildConfig.DEBUG)
        Log.d("WeatherLoadingService", "- extra woeids");

    if (woeids.length == 0) {
        bailOut("Not syncing because there are no woeids");
        // tell the service to reschedule normally
        result.stats.numUpdates++;
        return;
    }

    if (BuildConfig.DEBUG)
        Log.d("WeatherLoadingService", "find timezones");
    int N = woeids.length;
    SimpleArrayMap<String, String> woeidTimezones = new SimpleArrayMap<>(N);
    for (int i = 0; i < N; i++) {
        String woeid = woeids[i];
        long cellId = mConfigurationHelper.findCellWithPropertyValue(WeatherFragment.PREFERENCE_WEATHER_WOEID,
                woeid);
        if (cellId != -1) {
            String timezone = mConfigurationHelper.getProperty(cellId,
                    WeatherFragment.PREFERENCE_WEATHER_TIMEZONE, null);
            if (BuildConfig.DEBUG) {
                Log.d("WeatherLoadingService", "woeid -> timezone: " + woeid + " -> " + timezone);
            }
            woeidTimezones.put(woeid, timezone);
        }
    }
    if (BuildConfig.DEBUG)
        Log.d("WeatherLoadingService", "- find timezones");

    try {
        if (BuildConfig.DEBUG)
            Log.d("WeatherLoadingService", "request location");
        Location location;

        if (mPermissionUtils.holdsPermission(mContext, Manifest.permission.ACCESS_COARSE_LOCATION)) {
            location = requestLocationInfoBlocking();
        } else {
            woeids = addFallbackWoeid(woeids, woeidTimezones);
            location = null;
        }
        if (BuildConfig.DEBUG)
            Log.d("WeatherLoadingService", "- request location");

        SimpleArrayMap<String, WeatherData> previousData = new SimpleArrayMap<>(woeids.length);
        for (String woeid : woeids) {
            WeatherData data = mWeatherUtils.getWeatherData(mContext, woeid);
            previousData.put(woeid, data);
        }

        if (BuildConfig.DEBUG)
            Log.d("WeatherLoadingService", "load data");
        WeatherDataLoader loader = new WeatherDataLoader(location, woeids, defaultUnit);
        CircularArray<WeatherData> data = loader.queryWeather();
        result.stats.numUpdates++;
        if (BuildConfig.DEBUG)
            Log.d("WeatherLoadingService", "- load data");

        if (BuildConfig.DEBUG)
            Log.d("WeatherLoadingService", "sync images");

        int size = data.size();
        for (int i = 0; i < size; i++) {
            WeatherData weatherData = data.get(i);
            try {
                syncImages(result, mConnectivityManager, mPreferenceHelper, woeidTimezones, previousData,
                        weatherData);
            } catch (VolleyError e) {
                Log.w("WeatherLoadingService", "error getting images", e);
            }
        }
        if (BuildConfig.DEBUG)
            Log.d("WeatherLoadingService", "- sync images");
    } catch (InterruptedException ignore) {
        // we have been requested to stop, so simply stop
        result.stats.numIoExceptions++;
    } catch (CantGetWeatherException e) {
        Log.e("WeatherLoadingService", "error loading weather. Waiting for next retry", e);
        result.stats.numIoExceptions++;
    }

}