Example usage for android.os Bundle getParcelable

List of usage examples for android.os Bundle getParcelable

Introduction

In this page you can find the example usage for android.os Bundle getParcelable.

Prototype

@Nullable
public <T extends Parcelable> T getParcelable(@Nullable String key) 

Source Link

Document

Returns the value associated with the given key, or null if no mapping of the desired type exists for the given key or a null value is explicitly associated with the key.

Usage

From source file:com.abhijitvalluri.android.fitnotifications.AppChoicesActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_app_selector);

    LAUNCH_ACTIVITY_ANIM_BUNDLE = ActivityOptions
            .makeCustomAnimation(AppChoicesActivity.this, R.transition.left_in, R.transition.left_out)
            .toBundle();//from   ww w. j av a2s .c om

    mPackageManager = getPackageManager();
    mAppSelectionsStore = AppSelectionsStore.get(this);
    mRecyclerView = (RecyclerView) findViewById(R.id.app_selections_recycler_view);
    mLoadingView = (TextView) findViewById(R.id.app_list_loading_text_view);
    mProgressBar = (ProgressBar) findViewById(R.id.progressBar);
    mRecyclerView.setLayoutManager(new LinearLayoutManager(this));

    PreferenceManager.setDefaultValues(this, R.xml.main_settings, false);
    mPreferences = PreferenceManager.getDefaultSharedPreferences(this);
    mShowOnlyEnabledApps = mPreferences.getBoolean(getString(R.string.show_enabled_apps_key), false);

    if (savedInstanceState != null && getSetupStatus(savedInstanceState)) {
        mAppSelections = savedInstanceState.getParcelableArrayList(STATE_APP_SELECTIONS);
        Parcelable listState = savedInstanceState.getParcelable(STATE_RECYCLER_VIEW);

        if (mShowOnlyEnabledApps) {
            List<AppSelection> appSelectionsSubList = new ArrayList<>();

            for (AppSelection appSelection : mAppSelections) {
                if (appSelection.isSelected()) {
                    appSelectionsSubList.add(appSelection);
                }
            }
            mAdapter = new ActivityAdapter(appSelectionsSubList);
        } else {
            mAdapter = new ActivityAdapter(mAppSelections);
        }
        mRecyclerView.setAdapter(mAdapter);
        mRecyclerView.getLayoutManager().onRestoreInstanceState(listState);
        mSetupComplete = getSetupStatus(savedInstanceState);
    } else {
        mLoadingView.setText(getString(R.string.app_list_loading_text));
        mRecyclerView.setVisibility(View.GONE);
        mLoadingView.setVisibility(View.VISIBLE);
        mProgressBar.setVisibility(View.VISIBLE);
        new AppListSetup().execute();
    }
}

From source file:com.intel.moe.frameworks.inapppurchase.android.util.IabHelper.java

/**
 * Initiate the UI flow for an in-app purchase. Call this method to initiate an in-app purchase,
 * which will involve bringing up the Google Play screen. The calling activity will be paused while
 * the user interacts with Google Play, and the result will be delivered via the activity's
 * {@link Activity#onActivityResult} method, at which point you must call
 * this object's {@link #handleActivityResult} method to continue the purchase flow. This method
 * MUST be called from the UI thread of the Activity.
 *
 * @param act The calling activity.//from w w  w . ja va  2s.  c o  m
 * @param sku The sku of the item to purchase.
 * @param itemType indicates if it's a product or a subscription (ITEM_TYPE_INAPP or ITEM_TYPE_SUBS)
 * @param requestCode A request code (to differentiate from other responses --
 *     as in {@link Activity#startActivityForResult}).
 * @param listener The listener to notify when the purchase process finishes
 * @param extraData Extra data (developer payload), which will be returned with the purchase data
 *     when the purchase completes. This extra data will be permanently bound to that purchase
 *     and will always be returned when the purchase is queried.
 */
