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.adarshahd.indianrailinfo.donate.TrainDetails.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.layout_details);
    mActivity = this;
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    mDialog = new ProgressDialog(mActivity);
    mDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
    mDialog.setIndeterminate(true);/*from   ww w  .  j  a v  a2s .c o m*/
    mDialog.show();
    mButtonAvailability = (Button) findViewById(R.id.id_btn_avail_next_7);
    if (savedInstanceState != null) {
        mDetails = savedInstanceState.getParcelable("LIST");
        if (mDetails == null) {
            return;
        }
        mFrameLayout = null;
        mFrameLayout = (FrameLayout) findViewById(R.id.id_fl_details);
        if (mDetails.getAction().equals(TrainEnquiry.FARE)) {
            getSupportActionBar().setTitle("Fare Details");
            mButtonAvailability.setVisibility(View.GONE);
            createTableLayoutTrainFare();
        }
        if (mDetails.getAction().equals(TrainEnquiry.AVAILABILITY)) {
            getSupportActionBar().setTitle("Availability Details");
            mButtonAvailability.setVisibility(View.VISIBLE);
            mButtonAvailability.setOnClickListener(this);
            createTableLayoutTrainAvailability();
        }
        return;
    }
    mFrameLayout = (FrameLayout) findViewById(R.id.id_fl_details);
    Intent intent = getIntent();
    mAction = intent.getStringExtra(TrainEnquiry.ACTION);
    if (mAction.equals(TrainEnquiry.FARE)) {
        getSupportActionBar().setTitle("Fare Details");
        mButtonAvailability.setVisibility(View.GONE);
        mTrainNumber = intent.getStringExtra(TrainEnquiry.TRAIN);
        mSrc = intent.getStringExtra(TrainEnquiry.SRC);
        mDst = intent.getStringExtra(TrainEnquiry.DST);
        mDay = intent.getStringExtra(TrainEnquiry.DAY_TRAVEL);
        mMonth = intent.getStringExtra(TrainEnquiry.MONTH_TRAVEL);
        mCls = intent.getStringExtra(TrainEnquiry.CLS);
        mAge = intent.getStringExtra(TrainEnquiry.AGE);
        new GetFare().execute();
        mDialog.setMessage("Fetching train fare . . .");
    }
    if (mAction.equals(TrainEnquiry.AVAILABILITY)) {
        getSupportActionBar().setTitle("Availability Details");
        mButtonAvailability.setVisibility(View.VISIBLE);
        mButtonAvailability.setOnClickListener(this);
        mTrainNumber = intent.getStringExtra(TrainEnquiry.TRAIN);
        mSrc = intent.getStringExtra(TrainEnquiry.SRC);
        mDst = intent.getStringExtra(TrainEnquiry.DST);
        mDay = intent.getStringExtra(TrainEnquiry.DAY_TRAVEL);
        mMonth = intent.getStringExtra(TrainEnquiry.MONTH_TRAVEL);
        mCls = intent.getStringExtra(TrainEnquiry.CLS);
        new GetAvail().execute();
        mDialog.setMessage("Fetching train availability . . .");
    }
}

From source file:com.brandao.tictactoe.board.BoardFragment.java

