Example usage for android.util SparseArray valueAt

List of usage examples for android.util SparseArray valueAt

Introduction

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

Prototype

@SuppressWarnings("unchecked")
public E valueAt(int index) 

Source Link

Document

Given an index in the range 0...size()-1, returns the value from the indexth key-value mapping that this SparseArray stores.

Usage

From source file:com.example.bidisha.ace.ClueScan.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {

    if (requestCode == PHOTO_REQUEST && resultCode == RESULT_OK) {
        launchMediaScanIntent();//  w  ww .j a  v a 2 s  .c om
        try {
            Bitmap bitmap = decodeBitmapUri(this, imageUri);
            if (detector.isOperational() && bitmap != null) {
                Frame frame = new Frame.Builder().setBitmap(bitmap).build();
                SparseArray<Barcode> barcodes = detector.detect(frame);
                for (int index = 0; index < barcodes.size(); index++) {
                    Barcode code = barcodes.valueAt(index);
                    //scanResults.setText(/*scanResults.getText() +*/code.displayValue + "\n");

                    // TextView currQ = (TextView) findViewById(R.id.currentQ);

                    /**
                     * Comparing with the questions
                     *
                     */
                    String valueS = Integer.toString(i + 1);

                    switch (i) {
                    case 0:
                        //setting the current question value
                        currQ.setText(valueS);
                        //Log.d("mesg",rando[i]);
                        question.setText(rando[i]);

                        if (code.displayValue.compareToIgnoreCase(rando[i]) == 0) {
                            Toast.makeText(this, "Success", Toast.LENGTH_SHORT).show();
                            ((StoreGlobal) getApplication()).changeScore(5, time_left);
                            i++;

                            Intent in = new Intent(this, ClueScan.class);
                            //time left value
                            in.putExtra("time", time_left - 500);
                            //question number
                            in.putExtra("question_no", i);
                            startActivity(in);
                            ClueScan.this.finish();
                        } else {
                            Toast.makeText(this, "You are at wrong place", Toast.LENGTH_LONG).show();
                        }
                        break;
                    case 1:

                        currQ.setText(valueS);
                        // question.setText(rando[i]);
                        question.setText(rando[i]);

                        if (code.displayValue.compareToIgnoreCase(rando[i]) == 0) {
                            Toast.makeText(this, "Success", Toast.LENGTH_SHORT).show();
                            ((StoreGlobal) getApplication()).changeScore(5, time_left);
                            ++i;
                            Intent in = new Intent(this, ClueScan.class);
                            //time left value
                            in.putExtra("time", time_left - 500);
                            in.putExtra("question_no", i);

                            startActivity(in);
                            ClueScan.this.finish();
                        } else {
                            Toast.makeText(this, "You are at wrong place", Toast.LENGTH_LONG).show();
                        }
                        break;
                    case 2:
                        currQ.setText(valueS);
                        // question.setText(rando[i]);
                        question.setText(rando[i]);
                        if (code.displayValue.compareToIgnoreCase(rando[i]) == 0) {
                            Toast.makeText(this, "Success", Toast.LENGTH_SHORT).show();
                            ((StoreGlobal) getApplication()).changeScore(5, time_left);
                            ++i;
                            Intent in = new Intent(this, ClueScan.class);
                            //time left value
                            in.putExtra("time", time_left - 500);
                            //question number
                            in.putExtra("question_no", i);

                            startActivity(in);
                            ClueScan.this.finish();
                        } else {
                            Toast.makeText(this, "You are at wrong place", Toast.LENGTH_LONG).show();
                        }
                        break;
                    case 3:
                        currQ.setText(valueS);
                        // question.setText(rando[i]);
                        question.setText(rando[i]);
                        if (code.displayValue.compareToIgnoreCase(rando[i]) == 0) {
                            Toast.makeText(this, "Success", Toast.LENGTH_SHORT).show();
                            ((StoreGlobal) getApplication()).changeScore(5, time_left);
                            ++i;

                            Intent in = new Intent(this, ClueScan.class);
                            //time left value
                            in.putExtra("time", time_left - 500);
                            //question number
                            in.putExtra("question_no", i);

                            startActivity(in);
                            ClueScan.this.finish();
                        } else {
                            Toast.makeText(this, "You are at wrong place", Toast.LENGTH_LONG).show();
                        }
                        break;
                    case 4:
                        currQ.setText(valueS);
                        // question.setText(rando[i]);
                        question.setText(rando[i]);
                        if (code.displayValue.compareToIgnoreCase(rando[i]) == 0) {
                            Toast.makeText(this, "Success", Toast.LENGTH_SHORT).show();
                            ((StoreGlobal) getApplication()).changeScore(5, time_left);
                            ++i;

                            Intent in = new Intent(this, ClueScan.class);
                            //time left value
                            in.putExtra("time", time_left - 500);
                            //question number
                            in.putExtra("question_no", i);

                            startActivity(in);
                            ClueScan.this.finish();
                        } else {
                            Toast.makeText(this, "You are at wrong place", Toast.LENGTH_LONG).show();
                        }
                        break;
                    case 5:
                        //setting the current question value
                        currQ.setText(valueS);
                        //Log.d("mesg",rando[i]);
                        question.setText(rando[i]);

                        if (code.displayValue.compareToIgnoreCase(rando[i]) == 0) {
                            Toast.makeText(this, "Success", Toast.LENGTH_SHORT).show();
                            ((StoreGlobal) getApplication()).changeScore(5, time_left);
                            i++;

                            Intent in = new Intent(this, ClueScan.class);
                            //time left value
                            in.putExtra("time", time_left - 500);
                            //question number
                            in.putExtra("question_no", i);
                            startActivity(in);
                            ClueScan.this.finish();
                        } else {
                            Toast.makeText(this, "You are at wrong place", Toast.LENGTH_LONG).show();
                        }
                        break;
                    case 6:
                        //setting the current question value
                        currQ.setText(valueS);
                        //Log.d("mesg",rando[i]);
                        question.setText(rando[i]);

                        if (code.displayValue.compareToIgnoreCase(rando[i]) == 0) {
                            Toast.makeText(this, "Success", Toast.LENGTH_SHORT).show();
                            ((StoreGlobal) getApplication()).changeScore(5, time_left);
                            i++;

                            Intent in = new Intent(this, ClueScan.class);
                            //time left value
                            in.putExtra("time", time_left - 500);
                            //question number
                            in.putExtra("question_no", i);
                            startActivity(in);
                            ClueScan.this.finish();
                        } else {
                            Toast.makeText(this, "You are at wrong place", Toast.LENGTH_LONG).show();
                        }
                        break;
                    case 7:
                        //setting the current question value
                        currQ.setText(valueS);
                        //Log.d("mesg",rando[i]);
                        question.setText(rando[i]);

                        if (code.displayValue.compareToIgnoreCase(rando[i]) == 0) {
                            Toast.makeText(this, "Success", Toast.LENGTH_SHORT).show();
                            ((StoreGlobal) getApplication()).changeScore(5, time_left);
                            i++;

                            Intent in = new Intent(this, ClueScan.class);
                            //time left value
                            in.putExtra("time", time_left - 500);
                            //question number
                            in.putExtra("question_no", i);
                            startActivity(in);
                            ClueScan.this.finish();
                        } else {
                            Toast.makeText(this, "You are at wrong place", Toast.LENGTH_LONG).show();
                        }
                        break;
                    case 8:
                        //setting the current question value
                        currQ.setText(valueS);
                        //Log.d("mesg",rando[i]);
                        question.setText(rando[i]);

                        if (code.displayValue.compareToIgnoreCase(rando[i]) == 0) {
                            Toast.makeText(this, "Success", Toast.LENGTH_SHORT).show();
                            ((StoreGlobal) getApplication()).changeScore(5, time_left);
                            i++;

                            Intent in = new Intent(this, ClueScan.class);
                            //time left value
                            in.putExtra("time", time_left - 500);
                            //question number
                            in.putExtra("question_no", i);
                            startActivity(in);
                            ClueScan.this.finish();
                        } else {
                            Toast.makeText(this, "You are at wrong place", Toast.LENGTH_LONG).show();
                        }
                        break;
                    case 9:
                        //setting the current question value
                        currQ.setText(valueS);
                        //Log.d("mesg",rando[i]);
                        question.setText(rando[i]);

                        if (code.displayValue.compareToIgnoreCase(rando[i]) == 0) {
                            Toast.makeText(this, "Success", Toast.LENGTH_SHORT).show();
                            ((StoreGlobal) getApplication()).changeScore(5, time_left);
                            i++;

                            Intent i = new Intent(ClueScan.this, ScoreCal.class);
                            startActivity(i);
                            ClueScan.this.finish();

                        } else {
                            Toast.makeText(this, "You are at wrong place", Toast.LENGTH_LONG).show();
                        }
                        break;

                    }
                    //Required only if you need to extract the type of barcode
                    int type = barcodes.valueAt(index).valueFormat;
                    switch (type) {
                    case Barcode.CONTACT_INFO:
                        Log.i(LOG_TAG, code.contactInfo.title);
                        break;
                    case Barcode.EMAIL:
                        Log.i(LOG_TAG, code.email.address);
                        break;
                    case Barcode.ISBN:
                        Log.i(LOG_TAG, code.rawValue);
                        break;
                    case Barcode.PHONE:
                        Log.i(LOG_TAG, code.phone.number);
                        break;
                    case Barcode.PRODUCT:
                        Log.i(LOG_TAG, code.rawValue);
                        break;
                    case Barcode.SMS:
                        Log.i(LOG_TAG, code.sms.message);
                        break;
                    case Barcode.TEXT:
                        Log.i(LOG_TAG, code.rawValue);
                        break;
                    case Barcode.URL:
                        Log.i(LOG_TAG, "url: " + code.url.url);
                        break;
                    case Barcode.WIFI:
                        Log.i(LOG_TAG, code.wifi.ssid);
                        break;
                    case Barcode.GEO:
                        Log.i(LOG_TAG, code.geoPoint.lat + ":" + code.geoPoint.lng);
                        break;
                    case Barcode.CALENDAR_EVENT:
                        Log.i(LOG_TAG, code.calendarEvent.description);
                        break;
                    case Barcode.DRIVER_LICENSE:
                        Log.i(LOG_TAG, code.driverLicense.licenseNumber);
                        break;
                    default:
                        Log.i(LOG_TAG, code.rawValue);
                        break;
                    }
                }
                if (barcodes.size() == 0) {
                    scanResults.setText("Scan Failed: Found nothing to scan");
                }
            } else {
                scanResults.setText("Could not set up the detector!");
            }
        } catch (Exception e) {
            Toast.makeText(this, "Failed to load Image", Toast.LENGTH_SHORT).show();
            Log.e(LOG_TAG, e.toString());
        }
    }
}

