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.CloudRecognition.CloudReco.java

@Override
public void onQCARUpdate(State state) {
    // Get the tracker manager:
    TrackerManager trackerManager = TrackerManager.getInstance();

    // Get the image tracker:
    ImageTracker imageTracker = (ImageTracker) trackerManager.getTracker(ImageTracker.getClassType());

    // Get the target finder:
    TargetFinder finder = imageTracker.getTargetFinder();

    // Check if there are new results available:
    final int statusCode = finder.updateSearchResults();

    // Show a message if we encountered an error:
    if (statusCode < 0) {

        boolean closeAppAfterError = (statusCode == UPDATE_ERROR_NO_NETWORK_CONNECTION
                || statusCode == UPDATE_ERROR_SERVICE_NOT_AVAILABLE);

        showErrorMessage(statusCode, state.getFrame().getTimeStamp(), closeAppAfterError);

    } else if (statusCode == TargetFinder.UPDATE_RESULTS_AVAILABLE) {

        // Process new search results
        if (finder.getResultCount() > 0) {
            TargetSearchResult result = finder.getResult(0);
            Message msg = new Message();
            JSONObject json = comm.getInformacionOtroUsuario(result.getTargetName());
            Bundle data = conversor(json);

            msg.setData(data);/*from ww  w.  j a  v  a 2 s  .co m*/
            msg.what = USER_DETECTED;
            loadingDialogHandler.sendMessage(msg);

            // Check if this target is suitable for tracking:
            if (result.getTrackingRating() > 0) {
                Trackable trackable = finder.enableTracking(result);

                if (mExtendedTracking)
                    trackable.startExtendedTracking();
            }
        }
    }

}

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

public static void callOpenUrl(String url) {
    Message ou = new Message();
    ou.what = HANDLER_OPEN_URL;/*from w w w .j a  va2 s  . co m*/
    ou.obj = url;
    handler.sendMessage(ou);
}

From source file:com.android.launcher3.widget.DigitalAppWidgetProvider.java