public void restartGame(Bundle savedInstanceState) {
    mStartTime = savedInstanceState.getInt(SAVED_STATE_START_TIME);

    mLastGameWinner = savedInstanceState.getInt(SAVED_STATE_LAST_GAME_WINNER);
    mLastMoveIndex = savedInstanceState.getInt(SAVED_STATE_LAST_MOVE_INDEX);

    mGameState = savedInstanceState.getInt(SAVED_STATE_GAME_STATE);

    if (mBoard == null) {
        mBoard = savedInstanceState.getParcelable(SAVED_STATE_BOARD);

        if (mBoard == null) {
            restartGame(false);//from   w  ww.  j  a  v  a 2 s .c om
            return;
        }
    }

    for (int i = 0; i < mBoard.moves.length; i++) {
        if (mBoard.moves[i].player == C.SYMBLE_PLAYER_ONE) {
            mScreens[i].setBackgroundResource(R.drawable.ic_green_x_android);
        } else {
            if (mBoard.moves[i].player == C.SYMBLE_PLAYER_TWO) {
                mScreens[mBoard.moves[i].position].setBackgroundResource(R.drawable.ic_red_o_android);
            } else {
                mScreens[mBoard.moves[i].position].setBackgroundResource(R.drawable.transparent_image);
            }
        }
    }

    int state = mGameState;
    if (state == C.STATE_GAME_OVER) {
        if (mBoard.moves[mLastMoveIndex].player == C.SYMBLE_PLAYER_ONE) {
            state = C.STATE_PLAYER_ONE_TURN;
        } else {
            state = C.STATE_PLAYER_TWO_TURN;
        }
    }

    switch (state) {
    case C.STATE_PLAYER_ONE_TURN: {
        mPlayerOneNameDisplay.setShadowLayer(4.5f, 0, 0,
                ContextCompat.getColor(getActivity(), R.color.tic_tac_toe_green_shadow));
        mPlayerTwoNameDisplay.setShadowLayer(0f, 0, 0,
                ContextCompat.getColor(getActivity(), R.color.tic_tac_toe_red_shadow));
        mPlayerOneImage.setBackgroundResource(R.drawable.ic_green_x_android);
        mPlayerTwoImage.setBackgroundResource(R.drawable.ic_grey_o_android);

        break;
    }
    case C.STATE_PLAYER_TWO_TURN: {
        mPlayerOneNameDisplay.setShadowLayer(0f, 0, 0,
                ContextCompat.getColor(getActivity(), R.color.tic_tac_toe_green_shadow));
        mPlayerTwoNameDisplay.setShadowLayer(4.5f, 0, 0,
                ContextCompat.getColor(getActivity(), R.color.tic_tac_toe_red_shadow));
        mPlayerOneImage.setBackgroundResource(R.drawable.ic_grey_x_android);
        mPlayerTwoImage.setBackgroundResource(R.drawable.ic_red_o_android);

        break;
    }
    }
}

From source file:ca.rmen.android.scrumchatter.main.MainActivity.java

/**
 * The user tapped on the OK button of a confirmation dialog. Execute the action requested by the user.
 *
 * @param actionId the action id which was provided to the {@link DialogFragmentFactory} when creating the dialog.
 * @param extras   any extras which were provided to the {@link DialogFragmentFactory} when creating the dialog.
 * @see ca.rmen.android.scrumchatter.dialog.ConfirmDialogFragment.DialogButtonListener#onOkClicked(int, android.os.Bundle)
 *//*from  ww w.j  a v  a 2s .c  o m*/
@Override
public void onOkClicked(int actionId, Bundle extras) {
    Log.v(TAG, "onClicked: actionId = " + actionId + ", extras = " + extras);
    if (actionId == R.id.action_delete_meeting) {
        long meetingId = extras.getLong(Meetings.EXTRA_MEETING_ID);
        mMeetings.delete(meetingId);
    } else if (actionId == R.id.btn_stop_meeting) {
        MeetingFragment meetingFragment = MeetingFragment.lookupMeetingFragment(getSupportFragmentManager());
        if (meetingFragment != null)
            meetingFragment.stopMeeting();
    } else if (actionId == R.id.action_delete_member) {
        long memberId = extras.getLong(Members.EXTRA_MEMBER_ID);
        mMembers.deleteMember(memberId);
    } else if (actionId == R.id.action_team_delete) {
        Uri teamUri = extras.getParcelable(Teams.EXTRA_TEAM_URI);
        mTeams.deleteTeam(teamUri);
    } else if (actionId == R.id.action_import) {
        final Uri uri = extras.getParcelable(EXTRA_IMPORT_URI);
        DialogFragmentFactory.showProgressDialog(MainActivity.this, getString(R.string.progress_dialog_message),
                PROGRESS_DIALOG_FRAGMENT_TAG);
        Schedulers.io().scheduleDirect(() -> {
            boolean result = false;
            try {
                Log.v(TAG, "Importing db from " + uri);
                DBImport.importDB(MainActivity.this, uri);
                result = true;
            } catch (Exception e) {
                Log.e(TAG, "Error importing db: " + e.getMessage(), e);
            }
            // Notify ourselves with a broadcast.  If the user rotated the device, this activity
            // won't be visible any more. The new activity will receive the broadcast and update
            // the UI.
            Intent intent = new Intent(ACTION_IMPORT_COMPLETE).putExtra(EXTRA_IMPORT_RESULT, result);
            LocalBroadcastManager.getInstance(getApplicationContext()).sendBroadcast(intent);
        });
    }
}

