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.huofu.RestaurantOS.ui.splash.activate.java

@Override
protected void dealWithmessage(Message msg) {
    switch (msg.what) {
    case ERROR://from   w  w  w . j a v a  2  s. c  o m
        Bundle bd = (Bundle) msg.getData();
        CommonUtils.sendMsg(null, HIDE_LOADING, mUiHandler);
        showDialogError(bd.getString("reason"), 0);
        break;
    case AUTH_FAILED:
        stopQrScanTimer();
        buttonSwitchInputCode.performClick();
        CommonUtils.sendMsg(null, HIDE_LOADING, mUiHandler);
        showDialogError((String) msg.obj, 0);
        break;
    case AUTH_SUCCESS:
        CommonUtils.sendMsg(getString(R.string.readyToJumpToLogin), activate.SHOW_LOADING_TEXT, mUiHandler);
        mUiHandler.removeMessages(AUTH_SUCCESS);

        finishWithNextActivity(LoginActivity.class);
        break;
    case GET_QRCODE_SUCCESS://???
        qrcodeCreateTime = System.currentTimeMillis() / 1000;

        Bundle bdQrcode = (Bundle) msg.getData();

        tokenQrcode = bdQrcode.getString("token");
        String qrcode_url = bdQrcode.getString("qrcode_url");
        imageViewQrcode.setVisibility(View.VISIBLE);
        bitmapUtils.display(imageViewQrcode, qrcode_url, bigPicDisplayConfig, callback);
        break;
    case SCAN_QRCODE_SUCCESS://???
        flagAuthSuccess = true;
        //stopQrScanTimer();
        CommonUtils.sendMsg(null, AUTH_SUCCESS, mUiHandler);
        break;
    case GET_QRCODE://???
        CommonUtils.sendMsg(getString(R.string.loadingQrcode), SHOW_LOADING_TEXT, mUiHandler);
        ApisManager.GetAuthQrcode(new ApiCallback() {
            @Override
            public void success(Object object) {
                sendUIMessage(HIDE_LOADING, "");
                try {
                    JSONObject obj = (JSONObject) object;
                    String token = (String) obj.get("token");
                    String qrcode_url = (String) obj.get("qrcode_url");

                    Message msg = new Message();
                    msg.what = activate.GET_QRCODE_SUCCESS;
                    Bundle bd = new Bundle();
                    bd.putString("token", token);
                    bd.putString("qrcode_url", qrcode_url);
                    msg.setData(bd);
                    mUiHandler.sendMessage(msg);
                } catch (Exception e) {
                }

            }

            @Override
            public void error(BaseApi.ApiResponse response) {
                sendUIMessage(HIDE_LOADING, "");
                sendUIMessage(SHOW_ERROR_MESSAGE, response.error_message + "");
                CommonUtils.LogWuwei(tag, "GetAuthQrcode failed:" + response.error_message);
            }
        });

        break;
    case SHOW_LOADING_TEXT:
        String content = (String) msg.obj;
        showLoadingDialog(content);
        break;
    case HIDE_LOADING:
        hideLoadingDialog();
        break;
    case SHOW_ERROR_MESSAGE:
        String errMsg = (String) msg.obj;
        showDialogError(errMsg, 0);
        break;
    case UPDATE_QRCODE_SCAN_STATUS:
        textviewScanStauts.setText((String) msg.obj);
        break;
    case SHOW_QRCODE_REFRSH_AGAIN:
        dealQrcodeExpired();
        break;
    case STOP_SCAN_QRCODE_TIMER:
        stopQrScanTimer();
        break;

    }
}

From source file:com.mk4droid.IMC_Activities.Fragment_Map.java

