List of usage examples for android.util SparseArray SparseArray
public SparseArray()
From source file:cn.arvin.example.ui.custom.observablescrollview.CacheFragmentStatePagerAdapter.java
public CacheFragmentStatePagerAdapter(FragmentManager fm) { super(fm); mPages = new SparseArray<Fragment>(); mFm = fm; }
From source file:com.android.llibs.views.observablescrollview.CacheFragmentStatePagerAdapter.java
public CacheFragmentStatePagerAdapter(FragmentManager fm) { super(fm); mPages = new SparseArray<>(); mFm = fm; }
From source file:Main.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 av a 2s . co m*/ * @param samples The approximate max number of samples to use. */ 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 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.gm.grecyclerview.SimpleAdapter.java
SimpleAdapter() { this.cells = new ArrayList<>(); this.cellTypeMap = new SparseArray<>(); setHasStableIds(true); }
From source file:ch.gianulli.flashcards.lists.CardsAdapter.java
public CardsAdapter(Context context, ArrayList<Card> cards, OnCardAnsweredListener listener) { mInflater = LayoutInflater.from(context); if (cards != null) { mCards = new ArrayList<>(cards); } else {//from w ww.j a v a 2 s. co m mCards = new ArrayList<>(); } mListener = listener; mAnsweredCards = new SparseArray<>(); // Get font size from preferences mPreferenceModel = new PreferenceModel(context); mFontSize = mPreferenceModel.getFontSize(); mMathMLEnabled = mPreferenceModel.isMathMLEnabled(); }
From source file:com.dgsd.android.ShiftTracker.Adapter.TemplateAdapter.java
public TemplateAdapter(Context context) { super(context, R.layout.list_item_template, null, new String[] { DbField.ID.name }, new int[] { R.id.container }, 0); this.setViewBinder(this); mTimeFormat = DateFormat.getTimeFormat(context); //Caching/*from w w w . j av a2 s . c om*/ mIdToTimeArray = new SparseArray<String>(); }
From source file:com.secupwn.aimsicd.AndroidIMSICatcherDetector.java
public AndroidIMSICatcherDetector() { mActivityTaskMap = new SparseArray<>(); }
From source file:net.naonedbus.rest.controller.impl.ParkingPublicsController.java
public ParkingPublicsController() { super("opendata", "answer", "data", "Groupes_Parking", "Groupe_Parking"); statuts = new SparseArray<ParkingPublicStatut>(); for (final ParkingPublicStatut statut : ParkingPublicStatut.values()) { statuts.put(statut.getValue(), statut); }//from w w w . j av a 2s. c o m }
From source file:net.eledge.android.toolkit.db.internal.TableBuilder.java
public String[] update(Class<?> clazz, int oldVersion, int newVersion) { SparseArray<List<String>> versionUpdates = new SparseArray<>(); versionUpdates.put(-1, new ArrayList<String>()); for (int i = oldVersion + 1; i <= newVersion; i++) { versionUpdates.put(i, new ArrayList<String>()); }// w ww . j a v a 2s . co m if (!doesTableExists(clazz)) { versionUpdates.get(-1).add(create(clazz)); } else { versionUpdates.get(-1).addAll(createTableUpdates(clazz)); } collectTableUpdatesAnnotations(versionUpdates, clazz); collectFieldUpdatesAnnotations(versionUpdates, clazz); return StringArrayUtils.toArray(versionUpdates); }
From source file:com.github.monxalo.android.widget.SectionCursorAdapter.java
public SectionCursorAdapter(Context context, Cursor c, int headerLayout, int groupColumn) { super(context, c, 0); mSectionsIndexer = new SparseArray<String>(); mHeaderRes = headerLayout;//from w w w.j a v a2 s . com mGroupColumn = groupColumn; mLayoutInflater = LayoutInflater.from(context); if (c != null) { calculateSectionHeaders(); c.registerDataSetObserver(mDataSetObserver); } }