Example usage for android.util SparseArray size

List of usage examples for android.util SparseArray size

Introduction

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

Prototype

public int size() 

Source Link

Document

Returns the number of key-value mappings that this SparseArray currently stores.

Usage

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

private static void setViewTags(View view, SparseArray<Object> viewTags) {
    if (viewTags == null) {
        return;//from  ww  w  . j a va  2 s . c  o  m
    }

    if (view instanceof ComponentHost) {
        final ComponentHost host = (ComponentHost) view;
        host.setViewTags(viewTags);
    } else {
        for (int i = 0, size = viewTags.size(); i < size; i++) {
            view.setTag(viewTags.keyAt(i), viewTags.valueAt(i));
        }
    }
}

From source file:com.irccloud.android.fragment.BuffersListFragment.java

@Override
public void onSaveInstanceState(Bundle state) {
    if (adapter != null && adapter.data != null && adapter.data.size() > 0) {
        ArrayList<Integer> expandedArchives = new ArrayList<Integer>();
        SparseArray<ServersDataSource.Server> servers = ServersDataSource.getInstance().getServers();
        for (int i = 0; i < servers.size(); i++) {
            ServersDataSource.Server s = servers.valueAt(i);
            if (mExpandArchives.get(s.cid, false))
                expandedArchives.add(s.cid);
        }/*from  w w  w  .  j  ava2 s  .co m*/
        state.putIntegerArrayList("expandedArchives", expandedArchives);
        if (listView != null)
            state.putInt("scrollPosition", listView.getFirstVisiblePosition());
    }
}

From source file:com.blestep.sportsbracelet.view.TimelineChartView.java

private void drawBarItems(Canvas c, SparseArray<Object[]> data, double maxValue) {

    final float halfItemBarWidth = mBarItemWidth / 2;
    final float height = mGraphArea.height();
    final Paint seriesBgPaint;
    final Paint highlightSeriesBgPaint;
    synchronized (mLock) {
        seriesBgPaint = mBarItemBgPaint;
        highlightSeriesBgPaint = mHighlightBarItemBgPaint;
    }/*from  www .j  a va  2 s.  c o  m*/

    // Apply zoom animation
    final float graphCenterX = mGraphArea.left + (mGraphArea.width() / 2);

    final int size = data.size() - 1;
    for (int i = mItemsOnScreen[1]; i >= mItemsOnScreen[0] && i <= data.size(); i--) {
        final float barCenterX = graphCenterX + mCurrentOffset - (mBarWidth * (size - i));
        // ?
        double value = (double) data.valueAt(i)[1];
        float barTop = (float) (height - ((height * ((value * 100) / maxValue)) / 100)) + mTopSpaceHeight;
        float barBottom = height;
        float barLeft = barCenterX - halfItemBarWidth;
        float barRight = barCenterX + halfItemBarWidth;
        final Paint paint;
        // ?
        paint = barLeft < graphCenterX && barRight > graphCenterX
                && (mLastPosition == mCurrentPosition || (mState != STATE_SCROLLING)) ? highlightSeriesBgPaint
                        : seriesBgPaint;
        // 
        c.drawRect(barLeft, mGraphArea.top + barTop, barRight, mGraphArea.top + barBottom, paint);
    }
}

From source file:com.blestep.sportsbracelet.view.TimelineChartViewSleep.java

private void drawBarItems(Canvas c, SparseArray<Object[]> data, double maxValue) {

    final float halfItemBarWidth = mBarItemWidth / 2;
    final float height = mGraphArea.height();
    final Paint seriesBgPaint;
    final Paint highlightSeriesBgPaint;
    final Paint seriesDeepBgPaint;
    final Paint highlightSeriesDeepBgPaint;
    synchronized (mLock) {
        seriesBgPaint = mBarItemBgPaint;
        highlightSeriesBgPaint = mHighlightBarItemBgPaint;
        seriesDeepBgPaint = mBarDeepItemBgPaint;
        highlightSeriesDeepBgPaint = mHighlightBarDeepItemBgPaint;
    }/*w  ww .j  ava 2s . co m*/

    // Apply zoom animation
    final float graphCenterX = mGraphArea.left + (mGraphArea.width() / 2);

    final int size = data.size() - 1;
    for (int i = mItemsOnScreen[1]; i >= mItemsOnScreen[0] && i <= data.size(); i--) {
        final float barCenterX = graphCenterX + mCurrentOffset - (mBarWidth * (size - i));
        // ?
        double value = (double) data.valueAt(i)[6];
        // ?
        double deepValue = (double) data.valueAt(i)[3];
        float barTop = (float) (height - ((height * ((value * 100) / maxValue)) / 100)) + mTopSpaceHeight;
        float barBottom = height;
        float barLeft = barCenterX - halfItemBarWidth;
        float barRight = barCenterX + halfItemBarWidth;
        final Paint paint;
        final Paint deepPaint;
        float deepBarTop = (float) (height - ((height * ((deepValue * 100) / maxValue)) / 100))
                + mTopSpaceHeight;
        // ?
        paint = barLeft < graphCenterX && barRight > graphCenterX
                && (mLastPosition == mCurrentPosition || (mState != STATE_SCROLLING)) ? highlightSeriesBgPaint
                        : seriesBgPaint;
        // ?
        deepPaint = barLeft < graphCenterX && barRight > graphCenterX
                && (mLastPosition == mCurrentPosition || (mState != STATE_SCROLLING))
                        ? highlightSeriesDeepBgPaint
                        : seriesDeepBgPaint;
        // 
        c.drawRect(barLeft, mGraphArea.top + barTop, barRight, mGraphArea.top + barBottom, paint);
        c.drawRect(barLeft, mGraphArea.top + deepBarTop, barRight, mGraphArea.top + barBottom, deepPaint);
    }
}

