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.sdspikes.fireworks.FireworksActivity.java

@Override
public void onConnected(Bundle connectionHint) {
    Log.d(TAG, "onConnected() called. Sign in successful!");

    Log.d(TAG, "Sign-in succeeded.");

    // register listener so we are notified if we receive an invitation to play
    // while we are in the game
    Games.Invitations.registerInvitationListener(mGoogleApiClient, this);

    if (connectionHint != null) {
        Log.d(TAG, "onConnected: connection hint provided. Checking for invite.");
        Invitation inv = connectionHint.getParcelable(Multiplayer.EXTRA_INVITATION);
        if (inv != null && inv.getInvitationId() != null) {
            // retrieve and cache the invitation ID
            Log.d(TAG, "onConnected: connection hint has a room invite!");
            acceptInviteToRoom(inv.getInvitationId());
            return;
        }//www.  j a v  a 2s.c o  m
    }
    switchToMainScreen();

}

From source file:com.apptentive.android.sdk.module.engagement.interaction.fragment.MessageCenterFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    listViewSavedTopIndex = (savedInstanceState == null) ? -1 : savedInstanceState.getInt(LIST_TOP_INDEX);
    listViewSavedTopOffset = (savedInstanceState == null) ? 0 : savedInstanceState.getInt(LIST_TOP_OFFSET);
    composingViewSavedState = (savedInstanceState == null) ? null
            : savedInstanceState.getParcelable(COMPOSING_EDITTEXT_STATE);
    pendingWhoCardName = (savedInstanceState == null) ? null : savedInstanceState.getParcelable(WHO_CARD_NAME);
    pendingWhoCardEmail = (savedInstanceState == null) ? null
            : savedInstanceState.getParcelable(WHO_CARD_EMAIL);
    pendingWhoCardAvatarFile = (savedInstanceState == null) ? null
            : savedInstanceState.getString(WHO_CARD_AVATAR_FILE);
    pendingWhoCardMode = savedInstanceState != null && savedInstanceState.getBoolean(WHO_CARD_MODE);
    return inflater.inflate(R.layout.apptentive_message_center, container, false);
}

From source file:com.android.contacts.detail.ContactDetailLayoutController.java

