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

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

Introduction

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

Prototype

public K keyAt(int i) 

Source Link

Usage

From source file:Main.java

public static <T> void addKeys(SimpleArrayMap<T, ?> map, List<T> target) {
    int N = map.size();
    for (int i = 0; i < N; i++) {
        T p = map.keyAt(i);
        target.add(p);/*from   www  .j av  a2 s . c  om*/
    }
}

From source file:jahirfiquitiva.iconshowcase.tasks.LoadAppsToRequest.java

private static void showDuplicatedComponentsInLog(ArrayList<String> components, Context context) {

    String[] componentsArray = new String[components.size()];
    componentsArray = components.toArray(componentsArray);

    SimpleArrayMap<String, Integer> occurrences = new SimpleArrayMap<>();

    int count = 0;

    for (String word : componentsArray) {
        count = occurrences.get(word) == null ? 0 : occurrences.get(word);
        occurrences.put(word, count + 1);
    }/*www. jav  a 2  s. c  om*/

    for (int i = 0; i < occurrences.size(); i++) {
        String word = occurrences.keyAt(i);
        if (count > 0) {
            Utils.showAppFilterLog(context,
                    "Duplicated component: \'" + word + "\' - " + String.valueOf(count) + " times.");
        }
    }

    Utils.showAppFilterLog(context, "----- END OF APPFILTER DEBUG -----");

}

From source file:com.novoda.downloadmanager.notifications.SynchronisedDownloadNotifier.java

/**
 * Update Notifications to reflect the given set of
 * {@link DownloadBatch}, adding, collapsing, and removing as needed.
 *///from   w  ww. j  a  va  2 s. c  o  m
@Override
public void updateWith(Collection<DownloadBatch> batches) {
    synchronized (activeNotifications) {
        SimpleArrayMap<String, Collection<DownloadBatch>> clusters = getClustersByNotificationTag(batches);

        for (int i = 0, size = clusters.size(); i < size; i++) {
            String notificationId = clusters.keyAt(i);
            long firstShown = getFirstShownTime(notificationId);
            notificationDisplayer.buildAndShowNotification(clusters, notificationId, firstShown);
        }

        List<Integer> staleTagsToBeRemoved = getStaleTagsThatWereNotRenewed(clusters);
        notificationDisplayer.cancelStaleTags(staleTagsToBeRemoved);
    }
}

From source file:com.google.blockly.model.Workspace.java

/**
 * Reads the workspace in from a XML stream. This will clear the workspace and replace it with
 * the contents of the xml./*from  w w  w.  j a  v  a 2s. co m*/
 *
 * @param is The input stream to read from.
 * @throws BlockLoadingException If workspace was not loaded. May wrap an IOException or another
 *                               BlockLoadingException.
 */
public void loadWorkspaceContents(InputStream is) throws BlockLoadingException {
    List<Block> newBlocks = BlocklyXmlHelper.loadFromXml(is, mBlockFactory);

    // Successfully deserialized.  Update workspace.
    // TODO: (#22) Add proper variable support.
    // For now just save and restore the list of variables.
    SimpleArrayMap<String, String> varsMap = mVariableNameManager.getUsedNames();
    String[] vars = new String[varsMap.size()];
    for (int i = 0; i < varsMap.size(); i++) {
        vars[i] = varsMap.keyAt(i);
    }
    mController.resetWorkspace();
    for (int i = 0; i < vars.length; i++) {
        mController.addVariable(vars[i]);
    }

    mRootBlocks.addAll(newBlocks);
    for (int i = 0; i < mRootBlocks.size(); i++) {
        mStats.collectStats(mRootBlocks.get(i), true /* recursive */);
    }
}

From source file:com.facebook.litho.DataFlowTransitionManager.java

