android.os.Parcelable Java Examples

The following examples show how to use android.os.Parcelable. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MenuBuilder.java    From android-apps with MIT License 6 votes vote down vote up
private void dispatchSaveInstanceState(Bundle outState) {
    if (mPresenters.isEmpty()) return;

    SparseArray<Parcelable> presenterStates = new SparseArray<Parcelable>();

    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) {
                final Parcelable state = presenter.onSaveInstanceState();
                if (state != null) {
                    presenterStates.put(id, state);
                }
            }
        }
    }

    outState.putSparseParcelableArray(PRESENTER_KEY, presenterStates);
}
 
Example #2
Source File: AppBarLayout.java    From material-components-android with Apache License 2.0 6 votes vote down vote up
@Override
public Parcelable onSaveInstanceState(@NonNull CoordinatorLayout parent, @NonNull T abl) {
  final Parcelable superState = super.onSaveInstanceState(parent, abl);
  final int offset = getTopAndBottomOffset();

  // Try and find the first visible child...
  for (int i = 0, count = abl.getChildCount(); i < count; i++) {
    View child = abl.getChildAt(i);
    final int visBottom = child.getBottom() + offset;

    if (child.getTop() + offset <= 0 && visBottom >= 0) {
      final SavedState ss = new SavedState(superState);
      ss.firstVisibleChildIndex = i;
      ss.firstVisibleChildAtMinimumHeight =
          visBottom == (ViewCompat.getMinimumHeight(child) + abl.getTopInset());
      ss.firstVisibleChildPercentageShown = visBottom / (float) child.getHeight();
      return ss;
    }
  }

  // Else we'll just return the super state
  return superState;
}
 
Example #3
Source File: NumberProgressBar.java    From FireFiles with Apache License 2.0 6 votes vote down vote up
@Override
protected void onRestoreInstanceState(Parcelable state) {
    if(state instanceof Bundle){
        final Bundle bundle = (Bundle)state;
        mTextColor = bundle.getInt(INSTANCE_TEXT_COLOR);
        mTextSize = bundle.getFloat(INSTANCE_TEXT_SIZE);
        mReachedBarHeight = bundle.getFloat(INSTANCE_REACHED_BAR_HEIGHT);
        mUnreachedBarHeight = bundle.getFloat(INSTANCE_UNREACHED_BAR_HEIGHT);
        mReachedBarColor = bundle.getInt(INSTANCE_REACHED_BAR_COLOR);
        mUnreachedBarColor = bundle.getInt(INSTANCE_UNREACHED_BAR_COLOR);
        initializePainters();
        setMax(bundle.getInt(INSTANCE_MAX));
        setProgress(bundle.getInt(INSTANCE_PROGRESS));
        setPrefix(bundle.getString(INSTANCE_PREFIX));
        setSuffix(bundle.getString(INSTANCE_SUFFIX));
        setProgressTextVisibility(bundle.getBoolean(INSTANCE_TEXT_VISBILITY) ? ProgressTextVisibility.Visible : ProgressTextVisibility.Invisible);
        super.onRestoreInstanceState(bundle.getParcelable(INSTANCE_STATE));
        return;
    }
    super.onRestoreInstanceState(state);
}
 
Example #4
Source File: CustomColorDialogPreferenceX.java    From PhoneProfilesPlus with Apache License 2.0 6 votes vote down vote up
@Override
protected void onRestoreInstanceState(Parcelable state)
{
    if (!state.getClass().equals(SavedState.class)) {
        // Didn't save state for us in onSaveInstanceState
        super.onRestoreInstanceState(state);
        int value = this.value;
        if (fragment != null)
            fragment.chromaColorView.setCurrentColor(value);
        setSummaryCCDP(value);
        return;
    }

    // restore instance state
    CustomColorDialogPreferenceX.SavedState myState = (CustomColorDialogPreferenceX.SavedState)state;
    super.onRestoreInstanceState(myState.getSuperState());
    value = myState.value;
    defaultValue = myState.defaultValue;

    if (fragment != null)
        fragment.chromaColorView.setCurrentColor(value);
    setSummaryCCDP(value);
}
 
