List of usage examples for android.util SparseArray SparseArray
public SparseArray()
From source file:fr.cph.chicago.core.fragment.NearbyFragment.java
private SparseArray<TrainArrival> loadAroundTrainArrivals(@NonNull final List<Station> trainStations) { try {// w w w . jav a 2s .c o m final SparseArray<TrainArrival> trainArrivals = new SparseArray<>(); if (isAdded()) { final CtaConnect cta = CtaConnect.getInstance(getContext()); for (final Station station : trainStations) { final MultiValuedMap<String, String> reqParams = new ArrayListValuedHashMap<>(1, 1); reqParams.put(requestMapId, Integer.toString(station.getId())); final InputStream xmlRes = cta.connect(TRAIN_ARRIVALS, reqParams); final XmlParser xml = XmlParser.getInstance(); final SparseArray<TrainArrival> temp = xml.parseArrivals(xmlRes, DataHolder.getInstance().getTrainData()); for (int j = 0; j < temp.size(); j++) { trainArrivals.put(temp.keyAt(j), temp.valueAt(j)); } trackWithGoogleAnalytics(activity, R.string.analytics_category_req, R.string.analytics_action_get_train, TRAINS_ARRIVALS_URL, 0); } } return trainArrivals; } catch (final Throwable throwable) { throw Exceptions.propagate(throwable); } }
From source file:org.chromium.chrome.browser.media.ui.MediaNotificationManager.java
/** * Shows the notification with media controls with the specified media info. Replaces/updates * the current notification if already showing. Does nothing if |mediaNotificationInfo| hasn't * changed from the last one.//from ww w . j a va2 s. co m * * @param applicationContext context to create the notification with * @param notificationInfo information to show in the notification */ public static void show(Context applicationContext, MediaNotificationInfo notificationInfo) { synchronized (LOCK) { if (sManagers == null) { sManagers = new SparseArray<MediaNotificationManager>(); } } MediaNotificationManager manager = sManagers.get(notificationInfo.id); if (manager == null) { manager = new MediaNotificationManager(applicationContext, notificationInfo.id); sManagers.put(notificationInfo.id, manager); } manager.showNotification(notificationInfo); }
From source file:ca.mimic.apphangar.Settings.java
protected void setUpSpinner(Spinner spinner) { String[] spinnerItems = getResources().getStringArray(R.array.entries_action_spinner); List<SparseArray<String>> items = new ArrayList<SparseArray<String>>(); for (int i = 0; i < spinnerItems.length; i++) { SparseArray<String> spinnerMap = new SparseArray<String>(); spinnerMap.put(i, spinnerItems[i]); items.add(spinnerMap);// www. j ava 2 s .co m } final List<SparseArray<String>> finalItems = items; SpinnerAdapter mSpinnerAdapter = new CustomArrayAdapter(mContext, android.R.layout.simple_spinner_dropdown_item, items); spinner.setAdapter(mSpinnerAdapter); Spinner.OnItemSelectedListener spinnerListener = new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) { try { ((TextView) view).setText(finalItems.get(i).get(i)); } catch (NullPointerException e) { } switch (i) { case 0: return; case 1: startActivity(new Intent(mContext, AppsWidgetSettings.class)); break; case 2: startActivity(new Intent(mContext, StatsWidgetSettings.class)); break; } } @Override public void onNothingSelected(AdapterView<?> adapterView) { } }; spinner.setAdapter(mSpinnerAdapter); spinner.setOnItemSelectedListener(spinnerListener); }
From source file:org.openmrs.mobile.activities.login.LoginFragment.java
private void bindDrawableResources() { mBitmapCache = new SparseArray<>(); ImageView openMrsLogoImage = (ImageView) getActivity().findViewById(R.id.openmrsLogo); createImageBitmap(R.drawable.openmrs_logo, openMrsLogoImage.getLayoutParams()); openMrsLogoImage.setImageBitmap(mBitmapCache.get(R.drawable.openmrs_logo)); }
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 w w w .ja v a2 s . c o m @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); } }
From source file:android.support.v7ox.widget.AppCompatDrawableManager.java
private Drawable loadDrawableFromDelegates(@NonNull Context context, @DrawableRes int resId) { if (mDelegates != null && !mDelegates.isEmpty()) { if (mKnownDrawableIdTags != null) { final String cachedTagName = mKnownDrawableIdTags.get(resId); if (SKIP_DRAWABLE_TAG.equals(cachedTagName) || (cachedTagName != null && mDelegates.get(cachedTagName) == null)) { // If we don't have a delegate for the drawable tag, or we've been set to // skip it, fail fast and return null if (DEBUG) { Log.d(TAG, "[loadDrawableFromDelegates] Skipping drawable: " + context.getResources().getResourceName(resId)); }/*w ww. j a v a 2 s . c om*/ return null; } } else { // Create an id cache as we'll need one later mKnownDrawableIdTags = new SparseArray<>(); } if (mTypedValue == null) { mTypedValue = new TypedValue(); } final TypedValue tv = mTypedValue; final Resources res = context.getResources(); res.getValue(resId, tv, true); final long key = (((long) tv.assetCookie) << 32) | tv.data; Drawable dr = getCachedDelegateDrawable(context, key); if (dr != null) { if (DEBUG) { Log.i(TAG, "[loadDrawableFromDelegates] Returning cached drawable: " + context.getResources().getResourceName(resId)); } // We have a cached drawable, return it! return dr; } if (tv.string != null && tv.string.toString().endsWith(".xml")) { // If the resource is an XML file, let's try and parse it try { final XmlPullParser parser = res.getXml(resId); final AttributeSet attrs = Xml.asAttributeSet(parser); int type; while ((type = parser.next()) != XmlPullParser.START_TAG && type != XmlPullParser.END_DOCUMENT) { // Empty loop } if (type != XmlPullParser.START_TAG) { throw new XmlPullParserException("No start tag found"); } final String tagName = parser.getName(); // Add the tag name to the cache mKnownDrawableIdTags.append(resId, tagName); // Now try and find a delegate for the tag name and inflate if found final InflateDelegate delegate = mDelegates.get(tagName); if (delegate != null) { dr = delegate.createFromXmlInner(context, parser, attrs, context.getTheme()); } if (dr != null) { // Add it to the drawable cache dr.setChangingConfigurations(tv.changingConfigurations); if (addCachedDelegateDrawable(context, key, dr) && DEBUG) { Log.i(TAG, "[loadDrawableFromDelegates] Saved drawable to cache: " + context.getResources().getResourceName(resId)); } } } catch (Exception e) { Log.e(TAG, "Exception while inflating drawable", e); } } if (dr == null) { // If we reach here then the delegate inflation of the resource failed. Mark it as // bad so we skip the id next time mKnownDrawableIdTags.append(resId, SKIP_DRAWABLE_TAG); } return dr; } return null; }
From source file:com.codetroopers.shakemytours.ui.activity.TripActivity.java
private void generateMarkers(int count) { mMarkerList = new SparseArray<>(); for (int i = 0; i < count; i++) { Bitmap intermediateMarker = createIntermediateMarker(i); mMarkerList.put(i, intermediateMarker); }/*from w w w .ja v a 2 s . c om*/ }
From source file:com.httrack.android.HTTrackActivity.java
/** * Return the project category of a given project. * //from ww w.jav a 2 s . co m * @param projectName * @return the project category, or @c null if none (or there is no such * project) */ private String getProjectCategory(final String projectName) { final SparseArray<String> projectMap = new SparseArray<String>(); final File target = new File(getProjectRootFile(), projectName); try { OptionsMapper.unserialize(HTTrackActivity.getProfileFile(target), projectMap); final String description = projectMap.get(R.id.fieldProjectCategory); return description; } catch (final IOException e) { return null; } }
From source file:xyz.berial.textinputlayout.TintManager.java
public final ColorStateList getTintList(int resId) { final Context context = mContextRef.get(); if (context == null) return null; // Try the cache first (if it exists) ColorStateList tint = mTintLists != null ? mTintLists.get(resId) : null; if (tint == null) { // ...if the cache did not contain a color state list, try and create one if (resId == R.drawable.abc_edit_text_material) { tint = createEditTextColorStateList(context); } else if (resId == R.drawable.abc_switch_track_mtrl_alpha) { tint = createSwitchTrackColorStateList(context); } else if (resId == R.drawable.abc_switch_thumb_material) { tint = createSwitchThumbColorStateList(context); } else if (resId == R.drawable.abc_btn_default_mtrl_shape || resId == R.drawable.abc_btn_borderless_material) { tint = createDefaultButtonColorStateList(context); } else if (resId == R.drawable.abc_btn_colored_material) { tint = createColoredButtonColorStateList(context); } else if (resId == R.drawable.abc_spinner_mtrl_am_alpha || resId == R.drawable.abc_spinner_textfield_background_material) { tint = createSpinnerColorStateList(context); } else if (arrayContains(TINT_COLOR_CONTROL_NORMAL, resId)) { tint = getThemeAttrColorStateList(context, R.attr.colorControlNormal); } else if (arrayContains(TINT_COLOR_CONTROL_STATE_LIST, resId)) { tint = getDefaultColorStateList(context); } else if (arrayContains(TINT_CHECKABLE_BUTTON_LIST, resId)) { tint = createCheckableButtonColorStateList(context); }/*from w w w. j a va2 s.c o m*/ if (tint != null) { if (mTintLists == null) { // If our tint list cache hasn't been set up yet, create it mTintLists = new SparseArray<>(); } // Add any newly created ColorStateList to the cache mTintLists.append(resId, tint); } } return tint; }
From source file:android.support.v7.internal.view.menu.MenuBuilder.java
public void saveActionViewStates(Bundle outStates) { SparseArray<Parcelable> viewStates = null; final int itemCount = size(); for (int i = 0; i < itemCount; i++) { final MenuItem item = getItem(i); final View v = MenuItemCompat.getActionView(item); if (v != null && v.getId() != View.NO_ID) { if (viewStates == null) { viewStates = new SparseArray<Parcelable>(); }/*www.ja va 2 s. c om*/ v.saveHierarchyState(viewStates); if (MenuItemCompat.isActionViewExpanded(item)) { outStates.putInt(EXPANDED_ACTION_VIEW_ID, item.getItemId()); } } if (item.hasSubMenu()) { final SubMenuBuilder subMenu = (SubMenuBuilder) item.getSubMenu(); subMenu.saveActionViewStates(outStates); } } if (viewStates != null) { outStates.putSparseParcelableArray(getActionViewStatesKey(), viewStates); } }