List of usage examples for android.support.v4.util SparseArrayCompat get
public E get(int i)
From source file:com.facebook.litho.ComponentHostUtils.java
/** * Returns true if scrapItems is not null and contains an item with key index. *//*from www. j a v a 2s. c om*/ static <T> boolean existsScrapItemAt(int index, SparseArrayCompat<T> scrapItems) { return scrapItems != null && scrapItems.get(index) != null; }
From source file:Main.java
public static <T extends View> T get(View view, int id) { SparseArrayCompat<View> viewHolder = (SparseArrayCompat<View>) view.getTag(); if (viewHolder == null) { viewHolder = new SparseArrayCompat<>(); view.setTag(viewHolder);/*from www .j a v a2s .c om*/ } View childView = viewHolder.get(id); if (childView == null) { childView = view.findViewById(id); viewHolder.put(id, childView); } return (T) childView; }
From source file:com.facebook.litho.ComponentHostUtils.java
/** * Takes the item at position index from items and puts it into scrapItems. If no such item exists * the invocation of this method will have no effect. *///from ww w .j ava 2s . co m static <T> void scrapItemAt(int index, SparseArrayCompat<T> items, SparseArrayCompat<T> scrapItems) { final T value = items.get(index); if (value != null) { scrapItems.put(index, value); } }
From source file:com.brotherpowers.cameraview.AspectRatio.java
/** * Returns an instance of {@link AspectRatio} specified by {@code x} and {@code y} values. * The values {@code x} and {@code} will be reduced by their greatest common divider. * * @param x The width//w ww . java 2s.c o m * @param y The height * @return An instance of {@link AspectRatio} */ public static AspectRatio of(int x, int y) { int gcd = gcd(x, y); x /= gcd; y /= gcd; SparseArrayCompat<AspectRatio> arrayX = sCache.get(x); if (arrayX == null) { AspectRatio ratio = new AspectRatio(x, y); arrayX = new SparseArrayCompat<>(); arrayX.put(y, ratio); sCache.put(x, arrayX); return ratio; } else { AspectRatio ratio = arrayX.get(y); if (ratio == null) { ratio = new AspectRatio(x, y); arrayX.put(y, ratio); } return ratio; } }
From source file:com.facebook.litho.ComponentHostUtils.java
/** * Moves an item from oldIndex to newIndex. The item is taken from scrapitems if an item exists * in scrapItems at oldPosition. Otherwise the item is taken from items. This assumes that there * is no item at newIndex for the items array. If that's the case * {@link ComponentHostUtils#scrapItemAt(int, SparseArrayCompat, SparseArrayCompat)} * has to be called before invoking this. */// ww w.j ava 2 s . c o m static <T> void moveItem(int oldIndex, int newIndex, SparseArrayCompat<T> items, SparseArrayCompat<T> scrapItems) { T itemToMove; if (existsScrapItemAt(oldIndex, scrapItems)) { // Before moving the item from items we need to check whether an old item has been put in // the scrapItems array. If there is an item at oldIndex there, it means that in // items at position oldIndex there's now something else and the correct item to move to // newIndex is instead in the scrapItems SparseArray. itemToMove = scrapItems.get(oldIndex); scrapItems.remove(oldIndex); } else { itemToMove = items.get(oldIndex); items.remove(oldIndex); } items.put(newIndex, itemToMove); }
From source file:com.granita.tasks.groupings.BaseTaskViewDescriptor.java
protected <T extends View> T getView(View view, int viewId) { SparseArrayCompat<View> viewHolder = (SparseArrayCompat<View>) view.getTag(); if (viewHolder == null) { viewHolder = new SparseArrayCompat<View>(); view.setTag(viewHolder);//from www. j a v a 2 s . c o m } View res = viewHolder.get(viewId); if (res == null) { res = view.findViewById(viewId); viewHolder.put(viewId, res); } return (T) res; }
From source file:com.dm.material.dashboard.candybar.adapters.RequestAdapter.java
public boolean isContainsRequested() { SparseArrayCompat<Request> requests = getSelectedApps(); boolean requested = false; for (int i = 0; i < requests.size(); i++) { if (requests.get(i).isRequested()) { requested = true;/*from ww w . ja v a 2 s .c om*/ break; } } return requested; }
From source file:com.mvcoding.financius.data.paging.PageLoader.java
@NonNull public Observable<PageResult<T>> load(@NonNull DataConverter<T> dataConverter, @NonNull DatabaseQuery databaseQuery, @NonNull Observable<Page> pageObservable) { final SparseArrayCompat<T> cache = new SparseArrayCompat<>(); final Observable<Cursor> cursorObservable = database.load(databaseQuery).doOnNext(cursor -> cache.clear()); return Observable.combineLatest(pageObservable, cursorObservable, (page, cursor) -> { final List<T> items = new ArrayList<>(); for (int i = page.getStart(), size = Math.min(cursor.getCount(), page.getStart() + page.getSize()); i < size; i++) { T item = cache.get(i); if (item == null) { cursor.moveToPosition(i); item = dataConverter.from(cursor); cache.put(i, item);/*from www . j a v a2 s. c o m*/ } items.add(item); } return new PageResult<>(page, items, cache.size() == items.size()); }); }
From source file:com.dm.material.dashboard.candybar.databases.Database.java
private void resetDatabase(SQLiteDatabase db) { Cursor cursor = db.rawQuery("SELECT name FROM sqlite_master WHERE type=\'table\'", null); SparseArrayCompat<String> tables = new SparseArrayCompat<>(); if (cursor.moveToFirst()) { do {/* www. java 2 s.c o m*/ tables.append(tables.size(), cursor.getString(0)); } while (cursor.moveToNext()); } cursor.close(); for (int i = 0; i < tables.size(); i++) { try { String dropQuery = "DROP TABLE IF EXISTS " + tables.get(i); if (!tables.get(i).equalsIgnoreCase("SQLITE_SEQUENCE")) db.execSQL(dropQuery); } catch (Exception ignored) { } } onCreate(db); }
From source file:com.dm.material.dashboard.candybar.helpers.MuzeiHelper.java
@Nullable public Wallpaper getRandomDownloadedWallpaper() throws Exception { SparseArrayCompat<Wallpaper> downloaded = new SparseArrayCompat<>(); List<Wallpaper> wallpapers = mDatabase.getWallpapers(); for (Wallpaper wallpaper : wallpapers) { File file = new File(mDirectory + File.separator + wallpaper.getName() + FileHelper.IMAGE_EXTENSION); if (file.exists()) { downloaded.append(downloaded.size(), wallpaper); }/*w w w . j a v a2s.com*/ } wallpapers.clear(); int size = downloaded.size(); if (size > 0) { int position = getRandomInt(size); return new Wallpaper(downloaded.get(position).getName(), downloaded.get(position).getAuthor(), downloaded.get(position).getURL(), downloaded.get(position).getThumbUrl()); } return null; }