Example usage for android.util SparseArray put

List of usage examples for android.util SparseArray put

Introduction

In this page you can find the example usage for android.util SparseArray put.

Prototype

public void put(int key, E value) 

Source Link

Document

Adds a mapping from the specified key to the specified value, replacing the previous mapping from the specified key if there was one.

Usage

From source file:retrotooth.model.ScanRecord.java

/**
 * Parse scan record bytes to {@link ScanRecord}.
 * <p/>/*from w w  w.  j  av a  2 s .  c  om*/
 * The format is defined in Bluetooth 4.1 specification, Volume 3, Part C, Section 11 and 18.
 * <p/>
 * All numerical multi-byte entities and values shall use little-endian <strong>byte</strong>
 * order.
 *
 * @param scanRecord The scan record of Bluetooth LE advertisement and/or scan response.
 * @hide
 */
public static ScanRecord parseFromBytes(byte[] scanRecord) {
    if (scanRecord == null) {
        return null;
    }

    int currentPos = 0;
    int advertiseFlag = -1;
    List<ParcelUuid> serviceUuids = new ArrayList<ParcelUuid>();
    String localName = null;
    int txPowerLevel = Integer.MIN_VALUE;

    SparseArray<byte[]> manufacturerData = new SparseArray<byte[]>();
    Map<ParcelUuid, byte[]> serviceData = new ArrayMap<ParcelUuid, byte[]>();

    try {
        while (currentPos < scanRecord.length) {
            // length is unsigned int.
            int length = scanRecord[currentPos++] & 0xFF;
            if (length == 0) {
                break;
            }
            // Note the length includes the length of the field type itself.
            int dataLength = length - 1;
            // fieldType is unsigned int.
            int fieldType = scanRecord[currentPos++] & 0xFF;
            switch (fieldType) {
            case DATA_TYPE_FLAGS:
                advertiseFlag = scanRecord[currentPos] & 0xFF;
                break;
            case DATA_TYPE_SERVICE_UUIDS_16_BIT_PARTIAL:
            case DATA_TYPE_SERVICE_UUIDS_16_BIT_COMPLETE:
                parseServiceUuid(scanRecord, currentPos, dataLength, BluetoothUuid.UUID_BYTES_16_BIT,
                        serviceUuids);
                break;
            case DATA_TYPE_SERVICE_UUIDS_32_BIT_PARTIAL:
            case DATA_TYPE_SERVICE_UUIDS_32_BIT_COMPLETE:
                parseServiceUuid(scanRecord, currentPos, dataLength, BluetoothUuid.UUID_BYTES_32_BIT,
                        serviceUuids);
                break;
            case DATA_TYPE_SERVICE_UUIDS_128_BIT_PARTIAL:
            case DATA_TYPE_SERVICE_UUIDS_128_BIT_COMPLETE:
                parseServiceUuid(scanRecord, currentPos, dataLength, BluetoothUuid.UUID_BYTES_128_BIT,
                        serviceUuids);
                break;
            case DATA_TYPE_LOCAL_NAME_SHORT:
            case DATA_TYPE_LOCAL_NAME_COMPLETE:
                localName = new String(extractBytes(scanRecord, currentPos, dataLength));
                break;
            case DATA_TYPE_TX_POWER_LEVEL:
                txPowerLevel = scanRecord[currentPos];
                break;
            case DATA_TYPE_SERVICE_DATA:
                // The first two bytes of the service data are service data UUID in little
                // endian. The rest bytes are service data.
                int serviceUuidLength = BluetoothUuid.UUID_BYTES_16_BIT;
                byte[] serviceDataUuidBytes = extractBytes(scanRecord, currentPos, serviceUuidLength);
                ParcelUuid serviceDataUuid = BluetoothUuid.parseUuidFrom(serviceDataUuidBytes);
                byte[] serviceDataArray = extractBytes(scanRecord, currentPos + serviceUuidLength,
                        dataLength - serviceUuidLength);
                serviceData.put(serviceDataUuid, serviceDataArray);
                break;
            case DATA_TYPE_MANUFACTURER_SPECIFIC_DATA:
                // The first two bytes of the manufacturer specific data are
                // manufacturer ids in little endian.
                int manufacturerId = ((scanRecord[currentPos + 1] & 0xFF) << 8)
                        + (scanRecord[currentPos] & 0xFF);
                byte[] manufacturerDataBytes = extractBytes(scanRecord, currentPos + 2, dataLength - 2);
                manufacturerData.put(manufacturerId, manufacturerDataBytes);
                break;
            default:
                // Just ignore, we don't handle such data type.
                break;
            }
            currentPos += dataLength;
        }

        if (serviceUuids.isEmpty()) {
            serviceUuids = null;
        }
        return new ScanRecord(serviceUuids, manufacturerData, serviceData, advertiseFlag, txPowerLevel,
                localName, scanRecord);
    } catch (Exception e) {
        Log.e(TAG, "unable to parse scan record: " + Arrays.toString(scanRecord));
        // As the record is invalid, ignore all the parsed results for this packet
        // and return an empty record with raw scanRecord bytes in results
        return new ScanRecord(null, null, null, -1, Integer.MIN_VALUE, null, scanRecord);
    }
}