private void initialize(Bundle savedState) {
    boolean fragmentsAddedToFragmentManager = true;
    mDetailFragment = (ContactDetailFragment) mFragmentManager
            .findFragmentByTag(ContactDetailViewPagerAdapter.ABOUT_FRAGMENT_TAG);
    mUpdatesFragment = (ContactDetailUpdatesFragment) mFragmentManager
            .findFragmentByTag(ContactDetailViewPagerAdapter.UPDATES_FRAGMENT_TAG);

    // If the detail fragment was found in the {@link FragmentManager} then we don't need to add
    // it again. Otherwise, create the fragments dynamically and remember to add them to the
    // {@link FragmentManager}.
    if (mDetailFragment == null) {
        mDetailFragment = new ContactDetailFragment();
        mUpdatesFragment = new ContactDetailUpdatesFragment();
        fragmentsAddedToFragmentManager = false;
    }//  www. ja  v  a 2s  .  com

    mDetailFragment.setListener(mContactDetailFragmentListener);
    NfcHandler.register(mActivity, mDetailFragment);

    // Read from savedState if possible
    int currentPageIndex = 0;
    if (savedState != null) {
        mContactUri = savedState.getParcelable(KEY_CONTACT_URI);
        mContactHasUpdates = savedState.getBoolean(KEY_CONTACT_HAS_UPDATES);
        currentPageIndex = savedState.getInt(KEY_CURRENT_PAGE_INDEX, 0);
    }

    switch (mLayoutMode) {
    case LayoutMode.VIEW_PAGER_AND_TAB_CAROUSEL: {
        // Inflate 2 view containers to pass in as children to the {@link ViewPager},
        // which will in turn be the parents to the mDetailFragment and mUpdatesFragment
        // since the fragments must have the same parent view IDs in both landscape and
        // portrait layouts.
        mDetailFragmentView = mLayoutInflater.inflate(R.layout.contact_detail_about_fragment_container,
                mViewPager, false);
        mUpdatesFragmentView = mLayoutInflater.inflate(R.layout.contact_detail_updates_fragment_container,
                mViewPager, false);

        mViewPagerAdapter = new ContactDetailViewPagerAdapter();
        mViewPagerAdapter.setAboutFragmentView(mDetailFragmentView);
        mViewPagerAdapter.setUpdatesFragmentView(mUpdatesFragmentView);

        mViewPager.addView(mDetailFragmentView);
        mViewPager.addView(mUpdatesFragmentView);
        mViewPager.setAdapter(mViewPagerAdapter);
        mViewPager.setOnPageChangeListener(mOnPageChangeListener);

        if (!fragmentsAddedToFragmentManager) {
            FragmentTransaction transaction = mFragmentManager.beginTransaction();
            transaction.add(R.id.about_fragment_container, mDetailFragment,
                    ContactDetailViewPagerAdapter.ABOUT_FRAGMENT_TAG);
            transaction.add(R.id.updates_fragment_container, mUpdatesFragment,
                    ContactDetailViewPagerAdapter.UPDATES_FRAGMENT_TAG);
            transaction.commitAllowingStateLoss();
            mFragmentManager.executePendingTransactions();
        }

        mTabCarousel.setListener(mTabCarouselListener);
        mTabCarousel.restoreCurrentTab(currentPageIndex);
        mDetailFragment.setVerticalScrollListener(new VerticalScrollListener(TAB_INDEX_DETAIL));
        mUpdatesFragment.setVerticalScrollListener(new VerticalScrollListener(TAB_INDEX_UPDATES));
        mViewPager.setCurrentItem(currentPageIndex);
        break;
    }
    case LayoutMode.TWO_COLUMN: {
        if (!fragmentsAddedToFragmentManager) {
            FragmentTransaction transaction = mFragmentManager.beginTransaction();
            transaction.add(R.id.about_fragment_container, mDetailFragment,
                    ContactDetailViewPagerAdapter.ABOUT_FRAGMENT_TAG);
            transaction.add(R.id.updates_fragment_container, mUpdatesFragment,
                    ContactDetailViewPagerAdapter.UPDATES_FRAGMENT_TAG);
            transaction.commitAllowingStateLoss();
            mFragmentManager.executePendingTransactions();
        }
        break;
    }
    case LayoutMode.FRAGMENT_CAROUSEL:
    case LayoutMode.TWO_COLUMN_FRAGMENT_CAROUSEL: {
        // Add the fragments to the fragment containers in the carousel using a
        // {@link FragmentTransaction} if they haven't already been added to the
        // {@link FragmentManager}.
        if (!fragmentsAddedToFragmentManager) {
            FragmentTransaction transaction = mFragmentManager.beginTransaction();
            transaction.add(R.id.about_fragment_container, mDetailFragment,
                    ContactDetailViewPagerAdapter.ABOUT_FRAGMENT_TAG);
            transaction.add(R.id.updates_fragment_container, mUpdatesFragment,
                    ContactDetailViewPagerAdapter.UPDATES_FRAGMENT_TAG);
            transaction.commitAllowingStateLoss();
            mFragmentManager.executePendingTransactions();
        }

        mFragmentCarousel.setFragmentViews((FrameLayoutWithOverlay) mDetailFragmentView,
                (FrameLayoutWithOverlay) mUpdatesFragmentView);
        mFragmentCarousel.setCurrentPage(currentPageIndex);

        break;
    }
    }

    // Setup the layout if we already have a saved state
    if (savedState != null) {
        if (mContactHasUpdates) {
            showContactWithUpdates(false);
        } else {
            showContactWithoutUpdates();
        }
    }
}

From source file:jp.app_mart.billing.AppmartHelper.java

