Summary: Nested Classes | Inherited Constants | Ctors | Methods | Inherited Methods | [Expand All]
public final class

# WalletFragment

extends Fragment

java.lang.Object
↳ | android.app.Fragment
| ↳ | com.google.android.gms.wallet.fragment.WalletFragment

## Class Overview

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.WalletFragment"
        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.WalletFragment"
        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 `WalletFragment.OnStateChangedListener` via `setOnStateChangedListener(OnStateChangedListener)`.

Use this class only if you are targeting API 12 and above. Otherwise, use SupportWalletFragment.

## Summary

Nested Classes
interface | WalletFragment.OnStateChangedListener |

[Expand] Inherited Constants
From interface android.content.ComponentCallbacks2
int | TRIM_MEMORY_BACKGROUND |
int | TRIM_MEMORY_COMPLETE |
int | TRIM_MEMORY_MODERATE |
int | TRIM_MEMORY_RUNNING_CRITICAL |
int | TRIM_MEMORY_RUNNING_LOW |
int | TRIM_MEMORY_RUNNING_MODERATE |
int | TRIM_MEMORY_UI_HIDDEN |

Public Constructors
| WalletFragment()

Public Methods
int | getState() Returns the current state of the fragment.
void | initialize(WalletFragmentInitParams initParams) Initializes the fragment.
static WalletFragment | newInstance(WalletFragmentOptions options) Creates a Wallet fragment with the given `options`.
void | onActivityResult(int requestCode, int resultCode, Intent data)
void | onCreate(Bundle savedInstanceState)
View | onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
void | onDestroy()
void | onInflate(Activity activity, AttributeSet attrs, Bundle savedInstanceState)
void | onPause()
void | onResume()
void | onSaveInstanceState(Bundle outState)
void | onStart()
void | onStop()
void | setEnabled(boolean enabled) Sets a boolean that will enable or disable the fragment's UI components when it's in `READY`.
void | setOnStateChangedListener(WalletFragment.OnStateChangedListener listener) Sets a listener to receive state transition callbacks.
void | updateMaskedWallet(MaskedWallet maskedWallet) Modifies the `MaskedWallet`.
void | updateMaskedWalletRequest(MaskedWalletRequest request) Modifies the `MaskedWalletRequest`.