private void setAppearFromValues() {
    SimpleArrayMap<ComponentProperty, RuntimeValue> appearFromValues = new SimpleArrayMap<>();
    for (int i = 0, size = mAnimationBindings.size(); i < size; i++) {
        final AnimationBinding binding = mAnimationBindings.get(i);
        binding.collectAppearFromValues(appearFromValues);
    }/*w ww .  j a  v  a  2s .  co m*/

    for (int i = 0, size = appearFromValues.size(); i < size; i++) {
        final ComponentProperty property = appearFromValues.keyAt(i);
        final RuntimeValue runtimeValue = appearFromValues.valueAt(i);
        final AnimationState animationState = mAnimationStates.get(property.getTransitionKey());
        final float value = runtimeValue.resolve(mResolver, property);
        property.getProperty().set(animationState.mountItem, value);

        if (animationState.changeType != KeyStatus.APPEARED) {
            throw new RuntimeException("Wrong transition type for appear of key " + property.getTransitionKey()
                    + ": " + keyStatusToString(animationState.changeType));
        }
        animationState.currentDiff.beforeValues.put(property.getProperty(), value);
    }
}

From source file:com.facebook.litho.DataFlowTransitionManager.java

private void setDisappearToValues() {
    SimpleArrayMap<ComponentProperty, RuntimeValue> disappearToValues = new SimpleArrayMap<>();
    for (int i = 0, size = mAnimationBindings.size(); i < size; i++) {
        final AnimationBinding binding = mAnimationBindings.get(i);
        binding.collectDisappearToValues(disappearToValues);
    }//from w w  w .j a  va2 s.  com

    for (int i = 0, size = disappearToValues.size(); i < size; i++) {
        final ComponentProperty property = disappearToValues.keyAt(i);
        final RuntimeValue runtimeValue = disappearToValues.valueAt(i);
        final AnimationState animationState = mAnimationStates.get(property.getTransitionKey());
        if (animationState.changeType != KeyStatus.DISAPPEARED) {
            throw new RuntimeException("Wrong transition type for disappear of key "
                    + property.getTransitionKey() + ": " + keyStatusToString(animationState.changeType));
        }
        final float value = runtimeValue.resolve(mResolver, property);
        animationState.currentDiff.afterValues.put(property.getProperty(), value);
    }
}

From source file:com.facebook.litho.ComponentsStethoManagerImpl.java