Example #5
Source File: MainActivity.java    From arcgis-runtime-demos-android with Apache License 2.0 6 votes vote down vote up
@Override
public boolean dispatchTouchEvent(@NonNull MotionEvent event) {
  boolean wasLongPress = mGestureDetector.onTouchEvent(event);
  if(!wasLongPress) {
    Log.i("test", "not a long press");
    if(!mDismissOverlayView.isShown()) {
      Parcel p = Parcel.obtain();
      event.writeToParcel(p, Parcelable.PARCELABLE_WRITE_RETURN_VALUE);
      sendEvent(p.marshall());
    } else {
      return super.dispatchTouchEvent(event);
    }
  } else {
    Log.i("test", "long press");
  }
  return true;
}
 
Example #6
Source File: ParcelableModelsTest.java    From spotify-web-api-android with MIT License 6 votes vote down vote up
@Test
public void allParcelables() throws IllegalAccessException, InstantiationException, NoSuchFieldException {

    ModelPopulator populator = new ModelPopulator("CREATOR", "$jacocoData");

    for (Class<? extends Parcelable> modelClass : getModelClasses()) {

        Parcelable instance = populator.populateWithRandomValues(modelClass);

        testSingleParcelable(instance);
        testParcelableArray(instance);

        /* Trick to increase code coverage */
        instance.describeContents();
        ((Parcelable.Creator<?>) modelClass.getField("CREATOR").get(null)).newArray(13);
    }
}
 
Example #7
Source File: ReadBottomStatusBar.java    From HaoReader with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void onRestoreInstanceState(Parcelable state) {
    Bundle bundle = (Bundle) state;
    showTimeBattery = bundle.getBoolean("showTimeBattery");
    batteryLevel = bundle.getInt("batteryLevel", batteryLevel);
    durChapterName = bundle.getString("durChapterName");
    durPage = bundle.getInt("durPage");
    pageSize = bundle.getInt("pageSize");
    durChapter = bundle.getInt("durChapter");
    chapterSize = bundle.getInt("chapterSize");
    super.onRestoreInstanceState(bundle.getParcelable("super_data"));

    updateTime();
    setShowTimeBattery(showTimeBattery);
    updatePageIndex(durChapterName, durPage, pageSize);
    updateChapterIndex(durChapter, chapterSize);
}
 
Example #8
Source File: NumberProgressBar.java    From AppUpdate with Apache License 2.0 6 votes vote down vote up
@Override
protected Parcelable onSaveInstanceState() {
    final Bundle bundle = new Bundle();
    bundle.putParcelable(INSTANCE_STATE, super.onSaveInstanceState());
    bundle.putInt(INSTANCE_TEXT_COLOR, getTextColor());
    bundle.putFloat(INSTANCE_TEXT_SIZE, getProgressTextSize());
    bundle.putFloat(INSTANCE_REACHED_BAR_HEIGHT, getReachedBarHeight());
    bundle.putFloat(INSTANCE_UNREACHED_BAR_HEIGHT, getUnreachedBarHeight());
    bundle.putInt(INSTANCE_REACHED_BAR_COLOR, getReachedBarColor());
    bundle.putInt(INSTANCE_UNREACHED_BAR_COLOR, getUnreachedBarColor());
    bundle.putInt(INSTANCE_MAX, getMax());
    bundle.putInt(INSTANCE_PROGRESS, getProgress());
    bundle.putString(INSTANCE_SUFFIX, getSuffix());
    bundle.putString(INSTANCE_PREFIX, getPrefix());
    bundle.putBoolean(INSTANCE_TEXT_VISIBILITY, getProgressTextVisibility());
    return bundle;
}
 
Example #9
Source File: ViewUtils.java    From VideoMeeting with Apache License 2.0 6 votes vote down vote up
/**
 * 创建快捷方式
 * 
 * @param cxt
 *            Context
 * @param icon
 *            快捷方式图标
 * @param title
 *            快捷方式标题
 * @param cls
 *            要启动的Activity类
 */