From source file:com.cerema.cloud2.ui.activity.Uploader.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    prepareStreamsToUpload();//  w ww  . ja v  a2s.  c o  m

    if (savedInstanceState == null) {
        mParents = new Stack<String>();
        mAccountSelected = false;
        mAccountSelectionShowing = false;
        mNumCacheFile = 0;

        // ArrayList for files with path in private storage
        mRemoteCacheData = new ArrayList<String>();
    } else {
        mParents = (Stack<String>) savedInstanceState.getSerializable(KEY_PARENTS);
        mFile = savedInstanceState.getParcelable(KEY_FILE);
        mAccountSelected = savedInstanceState.getBoolean(KEY_ACCOUNT_SELECTED);
        mAccountSelectionShowing = savedInstanceState.getBoolean(KEY_ACCOUNT_SELECTION_SHOWING);
        mNumCacheFile = savedInstanceState.getInt(KEY_NUM_CACHE_FILE);
        mRemoteCacheData = savedInstanceState.getStringArrayList(KEY_REMOTE_CACHE_DATA);
    }

    super.onCreate(savedInstanceState);

    if (mAccountSelected) {
        setAccount((Account) savedInstanceState.getParcelable(FileActivity.EXTRA_ACCOUNT));
    }

    // Listen for sync messages
    IntentFilter syncIntentFilter = new IntentFilter(
            RefreshFolderOperation.EVENT_SINGLE_FOLDER_CONTENTS_SYNCED);
    syncIntentFilter.addAction(RefreshFolderOperation.EVENT_SINGLE_FOLDER_SHARES_SYNCED);
    mSyncBroadcastReceiver = new SyncBroadcastReceiver();
    registerReceiver(mSyncBroadcastReceiver, syncIntentFilter);
}