private void HandlersAndReceivers() {

    //----- Handler for Redrawing Markers from update thread ------------
    handlerMarkersUPD = new Handler() {
        public void handleMessage(Message msg) {

            setUpMap();//w w w . ja  v a  2s.com
            PutMarkers(msg.arg1); // 1 rezoom, 2 no-rezoom
            super.handleMessage(msg);
        }
    };

    //----- Handler for Redrawing Markers from update thread ------------
    handlerBroadcastRefresh = new Handler() // Broadcast 1. Refresh Button 2. DistanceCh 3. IssuesNoCh
    {
        public void handleMessage(Message msg) {
            if (msg.arg1 == 1) // Refresh Button
                ctx.sendBroadcast(new Intent("android.intent.action.MAIN").putExtra("Refresh", "ok"));
            else if (msg.arg1 == 2)
                ctx.sendBroadcast(
                        new Intent("android.intent.action.MAIN").putExtra("DistanceChanged", "Indeed"));
            else if (msg.arg1 == 3)
                ctx.sendBroadcast(new Intent("android.intent.action.MAIN").putExtra("IssuesNoChanged", "yep"));

            super.handleMessage(msg);
        }
    };

    //--------------- Receiver for Data change ------------
    intentFilter = new IntentFilter("android.intent.action.MAIN"); // DataCh

    mReceiverDataChanged = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            String DataChanged = intent.getStringExtra("DataChanged");
            String mes_touser = intent.getStringExtra("mes_touser");
            int progressval = intent.getIntExtra("progressval", -1);
            String progressBarVis = intent.getStringExtra("ProgressBar");

            if (progressBarVis != null) {
                if (progressBarVis.length() > 0) {
                    if (progressBarVis.equals("Visible"))
                        pbgeneral.setVisibility(View.VISIBLE);
                    else if (progressBarVis.equals("Gone"))
                        pbgeneral.setVisibility(View.GONE);
                }
            }

            if (DataChanged != null) {
                Log.e("FMain: DataChanged", " " + DataChanged);

                if (mes_touser != null)
                    if ((mes_touser.trim()).length() > 0)
                        Toast.makeText(ctx, mes_touser, Toast.LENGTH_LONG).show();

                pbgeneral.setVisibility(View.GONE);

                Message msg = new Message();
                msg.arg1 = 1;
                handlerMarkersUPD.sendMessage(msg);
            }

            if (progressval != -1) {
                pbgeneral.setProgress(progressval);
            }

        }
    };

    ctx.registerReceiver(mReceiverDataChanged, intentFilter);
}

From source file:cn.xiaocool.android_etong.net.constant.request.MainRequest.java

public void getgoodsinfo(final String id) {
    new Thread() {
        Message msg = new Message();

        @Override/*from   w  w w  .  j  a  v a  2  s .c om*/
        public void run() {
            //? userid  0 
            String data = "&userid=" + user.getUserId() + "&id=" + id;
            Log.e("data=", data);
            String result_data = NetUtil.getResponse(WebAddress.GET_GOODS_INFO, data);
            Log.e("result_data=", result_data);
            try {
                JSONObject jsonObject = new JSONObject(result_data);
                msg.what = CommunalInterfaces.GET_GOODS_INFO;
                msg.obj = jsonObject;
            } catch (JSONException e) {
                e.printStackTrace();
            } finally {
                handler.sendMessage(msg);
            }

        }
    }.start();
}

From source file:com.example.zf_android.activity.MerchantEdit.java