/**
 * ??//from w  ww  . ja v  a2s . co m
 * @param act
 * @param sku
 * @param requestCode
 * @param listener
 */
public void launchPurchaseFlow(final Activity act, final String sku, final int requestCode,
        final OnAppmartPurchaseFinishedListener listener) {

    final String itemType = "0";

    checkSetupDone("launchPurchaseFlow");

    (new Thread(new Runnable() {
        public void run() {

            logDebug(mContext.getString(R.string.get_information) + sku);
            AppmartResult result;

            try {
                Context context = mContext.getApplicationContext();
                String dataEncrypted = createEncryptedData(sku, mDeveloperId, mLicenseKey, mSignatureBase64);
                Bundle bundleForPaymentInterface = mService.prepareForBillingService(mAppId, dataEncrypted);

                if (bundleForPaymentInterface == null) {

                    logError(mContext.getString(R.string.bundle_unreachable));

                    result = new AppmartResult(APPMARTHELPER_GET_BUNDLE_FOR_PAYMENT_FAILED,
                            mContext.getString(R.string.bundle_unreachable));

                    if (listener != null)
                        listener.onAppmartPurchaseFinished(result, null);
                    return;
                }

                int response = bundleForPaymentInterface.getInt("resultCode");

                if (response != BILLING_RESPONSE_RESULT_OK) {

                    logError(mContext.getString(R.string.response_code_error) + response);
                    result = new AppmartResult(response, mContext.getString(R.string.product_not_purchasable));

                    if (listener != null)
                        listener.onAppmartPurchaseFinished(result, null);
                    return;
                }

                // ?
                resultKey = bundleForPaymentInterface.getString("resultKey");

                PendingIntent pIntent = bundleForPaymentInterface.getParcelable("appmart_pending_intent");
                mPurchaseListener = listener;
                mPurchasingItemType = itemType;
                mPurchasingSku = sku;
                pIntent.send(context, 0, new Intent());

            } catch (RemoteException e) {

                logError(mContext.getString(R.string.failed_prepare_bill_service));

                result = new AppmartResult(APPMARTHELPER_SEND_INTENT_FAILED,
                        mContext.getString(R.string.failed_sending_intent));

                if (listener != null)
                    listener.onAppmartPurchaseFinished(result, null);

            } catch (PendingIntent.CanceledException e) {

                logError(mContext.getString(R.string.failed_sending_intent));

                result = new AppmartResult(APPMARTHELPER_SEND_INTENT_FAILED,
                        mContext.getString(R.string.failed_sending_intent));

                if (listener != null)
                    listener.onAppmartPurchaseFinished(result, null);
            }
        }
    })).start();
}

From source file:com.afstd.sqlitecommander.app.filemanager.FMFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_fm, container, false);
    fListView = (ListView) view.findViewById(R.id.list);

    tvPath = (TextView) view.findViewById(R.id.tvPath);

    path = savedInstanceState != null ? savedInstanceState.getString(CURR_DIR) : FMUtils.FILE_SEPARATOR;//Environment.getExternalStorageDirectory().toString();
    tvPath.setText(path);//w w  w  .  j  a  v  a2 s  .  c  om

    fListView.setDrawingCacheEnabled(true);
    fAdapter = new FMAdapter(getActivity(), new ArrayList<FMEntry>());

    fListView.setAdapter(fAdapter);

    ls(path, false);

    fListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> arg0, View arg1, int pos, long arg3) {
            FMEntry entry = fAdapter.getItem(pos);
            if (entry.getType() == FMEntry.TYPE_DIRECTORY || entry.getType() == FMEntry.TYPE_DIRECTORY_LINK) {
                Parcelable state = fListView.onSaveInstanceState();
                listScrollStates.put(path, state);
                backstack.add(path);
                path = entry.getType() == FMEntry.TYPE_DIRECTORY_LINK ? entry.getLink() : entry.getPath();
                validatePath();
                ls(path, false);
            } else if (entry.getType() == FMEntry.TYPE_FILE || entry.getType() == FMEntry.TYPE_LINK) {
                SQLiteCMDActivity.start(getActivity(), entry.getPath(), true);
            }
        }
    });
    if (savedInstanceState != null) {
        backstack = (LinkedList<String>) savedInstanceState.getSerializable(BACKSTACK);
        Parcelable listState = savedInstanceState.getParcelable("list_position");
        if (listState != null)
            fListView.post(new RestoreListStateRunnable(listState));
    }
    return view;
}

