android.os.Bundle#getParcelable ( )源码实例Demo

下面列出了android.os.Bundle#getParcelable ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

/**
 * If the passed in state is a Bundle, an attempt is made to restore from it.
 * @param state a Parcelable containing the current state
 */
@Override
protected void onRestoreInstanceState(Parcelable state) {
    if (state.getClass() != Bundle.class) {
        super.onRestoreInstanceState(state);
    } else {
        Bundle instanceState = (Bundle)state;
        super.onRestoreInstanceState(instanceState.getParcelable(SUPER_STATE_KEY));

        profileId = instanceState.getString(PROFILE_ID_KEY);
        presetSizeType = instanceState.getInt(PRESET_SIZE_KEY);
        isCropped = instanceState.getBoolean(IS_CROPPED_KEY);
        queryWidth = instanceState.getInt(BITMAP_WIDTH_KEY);
        queryHeight = instanceState.getInt(BITMAP_HEIGHT_KEY);

        setImageBitmap((Bitmap)instanceState.getParcelable(BITMAP_KEY));

        if (instanceState.getBoolean(PENDING_REFRESH_KEY)) {
            refreshImage(true);
        }
    }
}
 
源代码2 项目: ud867   文件: ClickFragment.java
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_click, container, false);

    if (null != savedInstanceState) {
        mClickCounter = savedInstanceState.getParcelable(CLICK_COUNT_TAG);
    } else {
        mClickCounter = new ClickCounter();
    }

    mTextView = (TextView) rootView.findViewById(R.id.click_count_text_view);
    displayClickCount();
    Button button = (Button) rootView.findViewById(R.id.click_button);
    button.setOnClickListener(mListener);
    return rootView;
}
 
源代码3 项目: SimplifyReader   文件: AndroidAuthenticator.java
@SuppressWarnings("deprecation")
@Override
public String getAuthToken() throws AuthFailureError {
    AccountManagerFuture<Bundle> future = mAccountManager.getAuthToken(mAccount,
            mAuthTokenType, mNotifyAuthFailure, null, null);
    Bundle result;
    try {
        result = future.getResult();
    } catch (Exception e) {
        throw new AuthFailureError("Error while retrieving auth token", e);
    }
    String authToken = null;
    if (future.isDone() && !future.isCancelled()) {
        if (result.containsKey(AccountManager.KEY_INTENT)) {
            Intent intent = result.getParcelable(AccountManager.KEY_INTENT);
            throw new AuthFailureError(intent);
        }
        authToken = result.getString(AccountManager.KEY_AUTHTOKEN);
    }
    if (authToken == null) {
        throw new AuthFailureError("Got null auth token for type: " + mAuthTokenType);
    }

    return authToken;
}
 
源代码4 项目: octoandroid   文件: ConnectionFragment.java
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_connection, container, false);
    setUnbinder(ButterKnife.bind(this, view));
    setActionBarTitle("Status");
    mRefreshLayout.setOnRefreshListener(this);

    // ProgressBar doesn't show on top of CardView in Lollipop+ builds
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        mConnectProgressBar.setTranslationZ(mProgressZTranslation);
    }

    if (savedInstanceState != null && savedInstanceState.getParcelable(CONNECT_MODEL_KEY) != null) {
        mConnectModel = savedInstanceState.getParcelable(CONNECT_MODEL_KEY);
        updateUi(mConnectModel);
    }

    setEnableInputViews(false);
    return view;
}
 
@Override
protected final void onRestoreInstanceState(Parcelable state) {
	if (state instanceof Bundle) {
		Bundle bundle = (Bundle) state;

		setMode(Mode.mapIntToValue(bundle.getInt(STATE_MODE, 0)));
		mCurrentMode = Mode.mapIntToValue(bundle.getInt(STATE_CURRENT_MODE, 0));

		mScrollingWhileRefreshingEnabled = bundle.getBoolean(STATE_SCROLLING_REFRESHING_ENABLED, false);
		mShowViewWhileRefreshing = bundle.getBoolean(STATE_SHOW_REFRESHING_VIEW, true);

		// Let super Restore Itself
		super.onRestoreInstanceState(bundle.getParcelable(STATE_SUPER));

		State viewState = State.mapIntToValue(bundle.getInt(STATE_STATE, 0));
		if (viewState == State.REFRESHING || viewState == State.MANUAL_REFRESHING) {
			setState(viewState, true);
		}

		// Now let derivative classes restore their state
		onPtrRestoreInstanceState(bundle);
		return;
	}

	super.onRestoreInstanceState(state);
}
 
