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:cn.xiaocool.android_etong.net.constant.request.MainRequest.java

public void SearchShops(final String shop, final String address) {
    new Thread() {
        Message msg = new Message();

        @Override//from w  w w  .ja va2 s  . c  o  m
        public void run() {
            String data = "&shop=" + shop + "&address=" + address;
            Log.e("data=", data);
            String result_data = NetUtil.getResponse(WebAddress.SearchShops, data);
            Log.e("result_data=", result_data);
            try {
                JSONObject jsonObject = new JSONObject(result_data);
                msg.what = CommunalInterfaces.SEARCH_SHOPS;
                msg.obj = jsonObject;
            } catch (JSONException e) {
                e.printStackTrace();
            } finally {
                handler.sendMessage(msg);
            }
        }
    }.start();
}

From source file:opensource.zeocompanion.ZeoCompanionApplication.java

public static void postToErrorLog(String method, Throwable theException, String extra, String threadName,
        boolean noAlert) {
    String eMsg = "Exception";
    if (method != null) {
        if (!method.isEmpty()) {
            eMsg = eMsg + " in " + method;
        }/*from  w  w  w.  j ava2  s.com*/
    }
    if (threadName != null) {
        if (!threadName.isEmpty()) {
            eMsg = eMsg + " in Thread " + threadName;
        }
    }
    if (extra != null) {
        if (!extra.isEmpty()) {
            eMsg = eMsg + " (" + extra + ")";
        }
    }
    eMsg = eMsg + ": " + theException.toString();
    Log.e(_CTAG + ".postToErrorLog", eMsg);
    theException.printStackTrace();

    int r = checkExternalStorage();
    if (r != 0) {
        Log.e(_CTAG + ".postToErrorLog", "Cannot write to external storage code " + r);
        return;
    }

    FileWriter wrt = null;
    try {
        // pull the stack trace
        StackTraceElement[] traces = theException.getStackTrace();

        // ensure the directory structure is present and compose the file name
        File internalsDir = new File(mBaseExtStorageDir + File.separator + "internals");
        internalsDir.mkdirs();
        File errLogFile = new File(internalsDir + File.separator + "error.log");

        // create and append to the file
        wrt = new FileWriter(errLogFile, true); // append if file already exists
        wrt.write(new Date().toString() + "\n");
        if (threadName != null) {
            if (!threadName.isEmpty()) {
                wrt.write(" in Thread " + threadName + " ");
            }
        }
        wrt.write("AppVerName " + BuildConfig.VERSION_NAME + " AppVerCode " + BuildConfig.VERSION_CODE);
        if (mDatabaseHandler != null) {
            wrt.write(" with DBver " + mDatabaseHandler.mVersion);
        }
        wrt.write("\n");
        if (mZeoAppHandler != null) {
            if (mZeoAppHandler.mZeoApp_versionName == null) {
                wrt.write("Zeo App not installed\n");
            } else {
                wrt.write("Zeo App version " + mZeoAppHandler.mZeoApp_versionName + " build "
                        + mZeoAppHandler.mZeoApp_versionCode + "\n");
            }
        }
        wrt.write("Android Version " + android.os.Build.VERSION.RELEASE + " API "
                + android.os.Build.VERSION.SDK_INT + "\n");
        wrt.write("Platform Manf " + Build.MANUFACTURER + " Model " + Build.MODEL + "\n");
        WindowManager windowManager = (WindowManager) mApp.getSystemService(Context.WINDOW_SERVICE);
        Display display = windowManager.getDefaultDisplay();
        Point screenSize = new Point();
        display.getSize(screenSize);
        wrt.write("Platform Screen Orientation X,Y " + screenSize.x + "," + screenSize.y + ", Density="
                + mScreenDensity + "\n");
        if (method != null) {
            if (!method.isEmpty()) {
                wrt.write(method + "\n");
            }
        }
        if (extra != null) {
            if (!extra.isEmpty()) {
                wrt.write(extra + "\n");
            }
        }
        wrt.write(theException.toString() + "\n");
        for (StackTraceElement st : traces) {
            wrt.write(st.toString() + "\n");
        }
        wrt.write("=====\n");
        wrt.write("=====\n");
        wrt.flush();
        wrt.close();

        // force it to be shown and post an alert
        forceShowOnPC(errLogFile);
        if (!noAlert) {
            postAlert("An abort occured; details are in \'internals/error.log\'; contact the Developer");
        } // noAlert is only needed when an Alert itself was being posted to the database and it failed to post

        // must send the toast indirectly in case this is being called from a utility thread
        Message msg = new Message();
        msg.what = ZeoCompanionApplication.MESSAGE_APP_SEND_TOAST;
        msg.obj = "Abort successfully logged to \'internals/error.log\'";
        mAppHandler.sendMessage(msg);
    } catch (Exception e) {
        if (wrt != null) {
            try {
                wrt.close();
            } catch (Exception ignored) {
            }
        }
        Log.e(_CTAG + ".postToErrLog", "Cannot write to error.log: " + e.toString());
        e.printStackTrace();
    }
}

From source file:com.cognizant.trumobi.PersonaLauncher.java