From source file:com.adarshahd.indianrailinfo.donate.PNRStat.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.layout_pnr_status);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setTitle("PNR Status");
    mUtil = Util.getUtil(this);
    mBtnPNR = ((Button) findViewById(R.id.id_btn_get_pnr_sts));
    mBtnPNR.setOnClickListener(this);
    pnrDB = PNRDatabase.getPNRDatabase(this);
    mPNRList = new ArrayList<String>();
    mPNRList = pnrDB.getPNRs();//from   ww  w  .  jav a2 s  . c  o m
    mACTPNR = (AutoCompleteTextView) findViewById(R.id.id_act_pnr_sts);
    mACTPNR.setAdapter(new ArrayAdapter<String>(this, R.layout.layout_dropdown_list, mPNRList));
    mPref = PreferenceManager.getDefaultSharedPreferences(this);
    isWaitingList = false;

    if (savedInstanceState != null) {
        if (!mPNRNumber.equals("")) {
            if (!mUtil.isConnected()) {
                mFrameLayout = null;
                mFrameLayout = (FrameLayout) findViewById(R.id.id_fl_pnr);
                readAndShowOfflinePNRStatus();
                return;
            }
            mFrameLayout = null;
            mFrameLayout = (FrameLayout) findViewById(R.id.id_fl_pnr);

            mPassengerDetails = savedInstanceState.getParcelable("PSN");
            mTrainDetails = savedInstanceState.getParcelable("TRAIN");
            mPageResult = savedInstanceState.getString("PAGE");
            if (mPageResult == null) {
                return;
            }

            mTextViewPNRSts = null;
            mTextViewPNRSts = new TextView(mActivity);
            mTextViewPNRSts.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                    ViewGroup.LayoutParams.WRAP_CONTENT));
            mTextViewPNRSts.setGravity(Gravity.CENTER_HORIZONTAL);
            mTextViewPNRSts.setTextColor(Color.RED);

            createTableLayoutTrnDtls();
            createTableLayoutPsnDtls();
            try {
                combineTrainAndPsnDetails();
            } catch (Exception e) {
                Log.e("PNRStat Error:", "Error creating table layout. Please try again later!");
            }
            return;
        }
    }

    mActivity = this;
    mFrameLayout = (FrameLayout) findViewById(R.id.id_fl_pnr);
    mBtnPNR = ((Button) findViewById(R.id.id_btn_get_pnr_sts));
    mBtnPNR.setOnClickListener(this);
    mTextViewPNRSts = new TextView(mActivity);
    mTextViewPNRSts.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));
    mTextViewPNRSts.setGravity(Gravity.CENTER_HORIZONTAL);
    mTextViewPNRSts.setTextColor(Color.RED);
}

From source file:at.alladin.rmbt.android.map.RMBTMapFragment.java