public void launchPurchaseFlow(Object act, String sku, String itemType, int requestCode,
        OnIabPurchaseFinishedListener listener, String extraData) {
    checkNotDisposed();
    checkSetupDone("launchPurchaseFlow");
    flagStartAsync("launchPurchaseFlow");
    IabResult result;

    if (itemType.equals(ITEM_TYPE_SUBS) && !mSubscriptionsSupported) {
        IabResult r = new IabResult(IABHELPER_SUBSCRIPTIONS_NOT_AVAILABLE, "Subscriptions are not available.");
        flagEndAsync();
        if (listener != null)
            listener.onIabPurchaseFinished(r, null);
        return;
    }

    try {
        logDebug("Constructing buy intent for " + sku + ", item type: " + itemType);
        Bundle buyIntentBundle = mService.getBuyIntent(3, mContext.getPackageName(), sku, itemType, extraData);
        int response = getResponseCodeFromBundle(buyIntentBundle);
        if (response != BILLING_RESPONSE_RESULT_OK) {
            logError("Unable to buy item, Error response: " + getResponseDesc(response));
            flagEndAsync();
            result = new IabResult(response, "Unable to buy item");
            if (listener != null)
                listener.onIabPurchaseFinished(result, null);
            return;
        }

        PendingIntent pendingIntent = buyIntentBundle.getParcelable(RESPONSE_BUY_INTENT);
        logDebug("Launching buy intent for " + sku + ". Request code: " + requestCode);
        mRequestCode = requestCode;
        mPurchaseListener = listener;
        mPurchasingItemType = itemType;
        Class activityClass = Class.forName("android.app.Activity");

        Class[] paramTypes = new Class[] { IntentSender.class, int.class, Intent.class, int.class, int.class,
                int.class };
        Method method = activityClass.getMethod("startIntentSenderForResult", paramTypes);

        Object[] args = new Object[] { pendingIntent.getIntentSender(), requestCode, new Intent(),
                Integer.valueOf(0), Integer.valueOf(0), Integer.valueOf(0) };

        method.invoke(act, args);
    } catch (InvocationTargetException e) {
        if (e.getCause() instanceof IntentSender.SendIntentException) {
            logError("SendIntentException while launching purchase flow for sku " + sku);
            e.printStackTrace();
            flagEndAsync();

            result = new IabResult(IABHELPER_SEND_INTENT_FAILED, "Failed to send intent.");
            if (listener != null)
                listener.onIabPurchaseFinished(result, null);
        }
    } catch (RemoteException e) {
        logError("RemoteException while launching purchase flow for sku " + sku);
        e.printStackTrace();
        flagEndAsync();

        result = new IabResult(IABHELPER_REMOTE_EXCEPTION, "Remote exception while starting purchase flow");
        if (listener != null)
            listener.onIabPurchaseFinished(result, null);
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    } catch (NoSuchMethodException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    }
}

From source file:com.appsimobile.appsii.module.home.appwidget.WidgetChooserActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    AppInjector.inject(this);

    setContentView(R.layout.fragment_widget_chooser);

    mOkButton = findViewById(R.id.ok_button);
    mCancelButton = findViewById(R.id.cancel);
    mRecyclerView = (RecyclerView) findViewById(R.id.widget_recycler);
    mRecyclerView.setLayoutManager(new GridLayoutManager(this, 2));

    mOkButton.setOnClickListener(this);
    mCancelButton.setOnClickListener(this);

    mSingleSelectionDecoration = new SingleSelectionDecoration(this);
    mRecyclerView.addItemDecoration(mSingleSelectionDecoration);

    List<AppWidgetProviderInfo> appWidgetProviders = mAppWidgetUtils.loadAppWidgetProviderInfos();

    Collections.sort(appWidgetProviders, new WidgetNameComparator(this, mAppWidgetManager));

    WidgetAdapter adapter = new WidgetAdapter(appWidgetProviders, this, mAppWidgetUtils);
    mRecyclerView.setAdapter(adapter);//from   w w w  . java2  s  . c  o m

    mCellId = getIntent().getLongExtra(EXTRA_CELL_ID, -1);

    // restore the state and the selection
    if (savedInstanceState != null) {
        mPendingAddWidgetId = savedInstanceState.getInt("pendingAppWidgetId");
        mSelectedAppWidgetProviderInfo = savedInstanceState.getParcelable("providerInfo");
        int position = savedInstanceState.getInt("selection");
        mSingleSelectionDecoration.setSelectedPosition(position);
    }

    // disable the ok-button when nothing is selected. Useful in
    // case we where resumed with an active selection, or started
    // without a selection
    if (mSingleSelectionDecoration.mSelectedPosition == -1) {
        mOkButton.setEnabled(false);
    }
}

