List of usage examples for android.util SparseArray append
public void append(int key, E value)
From source file:android.support.v7.content.res.AppCompatResources.java
private static void addColorStateListToCache(@NonNull Context context, @ColorRes int resId, @NonNull ColorStateList value) { synchronized (sColorStateCacheLock) { SparseArray<ColorStateListCacheEntry> entries = sColorStateCaches.get(context); if (entries == null) { entries = new SparseArray<>(); sColorStateCaches.put(context, entries); }//from w ww .ja v a 2s. com entries.append(resId, new ColorStateListCacheEntry(value, context.getResources().getConfiguration())); } }
From source file:edu.umich.flowfence.sandbox.ResolvedQM.java
@Override public void call(int flags, IQMCallback callback, List<CallParam> params) throws RemoteException { try {//from w ww . j a v a2s . c om if (localLOGD) { Log.d(TAG, String.format("Incoming sandbox call for %s, %d parameters:", mOriginalDescriptor, params.size())); for (CallParam param : params) { Log.d(TAG, param.toString(mContext.getClassLoader())); } } if (localLOGV) { Log.v(TAG, String.format("Callback %s, flags %d", callback, flags)); } // Sanity check. final int numParams = params.size(); if (numParams != mMemberData.countParameters()) { throw new IllegalArgumentException("Wrong number of arguments supplied"); } boolean hasReturn = (flags & CallFlags.NO_RETURN_VALUE) == 0; final ArrayList<Object> args = new ArrayList<>(); final SparseArray<IBinder> outs = new SparseArray<>(); mContext.beginQM(); try { if (hasReturn) { outs.append(CallResult.RETURN_VALUE, null); } for (int i = 0; i < numParams; i++) { CallParam param = params.get(i); int paramHeader = param.getHeader(); if (param.getType() == CallParam.TYPE_HANDLE && (paramHeader & CallParam.HANDLE_SYNC_ONLY) != 0) { Log.w(TAG, "HANDLE_SYNC_ONLY in sandbox for " + mOriginalDescriptor); continue; } // Deserialize argument, marshaling as necessary. Object arg = unpack(param); // TODO: FLAG_BY_REF args.add(arg); // Put together the out parameter for inout params. if ((paramHeader & CallParam.FLAG_RETURN) != 0) { if (localLOGV) { Log.v(TAG, String.format("Adding out param %d", i)); } outs.append(i, SandboxObject.binderForObject(this, arg)); } } // Actually do the call. Object[] argArray = args.toArray(); if (localLOGD) { Log.d(TAG, "Preparing to call " + mOriginalDescriptor.printCall(argArray)); } Object retval = mMemberData.call(argArray); if (localLOGD) { Log.d(TAG, "Call returned: " + Objects.toString(retval)); } // Bundle up handle for return value. if (hasReturn) { IBinder retvalObj = SandboxObject.binderForObject(this, retval); outs.put(CallResult.RETURN_VALUE, retvalObj); } // DEBUG: print out params if (localLOGV) { for (int i = 0; i < outs.size(); i++) { Log.v(TAG, String.format("out[%d] = %s", outs.keyAt(i), outs.valueAt(i))); } } // Post results to caller. if (localLOGD) { Log.d(TAG, "Posting results to caller"); } callback.onResult(new CallResult(outs)); } catch (InvocationTargetException ioe) { Throwable t = ioe.getTargetException(); if (t instanceof Exception) { throw ((Exception) t); } throw ioe; } finally { // Clear our ambient context. if (localLOGD) { Log.d(TAG, "Clearing call token"); } mContext.endQM(); } } catch (Exception e) { //Log.e(TAG, String.format("Error invoking %s", mOriginalDescriptor), e); callback.onResult(new CallResult(e)); } }
From source file:edu.umich.oasis.sandbox.ResolvedSoda.java
@Override public void call(int flags, ISodaCallback callback, List<CallParam> params) throws RemoteException { try {/*from w w w . j a va2 s. c om*/ if (localLOGD) { Log.d(TAG, String.format("Incoming sandbox call for %s, %d parameters:", mOriginalDescriptor, params.size())); for (CallParam param : params) { Log.d(TAG, param.toString(mContext.getClassLoader())); } } if (localLOGV) { Log.v(TAG, String.format("Callback %s, flags %d", callback, flags)); } // Sanity check. final int numParams = params.size(); if (numParams != mMemberData.countParameters()) { throw new IllegalArgumentException("Wrong number of arguments supplied"); } boolean hasReturn = (flags & CallFlags.NO_RETURN_VALUE) == 0; final ArrayList<Object> args = new ArrayList<>(); final SparseArray<IBinder> outs = new SparseArray<>(); mContext.beginSoda(); try { if (hasReturn) { outs.append(CallResult.RETURN_VALUE, null); } for (int i = 0; i < numParams; i++) { CallParam param = params.get(i); int paramHeader = param.getHeader(); if (param.getType() == CallParam.TYPE_HANDLE && (paramHeader & CallParam.HANDLE_SYNC_ONLY) != 0) { Log.w(TAG, "HANDLE_SYNC_ONLY in sandbox for " + mOriginalDescriptor); continue; } // Deserialize argument, marshaling as necessary. Object arg = unpack(param); // TODO: FLAG_BY_REF args.add(arg); // Put together the out parameter for inout params. if ((paramHeader & CallParam.FLAG_RETURN) != 0) { if (localLOGV) { Log.v(TAG, String.format("Adding out param %d", i)); } outs.append(i, SandboxObject.binderForObject(this, arg)); } } // Actually do the call. Object[] argArray = args.toArray(); if (localLOGD) { Log.d(TAG, "Preparing to call " + mOriginalDescriptor.printCall(argArray)); } Object retval = mMemberData.call(argArray); if (localLOGD) { Log.d(TAG, "Call returned: " + Objects.toString(retval)); } // Bundle up handle for return value. if (hasReturn) { IBinder retvalObj = SandboxObject.binderForObject(this, retval); outs.put(CallResult.RETURN_VALUE, retvalObj); } // DEBUG: print out params if (localLOGV) { for (int i = 0; i < outs.size(); i++) { Log.v(TAG, String.format("out[%d] = %s", outs.keyAt(i), outs.valueAt(i))); } } // Post results to caller. if (localLOGD) { Log.d(TAG, "Posting results to caller"); } callback.onResult(new CallResult(outs)); } catch (InvocationTargetException ioe) { Throwable t = ioe.getTargetException(); if (t instanceof Exception) { throw ((Exception) t); } throw ioe; } finally { // Clear our ambient context. if (localLOGD) { Log.d(TAG, "Clearing call token"); } mContext.endSoda(); } } catch (Exception e) { //Log.e(TAG, String.format("Error invoking %s", mOriginalDescriptor), e); callback.onResult(new CallResult(e)); } }
From source file:com.bmd.android.collection.SparseArrayTest.java
@Override protected void setUp() throws Exception { super.setUp(); final SparseArray<String> array = new SparseArray<String>(); for (int i = 0; i < 5; i++) { array.append(i, String.valueOf(i)); }//from w ww . j av a2 s. c o m mArray = array; }
From source file:android.support.v7.widget.AppCompatDrawableManager.java
private void addTintListToCache(@NonNull Context context, @DrawableRes int resId, @NonNull ColorStateList tintList) { if (mTintLists == null) { mTintLists = new WeakHashMap<>(); }//w ww . ja v a 2 s. c o m SparseArray<ColorStateList> themeTints = mTintLists.get(context); if (themeTints == null) { themeTints = new SparseArray<>(); mTintLists.put(context, themeTints); } themeTints.append(resId, tintList); }
From source file:com.bmd.android.collection.SparseArrayCompatTest.java
public void testEquals() { final SparseArray<String> array = new SparseArray<String>(); for (int i = 0; i < 5; i++) { array.append(i, String.valueOf(i)); }/*from ww w . ja v a 2 s . c o m*/ assertThat(AndroidCollections.iterate(mArray).isStrictlyEqualTo(AndroidCollections.iterate(array))) .isTrue(); assertThat(AndroidCollections.iterate(array).isStrictlyEqualTo(AndroidCollections.iterate(mArray))) .isTrue(); assertThat(AndroidCollections.iterate(array).only().key(2).remove() .isStrictlyEqualTo(AndroidCollections.iterate(mArray))).isFalse(); assertThat(AndroidCollections.iterate(mArray).isStrictlyEqualTo(AndroidCollections.iterate(array))) .isFalse(); final SparseArrayCompat<String> sparseArray = AndroidCollections.iterate(mArray).toSparseArray(); assertThat(AndroidCollections.iterate(mArray).isEqualTo(mArray)).isTrue(); assertThat(AndroidCollections.iterate(mArray).only().first(2).isEqualTo(mArray)).isFalse(); assertThat(AndroidCollections.iterate(mArray).isEqualTo(sparseArray)).isTrue(); assertThat(AndroidCollections.iterate(mArray).only().first(2).isEqualTo(sparseArray)).isFalse(); final ArrayList<IntSparseObjectEntry<String>> list = AndroidCollections.iterate(mArray).toImmutableList(); assertThat(AndroidCollections.iterate(mArray).isEqualTo(list)).isTrue(); assertThat(AndroidCollections.iterate(mArray).only().first(2).isEqualTo(list)).isFalse(); final ArrayList<ParcelableIntSparseObjectEntry<String>> parcelableList = AndroidCollections.iterate(mArray) .toParcelableList(); assertThat(AndroidCollections.iterate(mArray).isEqualTo(parcelableList)).isTrue(); assertThat(AndroidCollections.iterate(mArray).only().first(2).isEqualTo(parcelableList)).isFalse(); final Map<Integer, String> map = AndroidCollections.iterate(mArray).toMap(); assertThat(AndroidCollections.iterate(mArray).isEqualTo(map)).isTrue(); assertThat(AndroidCollections.iterate(mArray).only().first(2).isEqualTo(map)).isFalse(); final SortedMap<Integer, String> sortedMap = AndroidCollections.iterate(mArray).toSortedMap(); assertThat(AndroidCollections.iterate(mArray).isEqualTo(sortedMap)).isTrue(); assertThat(AndroidCollections.iterate(mArray).only().first(2).isEqualTo(sortedMap)).isFalse(); mArray.append(7, "7"); assertThat(AndroidCollections.iterate(mArray).isEqualTo(sparseArray)).isFalse(); assertThat(AndroidCollections.iterate(mArray).but().last(1).isEqualTo(sparseArray)).isTrue(); assertThat(AndroidCollections.iterate(mArray).isEqualTo(list)).isFalse(); assertThat(AndroidCollections.iterate(mArray).but().last(1).isEqualTo(list)).isTrue(); assertThat(AndroidCollections.iterate(mArray).isEqualTo(parcelableList)).isFalse(); assertThat(AndroidCollections.iterate(mArray).but().last(1).isEqualTo(parcelableList)).isTrue(); assertThat(AndroidCollections.iterate(mArray).isEqualTo(map)).isFalse(); assertThat(AndroidCollections.iterate(mArray).but().last(1).isEqualTo(map)).isTrue(); assertThat(AndroidCollections.iterate(mArray).isEqualTo(sortedMap)).isFalse(); assertThat(AndroidCollections.iterate(mArray).but().last(1).isEqualTo(sortedMap)).isTrue(); }
From source file:com.quarterfull.newsAndroid.ListView.SubscriptionExpandableListAdapter.java
public Tuple<ArrayList<AbstractItem>, SparseArray<ArrayList<ConcreteFeedItem>>> ReloadAdapter() { SharedPreferences mPrefs = PreferenceManager.getDefaultSharedPreferences(mContext); showOnlyUnread = mPrefs.getBoolean(SettingsActivity.CB_SHOWONLYUNREAD_STRING, false); ArrayList<AbstractItem> mCategoriesArrayListAsync = new ArrayList<>(); mCategoriesArrayListAsync.add(new FolderSubscribtionItem(mContext.getString(R.string.allUnreadFeeds), null, ALL_UNREAD_ITEMS.getValue())); mCategoriesArrayListAsync.add(new FolderSubscribtionItem(mContext.getString(R.string.starredFeeds), null, ALL_STARRED_ITEMS.getValue())); StopWatch sw = new StopWatch(); sw.start();//from w w w . java 2 s.c o m List<Folder> folderList; //if(showOnlyUnread) { // folderList = dbConn.getListOfFoldersWithUnreadItems(); //} else { folderList = dbConn.getListOfFolders(); //} sw.stop(); Log.v(TAG, "Time needed (fetch folder list): " + sw.toString()); for (Folder folder : folderList) { mCategoriesArrayListAsync.add(new FolderSubscribtionItem(folder.getLabel(), null, folder.getId())); } for (Feed feed : dbConn.getListOfFeedsWithoutFolders(showOnlyUnread)) { mCategoriesArrayListAsync.add(new ConcreteFeedItem(feed.getFeedTitle(), (long) ITEMS_WITHOUT_FOLDER.getValue(), feed.getId(), feed.getFaviconUrl(), feed.getId())); } SparseArray<ArrayList<ConcreteFeedItem>> mItemsArrayListAsync = new SparseArray<>(); for (int groupPosition = 0; groupPosition < mCategoriesArrayListAsync.size(); groupPosition++) { //int parent_id = (int)getGroupId(groupPosition); int parent_id = (int) mCategoriesArrayListAsync.get(groupPosition).id_database; mItemsArrayListAsync.append(parent_id, new ArrayList<ConcreteFeedItem>()); List<Feed> feedItemList = null; if (parent_id == ALL_UNREAD_ITEMS.getValue()) { feedItemList = dbConn.getAllFeedsWithUnreadRssItems(); } else if (parent_id == ALL_STARRED_ITEMS.getValue()) { feedItemList = dbConn.getAllFeedsWithStarredRssItems(); } else { for (Folder folder : folderList) {//Find the current selected folder if (folder.getId() == parent_id) {//Current item feedItemList = dbConn.getAllFeedsWithUnreadRssItemsForFolder(folder.getId()); break; } } } if (feedItemList != null) { for (Feed feed : feedItemList) { ConcreteFeedItem newItem = new ConcreteFeedItem(feed.getFeedTitle(), (long) parent_id, feed.getId(), feed.getFaviconUrl(), feed.getId()); mItemsArrayListAsync.get(parent_id).add(newItem); } } } return new Tuple<>(mCategoriesArrayListAsync, mItemsArrayListAsync); }
From source file:net.naonedbus.fragment.impl.FavorisFragment.java
@Override protected AsyncResult<ListAdapter> loadContent(final Context context, final Bundle bundle) { if (DBG)//from w w w.j a v a 2 s . com Log.d(LOG_TAG, "loadContent"); final HoraireManager horaireManager = HoraireManager.getInstance(); final AsyncResult<ListAdapter> result = new AsyncResult<ListAdapter>(); final List<Favori> favoris = mFavorisViewManager.getAll(context.getContentResolver(), mSelectedGroupes); Collections.sort(favoris, comparators.get(mCurrentSort)); int position = 0; for (final Favori favori : favoris) { if (getActivity() != null) { favori.setDelay(FavorisUtil.formatDelayLoading(getActivity(), favori.getNextHoraire())); } if (favori.getNextHoraire() == null) { final NextHoraireTask horaireTask = new NextHoraireTask(); horaireTask.setContext(context); horaireTask.setArret(favori); horaireTask.setId(position); horaireTask.setLimit(1); horaireTask.setActionCallback(ACTION_UPDATE_DELAYS); horaireManager.schedule(horaireTask); } position++; } final FavoriArrayAdapter adapter = new FavoriArrayAdapter(context, favoris); if (mGroupes.isEmpty() == false) { final SparseArray<String> groupes = new SparseArray<String>(); for (final Groupe groupe : mGroupes) { groupes.append(groupe.getId(), groupe.getNom()); } adapter.setIndexer(new FavoriArrayIndexer(groupes)); } result.setResult(adapter); return result; }
From source file:br.ufrgs.ufrgsmapas.network.LocationParser.java
public static void parseBuildings(SparseArray<BuildingVo> mTempBuilding) { // Read JSON File Connection con = HttpConnection.connect(URL); con.method(Connection.Method.POST).ignoreContentType(true); Connection.Response resp; try {/*ww w . ja v a 2 s .co m*/ resp = con.execute(); } catch (IOException e) { if (DebugUtils.DEBUG) Log.e(TAG, "Error fetching positions: " + e); return; } String jsonDoc = resp.body(); // Parse JSON to find each element JSONObject jsonStartObject = (JSONObject) JSONValue.parse(jsonDoc); // Get the array with objects representing each building JSONArray jsonBuildings = (JSONArray) jsonStartObject.get("features"); int buildingsListSize = ((List) jsonBuildings).size(); // Iterate through buildings for (int i = 0; i < buildingsListSize; i++) { // Get buildingVo object JSONObject jsonBuilding = (JSONObject) jsonBuildings.get(i); // Get buildingVo id int id = ((Number) jsonBuilding.get("id")).intValue(); // Get coordinates array JSONObject jsonGeometry = (JSONObject) jsonBuilding.get("geometry"); JSONArray jsonCoordinates = (JSONArray) ((JSONArray) ((JSONArray) jsonGeometry.get("coordinates")) .get(0)).get(0); // Get latitudes and longitudes List coordList = jsonCoordinates; int coordListSize = coordList.size(); double[] latitude = new double[coordListSize]; double[] longitude = new double[coordListSize]; for (int j = 0; j < coordListSize; j++) { latitude[j] = (double) ((List) coordList.get(j)).get(1); longitude[j] = (double) ((List) coordList.get(j)).get(0); } // Create buildingVo object and add to list - store only the center of the position double[] center = centroid(latitude, longitude); BuildingVo buildingVo = new BuildingVo(id, center[0], center[1]); mTempBuilding.append(id, buildingVo); } }
From source file:com.tzutalin.dlibtest.CameraConnectionFragment.java
/** * Sets up member variables related to camera. * * @param width The width of available size for camera preview * @param height The height of available size for camera preview *///from ww w . jav a 2 s . com @DebugLog @SuppressLint("LongLogTag") private void setUpCameraOutputs(final int width, final int height) { final Activity activity = getActivity(); final CameraManager manager = (CameraManager) activity.getSystemService(Context.CAMERA_SERVICE); try { SparseArray<Integer> cameraFaceTypeMap = new SparseArray<>(); // Check the facing types of camera devices for (final String cameraId : manager.getCameraIdList()) { final CameraCharacteristics characteristics = manager.getCameraCharacteristics(cameraId); final Integer facing = characteristics.get(CameraCharacteristics.LENS_FACING); if (facing != null && facing == CameraCharacteristics.LENS_FACING_FRONT) { if (cameraFaceTypeMap.get(CameraCharacteristics.LENS_FACING_FRONT) != null) { cameraFaceTypeMap.append(CameraCharacteristics.LENS_FACING_FRONT, cameraFaceTypeMap.get(CameraCharacteristics.LENS_FACING_FRONT) + 1); } else { cameraFaceTypeMap.append(CameraCharacteristics.LENS_FACING_FRONT, 1); } } if (facing != null && facing == CameraCharacteristics.LENS_FACING_BACK) { if (cameraFaceTypeMap.get(CameraCharacteristics.LENS_FACING_FRONT) != null) { cameraFaceTypeMap.append(CameraCharacteristics.LENS_FACING_BACK, cameraFaceTypeMap.get(CameraCharacteristics.LENS_FACING_BACK) + 1); } else { cameraFaceTypeMap.append(CameraCharacteristics.LENS_FACING_BACK, 1); } } } Integer num_facing_back_camera = cameraFaceTypeMap.get(CameraCharacteristics.LENS_FACING_BACK); for (final String cameraId : manager.getCameraIdList()) { final CameraCharacteristics characteristics = manager.getCameraCharacteristics(cameraId); final Integer facing = characteristics.get(CameraCharacteristics.LENS_FACING); // If facing back camera or facing external camera exist, we won't use facing front camera if (num_facing_back_camera != null && num_facing_back_camera > 0) { // We don't use a front facing camera in this sample if there are other camera device facing types if (facing != null && facing == CameraCharacteristics.LENS_FACING_FRONT) { continue; } } final StreamConfigurationMap map = characteristics .get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP); if (map == null) { continue; } // For still image captures, we use the largest available size. final Size largest = Collections.max(Arrays.asList(map.getOutputSizes(ImageFormat.YUV_420_888)), new CompareSizesByArea()); // Danger, W.R.! Attempting to use too large a preview size could exceed the camera // bus' bandwidth limitation, resulting in gorgeous previews but the storage of // garbage capture data. previewSize = chooseOptimalSize(map.getOutputSizes(SurfaceTexture.class), width, height, largest); // We fit the aspect ratio of TextureView to the size of preview we picked. final int orientation = getResources().getConfiguration().orientation; if (orientation == Configuration.ORIENTATION_LANDSCAPE) { textureView.setAspectRatio(previewSize.getWidth(), previewSize.getHeight()); } else { textureView.setAspectRatio(previewSize.getHeight(), previewSize.getWidth()); } CameraConnectionFragment.this.cameraId = cameraId; return; } } catch (final CameraAccessException e) { Timber.tag(TAG).e("Exception!", e); } catch (final NullPointerException e) { // Currently an NPE is thrown when the Camera2API is used but not supported on the // device this code runs. ErrorDialog.newInstance(getString(R.string.camera_error)).show(getChildFragmentManager(), FRAGMENT_DIALOG); } }