public static void createDeskShortCut(Context cxt, int icon, String title,
        Class<?> cls) {
    // 创建快捷方式的Intent
    Intent shortcutIntent = new Intent(
            "com.android.launcher.action.INSTALL_SHORTCUT");
    // 不允许重复创建
    shortcutIntent.putExtra("duplicate", false);
    // 需要现实的名称
    shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, title);
    // 快捷图片
    Parcelable ico = Intent.ShortcutIconResource.fromContext(
            cxt.getApplicationContext(), icon);
    shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, ico);
    Intent intent = new Intent(cxt, cls);
    // 下面两个属性是为了当应用程序卸载时桌面上的快捷方式会删除
    intent.setAction("android.intent.action.MAIN");
    intent.addCategory("android.intent.category.LAUNCHER");
    // 点击快捷图片,运行的程序主入口
    shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, intent);
    // 发送广播。OK
    cxt.sendBroadcast(shortcutIntent);
}
 
Example #10
Source File: WatchingView.java    From cathode with Apache License 2.0 6 votes vote down vote up
@Override protected Parcelable onSaveInstanceState() {
  Parcelable superState = super.onSaveInstanceState();
  SavedState state = new SavedState(superState);

  state.type = type;
  state.showId = showId;
  state.showTitle = showTitle;
  state.episodeId = episodeId;
  state.episodeTitle = episodeTitle;
  state.movieId = movieId;
  state.movieTitle = movieTitle;
  state.movieOverview = movieOverview;
  state.poster = poster;
  state.startTime = startTime;
  state.endTime = endTime;
  state.startTime = startTime;
  state.endTime = endTime;
  state.isExpanded = isExpanded();

  return state;
}
 
Example #11
Source File: GifTextView.java    From sketch with Apache License 2.0 6 votes vote down vote up
@Override
public void onRestoreInstanceState(Parcelable state) {
	if (!(state instanceof GifViewSavedState)) {
		super.onRestoreInstanceState(state);
		return;
	}
	GifViewSavedState ss = (GifViewSavedState) state;
	super.onRestoreInstanceState(ss.getSuperState());

	Drawable[] compoundDrawables = getCompoundDrawables();
	ss.restoreState(compoundDrawables[0], 0);
	ss.restoreState(compoundDrawables[1], 1);
	ss.restoreState(compoundDrawables[2], 2);
	ss.restoreState(compoundDrawables[3], 3);
	if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
		Drawable[] compoundDrawablesRelative = getCompoundDrawablesRelative();
		ss.restoreState(compoundDrawablesRelative[0], 4);
		ss.restoreState(compoundDrawablesRelative[2], 5);
	}
	ss.restoreState(getBackground(), 6);
}
 
Example #12
Source File: FormulaResult.java    From microMathematics with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Parcelable interface: procedure reads the formula state
 */
@Override
public void onRestoreInstanceState(Parcelable state)
{
    if (state == null)
    {
        return;
    }
    if (state instanceof Bundle)
    {
        Bundle bundle = (Bundle) state;
        properties.assign((ResultProperties) bundle.getParcelable(STATE_RESULT_PROPERTIES));
        super.onRestoreInstanceState(bundle);
        updateResultView(false);
    }
}
 
Example #13
Source File: AbsSpinner.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public Parcelable onSaveInstanceState() {
    Parcelable superState = super.onSaveInstanceState();
    SavedState ss = new SavedState(superState);
    ss.selectedId = getSelectedItemId();
    if (ss.selectedId >= 0) {
        ss.position = getSelectedItemPosition();
    } else {
        ss.position = INVALID_POSITION;
    }
    return ss;
}
 
Example #14
Source File: ColorWheelView.java    From SimpleDialogFragments with Apache License 2.0 5 votes vote down vote up
@Override
public void onRestoreInstanceState(Parcelable state) {
    if(!(state instanceof SavedState)) {
        super.onRestoreInstanceState(state);
        return;
    }
    SavedState ss = (SavedState)state;
    super.onRestoreInstanceState(ss.getSuperState());

    myColor = new C(ss.saveAlpha, (int) ss.saveColor[0], ss.saveColor[1], ss.saveColor[2]);
}
 
