List of usage examples for android.os Message getData
public Bundle getData()
From source file:com.variable.demo.api.fragment.MotionFragment.java
@Override public void onAccelerometerUpdate(MotionSensor sensor, MotionReading reading) { DateFormat formatter = new SimpleDateFormat("MM-dd-yyyy hh:mm.ss"); // Log.d(TAG, "TimeStamp Source: " + reading.getTimeStampSource()); // Log.d(TAG," Time:" + formatter.format(reading.getTimeStamp())); Message m = mHandler.obtainMessage(MessageConstants.MESSAGE_ACCELEROMETER_READING); Bundle b = m.getData(); b.putFloat(MessageConstants.X_VALUE_KEY, (reading.getX() + 16) * DECIMAL_PRECISION); b.putFloat(MessageConstants.Y_VALUE_KEY, (reading.getY() + 16) * DECIMAL_PRECISION); b.putFloat(MessageConstants.Z_VALUE_KEY, (reading.getZ() + 16) * DECIMAL_PRECISION); //For this demo we are streaming all time stamp from the node device. b.putLong(MessageConstants.TIME_STAMP, reading.getTimeStamp().getTime()); b.putInt(MessageConstants.TIME_SOURCE, reading.getTimeStampSource()); final Context thiscontext = this.getActivity(); final String serialnumOne = sensor.getSerialNumber(); final String serialnum = serialnumOne.replaceAll("[^\\u0000-\\uFFFF]", ""); final String scanX = Float.toString((reading.getX() + 16) * DECIMAL_PRECISION); final String scanY = Float.toString((reading.getY() + 16) * DECIMAL_PRECISION); final String scanZ = Float.toString((reading.getZ() + 16) * DECIMAL_PRECISION); String json = "accelerometer;" + serialnum + ";" + scanX + "," + scanY + "," + scanZ; // POST to variable dashboard Ion.getDefault(thiscontext).getConscryptMiddleware().enable(false); Ion.with(thiscontext).load(/*from w ww .j a va 2 s. co m*/ "https://datadipity.com/clickslide/fleetplusdata.json?PHPSESSID=gae519f8k5humje0jqb195nob6&update&postparam[payload]=" + json) .setLogging("MyLogs", Log.DEBUG).asString().withResponse() .setCallback(new FutureCallback<Response<String>>() { @Override public void onCompleted(Exception e, Response<String> result) { if (e == null) { Log.i(TAG, "ION SENT MESSAGE WITH RESULT CODE: " + result.toString()); } else { Log.i(TAG, "ION SENT MESSAGE WITH EXCEPTION"); e.printStackTrace(); } } }); m.sendToTarget(); }
From source file:org.wahtod.wififixer.ui.MainActivity.java
private void handleIntentMessage(Message message) { if (message.getData().isEmpty()) return;/* w w w. j a v a 2 s . c o m*/ Bundle data = message.getData(); /* * Check (assuming SERVICEWARNED) for whether one-time alert fired */ if (data.containsKey(PrefConstants.SERVICEWARNED)) { data.remove(PrefConstants.SERVICEWARNED); showServiceAlert(); } /* * Delete Log if called by preference */ else if (data.containsKey(WRITE_LOG)) { data.remove(WRITE_LOG); LogUtil.writeLogtoSd(this); } else if (data.containsKey(DELETE_LOG)) { data.remove(DELETE_LOG); File logFile = VersionedFile.getFile(this, LogUtil.LOGFILE); if (logFile.exists()) { LogUtil.deleteLog(this, VersionedFile.getFile(this, LogUtil.LOGFILE)); NotifUtil.showToast(this, R.string.logfile_delete_toast); } } else if (data.containsKey(RUN_TUTORIAL)) { data.remove(RUN_TUTORIAL); phoneTutNag(); } else if (data.containsKey(SHOW_HELP)) { this.startActivity(new Intent(this, HelpActivity.class)); } else if (data.containsKey(SEND_LOG)) LogUtil.sendLog(this); /* * Set Activity intent to one without commands we've "consumed" */ Intent i = new Intent(data.getString(PrefUtil.INTENT_ACTION)); i.putExtras(data); setIntent(i); }
From source file:net.networksaremadeofstring.cyllell.ViewCookbooks_Fragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { settings = this.getActivity().getSharedPreferences("Cyllell", 0); try {/*from w w w.j a va 2s . com*/ Cut = new Cuts(getActivity()); } catch (Exception e) { e.printStackTrace(); } dialog = new ProgressDialog(getActivity()); dialog.setTitle("Contacting Chef"); dialog.setMessage("Please wait: Prepping Authentication protocols"); dialog.setIndeterminate(true); if (listOfCookbooks.size() < 1) { dialog.show(); } updateListNotify = new Handler() { public void handleMessage(Message msg) { int tag = msg.getData().getInt("tag", 999999); if (msg.what == 0) { if (tag != 999999) { listOfCookbooks.get(tag).SetSpinnerVisible(); } } else if (msg.what == 1) { //Get rid of the lock CutInProgress = false; //the notifyDataSetChanged() will handle the rest } else if (msg.what == 99) { if (tag != 999999) { Toast.makeText(ViewCookbooks_Fragment.this.getActivity(), "An error occured during that operation.", Toast.LENGTH_LONG).show(); listOfCookbooks.get(tag).SetErrorState(); } } CookbookAdapter.notifyDataSetChanged(); } }; handler = new Handler() { public void handleMessage(Message msg) { //Once we've checked the data is good to use start processing it if (msg.what == 0) { OnClickListener listener = new OnClickListener() { public void onClick(View v) { GetMoreDetails((Integer) v.getTag()); } }; OnLongClickListener listenerLong = new OnLongClickListener() { public boolean onLongClick(View v) { //selectForCAB((Integer)v.getTag()); Toast.makeText(getActivity(), "This version doesn't support Cookbook editing yet", Toast.LENGTH_SHORT).show(); return true; } }; CookbookAdapter = new CookbookListAdaptor(getActivity(), listOfCookbooks, listener, listenerLong); try { list = (ListView) getView().findViewById(R.id.cookbooksListView); } catch (Exception e) { e.printStackTrace(); } if (list != null) { if (CookbookAdapter != null) { list.setAdapter(CookbookAdapter); } else { //Log.e("CookbookAdapter","CookbookAdapter is null"); } } else { //Log.e("List","List is null"); } dialog.dismiss(); } else if (msg.what == 200) { dialog.setMessage("Sending request to Chef..."); } else if (msg.what == 201) { dialog.setMessage("Parsing JSON....."); } else if (msg.what == 202) { dialog.setMessage("Populating UI!"); } else { //Close the Progress dialog dialog.dismiss(); //Alert the user that something went terribly wrong AlertDialog alertDialog = new AlertDialog.Builder(context).create(); alertDialog.setTitle("API Error"); alertDialog.setMessage("There was an error communicating with the API:\n" + msg.getData().getString("exception")); alertDialog.setButton2("OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { //getActivity().finish(); } }); alertDialog.setIcon(R.drawable.icon); alertDialog.show(); } } }; Thread dataPreload = new Thread() { public void run() { if (listOfCookbooks.size() > 0) { handler.sendEmptyMessage(0); } else { try { handler.sendEmptyMessage(200); Cookbooks = Cut.GetCookbooks(); handler.sendEmptyMessage(201); JSONArray Keys = Cookbooks.names(); String URI = ""; String Version = "0.0.0"; JSONObject cookbook; for (int i = 0; i < Cookbooks.length(); i++) { cookbook = new JSONObject(Cookbooks.getString(Keys.get(i).toString())); //URI = Cookbooks.getString(Keys.get(i).toString()).replaceFirst("^(https://|http://).*/cookbooks/", ""); //Version = Cookbooks.getString(Keys.get(i).toString()) //Log.i("Cookbook Name", Keys.get(i).toString()); URI = cookbook.getString("url").replaceFirst("^(https://|http://).*/cookbooks/", ""); //Log.i("Cookbook URL", URI); JSONArray versions = cookbook.getJSONArray("versions"); Version = versions.getJSONObject(versions.length() - 1).getString("version"); //Log.i("Cookbook version", Version); listOfCookbooks.add(new Cookbook(Keys.get(i).toString(), URI, Version)); } handler.sendEmptyMessage(202); handler.sendEmptyMessage(0); } catch (Exception e) { BugSenseHandler.log("ViewCookbooksFragment", e); e.printStackTrace(); Message msg = new Message(); Bundle data = new Bundle(); data.putString("exception", e.getMessage()); msg.setData(data); msg.what = 1; handler.sendMessage(msg); } } return; } }; dataPreload.start(); return inflater.inflate(R.layout.cookbooks_landing, container, false); }
From source file:net.networksaremadeofstring.rhybudd.ZenossWidgetGraph.java
public void onUpdate(final Context context, final AppWidgetManager appWidgetManager, final int[] appWidgetIds) { if (settings == null) settings = PreferenceManager.getDefaultSharedPreferences(context); wContext = context;// ww w . j a va 2 s . co m Refresh(); handler = new Handler() { public void handleMessage(Message msg) { if (msg.what == 1) { Bundle Values = msg.getData(); final int N = appWidgetIds.length; RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.zenoss_widget_graph); //Intent intent = new Intent(context, rhestr.class); //PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0); //Log.i("GraphWidget","Drawing Graph!"); for (int i = 0; i < N; i++) { int appWidgetId = appWidgetIds[i]; views.setImageViewBitmap(R.id.graphCanvas, RenderBarGraph(Values.getInt("CritCount"), Values.getInt("ErrCount"), Values.getInt("WarnCount"))); appWidgetManager.updateAppWidget(appWidgetId, views); } } } }; }
From source file:com.example.helloworldlinked.backend.HelloWorldService.java
public void parseMessage(Message message) { Utility.logDebug(TAG, "parsing Message"); Bundle data = message.getData(); String str = data.getString(BUNDLE_DATA); try {/*from w w w. jav a 2s . co m*/ JSONObject jObj = new JSONObject(str); int type = jObj.getInt("type"); if (type == TYPE_FILE_PATH) { String fileName = jObj.getString("filename"); Utility.logDebug(TAG, "fileName = " + fileName); messageReceiver.setImage(fileName); } else if (type == TYPE_CONNECTION_STATUS) { boolean isConnected = jObj.getBoolean("connection"); Utility.logDebug(TAG, "isConnected = " + isConnected); messageReceiver.onConnectionStatusReceived(isConnected); } else if (type == TYPE_HEARTBEAT_COUNT) { int count = jObj.getInt("heartbeat"); Utility.logDebug(TAG, "heartbeat count = " + Integer.toString(count)); messageReceiver.onHeartbeatsReceived(count); } else if (type == TYPE_STEPS_COUNT) { int count = jObj.getInt("steps"); Utility.logDebug(TAG, "steps count = " + Integer.toString(count)); messageReceiver.onStepsReceived(count); } else if (type == TYPE_TEXT) { String text = jObj.getString("text"); Utility.logDebug(TAG, "text = " + text); messageReceiver.onMessageReceived(text); } else { Utility.logError(TAG, "unsupported type (" + type + ")"); } } catch (JSONException e) { Utility.logError(TAG, "", e); } }
From source file:org.planetmono.dcuploader.ActivityGalleryChooser.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); db = new DatabaseHelper(this); setContentView(R.layout.gallery_chooser); ((Button) findViewById(R.id.gallery_chooser_search)).setOnClickListener(new OnClickListener() { public void onClick(View v) { String query = ((EditText) findViewById(R.id.gallery_chooser_edit)).getText().toString(); if (query.length() > 0) { Message m = fetcherHandler.obtainMessage(); m.getData().putString("searchTerm", query); fetcherHandler.handleMessage(m); } else { fetcherHandler.sendEmptyMessage(0); }/*from ww w . j ava 2s. c o m*/ } }); ((Button) findViewById(R.id.gallery_chooser_ok)).setOnClickListener(new OnClickListener() { public void onClick(View v) { ListView lv = (ListView) findViewById(R.id.gallery_chooser_list); long nids[] = lv.getCheckItemIds(); String nstrs[] = new String[nids.length]; for (int i = 0; i < nids.length; ++i) nstrs[i] = ids.get((int) nids[i]); Intent i = new Intent(); i.putExtra("result", nstrs); setResult(Activity.RESULT_OK, i); finishActivity(Application.ACTION_ADD_GALLERY); finish(); } }); ((Button) findViewById(R.id.gallery_chooser_cancel)).setOnClickListener(new OnClickListener() { public void onClick(View v) { finish(); } }); if (db.rowCount() == 0) refresh(); else fetcherHandler.sendEmptyMessage(0); }
From source file:de.teunito.android.cyclelife.RennradNewsShare.java
/** Called when the activity is first created. */ @Override/*from w w w. ja va 2 s . com*/ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.share_rennradnews); Bundle data = new Bundle(); data = getIntent().getExtras(); trackId = data.getLong("trackId"); mTrackDb = TrackDb.getInstance(getApplicationContext()); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); APIKey = prefs.getString(Preferences.RENNRADNEWS_API_KEY, ""); bikeId = prefs.getString(Preferences.RENNRADNEWS_BIKE_ID, ""); weight = prefs.getString(Preferences.WEIGHT, ""); tv = (TextView) findViewById(R.id.rnsShareTitle); tv.setText("Share your track " + trackId + " to rennrad-news.de community!"); bt = (Button) findViewById(R.id.rnsShareBtn); etTemp = (EditText) findViewById(R.id.rnsShareTemp); spSports = (Spinner) findViewById(R.id.rnsShareSports); spZone = (Spinner) findViewById(R.id.rnsShareZone); spWeather = (Spinner) findViewById(R.id.rnsShareWeather); spMood = (Spinner) findViewById(R.id.rnsShareMood); sportsAdapter = ArrayAdapter.createFromResource(this, R.array.sports, android.R.layout.simple_spinner_item); zoneAdapter = ArrayAdapter.createFromResource(this, R.array.zone, android.R.layout.simple_spinner_item); weatherAdapter = ArrayAdapter.createFromResource(this, R.array.weather, android.R.layout.simple_spinner_item); moodAdapter = ArrayAdapter.createFromResource(this, R.array.mood, android.R.layout.simple_spinner_item); sportsAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); zoneAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); weatherAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); moodAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spSports.setAdapter(sportsAdapter); spZone.setAdapter(zoneAdapter); spWeather.setAdapter(weatherAdapter); spMood.setAdapter(moodAdapter); bt.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { dialog = ProgressDialog.show(RennradNewsShare.this, "", "Uploading. Please wait...", true); sportsID = String.valueOf(spSports.getSelectedItemPosition() + 1); zoneId = String.valueOf(spZone.getSelectedItemPosition() + 1); weatherId = String.valueOf(spWeather.getSelectedItemPosition() + 1); moodId = String.valueOf(spMood.getSelectedItemPosition() + 1); temperature = etTemp.getText().toString(); // execute is a blocking call, it's best to call this code in a thread separate from the ui's uploadThread.start(); } }); handler = new Handler() { public void handleMessage(Message msg) { String result = msg.getData().getString("result"); if (result.contains("success")) { Toast.makeText(getApplicationContext(), "Uploaded: " + result, Toast.LENGTH_LONG).show(); finish(); } else Toast.makeText(getApplicationContext(), "Error: " + result, Toast.LENGTH_LONG).show(); } }; if (APIKey.length() < 20) { AlertDialog.Builder builder = new AlertDialog.Builder(RennradNewsShare.this); builder.setMessage("Please enter first the rennrad-news.de API-key in the Settings!") .setCancelable(false).setIcon(android.R.drawable.ic_dialog_alert) .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { RennradNewsShare.this.finish(); startActivity(new Intent(RennradNewsShare.this, Preferences.class)); } }); builder.create().show(); } }
From source file:net.networksaremadeofstring.cyllell.ViewEnvironments_Fragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { list = (ListView) this.getActivity().findViewById(R.id.environmentsListView); settings = this.getActivity().getSharedPreferences("Cyllell", 0); try {// w w w. j a va2 s.co m Cut = new Cuts(getActivity()); } catch (Exception e) { e.printStackTrace(); } dialog = new ProgressDialog(getActivity()); dialog.setTitle("Contacting Chef"); dialog.setMessage("Please wait: Prepping Authentication protocols"); dialog.setIndeterminate(true); if (listOfEnvironments.size() < 1) { dialog.show(); } updateListNotify = new Handler() { public void handleMessage(Message msg) { int tag = msg.getData().getInt("tag", 999999); if (msg.what == 0) { if (tag != 999999) { listOfEnvironments.get(tag).SetSpinnerVisible(); } } else if (msg.what == 1) { //Get rid of the lock CutInProgress = false; //the notifyDataSetChanged() will handle the rest } else if (msg.what == 99) { if (tag != 999999) { Toast.makeText(ViewEnvironments_Fragment.this.getActivity(), "An error occured during that operation.", Toast.LENGTH_LONG).show(); listOfEnvironments.get(tag).SetErrorState(); } } EnvironmentAdapter.notifyDataSetChanged(); } }; final Handler handler = new Handler() { public void handleMessage(Message msg) { //Once we've checked the data is good to use start processing it if (msg.what == 0) { OnClickListener listener = new OnClickListener() { public void onClick(View v) { //Log.i("OnClick","Clicked"); GetMoreDetails((Integer) v.getTag()); } }; OnLongClickListener listenerLong = new OnLongClickListener() { public boolean onLongClick(View v) { selectForCAB((Integer) v.getTag()); return true; } }; EnvironmentAdapter = new EnvironmentListAdaptor(getActivity().getBaseContext(), listOfEnvironments, listener, listenerLong); list = (ListView) getView().findViewById(R.id.environmentsListView); if (list != null) { if (EnvironmentAdapter != null) { list.setAdapter(EnvironmentAdapter); } else { //Log.e("EnvironmentAdapter","EnvironmentAdapter is null"); } } else { //Log.e("List","List is null"); } dialog.dismiss(); } else if (msg.what == 200) { dialog.setMessage("Sending request to Chef..."); } else if (msg.what == 201) { dialog.setMessage("Parsing JSON....."); } else if (msg.what == 202) { dialog.setMessage("Populating UI!"); } else { //Close the Progress dialog dialog.dismiss(); //Alert the user that something went terribly wrong AlertDialog alertDialog = new AlertDialog.Builder(getActivity()).create(); alertDialog.setTitle("API Error"); alertDialog.setMessage("There was an error communicating with the API:\n" + msg.getData().getString("exception")); alertDialog.setButton2("Back", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { getActivity().finish(); } }); alertDialog.setIcon(R.drawable.icon); alertDialog.show(); } } }; Thread dataPreload = new Thread() { public void run() { if (listOfEnvironments.size() > 0) { handler.sendEmptyMessage(0); } else { try { handler.sendEmptyMessage(200); Environments = Cut.GetEnvironments(); handler.sendEmptyMessage(201); JSONArray Keys = Environments.names(); for (int i = 0; i < Keys.length(); i++) { listOfEnvironments.add( new Environment(Keys.getString(i), Environments.getString(Keys.getString(i)) .replaceFirst("^(https://|http://).*/environments/", ""))); } handler.sendEmptyMessage(202); handler.sendEmptyMessage(0); } catch (Exception e) { Message msg = new Message(); Bundle data = new Bundle(); data.putString("exception", e.getMessage()); msg.setData(data); msg.what = 1; handler.sendMessage(msg); } } return; } }; dataPreload.start(); return inflater.inflate(R.layout.environments_landing, container, false); }
From source file:edu.asu.cse535.assignment3.MainActivity.java
public void classifyActivity(View v) { final Handler testHandler = new Handler() { @Override//from ww w. java 2s.c o m public void handleMessage(Message msg) { Log.w(this.getClass().getSimpleName(), "Message received and stopping service"); Bundle b = msg.getData(); ActivityData activityData = (ActivityData) b.getSerializable("ActivityData"); notifyCompletion(); stopService(testIntent); unbindService(testServiceConnection); AndroidLibsvmClassifier androidLibsvmClassifier = new AndroidLibsvmClassifier(); String activity = androidLibsvmClassifier.classify(activityData); toastActivity(activity); } }; testIntent = new Intent(MainActivity.this.getBaseContext(), AccIntentService.class); testIntent.putExtra("activity", Constants.CLASSIFY); testServiceConnection = new ServiceConnection() { @Override public void onServiceConnected(ComponentName name, IBinder service) { AccIntentService testAaccIntentService = ((AccIntentService.LocalBinder) service).getInstance(); testAaccIntentService.setHandler(testHandler); Log.w(this.getClass().getSimpleName(), "Test activity is connected to service"); } @Override public void onServiceDisconnected(ComponentName name) { } }; startService(testIntent); bindService(testIntent, testServiceConnection, Context.BIND_AUTO_CREATE); }
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.ja va 2 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); }