From source file:com.borax12.materialdaterangepicker.single.time.TimePickerDialog.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (savedInstanceState != null && savedInstanceState.containsKey(KEY_INITIAL_TIME)
            && savedInstanceState.containsKey(KEY_IS_24_HOUR_VIEW)) {
        mInitialTime = savedInstanceState.getParcelable(KEY_INITIAL_TIME);
        mIs24HourMode = savedInstanceState.getBoolean(KEY_IS_24_HOUR_VIEW);
        mInKbMode = savedInstanceState.getBoolean(KEY_IN_KB_MODE);
        mTitle = savedInstanceState.getString(KEY_TITLE);
        mThemeDark = savedInstanceState.getBoolean(KEY_THEME_DARK);
        mThemeDarkChanged = savedInstanceState.getBoolean(KEY_THEME_DARK_CHANGED);
        mAccentColor = savedInstanceState.getInt(KEY_ACCENT);
        mVibrate = savedInstanceState.getBoolean(KEY_VIBRATE);
        mDismissOnPause = savedInstanceState.getBoolean(KEY_DISMISS);
        mSelectableTimes = (Timepoint[]) savedInstanceState.getParcelableArray(KEY_SELECTABLE_TIMES);
        mMinTime = savedInstanceState.getParcelable(KEY_MIN_TIME);
        mMaxTime = savedInstanceState.getParcelable(KEY_MAX_TIME);
        mEnableSeconds = savedInstanceState.getBoolean(KEY_ENABLE_SECONDS);
        mOkResid = savedInstanceState.getInt(KEY_OK_RESID);
        mOkString = savedInstanceState.getString(KEY_OK_STRING);
        mCancelResid = savedInstanceState.getInt(KEY_CANCEL_RESID);
        mCancelString = savedInstanceState.getString(KEY_CANCEL_STRING);
    }//  w w w . j  av  a2s .c  o m
}

From source file:de.geithonline.abattlwp.billinghelper.IabHelper.java