From source file:com.forkingcode.bluetoothcompat.ScanRecordCompat.java

/**
 * Parse scan record bytes to {@link ScanRecordCompat}.
 * <p>/*from   w  w  w.j av a2 s. com*/
 * The format is defined in Bluetooth 4.1 specification, Volume 3, Part C, Section 11 and 18.
 * <p>
 * All numerical multi-byte entities and values shall use little-endian <strong>byte</strong>
 * order.
 *
 * @param scanRecord The scan record of Bluetooth LE advertisement and/or scan response.
 */
public static ScanRecordCompat parseFromBytes(byte[] scanRecord) {
    if (scanRecord == null) {
        return null;
    }

    int currentPos = 0;
    int advertiseFlag = -1;
    List<ParcelUuid> serviceUuids = new ArrayList<>();
    String localName = null;
    int txPowerLevel = Integer.MIN_VALUE;

    SparseArray<byte[]> manufacturerData = new SparseArray<>();
    Map<ParcelUuid, byte[]> serviceData = new ArrayMap<>();

    try {
        while (currentPos < scanRecord.length) {
            // length is unsigned int.
            int length = scanRecord[currentPos++] & 0xFF;
            if (length == 0) {
                break;
            }
            // Note the length includes the length of the field type itself.
            int dataLength = length - 1;
            // fieldType is unsigned int.
            int fieldType = scanRecord[currentPos++] & 0xFF;
            switch (fieldType) {
            case DATA_TYPE_FLAGS:
                advertiseFlag = scanRecord[currentPos] & 0xFF;
                break;
            case DATA_TYPE_SERVICE_UUIDS_16_BIT_PARTIAL:
            case DATA_TYPE_SERVICE_UUIDS_16_BIT_COMPLETE:
                parseServiceUuid(scanRecord, currentPos, dataLength, BluetoothUuidCompat.UUID_BYTES_16_BIT,
                        serviceUuids);
                break;
            case DATA_TYPE_SERVICE_UUIDS_32_BIT_PARTIAL:
            case DATA_TYPE_SERVICE_UUIDS_32_BIT_COMPLETE:
                parseServiceUuid(scanRecord, currentPos, dataLength, BluetoothUuidCompat.UUID_BYTES_32_BIT,
                        serviceUuids);
                break;
            case DATA_TYPE_SERVICE_UUIDS_128_BIT_PARTIAL:
            case DATA_TYPE_SERVICE_UUIDS_128_BIT_COMPLETE:
                parseServiceUuid(scanRecord, currentPos, dataLength, BluetoothUuidCompat.UUID_BYTES_128_BIT,
                        serviceUuids);
                break;
            case DATA_TYPE_LOCAL_NAME_SHORT:
            case DATA_TYPE_LOCAL_NAME_COMPLETE:
                localName = new String(extractBytes(scanRecord, currentPos, dataLength));
                break;
            case DATA_TYPE_TX_POWER_LEVEL:
                txPowerLevel = scanRecord[currentPos];
                break;
            case DATA_TYPE_SERVICE_DATA:
                // The first two bytes of the service data are service data UUID in little
                // endian. The rest bytes are service data.
                int serviceUuidLength = BluetoothUuidCompat.UUID_BYTES_16_BIT;
                byte[] serviceDataUuidBytes = extractBytes(scanRecord, currentPos, serviceUuidLength);
                ParcelUuid serviceDataUuid = BluetoothUuidCompat.parseUuidFrom(serviceDataUuidBytes);
                byte[] serviceDataArray = extractBytes(scanRecord, currentPos + serviceUuidLength,
                        dataLength - serviceUuidLength);
                serviceData.put(serviceDataUuid, serviceDataArray);
                break;
            case DATA_TYPE_MANUFACTURER_SPECIFIC_DATA:
                // The first two bytes of the manufacturer specific data are
                // manufacturer ids in little endian.
                int manufacturerId = ((scanRecord[currentPos + 1] & 0xFF) << 8)
                        + (scanRecord[currentPos] & 0xFF);
                byte[] manufacturerDataBytes = extractBytes(scanRecord, currentPos + 2, dataLength - 2);
                manufacturerData.put(manufacturerId, manufacturerDataBytes);
                break;
            default:
                // Just ignore, we don't handle such data type.
                break;
            }
            currentPos += dataLength;
        }

        if (serviceUuids.isEmpty()) {
            serviceUuids = null;
        }
        return new ScanRecordCompat(serviceUuids, manufacturerData, serviceData, advertiseFlag, txPowerLevel,
                localName, scanRecord);
    } catch (Exception e) {
        Log.e(TAG, "unable to parse scan record: " + Arrays.toString(scanRecord));
        // As the record is invalid, ignore all the parsed results for this packet
        // and return an empty record with raw scanRecord bytes in results
        return new ScanRecordCompat(null, null, null, -1, Integer.MIN_VALUE, null, scanRecord);
    }
}