From source file:com.orbar.pxdemo.ImageView.FivePXImageFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    Log.d(TAG, "onCreateView");

    final View rootView = inflater.inflate(R.layout.fragment_five_px_image, container, false);

    getReusableViews(rootView);/*from w  ww.ja  v  a  2 s.co m*/

    // Set the attributes for the custom ActionBar
    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setDisplayShowCustomEnabled(true);
    actionBar.setDisplayShowTitleEnabled(false);

    // Set the placeholder until download finishes.
    actionBar.setIcon(R.drawable.ic_launcher);

    // get the ImageBean that was clicked
    Bundle bundle = this.getArguments();
    mFiveZeroZeroImageBean = (FiveZeroZeroImageBean) bundle.getParcelable(ARG_IMAGE_BEAN);

    // Inflate the custom action bar layout
    LayoutInflater inflator = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View actionView = inflator.inflate(R.layout.actionbar_five_px_image, null);

    // set the title and user name in the action bar
    TextView imageTitle = (TextView) actionView.findViewById(R.id.image_title);
    TextView imageuserName = (TextView) actionView.findViewById(R.id.image_username);

    imageTitle.setText(mFiveZeroZeroImageBean.getName());
    imageuserName.setText(mFiveZeroZeroImageBean.getUserBean().getUserName());

    actionBar.setCustomView(actionView);

    // get reference to userAccountLayout in the action bar
    userAccountLayout = (RelativeLayout) actionView.findViewById(R.id.image_account_layout);

    // Download the user image in Extra Small size. No Picasso for this image.
    mDownloadUserImage = new DownloadUserImage();
    mDownloadUserImage.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR,
            mFiveZeroZeroImageBean.getUserBean().getUserpicURL(USER_IMAGE_SIZE.LARGE));

    // Setup the Sliding Panel layout 
    mSlidingPaneLayout.setShadowDrawable(getResources().getDrawable(R.drawable.above_shadow));
    mSlidingPaneLayout.setAnchorPoint(0.2f);
    mSlidingPaneLayout.setDragView(imageControlsLayout);
    mSlidingPaneLayout.setEnableDragViewTouchEvents(true);

    // Download the Image and put it into a zoom-able and pan-able imageview. 
    ImageView mImageView = (ImageView) rootView.findViewById(R.id.image);

    // The MAGIC happens here!
    mAttacher = new PhotoViewAttacher(mImageView);

    Picasso.with(getActivity()) //
            .load(mFiveZeroZeroImageBean.getImageUrl(IMAGE_SIZE.ORIGINAL))
            //.placeholder(image.getDrawable()) // Use the smaller image while downloading the higher resolution image 
            .error(android.R.drawable.stat_notify_error) // The error image
            .into(mImageView, new Callback() {
                @Override
                public void onError() {
                }

                // When finished loading, update the attacher
                @Override
                public void onSuccess() {
                    mAttacher.update();
                }
            });

    //mAttacher.setOnPhotoTapListener(new PhotoTapListener());

    // Setup the comments ListView
    mCommentsAdapter = new CommentsAdapter(getActivity(), mFiveZeroZeroImageBean.getCommentBeans());
    commentsListView.setAdapter(mCommentsAdapter);

    // set the comment count
    imageComments.setText(Integer.toString(mFiveZeroZeroImageBean.getCommentsCount()));
    imageLikes.setText(Integer.toString(mFiveZeroZeroImageBean.getVotesCount()));
    imageFavorites.setText(Integer.toString(mFiveZeroZeroImageBean.getFavoritesCount()));

    // get the last page number (we want to add pages in reverse order (newest first)
    pageNumber.set((int) Math.ceil(mFiveZeroZeroImageBean.getCommentsCount() / 20.0));

    mFiveZeroZeroImageAPIBuilder = new FiveZeroZeroImageAPIBuilder().setPageNum(pageNumber.get());

    mLoadCommentsList = new LoadCommentsList(getActivity(), mFiveZeroZeroImageAPIBuilder, mLoginManager,
            mFiveZeroZeroImageBean, loadingMore, stopLoadingData, pageNumber);
    mLoadCommentsList.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);

    mLoadImageDetailsList = new LoadImageDetailsList(getActivity(), mFiveZeroZeroImageAPIBuilder, mLoginManager,
            mFiveZeroZeroImageBean);
    mLoadImageDetailsList.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);

    return rootView;
}

From source file:com.android.dragonkeyboardfirmwareupdater.KeyboardFirmwareUpdateService.java