public void applyOverrides(InternalNode node) {
    final String nodeKey = getGlobalKey(node, 0); // We only override the root

    if (mStyleOverrides.containsKey(nodeKey)) {
        final SimpleArrayMap<String, String> styles = mStyleOverrides.get(nodeKey);
        for (int i = 0, size = styles.size(); i < size; i++) {
            final String key = styles.keyAt(i);
            final String value = styles.get(key);

            try {
                if (key.equals("background")) {
                    node.backgroundColor(parseColor(value));
                }/*from w w w. ja  va2 s. c o  m*/

                if (key.equals("foreground")) {
                    node.foregroundColor(parseColor(value));
                }

                if (key.equals("direction")) {
                    node.layoutDirection(YogaDirection.valueOf(toEnumString(value)));
                }

                if (key.equals("flex-direction")) {
                    node.flexDirection(YogaFlexDirection.valueOf(toEnumString(value)));
                }

                if (key.equals("justify-content")) {
                    node.justifyContent(YogaJustify.valueOf(toEnumString(value)));
                }

                if (key.equals("align-items")) {
                    node.alignItems(YogaAlign.valueOf(toEnumString(value)));
                }

                if (key.equals("align-self")) {
                    node.alignSelf(YogaAlign.valueOf(toEnumString(value)));
                }

                if (key.equals("align-content")) {
                    node.alignContent(YogaAlign.valueOf(toEnumString(value)));
                }

                if (key.equals("position")) {
                    node.positionType(YogaPositionType.valueOf(toEnumString(value)));
                }

                if (key.equals("flex-grow")) {
                    node.flexGrow(parseFloat(value));
                }

                if (key.equals("flex-shrink")) {
                    node.flexShrink(parseFloat(value));
                }
            } catch (IllegalArgumentException ignored) {
                // ignore errors when the user suplied an invalid enum value
            }

            if (key.equals("flex-basis")) {
                final YogaValue flexBasis = yogaValueFromString(value);
                if (flexBasis == null) {
                    continue;
                }
                switch (flexBasis.unit) {
                case AUTO:
                    node.flexBasisAuto();
                    break;
                case UNDEFINED:
                case POINT:
                    node.flexBasisPx(FastMath.round(flexBasis.value));
                    break;
                case PERCENT:
                    node.flexBasisPercent(FastMath.round(flexBasis.value));
                    break;
                }
            }

            if (key.equals("width")) {
                final YogaValue width = yogaValueFromString(value);
                if (width == null) {
                    continue;
                }
                switch (width.unit) {
                case AUTO:
                    node.widthAuto();
                    break;
                case UNDEFINED:
                case POINT:
                    node.widthPx(FastMath.round(width.value));
                    break;
                case PERCENT:
                    node.widthPercent(FastMath.round(width.value));
                    break;
                }
            }

            if (key.equals("min-width")) {
                final YogaValue minWidth = yogaValueFromString(value);
                if (minWidth == null) {
                    continue;
                }
                switch (minWidth.unit) {
                case UNDEFINED:
                case POINT:
                    node.minWidthPx(FastMath.round(minWidth.value));
                    break;
                case PERCENT:
                    node.minWidthPercent(FastMath.round(minWidth.value));
                    break;
                }
            }

            if (key.equals("max-width")) {
                final YogaValue maxWidth = yogaValueFromString(value);
                if (maxWidth == null) {
                    continue;
                }
                switch (maxWidth.unit) {
                case UNDEFINED:
                case POINT:
                    node.maxWidthPx(FastMath.round(maxWidth.value));
                    break;
                case PERCENT:
                    node.maxWidthPercent(FastMath.round(maxWidth.value));
                    break;
                }
            }

            if (key.equals("height")) {
                final YogaValue height = yogaValueFromString(value);
                if (height == null) {
                    continue;
                }
                switch (height.unit) {
                case AUTO:
                    node.heightAuto();
                    break;
                case UNDEFINED:
                case POINT:
                    node.heightPx(FastMath.round(height.value));
                    break;
                case PERCENT:
                    node.heightPercent(FastMath.round(height.value));
                    break;
                }
            }

            if (key.equals("min-height")) {
                final YogaValue minHeight = yogaValueFromString(value);
                if (minHeight == null) {
                    continue;
                }
                switch (minHeight.unit) {
                case UNDEFINED:
                case POINT:
                    node.minHeightPx(FastMath.round(minHeight.value));
                    break;
                case PERCENT:
                    node.minHeightPercent(FastMath.round(minHeight.value));
                    break;
                }
            }

            if (key.equals("max-height")) {
                final YogaValue maxHeight = yogaValueFromString(value);
                if (maxHeight == null) {
                    continue;
                }
                switch (maxHeight.unit) {
                case UNDEFINED:
                case POINT:
                    node.maxHeightPx(FastMath.round(maxHeight.value));
                    break;
                case PERCENT:
                    node.maxHeightPercent(FastMath.round(maxHeight.value));
                    break;
                }
            }

            for (YogaEdge edge : edges) {
                if (key.equals("margin-" + toCSSString(edge))) {
                    final YogaValue margin = yogaValueFromString(value);
                    if (margin == null) {
                        continue;
                    }
                    switch (margin.unit) {
                    case UNDEFINED:
                    case POINT:
                        node.marginPx(edge, FastMath.round(margin.value));
                        break;
                    case AUTO:
                        node.marginAuto(edge);
                        break;
                    case PERCENT:
                        node.marginPercent(edge, FastMath.round(margin.value));
                        break;
                    }
                }
            }

            for (YogaEdge edge : edges) {
                if (key.equals("padding-" + toCSSString(edge))) {
                    final YogaValue padding = yogaValueFromString(value);
                    if (padding == null) {
                        continue;
                    }
                    switch (padding.unit) {
                    case UNDEFINED:
                    case POINT:
                        node.paddingPx(edge, FastMath.round(padding.value));
                        break;
                    case PERCENT:
                        node.paddingPercent(edge, FastMath.round(padding.value));
                        break;
                    }
                }
            }

            for (YogaEdge edge : edges) {
                if (key.equals("position-" + toCSSString(edge))) {
                    final YogaValue position = yogaValueFromString(value);
                    if (position == null) {
                        continue;
                    }
                    switch (position.unit) {
                    case UNDEFINED:
                    case POINT:
                        node.positionPx(edge, FastMath.round(position.value));
                        break;
                    case PERCENT:
                        node.positionPercent(edge, FastMath.round(position.value));
                        break;
                    }
                }
            }

            for (YogaEdge edge : edges) {
                if (key.equals("border-" + toCSSString(edge))) {
                    final float border = parseFloat(value);
                    node.borderWidthPx(edge, FastMath.round(border));
                }
            }
        }
    }

    if (mPropOverrides.containsKey(nodeKey)) {
        final Component component = node.getRootComponent();
        if (component != null) {
            final SimpleArrayMap<String, String> props = mPropOverrides.get(nodeKey);
            for (int i = 0, size = props.size(); i < size; i++) {
                final String key = props.keyAt(i);
                applyReflectiveOverride(component, key, props.get(key));
            }
        }
    }

    if (mStateOverrides.containsKey(nodeKey)) {
        final Component component = node.getRootComponent();
        final ComponentLifecycle.StateContainer stateContainer = component == null ? null
                : component.getStateContainer();
        if (stateContainer != null) {
            final SimpleArrayMap<String, String> state = mStateOverrides.get(nodeKey);
            for (int i = 0, size = state.size(); i < size; i++) {
                final String key = state.keyAt(i);
                applyReflectiveOverride(stateContainer, key, state.get(key));
            }
        }
    }
}