From source file:com.zenithed.core.widget.scaledimageview.ScaledImageView.java

/**
 * Loads the optimum tiles for display at the current scale and translate, so the screen can be filled with tiles
 * that are at least as high resolution as the screen. Frees up bitmaps that are now off the screen.
 * @param load Whether to load the new tiles needed. Use false while scrolling/panning for performance.
 *//*from  w  w  w. ja  v  a 2  s  . c  o m*/
private void refreshRequiredTiles(boolean load) {
    final int sampleSize = Math.min(mFullImageSampleSize,
            calculateInSampleSize((int) (mScale * mContentWidth), (int) (mScale * mContentHeight)));
    final RectF vVisRect = new RectF(0, 0, getWidth(), getHeight());
    final RectF sVisRect = viewToSourceRect(vVisRect);

    // Load tiles of the correct sample size that are on screen. Discard tiles off screen, and those that are higher
    // resolution than required, or lower res than required but not the base layer, so the base layer is always present.
    final SparseArray<List<Tile>> tileMap = mTileMap;
    final int SIZE = mTileMap.size();

    List<Tile> tileList = null;

    for (int i = 0; i < SIZE; i++) {
        tileList = tileMap.valueAt(i);
        for (Tile tile : tileList) {
            if (tile.sampleSize < sampleSize
                    || (tile.sampleSize > sampleSize && tile.sampleSize != mFullImageSampleSize)) {
                tile.visible = false;
                if (tile.bitmap != null) {
                    tile.bitmap.recycle();
                    tile.bitmap = null;
                }
            }
            if (tile.sampleSize == sampleSize) {
                if (RectF.intersects(sVisRect, convertRect(tile.sRect))) {
                    tile.visible = true;
                    if (!tile.loading && tile.bitmap == null && load) {
                        BitmapTileTask task = new BitmapTileTask(this, mBitmapRegionDecoder, tile);
                        task.execute();

                        mTasks.add(task);
                    }
                } else if (tile.sampleSize != mFullImageSampleSize) {
                    tile.visible = false;
                    if (tile.bitmap != null) {
                        tile.bitmap.recycle();
                        tile.bitmap = null;
                    }
                }
            } else if (tile.sampleSize == mFullImageSampleSize) {
                tile.visible = true;
            }
        }
    }

}