@Override
public void onStart() {
    super.onStart();
    geoLocation.start();//www  .  j  a  v a 2s  .  c  o m

    gMap = getMap();
    if (gMap != null) {
        if (firstStart) {
            final Bundle bundle = getArguments();

            firstStart = false;

            final UiSettings uiSettings = gMap.getUiSettings();
            uiSettings.setZoomControlsEnabled(false); // options.isEnableAllGestures());
            uiSettings.setMyLocationButtonEnabled(false);
            uiSettings.setCompassEnabled(false);
            uiSettings.setRotateGesturesEnabled(false);
            uiSettings.setScrollGesturesEnabled(options.isEnableAllGestures());

            gMap.setTrafficEnabled(false);
            gMap.setIndoorEnabled(false);

            LatLng latLng = MapProperties.DEFAULT_MAP_CENTER;
            float zoom = MapProperties.DEFAULT_MAP_ZOOM;

            final Location lastKnownLocation = geoLocation.getLastKnownLocation();
            if (lastKnownLocation != null) {
                latLng = new LatLng(lastKnownLocation.getLatitude(), lastKnownLocation.getLongitude());
                zoom = MapProperties.DEFAULT_MAP_ZOOM_LOCATION;
            }

            if (bundle != null) {
                final LatLng initialCenter = bundle.getParcelable("initialCenter");
                if (initialCenter != null) {
                    latLng = initialCenter;
                    zoom = MapProperties.POINT_MAP_ZOOM;

                    if (balloonMarker != null)
                        balloonMarker.remove();
                    balloonMarker = gMap.addMarker(new MarkerOptions().position(initialCenter).draggable(false)
                            .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE)));
                }
            }
            gMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng, zoom));

            gMap.setLocationSource(new LocationSource() {

                @Override
                public void deactivate() {
                    onLocationChangedListener = null;
                }

                @Override
                public void activate(OnLocationChangedListener listener) {
                    onLocationChangedListener = listener;
                }
            });

            gMap.setMyLocationEnabled(true);
            gMap.setOnMyLocationChangeListener(this);
            gMap.setOnMarkerClickListener(this);
            gMap.setOnMapClickListener(this);
            gMap.setInfoWindowAdapter(this);
            gMap.setOnInfoWindowClickListener(this);

            final Location myLocation = gMap.getMyLocation();
            if (myLocation != null)
                onMyLocationChange(myLocation);
        }

        final RMBTMainActivity activity = (RMBTMainActivity) getActivity();
        gMap.setMapType(
                activity.getMapTypeSatellite() ? GoogleMap.MAP_TYPE_SATELLITE : GoogleMap.MAP_TYPE_NORMAL);

        final Map<String, String> mapOptions = ((MapProperties) getActivity()).getCurrentMapOptions();

        boolean needHeatmapOverlay = false;
        boolean needPointsOverlay = false;
        boolean needShapesOverlay = false;

        final MapOverlay mapOverlayType = activity.getMapOverlayType();
        System.out.println(
                "addition parameters for " + mapOverlayType + " = " + mapOverlayType.getAdditionalParameters());
        mapOptions.putAll(mapOverlayType.getAdditionalParameters());

        final String mapType = activity.getCurrentMainMapType();
        if (mapOverlayType == MapOverlay.AUTO) {
            gMap.setOnCameraChangeListener(this);
            needPointsOverlay = true;
            if (mapType != null && mapType.equals("browser")) {
                needShapesOverlay = true;
                needHeatmapOverlay = false;
            } else
                needShapesOverlay = false;
            needHeatmapOverlay = true;
        } else {
            gMap.setOnCameraChangeListener(null);
            switch (mapOverlayType) {
            case HEATMAP:
                needPointsOverlay = false;
                needShapesOverlay = false;
                needHeatmapOverlay = true;
                break;

            case POINTS:
                needPointsOverlay = true;
                needShapesOverlay = false;
                needHeatmapOverlay = false;
                break;

            case REGIONS:
            case SETTLEMENTS:
            case MUNICIPALITY:
            case WHITESPOTS:
                gMap.setOnCameraChangeListener(this);
                needPointsOverlay = true;
                needShapesOverlay = true;
                needHeatmapOverlay = false;
                break;

            default:
                break;
            }
        }

        if (!options.isEnableOverlay()) {
            needHeatmapOverlay = false;
            needShapesOverlay = false;
            needPointsOverlay = false;
        }

        final String protocol = ConfigHelper.isMapSeverSSL(getActivity()) ? "https" : "http";
        final String host = ConfigHelper.getMapServerName(getActivity());
        final int port = ConfigHelper.getMapServerPort(getActivity());

        if (needHeatmapOverlay) {
            final RMBTTileSourceProvider heatmapProvider = new RMBTTileSourceProvider(protocol, host, port,
                    MapProperties.TILE_SIZE);
            heatmapProvider.setOptionMap(mapOptions);
            heatmapProvider.setPath(mapOverlayType.getPath());
            heatmapOverlay = gMap
                    .addTileOverlay(new TileOverlayOptions().tileProvider(heatmapProvider).zIndex(100000000));
        }

        if (needShapesOverlay) {
            final RMBTTileSourceProvider shapesProvider = new RMBTTileSourceProvider(protocol, host, port,
                    MapProperties.TILE_SIZE);
            shapesProvider.setOptionMap(mapOptions);
            shapesProvider.setPath(mapOverlayType.getPath());
            shapesOverlay = gMap
                    .addTileOverlay(new TileOverlayOptions().tileProvider(shapesProvider).zIndex(100000000));
        }

        if (needPointsOverlay) {
            final RMBTTileSourceProvider pointsProvider = new RMBTTileSourceProvider(protocol, host, port,
                    MapProperties.TILE_SIZE * 2);
            pointsProvider.setOptionMap(mapOptions);
            pointsProvider.setPath(mapOverlayType.getPath());
            pointsOverlay = gMap
                    .addTileOverlay(new TileOverlayOptions().tileProvider(pointsProvider).zIndex(200000000));

            if ((mapOverlayType == MapOverlay.AUTO) || (mapOverlayType.isShapeLayer()))
                onCameraChange(gMap.getCameraPosition());
        }
    }

    //gMap.getUiSettings().setAllGesturesEnabled(options.isEnableAllGestures());
    //gMap.getUiSettings().setCompassEnabled(false);
}

