List of usage examples for android.util SparseArray keyAt
public int keyAt(int index)
0...size()-1
, returns the key from the index
th key-value mapping that this SparseArray stores. From source file:com.sonymobile.androidapp.gridcomputing.fragments.ReportChartFragment.java
/** * Groups the original values into a sparse array. * The outer sparse array is indexed by the group field. * The inner sparse array is indexed by the index field. * If groupField and indexField are the same, then the outer sparse array contains only 1 entry * index by 0 and the inner sparse array is indexed by indexField. * @param original the original value returned from the SQL query. * @param groupField the field used to group the outer sparse array. * @param indexField the field used to group the inner sparse array. * @return a bidimensional sparse array indexed by groupField and indexField. *//*from ww w. j a va2 s.c o m*/ private SparseArray<SparseArray<Double>> groupValues(final SparseArray<Pair<Date, Double>> original, final int groupField, final int indexField) { final Calendar calendar = Calendar.getInstance(); final SparseArray<SparseArray<Double>> weeks = new SparseArray<>(); for (int i = 0; i < original.size(); i++) { try { final int key = original.keyAt(i); calendar.setTime(original.get(key).first); final double value = original.get(key).second; final int indexValue = calendar.get(indexField); final int groupValue = groupField == indexField ? 0 : calendar.get(groupField); SparseArray<Double> currentWeek = weeks.get(groupValue); if (currentWeek == null) { currentWeek = new SparseArray<>(); weeks.put(groupValue, currentWeek); } currentWeek.put(indexValue, value); } catch (Exception e) { Log.e(e.getMessage()); } } // normalize the data // if the index field is DAY_OF_WEEK, then we'll add the remaining days to fill // the week from sunday until saturday if (indexField == Calendar.DAY_OF_WEEK) { for (int i = 0; i < weeks.size(); i++) { final int key = weeks.keyAt(i); SparseArray<Double> currentWeek = weeks.get(key); for (int j = Calendar.SUNDAY; j <= Calendar.SATURDAY; j++) { if (currentWeek.get(j) == null) { currentWeek.put(j, 0.0); } } } } return weeks; }
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)); }/* w ww . j a v a2s.c o m*/ } 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:org.indywidualni.centrumfm.util.ChangeLog.java
/** * Returns the merged change log.//from ww w . j av a 2 s . c om * * @param full If this is {@code true} the full change log is returned. Otherwise only changes for * versions newer than the last version are returned. * @return A sorted {@code List} containing {@link ReleaseItem}s representing the (partial) * change log. * @see #getChangeLogComparator() */ public List<ReleaseItem> getChangeLog(boolean full) { SparseArray<ReleaseItem> masterChangelog = getMasterChangeLog(full); SparseArray<ReleaseItem> changelog = getLocalizedChangeLog(full); List<ReleaseItem> mergedChangeLog = new ArrayList<>(masterChangelog.size()); for (int i = 0, len = masterChangelog.size(); i < len; i++) { int key = masterChangelog.keyAt(i); // Use release information from localized change log and fall back to the master file // if necessary. ReleaseItem release = changelog.get(key, masterChangelog.get(key)); mergedChangeLog.add(release); } Collections.sort(mergedChangeLog, getChangeLogComparator()); return mergedChangeLog; }
From source file:com.linroid.pushapp.service.ApkAutoInstallService.java
/** * ??//from w w w. j a v a 2 s.com * * @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.linroid.pushapp.service.ApkAutoInstallService.java
/** * ?AccessibilityNodeInfo// www .j a v a2 s. c o m * * @param event * @param validPackageList * @return */ private AccessibilityNodeInfo getValidAccessibilityNodeInfo(AccessibilityEvent event, SparseArray<Pack> validPackageList) { if (validPackageList != null && validPackageList.size() > 0) { for (int i = 0; i < validPackageList.size(); i++) { int key = validPackageList.keyAt(i); Pack pack = validPackageList.get(key); AccessibilityNodeInfo nodeInfo = getAccessibilityNodeInfoByText(event, pack.getAppName()); if (nodeInfo != null) { return nodeInfo; } } } return null; }
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;/*w w w .j a va 2 s .co m*/ 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.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. *///from w w w. j a va2 s. c o 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.blestep.sportsbracelet.view.TimelineChartView.java
private int computeNearestPositionFromOffset(float offset) { final SparseArray<Object[]> data; synchronized (mLock) { data = mData;/*from w w w.j av a 2s . 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.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);/*from ww w. jav a2s .com*/ } else { if (viewTags != null) { for (int i = 0, size = viewTags.size(); i < size; i++) { view.setTag(viewTags.keyAt(i), null); } } } }
From source file:com.facebook.litho.MountState.java
private static void setViewTags(View view, SparseArray<Object> viewTags) { if (viewTags == null) { return;/* w ww.jav a 2 s . c o 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)); } } }