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 IsPrice() {
    new Thread() {
        Message msg = new Message();

        @Override//from   ww  w  .  j av  a 2  s  .  c  o m
        public void run() {
            String data = "";
            Log.e("data=", data);
            String result_data = NetUtil.getResponse(WebAddress.IsPrice, data);
            Log.e("result_data=", result_data);
            try {
                JSONObject jsonObject = new JSONObject(result_data);
                msg.what = CommunalInterfaces.IsPrice;
                msg.obj = jsonObject;
            } catch (JSONException e) {
                e.printStackTrace();
            } finally {
                handler.sendMessage(msg);
            }
        }
    }.start();
}

From source file:net.evecom.android.PublicOpinionLookActivity.java

/**
 * //from   w  ww .ja  va2 s  . com
 */
private void formSubmit() {
    new Thread(new Runnable() {
        @Override
        public void run() {
            try {
                Message msg_listData = new Message();
                String a = HttpUtil.BASE_URL + "teventAndroid/deleteAndroid";
                String b = "Id=" + Id;

                try {
                    sss = connServerForResultPost(a, b);
                } catch (Exception e) {
                    msg_listData.what = MESSAGETYPE_02;
                }
                if (sss == null || "".equals(sss) || sss.contains("failure")) {
                    msg_listData.what = MESSAGETYPE_02;
                } else {
                    msg_listData.what = MESSAGETYPE_01;
                }
                handler1.sendMessage(msg_listData);
            } catch (Exception e) {
                if (null != e) {
                    e.printStackTrace();
                }
            }
        }
    }).start();
}

From source file:au.com.infiniterecursion.vidiom.utils.PublishingUtils.java

public void asyncYouTubeUpload(final Activity activity, final File file, final Handler handler,
        final String emailAddress, final long sdrecord_id) {

    new Thread(new Runnable() {
        public void run() {
            Message msg = new Message();
            Bundle bundle = new Bundle();
            msg.setData(bundle);//from   ww  w  .j av a  2s  .  com

            String videoId = null;
            int submitCount = 0;
            try {
                while (submitCount <= MAX_RETRIES && videoId == null) {
                    try {
                        submitCount++;
                        videoId = startYouTubeUpload(activity, file, handler, emailAddress, sdrecord_id);
                        assert videoId != null;
                    } catch (Internal500ResumeException e500) { // TODO -
                        // this
                        // should
                        // not
                        // really
                        // happen
                        if (submitCount < MAX_RETRIES) {
                            Log.w(TAG, e500.getMessage());
                            Log.d(TAG, String.format("Upload retry :%d.", submitCount));
                        } else {
                            Log.d(TAG, "Giving up");
                            Log.e(TAG, e500.getMessage());
                            throw new IOException(e500.getMessage());
                        }
                    }
                }
            } catch (IOException e) {
                e.printStackTrace();
                Log.e(TAG, "AsyncYouTubeUpload ERROR - finishing");
                return;
            } catch (YouTubeAccountException e) {
                e.printStackTrace();
                Log.e(TAG, "AsyncYouTubeUpload ERROR - finishing");
                return;
            } catch (SAXException e) {
                e.printStackTrace();
                Log.e(TAG, "AsyncYouTubeUpload ERROR - finishing");
            } catch (ParserConfigurationException e) {
                e.printStackTrace();
                Log.e(TAG, "AsyncYouTubeUpload ERROR - finishing");
            }

        }
    }).start();
}

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