From source file:com.google.blockly.model.VariableCategoryFactory.java

private void rebuildItems(BlocklyCategory category) {
    category.clear();//from  www.j a  v  a 2  s .c o  m
    category.addItem(new BlocklyCategory.ButtonItem(mContext.getString(R.string.create_variable),
            ACTION_CREATE_VARIABLE));
    SimpleArrayMap<String, String> variables = mVariableNameManager.getUsedNames();
    if (variables.size() == 0) {
        return;
    }
    try {
        Block setter = mBlockFactory.obtainBlockFrom(SET_VAR_TEMPLATE);
        category.addItem(new BlocklyCategory.BlockItem(setter));
    } catch (BlockLoadingException e) {
        Log.e(TAG, "Fail to obtain \"" + SET_VAR_TEMPLATE.mTypeName + "\" block.");
    }
    try {
        Block changer = mBlockFactory.obtainBlockFrom(CHANGE_VAR_TEMPLATE);
        category.addItem(new BlocklyCategory.BlockItem(changer));
    } catch (BlockLoadingException e) {
        Log.e(TAG, "Fail to obtain \"" + CHANGE_VAR_TEMPLATE.mTypeName + "\" block.");
    }
    ArrayList<String> varNames = new ArrayList<>(variables.size());
    for (int i = 0; i < variables.size(); i++) {
        varNames.add(variables.keyAt(i));
    }
    Collections.sort(varNames);

    try {
        for (int i = 0; i < varNames.size(); i++) {
            Block varBlock = mBlockFactory.obtainBlockFrom(GET_VAR_TEMPLATE);
            varBlock.getFieldByName(GET_VAR_FIELD).setFromString(varNames.get(i));
            category.addItem(new BlocklyCategory.BlockItem(varBlock));
        }
    } catch (BlockLoadingException e) {
        Log.e(TAG, "Fail to obtain \"" + GET_VAR_TEMPLATE.mTypeName + "\" block.");
    }
}

From source file:com.facebook.litho.DebugComponent.java