public void getNetIp() {
    new Thread() {
        public void run() {
            String line = "";
            URL infoUrl = null;/*w w  w  .  j a  va  2 s.  c  o  m*/
            InputStream inStream = null;
            try {
                infoUrl = new URL("http://pv.sohu.com/cityjson?ie=utf-8");
                URLConnection connection = infoUrl.openConnection();
                HttpURLConnection httpConnection = (HttpURLConnection) connection;
                int responseCode = httpConnection.getResponseCode();
                if (responseCode == HttpURLConnection.HTTP_OK) {
                    inStream = httpConnection.getInputStream();
                    BufferedReader reader = new BufferedReader(new InputStreamReader(inStream, "utf-8"));
                    StringBuilder strber = new StringBuilder();
                    // String line = "";
                    while ((line = reader.readLine()) != null)
                        strber.append(line + "\n");
                    inStream.close();

                    int begin = strber.indexOf("cname\": \"") + 8;

                    int end = strber.indexOf("\"};") - 1;

                    //Log.e("sai", "begin = " + begin + " end =" + end);

                    line = strber.substring(begin + 1, end);
                    //Log.e("sai", "strber = " + strber);
                    Log.e("sai", "line = " + line);
                }
            } catch (MalformedURLException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
            // return null;
            Message message = new Message();
            message.what = 1;
            message.obj = line;
            myHandler.sendMessage(message);
        };
    }.start();
}

From source file:com.hiqes.andele.Andele.java

/**
 * After calling {@link #checkAndExecute}, Andele may have requested the required
 * permissions for the ProtectedAction.  This is an asynchronous operation
 * and will ultimately provide a response via the owner (Activity, Fragment,
 * etc.)  The app must properly call this method from the owner's
 * callback first to determine if this is a permission request that Andele
 * is handling.  If the app is using Andele for all permissions handling
 * (and it should!) then simply call through to this method and do nothing
 * else./*from  w  ww.j a va2 s .  c  o m*/
 * <p>
 * Note that for Activities where permissions are being requested (this
 * includes AppCompatActivity derivatives), care must be taken when
 * Fragments are also in use or if you decided to mix and handle some
 * permissions work yourself.  The best practice is to call through to
 * {@code onRequestPermissionsResult()} and if it returns {@code false}
 * call through to the superclass:
 * <pre>
 * {@code
 * @Override
 * public static void onRequestPermissionsResult(int reqCode, String[] permissions, int[] grantResults) {
 *     if (!Andele.onRequestPermissionsResult(reqCode, permissions, grantResults)) {
 *         super.onRequestPermissionsResult(reqCode, permissions, grantResults);
 *     }
 * }
 * }
 * </pre>
 * @param reqCode   The request code for the permissions request
 * @param permissions   The array of permissions which were requested
 * @param grantResults  The results of the permissions request
 * @return true if this method handled the results, otherwise false
 */
public static boolean onRequestPermissionsResult(int reqCode, String[] permissions, int[] grantResults) {
    boolean handled = false;
    Request req;

    //  Lookup the code, remove the node if there, complain if it doesn't exist
    req = sReqMgr.removeRequest(reqCode);

    if (req == null) {
        Log.w(TAG, "onRequestPermissionsResult: request not found for code " + reqCode);
    } else {
        ProtectedAction[] reqActions = req.getActions();
        int actionCount = req.getActionCount();

        for (int i = 0; i < permissions.length; i++) {
            String curPerm = permissions[i];

            for (int j = 0; j < actionCount; j++) {
                ProtectedAction curAction = reqActions[j];

                if (!TextUtils.equals(curAction.mPermDetails.mPermission, curPerm)) {
                    continue;
                }

                Message msg;

                //  Found a match with the request, fire up
                //  the right message to deal with it.
                if (grantResults[i] == PackageManager.PERMISSION_GRANTED) {
                    //  Call back the action handler, let them know
                    //  the grant was done.
                    curAction.mListener.onPermissionGranted(curAction.mPermDetails);

                    //  Now allow the action to take place.  Use the
                    //  request's handler for this since the original
                    //  execute request could have come on a different
                    //  thread.
                    msg = new Message();
                    msg.what = MSG_DO_ACTION;
                    msg.obj = curAction;
                    req.getHandler().sendMessage(msg);
                } else {
                    //  The permission request was denied.  Now figure out
                    //  what to show the user, if anything.
                    PermissionUse curUsage = curAction.mPermDetails.mUsage;
                    if (curUsage == PermissionUse.CRITICAL) {
                        //  If the permission is CRITICAL we need to inform
                        //  the user this is a big problem.
                        showDeniedCritical(req, j);
                        continue;
                    } else if (curUsage == PermissionUse.ESSENTIAL) {
                        //  If this is an ESSENTIAL permission then remind
                        //  the user of the problems with denial.
                        showDeniedReminder(req, j);
                        continue;
                    } else if (req.getOwner().shouldShowRequestPermissionRationale(curPerm)) {
                        //  This permission covers a secondary type of feature
                        //  so as long as the user is open to feedback go
                        //  ahead and provide it.
                        showDeniedFeedback(req, j);
                        continue;
                    }

                    //  If we get here there was either no UI to show for
                    //  this action or the app disabled UX helper.
                    notifyDenied(curAction);
                }
            }
        }

        handled = true;
    }

    return handled;
}

From source file:com.lewa.crazychapter11.MainActivity.java

private void cal() {
    Message msg = new Message();
    msg.what = 0x1234;//from   ww w.ja v a  2  s  .  c om
    Bundle bundle = new Bundle();
    bundle.putInt(UPPER_NUM, Integer.parseInt(etNum.getText().toString()));
    msg.setData(bundle);
    calThread.mHandler.sendMessage(msg);
}

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

@Override
public void OnMessageResponse(String url, JSONObject jo, AjaxStatus status) throws JSONException {
    // TODO Auto-generated method stub
    mXListView.stopRefresh();//from   ww w.  java  2 s . com
    if (url.endsWith(ApiInterface.ORDER_INFO)) {

        Message msg = new Message();
        msg.what = MessageConstant.RECEIVE_ORDER_PUSH;
        EventBus.getDefault().post(msg);

        if (jo != null) {
            mOrderEmptyView.setVisibility(View.GONE);
            mOrderEmptyView.setImageDrawable(null);
            mOrderEmptyView.setOnClickListener(null);
            setOrderDetailView(mOrderInfoModel.publicOrder);
        } else {
            mOrderEmptyView.setVisibility(View.VISIBLE);
            mOrderEmptyView.setImageResource(R.drawable.e7_no_connections);
            mOrderEmptyView.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    // TODO Auto-generated method stub
                    mOrderInfoModel.get(mOrderId);
                }
            });
        }
    } else if (url.endsWith(ApiInterface.ORDER_CANCEL)) {
        ToastView toast = new ToastView(D1_OrderActivity.this, getString(R.string.order_have_canceled));
        toast.setGravity(Gravity.CENTER, 0, 0);
        toast.show();
        setOrderDetailView(mOrderInfoModel.publicOrder);
    } else if (url.endsWith(ApiInterface.ORDER_ACCEPT)) {
        orderacceptResponse response = new orderacceptResponse();
        response.fromJson(jo);
        if (response.succeed == 1) {
            showOrderDialog(true, response);
        } else {
            showOrderDialog(false, response);
        }
        setOrderDetailView(mOrderInfoModel.publicOrder);
    } else if (url.endsWith(ApiInterface.ORDER_WORK_DONE)) {
        setOrderDetailView(mOrderInfoModel.publicOrder);
    } else if (url.endsWith(ApiInterface.ORDER_PAY)) {

        if (payCode == ENUM_PAY_CODE.PAY_OFFLINE) {
            AnimationUtil.backAnimationFromBottom(mOrderPlayOrderView);
            mOrderPlayOrderView.setVisibility(View.GONE);
            AnimationUtil.backAnimation(mOrderPlayButtonView);
            mOrderPlayButtonView.setVisibility(View.GONE);
            Handler mHandler = new Handler() {
                @Override
                public void handleMessage(Message msg) {
                    super.handleMessage(msg);
                    mOrderPlay.setVisibility(View.GONE);
                    mOrderBtnCancel.setVisibility(View.VISIBLE);
                }
            };
            mHandler.sendEmptyMessageDelayed(0, 200);
        } else {
            //Todo 
            ToastView toast = new ToastView(getApplicationContext(), getString(R.string.share_content));
            toast.setGravity(Gravity.CENTER, 0, 0);
            toast.show();
        }

        setOrderDetailView(mOrderInfoModel.publicOrder);
    } else if (url.endsWith(ApiInterface.ORDER_CONFIRM_PAY)) {
        setOrderDetailView(mOrderInfoModel.publicOrder);
    }
}

