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.example.yeshwanthemani.billpayementapp.HomeActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == PHOTO_REQUEST && resultCode == RESULT_OK) {
        launchMediaScanIntent();//from w  w  w  .j av  a 2s . 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);
                    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: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);/*from  www.j  a v  a 2  s .c o m*/

        viewTab.setOnTabSelectedListener(tabSelectedListener);
    }
}

From source file:github.nisrulz.qreader.QREader.java

/**
 * Init.// w w w  .  j a  v a  2 s  .co m
 */
private void init() {
    if (!hasAutofocus(context)) {
        Log.e(LOGTAG, "Do not have autofocus feature, disabling autofocus feature in the library!");
        autoFocusEnabled = false;
    }

    if (!hasCameraHardware(context)) {
        Log.e(LOGTAG, "Does not have camera hardware!");
        return;
    }
    if (!checkCameraPermission(context)) {
        Log.e(LOGTAG, "Do not have camera permission!");
        return;
    }

    if (barcodeDetector.isOperational()) {
        barcodeDetector.setProcessor(new Detector.Processor<Barcode>() {
            @Override
            public void release() {
                // Handled via public method
            }

            @Override
            public void receiveDetections(Detector.Detections<Barcode> detections) {
                final SparseArray<Barcode> barcodes = detections.getDetectedItems();
                if (barcodes.size() != 0 && qrDataListener != null) {
                    //Instead of just sending the string, the complete Barcode object is sent
                    qrDataListener.onDetected(barcodes.valueAt(0));
                }
            }
        });

        cameraSource = new CameraSource.Builder(context, barcodeDetector).setAutoFocusEnabled(autoFocusEnabled)
                .setFacing(facing).setRequestedPreviewSize(width, height).build();
    } else {
        Log.e(LOGTAG, "Barcode recognition libs are not downloaded and are not operational");
    }
}

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 w  w  .  j a  va2 s .co  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.cryart.sabbathschool.ui.activity.SSMainActivity.java

@Override
public void onScrollChanged(int deltaX, int deltaY, int scrollY) {
    _SSHero.setTranslationY(scrollY * 0.5f);

    int headerHeight = _SSHero.getHeight() - _SSToolbar.getHeight() - _SSStatusBar.getHeight();
    float ratio = (float) Math.min(Math.max(scrollY * -1, 0), headerHeight) / headerHeight;

    setToolbarStatusBarAlpha((int) (ratio * 255));

    int scrollOtherFragments = scrollY * -1;
    if (_SSTabs.getTop() + scrollY < _SSToolbar.getHeight() + _SSStatusBar.getHeight()) {
        _SSTabs.setY(_SSToolbar.getHeight() + _SSStatusBar.getHeight());
        scrollOtherFragments = _SSTabs.getBottom()
                - (_SSToolbar.getHeight() + _SSStatusBar.getHeight() + _SSTabs.getHeight());
    } else {/*from   w w w . j  av a  2s  .  c  o  m*/
        _SSTabs.setTranslationY(scrollY);
    }

    SparseArray<Fragment> registeredFragments = ((SSTabsAdapter) _SSPager.getAdapter()).registeredFragments;
    for (int i = 0; i < registeredFragments.size(); i++) {
        if (i == _SSPager.getCurrentItem())
            continue;
        ((SSWebViewFragment) (registeredFragments.get(i)))._SSWebView._SSOnScrollChangedCallbackEnabled = false;
        ((SSWebViewFragment) (registeredFragments.get(i)))._SSWebView.scrollTo(0, scrollOtherFragments);
        ((SSWebViewFragment) (registeredFragments.get(i)))._SSWebView._SSOnScrollChangedCallbackEnabled = true;
    }
}

From source file:com.oxilo.barcode.BarcodeCaptureActivity.java

/**
 * Creates and starts the camera.  Note that this uses a higher resolution in comparison
 * to other detection examples to enable the barcode detector to detect small barcodes
 * at long distances./*from   ww w .  j  ava  2 s  . c  om*/
 *
 * Suppressing InlinedApi since there is a check that the minimum version is met before using
 * the constant.
 */
