java.lang.Object | ||
↳ | android.app.Fragment | |
↳ | com.google.android.gms.wallet.fragment.WalletFragment |
This fragment is the simplest way to place a Wallet buy button or selection details UI
in an application for the InstantBuy API. It automatically handles life cycle and user events,
producing a MaskedWallet
in the end. Being a fragment, the component can be added
to an activity's layout with the XML below.
Buy Button mode:
<fragment android:name="com.google.android.gms.wallet.fragment.WalletFragment" android:layout_width="match_parent" android:layout_height="wrap_content" wallet:environment="sandbox" wallet:fragmentMode="buyButton"/>Selection Details mode:
<fragment android:name="com.google.android.gms.wallet.fragment.WalletFragment" android:layout_width="match_parent" android:layout_height="wrap_content" wallet:environment="sandbox" wallet:fragmentMode="selectionDetails"/>Alternatively it may also be created programmatically with
newInstance(WalletFragmentOptions)
and added to the activity's fragment manager.
The fragment must be initialized exactly once by calling
initialize(WalletFragmentInitParams)
. This sets a MaskedWalletRequest
for buy button mode or MaskedWallet
for selection details mode. For buy button mode the
request may be modified with updateMaskedWalletRequest(MaskedWalletRequest)
.
When the button is clicked, the masked payment credentials of the user will be retrieved and
returned in your activity's onActivityResult
callback with a request code specified in
WalletFragmentInitParams
.
The fragment may be in one of four states at any time. It starts out in
UNINITIALIZED
. UI components are disabled in this state.
Once initialize(WalletFragmentInitParams)
is called, the fragment transitions into
READY
, where it is ready for user interaction.
When the buy/change button is clicked, it transitions into PROCESSING
.
The button will be disabled to prevent further user interaction. Finally when the masked wallet
result comes back, the fragment goes back into READY
.
Sometimes the fragment can also get into WALLET_UNAVAILABLE
when
the Wallet service is temporarily not available. UI components will be disabled in this state.
You may receive state transition updates by setting a WalletFragment.OnStateChangedListener
via
setOnStateChangedListener(OnStateChangedListener)
.
Use this class only if you are targeting API 12 and above. Otherwise, use SupportWalletFragment.
Nested Classes | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
WalletFragment.OnStateChangedListener |
[Expand]
Inherited Constants | ||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
From interface
android.content.ComponentCallbacks2
|
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Returns the current state of the fragment.
| |||||||||||
Initializes the fragment.
| |||||||||||
Creates a Wallet fragment with the given
options .
| |||||||||||
Sets a boolean that will enable or disable the fragment's UI components when it's in
READY .
| |||||||||||
Sets a listener to receive state transition callbacks.
| |||||||||||
Modifies the
MaskedWallet .
| |||||||||||
Modifies the
MaskedWalletRequest .
|
[Expand]
Inherited Methods | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
From class
android.app.Fragment
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
From class
java.lang.Object
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
From interface
android.content.ComponentCallbacks2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
From interface
android.view.View.OnCreateContextMenuListener
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
From interface
android.content.ComponentCallbacks
|
Returns the current state of the fragment. See WalletFragmentState
for list of
possible values. Note that UNKNOWN
may be returned under the
following circumstances:
Initializes the fragment. This must be called exactly once. Any further invocations after the first will be ignored.
Creates a Wallet fragment with the given options
.
Sets a boolean that will enable or disable the fragment's UI components when it's in
READY
. The UI components can not be disabled in other states
and the boolean has no effect. This method is meant for temporarily disabling the buy
button while you load data or update UI in your app.
Sets a listener to receive state transition callbacks.
Modifies the MaskedWallet
. This should be called after
initialize(WalletFragmentInitParams)
. Any non-null maskedWallet
passed in here takes precedence over the MaskedWallet
in
WalletFragmentInitParams
passed in initialize(WalletFragmentInitParams)
.
Modifies the MaskedWalletRequest
. This should be called after
initialize(WalletFragmentInitParams)
. Any non-null request
passed in here
takes precedence over the MaskedWalletRequest
in WalletFragmentInitParams
passed in initialize(WalletFragmentInitParams)
.
Note that any user buy button click event before this method call would load a masked wallet
using whatever MaskedWalletRequest
available at that time.