List of usage examples for android.util SparseArray SparseArray
public SparseArray()
From source file:dentex.youtube.downloader.YTD.java
public static CharSequence getListFilterConstraint(int c) { //0/*from ww w . j av a 2 s . c o m*/ List<Integer> iMp4List = Arrays.asList(iMp4); //1 List<Integer> iWebmList = Arrays.asList(iWebm); //2 List<Integer> iFlvList = Arrays.asList(iFlv); //3 List<Integer> i3gpList = Arrays.asList(i3gp); //4 List<Integer> iHdList = Arrays.asList(iHd); //5 List<Integer> iLdList = Arrays.asList(iLd); //6 List<Integer> iMdList = Arrays.asList(iMd); //7 List<Integer> iSdList = Arrays.asList(iSd); //8 List<Integer> i3dList = Arrays.asList(i3d); //9 List<Integer> iVoList = Arrays.asList(iVo); //10 List<Integer> iAoList = Arrays.asList(iAo); SparseArray<List<Integer>> filtersMap = new SparseArray<List<Integer>>(); filtersMap.put(MP4_FILTER, iMp4List); filtersMap.put(WEBM_FILTER, iWebmList); filtersMap.put(FLV_FILTER, iFlvList); filtersMap.put(_3GP_FILTER, i3gpList); filtersMap.put(HD_FILTER, iHdList); filtersMap.put(LD_FILTER, iLdList); filtersMap.put(MD_FILTER, iMdList); filtersMap.put(SD_FILTER, iSdList); filtersMap.put(_3D_FILTER, i3dList); filtersMap.put(VO_FILTER, iVoList); filtersMap.put(AO_FILTER, iAoList); if (c == -1) return VIEW_ALL_STRING; CharSequence constraint = null; List<Integer> selectedMap = filtersMap.get(c); for (int i = 0; i < selectedMap.size(); i++) { if (constraint == null) { constraint = String.valueOf(selectedMap.get(i)); } else { constraint = constraint + "/" + selectedMap.get(i); } } //Utils.logger("i", "ListFilterConstraint: " + constraint, DEBUG_TAG); return constraint; }
From source file:dev.dworks.apps.anexplorer.fragment.DirectoryFragment.java
@Override public void onStop() { super.onStop(); // Remember last scroll location final SparseArray<Parcelable> container = new SparseArray<Parcelable>(); getView().saveHierarchyState(container); final State state = getDisplayState(this); state.dirState.put(mStateKey, container); }
From source file:eu.davidea.flexibleadapter.common.FlexibleItemDecoration.java
/** * As {@link #addItemViewType(int)} but with custom offset that will affect only this viewType. * * @param viewType the viewType affected * @param left the offset to the left of the item * @param top the offset to the top of the item * @param right the offset to the right of the item * @param bottom the offset to the bottom of the item * @return this FlexibleItemDecoration instance so the call can be chained * @see #addItemViewType(int, int)//from w ww . j a v a 2 s . c o m * @see #removeItemViewType(int) * @since 5.0.0-rc2 */ public FlexibleItemDecoration addItemViewType(@LayoutRes int viewType, int left, int top, int right, int bottom) { if (mDecorations == null) { mDecorations = new SparseArray<>(); } left = (int) (context.getResources().getDisplayMetrics().density * left); top = (int) (context.getResources().getDisplayMetrics().density * top); right = (int) (context.getResources().getDisplayMetrics().density * right); bottom = (int) (context.getResources().getDisplayMetrics().density * bottom); mDecorations.put(viewType, new ItemDecoration(left, top, right, bottom)); return this; }
From source file:com.atwal.wakeup.battery.util.Utilities.java
/** * This picks a dominant color, looking for high-saturation, high-value, repeated hues. * * @param bitmap The bitmap to scan/*from w w w .j a va 2s .co m*/ * @param samples The approximate max number of samples to use. */ public static int findDominantColorByHue(Bitmap bitmap, int samples) { final int height = bitmap.getHeight(); final int width = bitmap.getWidth(); int sampleStride = (int) Math.sqrt((height * width) / samples); if (sampleStride < 1) { sampleStride = 1; } // This is an out-param, for getting the hsv values for an rgb float[] hsv = new float[3]; // First get the best hue, by creating a histogram over 360 hue buckets, // where each pixel contributes a score weighted by saturation, value, and alpha. float[] hueScoreHistogram = new float[360]; float highScore = -1; int bestHue = -1; for (int y = 0; y < height; y += sampleStride) { for (int x = 0; x < width; x += sampleStride) { int argb = bitmap.getPixel(x, y); int alpha = 0xFF & (argb >> 24); if (alpha < 0x80) { // Drop mostly-transparent pixels. continue; } // Remove the alpha channel. int rgb = argb | 0xFF000000; Color.colorToHSV(rgb, hsv); // Bucket colors by the 360 integer hues. int hue = (int) hsv[0]; if (hue < 0 || hue >= hueScoreHistogram.length) { // Defensively avoid array bounds violations. continue; } float score = hsv[1] * hsv[2]; hueScoreHistogram[hue] += score; if (hueScoreHistogram[hue] > highScore) { highScore = hueScoreHistogram[hue]; bestHue = hue; } } } SparseArray<Float> rgbScores = new SparseArray<Float>(); int bestColor = 0xff000000; highScore = -1; // Go theme_icon_back over the RGB colors that match the winning hue, // creating a histogram of weighted s*v scores, for up to 100*100 [s,v] buckets. // The highest-scoring RGB color wins. for (int y = 0; y < height; y += sampleStride) { for (int x = 0; x < width; x += sampleStride) { int rgb = bitmap.getPixel(x, y) | 0xff000000; Color.colorToHSV(rgb, hsv); int hue = (int) hsv[0]; if (hue == bestHue) { float s = hsv[1]; float v = hsv[2]; int bucket = (int) (s * 100) + (int) (v * 10000); // Score by cumulative saturation * value. float score = s * v; Float oldTotal = rgbScores.get(bucket); float newTotal = oldTotal == null ? score : oldTotal + score; rgbScores.put(bucket, newTotal); if (newTotal > highScore) { highScore = newTotal; // All the colors in the winning bucket are very similar. Last in wins. bestColor = rgb; } } } } return bestColor; }
From source file:com.tomeokin.widget.jotablayout2.JoTabLayout.java
@Override protected Parcelable onSaveInstanceState() { Bundle bundle = new Bundle(); bundle.putParcelable("parentInstanceState", super.onSaveInstanceState()); bundle.putInt("mCurrentTab", mCurrentTab); SparseArray<Parcelable> childInstanceState = new SparseArray<>(); for (int i = 0; i < getChildCount(); i++) { getChildAt(i).saveHierarchyState(childInstanceState); }//from www.ja v a 2 s . co m bundle.putSparseParcelableArray("childInstanceState", childInstanceState); return bundle; }
From source file:com.twistedequations.rotor.MediaMetadataCompat.java
@TargetApi(Build.VERSION_CODES.KITKAT) private static void fillEditorKeyMapping() { EDITOR_KEY_MAPPING = new SparseArray<String>(); EDITOR_KEY_MAPPING.put(MediaMetadataEditor.BITMAP_KEY_ARTWORK, METADATA_KEY_ART); EDITOR_KEY_MAPPING.put(MediaMetadataEditor.RATING_KEY_BY_OTHERS, METADATA_KEY_RATING); EDITOR_KEY_MAPPING.put(MediaMetadataEditor.RATING_KEY_BY_USER, METADATA_KEY_USER_RATING); EDITOR_KEY_MAPPING.put(MediaMetadataRetriever.METADATA_KEY_ALBUM, METADATA_KEY_ALBUM); EDITOR_KEY_MAPPING.put(MediaMetadataRetriever.METADATA_KEY_ALBUMARTIST, METADATA_KEY_ALBUM_ARTIST); EDITOR_KEY_MAPPING.put(MediaMetadataRetriever.METADATA_KEY_ARTIST, METADATA_KEY_ARTIST); EDITOR_KEY_MAPPING.put(MediaMetadataRetriever.METADATA_KEY_AUTHOR, METADATA_KEY_AUTHOR); EDITOR_KEY_MAPPING.put(MediaMetadataRetriever.METADATA_KEY_CD_TRACK_NUMBER, METADATA_KEY_TRACK_NUMBER); EDITOR_KEY_MAPPING.put(MediaMetadataRetriever.METADATA_KEY_COMPOSER, METADATA_KEY_COMPOSER); EDITOR_KEY_MAPPING.put(MediaMetadataRetriever.METADATA_KEY_COMPILATION, METADATA_KEY_COMPILATION); EDITOR_KEY_MAPPING.put(MediaMetadataRetriever.METADATA_KEY_DATE, METADATA_KEY_DATE); EDITOR_KEY_MAPPING.put(MediaMetadataRetriever.METADATA_KEY_DISC_NUMBER, METADATA_KEY_DISC_NUMBER); EDITOR_KEY_MAPPING.put(MediaMetadataRetriever.METADATA_KEY_DURATION, METADATA_KEY_DURATION); EDITOR_KEY_MAPPING.put(MediaMetadataRetriever.METADATA_KEY_GENRE, METADATA_KEY_GENRE); EDITOR_KEY_MAPPING.put(MediaMetadataRetriever.METADATA_KEY_NUM_TRACKS, METADATA_KEY_NUM_TRACKS); EDITOR_KEY_MAPPING.put(MediaMetadataRetriever.METADATA_KEY_TITLE, METADATA_KEY_TITLE); EDITOR_KEY_MAPPING.put(MediaMetadataRetriever.METADATA_KEY_WRITER, METADATA_KEY_WRITER); EDITOR_KEY_MAPPING.put(MediaMetadataRetriever.METADATA_KEY_YEAR, METADATA_KEY_YEAR); }
From source file:org.secu3.android.ParamActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { Skeletons = new SparseArray<Secu3Packet>(); sharedPref = PreferenceManager.getDefaultSharedPreferences(this); uploadImmediatelly = sharedPref.getBoolean(getString(R.string.pref_upload_immediately_key), false); setTheme(sharedPref.getBoolean(getString(R.string.pref_night_mode_key), false) ? R.style.AppBaseTheme : R.style.AppBaseTheme_Light); setContentView(R.layout.activity_param); createFormFromXml(R.xml.parameters, SettingsActivity.getProtocolVersion(this)); packetUtils = new PacketUtils(this); paramAdapter = new ParamPagerAdapter(getSupportFragmentManager(), this, pages); progressBar = (ProgressBar) findViewById(R.id.paramsProgressBar); paramsRead();//from w w w. j a va 2 s . c o m receiver = new ReceiveMessages(); textViewStatus = (TextView) findViewById(R.id.paramsTextViewStatus); pager = (ViewPager) findViewById(R.id.paramsPager); pager.setAdapter(paramAdapter); if (savedInstanceState != null) { pager.setCurrentItem(savedInstanceState.getInt(PAGE)); } isValid = false; BaseParamItem i = paramAdapter.findItemByNameId(R.string.secur_par_apply_bluetooth_title); if (i != null) i.setEnabled(false); super.onCreate(savedInstanceState); }
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 . ja va2 s .c om 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:com.zenithed.core.widget.scaledimageview.ScaledImageView.java
/** * Once source image and view dimensions are known, creates a map of sample size to tile grid. *//*from w w w . j a v a2 s .co m*/ private static SparseArray<List<Tile>> initialiseTileMap(int fullImageSampleSize, int contentWidth, int contentHeight) { final SparseArray<List<Tile>> tileMap = new SparseArray<List<Tile>>(); int sampleSize = fullImageSampleSize; int tilesPerSide = 1; List<Tile> tileGrid = null; Tile tile = null; while (true) { int sTileWidth = contentWidth / tilesPerSide; int sTileHeight = contentHeight / tilesPerSide; int subTileWidth = sTileWidth / sampleSize; int subTileHeight = sTileHeight / sampleSize; while (subTileWidth > TILE_MAX_SIZE || subTileHeight > TILE_MAX_SIZE) { tilesPerSide *= 2; sTileWidth = contentWidth / tilesPerSide; sTileHeight = contentHeight / tilesPerSide; subTileWidth = sTileWidth / sampleSize; subTileHeight = sTileHeight / sampleSize; } tileGrid = new ArrayList<Tile>(tilesPerSide * tilesPerSide); for (int x = 0; x < tilesPerSide; x++) { for (int y = 0; y < tilesPerSide; y++) { tile = new Tile(); tile.sampleSize = sampleSize; tile.sRect = new Rect(x * sTileWidth, y * sTileHeight, (x + 1) * sTileWidth, (y + 1) * sTileHeight); tileGrid.add(tile); } } tileMap.put(sampleSize, tileGrid); tilesPerSide = (tilesPerSide == 1) ? 4 : tilesPerSide * 2; if (sampleSize == 1) { break; } else { sampleSize /= 2; } } return tileMap; }
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<>(); }//from w w w. j a v a 2 s . c om SparseArray<ColorStateList> themeTints = mTintLists.get(context); if (themeTints == null) { themeTints = new SparseArray<>(); mTintLists.put(context, themeTints); } themeTints.append(resId, tintList); }