List of usage examples for android.util SparseArray SparseArray
public SparseArray()
From source file:com.andremion.floatingnavigationview.FloatingNavigationView.java
@Override protected Parcelable onSaveInstanceState() { Parcelable superState = super.onSaveInstanceState(); SavedState ss = new SavedState(superState); ss.navigationViewState = new SparseArray(); //noinspection unchecked mNavigationView.saveHierarchyState(ss.navigationViewState); ss.opened = isOpened();/* w w w . j a v a2 s .co m*/ return ss; }
From source file:fr.cph.chicago.task.GlobalConnectTask.java
@Override protected final Boolean doInBackground(final Void... connects) { mTrainBoolean = true;//from w w w. j a va 2 s. c o m mBusBoolean = true; mBikeBoolean = true; mNetworkAvailable = Util.isNetworkAvailable(); if (mNetworkAvailable) { CtaConnect ctaConnect = CtaConnect.getInstance(); DivvyConnect divvyConnect = DivvyConnect.getInstance(); if (mLoadTrains) { try { for (Entry<String, Object> entry : mParams.entrySet()) { String key = entry.getKey(); if (key.equals("mapid")) { Object value = entry.getValue(); if (value instanceof String) { String xmlResult = ctaConnect.connect(mRequestType, mParams); this.mTrainArrivals = mXml.parseArrivals(xmlResult, mData); } else if (value instanceof List) { @SuppressWarnings("unchecked") List<String> list = (List<String>) value; if (list.size() < 5) { String xmlResult = ctaConnect.connect(mRequestType, mParams); this.mTrainArrivals = mXml.parseArrivals(xmlResult, mData); } else { int size = list.size(); SparseArray<TrainArrival> tempArrivals = new SparseArray<TrainArrival>(); int start = 0; int end = 4; while (end < size + 1) { List<String> subList = list.subList(start, end); MultiMap<String, String> paramsTemp = new MultiValueMap<String, String>(); for (String sub : subList) { paramsTemp.put(key, sub); } String xmlResult = ctaConnect.connect(mRequestType, paramsTemp); SparseArray<TrainArrival> temp = mXml.parseArrivals(xmlResult, mData); for (int j = 0; j < temp.size(); j++) { tempArrivals.put(temp.keyAt(j), temp.valueAt(j)); } start = end; if (end + 3 >= size - 1 && end != size) { end = size; } else { end = end + 3; } } this.mTrainArrivals = tempArrivals; } } } } // Apply filters int index = 0; while (index < mTrainArrivals.size()) { TrainArrival arri = mTrainArrivals.valueAt(index++); List<Eta> etas = arri.getEtas(); // Sort Eta by arriving time Collections.sort(etas); // Copy data into new list to be able to avoid looping on a list that we want to // modify List<Eta> etas2 = new ArrayList<Eta>(); etas2.addAll(etas); int j = 0; Eta eta = null; Station station = null; TrainLine line = null; TrainDirection direction = null; for (int i = 0; i < etas2.size(); i++) { eta = etas2.get(i); station = eta.getStation(); line = eta.getRouteName(); direction = eta.getStop().getDirection(); boolean toRemove = Preferences.getTrainFilter(station.getId(), line, direction); if (!toRemove) { etas.remove(i - j++); } } } } catch (ConnectException e) { mTrainBoolean = false; this.mTrackerTrainException = e; } catch (ParserException e) { mTrainBoolean = false; this.mTrackerTrainException = e; } } if (mLoadBuses) { try { List<String> rts = new ArrayList<String>(); List<String> stpids = new ArrayList<String>(); for (Entry<String, Object> entry : mParams2.entrySet()) { String key = entry.getKey(); StringBuilder str = new StringBuilder(); int i = 0; @SuppressWarnings("unchecked") List<String> values = (ArrayList<String>) entry.getValue(); for (String v : values) { str.append(v + ","); if (i == 9 || i == values.size() - 1) { if (key.equals("rt")) { rts.add(str.toString()); } else if (key.equals("stpid")) { stpids.add(str.toString()); } str = new StringBuilder(); i = -1; } i++; } } for (int i = 0; i < rts.size(); i++) { MultiMap<String, String> para = new MultiValueMap<String, String>(); para.put("rt", rts.get(i)); para.put("stpid", stpids.get(i)); String xmlResult = ctaConnect.connect(mRequestType2, para); this.mBusArrivals.addAll(mXml.parseBusArrivals(xmlResult)); } } catch (ConnectException e) { mBusBoolean = false; this.mTrackerBusException = e; } catch (ParserException e) { mBusBoolean = false; this.mTrackerBusException = e; } } if (mLoadBikes) { try { String bikeContent = divvyConnect.connect(); this.mBikeStations = mJson.parseStations(bikeContent); Collections.sort(this.mBikeStations, Util.BIKE_COMPARATOR_NAME); } catch (ParserException e) { mBikeBoolean = false; this.mTrackerBikeException = e; } catch (ConnectException e) { mBikeBoolean = false; this.mTrackerBikeException = e; } finally { if (!(mBusBoolean && mTrainBoolean)) { if (mParams2.size() == 0 && mBusBoolean) { mBusBoolean = false; } if (mParams.size() == 0 && mTrainBoolean) { mTrainBoolean = false; } } } } return mTrainBoolean || mBusBoolean || mBikeBoolean; } else { return mNetworkAvailable; } }
From source file:com.dgsd.android.ShiftTracker.Adapter.WeekAdapter.java
@Override public Cursor swapCursor(Cursor cursor) { clearCaches();/*from w w w . j a va 2s. co m*/ if (cursor == null) return super.swapCursor(null); MatrixCursor mc = new MatrixCursor(DbTable.SHIFTS.getFieldNames(), cursor.getCount() + 7); int jd = mStartingJulianDay; final int colCount = cursor.getColumnCount(); SparseArray<List<Object[]>> jdToRowArray = new SparseArray<List<Object[]>>(); if (cursor.moveToFirst()) { final int jdIndex = cursor.getColumnIndex(DbField.JULIAN_DAY.name); do { Object[] row = new Object[colCount]; for (int i = 0; i < colCount; i++) row[i] = cursor.getString(i); final int shiftDay = cursor.getInt(jdIndex); List<Object[]> rowsOnSameJd = jdToRowArray.get(shiftDay, null); if (rowsOnSameJd == null) rowsOnSameJd = new ArrayList<Object[]>(); rowsOnSameJd.add(row); jdToRowArray.put(shiftDay, rowsOnSameJd); } while (cursor.moveToNext()); } for (int i = jd; i < jd + 7; i++) { List<Object[]> rows = jdToRowArray.get(i); if (rows != null) for (Object[] row : rows) mc.addRow(row); //Add a 'Add Shift' row Object[] row = new Object[colCount]; row[0] = mRand.nextInt(Integer.MAX_VALUE); // DbField.ID row[1] = i; // DbField.JULIAN_DAY row[2] = i; // DbField.END_JULIAN_DAY row[3] = -1; // DbField.START_TIME row[4] = -1; // DbField.END_TIME row[5] = -1; // DbField.PAY_RATE row[6] = NEW_ROW_KEY; // DbField.NAME row[7] = null; // DbField.NOTE row[8] = -1; // DbField.BREAK_DURATION row[9] = 0; // DbField.IS_TEMPLATE row[10] = -1; // DbField.REMINDER mc.addRow(row); } return super.swapCursor(mc); }
From source file:com.tmall.wireless.tangram3.structure.BaseCell.java
/** * bind a tag to baseCell// w ww. ja va2s. com * * @param key * @param value */ public void setTag(int key, Object value) { if (mTag == null) { mTag = new SparseArray<>(); } mTag.put(key, value); }
From source file:com.frostwire.android.gui.fragments.MyFilesFragment.java
public MyFilesFragment() { super(R.layout.fragment_my_files); broadcastReceiver = new LocalBroadcastReceiver(); setHasOptionsMenu(true);/*from w ww . j a va2 s . co m*/ checkedItemsMap = new SparseArray<>(); selectionModeCallback = new MyFilesActionModeCallback(); }
From source file:com.karura.framework.plugins.Capture.java
protected Capture(int pluginId, PluginManager pluginManager, KaruraWebView webView, Bundle savedInstance) { super(pluginId, pluginManager, webView, savedInstance); requestCallIdMap = new SparseArray<String>(); }
From source file:android.support.v17.leanback.widget.ViewsStateBundle.java
/** * The on screen view is saved when policy is not {@link #SAVE_NO_CHILD}. * * @param bundle Bundle where we save the on screen view state. If null, * a new Bundle is created and returned. * @param view The view to save.//from ww w . j av a 2 s . c o m * @param id Id of the view. */ public final Bundle saveOnScreenView(Bundle bundle, View view, int id) { if (mSavePolicy != SAVE_NO_CHILD) { String key = getSaveStatesKey(id); SparseArray<Parcelable> container = new SparseArray<Parcelable>(); view.saveHierarchyState(container); if (bundle == null) { bundle = new Bundle(); } bundle.putSparseParcelableArray(key, container); } return bundle; }
From source file:com.abslyon.abetterselection.CoverFlow.CoverFlowView.java
private void init() { setWillNotDraw(false);/*from w ww. j a v a 2 s.c o m*/ setClickable(true); mChildTransfromer = new Matrix(); mReflectionTransfromer = new Matrix(); mTouchRect = new RectF(); mImageRecorder = new SparseArray<int[]>(); mDrawChildPaint = new Paint(); mDrawChildPaint.setAntiAlias(true); mDrawChildPaint.setFlags(Paint.ANTI_ALIAS_FLAG); mCoverFlowPadding = new Rect(); mDrawFilter = new PaintFlagsDrawFilter(0, Paint.ANTI_ALIAS_FLAG | Paint.FILTER_BITMAP_FLAG); mScroller = new Scroller(getContext(), new AccelerateDecelerateInterpolator()); mRemoveReflectionPendingArray = new ArrayList<Integer>(); }
From source file:com.bilibili.magicasakura.utils.TintManager.java
private boolean addCachedDrawable(final int key, @NonNull final Drawable drawable) { if (drawable instanceof FilterableStateListDrawable) { return false; }/*from w w w. java2 s .c om*/ final Drawable.ConstantState cs = drawable.getConstantState(); if (cs != null) { synchronized (mDrawableCacheLock) { if (mCacheDrawables == null) { mCacheDrawables = new SparseArray<>(); } mCacheDrawables.put(key, new WeakReference<>(cs)); } return true; } return false; }
From source file:com.dolphinwang.imagecoverflow.CoverFlowView.java
private void init() { setWillNotDraw(false);/*from w w w. j a v a2s .c o m*/ setClickable(true); mChildTransfromer = new Matrix(); mReflectionTransfromer = new Matrix(); mTouchRect = new RectF(); mTouchRect2 = new ArrayList<RectF>(); for (int i = 0; i < 5; i++) { RectF a = new RectF(); mTouchRect2.add(a); } mImageRecorder = new SparseArray<int[]>(); mDrawChildPaint = new Paint(); mDrawChildPaint.setAntiAlias(true); mDrawChildPaint.setFlags(Paint.ANTI_ALIAS_FLAG); mCoverFlowPadding = new Rect(); mDrawFilter = new PaintFlagsDrawFilter(0, Paint.ANTI_ALIAS_FLAG | Paint.FILTER_BITMAP_FLAG); mScroller = new Scroller(getContext(), new AccelerateDecelerateInterpolator()); mRemoveReflectionPendingArray = new ArrayList<Integer>(); }