Example usage for android.os Message Message

List of usage examples for android.os Message Message

Introduction

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

Prototype

public Message() 

Source Link

Document

Constructor (but the preferred way to get a Message is to call #obtain() Message.obtain() ).

Usage

From source file:com.oasis.sdk.activity.GooglePlayBillingActivity.java

/**
 * ?//www . j  a  va 2  s .c o  m
 * */
private void consumeOldOrder(Purchase purchase, final int code, final int isEnd) {
    mHelper.consumeAsync(purchase, new IabHelper.OnConsumeFinishedListener() {
        public void onConsumeFinished(Purchase p, IabResult result) {
            BaseUtils.logDebug(TAG, "consumeOldOrder finished. Purchase: " + p + ", result: " + result);

            // if we were disposed of in the meantime, quit.
            if (mHelper == null)
                return;

            Message msg = null;
            if (result.isSuccess()) {
                BaseUtils.logDebug(TAG,
                        "consumeOldOrder successful. Provisioning. Purchase.orderID=" + p.getOrderId());
                //                  case 1000000://???
                //                case 1000002://?????2?

                if (GoogleBillingUtils.deletePurchase(p.getOrderId()) > 0) {
                    if (code == 1000000 || code == 1000002) { // ????
                        msg = new Message();
                        msg.what = 103;//??
                        msg.obj = p;
                        myHandler.sendMessage(msg);

                        msg = new Message();
                        msg.what = 102;// 
                        msg.obj = p;
                        msg.arg1 = code;
                        myHandler.sendMessage(msg);
                    }
                } else {
                    BaseUtils.logError(TAG, "delete by orderid=" + p.getOrderId());
                }
            } else {
                if (result.getResponse() == IabHelper.BILLING_RESPONSE_RESULT_ITEM_NOT_OWNED) {
                    if (GoogleBillingUtils.deletePurchase(p.getOrderId()) > 0) {
                        //                      ???
                        //                     msg = new Message();
                        //                      msg.what = 102;// 
                        //                      msg.obj = p;
                        //                      myHandler.sendMessage(msg);
                    } else {
                        BaseUtils.logError(TAG, "delete by orderid=" + p.getOrderId());
                    }
                }
            }

            myHandler.sendEmptyMessage(98);//??
        }
    });
}

From source file:org.huxizhijian.hhcomicviewer.ui.entry.ComicDetailsActivity.java

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
        @NonNull int[] grantResults) {
    switch (requestCode) {
    case CHECK_SD_WRITE_PERMISSION:
        if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
            // permission was granted, yay! Do the contacts-related task you need to do.
            if (mSelectedChapters != null && mSelectedChapters.size() != 0) {
                int position = -1;
                List<Integer> positionList = new ArrayList<>();
                ComicChapter Chapter = null;
                for (String volName : mSelectedChapters) {
                    position = mComic.getChapterName().indexOf(volName);
                    positionList.add(position);
                }/* ww w.  j av  a  2s  .co m*/
                //?
                Collections.sort(positionList);
                for (int i = 0; i < positionList.size(); i++) {
                    position = positionList.get(i);
                    Chapter = new ComicChapter(mComic.getTitle(), mComic.getCid(),
                            mComic.getChapterId().get(position), mComic.getChapterName().get(position),
                            mComic.getServerId());
                    Message msg = new Message();
                    msg.what = Constants.MSG_DOWNLOAD;
                    msg.obj = Chapter;
                    //??10ms
                    mHandler.sendMessageDelayed(msg, 10 * i);
                }
                mSelectedChapters = null;
            }
            //.nomedia
            try {
                CommonUtils.createNomediaIfAllow(getApplicationContext());
            } catch (IOException e) {
                e.printStackTrace();
            }
        } else {
            // permission denied, boo! Disable the functionality that depends on this permission.
            return;
        }
        break;
    }
    super.onRequestPermissionsResult(requestCode, permissions, grantResults);
}

From source file:opensource.zeocompanion.ZeoCompanionApplication.java

public static void deleteAlertLine(long id) {
    CompanionAlertRec.removeFromDB(ZeoCompanionApplication.mDatabaseHandler, id);

    // inform the Main Activity so it can changes its menus; must be done via messaging
    if (MainActivity.instance != null) {
        Message msg = new Message();
        msg.what = ZeoCompanionApplication.MESSAGE_MAIN_UPDATE_MENU;
        MainActivity.instance.mHandler.sendMessage(msg);
    }//from ww w .  j  a v a2  s  .  c  o  m
}