From source file:com.apptentive.android.sdk.module.messagecenter.view.MessageCenterActivityContent.java

@Override
public void doOnCreate(Activity activity, Bundle onSavedInstanceState) {
    activity.setContentView(R.layout.apptentive_message_center);
    viewActivity = activity;/*from   www .  j  a va 2  s .  c o m*/

    listViewSavedTopIndex = (onSavedInstanceState == null) ? -1 : onSavedInstanceState.getInt(LIST_TOP_INDEX);
    listViewSavedTopOffset = (onSavedInstanceState == null) ? 0 : onSavedInstanceState.getInt(LIST_TOP_OFFSET);
    composingViewSavedState = (onSavedInstanceState == null) ? null
            : onSavedInstanceState.getParcelable(COMPOSING_EDITTEXT_STATE);
    pendingWhoCardName = (onSavedInstanceState == null) ? null
            : onSavedInstanceState.getParcelable(WHO_CARD_NAME);
    pendingWhoCardEmail = (onSavedInstanceState == null) ? null
            : onSavedInstanceState.getParcelable(WHO_CARD_EMAIL);
    pendingWhoCardAvatarFile = (onSavedInstanceState == null) ? null
            : onSavedInstanceState.getString(WHO_CARD_AVATAR_FILE);
    pendingWhoCardMode = (onSavedInstanceState == null) ? 0 : onSavedInstanceState.getInt(WHO_CARD_MODE);
    String contextualMessageBody = interaction.getContextualMessageBody();
    contextualMessage = CompoundMessage.createAutoMessage(null, contextualMessageBody);

    setup();

    // This listener will run when messages are retrieved from the server, and will start a new thread to update the view.
    MessageManager.addInternalOnMessagesUpdatedListener(this);
    // Give the MessageCenterView a callback when a message is sent.
    MessageManager.setAfterSendMessageListener(this);
    // Needed to prevent the window from being pushed up when a text input area is focused.
    activity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_UNCHANGED
            | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);

    if (listViewSavedTopIndex == -1) {
        messageCenterViewHandler.sendEmptyMessageDelayed(MSG_SCROLL_TO_BOTTOM, DEFAULT_DELAYMILLIS);
    }
}