From source file:com.zenithed.core.widget.scaledimageview.ScaledImageView.java

/**
 * Reset all state before setting/changing image.
 */// www. j a  va 2 s  .  c o m
private void reset(boolean resetScale) {
    setOnTouchListener(null);
    if (mBitmapRegionDecoder != null) {
        synchronized (mBitmapRegionDecoder) {
            mBitmapRegionDecoder.recycle();
        }
        mBitmapRegionDecoder = null;
    }
    if (mTileMap != null && mTileMap.size() > 0) {
        final SparseArray<List<Tile>> tileMap = mTileMap;
        final int SIZE = mTileMap.size();

        List<Tile> tileList = null;

        for (int i = 0; i < SIZE; i++) {
            tileList = tileMap.valueAt(i);
            for (Tile tile : tileList) {
                if (tile.bitmap != null) {
                    tile.bitmap.recycle();
                    tile.bitmap = null;
                }
            }
        }
    }

    // sometime we just replace the image.
    if (resetScale) {
        mScale = mDefaultScale;
    }
    mTranslate.set(0, 0);
    mContentWidth = 0;
    mContentHeight = 0;
    mFullImageSampleSize = 0;
    mTileMap = null;
    mImageReadyNotified = false;
    // by default the view must be enabled since it doesn't contain any content.
    setEnabled(false);
}