From source file:com.android.launcher3.CellLayout.java

@Override
protected void dispatchSaveInstanceState(SparseArray<Parcelable> container) {
    if (mJailContent) {
        ParcelableSparseArray jail = getJailedArray(container);
        super.dispatchSaveInstanceState(jail);
        container.put(R.id.cell_layout_jail_id, jail);
    } else {/*from   w  w w.j  a v a2 s  . c  o  m*/
        super.dispatchSaveInstanceState(container);
    }
}

From source file:dev.ukanth.ufirewall.Api.java

/**
 * @param ctx application context (mandatory)
 * @return a list of applications//from w  w  w.  j  a  v  a  2  s  . c o m
 */
public static List<PackageInfoData> getApps(Context ctx, GetAppList appList) {

    initSpecial();
    if (applications != null && applications.size() > 0) {
        // return cached instance
        return applications;
    }

    final SharedPreferences defaultPrefs = PreferenceManager.getDefaultSharedPreferences(ctx);
    final boolean enableVPN = defaultPrefs.getBoolean("enableVPN", false);
    final boolean enableLAN = defaultPrefs.getBoolean("enableLAN", false);
    final boolean enableRoam = defaultPrefs.getBoolean("enableRoam", true);

    final SharedPreferences prefs = ctx.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);

    final String savedPkg_wifi_uid = prefs.getString(PREF_WIFI_PKG_UIDS, "");
    final String savedPkg_3g_uid = prefs.getString(PREF_3G_PKG_UIDS, "");
    final String savedPkg_roam_uid = prefs.getString(PREF_ROAMING_PKG_UIDS, "");
    final String savedPkg_vpn_uid = prefs.getString(PREF_VPN_PKG_UIDS, "");
    final String savedPkg_lan_uid = prefs.getString(PREF_LAN_PKG_UIDS, "");

    List<Integer> selected_wifi = new ArrayList<Integer>();
    List<Integer> selected_3g = new ArrayList<Integer>();
    List<Integer> selected_roam = new ArrayList<Integer>();
    List<Integer> selected_vpn = new ArrayList<Integer>();
    List<Integer> selected_lan = new ArrayList<Integer>();

    selected_wifi = getListFromPref(savedPkg_wifi_uid);
    selected_3g = getListFromPref(savedPkg_3g_uid);

    if (enableRoam) {
        selected_roam = getListFromPref(savedPkg_roam_uid);
    }
    if (enableVPN) {
        selected_vpn = getListFromPref(savedPkg_vpn_uid);
    }
    if (enableLAN) {
        selected_lan = getListFromPref(savedPkg_lan_uid);
    }
    //revert back to old approach

    //always use the defaul preferences to store cache value - reduces the application usage size
    final SharedPreferences cachePrefs = ctx.getSharedPreferences("AFWallPrefs", Context.MODE_PRIVATE);

    int count = 0;
    try {
        final PackageManager pkgmanager = ctx.getPackageManager();
        final List<ApplicationInfo> installed = pkgmanager
                .getInstalledApplications(PackageManager.GET_META_DATA);
        SparseArray<PackageInfoData> syncMap = new SparseArray<PackageInfoData>();
        final Editor edit = cachePrefs.edit();
        boolean changed = false;
        String name = null;
        String cachekey = null;
        final String cacheLabel = "cache.label.";
        PackageInfoData app = null;
        ApplicationInfo apinfo = null;

        for (int i = 0; i < installed.size(); i++) {
            //for (final ApplicationInfo apinfo : installed) {
            count = count + 1;
            apinfo = installed.get(i);

            if (appList != null) {
                appList.doProgress(count);
            }

            boolean firstseen = false;
            app = syncMap.get(apinfo.uid);
            // filter applications which are not allowed to access the Internet
            if (app == null && PackageManager.PERMISSION_GRANTED != pkgmanager
                    .checkPermission(Manifest.permission.INTERNET, apinfo.packageName)) {
                continue;
            }
            // try to get the application label from our cache - getApplicationLabel() is horribly slow!!!!
            cachekey = cacheLabel + apinfo.packageName;
            name = prefs.getString(cachekey, "");
            if (name.length() == 0) {
                // get label and put on cache
                name = pkgmanager.getApplicationLabel(apinfo).toString();
                edit.putString(cachekey, name);
                changed = true;
                firstseen = true;
            }
            if (app == null) {
                app = new PackageInfoData();
                app.uid = apinfo.uid;
                app.names = new ArrayList<String>();
                app.names.add(name);
                app.appinfo = apinfo;
                app.pkgName = apinfo.packageName;
                syncMap.put(apinfo.uid, app);
            } else {
                app.names.add(name);
            }
            app.firstseen = firstseen;
            // check if this application is selected
            if (!app.selected_wifi && Collections.binarySearch(selected_wifi, app.uid) >= 0) {
                app.selected_wifi = true;
            }
            if (!app.selected_3g && Collections.binarySearch(selected_3g, app.uid) >= 0) {
                app.selected_3g = true;
            }
            if (enableRoam && !app.selected_roam && Collections.binarySearch(selected_roam, app.uid) >= 0) {
                app.selected_roam = true;
            }
            if (enableVPN && !app.selected_vpn && Collections.binarySearch(selected_vpn, app.uid) >= 0) {
                app.selected_vpn = true;
            }
            if (enableLAN && !app.selected_lan && Collections.binarySearch(selected_lan, app.uid) >= 0) {
                app.selected_lan = true;
            }

        }

        List<PackageInfoData> specialData = new ArrayList<PackageInfoData>();
        specialData.add(new PackageInfoData(SPECIAL_UID_ANY, ctx.getString(R.string.all_item),
                "dev.afwall.special.any"));
        specialData.add(new PackageInfoData(SPECIAL_UID_KERNEL, ctx.getString(R.string.kernel_item),
                "dev.afwall.special.kernel"));
        specialData.add(new PackageInfoData(SPECIAL_UID_TETHER, ctx.getString(R.string.tethering_item),
                "dev.afwall.special.tether"));
        //specialData.add(new PackageInfoData(SPECIAL_UID_DNSPROXY, ctx.getString(R.string.dnsproxy_item), "dev.afwall.special.dnsproxy"));
        specialData.add(new PackageInfoData(SPECIAL_UID_NTP, ctx.getString(R.string.ntp_item),
                "dev.afwall.special.ntp"));
        specialData
                .add(new PackageInfoData("root", ctx.getString(R.string.root_item), "dev.afwall.special.root"));
        specialData.add(new PackageInfoData("media", "Media server", "dev.afwall.special.media"));
        specialData.add(new PackageInfoData("vpn", "VPN networking", "dev.afwall.special.vpn"));
        specialData.add(new PackageInfoData("shell", "Linux shell", "dev.afwall.special.shell"));
        specialData.add(new PackageInfoData("gps", "GPS", "dev.afwall.special.gps"));
        specialData.add(new PackageInfoData("adb", "ADB (Android Debug Bridge)", "dev.afwall.special.adb"));

        if (specialApps == null) {
            specialApps = new HashMap<String, Integer>();
        }
        for (int i = 0; i < specialData.size(); i++) {
            app = specialData.get(i);
            specialApps.put(app.pkgName, app.uid);
            //default DNS/NTP
            if (app.uid != -1 && syncMap.get(app.uid) == null) {
                // check if this application is allowed
                if (!app.selected_wifi && Collections.binarySearch(selected_wifi, app.uid) >= 0) {
                    app.selected_wifi = true;
                }
                if (!app.selected_3g && Collections.binarySearch(selected_3g, app.uid) >= 0) {
                    app.selected_3g = true;
                }
                if (enableRoam && !app.selected_roam && Collections.binarySearch(selected_roam, app.uid) >= 0) {
                    app.selected_roam = true;
                }
                if (enableVPN && !app.selected_vpn && Collections.binarySearch(selected_vpn, app.uid) >= 0) {
                    app.selected_vpn = true;
                }
                if (enableLAN && !app.selected_lan && Collections.binarySearch(selected_lan, app.uid) >= 0) {
                    app.selected_lan = true;
                }
                syncMap.put(app.uid, app);
            }
        }

        if (changed) {
            edit.commit();
        }
        /* convert the map into an array */
        applications = new ArrayList<PackageInfoData>();
        for (int i = 0; i < syncMap.size(); i++) {
            applications.add(syncMap.valueAt(i));
        }

        return applications;
    } catch (Exception e) {
        alert(ctx, ctx.getString(R.string.error_common) + e);
    }
    return null;
}

