private void purchase() {
    if (isLoading) {
      BLog.v(TAG, "is Loading ...");
      return;
    }

    if (!MarketUtils.hasSDcard()) {
      Toast.makeText(mActivity, R.string.msg_no_sdcard, Toast.LENGTH_SHORT).show();
      return;
    }

    if (!DataConnectionUtils.testValidConnection(mActivity)) {
      Toast.makeText(mActivity, R.string.dlg_msg_no_active_connectivity, Toast.LENGTH_SHORT).show();
      //            showLoadMessage(R.string.dlg_msg_no_active_connectivity);
      return;
    }
    if (!AccountSession.isLogin() && !mData.isFree) {
      BasicActivity bac = (BasicActivity) getActivity();
      bac.login();
      return;
    }
    synchronized (mLocked) {
      isLoading = true;
    }

    if (mData.isFree || mData.purchased) {
      onPayed(null);
    } else {
      doPaying();
    }
  }
  private void doPaying() {
    if (mActivity != null && BasicActivity.class.isInstance(mActivity)) {
      ((BasicActivity) mActivity)
          .purchase(
              mData,
              new MarketPurchaseListener() {

                @Override
                public void onBillingFinished(boolean isSuccess, MarketBillingResult result) {
                  if (isSuccess) {
                    onPayed(result);
                  } else {
                    synchronized (mLocked) {
                      isLoading = false;
                    }

                    Message mds = mHandler.obtainMessage(PAYING_FAILED);
                    mds.getData().putString(MESSAGE, result.response);
                    mHandler.sendMessage(mds);
                  }
                }
              });
    }
  }
    @Override
    public void handleMessage(Message msg) {
      switch (msg.what) {
        case LOAD_END:
          {
            end();
            if (getActivity() == null) return;
            boolean suc = msg.getData().getBoolean(RESULT);
            if (suc) {
              refreshUI();
            } else {
              showLoadMessage(R.string.msg_loadi_failed);
            }
            break;
          }
        case DELETE_END:
          {
            // end();
            dismissProgress();
            if (getActivity() == null) return;
            boolean suc = msg.getData().getBoolean(RESULT);
            if (suc) {
              if (!TextUtils.isEmpty(mData.localUrl)) {
                File f = new File(mData.localUrl);
                f.delete();
              }
              downLoadHelper.deleteFile(product_id, version_code);
              refreshProductStatus(PRODUCT_STATUS_DOWNLOAD);
            } else {

            }
            break;
          }
        case MSG_ON_CHANGE:
          {
            if ((PRODUCT_STATUS == PRODUCT_STATUS_DOWNLOADING) && downLoadID != -1) {
              int[] bytesAndStatus = DownloadUtils.getBytesAndStatus(mActivity, downLoadID);
              updateView(bytesAndStatus[0], bytesAndStatus[1], bytesAndStatus[2]);
            }
            break;
          }
        case PURCHASE_END:
          {
            if (getActivity() == null) return;
            boolean suc = msg.getData().getBoolean(RESULT);
            if (suc) {
              if (mActivity != null && BasicActivity.class.isInstance(mActivity)) {
                ((BasicActivity) mActivity).consumeAsync();
              }
              String url = msg.getData().getString(URL);
              if (TextUtils.isEmpty(url)) {
                BLog.e("url is null");
              } else {
                mData.purchased = true;
                DownloadUtils downloadUtils = new DownloadUtils(mActivity.getApplicationContext());
                downLoadID = downloadUtils.download(url, mData.name, mData.product_id);
                if (downLoadID != -1) {
                  int[] bytesAndStatus = DownloadUtils.getBytesAndStatus(mActivity, downLoadID);
                  updateView(bytesAndStatus[0], bytesAndStatus[1], bytesAndStatus[2]);
                  refreshProductStatus(PRODUCT_STATUS_DOWNLOADING);
                  //
                  downLoadHelper.insert(mData, null, downLoadID, jsonString);
                  mDownloadOrDeleteButton.setText(R.string.action_downloading);
                } else {
                  Toast.makeText(mActivity, R.string.download_failed, Toast.LENGTH_SHORT).show();
                }
              }
            } else {
              //                    Toast.makeText(mActivity, R.string.purchase_failed,
              //                            Toast.LENGTH_SHORT).show();

            }
            break;
          }
        case PAYING_FAILED:
          {
            if (getActivity() == null) return;
            String respone = msg.getData().getString(MESSAGE);
            Toast.makeText(mActivity, respone, Toast.LENGTH_LONG).show();
            refreshProductStatus(PRODUCT_STATUS_PURCHASE);
            break;
          }
      }
    }