List of usage examples for android.os Message Message
public Message()
From source file:com.example.rps.RpsFragment.java
private void switchState(RpsState newState, boolean isOnResume) { if (!isResumed()) { // if we're not in between onResume and onPause, don't transition states return;//from w w w.jav a 2 s.co m } switch (newState) { case INIT: playerChoice = INVALID_CHOICE; computerChoice = INVALID_CHOICE; result = RpsResult.INVALID; showViews(shootGroup, playerChoiceGroup, rpsFlipper); rpsFlipper.startFlipping(); hideViews(gestureImages); hideViews(gestureTextViews); hideViews(resultGroup, shootTextView, againButton); enableViews(false, gestureImages); enableViews(false, againButton); Message initMessage = new Message(); initMessage.what = ROCK; handler.sendMessageDelayed(initMessage, INITIAL_DELAY_MILLIS); break; case PLAYING: enableViews(true, gestureImages); showViews(rpsFlipper); rpsFlipper.startFlipping(); break; case RESULT: hideViews(shootGroup, playerChoiceGroup); playerChoiceView.setImageResource(DRAWABLES_HUMAN[playerChoice]); computerChoiceView.setImageResource(DRAWABLES_COMPUTER[computerChoice]); resultTextView.setText(result.getStringId()); showViews(resultGroup, againButton); enableViews(true, againButton); if (!isOnResume) { // don't publish if we're switching states because onResumed is being called publishResult(); } break; default: Log.e(TAG, "Unexpected state reached: " + newState.toString()); break; } String statsFormat = getResources().getString(R.string.stats_format); statsTextView.setText(String.format(statsFormat, wins, losses, ties)); currentState = newState; }
From source file:com.kaixin.android.service.UpdateApp.java
private void sendMsg(int flag, int c) { Message msg = new Message(); msg.what = flag; msg.arg1 = c; handler.sendMessage(msg); }
From source file:cn.xiaocool.android_etong.net.constant.request.MainRequest.java
public void userinfo() { new Thread() { Message msg = new Message(); public void run() { String data = "&userid=" + user.getUserId(); Log.e("data is ", data); String result_data = NetUtil.getResponse(WebAddress.GETUSERINFO, data); Log.e("successful", result_data); try { JSONObject obj = new JSONObject(result_data); msg.what = CommunalInterfaces.GETUSERINFO; msg.obj = obj;/*from www . ja va2 s.c om*/ } catch (JSONException e) { e.printStackTrace(); } finally { handler.sendMessage(msg); } } }.start(); }
From source file:com.suan.weclient.fragment.mass.VoiceFragment.java
private void startRecord() { if (audioRecord == null) { initRecorder();// ww w .ja v a 2 s . co m } audioRecord.startRecording(); // ?true isRecord = true; // ? wavAudioPath = Util.getFilePath("record.wav"); recorderThread = new RecorderThread(audioRecord, bufferSizeInBytes, sampleRateInHz, wavAudioPath, new RecorderThread.RecordListener() { @Override public void onRecordStart(int type) { vibrator.vibrate(100); Message message = new Message(); message.arg1 = RECORD_MSG_START; message.arg2 = type; voiceHandler.sendMessage(message); } @Override public void onRecordFinish(int type, String filePath, long playLength) { vibrator.vibrate(100); Message message = new Message(); message.arg1 = RECORD_MSG_FINISH; message.arg2 = type; RecordResultHolder recordResultHolder = new RecordResultHolder(filePath, type, playLength); message.obj = recordResultHolder; voiceHandler.sendMessage(message); } @Override public void onRecordError(int type) { Message message = new Message(); message.arg1 = RECORD_MSG_ERROR; message.arg2 = type; voiceHandler.sendMessage(message); vibrator.vibrate(100); } }); recorderThread.setRecording(true); new Thread(recorderThread).start(); }
From source file:com.baidu.asynchttpclient.AsyncHttpResponseHandler.java
protected Message obtainMessage(int responseMessage, Object response) { Message msg = null;//from w w w . j a v a2 s . co m if (handler != null) { msg = this.handler.obtainMessage(responseMessage, response); } else { msg = new Message(); msg.what = responseMessage; msg.obj = response; } return msg; }
From source file:com.app.jdy.ui.CallBackPasswordActivity.java
public void getCode() { String phone = back_password_username.getText().toString().trim(); params = new ArrayList<NameValuePair>(); params.add(new BasicNameValuePair("phone", phone)); if (phone.length() == 11) { /**/*w ww . jav a2s . c o m*/ * ???? */ Thread thread = new Thread(new Runnable() { @Override public void run() { dataJson = HttpUtils.request(params, URLs.FING_PASSWORD_GET_CORD); Message msg = new Message(); if (dataJson.length() != 0 && !dataJson.equals("0x110")) { try { jsonObject = new JSONObject(dataJson); if (jsonObject.getBoolean("success")) { msg.what = 1; } else { msg.what = 2; } } catch (JSONException e) { e.printStackTrace(); } } else { msg.what = 0; } handler.sendMessage(msg); } }); thread.start(); } else { Toast.makeText(CallBackPasswordActivity.this, "???", Toast.LENGTH_SHORT).show(); } }
From source file:com.gdpi.app.UpdateManager.java
public void getUpdateUrl() { try {//w w w . j av a 2 s .com Map<String, String> paras = new HashMap<>(); paras.put("enterprise", URLs.ENTERPRISE); HttpMultipartPost httpMultipartPost = new HttpMultipartPost(mContext, URLs.URL_UPDATE_CLIENT, paras, false); httpMultipartPost.setCallback(new HttpMultipartPost.HttpConnectionCallback() { @Override public void result(String result) { Message message = new Message(); message.what = GET_UPDATE_URL; message.obj = result; mHandler.sendMessage(message); } @Override public void progressUpdate(Integer... progress) { } }); httpMultipartPost.execute(); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.todoroo.astrid.taskrabbit.TaskRabbitControlSet.java
protected void updateStatus(JSONObject json) { if (json == null) return;/*from ww w . ja v a2s. co m*/ final long taskID = json.optLong(TaskRabbitActivity.TASK_RABBIT_ID); if (taskID == TaskRabbitTaskContainer.NO_ID) return; new Thread(new Runnable() { @Override public void run() { try { String response = restClient.get(taskRabbitURL("tasks/" + taskID)); //$NON-NLS-1$ JSONObject taskResponse = new JSONObject(response); if (taskResponse.has(TaskRabbitActivity.TASK_RABBIT_ID)) { taskRabbitTask.setRemoteTaskData(response); taskRabbitTask.setTaskID(taskResponse.optString(TaskRabbitActivity.TASK_RABBIT_ID)); Message successMessage = new Message(); successMessage.what = 2; handler.sendMessage(successMessage); } } catch (Exception e) { e.printStackTrace(); Message failureMessage = new Message(); failureMessage.what = 0; handler.sendMessage(failureMessage); } } }).start(); //submit! }
From source file:com.iloomo.net.AsyncHttpGet.java
@Override public void run() { String ret = ""; try {//from w ww. ja v a 2 s . c o m if (parameter != null && parameter.size() > 0) { StringBuilder bulider = new StringBuilder(); Set<String> keys = parameter.keySet(); for (String key : keys) { if (bulider.length() != 0) { bulider.append("&"); } bulider.append(EncodeUtils.encode(key)); bulider.append("="); bulider.append(EncodeUtils.encode(String.valueOf(parameter.get(key)))); } url += "?" + bulider.toString(); Log.i("request", url); } for (int i = 0; i < HttpConstant.CONNECTION_COUNT; i++) { try { request = new HttpGet(url); if (HttpConstant.isGzip) { request.addHeader("Accept-Encoding", "gzip"); } else { request.addHeader("Accept-Encoding", "default"); } // httpClient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, connectTimeout); // ? httpClient.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT, readTimeout); HttpResponse response = httpClient.execute(request); int statusCode = response.getStatusLine().getStatusCode(); if (statusCode == HttpStatus.SC_OK) { InputStream is = response.getEntity().getContent(); BufferedInputStream bis = new BufferedInputStream(is); bis.mark(2); // ?? byte[] header = new byte[2]; int result = bis.read(header); // reset?? bis.reset(); // ?GZIP? int headerData = getShort(header); // Gzip ? ? 0x1f8b if (result != -1 && headerData == 0x1f8b) { is = new GZIPInputStream(bis); } else { is = bis; } InputStreamReader reader = new InputStreamReader(is, "utf-8"); char[] data = new char[100]; int readSize; StringBuffer sb = new StringBuffer(); while ((readSize = reader.read(data)) > 0) { sb.append(data, 0, readSize); } ret = sb.toString(); bis.close(); reader.close(); // ByteArrayOutputStream content = new // ByteArrayOutputStream(); // response.getEntity().writeTo(content); // ret = new String(content.toByteArray()).trim(); // content.close(); } else { ret = ErrorUtil.errorJson("" + statusCode, "??,??" + statusCode); continue; } break; } catch (Exception e) { if (i == HttpConstant.CONNECTION_COUNT - 1) { ret = ErrorUtil.errorJson("999", ""); } else { Log.d("connection url", "" + i); continue; } } } } catch (IllegalArgumentException e) { RequestException exception = new RequestException(RequestException.IO_EXCEPTION, HttpConstant.ERROR_MESSAGE); ret = ErrorUtil.errorJson("999", exception.getMessage()); } finally { if (!HttpConstant.IS_STOP_REQUEST) { Message msg = new Message(); msg.obj = ret; msg.getData().putSerializable("callback", callBack); resultHandler.sendMessage(msg); } } super.run(); }
From source file:com.nextgis.firereporter.ScanexHttpLogin.java
@Override protected void onPostExecute(Void unused) { super.onPostExecute(unused); if (mbShowProgress) { mDownloadDialog.dismiss();/*w w w .j av a 2 s .c o m*/ } if (mError != null) { Bundle bundle = new Bundle(); bundle.putBoolean(GetFiresService.ERROR, true); bundle.putString(GetFiresService.ERR_MSG, mError); bundle.putInt(GetFiresService.SOURCE, mnType); Message msg = new Message(); msg.setData(bundle); if (mEventReceiver != null) { mEventReceiver.sendMessage(msg); } } }