Example #15
Source File: IcsProgressBar.java    From Libraries-for-Android-Developers with MIT License 5 votes vote down vote up
@Override
public Parcelable onSaveInstanceState() {
    // Force our ancestor class to save its state
    Parcelable superState = super.onSaveInstanceState();
    SavedState ss = new SavedState(superState);

    ss.progress = mProgress;
    ss.secondaryProgress = mSecondaryProgress;

    return ss;
}
 
Example #16
Source File: LocationService.java    From PokeFaker with MIT License 5 votes vote down vote up
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    mIntent = intent;
    Parcelable p = intent.getParcelableExtra("position");
    if (p != null) {
        mCurrentLatLng = ((LatLng) p);
        updateLocation();
    }
    return super.onStartCommand(intent, flags, startId);
}
 
Example #17
Source File: FloatLabel.java    From AndroidFloatLabel with Apache License 2.0 5 votes vote down vote up
@Override
protected Parcelable onSaveInstanceState() {
    final Parcelable superState = super.onSaveInstanceState();
    final Bundle saveState = new Bundle();
    saveState.putParcelable(SAVE_STATE_KEY_EDIT_TEXT, mEditText.onSaveInstanceState());
    saveState.putParcelable(SAVE_STATE_KEY_LABEL, mLabel.onSaveInstanceState());
    saveState.putBoolean(SAVE_STATE_KEY_FOCUS, mEditText.isFocused());
    saveState.putBoolean(SAVE_STATE_TAG, true);
    saveState.putParcelable(SAVE_STATE_PARENT, superState);

    return saveState;
}
 
Example #18
Source File: RangeSliderViewEx.java    From AndroidReview with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Parcelable onSaveInstanceState() {
    Parcelable superState = super.onSaveInstanceState();
    SavedState ss = new SavedState(superState);
    ss.saveIndex = this.currentIndex;
    return ss;
}
 
Example #19
Source File: MarqueeTextView.java    From BigApp_Discuz_Android with Apache License 2.0 5 votes vote down vote up
@Override
public Parcelable onSaveInstanceState() {
	Parcelable superState = super.onSaveInstanceState();
	SavedState ss = new SavedState(superState);

	ss.step = step;
	ss.isStarting = isStarting;

	return ss;

}
 
Example #20
Source File: GradientIconView.java    From AndroidGradientUI with Apache License 2.0 5 votes vote down vote up
@Override
protected Parcelable onSaveInstanceState() {
    Bundle bundle = new Bundle();
    bundle.putParcelable(INSTANCE_STATE, super.onSaveInstanceState());
    bundle.putFloat(STATE_ALPHA, mAlpha);
    return bundle;
}
 
Example #21
Source File: FloatingActionsMenu.java    From TestChat with Apache License 2.0 5 votes vote down vote up
@Override
public Parcelable onSaveInstanceState() {
        Parcelable superState = super.onSaveInstanceState();
        SavedState savedState = new SavedState(superState);
        savedState.mExpanded = mExpanded;

        return savedState;
}
 
Example #22
Source File: StickyGridHeadersGridView.java    From StickyGridHeaders with Apache License 2.0 5 votes vote down vote up
@Override
public Parcelable onSaveInstanceState() {
    Parcelable superState = super.onSaveInstanceState();

    SavedState ss = new SavedState(superState);
    ss.areHeadersSticky = mAreHeadersSticky;
    return ss;
}
 
Example #23
Source File: DrawerLayout.java    From android-recipes-app with Apache License 2.0 5 votes vote down vote up
@Override
protected void onRestoreInstanceState(Parcelable state) {
    final SavedState ss = (SavedState) state;
    super.onRestoreInstanceState(ss.getSuperState());

    if (ss.openDrawerGravity != Gravity.NO_GRAVITY) {
        final View toOpen = findDrawerWithGravity(ss.openDrawerGravity);
        if (toOpen != null) {
            openDrawer(toOpen);
        }
    }

    setDrawerLockMode(ss.lockModeLeft, Gravity.LEFT);
    setDrawerLockMode(ss.lockModeRight, Gravity.RIGHT);
}
 