源代码6 项目: OmniList   文件: CircularSeekBar.java
@Override
protected void onRestoreInstanceState(Parcelable state) {
    Bundle savedState = (Bundle) state;

    Parcelable superState = savedState.getParcelable("PARENT");
    super.onRestoreInstanceState(superState);

    mMax = savedState.getInt("MAX");
    mProgress = savedState.getInt("PROGRESS");
    mCircleColor = savedState.getInt("mCircleColor");
    mCircleProgressColor = savedState.getInt("mCircleProgressColor");
    mPointerColor = savedState.getInt("mPointerColor");
    mPointerHaloColor = savedState.getInt("mPointerHaloColor");
    mPointerHaloColorOnTouch = savedState.getInt("mPointerHaloColorOnTouch");
    mPointerAlpha = savedState.getInt("mPointerAlpha");
    mPointerAlphaOnTouch = savedState.getInt("mPointerAlphaOnTouch");
    lockEnabled = savedState.getBoolean("lockEnabled");

    initPaints();

    recalculateAll();
}
 
源代码7 项目: nono-android   文件: ValueBar.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)));
	setValue(savedState.getFloat(STATE_VALUE));
}
 
源代码8 项目: island   文件: SetupWizardFragment.java
@Override public View onCreateView(final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState) {
		final SetupViewModel vm;
		if (savedInstanceState == null) {
			final Bundle args = getArguments();
			vm = args != null ? args.getParcelable(null) : null;
		} else vm = savedInstanceState.getParcelable(EXTRA_VIEW_MODEL);

		if (vm == null) {
			mViewModel = new SetupViewModel();		// Initial view - "Welcome"
			mViewModel.button_next.set(R.string.setup_accept);	// "Accept" button for device-admin privilege consent, required by Google Play developer policy.
		} else mViewModel = vm;

		mContainerViewId = container.getId();
		final SetupWizardBinding binding = SetupWizardBinding.inflate(inflater, container, false);
		binding.setSetup(mViewModel);
		final View view = binding.getRoot();
		final SetupWizardLayout layout = view.findViewById(R.id.setup_wizard_layout);
		layout.requireScrollToBottom();

		final NavigationBar nav_bar = layout.getNavigationBar();
		nav_bar.setNavigationBarListener(this);
		setButtonText(nav_bar.getBackButton(), mViewModel.button_back);
		setButtonText(nav_bar.getNextButton(), mViewModel.button_next.get());
//		mViewModel.button_back.addOnPropertyChangedCallback(new Observable.OnPropertyChangedCallback() { @Override public void onPropertyChanged(final Observable observable, final int i) {
//			setButtonText(button_back, mViewModel.button_back);
//		}});
		mViewModel.button_next.addOnPropertyChangedCallback(new Observable.OnPropertyChangedCallback() { @Override public void onPropertyChanged(final Observable observable, final int i) {
			setButtonText(nav_bar.getNextButton(), mViewModel.button_next.get());
		}});

		return view;
	}
 