From source file:com.zenithed.core.widget.scaledimageview.ScaledImageView.java

/**
 * Draw method should not be called until the view has dimensions so the first calls are used as triggers to calculate
 * the scaling and tiling required. Once the view is setup, tiles are displayed as they are loaded.
 *//* w  ww  .j  a  v a 2s . co  m*/
@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    // If image or view dimensions are not known yet, abort.
    if (mContentWidth == 0 || mContentHeight == 0 || mBitmapRegionDecoder == null || getWidth() == 0
            || getHeight() == 0) {
        return;
    }

    // On first render with no tile map ready, initialise it and kick off async base image loading.
    if (mTileMap == null) {
        initialiseBaseLayer();
        return;
    }

    // On first display of base image set up position, and in other cases make sure scale is correct.
    fitToBounds();

    // Everything is set up and coordinates are valid. Inform subclasses.
    if (!mImageReadyNotified) {
        setEnabled(true);
        onImageReady();
        mImageReadyNotified = true;
    }

    canvas.clipRect(mViewPortRect);

    // Optimum sample size for current scale
    final int sampleSize = Math.min(mFullImageSampleSize,
            calculateInSampleSize((int) (mContentWidth * mScale), (int) (mContentHeight * mScale)));

    // First check for missing tiles - if there are any we need the base layer underneath to avoid gaps
    boolean hasMissingTiles = false;

    final SparseArray<List<Tile>> tileMap = mTileMap;
    final int SIZE = mTileMap.size();

    for (int i = 0; i < SIZE; i++) {
        if (tileMap.keyAt(i) == sampleSize) {
            final List<Tile> tileList = tileMap.valueAt(i);
            for (Tile tile : tileList) {
                if (tile.visible && (tile.loading || tile.bitmap == null)) {
                    hasMissingTiles = true;
                }
            }
        }
    }

    // Render all loaded tiles. LinkedHashMap used for bottom up rendering - lower res tiles underneath.
    for (int i = 0; i < SIZE; i++) {
        if (tileMap.keyAt(i) == sampleSize || hasMissingTiles) {
            final List<Tile> tileList = tileMap.valueAt(i);
            for (Tile tile : tileList) {
                if (!tile.loading && tile.bitmap != null) {
                    canvas.drawBitmap(tile.bitmap, null, convertRect(sourceToViewRect(tile.sRect)),
                            sDrawingPaint);
                }
            }
        }
    }

}

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

private static void setViewTags(View view, SparseArray<Object> viewTags) {
    if (viewTags == null) {
        return;//w ww .j  a v  a  2  s  .co 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  a  va2s .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 drawTickLabels(Canvas c, SparseArray<Object[]> data) {
    final int size = data.size() - 1;
    final float graphCenterX = mGraphArea.left + (mGraphArea.width() / 2);
    final float halfItemBarWidth = mBarItemWidth / 2;
    for (int i = mItemsOnScreen[1]; i >= mItemsOnScreen[0] && i <= data.size(); i--) {
        final float barCenterX = graphCenterX + mCurrentOffset - (mBarWidth * (size - i));
        float barLeft = barCenterX - halfItemBarWidth;
        float barRight = barCenterX + halfItemBarWidth;
        // Update the dynamic layout
        String label = (String) data.valueAt(i)[0];
        // /*from  w  w  w .j a v a  2  s .co  m*/
        // Calculate the x position and draw the layout
        final float x = graphCenterX + mCurrentOffset - (mBarWidth * (size - i))
                - (mLabelFgPaint.measureText(label) / 2);
        final int restoreCount = c.save();
        c.translate(x, mFooterArea.top + (mFooterArea.height() / 2 - mTickLabelMinHeight / 2));
        final Paint paint;
        // ?
        paint = barLeft < graphCenterX && barRight > graphCenterX
                && (mLastPosition == mCurrentPosition || (mState != STATE_SCROLLING)) ? mHighlightLabelFgPaint
                        : mLabelFgPaint;
        c.drawText(label, 0, 0, paint);
        c.restoreToCount(restoreCount);
    }
}

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 w  w w .ja v a 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;
    }/*from w  w w  .ja  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)[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.ruesga.timelinechart.TimelineChartView.java

private void ensureBarWidth() {
    if (!mShowFooter) {
        return;//from   w  w w  .ja va  2 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;
}