List of usage examples for android.os Message Message
public Message()
From source file:com.browsertophone.ShareLink.java
private void sendToast(String toastMessage) { Message msg = new Message(); Bundle data = new Bundle(); data.putString(TOAST, toastMessage); msg.setData(data);/*from www . j ava 2 s . c o m*/ mHandler.sendMessage(msg); }
From source file:com.blogspot.holbohistorier.readonfree.BookView.java
@Override public void onActivityCreated(Bundle saved) { super.onActivityCreated(saved); view = (WebView) getView().findViewById(R.id.Viewport); // enable JavaScript for cool things to happen! view.getSettings().setJavaScriptEnabled(true); // ----- SWIPE PAGE view.setOnTouchListener(new OnTouchListener() { @Override/*w w w . j a v a2 s . c om*/ public boolean onTouch(View v, MotionEvent event) { if (state == ViewStateEnum.books) swipePage(v, event, 0); WebView view = (WebView) v; return view.onTouchEvent(event); } }); // ----- NOTE & LINK view.setOnLongClickListener(new OnLongClickListener() { @Override public boolean onLongClick(View v) { Message msg = new Message(); msg.setTarget(new Handler() { @Override public void handleMessage(Message msg) { super.handleMessage(msg); String url = msg.getData().getString(getString(R.string.url)); if (url != null) navigator.setNote(url, index); } }); view.requestFocusNodeHref(msg); return false; } }); view.setWebViewClient(new WebViewClient() { public boolean shouldOverrideUrlLoading(WebView view, String url) { try { navigator.setBookPage(url, index); } catch (Exception e) { errorMessage(getString(R.string.error_LoadPage)); } return true; } }); loadPage(viewedPage); }
From source file:it.fdev.utils.DrawableManager.java
public void fetchDrawableOnThread(final String urlString, final DrawableManagerListener listener) { if (drawableMap.containsKey(urlString)) { listener.onLoadingComplete(drawableMap.get(urlString)); }/*from w w w . j a va 2s. c o m*/ final Handler handler = new Handler() { @Override public void handleMessage(Message message) { listener.onLoadingComplete((Drawable) message.obj); } }; final Handler errorHandler = new Handler() { @Override public void handleMessage(Message message) { listener.onLoadingError(); } }; Thread thread = new Thread() { @Override public void run() { //TODO : set imageView to a "pending" image Drawable drawable = fetchDrawable(urlString); if (drawable != null) { Message message = handler.obtainMessage(1, drawable); handler.sendMessage(message); } else { Message message = new Message(); errorHandler.sendMessage(message); } } }; thread.start(); }
From source file:com.noah.lol.network.RequestNetwork.java
protected void asyncRequestGet(final String url, final NetworkListener<String> listener) { if (url == null) { return;//from www .j a v a 2 s . c o m } try { environmentCheck(); } catch (EnvironmentException e) { if (listener != null) { e.setStatus(BAD_REQUEST_ENVIRONMENT_CONFIG); listener.onNetworkFail(BAD_REQUEST_ENVIRONMENT_CONFIG, e); } return; } final Handler handler = new Handler() { @Override public void handleMessage(Message msg) { Bundle bundle = msg.getData(); switch (msg.what) { case REQUEST_SUCCESS: String responseBody = bundle.getString(RESPONSE_KEY); if (listener != null && responseBody != null) { listener.onSuccess(responseBody); } break; case REQUEST_FAIL: NetworkException e = (NetworkException) bundle.getSerializable(EXCEPTION_KEY); if (listener != null) { listener.onNetworkFail(e.getStatus(), e); } break; } } }; new Thread(new Runnable() { @Override public void run() { String responseBody = null; Message message = new Message(); try { responseBody = syncRequestGet(url); Bundle bundle = new Bundle(); bundle.putString(RESPONSE_KEY, responseBody); message = Message.obtain(handler, REQUEST_SUCCESS); message.setData(bundle); handler.sendMessage(message); } catch (NetworkException e) { Bundle bundle = new Bundle(); bundle.putSerializable(EXCEPTION_KEY, e); message = Message.obtain(handler, REQUEST_FAIL); message.setData(bundle); handler.sendMessage(message); e.printStackTrace(); } } }).start(); }
From source file:com.example.administrator.myapplication2._3_HB.fragments.ExampleFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout._3_fragment_main_dummy, container, false); mTextChat = (TextView) rootView.findViewById(R.id.text_chat); mTextChat.setMaxLines(1000);/*from w w w .ja v a2s. c o m*/ mTextChat.setVerticalScrollBarEnabled(true); mTextChat.setMovementMethod(new ScrollingMovementMethod()); mEditChat = (EditText) rootView.findViewById(R.id.edit_chat); mEditChat.setOnEditorActionListener(mWriteListener); mBtnSend = (Button) rootView.findViewById(R.id.button_send); mBtnSend.setOnClickListener(this); handler = new MyHandler(); progressBar = (ProgressBar) rootView.findViewById(R.id.progressBar2); seekbar = (SeekBar) rootView.findViewById(R.id.seekBar); new Thread() { @Override public void run() { try { while (true) { sleep(1000); handler.sendMessage(new Message()); if (threadBool == false) { break; } } } catch (InterruptedException e) { e.printStackTrace(); } } }.start(); return rootView; }
From source file:com.aselalee.trainschedule.GetResultsFromSiteV2.java
public void run() { /**/*from ww w . j a va2 s . c om*/ * Call the "GetResults" method to retrieve schedule data from server. */ GetResultsViaJSON(station_from, station_to, time_from, time_to, query_date); /** * Call the "GetPrice" method to retrieve price from server. */ GetPriceViaJSON(station_from, station_to); /** * This will send message to the calling thread to continue and display data. */ Message myMsg = new Message(); myMsg.arg1 = Constants.THREAD_GET_RESULTS; mHandler.sendMessage(myMsg); }
From source file:net.evecom.androidecssp.activity.event.ETypeListActivity.java
/** * /*from w ww. ja v a 2s. c o m*/ * * * @author Stark Zhou * @created 2016-1-27 4:58:46 */ private void initList() { new Thread(new Runnable() { @Override public void run() { Message message = new Message(); HashMap<String, String> map = new HashMap<String, String>(); String etypeId; try { // ,id if (etype != null) { etypeId = etype.getStr("id"); map.put("currentid", etypeId); } resultArray = connServerForResultPost("jfs/ecssp/mobile/eventCtr/getAsyEventTypeTree", map); } catch (ClientProtocolException e) { message.what = MESSAGETYPE_02; } catch (IOException e) { message.what = MESSAGETYPE_02; } if (resultArray.length() > 0) { try { etypes = getObjsInfo(resultArray); // if (etypes.size() == 0) { BaseModel root = new BaseModel(); root.set("id", "10000"); root.set("name", ""); etypes.add(0, root); } if (null == etypes) { message.what = MESSAGETYPE_02; } else { message.what = MESSAGETYPE_01; } } catch (JSONException e) { message.what = MESSAGETYPE_02; } } else { message.what = MESSAGETYPE_02; } Log.v("stark", resultArray); etypeListHandler.sendMessage(message); } }).start(); }
From source file:org.changhong.sync.web.SnowySyncService.java
public void getAuthUri(final String server, final Handler handler) { execInThread(new Runnable() { public void run() { // Reset the authentication credentials OAuthConnection auth = new OAuthConnection(); Uri authUri = null;/*from ww w . ja v a 2s .c o m*/ try { authUri = auth.getAuthorizationUrl(server); } catch (UnknownHostException e) { TLog.e(TAG, "Internet connection not available"); sendMessage(NO_INTERNET); } Message message = new Message(); message.obj = authUri; handler.sendMessage(message); } }); }
From source file:com.cleanwiz.applock.ui.activity.SplashActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); updateVersionManagerService = new UpdateVersionManagerService(this); MobclickAgent.setDebugMode(true);//from w w w. j a v a 2s.c o m MobclickAgent.openActivityDurationTrack(false); MobclickAgent.updateOnlineConfig(this); NewCheckVersion(); handler = new SplashHandler(); Message msg = new Message(); msg.what = SPLASH_DONE; handler.sendMessage(msg); if (SharedPreferenceUtil.readEnterFlag()) { startService(new Intent("com.cleanwiz.applock.service.LockService").setPackage("com.cleanwiz.applock")); } }
From source file:it.angrydroids.epub3reader.BookView.java
@Override public void onActivityCreated(Bundle saved) { super.onActivityCreated(saved); view = (WebView) getView().findViewById(R.id.Viewport); // enable JavaScript for cool things to happen! view.getSettings().setJavaScriptEnabled(true); // ----- SWIPE PAGE view.setOnTouchListener(new OnTouchListener() { @Override//www . ja v a2s . c om public boolean onTouch(View v, MotionEvent event) { if (state == ViewStateEnum.books) swipePage(v, event, 0); WebView view = (WebView) v; return view.onTouchEvent(event); } }); // ----- NOTE & LINK view.setOnLongClickListener(new OnLongClickListener() { @Override public boolean onLongClick(View v) { Message msg = new Message(); msg.setTarget(new Handler() { @Override public void handleMessage(Message msg) { super.handleMessage(msg); String url = msg.getData().getString(getString(R.string.url)); if (url != null) navigator.setNote(url, index); } }); view.requestFocusNodeHref(msg); return false; } }); view.setWebViewClient(new WebViewClient() { public boolean shouldOverrideUrlLoading(WebView view, String url) { try { navigator.setBookPage(url, index); } catch (Exception e) { errorMessage(getString(R.string.error_LoadPage)); } return true; } }); view.addJavascriptInterface(new MyJavaScriptInterface(), "INTERFACE"); view.setWebViewClient(new WebViewClient() { @Override public void onPageFinished(WebView view, String url) { view.loadUrl( "javascript:window.INTERFACE.processContent(document.getElementsByTagName('body')[0].innerText);"); } }); PreButton = (Button) getView().findViewById(R.id.btn_prev_chunk); TopButton = (Button) getView().findViewById(R.id.btn_display_from_top); FwdButton = (Button) getView().findViewById(R.id.btn_fwd_chunk); PreButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { BtnPrevChunkOnClickListner(v); } }); TopButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { BtnDisplayTopOnClickListner(v); } }); FwdButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { BtnFwdChunkOnClickListner(v); } }); loadPage(viewedPage); }