From source file:com.hx.hxchat.activity.ContactlistFragment.java

public void getHeadBynet(final List<User> list) {
    new Thread(new Runnable() {
        @Override/*w w w  .  j  a  v a 2  s . c o m*/
        public void run() {
            try {
                String userLiString = "";
                for (User user : list) {
                    if (userLiString.length() > 0)
                        userLiString += ",";
                    userLiString += user.getUsername();
                }

                if (userLiString.length() > 0) {
                    JSONObject jo = Http.postUesrs(userLiString);
                    Message msg = new Message();
                    msg.obj = jo;
                    msg.what = 2;
                    handler.sendMessage(msg);
                } else {

                    handler.sendEmptyMessage(0);

                }
            } catch (JSONException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
                handler.sendEmptyMessage(-1);
            }
        }
    }).start();
}

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

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

        @Override/*  www . j a  v  a  2s.c  o  m*/
        public void run() {
            String data = "&id=" + id;
            Log.e("data=", data);
            String result_data = NetUtil.getResponse(WebAddress.GOODSSHANGJIA, data);
            Log.e("result_data = ", result_data);
            try {
                JSONObject jsonObject = new JSONObject(result_data);
                msg.what = CommunalInterfaces.GOODSSHANGJIA;
                msg.obj = jsonObject;
            } catch (JSONException e) {
                e.printStackTrace();
            } finally {
                handler.sendMessage(msg);
            }
        }
    }.start();
}

From source file:org.geek.utils.ApplicationUtils.java

/**
 * Build the html result of weather//from  ww w. j  a va2s. com
 * @param context The current context
 * @return The html result of weather
 */
private static String getWeatherHtml(Context context) {
    String result = "";

    //Thread getWeatherInfo = new Thread() {
    //@Override  
    //public void run() {  
    //Intent intent = new Intent(RECI_COAST);  
    try {
        //???  
        result = getRequest("http://www.weather.com.cn/data/sk/101010100.html");
        Message weather = new Message();
        weather.what = WEATHER;
        weather.obj = result;
        mHandler.sendMessage(weather);
        result = parseWeatherInfo(result);
        /*JSONObject jsonobject = new JSONObject(  
                intent.getStringExtra("weatherinfo"));  
        JSONObject jsoncity = new JSONObject(  
                jsonobject.getString("weatherinfo"));  
        show.setText(":" + jsoncity.getString("city") + "\t"  
                + ":" + jsoncity.getString("date_y") + "\n" + ":"  
                + jsoncity.getString("temp1") + "\t"  
                + jsoncity.getString("weather1")+"\t"+jsoncity.getString("wind1"));*/
        //intent.putExtra("weatherinfo", reslut);  
        //??  
        //sendBroadcast(intent);
    } catch (InterruptedException e) {
        e.printStackTrace();
    } catch (ExecutionException e) {
        e.printStackTrace();
    }
    //}
    //};
    //getWeatherInfo.start();
    //try {
    //getWeatherInfo.join();
    //} catch (Exception e) {
    //e.printStackTrace();
    //}
    return result;
}

From source file:com.xpg.gokit.activity.GokitControlActivity.java

/**
 * Show data in ui.//from   ww  w .  j  ava  2 s.c o  m
 * 
 * @param data
 *            the data
 * @throws JSONException
 *             the JSON exception
 */
private void showDataInUI(String data) throws JSONException {
    Log.i("revjson", data);
    JSONObject receive = new JSONObject(data);
    @SuppressWarnings("rawtypes")
    Iterator actions = receive.keys();
    while (actions.hasNext()) {
        String action = actions.next().toString();
        // 
        if (action.equals("cmd") || action.equals("qos") || action.equals("seq") || action.equals("version")) {
            continue;
        }
        JSONObject params = receive.getJSONObject(action);
        @SuppressWarnings("rawtypes")
        Iterator it_params = params.keys();
        while (it_params.hasNext()) {
            String param = it_params.next().toString();
            Object value = params.get(param);
            deviceStatu.put(param, value);
        }
    }
    Message msg = new Message();
    msg.obj = data;
    msg.what = UPDATE_UI;
    handler.sendMessage(msg);
}