@SuppressLint("InlinedApi")
private void createCameraSource(boolean autoFocus, boolean useFlash) {
    Context context = getApplicationContext();

    // A barcode detector is created to track barcodes.  An associated multi-processor instance
    // is set to receive the barcode detection results, track the barcodes, and maintain
    // graphics for each barcode on screen.  The factory is used by the multi-processor to
    // create a separate tracker instance for each barcode.
    BarcodeDetector barcodeDetector = new BarcodeDetector.Builder(context).build();
    BarcodeTrackerFactory barcodeFactory = new BarcodeTrackerFactory(mGraphicOverlay);
    //        barcodeDetector.setProcessor(
    //                new MultiProcessor.Builder<>(barcodeFactory).build());

    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) {
                if (barcodes != null) {
                    Log.e("BASDAA", "" + barcodes.valueAt(0).displayValue);
                    Intent data = new Intent();
                    data.putExtra(BarcodeObject, barcodes.valueAt(0));
                    setResult(CommonStatusCodes.SUCCESS, data);
                    finish();
                } else {
                    Log.d(TAG, "barcode data is null");
                }
            }
        }
    });

    if (!barcodeDetector.isOperational()) {
        // Note: The first time that an app using the barcode or face API is installed on a
        // device, GMS will download a native libraries to the device in order to do detection.
        // Usually this completes before the app is run for the first time.  But if that
        // download has not yet completed, then the above call will not detect any barcodes
        // and/or faces.
        //
        // isOperational() can be used to check if the required native libraries are currently
        // available.  The detectors will automatically become operational once the library
        // downloads complete on device.
        Log.w(TAG, "Detector dependencies are not yet available.");

        // Check for low storage.  If there is low storage, the native library will not be
        // downloaded, so detection will not become operational.
        IntentFilter lowstorageFilter = new IntentFilter(Intent.ACTION_DEVICE_STORAGE_LOW);
        boolean hasLowStorage = registerReceiver(null, lowstorageFilter) != null;

        if (hasLowStorage) {
            Toast.makeText(this, R.string.low_storage_error, Toast.LENGTH_LONG).show();
            Log.w(TAG, getString(R.string.low_storage_error));
        }
    }

    // Creates and starts the camera.  Note that this uses a higher resolution in comparison
    // to other detection examples to enable the barcode detector to detect small barcodes
    // at long distances.
    CameraSource.Builder builder = new CameraSource.Builder(getApplicationContext(), barcodeDetector)
            .setFacing(CameraSource.CAMERA_FACING_BACK).setRequestedPreviewSize(640, 480)
            .setRequestedFps(15.0f);

    // make sure that auto focus is an available option
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        builder = builder.setFocusMode(autoFocus ? Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE : null);
    }

    mCameraSource = builder.setFlashMode(useFlash ? Camera.Parameters.FLASH_MODE_TORCH : null).build();
}

From source file:com.sonymobile.androidapp.gridcomputing.fragments.ReportChartFragment.java

private LineData getData() {
    ArrayList<ILineDataSet> dataSets = new ArrayList<>();
    final SparseArray<Pair<Date, Double>> sparseArray = JobCheckpointsContract.getHourlyReport(mDataType);

    if (mDataType == DataType.WEEK) {
        final SparseArray<SparseArray<Double>> weeksDays = groupValues(sparseArray, 0, Calendar.DAY_OF_WEEK);
        if (weeksDays.size() > 0) {
            final Calendar calendar = Calendar.getInstance();
            calendar.add(Calendar.DATE, 1);
            final int startValue = calendar.get(Calendar.DAY_OF_WEEK);
            dataSets.add(getData(0, "", weeksDays.get(weeksDays.keyAt(0)), startValue));
        }// ww  w.j a v  a 2  s . c om
    } else if (mDataType == DataType.MONTH) {
        final SparseArray<SparseArray<Double>> weeksInMonth = groupValues(sparseArray, Calendar.WEEK_OF_YEAR,
                Calendar.DAY_OF_WEEK);
        for (int i = 0; i < weeksInMonth.size(); i++) {
            final String label = getString(R.string.chart_week_label, i + 1);
            dataSets.add(getData(i, label, weeksInMonth.get(weeksInMonth.keyAt(i)), 0));
        }
    } else if (mDataType == DataType.ALL_TIME) {
        final SparseArray<SparseArray<Double>> years = groupValues(sparseArray, Calendar.YEAR, Calendar.YEAR);
        if (years.size() > 0) {
            dataSets.add(getData(0, "", years.get(years.keyAt(0)), 0));
        }
    }

    return new LineData(dataSets);
}

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

/**
 * Destroys the loader with the specified ID.
 *
 * @param context  the context./*  www.j a  v  a2  s  .  com*/
 * @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);
    }
}

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

/**
 * Destroys the loader with the specified ID and the specified inputs.
 *
 * @param context  the context./*  ww w  .java2  s.c  o m*/
 * @param loaderId the loader ID.
 * @param inputs   the invocation inputs.
 */
@SuppressWarnings("unchecked")
static void purgeLoader(@Nonnull final Object context, final int loaderId, @Nonnull final List<?> inputs) {

    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<Object, Object> loader = (RoutineLoader<Object, Object>) callbacks.mLoader;

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

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

        ++i;
    }

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

        sCallbackMap.remove(context);
    }
}

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

/**
 * Destroys all loaders with the specified invocation class.
 *
 * @param context         the context.//from   www .  j  av  a2s  .c om
 * @param loaderId        the loader ID.
 * @param invocationClass the invocation class.
 * @param invocationArgs  the invocation constructor arguments.
 */
static void purgeLoaders(@Nonnull final Object context, final int loaderId,
        @Nonnull final Class<?> invocationClass, @Nonnull final Object[] invocationArgs) {

    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 ((loader.getInvocationType() == invocationClass)
                && Arrays.equals(loader.getInvocationArgs(), invocationArgs)
                && (loader.getInvocationCount() == 0)) {

            final int id = callbackArray.keyAt(i);

            if ((loaderId == ContextRoutineBuilder.AUTO) || (loaderId == id)) {

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

        ++i;
    }

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

        sCallbackMap.remove(context);
    }
}