@Override
protected final void onRestoreInstanceState(Parcelable state) {
	try {
		if (state instanceof Bundle) {
               Bundle bundle = (Bundle) state;

               setMode(Mode.mapIntToValue(bundle.getInt(STATE_MODE, 0)));
               mCurrentMode = Mode.mapIntToValue(bundle.getInt(STATE_CURRENT_MODE, 0));

               mScrollingWhileRefreshingEnabled = bundle.getBoolean(STATE_SCROLLING_REFRESHING_ENABLED, false);
               mShowViewWhileRefreshing = bundle.getBoolean(STATE_SHOW_REFRESHING_VIEW, true);

               // Let super Restore Itself
               super.onRestoreInstanceState(bundle.getParcelable(STATE_SUPER));

               State viewState = State.mapIntToValue(bundle.getInt(STATE_STATE, 0));
               if (viewState == State.REFRESHING || viewState == State.MANUAL_REFRESHING) {
                   setState(viewState, true);
               }

               // Now let derivative classes restore their state
               onPtrRestoreInstanceState(bundle);
               return;
           }

		super.onRestoreInstanceState(state);
	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
源代码10 项目: UltimateAndroid   文件: ItemSelectionSupport.java
public void onRestoreInstanceState(Bundle state) {
    mChoiceMode = ChoiceMode.values()[state.getInt(STATE_KEY_CHOICE_MODE)];
    mCheckedStates = state.getParcelable(STATE_KEY_CHECKED_STATES);
    mCheckedIdStates = state.getParcelable(STATE_KEY_CHECKED_ID_STATES);
    mCheckedCount = state.getInt(STATE_KEY_CHECKED_COUNT);

    // TODO confirm ids here
}
 
源代码11 项目: xifan   文件: UserTimelineFragment.java
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Bundle bundle = getArguments();
    if (bundle != null) {
        mUser = bundle.getParcelable(ProfileActivity.BUNDLE_USER);
    }

    if (isVisible) {
        getUserTimeline(false);
    }

    isPrepared = true;
}
 
源代码12 项目: px-android   文件: ColorPicker.java
@Override
protected void onRestoreInstanceState(Parcelable state) {
    if (state instanceof Bundle) {
        Bundle bundle = (Bundle) state;
        colorHSV = bundle.getFloatArray("color");
        super.onRestoreInstanceState(bundle.getParcelable("super"));
    } else {
        super.onRestoreInstanceState(state);
    }
}
 
源代码13 项目: Protein   文件: FolloweeListPresenter.java
@Override
public void onRestoreInstanceState(@NonNull Bundle savedInstanceState) {
    user = savedInstanceState.getParcelable(STATE_USER);
    firstPageFollowees = savedInstanceState.getParcelableArrayList(STATE_FIRST_PAGE_DATA);
    if (firstPageFollowees == null) {
        firstPageFollowees = new ArrayList<>();
    }
    setNextPageUrl(savedInstanceState.getString(STATE_NEXT_PAGE_URL));
}
 
源代码14 项目: Nimingban   文件: HeaderImageView.java
@Override
protected void onRestoreInstanceState(Parcelable state) {
    Bundle saved = (Bundle) state;
    Uri uri = saved.getParcelable(KEY_IMAGE_UNI_FILE_URI);
    if (uri != null) {
        UniFile file = UniFile.fromUri(getContext(), uri);
        if (file != null && file.exists()) {
            setImageFile(file);
        }
    }

    super.onRestoreInstanceState(saved.getParcelable(KEY_SUPER));
}
 
private void loadArguments() {
    Bundle arguments = getArguments();

    if (arguments != null) {
        this.request = arguments.getParcelable(INTENT_TO_START);
    }
}
 
源代码16 项目: MultiView   文件: ItemSelectionSupport.java
public void onRestoreInstanceState(Bundle state) {
    mChoiceMode = ChoiceMode.values()[state.getInt(STATE_KEY_CHOICE_MODE)];
    mCheckedStates = state.getParcelable(STATE_KEY_CHECKED_STATES);
    mCheckedIdStates = state.getParcelable(STATE_KEY_CHECKED_ID_STATES);
    mCheckedCount = state.getInt(STATE_KEY_CHECKED_COUNT);

    // TODO confirm ids here
}
 
源代码17 项目: FlycoTabLayout   文件: CommonTabLayout.java
@Override
protected void onRestoreInstanceState(Parcelable state) {
    if (state instanceof Bundle) {
        Bundle bundle = (Bundle) state;
        mCurrentTab = bundle.getInt("mCurrentTab");
        state = bundle.getParcelable("instanceState");
        if (mCurrentTab != 0 && mTabsContainer.getChildCount() > 0) {
            updateTabSelection(mCurrentTab);
        }
    }
    super.onRestoreInstanceState(state);
}
 
源代码18 项目: Conversations   文件: ConversationFragment.java
private List<Uri> extractUris(final Bundle extras) {
    final List<Uri> uris = extras.getParcelableArrayList(Intent.EXTRA_STREAM);
    if (uris != null) {
        return uris;
    }
    final Uri uri = extras.getParcelable(Intent.EXTRA_STREAM);
    if (uri != null) {
        return Collections.singletonList(uri);
    } else {
        return null;
    }
}
 
@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        Bundle extras = getIntent().getExtras();
        if (extras == null) {
            finish();
            return;
        }

        mNumDeletes = extras.getLong("numDeletes");
        mAccount = (Account) extras.getParcelable("account");
        mAuthority = extras.getString("authority");
        mProvider = extras.getString("provider");

        // the order of these must match up with the constants for position used in onItemClick
        CharSequence[] options = new CharSequence[]{
                getResources().getText(R.string.sync_really_delete),
                getResources().getText(R.string.sync_undo_deletes),
                getResources().getText(R.string.sync_do_nothing)
        };

        ListAdapter adapter = new ArrayAdapter<CharSequence>(this,
                android.R.layout.simple_list_item_1,
                android.R.id.text1,
                options);

        ListView listView = new ListView(this);
        listView.setAdapter(adapter);
        listView.setItemsCanFocus(true);
        listView.setOnItemClickListener(this);

        TextView textView = new TextView(this);
        CharSequence tooManyDeletesDescFormat =
                getResources().getText(R.string.sync_too_many_deletes_desc);
        textView.setText(String.format(tooManyDeletesDescFormat.toString(),
                mNumDeletes, mProvider, mAccount.name));

        final LinearLayout ll = new LinearLayout(this);
        ll.setOrientation(LinearLayout.VERTICAL);
        final LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
                ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT, 0);
        ll.addView(textView, lp);
        ll.addView(listView, lp);

        // TODO: consider displaying the icon of the account type
//        AuthenticatorDescription[] descs = AccountManager.get(this).getAuthenticatorTypes();
//        for (AuthenticatorDescription desc : descs) {
//            if (desc.type.equals(mAccount.type)) {
//                try {
//                    final Context authContext = createPackageContext(desc.packageName, 0);
//                    ImageView imageView = new ImageView(this);
//                    imageView.setImageDrawable(authContext.getDrawable(desc.iconId));
//                    ll.addView(imageView, lp);
//                } catch (PackageManager.NameNotFoundException e) {
//                }
//                break;
//            }
//        }

        setContentView(ll);
    }
 
源代码20 项目: Klyph   文件: GroupActivity.java
@Override
protected boolean hasCachedData(Bundle savedInstanceState)
{
	return savedInstanceState != null && savedInstanceState.getParcelable("group") != null;
}