[Expand] Inherited Methods
From class android.app.Fragment
void | dump(String arg0, FileDescriptor arg1, PrintWriter arg2, String[] arg3)
final boolean | equals(Object arg0)
final Activity | getActivity()
boolean | getAllowEnterTransitionOverlap()
boolean | getAllowReturnTransitionOverlap()
final Bundle | getArguments()
final FragmentManager | getChildFragmentManager()
Context | getContext()
Transition | getEnterTransition()
Transition | getExitTransition()
final FragmentManager | getFragmentManager()
final Object | getHost()
final int | getId()
LoaderManager | getLoaderManager()
final Fragment | getParentFragment()
Transition | getReenterTransition()
final Resources | getResources()
final boolean | getRetainInstance()
Transition | getReturnTransition()
Transition | getSharedElementEnterTransition()
Transition | getSharedElementReturnTransition()
final String | getString(int arg0, Object... arg1)
final String | getString(int arg0)
final String | getTag()
final Fragment | getTargetFragment()
final int | getTargetRequestCode()
final CharSequence | getText(int arg0)
boolean | getUserVisibleHint()
View | getView()
final int | hashCode()
static Fragment | instantiate(Context arg0, String arg1)
static Fragment | instantiate(Context arg0, String arg1, Bundle arg2)
final boolean | isAdded()
final boolean | isDetached()
final boolean | isHidden()
final boolean | isInLayout()
final boolean | isRemoving()
final boolean | isResumed()
final boolean | isVisible()
void | onActivityCreated(Bundle arg0)
void | onActivityResult(int arg0, int arg1, Intent arg2)
void | onAttach(Activity arg0)
void | onAttach(Context arg0)
void | onConfigurationChanged(Configuration arg0)
boolean | onContextItemSelected(MenuItem arg0)
void | onCreate(Bundle arg0)
Animator | onCreateAnimator(int arg0, boolean arg1, int arg2)
void | onCreateContextMenu(ContextMenu arg0, View arg1, ContextMenu.ContextMenuInfo arg2)
void | onCreateOptionsMenu(Menu arg0, MenuInflater arg1)
View | onCreateView(LayoutInflater arg0, ViewGroup arg1, Bundle arg2)
void | onDestroy()
void | onDestroyOptionsMenu()
void | onDestroyView()
void | onDetach()
void | onHiddenChanged(boolean arg0)
void | onInflate(AttributeSet arg0, Bundle arg1)
void | onInflate(Activity arg0, AttributeSet arg1, Bundle arg2)
void | onInflate(Context arg0, AttributeSet arg1, Bundle arg2)
void | onLowMemory()
boolean | onOptionsItemSelected(MenuItem arg0)
void | onOptionsMenuClosed(Menu arg0)
void | onPause()
void | onPrepareOptionsMenu(Menu arg0)
void | onRequestPermissionsResult(int arg0, String[] arg1, int[] arg2)
void | onResume()
void | onSaveInstanceState(Bundle arg0)
void | onStart()
void | onStop()
void | onTrimMemory(int arg0)
void | onViewCreated(View arg0, Bundle arg1)
void | onViewStateRestored(Bundle arg0)
void | registerForContextMenu(View arg0)
final void | requestPermissions(String[] arg0, int arg1)
void | setAllowEnterTransitionOverlap(boolean arg0)
void | setAllowReturnTransitionOverlap(boolean arg0)
void | setArguments(Bundle arg0)
void | setEnterSharedElementCallback(SharedElementCallback arg0)
void | setEnterTransition(Transition arg0)
void | setExitSharedElementCallback(SharedElementCallback arg0)
void | setExitTransition(Transition arg0)
void | setHasOptionsMenu(boolean arg0)
void | setInitialSavedState(Fragment.SavedState arg0)
void | setMenuVisibility(boolean arg0)
void | setReenterTransition(Transition arg0)
void | setRetainInstance(boolean arg0)
void | setReturnTransition(Transition arg0)
void | setSharedElementEnterTransition(Transition arg0)
void | setSharedElementReturnTransition(Transition arg0)
void | setTargetFragment(Fragment arg0, int arg1)
void | setUserVisibleHint(boolean arg0)
boolean | shouldShowRequestPermissionRationale(String arg0)
void | startActivity(Intent arg0)
void | startActivity(Intent arg0, Bundle arg1)
void | startActivityForResult(Intent arg0, int arg1)
void | startActivityForResult(Intent arg0, int arg1, Bundle arg2)
String | toString()
void | unregisterForContextMenu(View arg0)
From class java.lang.Object
Object | clone()
boolean | equals(Object arg0)
void | finalize()
final Class<?> | getClass()
int | hashCode()
final void | notify()
final void | notifyAll()
String | toString()
final void | wait(long arg0, int arg1)
final void | wait(long arg0)
final void | wait()
From interface android.content.ComponentCallbacks2
abstract void | onTrimMemory(int arg0)
From interface android.view.View.OnCreateContextMenuListener
abstract void | onCreateContextMenu(ContextMenu arg0, View arg1, ContextMenu.ContextMenuInfo arg2)
From interface android.content.ComponentCallbacks
abstract void | onConfigurationChanged(Configuration arg0)
abstract void | onLowMemory()

## Public Constructors

#### public WalletFragment ()

## Public Methods

#### public int getState ()

Returns the current state of the fragment. See `WalletFragmentState` for list of possible values. Note that `UNKNOWN` may be returned under the following circumstances:

- before onStart() is executed
- when Google Play services is unavailable or requires update

#### public void initialize (WalletFragmentInitParams initParams)

Initializes the fragment. This must be called exactly once. Any further invocations after the first will be ignored.

#### public static WalletFragment newInstance (WalletFragmentOptions options)

Creates a Wallet fragment with the given `options`.

#### public void onActivityResult (int requestCode, int resultCode, Intent data)

#### public void onCreate (Bundle savedInstanceState)

#### public View onCreateView (LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)

#### public void onDestroy ()

#### public void onInflate (Activity activity, AttributeSet attrs, Bundle savedInstanceState)

#### public void onPause ()

#### public void onResume ()

#### public void onSaveInstanceState (Bundle outState)

#### public void onStart ()

#### public void onStop ()

#### public void setEnabled (boolean enabled)

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.

#### public void setOnStateChangedListener (WalletFragment.OnStateChangedListener listener)

Sets a listener to receive state transition callbacks.

#### public void updateMaskedWallet (MaskedWallet maskedWallet)

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)`.

#### public void updateMaskedWalletRequest (MaskedWalletRequest request)

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.