@Override
protected void onActivityResult(final int requestCode, int resultCode, final Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode != RESULT_OK) {
        return;// w  w w  . jav  a2 s.c  om
    }
    String value = "";
    if (data != null) {
        value = data.getStringExtra("value");
    }
    switch (requestCode) {
    case TYPE_1:
        merchantEntity.setTitle(value);
        tv1.setText(value);
        break;
    case TYPE_2:
        merchantEntity.setLegalPersonName(value);
        tv2.setText(value);
        break;
    case TYPE_3:
        merchantEntity.setLegalPersonCardId(value);
        tv3.setText(value);
        break;
    case TYPE_4:
        merchantEntity.setBusinessLicenseNo(value);
        tv4.setText(value);
        break;
    case TYPE_5:
        merchantEntity.setTaxRegisteredNo(value);
        tv5.setText(value);
        break;
    case TYPE_6:
        merchantEntity.setOrganizationCodeNo(value);
        tv6.setText(value);
        break;
    case TYPE_7:
        Province province = (Province) data.getSerializableExtra(Constants.CityIntent.SELECTED_PROVINCE);
        City city = (City) data.getSerializableExtra(Constants.CityIntent.SELECTED_CITY);
        if (province == null || city == null) {
            merchantEntity.setCityId(0);
            tv7.setText("");
        } else {
            merchantEntity.setCityId(city.getId());
            tv7.setText(province.getName() + city.getName());
        }

        break;
    case TYPE_KHYH:
        merchantEntity.setAccountBankName(value);
        tvkhyh.setText(value);
        break;
    case TYPE_8:
        merchantEntity.setBankOpenAccount(value);
        tv8.setText(value);
        break;

    case REQUEST_UPLOAD_IMAGE:
    case REQUEST_TAKE_PHOTO: {
        final LinearLayout layout = linearLayout.get(MerchantEdit.this.type);
        final Handler handler = new Handler() {
            private int type;

            @Override
            public void handleMessage(Message msg) {
                this.type = MerchantEdit.this.type;
                if (msg.what == 1) {
                    // CommonUtil.toastShort(MerchantEdit.this,
                    // (String) msg.obj);
                    layout.setClickable(false);
                    layout.findViewById(R.id.imgView).setVisibility(View.VISIBLE);
                    layout.findViewById(R.id.textView).setVisibility(View.GONE);
                    String url = (String) msg.obj;
                    layout.setClickable(true);
                    switch (type) {
                    case TYPE_10:
                        merchantEntity.setCardIdFrontPhotoPath(url);
                        break;
                    case TYPE_11:
                        merchantEntity.setCardIdBackPhotoPath(url);
                        break;
                    case TYPE_12:
                        merchantEntity.setBodyPhotoPath(url);
                        break;
                    case TYPE_13:
                        merchantEntity.setLicenseNoPicPath(url);
                        break;
                    case TYPE_14:
                        merchantEntity.setTaxNoPicPath(url);
                        break;
                    case TYPE_15:
                        merchantEntity.setOrgCodeNoPicPath(url);
                        break;
                    case TYPE_16:
                        merchantEntity.setAccountPicPath(url);
                        break;
                    default:
                        break;
                    }
                } else {
                    CommonUtil.toastShort(MerchantEdit.this, getString(R.string.toast_upload_failed));
                    layout.setClickable(true);
                }

            }
        };
        if (null != layout) {
            ImageView imgView = (ImageView) layout.findViewById(R.id.imgView);
            TextView textView = (TextView) layout.findViewById(R.id.textView);
            imgView.setVisibility(View.GONE);
            textView.setVisibility(View.VISIBLE);
            textView.setText(getString(R.string.apply_uploading));
            layout.setClickable(false);
        }
        new Thread() {
            @Override
            public void run() {
                String realPath = "";
                if (requestCode == REQUEST_TAKE_PHOTO) {
                    realPath = photoPath;
                } else {
                    Uri uri = data.getData();
                    if (uri != null) {
                        realPath = Tools.getRealPathFromURI(MerchantEdit.this, uri);
                    }
                }
                if (TextUtils.isEmpty(realPath)) {
                    handler.sendEmptyMessage(0);
                    return;
                }
                CommonUtil.uploadFile(realPath, "img", new CommonUtil.OnUploadListener() {
                    @Override
                    public void onSuccess(String result) {
                        try {
                            JSONObject jo = new JSONObject(result);
                            String url = jo.getString("result");
                            Message msg = new Message();
                            msg.what = 1;
                            msg.obj = url;
                            handler.sendMessage(msg);
                        } catch (JSONException e) {
                            handler.sendEmptyMessage(0);
                        }
                    }

                    @Override
                    public void onFailed(String message) {
                        handler.sendEmptyMessage(0);
                    }
                });
            }
        }.start();
        break;
    }
    default:
        break;
    }
}

From source file:com.sabdroidex.controllers.couchpotato.CouchPotatoController.java

/**
 * Sends a message to the calling {@link Activity} to update it's status bar
 * /*from ww w  . j a  v a  2s  . c o  m*/
 * @param messageHandler The message handler to be notified
 * @param text The text to write in the message
 */