public void getDevicesList(DeviceTypes type, final IoTServiceStatusNotification callback, boolean forceRescan) {
    if (!mInitialized) {
        InitializeRequiredException initException = new InitializeRequiredException(
                "Init required Exception!!");

        try {/*from   ww w .j ava 2s  .  c  o m*/
            throw initException;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return;
    }

    if (mServiceStatus.equals(IoTServiceStatus.NONE) && !mErrorCodes.equals(IoTResultCodes.SUCCESS)) {
        mHandler.postDelayed(new Runnable() {
            @Override
            public void run() {
                callback.onResult(IoTServiceCommand.GET_DEVICE_LIST, mServiceStatus, mErrorCodes, null);
            }
        }, 100);
    } else if (mServiceStatus.equals(IoTServiceStatus.RUNNING)) {
        //  ?? 
        if (forceRescan) {
            //   ?  ..
            Message msg = new Message();

            msg.what = IoTServiceCommand.GET_DEVICE_LIST;
            Bundle b = new Bundle();
            String msgId = IoTServiceCommand.generateMessageId(mCtx);
            b.putString(IoTServiceCommand.KEY_MSGID, msgId);
            b.putSerializable(IoTServiceCommand.KEY_DEVICE_TYPE, type);

            mForceRescanCallback = new WeakReference<>(callback);
            //mRequestedCallbaks.put(msgId, new WeakReference<>(callback));

            msg.setData(b);
            try {
                mServiceMessenger.send(msg);
            } catch (RemoteException e) {
                e.printStackTrace();
            }
        } else {
            mHandler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    Bundle b = new Bundle();
                    ArrayList<IoTDevice> devicesList = null;
                    if (mBondedWithServerList != null && mBondedWithServerList.size() > 0) {
                        devicesList = new ArrayList<>(mBondedWithServerList.values());
                    } else {
                        devicesList = new ArrayList<>();
                    }

                    b.putParcelableArrayList(IoTServiceCommand.KEY_DATA, devicesList);
                    callback.onResult(IoTServiceCommand.GET_DEVICE_LIST, mServiceStatus, mErrorCodes, b);
                }
            }, 100);
        }
    } else if (mServiceStatus.equals(IoTServiceStatus.INITIALIZE)) {
        // bound ?
        String msgId = IoTServiceCommand.generateMessageId(mCtx);
        mForceRescanCallback = new WeakReference<>(callback);
    } else {
        // stop ?.. ?? ? ? ?.
        mHandler.postDelayed(new Runnable() {
            @Override
            public void run() {
                callback.onResult(IoTServiceCommand.GET_DEVICE_LIST, mServiceStatus, mErrorCodes, null);
            }
        }, 100);
    }
}

From source file:com.quwu.xinwo.release.Release_Activity.java

@SuppressWarnings("rawtypes")
private void isAreaSelector() {

    // // w ww. j  av  a2 s. c o  m
    pvOptions = new OptionsPickerView(Release_Activity.this);

    new Thread(new Runnable() {

        public void run() {
            // TODO Auto-generated method stub
            System.out.println(System.currentTimeMillis());
            if (item1 != null && item2 != null && item3 != null) {
                Message message = new Message();
                message.what = 3;
                handler.sendMessage(message);
                return;
            }
            RegionDAO.queryAllInfo();
            item1 = (ArrayList<RegionInfo>) RegionDAO.getProvencesOrCity(1);
            for (RegionInfo regionInfo : item1) {
                item2.add((ArrayList<RegionInfo>) RegionDAO.getProvencesOrCityOnParent(regionInfo.getId()));
            }

            for (ArrayList<RegionInfo> arrayList : item2) {
                ArrayList<ArrayList<RegionInfo>> list2 = new ArrayList<ArrayList<RegionInfo>>();
                for (RegionInfo regionInfo : arrayList) {

                    ArrayList<RegionInfo> q = (ArrayList<RegionInfo>) RegionDAO
                            .getProvencesOrCityOnParent(regionInfo.getId());
                    list2.add(q);

                }
                item3.add(list2);
            }

            Message message = new Message();
            message.what = 3;
            handler.sendMessage(message);

        }
    }).start();
    // ??
    // pwOptions.setLabels("?", "", "");
    pvOptions.setTitle("");

    // 
    // ?

    pvOptions.setOnoptionsSelectListener(new OptionsPickerView.OnOptionsSelectListener() {

        public void onOptionsSelect(int options1, int option2, int options3) {
            // ?
            String tx = " " + item1.get(options1).getPickerViewText() + " "
                    + item2.get(options1).get(option2).getPickerViewText() + " "
                    + item3.get(options1).get(option2).get(options3).getPickerViewText();
            areaBtn.setText(tx);
            good_region = item1.get(options1).getPickerViewText();
            city_region = item2.get(options1).get(option2).getPickerViewText();
            small_area = item3.get(options1).get(option2).get(options3).getPickerViewText();
        }
    });
    // 
    areaBtn.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            pvOptions.show();
        }
    });

    areaBtn.setClickable(false);
}