From source file:android.transitions.everywhere.Transition.java

/**
 * This method, essentially a wrapper around all calls to createAnimator for all
 * possible target views, is called with the entire set of start/end
 * values. The implementation in Transition iterates through these lists
 * and calls {@link #createAnimator(ViewGroup, TransitionValues, TransitionValues)}
 * with each set of start/end values on this transition. The
 * TransitionSet subclass overrides this method and delegates it to
 * each of its children in succession.// www  .j  a  va 2 s. co  m
 *
 * @hide
 */
protected void createAnimators(ViewGroup sceneRoot, TransitionValuesMaps startValues,
        TransitionValuesMaps endValues, ArrayList<TransitionValues> startValuesList,
        ArrayList<TransitionValues> endValuesList) {
    if (DBG) {
        Log.d(LOG_TAG, "createAnimators() for " + this);
    }
    ArrayMap<Animator, AnimationInfo> runningAnimators = getRunningAnimators();
    long minStartDelay = Long.MAX_VALUE;
    int minAnimator = mAnimators.size();
    SparseArray<Long> startDelays = new SparseArray<Long>();
    int startValuesListCount = startValuesList.size();
    for (int i = 0; i < startValuesListCount; ++i) {
        TransitionValues start = startValuesList.get(i);
        TransitionValues end = endValuesList.get(i);
        if (start != null && !start.targetedTransitions.contains(this)) {
            start = null;
        }
        if (end != null && !end.targetedTransitions.contains(this)) {
            end = null;
        }
        if (start == null && end == null) {
            continue;
        }
        // Only bother trying to animate with values that differ between start/end
        boolean isChanged = start == null || end == null || areValuesChanged(start, end);
        if (isChanged) {
            if (DBG) {
                View view = (end != null) ? end.view : start.view;
                Log.d(LOG_TAG, "  differing start/end values for view " + view);
                if (start == null || end == null) {
                    Log.d(LOG_TAG, "    "
                            + ((start == null) ? "start null, end non-null" : "start non-null, end null"));
                } else {
                    for (String key : start.values.keySet()) {
                        Object startValue = start.values.get(key);
                        Object endValue = end.values.get(key);
                        if (startValue != endValue && !startValue.equals(endValue)) {
                            Log.d(LOG_TAG, "    " + key + ": start(" + startValue + "), end(" + endValue + ")");
                        }
                    }
                }
            }
            // TODO: what to do about targetIds and itemIds?
            Animator animator = createAnimator(sceneRoot, start, end);
            if (animator != null) {
                // Save animation info for future cancellation purposes
                View view = null;
                TransitionValues infoValues = null;
                if (end != null) {
                    view = end.view;
                    String[] properties = getTransitionProperties();
                    if (view != null && properties != null && properties.length > 0) {
                        infoValues = new TransitionValues();
                        infoValues.view = view;
                        TransitionValues newValues = endValues.viewValues.get(view);
                        if (newValues != null) {
                            for (int j = 0; j < properties.length; ++j) {
                                infoValues.values.put(properties[j], newValues.values.get(properties[j]));
                            }
                        }
                        int numExistingAnims = runningAnimators.size();
                        for (int j = 0; j < numExistingAnims; ++j) {
                            Animator anim = runningAnimators.keyAt(j);
                            AnimationInfo info = runningAnimators.get(anim);
                            if (info.values != null && info.view == view
                                    && ((info.name == null && getName() == null)
                                            || info.name.equals(getName()))) {
                                if (info.values.equals(infoValues)) {
                                    // Favor the old animator
                                    animator = null;
                                    break;
                                }
                            }
                        }
                    }
                } else {
                    view = (start != null) ? start.view : null;
                }
                if (animator != null) {
                    if (mPropagation != null) {
                        long delay = mPropagation.getStartDelay(sceneRoot, this, start, end);
                        startDelays.put(mAnimators.size(), delay);
                        minStartDelay = Math.min(delay, minStartDelay);
                    }
                    AnimationInfo info = new AnimationInfo(view, getName(), this,
                            ViewUtils.getWindowId(sceneRoot), infoValues);
                    runningAnimators.put(animator, info);
                    mAnimators.add(animator);
                }
            }
        }
    }
    if (minStartDelay != 0) {
        for (int i = 0; i < startDelays.size(); i++) {
            int index = startDelays.keyAt(i);
            Animator animator = mAnimators.get(index);
            long delay = startDelays.valueAt(i) - minStartDelay + animator.getStartDelay();
            animator.setStartDelay(delay);
        }
    }
}