From source file:com.oasis.sdk.activity.GooglePlayBillingActivity.java

private void consume(Purchase purchase, final int code) {
    mHelper.consumeAsync(purchase, new IabHelper.OnConsumeFinishedListener() {
        public void onConsumeFinished(Purchase p, IabResult result) {
            BaseUtils.logDebug(TAG, "Consumption finished. Purchase: " + p + ", result: " + result);

            // if we were disposed of in the meantime, quit.
            if (mHelper == null)
                return;

            if (result.isFailure()) {
                BaseUtils.logError(TAG,// w  w w.j  ava2 s .co m
                        "Error while consuming: " + IabHelper.getResponseDesc(result.getResponse()));
                if (code == -1) {// ??
                    if (result.getResponse() == IabHelper.BILLING_RESPONSE_RESULT_ITEM_NOT_OWNED) {// ? item not owned,??
                        //                         queryInventory();
                        myHandler.sendEmptyMessage(101);
                        return;
                    }
                    //????
                    Message msg = new Message();
                    msg.what = 0;
                    msg.obj = getResources()
                            .getString(BaseUtils.getResourceValue("string", "oasisgames_sdk_pay_error_fail"));
                    myHandler.sendMessage(msg);
                    return;
                }
            }

            if (result.isSuccess()) {
                BaseUtils.logDebug(TAG,
                        "Consumption successful. Provisioning. Purchase.orderID=" + p.getOrderId());
                //                  case 1000000://???
                //                case 1000002://?????2?

                if (GoogleBillingUtils.deletePurchase(p.getOrderId()) > 0) {// ??
                    if (code == 1000000 || code == 1000002) { // ????
                        Message msg = new Message();
                        msg = new Message();
                        msg.what = 102;// 
                        msg.obj = p;
                        msg.arg1 = code;
                        myHandler.sendMessage(msg);
                    }
                } else {
                    BaseUtils.logError(TAG, "delete by orderid=" + p.getOrderId());
                }
            }
            if (code == -1) {// ????
                //                   launchPurchaseFlow();
                //                   queryInventory();
                if (isPageClose()) {
                    isPageCloseHandler();
                    return;
                }
                myHandler.sendEmptyMessage(101);
                return;
            }
            Message msg = new Message();
            msg.what = HANDLER_SUCECCES;
            msg.arg1 = code;
            myHandler.sendMessage(msg);
            BaseUtils.logDebug(TAG, "End consumption flow.");
        }
    });
}

From source file:com.nbplus.iotlib.IoTInterface.java

private void sendMessageToService(int what, Bundle b) {
    // Now that we have the service messenger, lets send our messenger
    Message msg = new Message();
    msg.what = what;//from   ww  w .j  a  v a 2s .  c o  m

    /*
     * In case we would want to send extra data, we could use Bundles:
     * Bundle b = new Bundle(); b.putString("key", "hello world");
     * msg.setData(b);
     */
    if (b == null) {
        b = new Bundle();

        IoTHandleData data = new IoTHandleData();
        b.putParcelable(IoTServiceCommand.KEY_DATA, data);
    }
    b.putString(IoTServiceCommand.KEY_MSGID, IoTServiceCommand.generateMessageId(mCtx));
    msg.setData(b);

    try {
        mServiceMessenger.send(msg);
    } catch (RemoteException e) {
        e.printStackTrace();
    }
}

From source file:com.insthub.O2OMobile.Activity.D1_OrderActivity.java

/**
 * ?/*from ww  w . j av a  2  s . co  m*/
 * @param order
 */