From source file:com.blestep.sportsbracelet.view.TimelineChartView.java

private void processData() {
    if (mCursor != null && !mCursor.isClosed() && mCursor.moveToFirst()) {
        // Load the cursor to memory
        double max = 0d;
        final SparseArray<Object[]> data = new SparseArray<>(mCursor.getCount());

        do {//from w  ww  .j a  va2  s  .  c o  m
            int position = mCursor.getInt(0);
            String label = mCursor.getString(1);
            double stepCount = mCursor.getDouble(2);
            double stepDuration = mCursor.getDouble(3);
            double stepDistance = mCursor.getDouble(4);
            double stepCalorie = mCursor.getDouble(5);
            if (stepCount > max) {
                max = stepCount;
            }
            Object[] values = new Object[] { label, stepCount, stepDuration, stepDistance, stepCalorie };
            data.put(position, values);
        } while (mCursor.moveToNext());

        // Calculate the max available offset
        int size = data.size() - 1;
        float maxOffset = mBarWidth * size;

        //swap data
        synchronized (mLock) {
            mData = data;
            mMaxValue = max;
            mMaxOffset = maxOffset;
            mLastOffset = -1.f;
            mCurrentPosition = size;
            mCurrentOffset = computeOffsetForPosition(mCurrentPosition);
            setupTickLabels();
        }
    }
}

From source file:com.blestep.sportsbracelet.view.TimelineChartViewSleep.java

private void processData() {
    if (mCursor != null && !mCursor.isClosed() && mCursor.moveToFirst()) {
        // Load the cursor to memory
        double max = 0d;
        final SparseArray<Object[]> data = new SparseArray<>(mCursor.getCount());

        do {/*from w w w. j a v  a2  s . c o  m*/
            int position = mCursor.getInt(0);
            String label = mCursor.getString(1);
            String start = mCursor.getString(2);
            String end = mCursor.getString(3);
            double deep = mCursor.getDouble(4);
            double light = mCursor.getDouble(5);
            double awake = mCursor.getDouble(6);
            double asleep = mCursor.getDouble(7);
            if (asleep > max) {
                max = asleep;
            }
            Object[] values = new Object[] { label, start, end, deep, light, awake, asleep };
            data.put(position, values);
        } while (mCursor.moveToNext());

        // Calculate the max available offset
        int size = data.size() - 1;
        float maxOffset = mBarWidth * size;

        //swap data
        synchronized (mLock) {
            mData = data;
            mMaxValue = max;
            mMaxOffset = maxOffset;
            mLastOffset = -1.f;
            mCurrentPosition = size;
            mCurrentOffset = computeOffsetForPosition(mCurrentPosition);
            setupTickLabels();
        }
    }
}

From source file:org.telegraph.messenger.NotificationsController.java

