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

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

Introduction

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

Prototype

public int size() 

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);//  ww  w .j av  a  2  s .  c  o m
        target.add(p);
    }
}

From source file:Main.java

public static <T> void addValues(SimpleArrayMap<?, T> map, List<T> target) {
    int N = map.size();
    for (int i = 0; i < N; i++) {
        T p = map.valueAt(i);/*  ww w .j av a  2 s  . c o  m*/
        target.add(p);
    }
}

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);
    }//from  w  ww  . j  av a 2 s .co  m

    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.bmd.android.collection.internal.SimpleArrayMapReverseIterator.java

public SimpleArrayMapReverseIterator(final SimpleArrayMap<K, V> arrayMap) {

    super(arrayMap.size());

    mArrayMap = arrayMap;
}

From source file:com.bmd.android.collection.internal.SimpleArrayMapIterator.java

public SimpleArrayMapIterator(final SimpleArrayMap<K, V> arrayMap) {

    super(arrayMap.size());

    mArrayMap = arrayMap;
}

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

private void rebuildItems(BlocklyCategory category) {
    category.clear();/*from   w  ww .ja v  a2s.co  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.novoda.downloadmanager.notifications.SynchronisedDownloadNotifier.java

/**
 * Update Notifications to reflect the given set of
 * {@link DownloadBatch}, adding, collapsing, and removing as needed.
 *///from ww  w .  java2s . c  om
@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.android.gcm.demo.ui.GroupsFragment.java

@Override
public void refresh() {
    float density = getActivity().getResources().getDisplayMetrics().density;
    SimpleArrayMap<String, Sender> senders = mSenders.getSenders();
    LinearLayout sendersList = new LinearLayout(getActivity());
    sendersList.setOrientation(LinearLayout.VERTICAL);
    for (int i = 0; i < senders.size(); i++) {
        Sender sender = senders.valueAt(i);
        if (sender.groups.size() > 0) {
            LinearLayout senderRow = (LinearLayout) getActivity().getLayoutInflater()
                    .inflate(R.layout.widget_icon_text_button_row, sendersList, false);
            ImageView senderIcon = (ImageView) senderRow.findViewById(R.id.widget_itbr_icon);
            TextView senderText = (TextView) senderRow.findViewById(R.id.widget_itbr_text);
            senderRow.findViewById(R.id.widget_itbr_button).setVisibility(View.GONE);
            senderIcon.setImageResource(R.drawable.cloud_googblue);
            senderIcon.setPadding(0, 0, (int) (8 * density), 0);
            senderText.setText(getString(R.string.groups_sender_id, sender.senderId));
            sendersList.addView(senderRow);
            for (DeviceGroup deviceGroup : sender.groups.values()) {
                LinearLayout row = (LinearLayout) getActivity().getLayoutInflater()
                        .inflate(R.layout.widget_icon_text_button_row, sendersList, false);
                ImageView icon = (ImageView) row.findViewById(R.id.widget_itbr_icon);
                TextView label = (TextView) row.findViewById(R.id.widget_itbr_text);
                Button button = (Button) row.findViewById(R.id.widget_itbr_button);
                icon.setImageResource(R.drawable.group_grey600);
                label.setText(deviceGroup.notificationKeyName);
                label.setBackgroundResource(selectableBackgroundResource);
                label.setTag(R.id.tag_action, ACTION_OPEN_GROUP);
                label.setTag(R.id.tag_senderid, sender.senderId);
                label.setTag(R.id.tag_group, deviceGroup.notificationKeyName);
                label.setOnClickListener(this);

                button.setText(R.string.groups_delete);
                button.setTag(R.id.tag_action, ACTION_DELETE_GROUP);
                button.setTag(R.id.tag_senderid, sender.senderId);
                button.setTag(R.id.tag_group, deviceGroup.notificationKeyName);
                button.setOnClickListener(this);
                row.setPadding((int) (16 * density), 0, 0, 0);
                sendersList.addView(row);
            }//w w w  .j a  va2s .  co m
        }
    }
    if (sendersList.getChildCount() == 0) {
        TextView noTokens = new TextView(getActivity());
        noTokens.setText(getString(R.string.groups_no_groups_available));
        noTokens.setTypeface(null, Typeface.ITALIC);
        sendersList.addView(noTokens);
    }
    FrameLayout topicsView = (FrameLayout) getActivity().findViewById(R.id.groups_list_wrapper);
    topicsView.removeAllViews();
    topicsView.addView(sendersList);
}

From source file:com.google.android.gcm.demo.ui.TopicsFragment.java

@Override
public void refresh() {
    float density = getActivity().getResources().getDisplayMetrics().density;
    SimpleArrayMap<String, Sender> addressBook = mSenders.getSenders();
    LinearLayout sendersList = new LinearLayout(getActivity());
    sendersList.setOrientation(LinearLayout.VERTICAL);
    for (int i = 0; i < addressBook.size(); i++) {
        Sender sender = addressBook.valueAt(i);
        // Check if at least a topic is subscribed for this sender
        int subscribedTopics = 0;
        for (Boolean subscribed : sender.topics.values()) {
            if (subscribed) {
                subscribedTopics++;/*from   w  w  w.  jav a2 s . co  m*/
            }
        }
        if (subscribedTopics > 0) {
            LinearLayout senderRow = (LinearLayout) getActivity().getLayoutInflater()
                    .inflate(R.layout.widget_icon_text_button_row, sendersList, false);
            ImageView senderIcon = (ImageView) senderRow.findViewById(R.id.widget_itbr_icon);
            TextView senderLabel = (TextView) senderRow.findViewById(R.id.widget_itbr_text);
            senderRow.findViewById(R.id.widget_itbr_button).setVisibility(View.GONE);
            senderIcon.setImageResource(R.drawable.cloud_googblue);
            senderIcon.setPadding(0, 0, (int) (8 * density), 0);
            senderLabel.setText(getString(R.string.topics_sender_id, sender.senderId));
            sendersList.addView(senderRow);
            for (Map.Entry<String, Boolean> topic : sender.topics.entrySet()) {
                if (topic.getValue()) {
                    LinearLayout row = (LinearLayout) getActivity().getLayoutInflater()
                            .inflate(R.layout.widget_icon_text_button_row, sendersList, false);
                    ImageView icon = (ImageView) row.findViewById(R.id.widget_itbr_icon);
                    TextView label = (TextView) row.findViewById(R.id.widget_itbr_text);
                    Button button = (Button) row.findViewById(R.id.widget_itbr_button);
                    icon.setImageResource(R.drawable.bigtop_updates_grey600);
                    label.setText(topic.getKey());
                    button.setText(R.string.topics_unsubscribe);
                    button.setTag(R.id.tag_action, ACTION_UNSUBSCRIBE);
                    button.setTag(R.id.tag_senderid, sender.senderId);
                    button.setTag(R.id.tag_topic, topic.getKey());
                    button.setOnClickListener(this);
                    row.setPadding((int) (16 * density), 0, 0, 0);
                    sendersList.addView(row);
                }
            }
        }
    }
    if (sendersList.getChildCount() == 0) {
        TextView noTokens = new TextView(getActivity());
        noTokens.setText(getString(R.string.topics_no_topic_subscribed));
        noTokens.setTypeface(null, Typeface.ITALIC);
        sendersList.addView(noTokens);
    }
    FrameLayout topicsView = (FrameLayout) getActivity().findViewById(R.id.topics_list_wrapper);
    topicsView.removeAllViews();
    topicsView.addView(sendersList);
}

From source file:com.google.android.gcm.demo.ui.InstanceIdFragment.java

@Override
public void refresh() {
    new AsyncTask<Void, Void, Void>() {
        @Override/*from ww  w . java 2s.c  o m*/
        protected Void doInBackground(Void... params) {
            final String instanceId = mInstanceIdHelper.getInstanceId();
            final String creationTime = DateFormat.getDateTimeInstance()
                    .format(new Date(mInstanceIdHelper.getCreationTime()));
            final Activity activity = getActivity();
            if (activity != null) {
                Handler handler = new Handler(activity.getMainLooper());
                handler.post(new Runnable() {
                    public void run() {
                        setValue(activity.findViewById(R.id.iid_instance_id), instanceId);
                        setValue(activity.findViewById(R.id.iid_creation_time), creationTime);
                    }
                });
            }
            return null;
        }
    }.execute();
    float density = getActivity().getResources().getDisplayMetrics().density;
    SimpleArrayMap<String, Sender> addressBook = mSenders.getSenders();
    LinearLayout sendersList = new LinearLayout(getActivity());
    sendersList.setOrientation(LinearLayout.VERTICAL);
    for (int i = 0; i < addressBook.size(); i++) {
        Sender sender = addressBook.valueAt(i);
        if (sender.appTokens.size() > 0) {
            LinearLayout senderRow = (LinearLayout) getActivity().getLayoutInflater()
                    .inflate(R.layout.widget_icon_text_button_row, sendersList, false);
            ImageView senderIcon = (ImageView) senderRow.findViewById(R.id.widget_itbr_icon);
            TextView senderLabel = (TextView) senderRow.findViewById(R.id.widget_itbr_text);
            senderRow.findViewById(R.id.widget_itbr_button).setVisibility(View.GONE);
            senderIcon.setImageResource(R.drawable.cloud_googblue);
            senderIcon.setPadding(0, 0, (int) (8 * density), 0);
            senderLabel.setText(getString(R.string.topics_sender_id, sender.senderId));
            sendersList.addView(senderRow);
            for (Token token : sender.appTokens.values()) {
                LinearLayout row = (LinearLayout) getActivity().getLayoutInflater()
                        .inflate(R.layout.widget_icon_text_button_row, sendersList, false);
                ImageView icon = (ImageView) row.findViewById(R.id.widget_itbr_icon);
                TextView label = (TextView) row.findViewById(R.id.widget_itbr_text);
                Button button = (Button) row.findViewById(R.id.widget_itbr_button);
                icon.setImageResource(R.drawable.smartphone_grey600);
                label.setText(token.scope + " - " + AbstractFragment.truncateToMediumString(token.token));
                button.setText(R.string.iid_delete_token);
                button.setTag(R.id.tag_senderid, sender.senderId);
                button.setTag(R.id.tag_scope, token.scope);
                button.setOnClickListener(this);
                row.setPadding((int) (16 * density), 0, 0, 0);
                sendersList.addView(row);
            }
        }
    }
    if (sendersList.getChildCount() == 0) {
        TextView noTokens = new TextView(getActivity());
        noTokens.setText(getString(R.string.iid_no_tokens));
        noTokens.setTypeface(null, Typeface.ITALIC);
        sendersList.addView(noTokens);
    }
    FrameLayout tokensView = (FrameLayout) getActivity().findViewById(R.id.iid_tokens_wrapper);
    tokensView.removeAllViews();
    tokensView.addView(sendersList);
}