java.lang.Object | ||
↳ | android.support.v4.app.Fragment | |
↳ | com.google.android.gms.wallet.fragment.SupportWalletFragment |
This fragment is the simplest way to place a purchase button or selection details UI in an
application. 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.SupportWalletFragment" android:layout_width="match_parent" android:layout_height="wrap_content" wallet:environment="test" wallet:fragmentMode="buyButton"/>Selection Details mode:
<fragment android:name="com.google.android.gms.wallet.fragment.SupportWalletFragment" android:layout_width="match_parent" android:layout_height="wrap_content" wallet:environment="test" 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 SupportWalletFragment.OnStateChangedListener
via setOnStateChangedListener(OnStateChangedListener)
.
Use this class only if you are targeting API 12 and above. Otherwise, use SupportWalletFragment.
Nested Classes | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
SupportWalletFragment.OnStateChangedListener |
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 | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
![]() | |||||||||||
![]() | |||||||||||
![]() | |||||||||||
![]() |
Returns the current state of the fragment. See WalletFragmentState
for list of possible
values. Note that UNKNOWN
may be returned under the following
circumstances:
Returns | |
---|---|
int |
Initializes the fragment. This must be called exactly once. Any further invocations after the first will be ignored.
Parameters | |
---|---|
initParams |
WalletFragmentInitParams
|
Creates a Wallet fragment with the given options
.
Parameters | |
---|---|
options |
WalletFragmentOptions
|
Returns | |
---|---|
SupportWalletFragment |
Parameters | |
---|---|
requestCode |
int
|
resultCode |
int
|
data |
Intent
|
Parameters | |
---|---|
savedInstanceState |
Bundle
|
Parameters | |
---|---|
inflater |
LayoutInflater
|
container |
ViewGroup
|
savedInstanceState |
Bundle
|
Returns | |
---|---|
View |
Parameters | |
---|---|
activity |
Activity
|
attrs |
AttributeSet
|
savedInstanceState |
Bundle
|
Parameters | |
---|---|
outState |
Bundle
|
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.
Parameters | |
---|---|
enabled |
boolean
|
Sets a listener to receive state transition callbacks.
Parameters | |
---|---|
listener |
SupportWalletFragment.OnStateChangedListener
|
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)
.
Parameters | |
---|---|
maskedWallet |
MaskedWallet
|
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.
Parameters | |
---|---|
request |
MaskedWalletRequest
|