/**
 * Handles intents ACTION_CONNECTION_STATE_CHANGED, ACTION_STATE_CHANGED,
 * ACTION_BOND_STATE_CHANGED, ACTION_KEYBOARD_UPDATE_CONFIRMED.
 * <p/>/*from  www  .  j  av  a  2s  . c o  m*/
 * [ACTION_STATE_CHANGED]
 * This action is used to keep track of ON/OFF state change on the system Bluetooth adapter.
 * The
 * purpose is to synchronize the local Bluetooth connectivity with system Bluetooth state.
 * <p/>
 * [ACTION_CONNECTION_STATE_CHANGED]
 * This action is used to keep track of the connection change on the target device. The purpose
 * is to synchronize the connection cycles of the local GATT connection and the system
 * Bluetooth
 * connection.
 * <p/>
 * [ACTION_BOND_STATE_CHANGED]
 * This action is used to keep track of the bond state change on the target device. The purpose
 * is to the connection cycles of the local GATT connection and the system Bluetooth
 * connection.
 * <p/>
 * [ACTION_KEYBOARD_UPDATE_CONFIRMED]
 * This action is used to receive the update confirmation from the user. The purpose is to
 * trigger DFU process.
 */
private void onHandleIntent(Context context, Intent intent) {
    final String action = intent.getAction();
    Log.d(TAG, "onHandleIntent: Received action: " + action);

    if (BluetoothAdapter.ACTION_CONNECTION_STATE_CHANGED.equals(action)) {

        if (!isBluetoothEnabled()) {
            Log.w(TAG, "onHandleIntent: Bluetooth connectivity not enabled");
            return;
        }

        // Match the connected device with the default keyboard name.
        Bundle extras = intent.getExtras();
        if (extras == null)
            return;
        final BluetoothDevice device = extras.getParcelable(BluetoothDevice.EXTRA_DEVICE);
        final int deviceConnectionState = extras.getInt(BluetoothAdapter.EXTRA_CONNECTION_STATE);

        Log.d(TAG, "onHandleIntent: " + device.getName() + " [" + device.getAddress() + "] change to state: "
                + deviceConnectionState);

        // Match the name of the target keyboard.
        if (!isTargetKeyboard(device))
            return;

        if (deviceConnectionState == BluetoothAdapter.STATE_CONNECTED) {
            // Prevent the second keyboard from using the service.
            if (isUpdateServiceInUse())
                return;

            obtainKeyboardInfo(device.getName(), device.getAddress());

            if (mDfuStatus != DFU_STATE_INFO_READY) {
                Log.w(TAG, "onHandleIntent: DFU preparation failed");
                changeDfuStatus(DFU_STATE_OBTAIN_INFO_ERROR);
                return;
            }

            showUpdateNotification();
        } else if (deviceConnectionState == BluetoothAdapter.STATE_DISCONNECTING) {
            handleGattDisconnection();
        }

    } else if (BluetoothAdapter.ACTION_STATE_CHANGED.equals(action)) {
        final int adapterState = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR);
        if (adapterState == BluetoothAdapter.STATE_ON) {
            if (!isBluetoothEnabled())
                enableBluetoothConnectivity();
        } else if (adapterState == BluetoothAdapter.STATE_TURNING_OFF) {
            // Terminate update process and disable Bluetooth connectivity.
            disableBluetoothConnectivity();

            // Since BluetoothAdapter has been disabled, the callback of disconnection would not
            // be called. Therefore a separate clean-up of GATT connection is need.
            cleanUpGattConnection();
        }

    } else if (BluetoothDevice.ACTION_BOND_STATE_CHANGED.equals(action)) {
        Bundle extras = intent.getExtras();
        if (extras == null)
            return;
        final BluetoothDevice device = extras.getParcelable(BluetoothDevice.EXTRA_DEVICE);
        final int deviceBondState = extras.getInt(BluetoothDevice.EXTRA_BOND_STATE);

        Log.d(TAG, "onHandleIntent: state change on device " + device.getName() + " [" + device.getAddress()
                + "], bond state: " + deviceBondState);

        if (!isTargetKeyboard(device))
            return;

        if (deviceBondState == BluetoothDevice.BOND_NONE) {
            handleGattDisconnection();
        }

    } else if (ACTION_KEYBOARD_UPDATE_CONFIRMED.equals(action)) {
        dismissUpdateNotification();

        if (mDfuStatus != DFU_STATE_INFO_READY || mDfuStatus == DFU_STATE_UPDATING) {
            Log.w(TAG, "onHandleIntent: DFP preparation not ready or DFU is in progress. ");
            changeDfuStatus(DFU_STATE_UPDATE_ABORTED);
            return;
        }

        String keyboardName = intent.getStringExtra(EXTRA_KEYBOARD_NAME);
        String keyboardAddress = intent.getStringExtra(EXTRA_KEYBOARD_ADDRESS);
        if (!mKeyboardName.equals(keyboardName) || !mKeyboardAddress.equals(keyboardAddress)) {
            Log.w(TAG, "onHandleIntent: No DFU service associated with " + keyboardName + " [" + keyboardAddress
                    + "]");
            return;
        }

        Log.d(TAG, "onHandleIntent: Start update process on " + keyboardName + " [" + keyboardAddress + "]");
        changeDfuStatus(DFU_STATE_SWITCHING_TO_DFU_MODE);

    } else if (ACTION_KEYBOARD_UPDATE_POSTPONED.equals(action)) {
        dismissUpdateNotification();
        // TODO(mcchou): Update the preference when the Settings keyboard entry is available.
    }
}