From source file:com.transitionseverywhere.Transition.java

/**
 * This method, essentially a wrapper around all calls to createAnimator for all
 * possible target views, is called with the entire set of start/end
 * values. The implementation in Transition iterates through these lists
 * and calls {@link #createAnimator(ViewGroup, TransitionValues, TransitionValues)}
 * with each set of start/end values on this transition. The
 * TransitionSet subclass overrides this method and delegates it to
 * each of its children in succession./*from  w w w . j a  v a 2  s.c  om*/
 *
 * @hide
 */
protected void createAnimators(ViewGroup sceneRoot, TransitionValuesMaps startValues,
        TransitionValuesMaps endValues, ArrayList<TransitionValues> startValuesList,
        ArrayList<TransitionValues> endValuesList) {
    if (DBG) {
        Log.d(LOG_TAG, "createAnimators() for " + this);
    }
    ArrayMap<Animator, AnimationInfo> runningAnimators = getRunningAnimators();
    long minStartDelay = Long.MAX_VALUE;
    int minAnimator = mAnimators.size();
    SparseArray<Long> startDelays = new SparseArray<Long>();
    int startValuesListCount = startValuesList.size();
    for (int i = 0; i < startValuesListCount; ++i) {
        TransitionValues start = startValuesList.get(i);
        TransitionValues end = endValuesList.get(i);
        if (start != null && !start.targetedTransitions.contains(this)) {
            start = null;
        }
        if (end != null && !end.targetedTransitions.contains(this)) {
            end = null;
        }
        if (start == null && end == null) {
            continue;
        }
        // Only bother trying to animate with values that differ between start/end
        boolean isChanged = start == null || end == null || isTransitionRequired(start, end);
        if (isChanged) {
            if (DBG) {
                View view = (end != null) ? end.view : start.view;
                Log.d(LOG_TAG, "  differing start/end values for view " + view);
                if (start == null || end == null) {
                    Log.d(LOG_TAG, "    "
                            + ((start == null) ? "start null, end non-null" : "start non-null, end null"));
                } else {
                    for (String key : start.values.keySet()) {
                        Object startValue = start.values.get(key);
                        Object endValue = end.values.get(key);
                        if (startValue != endValue && !startValue.equals(endValue)) {
                            Log.d(LOG_TAG, "    " + key + ": start(" + startValue + "), end(" + endValue + ")");
                        }
                    }
                }
            }
            // TODO: what to do about targetIds and itemIds?
            Animator animator = createAnimator(sceneRoot, start, end);
            if (animator != null) {
                // Save animation info for future cancellation purposes
                View view;
                TransitionValues infoValues = null;
                if (end != null) {
                    view = end.view;
                    String[] properties = getTransitionProperties();
                    if (view != null && properties != null && properties.length > 0) {
                        infoValues = new TransitionValues();
                        infoValues.view = view;
                        TransitionValues newValues = endValues.viewValues.get(view);
                        if (newValues != null) {
                            for (int j = 0; j < properties.length; ++j) {
                                infoValues.values.put(properties[j], newValues.values.get(properties[j]));
                            }
                        }
                        synchronized (sRunningAnimators) {
                            int numExistingAnims = runningAnimators.size();
                            for (int j = 0; j < numExistingAnims; ++j) {
                                Animator anim = runningAnimators.keyAt(j);
                                AnimationInfo info = runningAnimators.get(anim);
                                if (info.values != null && info.view == view
                                        && ((info.name == null && getName() == null)
                                                || (info.name != null && info.name.equals(getName())))) {
                                    if (info.values.equals(infoValues)) {
                                        // Favor the old animator
                                        animator = null;
                                        break;
                                    }
                                }
                            }
                        }
                    }
                } else {
                    view = start.view;
                }
                if (animator != null) {
                    if (mPropagation != null) {
                        long delay = mPropagation.getStartDelay(sceneRoot, this, start, end);
                        startDelays.put(mAnimators.size(), delay);
                        minStartDelay = Math.min(delay, minStartDelay);
                    }
                    AnimationInfo info = new AnimationInfo(view, getName(), this,
                            ViewUtils.getWindowId(sceneRoot), infoValues);
                    runningAnimators.put(animator, info);
                    mAnimators.add(animator);
                }
            }
        }
    }
    if (startDelays.size() != 0) {
        for (int i = 0; i < startDelays.size(); i++) {
            int index = startDelays.keyAt(i);
            Animator animator = mAnimators.get(index);
            long delay = startDelays.valueAt(i) - minStartDelay + animator.getStartDelay();
            animator.setStartDelay(delay);
        }
    }
}

