List of usage examples for android.os Bundle getSparseParcelableArray
@Nullable public <T extends Parcelable> SparseArray<T> getSparseParcelableArray(@Nullable String key)
From source file:com.tomeokin.widget.jotablayout2.JoTabLayout.java
@Override protected void onRestoreInstanceState(Parcelable state) { if (state instanceof Bundle) { Bundle bundle = (Bundle) state; mCurrentTab = bundle.getInt("mCurrentTab"); state = bundle.getParcelable("parentInstanceState"); super.onRestoreInstanceState(state); SparseArray<Parcelable> childInstanceStates = bundle.getSparseParcelableArray("childInstanceState"); for (int i = 0; i < getChildCount(); i++) { getChildAt(i).restoreHierarchyState(childInstanceStates); }//from w w w .ja v a2s .c om } }
From source file:com.quectel.presentationtest.PresentationTest.java
/** * Initialization of the Activity after it is first created. Must at least * call {@link android.app.Activity#setContentView setContentView()} to * describe what is to be displayed in the screen. *//*from w w w .j a v a 2 s. c o m*/ @Override protected void onCreate(Bundle savedInstanceState) { // Be sure to call the super class. super.onCreate(savedInstanceState); // Restore saved instance state. if (savedInstanceState != null) { mSavedPresentationContents = savedInstanceState.getSparseParcelableArray(PRESENTATION_KEY); } else { mSavedPresentationContents = new SparseArray<DemoPresentationContents>(); } // Get the display manager service. mDisplayManager = (DisplayManager) getSystemService(Context.DISPLAY_SERVICE); // See assets/res/any/layout/presentation_activity.xml for this // view layout definition, which is being set here as // the content of our screen. setContentView(R.layout.presentation_activity); mDetector = new GestureDetectorCompat(this, new MyGestureListener()); // Set up checkbox to toggle between showing all displays or only presentation displays. mShowAllDisplaysCheckbox = (CheckBox) findViewById(R.id.show_all_displays); mShowAllDisplaysCheckbox.setOnCheckedChangeListener(this); // Set up the list of displays. mDisplayListAdapter = new DisplayListAdapter(this); mListView = (ListView) findViewById(R.id.display_list); mListView.setAdapter(mDisplayListAdapter); }
From source file:atownsend.swipeopenhelper.SwipeOpenItemTouchHelper.java
public void restoreInstanceState(Bundle savedInstanceState) { openedPositions = savedInstanceState.getSparseParcelableArray(OPENED_STATES); if (openedPositions == null) { openedPositions = new SparseArray<>(); }/*from ww w . ja v a 2 s .c om*/ }
From source file:com.actionbarsherlock.internal.view.menu.MenuBuilder.java
private void dispatchRestoreInstanceState(Bundle state) { SparseArray<Parcelable> presenterStates = state.getSparseParcelableArray(PRESENTER_KEY); if (presenterStates == null || mPresenters.isEmpty()) return;//from ww w.ja va 2 s .c om for (WeakReference<MenuPresenter> ref : mPresenters) { final MenuPresenter presenter = ref.get(); if (presenter == null) { mPresenters.remove(ref); } else { final int id = presenter.getId(); if (id > 0) { Parcelable parcel = presenterStates.get(id); if (parcel != null) { presenter.onRestoreInstanceState(parcel); } } } } }
From source file:com.actionbarsherlock.internal.view.menu.MenuBuilder.java
public void restoreActionViewStates(Bundle states) { if (states == null) { return;//from ww w. j a v a2s . c om } SparseArray<Parcelable> viewStates = states.getSparseParcelableArray(getActionViewStatesKey()); final int itemCount = size(); for (int i = 0; i < itemCount; i++) { final MenuItem item = getItem(i); final View v = item.getActionView(); if (v != null && v.getId() != View.NO_ID) { v.restoreHierarchyState(viewStates); } if (item.hasSubMenu()) { final SubMenuBuilder subMenu = (SubMenuBuilder) item.getSubMenu(); subMenu.restoreActionViewStates(states); } } }
From source file:android.support.v7.internal.view.menu.MenuBuilder.java
public void restoreActionViewStates(Bundle states) { if (states == null) { return;// ww w. jav a 2 s . c om } SparseArray<Parcelable> viewStates = states.getSparseParcelableArray(getActionViewStatesKey()); 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) { v.restoreHierarchyState(viewStates); } if (item.hasSubMenu()) { final SubMenuBuilder subMenu = (SubMenuBuilder) item.getSubMenu(); subMenu.restoreActionViewStates(states); } } final int expandedId = states.getInt(EXPANDED_ACTION_VIEW_ID); if (expandedId > 0) { MenuItem itemToExpand = findItem(expandedId); if (itemToExpand != null) { MenuItemCompat.expandActionView(itemToExpand); } } }
From source file:org.totschnig.myexpenses.fragment.TransactionList.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final MyExpenses ctx = (MyExpenses) getActivity(); if (mAccount == null) { TextView tv = new TextView(ctx); //noinspection SetTextI18n tv.setText("Error loading transaction list for account " + getArguments().getLong(KEY_ACCOUNTID)); return tv; }// w ww . ja va 2s . co m mManager = getLoaderManager(); //setGrouping(); if (savedInstanceState != null) { mFilter = new WhereFilter(savedInstanceState.getSparseParcelableArray(KEY_FILTER)); } else { restoreFilterFromPreferences(); } View v = inflater.inflate(R.layout.expenses_list, container, false); //TODO check if still needed with Appcompat //work around the problem that the view pager does not display its background correctly with Sherlock if (Build.VERSION.SDK_INT < 11) { v.setBackgroundColor(ctx.getResources() .getColor(PrefKey.UI_THEME_KEY.getString("dark").equals("light") ? android.R.color.white : android.R.color.black)); } mListView = (ExpandableStickyListHeadersListView) v.findViewById(R.id.list); setAdapter(); mListView.setOnHeaderClickListener(this); mListView.setDrawingListUnderStickyHeader(false); if (scheduledRestart) { mManager.restartLoader(TRANSACTION_CURSOR, null, this); mManager.restartLoader(GROUPING_CURSOR, null, this); scheduledRestart = false; } else { mManager.initLoader(GROUPING_CURSOR, null, this); mManager.initLoader(TRANSACTION_CURSOR, null, this); } mManager.initLoader(SUM_CURSOR, null, this); mListView.setEmptyView(v.findViewById(R.id.empty)); mListView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> a, View v, int position, long id) { FragmentManager fm = ctx.getSupportFragmentManager(); DialogFragment f = (DialogFragment) fm.findFragmentByTag(TransactionDetailFragment.class.getName()); if (f == null) { FragmentTransaction ft = fm.beginTransaction(); TransactionDetailFragment.newInstance(id).show(ft, TransactionDetailFragment.class.getName()); } } }); aObserver = new AccountObserver(new Handler()); ContentResolver cr = getActivity().getContentResolver(); //when account has changed, we might have //1) to refresh the list (currency has changed), //2) update current balance(opening balance has changed), //3) update the bottombarcolor (color has changed) //4) refetch grouping cursor (grouping has changed) cr.registerContentObserver(TransactionProvider.ACCOUNTS_URI, true, aObserver); registerForContextualActionBar(mListView.getWrappedList()); return v; }
From source file:de.eidottermihi.rpicheck.activity.MainActivity.java
@Override protected void onRestoreInstanceState(@NonNull Bundle savedInstanceState) { super.onRestoreInstanceState(savedInstanceState); if (savedInstanceState.getSerializable(CURRENT_DEVICE) != null) { LOGGER.debug("Restoring device.."); currentDevice = (RaspberryDeviceBean) savedInstanceState.getSerializable(CURRENT_DEVICE); // restoring tables LOGGER.debug("Setting spinner to show last Pi."); this.getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_LIST); this.getSupportActionBar().setSelectedNavigationItem(currentDevice.getSpinnerPosition()); if (currentDevice.getLastQueryData() != null && currentDevice.getLastQueryData().getException() == null) { LOGGER.debug("Restoring query data.."); this.updateQueryDataInView(currentDevice.getLastQueryData()); } else {//from w w w . jav a2s.c om LOGGER.debug("No last query data present."); this.resetView(); } } if (savedInstanceState.getSparseParcelableArray(ALL_DEVICES) != null) { LOGGER.debug("Restoring all devices."); allDevices = savedInstanceState.getSparseParcelableArray(ALL_DEVICES); } }
From source file:com.mattfred.betterpickers.calendardatepicker.CalendarDatePickerDialogFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { Log.d(TAG, "onCreateView: "); if (getShowsDialog()) { getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE); }// www .j a va2 s . co m View view = inflater.inflate(R.layout.calendar_date_picker_dialog, null); mSelectedDateLayout = (LinearLayout) view.findViewById(R.id.day_picker_selected_date_layout); mDayOfWeekView = (TextView) view.findViewById(R.id.date_picker_header); mMonthAndDayView = (LinearLayout) view.findViewById(R.id.date_picker_month_and_day); mMonthAndDayView.setOnClickListener(this); mSelectedMonthTextView = (TextView) view.findViewById(R.id.date_picker_month); mSelectedDayTextView = (TextView) view.findViewById(R.id.date_picker_day); mYearView = (TextView) view.findViewById(R.id.date_picker_year); mYearView.setOnClickListener(this); int listPosition = -1; int listPositionOffset = 0; int currentView = MONTH_AND_DAY_VIEW; if (savedInstanceState != null) { mWeekStart = savedInstanceState.getInt(KEY_WEEK_START); mMinDate = new CalendarDay(savedInstanceState.getLong(KEY_DATE_START)); mMaxDate = new CalendarDay(savedInstanceState.getLong(KEY_DATE_END)); currentView = savedInstanceState.getInt(KEY_CURRENT_VIEW); listPosition = savedInstanceState.getInt(KEY_LIST_POSITION); listPositionOffset = savedInstanceState.getInt(KEY_LIST_POSITION_OFFSET); mStyleResId = savedInstanceState.getInt(KEY_THEME); mDisabledDays = savedInstanceState.getSparseParcelableArray(KEY_DISABLED_DAYS); } final Activity activity = getActivity(); mDayPickerView = new SimpleDayPickerView(activity, this); mYearPickerView = new YearPickerView(activity, this); Resources res = getResources(); TypedArray themeColors = getActivity().obtainStyledAttributes(mStyleResId, R.styleable.BetterPickersDialog); mDayPickerDescription = res.getString(R.string.day_picker_description); mSelectDay = res.getString(R.string.select_day); mYearPickerDescription = res.getString(R.string.year_picker_description); mSelectYear = res.getString(R.string.select_year); mSelectedColor = themeColors.getColor(R.styleable.BetterPickersDialog_bpAccentColor, R.color.bpBlue); mUnselectedColor = themeColors.getColor(R.styleable.BetterPickersDialog_bpMainTextColor, R.color.numbers_text_color); mAnimator = (AccessibleDateAnimator) view.findViewById(R.id.animator); mAnimator.addView(mDayPickerView); mAnimator.addView(mYearPickerView); mAnimator.setDateMillis(mCalendar.getTimeInMillis()); // TODO: Replace with animation decided upon by the design team. Animation animation = new AlphaAnimation(0.0f, 1.0f); animation.setDuration(ANIMATION_DURATION); mAnimator.setInAnimation(animation); // TODO: Replace with animation decided upon by the design team. Animation animation2 = new AlphaAnimation(1.0f, 0.0f); animation2.setDuration(ANIMATION_DURATION); mAnimator.setOutAnimation(animation2); Button doneButton = (Button) view.findViewById(R.id.done_button); doneButton.setTextColor(mSelectedColor); doneButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { onOkClick(); } }); Button cancelButton = (Button) view.findViewById(R.id.cancel_button); cancelButton.setTextColor(mSelectedColor); cancelButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { tryVibrate(); dismiss(); } }); updateDisplay(false); setCurrentView(currentView); if (listPosition != -1) { if (currentView == MONTH_AND_DAY_VIEW) { mDayPickerView.postSetSelection(listPosition); } else if (currentView == YEAR_VIEW) { mYearPickerView.postSetSelectionFromTop(listPosition, listPositionOffset); } } mHapticFeedbackController = new HapticFeedbackController(activity); int mainColor1 = themeColors.getColor(R.styleable.BetterPickersDialog_bpMainColor1, R.color.bpWhite); int mainColor2 = themeColors.getColor(R.styleable.BetterPickersDialog_bpMainColor2, R.color.circle_background); int backgroundColor = themeColors.getColor(R.styleable.BetterPickersDialog_bpLineColor, R.color.bpWhite); mDayPickerView.setTheme(themeColors); mYearPickerView.setTheme(themeColors); mSelectedDateLayout.setBackgroundColor(mainColor1); mYearView.setBackgroundColor(mainColor1); mMonthAndDayView.setBackgroundColor(mainColor1); view.setBackgroundColor(mainColor2); if (mDayOfWeekView != null) { mDayOfWeekView.setBackgroundColor(backgroundColor); } mYearPickerView.setBackgroundColor(mainColor2); mDayPickerView.setBackgroundColor(mainColor2); return view; }
From source file:com.codetroopers.betterpickers.calendardatepicker.CalendarDatePickerDialogFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { Log.d(TAG, "onCreateView: "); if (getShowsDialog()) { getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE); }/* w ww .ja va 2s . com*/ View view = inflater.inflate(R.layout.calendar_date_picker_dialog, container, false); mSelectedDateLayout = (LinearLayout) view.findViewById(R.id.day_picker_selected_date_layout); mDayOfWeekView = (TextView) view.findViewById(R.id.date_picker_header); mMonthAndDayView = (LinearLayout) view.findViewById(R.id.date_picker_month_and_day); mMonthAndDayView.setOnClickListener(this); mSelectedMonthTextView = (TextView) view.findViewById(R.id.date_picker_month); mSelectedDayTextView = (TextView) view.findViewById(R.id.date_picker_day); mYearView = (TextView) view.findViewById(R.id.date_picker_year); mYearView.setOnClickListener(this); int listPosition = -1; int listPositionOffset = 0; int currentView = MONTH_AND_DAY_VIEW; if (savedInstanceState != null) { mWeekStart = savedInstanceState.getInt(KEY_WEEK_START); mMinDate = new CalendarDay(savedInstanceState.getLong(KEY_DATE_START)); mMaxDate = new CalendarDay(savedInstanceState.getLong(KEY_DATE_END)); currentView = savedInstanceState.getInt(KEY_CURRENT_VIEW); listPosition = savedInstanceState.getInt(KEY_LIST_POSITION); listPositionOffset = savedInstanceState.getInt(KEY_LIST_POSITION_OFFSET); mStyleResId = savedInstanceState.getInt(KEY_THEME); mDisabledDays = savedInstanceState.getSparseParcelableArray(KEY_DISABLED_DAYS); } final Activity activity = getActivity(); mDayPickerView = new SimpleDayPickerView(activity, this); mYearPickerView = new YearPickerView(activity, this); Resources res = getResources(); TypedArray themeColors = getActivity().obtainStyledAttributes(mStyleResId, R.styleable.BetterPickersDialogs); mDayPickerDescription = res.getString(R.string.day_picker_description); mSelectDay = res.getString(R.string.select_day); mYearPickerDescription = res.getString(R.string.year_picker_description); mSelectYear = res.getString(R.string.select_year); int headerBackgroundColor = themeColors.getColor(R.styleable.BetterPickersDialogs_bpHeaderBackgroundColor, ContextCompat.getColor(getActivity(), R.color.bpWhite)); int preHeaderBackgroundColor = themeColors.getColor( R.styleable.BetterPickersDialogs_bpPreHeaderBackgroundColor, ContextCompat.getColor(getActivity(), R.color.bpWhite)); int bodyBgColor = themeColors.getColor(R.styleable.BetterPickersDialogs_bpBodyBackgroundColor, ContextCompat.getColor(getActivity(), R.color.bpWhite)); int buttonBgColor = themeColors.getColor(R.styleable.BetterPickersDialogs_bpButtonsBackgroundColor, ContextCompat.getColor(getActivity(), R.color.bpWhite)); int buttonTextColor = themeColors.getColor(R.styleable.BetterPickersDialogs_bpButtonsTextColor, ContextCompat.getColor(getActivity(), R.color.bpBlue)); mSelectedColor = themeColors.getColor(R.styleable.BetterPickersDialogs_bpHeaderSelectedTextColor, ContextCompat.getColor(getActivity(), R.color.bpWhite)); mUnselectedColor = themeColors.getColor(R.styleable.BetterPickersDialogs_bpHeaderUnselectedTextColor, ContextCompat.getColor(getActivity(), R.color.radial_gray_light)); mAnimator = (AccessibleDateAnimator) view.findViewById(R.id.animator); mAnimator.addView(mDayPickerView); mAnimator.addView(mYearPickerView); mAnimator.setDateMillis(mCalendar.getTimeInMillis()); // TODO: Replace with animation decided upon by the design team. Animation animation = new AlphaAnimation(0.0f, 1.0f); animation.setDuration(ANIMATION_DURATION); mAnimator.setInAnimation(animation); // TODO: Replace with animation decided upon by the design team. Animation animation2 = new AlphaAnimation(1.0f, 0.0f); animation2.setDuration(ANIMATION_DURATION); mAnimator.setOutAnimation(animation2); Button doneButton = (Button) view.findViewById(R.id.done_button); if (mDoneText != null) { doneButton.setText(mDoneText); } doneButton.setTextColor(buttonTextColor); doneButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { tryVibrate(); if (mCallBack != null) { mCallBack.onDateSet(CalendarDatePickerDialogFragment.this, mCalendar.get(Calendar.YEAR), mCalendar.get(Calendar.MONTH), mCalendar.get(Calendar.DAY_OF_MONTH)); } dismiss(); } }); Button cancelButton = (Button) view.findViewById(R.id.cancel_button); if (mCancelText != null) { cancelButton.setText(mCancelText); } cancelButton.setTextColor(buttonTextColor); cancelButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { tryVibrate(); dismiss(); } }); view.findViewById(R.id.ok_cancel_buttons_layout).setBackgroundColor(buttonBgColor); updateDisplay(false); setCurrentView(currentView); if (listPosition != -1) { if (currentView == MONTH_AND_DAY_VIEW) { mDayPickerView.postSetSelection(listPosition); } else if (currentView == YEAR_VIEW) { mYearPickerView.postSetSelectionFromTop(listPosition, listPositionOffset); } } mHapticFeedbackController = new HapticFeedbackController(activity); mDayPickerView.setTheme(themeColors); mYearPickerView.setTheme(themeColors); mSelectedDateLayout.setBackgroundColor(headerBackgroundColor); mYearView.setBackgroundColor(headerBackgroundColor); mMonthAndDayView.setBackgroundColor(headerBackgroundColor); if (mDayOfWeekView != null) { mDayOfWeekView.setBackgroundColor(preHeaderBackgroundColor); } view.setBackgroundColor(bodyBgColor); mYearPickerView.setBackgroundColor(bodyBgColor); mDayPickerView.setBackgroundColor(bodyBgColor); return view; }