From source file:com.abplus.surroundcalc.billing.BillingHelper.java

public void launchPurchaseFlow(Activity activity, String sku, int requestCode,
        OnPurchaseFinishedListener listener, String extraData) {
    checkSetupDone("launchPurchaseFlow");
    asyncFlag.start("launchPurchaseFlow");
    Result result;// w w w  . j  av a2 s.com

    try {
        Bundle buyIntentBundle = connection.getBuyIntent(sku, extraData);
        int response = getResponseCodeFromBundle(buyIntentBundle);
        if (response != BILLING_RESPONSE_RESULT_OK) {
            result = new Result(response, "Unable to buy item");
            if (listener != null)
                listener.onPurchaseFinished(result, null);
        } else {
            PendingIntent intent = buyIntentBundle.getParcelable(RESPONSE_BUY_INTENT);
            this.requestCode = requestCode;
            purchaseListener = listener;
            activity.startIntentSenderForResult(intent.getIntentSender(), requestCode, new Intent(), 0, 0, 0);
        }
    } catch (IntentSender.SendIntentException e) {
        result = new Result(HELPER_SEND_INTENT_FAILED, "Failed to send intent.");
        if (listener != null)
            listener.onPurchaseFinished(result, null);
    } catch (RemoteException e) {
        result = new Result(HELPER_REMOTE_EXCEPTION, "Remote exception while starting purchase flow");
        if (listener != null)
            listener.onPurchaseFinished(result, null);
    }
}

