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:br.ufrgs.ufrgsmapas.network.ExtraInfoParser.java

public static void fillBuildings(SparseArray<BuildingVo> mTempBuilding) {

    if (mTempBuilding == null || mTempBuilding.size() == 0) {
        if (DebugUtils.DEBUG)
            Log.e(TAG, "No list to fillBuildings() populate");
        return;//from   ww  w  . j a  v  a 2  s  .  c  om
    }

    BuildingVo buildingVo;
    for (int i = 0; i < mTempBuilding.size(); i++) {
        buildingVo = mTempBuilding.valueAt(i);
        fillBuildingInformation(buildingVo);
    }
}

From source file:com.appsimobile.appsii.AbstractSidebarPagerAdapter.java

static <T> int keyOf(SparseArray<T> array, T object) {
    int length = array.size();
    for (int i = 0; i < length; i++) {
        T value = array.valueAt(i);
        if (value == object)
            return array.keyAt(i);
    }//from   w  w w . j a  v  a2  s  .co  m
    return -1;
}

From source file:Main.java

/**
 * Check whether two {@link SparseArray} equal.
 *//*from  w w w.j a v a  2s . c  o m*/
static boolean equals(SparseArray<byte[]> array, SparseArray<byte[]> otherArray) {
    if (array == otherArray) {
        return true;
    }
    if (array == null || otherArray == null) {
        return false;
    }
    if (array.size() != otherArray.size()) {
        return false;
    }

    // Keys are guaranteed in ascending order when indices are in ascending order.
    for (int i = 0; i < array.size(); ++i) {
        if (array.keyAt(i) != otherArray.keyAt(i) || !Arrays.equals(array.valueAt(i), otherArray.valueAt(i))) {
            return false;
        }
    }
    return true;
}

From source file:Main.java

/**
 * Check whether two {@link SparseArray} equal.
 *//*from   w  w  w . j av  a 2  s .co  m*/
public static boolean equals(SparseArray<byte[]> array, SparseArray<byte[]> otherArray) {
    if (array == otherArray) {
        return true;
    }
    if (array == null || otherArray == null) {
        return false;
    }
    if (array.size() != otherArray.size()) {
        return false;
    }

    // Keys are guaranteed in ascending order when indices are in ascending order.
    for (int i = 0; i < array.size(); ++i) {
        if (array.keyAt(i) != otherArray.keyAt(i) || !Arrays.equals(array.valueAt(i), otherArray.valueAt(i))) {
            return false;
        }
    }
    return true;
}

From source file:com.ruesga.rview.misc.NotificationsHelper.java

@SuppressWarnings("Convert2streamapi")
public static void recreateNotifications(Context ctx) {
    List<NotificationEntity> entities = NotificationEntity.getAllNotifications(ctx, true, true);
    SparseArray<Account> notifications = new SparseArray<>();
    for (NotificationEntity entity : entities) {
        if (notifications.indexOfKey(entity.mGroupId) < 0) {
            notifications.put(entity.mGroupId, ModelHelper.getAccountFromHash(ctx, entity.mAccountId));
        }/*from   w  w  w.ja  va 2 s . c om*/
    }

    int count = notifications.size();
    for (int i = 0; i < count; i++) {
        int groupId = notifications.keyAt(i);
        Account account = notifications.valueAt(i);
        dismissNotification(ctx, groupId);
        createNotification(ctx, account, groupId, false);
    }
}

From source file:com.guanqing.hao.OcrDetectorProcessor.java

/**
 * Called by the detector to deliver detection results.
 * If your application called for it, this could be a place to check for
 * equivalent detections by tracking TextBlocks that are similar in location and content from
 * previous frames, or reduce noise by eliminating TextBlocks that have not persisted through
 * multiple detections./*w  w  w .  j  a v  a  2 s  .c o  m*/
 */
@Override
public void receiveDetections(Detector.Detections<TextBlock> detections) {
    // TODO
    mGraphicOverlay.clear();
    SparseArray<TextBlock> items = detections.getDetectedItems();
    for (int i = 0; i < items.size(); ++i) {
        TextBlock item = items.valueAt(i);
        final String key = item.getValue().trim().toLowerCase();
        final boolean success = mDict.get().containsKey(key);
        if (success) {
            final String translation = mDict.get().get(key);
            final OcrGraphic graphic = new OcrGraphic(mGraphicOverlay, item, success, translation);
            mGraphicOverlay.add(graphic);
        }
    }
}

From source file:com.marpies.ane.facedetection.functions.DetectFacesFunction.java

private JSONArray getFacesJSONArray(SparseArray<Face> faces) {
    int numFaces = faces.size();
    JSONArray facesResult = new JSONArray();
    for (int i = 0; i < numFaces; i++) {
        Face face = faces.valueAt(i);
        String faceJSON = getFaceJSON(face);
        if (faceJSON != null) {
            facesResult.put(faceJSON);/*from  w w w  .  ja  v a2 s.  com*/
        } else {
            AIR.log("Error making JSON out of Face object");
        }
    }
    AIR.log("Parsed " + facesResult.length() + " faces");
    return facesResult;
}

From source file:com.dvn.vindecoder.ui.OCR.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == PHOTO_REQUEST && resultCode == RESULT_OK) {
        launchMediaScanIntent();//from   w  ww .ja va2s  .c  o m
        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");

                    //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.grepsound.fragments.MyProfileFragment.java

@Override
public void onPageSelected(int position) {
    SparseArray<ScrollTabHolder> scrollTabHolders = mPagerAdapter.getScrollTabHolders();
    ScrollTabHolder currentHolder = scrollTabHolders.valueAt(position);

    if (mHeader != null)
        currentHolder.adjustScroll((int) (mHeader.getHeight() + mHeader.getTranslationY()));
}

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

public void onResume() {
    super.onResume();
    ArrayList<Server> servers = new ArrayList<Server>();
    SparseArray<Server> s = ServersList.getInstance().getServers();
    for (int i = 0; i < s.size(); i++) {
        servers.add(s.valueAt(i));
    }/*from w  w w. j  a  v  a 2s . c o  m*/
    Collections.sort(servers);
    refresh(servers);
}