List of usage examples for android.util SparseArray size
public int size()
From source file:com.linroid.pushapp.service.ApkAutoInstallService.java
/** * ??//from w w w. j a v a2 s.c om * * @param list ? * @param appName ?? * @param becauseInstalled ?? */ private void removePackFromListByAppName(SparseArray<Pack> list, String appName, boolean becauseInstalled) { for (int i = 0; i < list.size(); i++) { int key = list.keyAt(i); Pack pack = list.get(key); if (pack.getAppName().equals(appName)) { sInstallList.remove(key); if (becauseInstalled) { showInstalledNotification(pack); } break; } } if (sInstallList.size() == 0 && sUninstallList.size() == 0) { enable = false; } }
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();/*from w w w . j av a 2s.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); //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.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]; // // w w w. j ava2s . c om // 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.tmall.wireless.tangram3.dataparser.concrete.Card.java
private void diffCells(@NonNull SparseArray<BaseCell> added, @NonNull SparseArray<BaseCell> removed) { if (!mIsActivated) return;/*from w ww. ja va 2s. c om*/ for (int i = 0, size = added.size(); i < size; i++) { int key = added.keyAt(i); BaseCell cell = added.get(key); if (cell != null) { cell.added(); } } for (int i = 0, size = removed.size(); i < size; i++) { int key = removed.keyAt(i); BaseCell cell = removed.get(key); if (cell != null) { cell.removed(); } } }
From source file:com.blestep.sportsbracelet.view.TimelineChartView.java
private int computeNearestPositionFromOffset(float offset) { final SparseArray<Object[]> data; synchronized (mLock) { data = mData;/*from w w w.ja v a2 s . c o m*/ } int size = data.size() - 1; if (size < 0) { return -1; } // So we are in an bar area, so we have a valid index final int index = size - ((int) Math.ceil((offset - (mBarItemWidth / 2) - mBarItemSpace) / mBarWidth)); return data.keyAt(index); }
From source file:com.blestep.sportsbracelet.view.TimelineChartViewSleep.java
/** * {@inheritDoc}//from ww w.jav a2 s. c o m */ @Override protected void onDraw(Canvas c) { // c.clipRect(mViewArea); mViewAreaBgShader = new LinearGradient(0, 0, 0, mViewArea.height(), ContextCompat.getColor(getContext(), R.color.tlcSleepGraphBgColorStart), ContextCompat.getColor(getContext(), R.color.tlcSleepGraphBgColorEnd), Shader.TileMode.CLAMP); mViewAreaBgPaint.setShader(mViewAreaBgShader); // c.drawRect(mViewArea, mViewAreaBgPaint); c.drawRect(mGraphArea, mGraphAreaBgPaint); c.drawRect(mFooterArea, mFooterAreaBgPaint); // c.drawLine(0, mGraphArea.height(), mGraphArea.width(), mGraphArea.height(), mGraphBottomLinePaint); final SparseArray<Object[]> data; final double maxValue; synchronized (mLock) { data = mData; maxValue = mMaxValue; } boolean hasData = data.size() > 0; if (hasData) { // ??? computeItemsOnScreen(data.size()); // drawBarItems(c, data, maxValue); // drawTickLabels(c, data); } }
From source file:com.blestep.sportsbracelet.view.TimelineChartView.java
private float computeOffsetForPosition(int position) { final SparseArray<Object[]> data; synchronized (mLock) { data = mData;/*from ww w.j a v a 2 s.co m*/ } final int index = data.indexOfKey(position); if (index >= 0) { final int size = data.size(); return (mBarWidth * (size - index - 1)); } return -1; }
From source file:com.wit.android.support.fragment.manage.BaseFragmentFactory.java
/** * Creates a new instance of BaseFragmentFactory. If {@link com.wit.android.support.fragment.annotation.FactoryFragments @FactoryFragments} * or {@link com.wit.android.support.fragment.annotation.FragmentFactories @FragmentFactories} * annotations are presented above a sub-class of this BaseFragmentFactory, they will be processed * here./*from w w w . j av a 2 s. c o m*/ */ public BaseFragmentFactory() { final Class<?> classOfFactory = ((Object) this).getClass(); /** * Process class annotations. */ final SparseArray<FragmentItem> items = new SparseArray<>(); // Obtain fragment ids. if (classOfFactory.isAnnotationPresent(FactoryFragments.class)) { final FactoryFragments fragments = classOfFactory.getAnnotation(FactoryFragments.class); final int[] ids = fragments.value(); if (ids.length > 0) { for (int id : ids) { items.put(id, new FragmentItem(id, getFragmentTag(id), null)); } } } this.processAnnotatedFragments(classOfFactory, items); if (items.size() > 0) { this.mItems = items; } // Obtain joined factories. final List<Class<? extends FragmentController.FragmentFactory>> factories = this.gatherJoinedFactories( classOfFactory, new ArrayList<Class<? extends FragmentController.FragmentFactory>>()); if (!factories.isEmpty()) { for (Class<? extends FragmentController.FragmentFactory> factory : factories) { FragmentController.FragmentFactory fragmentFactory = null; try { fragmentFactory = factory.newInstance(); } catch (InstantiationException | IllegalAccessException e) { Log.e(TAG, "Failed to instantiate the fragment factory class of(" + factory.getSimpleName() + ")." + "Make sure this fragment factory has public empty constructor.", e); } if (fragmentFactory != null) { joinFactory(fragmentFactory); } } } }
From source file:com.facebook.litho.MountState.java
private static void unsetViewTags(View view, SparseArray<Object> viewTags) { if (view instanceof ComponentHost) { final ComponentHost host = (ComponentHost) view; host.setViewTags(null);/* w w w . j a v a2 s . c o m*/ } else { if (viewTags != null) { for (int i = 0, size = viewTags.size(); i < size; i++) { view.setTag(viewTags.keyAt(i), null); } } } }
From source file:com.blestep.sportsbracelet.view.TimelineChartView.java
/** * {@inheritDoc}/*from w ww .j ava 2 s.c om*/ */ @Override protected void onDraw(Canvas c) { // c.clipRect(mViewArea); mViewAreaBgShader = new LinearGradient(0, 0, 0, mViewArea.height(), ContextCompat.getColor(getContext(), R.color.tlcStepsGraphBgColorStart), ContextCompat.getColor(getContext(), R.color.tlcStepsGraphBgColorEnd), Shader.TileMode.CLAMP); mViewAreaBgPaint.setShader(mViewAreaBgShader); // c.drawRect(mViewArea, mViewAreaBgPaint); c.drawRect(mGraphArea, mGraphAreaBgPaint); c.drawRect(mFooterArea, mFooterAreaBgPaint); // c.drawLine(0, mGraphArea.height(), mGraphArea.width(), mGraphArea.height(), mGraphBottomLinePaint); final SparseArray<Object[]> data; final double maxValue; synchronized (mLock) { data = mData; if (mIsShowTargetDashedLine && mTargetValue > mMaxValue) { maxValue = mTargetValue; } else { maxValue = mMaxValue; } } boolean hasData = data.size() > 0; if (hasData) { // ??? computeItemsOnScreen(data.size()); // drawTargetLine(c); // drawBarItems(c, data, maxValue); // drawTickLabels(c, data); } }