void applyOverrides() {
    final InternalNode node = mNode.get();
    if (node == null) {
        return;/*w ww.  jav a 2s.  com*/
    }

    if (mStyleOverrides.containsKey(mKey)) {
        final SimpleArrayMap<String, Object> styles = mStyleOverrides.get(mKey);
        for (int i = 0, size = styles.size(); i < size; i++) {
            final String key = styles.keyAt(i);
            final Object value = styles.get(key);

            try {
                if (key.equals("background")) {
                    node.backgroundColor((Integer) value);
                }

                if (key.equals("foreground")) {
                    node.foregroundColor((Integer) value);
                }

                if (key.equals("direction")) {
                    node.layoutDirection(YogaDirection.valueOf(((String) value).toUpperCase()));
                }

                if (key.equals("flex-direction")) {
                    node.flexDirection(YogaFlexDirection.valueOf(((String) value).toUpperCase()));
                }

                if (key.equals("justify-content")) {
                    node.justifyContent(YogaJustify.valueOf(((String) value).toUpperCase()));
                }

                if (key.equals("align-items")) {
                    node.alignItems(YogaAlign.valueOf(((String) value).toUpperCase()));
                }

                if (key.equals("align-self")) {
                    node.alignSelf(YogaAlign.valueOf(((String) value).toUpperCase()));
                }

                if (key.equals("align-content")) {
                    node.alignContent(YogaAlign.valueOf(((String) value).toUpperCase()));
                }

                if (key.equals("position")) {
                    node.positionType(YogaPositionType.valueOf(((String) value).toUpperCase()));
                }

                if (key.equals("flex-grow")) {
                    node.flexGrow((Float) value);
                }

                if (key.equals("flex-shrink")) {
                    node.flexShrink((Float) value);
                }
            } catch (IllegalArgumentException ignored) {
                // ignore errors when the user suplied an invalid enum value
            }

            if (key.equals("flex-basis")) {
                final YogaValue flexBasis = YogaValue.parse(((String) value).toLowerCase());
                if (flexBasis == null) {
                    continue;
                }
                switch (flexBasis.unit) {
                case AUTO:
                    node.flexBasisAuto();
                    break;
                case UNDEFINED:
                case POINT:
                    node.flexBasisPx(FastMath.round(flexBasis.value));
                    break;
                case PERCENT:
                    node.flexBasisPercent(FastMath.round(flexBasis.value));
                    break;
                }
            }

            if (key.equals("width")) {
                final YogaValue width = YogaValue.parse(((String) value).toLowerCase());
                if (width == null) {
                    continue;
                }
                switch (width.unit) {
                case AUTO:
                    node.widthAuto();
                    break;
                case UNDEFINED:
                case POINT:
                    node.widthPx(FastMath.round(width.value));
                    break;
                case PERCENT:
                    node.widthPercent(FastMath.round(width.value));
                    break;
                }
            }

            if (key.equals("min-width")) {
                final YogaValue minWidth = YogaValue.parse(((String) value).toLowerCase());
                if (minWidth == null) {
                    continue;
                }
                switch (minWidth.unit) {
                case UNDEFINED:
                case POINT:
                    node.minWidthPx(FastMath.round(minWidth.value));
                    break;
                case PERCENT:
                    node.minWidthPercent(FastMath.round(minWidth.value));
                    break;
                }
            }

            if (key.equals("max-width")) {
                final YogaValue maxWidth = YogaValue.parse(((String) value).toLowerCase());
                if (maxWidth == null) {
                    continue;
                }
                switch (maxWidth.unit) {
                case UNDEFINED:
                case POINT:
                    node.maxWidthPx(FastMath.round(maxWidth.value));
                    break;
                case PERCENT:
                    node.maxWidthPercent(FastMath.round(maxWidth.value));
                    break;
                }
            }

            if (key.equals("height")) {
                final YogaValue height = YogaValue.parse(((String) value).toLowerCase());
                if (height == null) {
                    continue;
                }
                switch (height.unit) {
                case AUTO:
                    node.heightAuto();
                    break;
                case UNDEFINED:
                case POINT:
                    node.heightPx(FastMath.round(height.value));
                    break;
                case PERCENT:
                    node.heightPercent(FastMath.round(height.value));
                    break;
                }
            }

            if (key.equals("min-height")) {
                final YogaValue minHeight = YogaValue.parse(((String) value).toLowerCase());
                if (minHeight == null) {
                    continue;
                }
                switch (minHeight.unit) {
                case UNDEFINED:
                case POINT:
                    node.minHeightPx(FastMath.round(minHeight.value));
                    break;
                case PERCENT:
                    node.minHeightPercent(FastMath.round(minHeight.value));
                    break;
                }
            }

            if (key.equals("max-height")) {
                final YogaValue maxHeight = YogaValue.parse(((String) value).toLowerCase());
                if (maxHeight == null) {
                    continue;
                }
                switch (maxHeight.unit) {
                case UNDEFINED:
                case POINT:
                    node.maxHeightPx(FastMath.round(maxHeight.value));
                    break;
                case PERCENT:
                    node.maxHeightPercent(FastMath.round(maxHeight.value));
                    break;
                }
            }

            for (YogaEdge edge : edges) {
                if (key.equals("margin-" + edge.toString().toLowerCase())) {
                    final YogaValue margin = YogaValue.parse(((String) value).toLowerCase());
                    if (margin == null) {
                        continue;
                    }
                    switch (margin.unit) {
                    case UNDEFINED:
                    case POINT:
                        node.marginPx(edge, FastMath.round(margin.value));
                        break;
                    case AUTO:
                        node.marginAuto(edge);
                        break;
                    case PERCENT:
                        node.marginPercent(edge, FastMath.round(margin.value));
                        break;
                    }
                }
            }

            for (YogaEdge edge : edges) {
                if (key.equals("padding-" + edge.toString().toLowerCase())) {
                    final YogaValue padding = YogaValue.parse(((String) value).toLowerCase());
                    if (padding == null) {
                        continue;
                    }
                    switch (padding.unit) {
                    case UNDEFINED:
                    case POINT:
                        node.paddingPx(edge, FastMath.round(padding.value));
                        break;
                    case PERCENT:
                        node.paddingPercent(edge, FastMath.round(padding.value));
                        break;
                    }
                }
            }

            for (YogaEdge edge : edges) {
                if (key.equals("position-" + edge.toString().toLowerCase())) {
                    final YogaValue position = YogaValue.parse(((String) value).toLowerCase());
                    if (position == null) {
                        continue;
                    }
                    switch (position.unit) {
                    case UNDEFINED:
                    case POINT:
                        node.positionPx(edge, FastMath.round(position.value));
                        break;
                    case PERCENT:
                        node.positionPercent(edge, FastMath.round(position.value));
                        break;
                    }
                }
            }

            for (YogaEdge edge : edges) {
                if (key.equals("border-" + edge.toString().toLowerCase())) {
                    node.borderWidthPx(edge, FastMath.round((Float) value));
                }
            }
        }
    }

    if (mPropOverrides.containsKey(mKey)) {
        final Component component = node.getRootComponent();
        if (component != null) {
            final SimpleArrayMap<String, Object> props = mPropOverrides.get(mKey);
            for (int i = 0, size = props.size(); i < size; i++) {
                final String key = props.keyAt(i);
                applyReflectiveOverride(component, key, props.get(key));
            }
        }
    }

    if (mStateOverrides.containsKey(mKey)) {
        final Component component = node.getRootComponent();
        final ComponentLifecycle.StateContainer stateContainer = component == null ? null
                : component.getStateContainer();
        if (stateContainer != null) {
            final SimpleArrayMap<String, Object> state = mStateOverrides.get(mKey);
            for (int i = 0, size = state.size(); i < size; i++) {
                final String key = state.keyAt(i);
                applyReflectiveOverride(stateContainer, key, state.get(key));
            }
        }
    }
}