private static void sendUpdateMessageStatus(Handler messageHandler, String text) {

    Message message = new Message();
    message.setTarget(messageHandler);
    message.what = MESSAGE.UPDATE.hashCode();
    message.obj = text;
    message.sendToTarget();
}

From source file:com.loftcat.ui.utils.slidingmenu.fragment.MiddleFragment.java

private void resetData(long id, final int index) {
    since_id = 0;//from   www  . ja  v a2s.c  om
    count = 1;
    list_id = id;
    if (list_id != 0) {
        friendshipsAPI.groups_timeline(list_id, since_id, 0, 20, count++, 0, 0, new RequestListener() {

            @Override
            public void onIOException(IOException arg0) {
                // TODO Auto-generated method stub

            }

            @Override
            public void onError(WeiboException arg0) {
                // TODO Auto-generated method stub

            }

            @Override
            public void onComplete(String arg0) {
                Message message = new Message();
                message.obj = arg0;
                message.what = 1;
                message.arg1 = index;
                hanlder.sendMessage(message);
            }
        });

    } else {
        statusesAPI.friendsTimeline(since_id, 0l, 20, count++, false, FEATURE.ALL, false,
                new RequestListener() {

                    @Override
                    public void onIOException(IOException arg0) {
                        Log.d("RESULT", "arg0:    ||   " + arg0);

                    }

                    @Override
                    public void onError(WeiboException arg0) {
                        Log.d("RESULT", "arg0:    ||   " + arg0);

                    }

                    @Override
                    public void onComplete(String arg0) {
                        Message message = new Message();
                        message.obj = arg0;
                        message.what = 1;
                        hanlder.sendMessage(message);
                    }
                });
    }

}

From source file:cn.xiaocool.android_etong.net.constant.request.MainRequest.java

public void getshopinfo(final String shopid) {
    new Thread() {
        Message msg = new Message();

        @Override//from w ww  . jav a2 s. c  o  m
        public void run() {
            String data = "&shopid=" + shopid;
            Log.e("data=", data);
            String result_data = NetUtil.getResponse(WebAddress.GET_SHOP_INFO, data);
            Log.e("result_data=", result_data);
            try {
                JSONObject jsonObject = new JSONObject(result_data);
                msg.what = CommunalInterfaces.GET_SHOP_INFO;
                msg.obj = jsonObject;
            } catch (JSONException e) {
                e.printStackTrace();
            } finally {
                handler.sendMessage(msg);
            }

        }
    }.start();
}

From source file:lvge.com.myapp.modules.shop_management.NotAuthenticationFragment.java

private void returnMessage(String string) {
    Message msg = new Message();
    if (string.equals("error")) {
        msg.what = 1;//from   w  ww  .  ja va  2 s .  com
        mHander.sendMessage(msg);
        return;
    }

    My4sUpdataImageViewModel result = new Gson().fromJson(string, My4sUpdataImageViewModel.class);

    if (result.getOperationResult().getResultCode() == 0) {

        msg.what = 0;
        mHander.sendMessage(msg);
    } else {
        msg.what = 1;
        mHander.sendMessage(msg);
    }
    // dissmissProgressDialog();
}

From source file:com.xdyou.sanguo.GameSanGuo.java

public void sendBuildMessage() {
    Message build = new Message();
    build.what = BUID_DIALOG;
    handler.sendMessage(build);
}

From source file:com.google.code.twisty.Twisty.java

/** Launch UI to pick a file to load and execute */
private void pickFile() {
    String storagestate = Environment.getExternalStorageState();
    if (storagestate.equals(Environment.MEDIA_MOUNTED)
            || storagestate.equals(Environment.MEDIA_MOUNTED_READ_ONLY)) {
        final ProgressDialog pd = ProgressDialog.show(Twisty.this, "Scanning Media", "Searching for Games...",
                true);/* www .  j av a 2s . co m*/
        Thread t = new Thread() {
            public void run() {
                // populate our list of games:
                discovered_games = scanForGames();
                pd.dismiss();
                Message msg = new Message();
                msg.what = PROMPT_FOR_GAME;
                dialog_handler.sendMessage(msg);
            }
        };
        t.start();
    } else
        showDialog(DIALOG_NO_SDCARD); // no sdcard to scan
}