private void setOrderDate(final ORDER_INFO order) {
    if (order.employer != null && order.employer.avatar != null && order.employer.avatar.thumb != null) {
        mImageLoader.displayImage(order.employer.avatar.thumb, mOrderEmployerAvatar, O2OMobile.options_head);
    }
    mOrderEmployerAvatar.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            Intent intent = new Intent(D1_OrderActivity.this, F0_ProfileActivity.class);
            intent.putExtra(F0_ProfileActivity.USER_ID, order.employer.id);
            startActivity(intent);
        }
    });
    if (order.employer != null && order.employer.nickname != null) {
        mOrderEmployerName.setText(order.employer.nickname);
    }
    if (order.created_at != null) {
        mOrderTime.setText(TimeUtil.timeAgo(order.created_at));
    }
    if (order.order_sn != null) {
        mOrderSn.setText(order.order_sn);
    }
    if (order.service_type != null && order.service_type.title != null) {
        mOrderServiceType.setText(order.service_type.title);
    }
    if (order.appointment_time != null) {
        mOrderAppointmentTime.setText(order.appointment_time);
    }
    if (order.location != null && order.location.name != null) {
        mOrderLocation.setText(order.location.name);
    }
    if (order.offer_price != null) {
        mOrderPrice.setText(Utils.formatBalance(order.offer_price) + getString(R.string.yuan));
    }
    if (order.content != null && order.content.text != null && !order.content.text.equals("")) {
        mOrderContentText.setText(order.content.text);
    }
    if (order.content != null && order.content.voice != null) {
        if (!order.content.voice.equals("")) {
            mOrderContentVoiceView.setVisibility(View.VISIBLE);
            mOrderContentVoiceTime.setText(order.duration + "'");

            LayoutParams layoutParams_icon = (LayoutParams) mOrderContentVoiceView.getLayoutParams();
            layoutParams_icon.width = mWidthPixels / 6 + order.duration * 3;
            layoutParams_icon.height = mWidthPixels / 12;
            mOrderContentVoiceView.setLayoutParams(layoutParams_icon);

        }
        mOrderContentVoiceView.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                if (mPlayer == null) {
                    mOrderContentVoiceIcon.setImageResource(R.anim.voice_play_animation);
                    mAnimationDrawable = (AnimationDrawable) mOrderContentVoiceIcon.getDrawable();
                    mAnimationDrawable.setOneShot(false);
                    mAnimationDrawable.start();

                    Message msg = new Message();
                    msg.what = PLAY_VOICE;
                    msg.obj = order;
                    handler.sendMessage(msg);
                } else {
                    mPlayer.release();
                    mPlayer = null;
                    mAnimationDrawable.stop();
                    mOrderContentVoiceIcon.setImageResource(R.drawable.d8_btn_playing_2);
                }
            }
        });
    }
    mOrderStatus.setText(StringUtils.getOrderStatusName(order.order_status));
}

From source file:com.oasis.sdk.activity.GooglePlayBillingActivity.java

/**
 * ??//from  w  w  w  .j  a  va 2 s  . c o  m
 */
private void check(final Purchase purchase) {
    new Thread(new Runnable() {

        @Override
        public void run() {
            Message msg = new Message();
            int res = -1;
            try {
                res = HttpService.instance().checkPurchaseForGoogle(purchase, GoogleBillingUtils.SEPARATE);
                switch (res) {
                case 1000000://???
                case 1000002://?????2?
                case 1000006://?Google??
                case 1000001://sign?????
                    BaseUtils.logDebug(TAG, "Code=" + res + "; Start consume." + purchase.toString());

                    msg.what = 100;
                    msg.arg1 = res;
                    msg.obj = purchase;
                    myHandler.sendMessage(msg);
                    break;

                case 1000100://
                case 1000004://ProductID?BUG
                    checkAndAddPurchase(purchase);
                    myHandler.sendEmptyMessage(HANDLER_FAIL);
                    break;

                case 1000003://??-Google?
                case 1000005://????
                default:
                    msg.what = HANDLER_EXCEPTION;
                    msg.obj = purchase;
                    myHandler.sendMessage(msg);// retry
                    break;
                }
            } catch (OasisSdkException e) {// oas?2???
                msg.what = HANDLER_EXCEPTION;
                msg.obj = purchase;
                myHandler.sendMessage(msg);// retry
            } finally {
                try {
                    String[] info = purchase.getDeveloperPayload().split(GoogleBillingUtils.SEPARATE);

                    // ?Mdata???
                    List<String> parameters = new ArrayList<String>();
                    parameters.add("\"uid\":\"" + info[0] + "\"");
                    parameters.add("\"roleid\":\"" + info[2] + "\"");
                    parameters.add("\"serverid\":\"" + info[1] + "\"");
                    if (info.length >= 6 && ("android".equalsIgnoreCase(info[5])
                            || "all".equalsIgnoreCase(info[5]) || "test".equalsIgnoreCase(info[5])))
                        parameters.add("\"servertype\":\"" + info[5] + "\"");
                    else
                        parameters.add("\"servertype\":\"\"");
                    parameters.add("\"product_id\":\"" + purchase.getSku() + "\"");
                    parameters.add("\"payment_channal\":\"mob_google\"");
                    String re = info[4];
                    if (re != null && !TextUtils.isEmpty(re)) {
                        String[] rev = re.split("_");
                        parameters.add("\"cost\":\"" + (rev.length > 0 ? rev[0] : "") + "\"");
                        parameters.add("\"currency\":\"" + (rev.length > 1 ? rev[1] : "") + "\"");
                    } else {
                        parameters.add("\"cost\":\"\"");
                        parameters.add("\"currency\":\"\"");
                    }
                    parameters.add("\"value\":\"\"");
                    if (info.length >= 7)
                        parameters.add("\"oas_order_id\":\"" + info[6] + "\"");
                    else
                        parameters.add("\"oas_order_id\":\"\"");
                    parameters.add("\"third_party_orderid\":\"" + purchase.getOrderId() + "\"");
                    parameters.add("\"result_code\":\"" + res + "\"");
                    parameters.add("\"isreport\":\"" + (PhoneInfo.instance().isTrackAble() ? "Y" : "N") + "\"");

                    List<String> status = new ArrayList<String>();
                    status.add("\"event_type\":\"order\"");
                    ReportUtils.add(ReportUtils.DEFAULTEVENT_ORDER_REPORTED, parameters, status);
                } catch (Exception e) {
                    BaseUtils.logError(TAG, "Google play billing send mdata fail.");
                }
            }
        }
    }).start();

    //       *          1000001:??key
    //       *          1000002:??
    //       *          1000003:??-Google?
    //       *          1000004ProductID?BUG
    //       *          1000005:????
    //       *          1000100:
}

