Java Code Examples for android.os.Parcelable

The following examples show how to use android.os.Parcelable. These examples are extracted from open source projects. 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
@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 2
@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 3
Source Project: AppUpdate   Source File: NumberProgressBar.java    License: 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 4
Source Project: VideoMeeting   Source File: ViewUtils.java    License: 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 5
Source Project: android-apps   Source File: MenuBuilder.java    License: 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 6
/**
 * 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 7
Source Project: sketch   Source File: GifTextView.java    License: 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 8
Source Project: cathode   Source File: WatchingView.java    License: 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 9
Source Project: FireFiles   Source File: NumberProgressBar.java    License: 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 10
Source Project: material-components-android   Source File: AppBarLayout.java    License: 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 11
Source Project: arcgis-runtime-demos-android   Source File: MainActivity.java    License: 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 12
Source Project: spotify-web-api-android   Source File: ParcelableModelsTest.java    License: 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 13
Source Project: SwipeRevealLayoutExample   Source File: SwipeRevealLayout.java    License: MIT License 5 votes vote down vote up
@Nullable
@Override
protected Parcelable onSaveInstanceState() {
    Bundle bundle = new Bundle();
    bundle.putParcelable(SUPER_INSTANCE_STATE, super.onSaveInstanceState());
    return super.onSaveInstanceState();
}
 
Example 14
Source Project: Libraries-for-Android-Developers   Source File: IcsProgressBar.java    License: 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 15
Source Project: MyBookshelf   Source File: RefreshLayout.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onRestoreInstanceState(Parcelable state) {
    SavedState savedState = (SavedState) state;
    super.onRestoreInstanceState(savedState.getSuperState());
    //刷新状态
    toggleStatus(savedState.status);
}
 
Example 16
public EntryState(int formulaId, FormulaBase.BaseType type, Parcelable data)
{
    super();
    this.formulaId = formulaId;
    this.type = type;
    this.data = data;
}
 
Example 17
Source Project: persistentsearchview   Source File: StateUtils.java    License: Apache License 2.0 5 votes vote down vote up
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;
    }
}
 
Example 18
Source Project: mv2m   Source File: ParcelableTester.java    License: Apache License 2.0 5 votes vote down vote up
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());
        }
    }
}
 
Example 19
Source Project: InfiniteViewPager   Source File: LinePageIndicator.java    License: MIT License 5 votes vote down vote up
@Override
public void onRestoreInstanceState(Parcelable state) {
    SavedState savedState = (SavedState)state;
    super.onRestoreInstanceState(savedState.getSuperState());
    mCurrentPage = savedState.currentPage;
    requestLayout();
}
 
Example 20
Source Project: monolog-android   Source File: UnderlinePageIndicator.java    License: MIT License 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 21
Source Project: Klyph   Source File: UnderlinePageIndicator.java    License: MIT License 5 votes vote down vote up
@Override
public void onRestoreInstanceState(Parcelable state) {
    SavedState savedState = (SavedState)state;
    super.onRestoreInstanceState(savedState.getSuperState());
    mCurrentPage = savedState.currentPage;
    requestLayout();
}
 
Example 22
Source Project: EhViewer   Source File: CheckTextView.java    License: Apache License 2.0 5 votes vote down vote up
@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);
    }
}
 
Example 23
Source Project: ColorPicker   Source File: ColorPickerView.java    License: Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example 24
Source Project: fab-speed-dial   Source File: FabSpeedDial.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected Parcelable onSaveInstanceState() {
    Parcelable superState = super.onSaveInstanceState();
    SavedState ss = new SavedState(superState);

    ss.isShowingMenu = isMenuOpen();

    return ss;
}
 
Example 25
@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);
}
 
Example 26
Source Project: ScaleLayout   Source File: ScaleLayout.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 存储当前状态
 * @return
 */
@Override
public Parcelable onSaveInstanceState() {
    Bundle bundle = new Bundle();
    bundle.putParcelable("superState", super.onSaveInstanceState());
    bundle.putSerializable(TAG, mState);
    return bundle;
}
 
Example 27
Source Project: RecyclerBanner   Source File: BannerLayoutManager.java    License: Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example 28
Source Project: PhotoEdit   Source File: SVBar.java    License: Apache License 2.0 5 votes vote down vote up
@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));
    }
}
 
Example 29
Source Project: commcare-android   Source File: EntityDetailFragment.java    License: Apache License 2.0 5 votes vote down vote up
@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!");
    }
}
 
Example 30
Source Project: moviedb-android   Source File: ObservableGridView.java    License: Apache License 2.0 5 votes vote down vote up
@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;
}