From source file:com.yourkey.billing.util.InAppBilling.java

private void serviceConnected(IBinder service) {
    // get service pointer
    inAppBillingService = IInAppBillingService.Stub.asInterface(service);

    // make sure billing is supported for itemType (one-time or subscription)
    try {/*w w  w  .  ja  va2  s. c  o m*/
        // check for in-app billing v3 support
        int result = inAppBillingService.isBillingSupported(IN_APP_BILLING_API_VERSION, packageName, itemType);
        if (result != RESULT_OK) {
            // unbind service
            dispose();

            // call purchase listener with error message
            inAppBillingListener.inAppBillingFailure(errorMessage(PLAY_STORE_PURCHASE_NOT_SUPPORTED, result));
            return;
        }
    }

    // system exception executing isBillingSupported method
    catch (Exception e) {
        // unbind service
        dispose();

        // call purchase listener with error message
        inAppBillingListener.inAppBillingFailure(exceptionMessage(PLAY_STORE_PURCHASE_NOT_SUPPORTED, e));
        return;
    }

    // test to make sure item sku is valid
    String resultMsg = testItemSku();
    if (resultMsg != null) {
        // unbind service
        dispose();

        // call purchase listener with error message
        inAppBillingListener.inAppBillingFailure(resultMsg);
        return;
    }

    // Get all items owned by this user for this application
    // and test if user already owns this item.
    // If we are in consume mode and item is owned, consume the item

    /*   
       resultMsg = testItemOwned();
       if(!resultMsg.equals(RESULT_TEXT_ITEM_ALREADY_OWNED) && !resultMsg.equals(RESULT_TEXT_ITEM_NOT_OWNED))
          {
          // unbind service
           dispose();
            
           // call purchase listener with error message
          inAppBillingListener.inAppBillingFailure(resultMsg);
          return;
          }
            
       // user owns this item
       if(resultMsg.equals(RESULT_TEXT_ITEM_ALREADY_OWNED))
          {
          // unbind service
           dispose();
            
           // for consume mode
           if(consumeActivity)
             inAppBillingListener.inAppBillingConsumeSuccsess();
                   
           // for buy mode 
           else
             inAppBillingListener.inAppBillingItemAlreadyOwned();
                   
           // exit
          return;
          }*/

    // consume and user does not own this item
    if (consumeActivity) {
        // unbind service
        dispose();

        // call listener
        inAppBillingListener.inAppBillingItemNotOwned();
        return;
    }

    try {
        // build intent bundle for the purpose of purchase itemSku
        Bundle buyIntentBundle = inAppBillingService.getBuyIntent(IN_APP_BILLING_API_VERSION, packageName,
                itemSku, itemType, PURCHASE_EXTRA_DATA);

        // buyIntentBundle has two key value pairs
        // RESPONSE_CODE with standard response code
        // BUY_INTENT with PendingIntent to start the purchase flow
        int buyResult = getResponseCodeFromBundle(buyIntentBundle);
        if (buyResult != RESULT_OK) {
            // unbind service
            dispose();

            // error message
            inAppBillingListener
                    .inAppBillingFailure(errorMessage(PLAY_STORE_PURCHASE_FAILED + resultMessage(buyResult)));
            return;
        }

        // send Google Play Store request to purchase itemSku
        // when the purchase process is completed, the system will call onActivityResult method in parent activity
        PendingIntent pendingIntent = buyIntentBundle.getParcelable(RESPONSE_BUY_INTENT);
        parentActivity.startIntentSenderForResult(pendingIntent.getIntentSender(), purchaseRequestCode,
                new Intent(), Integer.valueOf(0), Integer.valueOf(0), Integer.valueOf(0));
    }

    // trap exceptions
    catch (Exception e) {
        // unbind service
        dispose();

        // error message
        inAppBillingListener.inAppBillingFailure(exceptionMessage(PLAY_STORE_PURCHASE_FAILED, e));
        return;
    }

    // exit
    return;
}