Example #24
Source File: LinePageIndicator.java    From Huochexing12306 with Apache License 2.0 5 votes vote down vote up
@Override
public Parcelable onSaveInstanceState() {
    Parcelable superState = super.onSaveInstanceState();
    SavedState savedState = new SavedState(superState);
    savedState.currentPage = mCurrentPage;
    return savedState;
}
 
Example #25
Source File: ScrollableLayout.java    From Scrollable with Apache License 2.0 5 votes vote down vote up
@Override
public Parcelable onSaveInstanceState() {
	final Parcelable superState = super.onSaveInstanceState();
	final ScrollableLayoutSavedState savedState = new ScrollableLayoutSavedState(superState);

    savedState.scrollY = getScrollY();
    savedState.autoMaxScroll = mAutoMaxScroll;

	return savedState;
}
 
Example #26
Source File: LockPatternView.java    From android-lockpattern with Apache License 2.0 5 votes vote down vote up
/**
 * Constructor called from {@link LockPatternView#onSaveInstanceState()}
 */
private SavedState(Parcelable superState, String serializedPattern,
        int displayMode, boolean inputEnabled, boolean inStealthMode,
        boolean tactileFeedbackEnabled) {
    super(superState);
    mSerializedPattern = serializedPattern;
    mDisplayMode = displayMode;
    mInputEnabled = inputEnabled;
    mInStealthMode = inStealthMode;
    mTactileFeedbackEnabled = tactileFeedbackEnabled;
}
 
Example #27
Source File: SlidingUpPanel.java    From Android-SlidingUpPanel with MIT License 5 votes vote down vote up
@Override
public void onRestoreInstanceState(Parcelable state) {
	SavedState savedState = (SavedState) state;
	super.onRestoreInstanceState(savedState.getSuperState());
	mIsOpen = savedState.isOpen;
	requestLayout();
}
 
Example #28
Source File: CustomFragmentStatePagerAdapter.java    From Music-Player with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void restoreState(Parcelable state, ClassLoader loader) {
    if (state != null) {
        Bundle bundle = (Bundle) state;
        bundle.setClassLoader(loader);
        Parcelable[] fss = bundle.getParcelableArray("states");
        mSavedState.clear();
        mFragments.clear();
        if (fss != null) {
            for (Parcelable fs : fss) {
                mSavedState.add((Fragment.SavedState) fs);
            }
        }
        Iterable<String> keys = bundle.keySet();
        for (String key : keys) {
            if (key.startsWith("f")) {
                int index = Integer.parseInt(key.substring(1));
                Fragment f = mFragmentManager.getFragment(bundle, key);
                if (f != null) {
                    while (mFragments.size() <= index) {
                        mFragments.add(null);
                    }
                    f.setMenuVisibility(false);
                    mFragments.set(index, f);
                } else {
                    Log.w(TAG, "Bad fragment at key " + key);
                }
            }
        }
    }
}
 
Example #29
Source File: PaymentTypesActivity.java    From px-android with MIT License 5 votes vote down vote up
@Override
public void finishWithResult(PaymentType paymentType) {
    Intent returnIntent = new Intent();
    returnIntent.putExtra(EXTRA_PAYMENT_TYPE, (Parcelable) paymentType);
    setResult(RESULT_OK, returnIntent);
    finish();
    overridePendingTransition(R.anim.px_hold, R.anim.px_hold);
}
 
Example #30
Source File: ToDayView.java    From ToDay with MIT License 5 votes vote down vote up
@Override
protected Parcelable onSaveInstanceState() {
    Bundle outState = new Bundle();
    outState.putParcelable(STATE_VIEW, super.onSaveInstanceState());
    if (mAdapter != null) {
        outState.putBundle(STATE_ADAPTER, mAdapter.saveState());
    }
    return outState;
}