/**
 * Initiate the UI flow for an in-app purchase. Call this method to initiate
 * an in-app purchase, which will involve bringing up the Google Play
 * screen. The calling activity will be paused while the user interacts with
 * Google Play, and the result will be delivered via the activity's
 * {@link android.app.Activity#onActivityResult} method, at which point you
 * must call this object's {@link #handleActivityResult} method to continue
 * the purchase flow. This method MUST be called from the UI thread of the
 * Activity./* w w  w. ja v  a  2 s . c  o m*/
 * 
 * @param act
 *            The calling activity.
 * @param sku
 *            The sku of the item to purchase.
 * @param itemType
 *            indicates if it's a product or a subscription (ITEM_TYPE_INAPP
 *            or ITEM_TYPE_SUBS)
 * @param requestCode
 *            A request code (to differentiate from other responses -- as in
 *            {@link android.app.Activity#startActivityForResult}).
 * @param listener
 *            The listener to notify when the purchase process finishes
 * @param extraData
 *            Extra data (developer payload), which will be returned with
 *            the purchase data when the purchase completes. This extra data
 *            will be permanently bound to that purchase and will always be
 *            returned when the purchase is queried.
 */
public void launchPurchaseFlow(final Activity act, final String sku, final String itemType,
        final int requestCode, final OnIabPurchaseFinishedListener listener, final String extraData) {
    checkNotDisposed();
    checkSetupDone("launchPurchaseFlow");
    flagStartAsync("launchPurchaseFlow");
    IabResult result;

    if (itemType.equals(ITEM_TYPE_SUBS) && !mSubscriptionsSupported) {
        final IabResult r = new IabResult(IABHELPER_SUBSCRIPTIONS_NOT_AVAILABLE,
                "Subscriptions are not available.");
        flagEndAsync();
        if (listener != null) {
            listener.onIabPurchaseFinished(r, null);
        }
        return;
    }

    try {
        logDebug("Constructing buy intent for " + sku + ", item type: " + itemType);
        final Bundle buyIntentBundle = mService.getBuyIntent(3, mContext.getPackageName(), sku, itemType,
                extraData);
        final int response = getResponseCodeFromBundle(buyIntentBundle);
        if (response != BILLING_RESPONSE_RESULT_OK) {
            logError("Unable to buy item, Error response: " + getResponseDesc(response));
            flagEndAsync();
            result = new IabResult(response, "Unable to buy item");
            if (listener != null) {
                listener.onIabPurchaseFinished(result, null);
            }
            return;
        }

        final PendingIntent pendingIntent = buyIntentBundle.getParcelable(RESPONSE_BUY_INTENT);
        logDebug("Launching buy intent for " + sku + ". Request code: " + requestCode);
        mRequestCode = requestCode;
        mPurchaseListener = listener;
        mPurchasingItemType = itemType;
        act.startIntentSenderForResult(pendingIntent.getIntentSender(), requestCode, new Intent(),
                Integer.valueOf(0), Integer.valueOf(0), Integer.valueOf(0));
    } catch (final SendIntentException e) {
        logError("SendIntentException while launching purchase flow for sku " + sku);
        e.printStackTrace();
        flagEndAsync();

        result = new IabResult(IABHELPER_SEND_INTENT_FAILED, "Failed to send intent.");
        if (listener != null) {
            listener.onIabPurchaseFinished(result, null);
        }
    } catch (final RemoteException e) {
        logError("RemoteException while launching purchase flow for sku " + sku);
        e.printStackTrace();
        flagEndAsync();

        result = new IabResult(IABHELPER_REMOTE_EXCEPTION, "Remote exception while starting purchase flow");
        if (listener != null) {
            listener.onIabPurchaseFinished(result, null);
        }
    }
}

From source file:com.soomla.billing.IabHelper.java

/**
 * Initiate the UI flow for an in-app purchase. Call this method to initiate an in-app purchase,
 * which will involve bringing up the Google Play screen. The calling activity will be paused while
 * the user interacts with Google Play, and the result will be delivered via the activity's
 * {@link android.app.Activity#onActivityResult} method, at which point you must call
 * this object's {@link #handleActivityResult} method to continue the purchase flow. This method
 * MUST be called from the UI thread of the Activity.
 *
 * @param act The calling activity./*from   w  ww.  j a v  a  2  s . co m*/
 * @param sku The sku of the item to purchase.
 * @param itemType indicates if it's a product or a subscription (ITEM_TYPE_INAPP or ITEM_TYPE_SUBS)
 * @param requestCode A request code (to differentiate from other responses --
 *     as in {@link android.app.Activity#startActivityForResult}).
 * @param listener The listener to notify when the purchase process finishes
 * @param extraData Extra data (developer payload), which will be returned with the purchase data
 *     when the purchase completes. This extra data will be permanently bound to that purchase
 *     and will always be returned when the purchase is queried.
 */
public void launchPurchaseFlow(Activity act, String sku, String itemType, int requestCode,
        OnIabPurchaseFinishedListener listener, String extraData) {
    checkSetupDone("launchPurchaseFlow");
    flagStartAsync("launchPurchaseFlow");
    IabResult result;

    if (itemType.equals(ITEM_TYPE_SUBS) && !mSubscriptionsSupported) {
        IabResult r = new IabResult(IABHELPER_SUBSCRIPTIONS_NOT_AVAILABLE, "Subscriptions are not available.");
        if (listener != null)
            listener.onIabPurchaseFinished(r, null);
        return;
    }

    try {
        StoreUtils.LogDebug(TAG, "Constructing buy intent for " + sku + ", item type: " + itemType);
        Bundle buyIntentBundle = mService.getBuyIntent(3, SoomlaApp.getAppContext().getPackageName(), sku,
                itemType, extraData);
        buyIntentBundle.putString("PURCHASE_SKU", sku);
        int response = getResponseCodeFromBundle(buyIntentBundle);
        if (response != BILLING_RESPONSE_RESULT_OK) {
            StoreUtils.LogError(TAG, "Unable to buy item, Error response: " + getResponseDesc(response));

            result = new IabResult(response, "Unable to buy item");
            if (listener != null)
                listener.onIabPurchaseFinished(result, null);
            // make sure to end the async operation...
            flagEndAsync();
            act.finish();
            return;
        }

        PendingIntent pendingIntent = buyIntentBundle.getParcelable(RESPONSE_BUY_INTENT);
        StoreUtils.LogDebug(TAG, "Launching buy intent for " + sku + ". Request code: " + requestCode);
        mRequestCode = requestCode;
        mPurchaseListener = listener;
        mPurchasingItemSku = sku;
        mPurchasingItemType = itemType;

        act.startIntentSenderForResult(pendingIntent.getIntentSender(), requestCode, new Intent(),
                Integer.valueOf(0), Integer.valueOf(0), Integer.valueOf(0));
    } catch (SendIntentException e) {
        StoreUtils.LogError(TAG, "SendIntentException while launching purchase flow for sku " + sku);
        e.printStackTrace();

        result = new IabResult(IABHELPER_SEND_INTENT_FAILED, "Failed to send intent.");
        if (listener != null)
            listener.onIabPurchaseFinished(result, null);
    } catch (RemoteException e) {
        StoreUtils.LogError(TAG, "RemoteException while launching purchase flow for sku " + sku);
        e.printStackTrace();

        result = new IabResult(IABHELPER_REMOTE_EXCEPTION, "Remote exception while starting purchase flow");
        if (listener != null)
            listener.onIabPurchaseFinished(result, null);
    }
}

From source file:com.android.mail.ui.FolderListFragment.java

/**
 * Set the instance variables from the arguments provided here.
 * @param args bundle of arguments with keys named ARG_*
 *//*ww w  .ja  v a  2s .c  o m*/
private void setInstanceFromBundle(Bundle args) {
    if (args == null) {
        return;
    }
    mParentFolder = args.getParcelable(ARG_PARENT_FOLDER);
    final String folderUri = args.getString(ARG_FOLDER_LIST_URI);
    if (folderUri != null) {
        mFolderListUri = Uri.parse(folderUri);
    }
    mExcludedFolderTypes = args.getIntegerArrayList(ARG_EXCLUDED_FOLDER_TYPES);
}

From source file:android.support.v7.preference.Preference.java

/**
 * Called by {@link #restoreHierarchyState} to retrieve the saved state for this
 * Preference and its children. May be overridden to modify how restoring
 * happens to the children of a Preference. For example, some Preference objects may
 * not want to save state for their children.
 *
 * @param container The Bundle that holds the previously saved state.
 * @see #restoreHierarchyState/*from   www.  jav a 2 s.c  o  m*/
 * @see #onRestoreInstanceState
 */
void dispatchRestoreInstanceState(Bundle container) {
    if (hasKey()) {
        Parcelable state = container.getParcelable(mKey);
        if (state != null) {
            mBaseMethodCalled = false;
            onRestoreInstanceState(state);
            if (!mBaseMethodCalled) {
                throw new IllegalStateException("Derived class did not call super.onRestoreInstanceState()");
            }
        }
    }
}

From source file:com.google.example.eightbitartist.DrawingActivity.java

@Override
public void onConnected(Bundle bundle) {
    Log.i(TAG, "onConnected: sign-in successful.");

    // This is *NOT* required; if you do not register a handler for
    // invitation events, you will get standard notifications instead.
    // Standard notifications may be preferable behavior in many cases.
    Games.Invitations.registerInvitationListener(mGoogleApiClient, this);

    // Get invitation from Bundle
    if (bundle != null) {
        Invitation invitation = bundle.getParcelable(Multiplayer.EXTRA_INVITATION);
        if (invitation != null) {
            onInvitationReceived(invitation);
        }/*from   ww w . j  ava2  s.c  o m*/
    }

    updateViewVisibility();
}

From source file:com.android.tv.settings.dialog.DialogFragment.java

@Override
public void onCreate(Bundle savedInstanceState) {
    android.util.Log.v("DialogFragment", "onCreate");
    super.onCreate(savedInstanceState);
    Bundle state = (savedInstanceState != null) ? savedInstanceState : getArguments();
    if (mTitle == null) {
        mTitle = state.getString(EXTRA_CONTENT_TITLE);
    }/*from w w w . j  av  a2  s.com*/
    if (mBreadcrumb == null) {
        mBreadcrumb = state.getString(EXTRA_CONTENT_BREADCRUMB);
    }
    if (mDescription == null) {
        mDescription = state.getString(EXTRA_CONTENT_DESCRIPTION);
    }
    if (mIconResourceId == 0) {
        mIconResourceId = state.getInt(EXTRA_CONTENT_ICON_RESOURCE_ID, 0);
    }
    if (mIconUri == null) {
        mIconUri = state.getParcelable(EXTRA_CONTENT_ICON_URI);
    }
    if (mIconBitmap == null) {
        mIconBitmap = state.getParcelable(EXTRA_CONTENT_ICON_BITMAP);
    }
    if (mIconBackgroundColor == Color.TRANSPARENT) {
        mIconBackgroundColor = state.getInt(EXTRA_CONTENT_ICON_BACKGROUND, Color.TRANSPARENT);
    }
    if (mActions == null) {
        mActions = state.getParcelableArrayList(EXTRA_ACTION_ACTIONS);
    }
    if (mName == null) {
        mName = state.getString(EXTRA_ACTION_NAME);
    }
    if (mSelectedIndex == -1) {
        mSelectedIndex = state.getInt(EXTRA_ACTION_SELECTED_INDEX, -1);
    }
    mEntryTransitionPerformed = state.getBoolean(EXTRA_ENTRY_TRANSITION_PERFORMED, false);
}