List of usage examples for android.util SparseArray SparseArray
public SparseArray()
From source file:android.app.FragmentManager.java
void saveFragmentViewState(Fragment f) { if (f.mView == null) { return;/*w w w . j a v a2 s.c om*/ } if (mStateArray == null) { mStateArray = new SparseArray<Parcelable>(); } else { mStateArray.clear(); } f.mView.saveHierarchyState(mStateArray); if (mStateArray.size() > 0) { f.mSavedViewState = mStateArray; mStateArray = null; } }
From source file:com.chuhan.privatecalc.fragment.os.FragmentManager.java
void saveFragmentViewState(Fragment f) { if (f.mInnerView == null) { return;/*ww w . j a va2 s . co m*/ } if (mStateArray == null) { mStateArray = new SparseArray<Parcelable>(); } else { mStateArray.clear(); } f.mInnerView.saveHierarchyState(mStateArray); if (mStateArray.size() > 0) { f.mSavedViewState = mStateArray; mStateArray = null; } }
From source file:ti.modules.titanium.ui.widget.collectionview.TiCollectionView.java
protected void processTemplates(HashMap<String, Object> templates) { templatesByBinding = new HashMap<String, TiAbsListViewTemplate>(); templatesByType = new SparseArray<TiAbsListViewTemplate>(); templatesByBinding.put(defaultTemplateKey, defaultTemplate); templatesByType.put(defaultTemplate.getType(), defaultTemplate); if (templates != null) { for (String key : templates.keySet()) { HashMap templateDict = (HashMap) templates.get(key); if (templateDict != null) { // Here we bind each template with a key so we can use it to // look up later KrollDict properties = new KrollDict((HashMap) templates.get(key)); TiAbsListViewTemplate template = new TiAbsListViewTemplate(key, properties); final int type = getItemType(); template.setType(type);/*from ww w.j a v a 2s . c om*/ templatesByBinding.put(key, template); templatesByType.put(type, template); mRecyclerView.getRecycledViewPool().setMaxRecycledViews(type, 20); } else { Log.e(TAG, "null template definition: " + key); } } } }
From source file:com.ruesga.timelinechart.TimelineChartView.java
@SuppressWarnings("unchecked") private void setupTickLabels() { synchronized (mLock) { mTickCalendar = Calendar.getInstance(TimeZone.getDefault(), Locale.getDefault()); mTextSizeFactor = mFooterBarHeight / mDefFooterBarHeight; mTickLabelFgPaint.setTextSize((int) (mSize8 * mTextSizeFactor)); mTickDate = new Date(); int count = mTickFormats.length; mTickTextLayouts = new SparseArray[count]; mTickFormatter = new SimpleDateFormat[count]; mTickTextSpannables = new SparseArray[count]; for (int i = 0; i < count; i++) { mTickFormatter[i] = new SimpleDateFormat(mTickFormats[i], Locale.getDefault()); mTickDate.setTime(Long.valueOf(mTickLabels[i])); final String text = mTickFormatter[i].format(mTickDate).replace(".", "") .toUpperCase(Locale.getDefault()); mTickTextSpannables[i] = new SparseArray<>(); mTickTextLayouts[i] = new SparseArray<>(); // Store spannable in memory based in its length, so we don't have to rebuild // a every time, just only in case they are needed (normally never) DynamicSpannableString spannable = createSpannableTick(i, text); mTickTextLayouts[i].put(text.length(), new DynamicLayout(spannable, mTickLabelFgPaint, (int) mBarItemWidth, Layout.Alignment.ALIGN_CENTER, 1.0f, 1.0f, false)); // Save min height mTickLabelMinHeight = Math.max(mTickLabelMinHeight, mTickTextLayouts[i].get(text.length()).getHeight()); }//from ww w . j a v a2s .c o m } }
From source file:android.support.v17.leanback.widget.GridWidgetTest.java
public void testChildStates() throws Throwable { mInstrumentation = getInstrumentation(); Intent intent = new Intent(mInstrumentation.getContext(), GridActivity.class); intent.putExtra(GridActivity.EXTRA_LAYOUT_RESOURCE_ID, R.layout.vertical_linear); int[] items = new int[100]; for (int i = 0; i < items.length; i++) { items[i] = 200;//from w w w . j a v a2 s.c o m } intent.putExtra(GridActivity.EXTRA_ITEMS, items); intent.putExtra(GridActivity.EXTRA_STAGGERED, false); intent.putExtra(GridActivity.EXTRA_REQUEST_LAYOUT_ONFOCUS, true); intent.putExtra(GridActivity.EXTRA_CHILD_LAYOUT_ID, R.layout.selectable_text_view); mOrientation = BaseGridView.VERTICAL; mNumRows = 1; initActivity(intent); mGridView.setSaveChildrenPolicy(VerticalGridView.SAVE_ALL_CHILD); final SparseArray<Parcelable> container = new SparseArray<Parcelable>(); // 1 Save view states runTestOnUiThread(new Runnable() { public void run() { Selection.setSelection((Spannable) (((TextView) mGridView.getChildAt(0)).getText()), 0, 1); Selection.setSelection((Spannable) (((TextView) mGridView.getChildAt(1)).getText()), 0, 1); mGridView.saveHierarchyState(container); } }); // 2 Change view states runTestOnUiThread(new Runnable() { public void run() { Selection.setSelection((Spannable) (((TextView) mGridView.getChildAt(0)).getText()), 1, 2); Selection.setSelection((Spannable) (((TextView) mGridView.getChildAt(1)).getText()), 1, 2); } }); // 3 Detached and re-attached, should still maintain state of (2) runTestOnUiThread(new Runnable() { public void run() { mGridView.setSelectedPositionSmooth(1); } }); waitForScrollIdleAndItemAnimation(mVerifyLayout); assertEquals(((TextView) mGridView.getChildAt(0)).getSelectionStart(), 1); assertEquals(((TextView) mGridView.getChildAt(0)).getSelectionEnd(), 2); assertEquals(((TextView) mGridView.getChildAt(1)).getSelectionStart(), 1); assertEquals(((TextView) mGridView.getChildAt(1)).getSelectionEnd(), 2); // 4 Recycled and rebound, should load state from (2) runTestOnUiThread(new Runnable() { public void run() { mGridView.setSelectedPositionSmooth(20); } }); waitForScrollIdle(mVerifyLayout); runTestOnUiThread(new Runnable() { public void run() { mGridView.setSelectedPositionSmooth(0); } }); waitForScrollIdleAndItemAnimation(mVerifyLayout); assertEquals(((TextView) mGridView.getChildAt(0)).getSelectionStart(), 1); assertEquals(((TextView) mGridView.getChildAt(0)).getSelectionEnd(), 2); assertEquals(((TextView) mGridView.getChildAt(1)).getSelectionStart(), 1); assertEquals(((TextView) mGridView.getChildAt(1)).getSelectionEnd(), 2); }
From source file:android.support.v17.leanback.widget.GridWidgetTest.java
public void testNoDispatchSaveChildState() throws Throwable { mInstrumentation = getInstrumentation(); Intent intent = new Intent(mInstrumentation.getContext(), GridActivity.class); intent.putExtra(GridActivity.EXTRA_LAYOUT_RESOURCE_ID, R.layout.vertical_linear); int[] items = new int[100]; for (int i = 0; i < items.length; i++) { items[i] = 200;/*from ww w. j av a2 s. com*/ } intent.putExtra(GridActivity.EXTRA_ITEMS, items); intent.putExtra(GridActivity.EXTRA_STAGGERED, false); intent.putExtra(GridActivity.EXTRA_CHILD_LAYOUT_ID, R.layout.selectable_text_view); mOrientation = BaseGridView.VERTICAL; mNumRows = 1; initActivity(intent); mGridView.setSaveChildrenPolicy(VerticalGridView.SAVE_NO_CHILD); final SparseArray<Parcelable> container = new SparseArray<Parcelable>(); // 1. Set text selection, save view states should do nothing on child runTestOnUiThread(new Runnable() { public void run() { for (int i = 0; i < mGridView.getChildCount(); i++) { Selection.setSelection((Spannable) (((TextView) mGridView.getChildAt(i)).getText()), 0, 1); } mGridView.saveHierarchyState(container); } }); // 2. clear the text selection runTestOnUiThread(new Runnable() { public void run() { for (int i = 0; i < mGridView.getChildCount(); i++) { Selection.removeSelection((Spannable) (((TextView) mGridView.getChildAt(i)).getText())); } } }); // 3. Restore view states should be a no-op for child runTestOnUiThread(new Runnable() { public void run() { mGridView.restoreHierarchyState(container); for (int i = 0; i < mGridView.getChildCount(); i++) { assertEquals(-1, ((TextView) mGridView.getChildAt(i)).getSelectionStart()); assertEquals(-1, ((TextView) mGridView.getChildAt(i)).getSelectionEnd()); } } }); }
From source file:org.tvbrowser.tvbrowser.TvBrowser.java
private void uploadChannels() { String[] projection = { TvBrowserContentProvider.GROUP_KEY_GROUP_ID, TvBrowserContentProvider.CHANNEL_KEY_CHANNEL_ID, TvBrowserContentProvider.CHANNEL_KEY_ORDER_NUMBER }; Cursor channels = getContentResolver().query(TvBrowserContentProvider.CONTENT_URI_CHANNELS, projection, TvBrowserContentProvider.CHANNEL_KEY_SELECTION, null, TvBrowserContentProvider.CHANNEL_KEY_ORDER_NUMBER); SparseArray<String> groupKeys = new SparseArray<String>(); StringBuilder uploadChannels = new StringBuilder(); try {//from w ww . j a va 2 s . c o m channels.moveToPosition(-1); int groupKeyColumn = channels.getColumnIndex(TvBrowserContentProvider.GROUP_KEY_GROUP_ID); int channelKeyColumn = channels.getColumnIndex(TvBrowserContentProvider.CHANNEL_KEY_CHANNEL_ID); int channelKeyOrderNumberColumn = channels .getColumnIndex(TvBrowserContentProvider.CHANNEL_KEY_ORDER_NUMBER); while (channels.moveToNext()) { int groupKey = channels.getInt(groupKeyColumn); String channelId = channels.getString(channelKeyColumn); int orderNumber = channels.getInt(channelKeyOrderNumberColumn); String groupId = groupKeys.get(groupKey); if (groupId == null) { String[] groupProjection = { TvBrowserContentProvider.GROUP_KEY_GROUP_ID, TvBrowserContentProvider.GROUP_KEY_DATA_SERVICE_ID }; Cursor groups = getContentResolver().query(TvBrowserContentProvider.CONTENT_URI_GROUPS, groupProjection, TvBrowserContentProvider.KEY_ID + "=" + groupKey, null, null); try { if (groups.moveToFirst()) { String dataServiceId = groups.getString( groups.getColumnIndex(TvBrowserContentProvider.GROUP_KEY_DATA_SERVICE_ID)); String goupIdValue = groups .getString(groups.getColumnIndex(TvBrowserContentProvider.GROUP_KEY_GROUP_ID)); String dataServiceIdNumber = SettingConstants.getNumberForDataServiceKey(dataServiceId); if (dataServiceIdNumber != null) { if (dataServiceId.equals(SettingConstants.EPG_FREE_KEY)) { groupId = dataServiceIdNumber + ":" + goupIdValue + ":"; } else if (dataServiceId.equals(SettingConstants.EPG_DONATE_KEY)) { groupId = dataServiceIdNumber + ":"; } groupKeys.put(groupKey, groupId); } } } finally { groups.close(); } } uploadChannels.append(groupId).append(channelId); if (orderNumber > 0) { uploadChannels.append(":").append(orderNumber); } uploadChannels.append("\n"); } } finally { channels.close(); } if (uploadChannels.toString().trim().length() > 0) { startSynchronizeUp(true, uploadChannels.toString().trim(), "http://android.tvbrowser.org/data/scripts/syncUp.php?type=channelsFromDesktop", SettingConstants.SYNCHRONIZE_UP_DONE, getString(R.string.backup_channels_success)); } }
From source file:com.oakesville.mythling.MediaActivity.java
SparseArray<String> getLongClickMenuItems(Item item) { String[] menuItems = getResources().getStringArray(R.array.item_long_click_menu); SparseArray<String> relevantItems = new SparseArray<String>(); for (int i = 0; i < menuItems.length; i++) { if (i == LONG_CLICK_MENU_PLAY) relevantItems.put(i, menuItems[i]); else if (i == LONG_CLICK_MENU_TRANSCODE && !item.isMusic()) relevantItems.put(i, menuItems[i]); else if (i == LONG_CLICK_MENU_DOWNLOAD && !item.isLiveTv()) relevantItems.put(i, menuItems[i]); else if (i == LONG_CLICK_MENU_DELETE && item.isRecording()) relevantItems.put(i, menuItems[i]); }/*from w ww. j a va2 s.c om*/ return relevantItems; }
From source file:android.support.v17.leanback.widget.GridWidgetTest.java
public void testRestoreIndexAndAddItems() throws Throwable { mInstrumentation = getInstrumentation(); Intent intent = new Intent(mInstrumentation.getContext(), GridActivity.class); intent.putExtra(GridActivity.EXTRA_LAYOUT_RESOURCE_ID, R.layout.vertical_linear); intent.putExtra(GridActivity.EXTRA_CHILD_LAYOUT_ID, R.layout.horizontal_item); intent.putExtra(GridActivity.EXTRA_NUM_ITEMS, 4); initActivity(intent);//from ww w.ja v a 2 s. c o m mOrientation = BaseGridView.VERTICAL; mNumRows = 1; assertEquals(mGridView.getSelectedPosition(), 0); final SparseArray states = new SparseArray(); runTestOnUiThread(new Runnable() { @Override public void run() { mGridView.saveHierarchyState(states); mGridView.setAdapter(null); } }); runTestOnUiThread(new Runnable() { @Override public void run() { mGridView.restoreHierarchyState(states); mActivity.attachToNewAdapter(new int[0]); mActivity.addItems(0, new int[] { 100, 100, 100, 100 }); } }); waitForTransientStateGone(null); assertEquals(mGridView.getSelectedPosition(), 0); }
From source file:android.support.design.widget.CoordinatorLayout.java
@Override protected Parcelable onSaveInstanceState() { final SavedState ss = new SavedState(super.onSaveInstanceState()); final SparseArray<Parcelable> behaviorStates = new SparseArray<>(); for (int i = 0, count = getChildCount(); i < count; i++) { final View child = getChildAt(i); final int childId = child.getId(); final LayoutParams lp = (LayoutParams) child.getLayoutParams(); final Behavior b = lp.getBehavior(); if (childId != NO_ID && b != null) { // If the child has an ID and a Behavior, let it save some state... Parcelable state = b.onSaveInstanceState(this, child); if (state != null) { behaviorStates.append(childId, state); }/*from ww w. j ava 2s . c o m*/ } } ss.behaviorStates = behaviorStates; return ss; }