From source file:org.tvbrowser.tvbrowser.TvBrowser.java

private void uploadChannels() {
    String[] projection = { TvBrowserContentProvider.GROUP_KEY_GROUP_ID,
            TvBrowserContentProvider.CHANNEL_KEY_CHANNEL_ID,
            TvBrowserContentProvider.CHANNEL_KEY_ORDER_NUMBER };

    Cursor channels = getContentResolver().query(TvBrowserContentProvider.CONTENT_URI_CHANNELS, projection,
            TvBrowserContentProvider.CHANNEL_KEY_SELECTION, null,
            TvBrowserContentProvider.CHANNEL_KEY_ORDER_NUMBER);

    SparseArray<String> groupKeys = new SparseArray<String>();

    StringBuilder uploadChannels = new StringBuilder();

    try {// ww  w  .  j ava2  s  . co m
        channels.moveToPosition(-1);

        int groupKeyColumn = channels.getColumnIndex(TvBrowserContentProvider.GROUP_KEY_GROUP_ID);
        int channelKeyColumn = channels.getColumnIndex(TvBrowserContentProvider.CHANNEL_KEY_CHANNEL_ID);
        int channelKeyOrderNumberColumn = channels
                .getColumnIndex(TvBrowserContentProvider.CHANNEL_KEY_ORDER_NUMBER);

        while (channels.moveToNext()) {
            int groupKey = channels.getInt(groupKeyColumn);
            String channelId = channels.getString(channelKeyColumn);
            int orderNumber = channels.getInt(channelKeyOrderNumberColumn);

            String groupId = groupKeys.get(groupKey);

            if (groupId == null) {
                String[] groupProjection = { TvBrowserContentProvider.GROUP_KEY_GROUP_ID,
                        TvBrowserContentProvider.GROUP_KEY_DATA_SERVICE_ID };

                Cursor groups = getContentResolver().query(TvBrowserContentProvider.CONTENT_URI_GROUPS,
                        groupProjection, TvBrowserContentProvider.KEY_ID + "=" + groupKey, null, null);

                try {
                    if (groups.moveToFirst()) {
                        String dataServiceId = groups.getString(
                                groups.getColumnIndex(TvBrowserContentProvider.GROUP_KEY_DATA_SERVICE_ID));
                        String goupIdValue = groups
                                .getString(groups.getColumnIndex(TvBrowserContentProvider.GROUP_KEY_GROUP_ID));

                        String dataServiceIdNumber = SettingConstants.getNumberForDataServiceKey(dataServiceId);

                        if (dataServiceIdNumber != null) {
                            if (dataServiceId.equals(SettingConstants.EPG_FREE_KEY)) {
                                groupId = dataServiceIdNumber + ":" + goupIdValue + ":";
                            } else if (dataServiceId.equals(SettingConstants.EPG_DONATE_KEY)) {
                                groupId = dataServiceIdNumber + ":";
                            }
                            groupKeys.put(groupKey, groupId);
                        }
                    }
                } finally {
                    groups.close();
                }
            }

            uploadChannels.append(groupId).append(channelId);

            if (orderNumber > 0) {
                uploadChannels.append(":").append(orderNumber);
            }

            uploadChannels.append("\n");
        }
    } finally {
        channels.close();
    }

    if (uploadChannels.toString().trim().length() > 0) {
        startSynchronizeUp(true, uploadChannels.toString().trim(),
                "http://android.tvbrowser.org/data/scripts/syncUp.php?type=channelsFromDesktop",
                SettingConstants.SYNCHRONIZE_UP_DONE, getString(R.string.backup_channels_success));
    }
}