类android.os.Parcelable源码实例Demo

下面列出了怎么用android.os.Parcelable的API类实例代码及写法,或者点击链接到github查看源代码。

@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);
}
 
源代码2 项目: HaoReader   文件: ReadBottomStatusBar.java
@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);
}
 
源代码3 项目: AppUpdate   文件: NumberProgressBar.java
@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;
}
 
源代码4 项目: VideoMeeting   文件: ViewUtils.java
/**
 * 创建快捷方式
 * 
 * @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);
}
 
源代码5 项目: android-apps   文件: MenuBuilder.java
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);
}
 
源代码6 项目: microMathematics   文件: FormulaResult.java
/**
 * 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);
    }
}
 
源代码7 项目: sketch   文件: GifTextView.java
@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);
}
 
源代码8 项目: cathode   文件: WatchingView.java
@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;
}
 
源代码9 项目: FireFiles   文件: NumberProgressBar.java
@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);
}
 
源代码10 项目: material-components-android   文件: AppBarLayout.java
@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;
}
 
@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;
}
 
@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);
    }
}
 
@Nullable
@Override
protected Parcelable onSaveInstanceState() {
    Bundle bundle = new Bundle();
    bundle.putParcelable(SUPER_INSTANCE_STATE, super.onSaveInstanceState());
    return super.onSaveInstanceState();
}
 
@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;
}
 
源代码15 项目: MyBookshelf   文件: RefreshLayout.java
@Override
protected void onRestoreInstanceState(Parcelable state) {
    SavedState savedState = (SavedState) state;
    super.onRestoreInstanceState(savedState.getSuperState());
    //刷新状态
    toggleStatus(savedState.status);
}
 
源代码16 项目: microMathematics   文件: ReplaceState.java
public EntryState(int formulaId, FormulaBase.BaseType type, Parcelable data)
{
    super();
    this.formulaId = formulaId;
    this.type = type;
    this.data = data;
}
 
源代码17 项目: persistentsearchview   文件: StateUtils.java
public static Parcelable fetchParentState(Parcelable state) {
    if(state == null) {
        return null;
    }

    if(Utils.IS_AT_LEAST_MARSHMALLOW) {
        return state;
    } else {
        return View.BaseSavedState.EMPTY_STATE;
    }
}
 
源代码18 项目: mv2m   文件: ParcelableTester.java
private static void writeList(LinkedList<Object> parcelData, InvocationOnMock invocation, List<Parcelable> list) {
    if (list == null) {
        parcelData.add(-1);
    } else {
        parcelData.add(list.size());
        for (Parcelable item : list) {
            writeParcelable(parcelData, item, (Parcel) invocation.getMock());
        }
    }
}
 
源代码19 项目: InfiniteViewPager   文件: LinePageIndicator.java
@Override
public void onRestoreInstanceState(Parcelable state) {
    SavedState savedState = (SavedState)state;
    super.onRestoreInstanceState(savedState.getSuperState());
    mCurrentPage = savedState.currentPage;
    requestLayout();
}
 
源代码20 项目: monolog-android   文件: UnderlinePageIndicator.java
@Override
public Parcelable onSaveInstanceState() {
    Parcelable superState = super.onSaveInstanceState();
    SavedState savedState = new SavedState(superState);
    savedState.currentPage = mCurrentPage;
    return savedState;
}
 
源代码21 项目: Klyph   文件: UnderlinePageIndicator.java
@Override
public void onRestoreInstanceState(Parcelable state) {
    SavedState savedState = (SavedState)state;
    super.onRestoreInstanceState(savedState.getSuperState());
    mCurrentPage = savedState.currentPage;
    requestLayout();
}
 
源代码22 项目: EhViewer   文件: CheckTextView.java
@Override
public void onRestoreInstanceState(Parcelable state) {
    if (state instanceof Bundle) {
        final Bundle savedState = (Bundle) state;
        super.onRestoreInstanceState(savedState.getParcelable(STATE_KEY_SUPER));
        setChecked(savedState.getBoolean(STATE_KEY_CHECKED), false);
    }
}
 
源代码23 项目: ColorPicker   文件: ColorPickerView.java
@Override
protected Parcelable onSaveInstanceState() {
    Parcelable parcelable = super.onSaveInstanceState();
    SavedState ss = new SavedState(parcelable);
    ss.selX = curX;
    ss.selY = curY;
    ss.color = bitmapForColor;
    if (mIndicatorEnable) {
        ss.indicator = bitmapForIndicator;
    }
    return ss;
}
 
源代码24 项目: fab-speed-dial   文件: FabSpeedDial.java
@Override
protected Parcelable onSaveInstanceState() {
    Parcelable superState = super.onSaveInstanceState();
    SavedState ss = new SavedState(superState);

    ss.isShowingMenu = isMenuOpen();

    return ss;
}
 
源代码25 项目: screenrecorder   文件: FolderChooser.java
@Override
protected Parcelable onSaveInstanceState() {
    Parcelable superState = super.onSaveInstanceState();
    if (currentDir == null) return superState;
    Bundle dialogState = dialog == null ? null : dialog.onSaveInstanceState();
    return new SavedStateHandler(superState, currentDir.getPath(), dialogState);
}
 
源代码26 项目: ScaleLayout   文件: ScaleLayout.java
/**
 * 存储当前状态
 * @return
 */
@Override
public Parcelable onSaveInstanceState() {
    Bundle bundle = new Bundle();
    bundle.putParcelable("superState", super.onSaveInstanceState());
    bundle.putSerializable(TAG, mState);
    return bundle;
}
 
源代码27 项目: RecyclerBanner   文件: BannerLayoutManager.java
@Override
public Parcelable onSaveInstanceState() {
    if (mPendingSavedState != null) {
        return new SavedState(mPendingSavedState);
    }
    SavedState savedState = new SavedState();
    savedState.position = mPendingScrollPosition;
    savedState.offset = mOffset;
    savedState.isReverseLayout = mShouldReverseLayout;
    return savedState;
}
 
源代码28 项目: PhotoEdit   文件: SVBar.java
@Override
protected void onRestoreInstanceState(Parcelable state) {
    Bundle savedState = (Bundle) state;

    Parcelable superState = savedState.getParcelable(STATE_PARENT);
    super.onRestoreInstanceState(superState);

    setColor(Color.HSVToColor(savedState.getFloatArray(STATE_COLOR)));
    if (savedState.containsKey(STATE_SATURATION)) {
        setSaturation(savedState.getFloat(STATE_SATURATION));
    } else {
        setValue(savedState.getFloat(STATE_VALUE));
    }
}
 
源代码29 项目: commcare-android   文件: EntityDetailFragment.java
@Override
public void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    if (modifier instanceof Parcelable) {
        outState.putParcelable(MODIFIER_KEY, (Parcelable)modifier);
    } else {
        throw new IllegalArgumentException(modifier + " must implement Parcelable!");
    }
}
 
源代码30 项目: moviedb-android   文件: ObservableGridView.java
@Override
public Parcelable onSaveInstanceState() {
    Parcelable superState = super.onSaveInstanceState();
    SavedState ss = new SavedState(superState);
    ss.prevFirstVisiblePosition = mPrevFirstVisiblePosition;
    ss.prevFirstVisibleChildHeight = mPrevFirstVisibleChildHeight;
    ss.prevScrolledChildrenHeight = mPrevScrolledChildrenHeight;
    ss.prevScrollY = mPrevScrollY;
    ss.scrollY = mScrollY;
    ss.childrenHeights = mChildrenHeights;
    return ss;
}
 
 类所在包
 同包方法