private void updateMessengerBadgeCounts() {
    // SmsListdisplay mSms = new SmsListdisplay();
    final int mNewMessages = SmsListdisplay.unReadSMSCount(mContext);
    //         updateCountersForPackage("com.cognizant.trumobi", mNewMessages,
    //               R.color.PR_TEXTBOX_FOCUSED_COLOR, 2);

    Bundle b = new Bundle();

    b.putString("package", "com.cognizant.trumobi");
    b.putInt("counter", mNewMessages);
    b.putInt("color", R.color.PR_TEXTBOX_FOCUSED_COLOR);
    b.putInt("updateCountFor", 2);
    Message m = new Message();
    m.setData(b);/*w w w  .  jav a 2  s  .  com*/
    UiHandler.sendMessage(m);

}

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

public void SearchGoods(final String goods) {
    new Thread() {
        Message msg = new Message();

        @Override/*w  w  w.  ja v  a2  s.  c  o  m*/
        public void run() {
            String data = "&goods=" + goods;
            Log.e("data=", data);
            String result_data = NetUtil.getResponse(WebAddress.SearchGoods, data);
            Log.e("result_data=", result_data);
            try {
                JSONObject jsonObject = new JSONObject(result_data);
                msg.what = CommunalInterfaces.SEARCH_GOODS;
                msg.obj = jsonObject;
            } catch (JSONException e) {
                e.printStackTrace();
            } finally {
                handler.sendMessage(msg);
            }
        }
    }.start();
}

From source file:de.rosche.spectraTelemetry.SpectraTelemetry.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    initapp = true;//from   w ww.  j a va2  s .  c  o  m
    //sandbox();
    initialized = false;
    if (android.os.Build.VERSION.SDK_INT > 10) {
        requestWindowFeature(Window.FEATURE_ACTION_BAR);
        //getOverflowMenu();
    }
    mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
    if (mBluetoothAdapter == null) {
        finishDialogNoBluetooth();
        return;
    }
    setContentView(R.layout.term_activity);
    Message msg = new Message();
    msg.what = STOPSPLASH;
    splashHandler.sendMessageDelayed(msg, SPLASHTIME);
}

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

public void SearchGoods(final String goods, final String address) {
    new Thread() {
        Message msg = new Message();

        @Override//from w  w w  .  j a  va2  s  .  c  om
        public void run() {
            String data = "&goods=" + goods + "&address=" + address;
            Log.e("data=", data);
            String result_data = NetUtil.getResponse(WebAddress.SearchGoods, data);
            Log.e("result_data=", result_data);
            try {
                JSONObject jsonObject = new JSONObject(result_data);
                msg.what = CommunalInterfaces.SEARCH_GOODS;
                msg.obj = jsonObject;
            } catch (JSONException e) {
                e.printStackTrace();
            } finally {
                handler.sendMessage(msg);
            }
        }
    }.start();
}

From source file:de.bogutzky.psychophysiocollector.app.MainActivity.java

private void startTimerThread() {
    timerThreadShouldContinue = true;/*from  w  w w . j  a  v a 2s  . c o  m*/
    timerHandler = new Handler(new TimerHandlerCallback());

    Random r = new Random();
    int variance = 0;
    if (selfReportVariance != 0)
        variance = r.nextInt(selfReportVariance * 2) - selfReportVariance;
    long timerInterval = (long) (1000 * 60 * selfReportInterval) - (1000 * variance);
    final long endTime = System.currentTimeMillis() + timerInterval;

    timerThread = new Thread(new Runnable() {

        @Override
        public void run() {
            long now = System.currentTimeMillis();
            while (now < endTime && timerThreadShouldContinue) {
                Message message = new Message();
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                message.what = TIMER_UPDATE;
                message.arg1 = (int) (endTime - now);
                timerHandler.sendMessage(message);

                // Update time
                now = System.currentTimeMillis();
            }
            Message message = new Message();
            message.what = TIMER_END;
            timerHandler.sendMessage(message);
        }
    });
    timerThread.start();
}

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

public static void tryShowToast(String notice) {
    Message msg = new Message();
    msg.what = MSG_SHOW_TOAST;// ww w .jav  a  2 s.  c  o  m
    msg.obj = notice;
    handler.sendMessage(msg);
}

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

public static void trySetUserData(SgUserData ud) {
    Message msg = new Message();
    msg.what = MSG_SET_USER_DATA;
    msg.obj = ud;
    handler.sendMessage(msg);
}

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

public void IsE() {
    new Thread() {
        Message msg = new Message();

        @Override//w  w  w. ja  v a 2 s  .co  m
        public void run() {
            String data = "";
            Log.e("data=", data);
            String result_data = NetUtil.getResponse(WebAddress.IsE, data);
            Log.e("result_data=", result_data);
            try {
                JSONObject jsonObject = new JSONObject(result_data);
                msg.what = CommunalInterfaces.IsE;
                msg.obj = jsonObject;
            } catch (JSONException e) {
                e.printStackTrace();
            } finally {
                handler.sendMessage(msg);
            }
        }
    }.start();
}