From source file:opensource.zeocompanion.ZeoCompanionApplication.java

public static void postToErrorLog(String method, String errorMessage, String extra, boolean noAlert) {
    String eMsg = "Severe Error";
    if (method != null) {
        if (!method.isEmpty()) {
            eMsg = eMsg + " in " + method;
        }//from  www.jav  a2 s.  c o  m
    }
    if (extra != null) {
        if (!extra.isEmpty()) {
            eMsg = eMsg + " (" + extra + ")";
        }
    }
    eMsg = eMsg + ": " + errorMessage;
    Log.e(_CTAG + ".postToErrorLog", eMsg);

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

    FileWriter wrt = null;
    try {
        // 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");
        wrt.write("Appver " + BuildConfig.VERSION_NAME);
        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");
        if (method != null) {
            if (!method.isEmpty()) {
                wrt.write(method + "\n");
            }
        }
        if (extra != null) {
            if (!extra.isEmpty()) {
                wrt.write(extra + "\n");
            }
        }
        wrt.write(errorMessage + "\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:org.huxizhijian.hhcomicviewer.ui.entry.ComicDetailsActivity.java

public void sendSelectedChapters(List<String> selectedChapters) {
    //?//from   www .  j  a  va2 s  .  c  om
    Comic findComic = mComicDBHelper.findByCid(mComic.getCid());
    //true
    mComic.setDownload(true);
    if (findComic != null) {
        //?
        mComic.setLastReadTime(System.currentTimeMillis());
        mComicDBHelper.update(mComic);
    } else if (mComic == null) {
        Toast.makeText(ComicDetailsActivity.this, "??~",
                Toast.LENGTH_SHORT).show();
        return;
    } else {
        //??
        mComic.setLastReadTime(System.currentTimeMillis());
        //?
        mComicDBHelper.add(mComic);
        mComic.setId(mComicDBHelper.findByCid(mComic.getCid()).getId());
    }

    //
    if (selectedChapters.size() != 0) {
        //??
        if (ContextCompat.checkSelfPermission(this,
                Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
            if (ActivityCompat.shouldShowRequestPermissionRationale(this,
                    Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
                Toast.makeText(this, "???", Toast.LENGTH_SHORT).show();
                mSelectedChapters = selectedChapters;
                ActivityCompat.requestPermissions(this,
                        new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE }, CHECK_SD_WRITE_PERMISSION);
            } else {
                mSelectedChapters = selectedChapters;
                ActivityCompat.requestPermissions(this,
                        new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE }, CHECK_SD_WRITE_PERMISSION);
            }
            return;
        }

        int position = -1;
        List<Integer> positionList = new ArrayList<>();
        ComicChapter Chapter = null;
        for (String volName : selectedChapters) {
            position = mComic.getChapterName().indexOf(volName);
            positionList.add(position);
        }
        //?
        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;
            //??1000ms
            mHandler.sendMessageDelayed(msg, 10 * i);
        }
    }
}

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

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

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

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

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

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

From source file:opensource.zeocompanion.ZeoCompanionApplication.java

public static void postAlert(String message) {
    if (ZeoCompanionApplication.mDatabaseHandler != null) {
        CompanionAlertRec aRec = new CompanionAlertRec(System.currentTimeMillis(), message);
        aRec.saveToDB(ZeoCompanionApplication.mDatabaseHandler);

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