From source file:com.mobileobservinglog.support.billing.DonationBillingHandler.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 w  w  .  j  a v  a 2  s  . co m
 * @param sku The sku of the item to purchase.
 * @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, int requestCode, OnPurchaseFinishedListener listener,
        String extraData) {
    Log.d("InAppPurchase", "Purchase Flow started -- handler");
    BillingHandlerResult result;
    purchaseListener = listener;
    try {
        checkSetupDone("launchPurchaseFlow");
    } catch (IllegalStateException e) {
        Log.d("InAppPurchase", "Setup was not done -- handler");
        result = new BillingHandlerResult(BILLING_RESPONSE_RESULT_BILLING_UNAVAILABLE,
                "Setup was not finished yet");
        if (listener != null)
            listener.onPurchaseFinished(result, null);
        return;
    }
    flagStartAsync("launchPurchaseFlow");

    try {
        Log.d("InAppPurchase", "Starting the purchase try -- handler");
        Bundle buyIntentBundle = service.getBuyIntent(3, context.getPackageName(), sku, ITEM_TYPE_INAPP,
                extraData);
        int response = getResponseCodeFromBundle(buyIntentBundle);
        if (response != BILLING_RESPONSE_RESULT_OK) {
            Log.d("InAppPurchase", "The response code from the bundle was not OK -- handler");

            //In case we have a managed item that needs to be consumed. Bit of a hack. But works for now
            if (response == BILLING_RESPONSE_RESULT_ITEM_ALREADY_OWNED) {
                String packageName = context.getPackageName();
                service.consumePurchase(3, packageName, "inapp:" + packageName + ":" + sku);
                buyIntentBundle = service.getBuyIntent(3, packageName, sku, ITEM_TYPE_INAPP, extraData);
            }
        }

        PendingIntent pendingIntent = buyIntentBundle.getParcelable(RESPONSE_BUY_INTENT);
        this.requestCode = requestCode;
        Log.d("InAppPurchase", "About to start the intent sender for result -- handler");
        if (pendingIntent != null) {
            act.startIntentSenderForResult(pendingIntent.getIntentSender(), requestCode, new Intent(),
                    Integer.valueOf(0), Integer.valueOf(0), Integer.valueOf(0));
            Log.d("InAppPurchase", "Done with the intent sender for result -- handler");
        } else {
            result = new BillingHandlerResult(BILLINGHELPER_SEND_INTENT_FAILED,
                    "Failed to send intent. We had a null pending intent");
            if (purchaseListener != null)
                purchaseListener.onPurchaseFinished(result, null);
        }
    } catch (SendIntentException e) {
        Log.d("InAppPurchase", "Caught a SendIntentException -- handler");
        e.printStackTrace();

        result = new BillingHandlerResult(BILLINGHELPER_SEND_INTENT_FAILED, "Failed to send intent.");
        if (purchaseListener != null)
            purchaseListener.onPurchaseFinished(result, null);
    } catch (RemoteException e) {
        Log.d("InAppPurchase", "Caught RemoteException -- handler");
        e.printStackTrace();

        result = new BillingHandlerResult(BILLINGHELPER_REMOTE_EXCEPTION,
                "Remote exception while starting purchase flow");
        if (purchaseListener != null)
            purchaseListener.onPurchaseFinished(result, null);
    }
}

From source file:com.carlrice.reader.fragment.EntryFragment.java

@Override
public View inflateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_entry, container, true);

    mCancelFullscreenBtn = rootView.findViewById(R.id.cancelFullscreenBtn);
    mCancelFullscreenBtn.setOnClickListener(new View.OnClickListener() {
        @Override/*w w w.ja v  a2  s . c  o m*/
        public void onClick(View view) {
            setImmersiveFullScreen(false);
        }
    });

    mEntryPager = (ViewPager) rootView.findViewById(R.id.pager);
    //mEntryPager.setPageTransformer(true, new DepthPageTransformer());
    mEntryPager.setAdapter(mEntryPagerAdapter);

    if (savedInstanceState != null) {
        mBaseUri = savedInstanceState.getParcelable(STATE_BASE_URI);
        mEntriesIds = savedInstanceState.getLongArray(STATE_ENTRIES_IDS);
        mInitialEntryId = savedInstanceState.getLong(STATE_INITIAL_ENTRY_ID);
        mCurrentPagerPos = savedInstanceState.getInt(STATE_CURRENT_PAGER_POS);
        mEntryPager.getAdapter().notifyDataSetChanged();
        mEntryPager.setCurrentItem(mCurrentPagerPos);
    }

    mEntryPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
        @Override
        public void onPageScrolled(int i, float v, int i2) {
        }

        @Override
        public void onPageSelected(int i) {
            mCurrentPagerPos = i;
            mEntryPagerAdapter.onPause(); // pause all webviews
            mEntryPagerAdapter.onResume(); // resume the current webview

            refreshUI(mEntryPagerAdapter.getCursor(i));
        }

        @Override
        public void onPageScrollStateChanged(int i) {
        }
    });

    disableSwipe();

    return rootView;
}