From source file:com.ubiLive.GameCloud.Browser.WebBrowser.java

/** open new browser */
public void newWindow(String url) {
    if ("".equals(url) || url == null) {
        return;//from  w  w w  .  j  av  a 2  s.com
    }
    Message msg = new Message();
    msg.what = HANDLE_OPEN_NEW_WINDOW;
    msg.obj = url;
    if (mHandler != null)
        mHandler.sendMessage(msg);
}

From source file:com.ubiLive.GameCloud.Browser.WebBrowser.java

/**
 * JavaScript call back method/*from  w  ww . j  av  a2s .  c  om*/
 * remove child browser 
 */
public void removeChildBrowser() {
    DebugLog.d(TAG, "removeChildBrowser()");
    Message msg = new Message();
    msg.what = HANDLE_CLOSE_CHILD_BROWSER;
    mHandler.sendMessage(msg);
}

From source file:com.almalence.opencam.PluginManager.java

private void delayedCapture(int delayInterval) {
    initializeSoundPlayers(/*from   www  .j  ava2s.c o  m*/
            ApplicationScreen.getAppResources().openRawResourceFd(R.raw.plugin_capture_selftimer_countdown),
            ApplicationScreen.getAppResources()
                    .openRawResourceFd(R.raw.plugin_capture_selftimer_finalcountdown));
    countdownHandler.removeCallbacks(flashOff);
    finalcountdownHandler.removeCallbacks(flashBlink);

    timer = new CountDownTimer(delayInterval * 1000 + 500, 1000) {
        public void onTick(long millisUntilFinished) {
            countdownView.setRotation(90 - MainScreen.getOrientation());
            countdownView.setText(String.valueOf(millisUntilFinished / 1000));
            countdownView.clearAnimation();
            countdownLayout.setVisibility(View.VISIBLE);
            countdownView.startAnimation(countdownAnimation);

            if (!delayedCaptureFlashPrefCommon && !delayedCaptureSoundPrefCommon)
                return;

            TickEverySecond((millisUntilFinished / 1000 <= 1) ? true : false);

            if (delayedCaptureFlashPrefCommon) {
                if (millisUntilFinished > 1000) {
                    try {
                        flashModeBackUp = CameraController.getFlashMode();
                        CameraController.setCameraFlashMode(CameraParameters.FLASH_MODE_TORCH);
                    } catch (Exception e) {
                        e.printStackTrace();
                        Log.e("Self-timer", "Torch exception: " + e.getMessage());
                    }
                    countdownHandler.postDelayed(flashOff, 50);
                }
            }
        }

        public void onFinish() {
            countdownView.clearAnimation();
            countdownLayout.setVisibility(View.GONE);

            countdownHandler.removeCallbacks(flashOff);
            finalcountdownHandler.removeCallbacks(flashBlink);
            if (delayedCaptureFlashPrefCommon)
                if (CameraController.getSupportedFlashModes() != null)
                    CameraController.setCameraFlashMode(flashModeBackUp);

            Message msg = new Message();
            msg.what = ApplicationInterface.MSG_DELAYED_CAPTURE;
            ApplicationScreen.getMessageHandler().sendMessage(msg);

            timer = null;
        }
    };
    timer.start();
}