public void processReadMessages(SparseArray<Long> inbox, long dialog_id, int max_date, int max_id,
        boolean isPopup) {
    int oldCount = popupMessages.size();
    if (inbox != null) {
        for (int b = 0; b < inbox.size(); b++) {
            int key = inbox.keyAt(b);
            long messageId = inbox.get(key);
            for (int a = 0; a < pushMessages.size(); a++) {
                MessageObject messageObject = pushMessages.get(a);
                if (messageObject.getDialogId() == key && messageObject.getId() <= (int) messageId) {
                    if (isPersonalMessage(messageObject)) {
                        personal_count--;
                    }/*from  w w w  .  j av  a2  s.  c  o m*/
                    popupMessages.remove(messageObject);
                    pushMessagesDict.remove(messageObject.getId());
                    delayedPushMessages.remove(messageObject);
                    pushMessages.remove(a);
                    a--;
                }
            }
        }
        if (pushMessages.isEmpty() && !popupMessages.isEmpty()) {
            popupMessages.clear();
        }
    }
    if (dialog_id != 0 && (max_id != 0 || max_date != 0)) {
        for (int a = 0; a < pushMessages.size(); a++) {
            MessageObject messageObject = pushMessages.get(a);
            if (messageObject.getDialogId() == dialog_id) {
                boolean remove = false;
                if (max_date != 0) {
                    if (messageObject.messageOwner.date <= max_date) {
                        remove = true;
                    }
                } else {
                    if (!isPopup) {
                        if (messageObject.getId() <= max_id || max_id < 0) {
                            remove = true;
                        }
                    } else {
                        if (messageObject.getId() == max_id || max_id < 0) {
                            remove = true;
                        }
                    }
                }
                if (remove) {
                    if (isPersonalMessage(messageObject)) {
                        personal_count--;
                    }
                    pushMessages.remove(a);
                    delayedPushMessages.remove(messageObject);
                    popupMessages.remove(messageObject);
                    pushMessagesDict.remove(messageObject.getId());
                    a--;
                }
            }
        }
        if (pushMessages.isEmpty() && !popupMessages.isEmpty()) {
            popupMessages.clear();
        }
    }
    if (oldCount != popupMessages.size()) {
        NotificationCenter.getInstance().postNotificationName(NotificationCenter.pushMessagesUpdated);
    }
}

From source file:com.oakesville.mythling.MediaActivity.java

@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
    if (v == getListView()) {
        AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
        Listable listable = (Listable) getListView().getItemAtPosition(info.position);
        if (listable instanceof Item) {
            Item item = (Item) listable;
            menu.setHeaderTitle(item.getDialogTitle());
            if (isSplitView()) {
                getListView().performItemClick(getListView().getChildAt(info.position), info.position,
                        getListView().getAdapter().getItemId(info.position));
            } else {
                getListView().setItemChecked(info.position, true);
            }// w w  w  .ja v  a  2s  . c  om
            SparseArray<String> menuItems = getLongClickMenuItems(item);
            for (int i = 0; i < menuItems.size(); i++) {
                int id = menuItems.keyAt(i);
                menu.add(MEDIA_ACTIVITY_CONTEXT_MENU_GROUP_ID, id, id, menuItems.get(id));
            }
        }
    }
}

From source file:com.ruesga.timelinechart.TimelineChartView.java

private void ensureBarWidth() {
    if (!mShowFooter) {
        return;/* w  ww  .  j a va2  s . c o  m*/
    }
    if (mTickTextLayouts != null) {
        float minWidth = 0.f;
        for (SparseArray<DynamicLayout> a : mTickTextLayouts) {
            int count = a.size();
            for (int i = 0; i < count; i++) {
                DynamicLayout layout = a.valueAt(i);
                final float width = layout.getWidth();
                if (minWidth < width) {
                    minWidth = width;
                }
            }
        }
        if (minWidth > mBarItemWidth) {
            Log.w(TAG, "There is not enough space for labels. Switch BarItemWidth to " + minWidth);
            mBarItemWidth = minWidth;
        }
    }
    mBarWidth = mBarItemWidth + mBarItemSpace;
}

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

/**
 * Match start/end values by Adapter view ID. Adds matched values to mStartValuesList
 * and mEndValuesList and removes them from unmatchedStart and unmatchedEnd, using
 * startIds and endIds as a guide for which Views have unique IDs.
 *///from ww w . j  av  a 2  s.  c  o  m
private void matchIds(ArrayMap<View, TransitionValues> unmatchedStart,
        ArrayMap<View, TransitionValues> unmatchedEnd, SparseArray<View> startIds, SparseArray<View> endIds) {
    int numStartIds = startIds.size();
    for (int i = 0; i < numStartIds; i++) {
        View startView = startIds.valueAt(i);
        if (startView != null && isValidTarget(startView)) {
            View endView = endIds.get(startIds.keyAt(i));
            if (endView != null && isValidTarget(endView)) {
                TransitionValues startValues = unmatchedStart.get(startView);
                TransitionValues endValues = unmatchedEnd.get(endView);
                if (startValues != null && endValues != null) {
                    mStartValuesList.add(startValues);
                    mEndValuesList.add(endValues);
                    unmatchedStart.remove(startView);
                    unmatchedEnd.remove(endView);
                }
            }
        }
    }
}