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.app.ecofriend.ecofriend.DisplayMessageActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == PHOTO_REQUEST && resultCode == RESULT_OK) {
        launchMediaScanIntent();//from  w w  w  . java 2  s.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() + "20 bottles recycled by " + code.displayValue + "\n");
                    TextView textView = (TextView) findViewById(R.id.textView3);
                    textView.setText("");
                    //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.example.lenny.barcodevison.ScanBarcodeActivity.java

private void createCameraSource() {
    BarcodeDetector barcodeDetector = new BarcodeDetector.Builder(this)
            .setBarcodeFormats(UPC_A | UPC_E | EAN_13).build();

    cameraSource = new CameraSource.Builder(this, barcodeDetector).setAutoFocusEnabled(true)
            .setRequestedPreviewSize(1600, 1024).setFacing(CameraSource.CAMERA_FACING_BACK).build();

    cameraPreview.getHolder().addCallback(new SurfaceHolder.Callback() {

        @Override// www.ja  v a  2s  .  c  o  m
        public void surfaceCreated(SurfaceHolder holder) {

            try {
                if (ActivityCompat.checkSelfPermission(ScanBarcodeActivity.this,
                        Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
                    ActivityCompat.requestPermissions(ScanBarcodeActivity.this,
                            new String[] { Manifest.permission.CAMERA }, 1);
                    return;
                }
                cameraSource.start(cameraPreview.getHolder());
            } catch (IOException e) {

            }

        }

        @Override
        public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {

        }

        @Override
        public void surfaceDestroyed(SurfaceHolder holder) {
            cameraSource.stop();
        }
    });

    barcodeDetector.setProcessor(new Detector.Processor<Barcode>() {

        @Override
        public void release() {

        }

        @Override
        public void receiveDetections(Detector.Detections<Barcode> detections) {
            final SparseArray<Barcode> barcodes = detections.getDetectedItems();
            if (barcodes.size() > 0) {
                Intent intent = new Intent();
                intent.putExtra("barcode", barcodes.valueAt(0));
                setResult(CommonStatusCodes.SUCCESS, intent);
                finish();

            }
        }
    });
}

From source file:com.bilibili.lib.pageradapter.IDFragmentStatePagerAdapter.java

@Override
@CallSuper//from   w ww . j ava2s . co m
public void restoreState(Parcelable state, ClassLoader loader) {
    if (state != null) {
        Bundle bundle = (Bundle) state;
        bundle.setClassLoader(loader);
        mSavedState.clear();
        mFragments.clear();
        SparseArray<Fragment.SavedState> fss = bundle.getSparseParcelableArray(KEY_SAVED_STATES);
        if (fss != null) {
            for (int i = 0; i < fss.size(); i++) {
                mSavedState.put(fss.keyAt(i), fss.valueAt(i));
            }
        }
        Iterable<String> keys = bundle.keySet();
        for (String key : keys) {
            if (key.startsWith(KEY_PREFIX)) {
                Fragment f = mFragmentManager.getFragment(bundle, key);
                int id;
                try {
                    id = Integer.parseInt(key.substring(KEY_PREFIX.length()));
                } catch (NumberFormatException e) {
                    // should not happen!
                    throw new IllegalStateException("Can't find id at key " + key);
                }
                if (f != null) {
                    f.setMenuVisibility(false);
                    mFragments.put(id, f);
                } else {
                    Log.w(TAG, "Bad fragment at key " + key);
                }
            }
        }
    }
}

From source file:love.juhe.androidmonkey.MonkeyTouchEvent.java

@Override
public JSONObject getEventInfo() {
    JSONObject json = new JSONObject();
    try {//from  w  w  w  .  j  a va  2 s.com
        json.put("event_type", "event_touch");

        JSONObject params = new JSONObject();
        params.put("e_act", event.getAction());
        params.put("e_donw_time", event.getDownTime());
        params.put("e_event_time", event.getEventTime());
        params.put("e_pointer_count", event.getPointerCount());
        params.put("e_meta_state", event.getMetaState());
        params.put("e_x_precision", event.getXPrecision());
        params.put("e_y_precision", event.getYPrecision());
        params.put("e_device_id", event.getDeviceId());
        params.put("e_edge_flag", event.getEdgeFlags());
        params.put("e_source", event.getSource());
        params.put("e_flag", event.getFlags());

        SparseArray<MotionEvent.PointerCoords> pArray = getPointers();

        JSONArray pointers = new JSONArray();

        final int pointerCount = pArray.size();
        for (int i = 0; i < pointerCount; i++) {
            JSONObject point = new JSONObject();
            point.put("p_id", pArray.keyAt(i));
            point.put("p_x", pArray.valueAt(i).x);
            point.put("p_y", pArray.valueAt(i).y);
            point.put("p_pressure", pArray.valueAt(i).pressure);
            point.put("p_size", pArray.valueAt(i).size);
            pointers.put(i, point);
        }

        params.put("e_pointers", pointers);
        json.put("event_params", params);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return json;
}

From source file:love.juhe.androidmonkey.MonkeyTrackballEvent.java

@Override
public JSONObject getEventInfo() {
    JSONObject json = new JSONObject();
    try {// w  ww .j ava  2s  .  c  o  m
        json.put("event_type", "event_trackball");

        JSONObject params = new JSONObject();
        params.put("e_act", event.getAction());
        params.put("e_donw_time", event.getDownTime());
        params.put("e_event_time", event.getEventTime());
        params.put("e_pointer_count", event.getPointerCount());
        params.put("e_meta_state", event.getMetaState());
        params.put("e_x_precision", event.getXPrecision());
        params.put("e_y_precision", event.getYPrecision());
        params.put("e_device_id", event.getDeviceId());
        params.put("e_edge_flag", event.getEdgeFlags());
        params.put("e_source", event.getSource());
        params.put("e_flag", event.getFlags());

        SparseArray<MotionEvent.PointerCoords> pArray = getPointers();

        JSONArray pointers = new JSONArray();

        final int pointerCount = pArray.size();
        for (int i = 0; i < pointerCount; i++) {
            JSONObject point = new JSONObject();
            point.put("p_id", pArray.keyAt(i));
            point.put("p_x", pArray.valueAt(i).x);
            point.put("p_y", pArray.valueAt(i).y);
            point.put("p_pressure", pArray.valueAt(i).pressure);
            point.put("p_size", pArray.valueAt(i).size);
            pointers.put(i, point);
        }

        params.put("e_pointers", pointers);
        json.put("event_params", params);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return json;
}

From source file:com.example.carrie.carrie_test1.scandrug.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_scandrug);
    cameraView = (SurfaceView) findViewById(R.id.cameraView);
    cameraView.setZOrderMediaOverlay(true);
    holder = cameraView.getHolder();/*from ww w  . j a  v a2  s .  c  o m*/
    barcode = new BarcodeDetector.Builder(this).setBarcodeFormats(Barcode.QR_CODE).build();
    if (!barcode.isOperational()) {
        Toast.makeText(getApplicationContext(), "Sorry ,Couldn't set up the detector", Toast.LENGTH_LONG)
                .show();
        this.finish();
    }

    cameraSource = new CameraSource.Builder(this, barcode).setFacing(CameraSource.CAMERA_FACING_BACK)
            .setRequestedFps(24).setAutoFocusEnabled(true).setRequestedPreviewSize(1920, 1024).build();
    cameraView.getHolder().addCallback(new SurfaceHolder.Callback() {
        @Override
        public void surfaceCreated(SurfaceHolder holder) {
            try {
                if (ContextCompat.checkSelfPermission(scandrug.this,
                        android.Manifest.permission.CAMERA) == PackageManager.PERMISSION_GRANTED) {
                    cameraSource.start(cameraView.getHolder());
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        @Override
        public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {

        }

        @Override
        public void surfaceDestroyed(SurfaceHolder holder) {

        }
    });
    barcode.setProcessor(new Detector.Processor<Barcode>() {
        @Override
        public void release() {

        }

        @Override
        public void receiveDetections(Detector.Detections<Barcode> detections) {
            final SparseArray<Barcode> barcodes = detections.getDetectedItems();
            if (barcodes.size() > 0) {
                int count;
                Intent intent = new Intent();
                intent.putExtra("barcode", barcodes.valueAt(0));
                Log.d("code", barcodes.valueAt(0).displayValue);
                urlcode = barcodes.valueAt(0).displayValue;
                Log.d("code2", barcodes.valueAt(0).displayValue);
                geturl();
                setResult(RESULT_OK, intent);
                //                    cameraSource.stop();
                //                    addNormalDialogEvent();

            }
        }
    });

}

From source file:it.unicaradio.android.activities.MainActivity.java

private void setupListeners(SparseArray<Tab> tabs) {
    for (int i = 0; i < tabs.size(); i++) {
        Tab viewTab = tabs.valueAt(i);

        viewTab.setOnTabSelectedListener(tabSelectedListener);
    }/*  w  w w .ja v a2  s.  c o  m*/
}

From source file:com.example.yeshwanthemani.billpayementapp.HomeActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == PHOTO_REQUEST && resultCode == RESULT_OK) {
        launchMediaScanIntent();/*  www . ja  va 2 s.  co  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);
                    scanresult = scanResults.getText() + code.displayValue;
                    //   scanResults.setText(scanResults.getText() + code.displayValue + "\n");

                    Intent i = new Intent(this, PayActivity.class);
                    startActivity(i);

                    //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.jcedar.tixee.activity.ScanTicketActivity.java

private void scanAndReturn(Context context, Uri uri, TextView scanResultss, ImageView scanTicket) {
    Bitmap bitmap = null;/*from   w  ww  . j  a v  a2  s. c  o m*/
    try {
        bitmap = decodeBitmapUri(context, uri);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
    if (detector.isOperational() && bitmap != null) {
        scanTicket.setImageURI(uri);
        scanTicket.setVisibility(View.VISIBLE);
        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);
            cdScanResult.setVisibility(View.VISIBLE);
            //                scanResultss.setText(scanResultss.getText() + code.displayValue + "\n");
            //                scanResultString = scanResultss.getText() + code.displayValue;
            scanResultString = code.rawValue;
            scanResultss.setText(scanResultString);
            //                Log.e(TAG, " scanned Barcode String " + rr);

            //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(TAG, code.contactInfo.title);
                break;
            case Barcode.EMAIL:
                Log.i(TAG, code.email.address);
                break;
            case Barcode.ISBN:
                Log.i(TAG, code.rawValue);
                break;
            case Barcode.PHONE:
                Log.i(TAG, code.phone.number);
                break;
            case Barcode.PRODUCT:
                Log.i(TAG, code.rawValue);
                break;
            case Barcode.SMS:
                Log.i(TAG, code.sms.message);
                break;
            case Barcode.TEXT:
                Log.i(TAG, code.rawValue);
                break;
            case Barcode.URL:
                Log.i(TAG, "url: " + code.url.url);
                break;
            case Barcode.WIFI:
                Log.i(TAG, code.wifi.ssid);
                break;
            case Barcode.GEO:
                Log.i(TAG, code.geoPoint.lat + ":" + code.geoPoint.lng);
                break;
            case Barcode.CALENDAR_EVENT:
                Log.i(TAG, code.calendarEvent.description);
                break;
            case Barcode.DRIVER_LICENSE:
                Log.i(TAG, code.driverLicense.licenseNumber);
                break;
            default:
                Log.i(TAG, code.rawValue);
                break;
            }
        }
        if (barcodes.size() == 0) {
            scanResultss.setText("Scan Failed: Found nothing to scan");
        }
    } else {
        scanResultss.setText("Could not set up the detector!");
    }
}

From source file:com.gh.bmd.jrt.android.v4.core.LoaderInvocation.java

/**
 * Destroys the loader with the specified ID.
 *
 * @param context  the context./* ww w.  ja  v  a 2s.c  om*/
 * @param loaderId the loader ID.
 */
static void purgeLoader(@Nonnull final Object context, final int loaderId) {

    final SparseArray<WeakReference<RoutineLoaderCallbacks<?>>> callbackArray = sCallbackMap.get(context);

    if (callbackArray == null) {

        return;
    }

    final LoaderManager loaderManager;

    if (context instanceof FragmentActivity) {

        final FragmentActivity activity = (FragmentActivity) context;
        loaderManager = activity.getSupportLoaderManager();

    } else if (context instanceof Fragment) {

        final Fragment fragment = (Fragment) context;
        loaderManager = fragment.getLoaderManager();

    } else {

        throw new IllegalArgumentException("invalid context type: " + context.getClass().getCanonicalName());
    }

    int i = 0;

    while (i < callbackArray.size()) {

        final RoutineLoaderCallbacks<?> callbacks = callbackArray.valueAt(i).get();

        if (callbacks == null) {

            callbackArray.remove(callbackArray.keyAt(i));
            continue;
        }

        final RoutineLoader<?, ?> loader = callbacks.mLoader;

        if ((loaderId == callbackArray.keyAt(i)) && (loader.getInvocationCount() == 0)) {

            loaderManager.destroyLoader(loaderId);
            callbackArray.remove(loaderId);
            continue;
        }

        ++i;
    }

    if (callbackArray.size() == 0) {

        sCallbackMap.remove(context);
    }
}