List of usage examples for android.os Message setData
public void setData(Bundle data)
From source file:org.ymkm.lib.controller.support.ControlledDialogFragment.java
/** * Sends a message to the controller via its supplied {@link Messenger} * <p>//from w w w . j a va 2 s . com * A {@link ControlledDialogFragment} can only communicate with the * {@link FragmentController}. * </p> * The sent message wraps the actual message that will be dispatched by the * controller, and has the following values : * <dl> * <dt>what</dt> * <dd>{@link FragmentController#MSG_DISPATCH_MESSAGE} => Dispatches the * message in the controller</dd> * <dt>arg1</dt> * <dd>The control ID assigned to the ControlledDialogFragment that owns this * callback</dd> * <dt>arg2</dt> * <dd>The {@code what} passed as a parameter that needs to be dispatched</dd> * <dt>obj</dt> * <dd>{@link Message} that will get dispatched (the {@code what} will be * added to it)</dd> * </dl> * obj is a message instance that will eventually contain what, arg1, arg2, * obj passed as parameters of this method.<br> * * @param what * message ID to get dispatched by the controller * @param arg1 * first message int argument * @param arg2 * second message int argment * @param obj * Object argument * @return {@code true} if message could be sent, {@code false} otherwise */ @Override public final boolean sendToController(int what, int arg1, int arg2, Object obj) { if (null != mControllerMessenger) { Message m = Message.obtain(); m.what = FragmentController.MSG_DISPATCH_MESSAGE; m.arg1 = getControlId(); m.arg2 = what; m.obj = FragmentController.CallbackMessage.obtain(arg1, arg2, obj); Bundle b = new Bundle(); b.putString("controllableName", mControllableName); m.setData(b); try { mControllerMessenger.send(m); } catch (RemoteException e) { e.printStackTrace(); return false; } } return true; }
From source file:com.cttapp.bby.mytlc.layer8apps.CalendarHandler.java
/************ * PURPOSE: Handles the primary thread in the service * ARGUMENTS: Intent intent/*from w w w .ja v a 2 s . c om*/ * RETURNS: VOID * AUTHOR: Devin Collins <agent14709@gmail.com> *************/ @Override protected void onHandleIntent(Intent intent) { // Get our stored data from the intent username = intent.getStringExtra("username"); password = intent.getStringExtra("password"); messenger = (Messenger) intent.getExtras().get("handler"); calID = intent.getIntExtra("calendarID", -1); String url = getApplicationContext().getResources().getString(R.string.url); // Create variables to be used through the application List<String[]> workDays = null; ConnectionManager conn = ConnectionManager.newConnection(); /************ * Once we verify that we have a valid token, we get the actual schedule *************/ updateStatus("Logging in..."); String tempToken = conn.getData(url + "/etm/login.jsp"); if (tempToken != null) { loginToken = parseToken(tempToken); } else { showError("Error connecting to MyTLC, make sure you have a valid network connection"); return; } String postResults = null; // This creates our login information List<NameValuePair> parameters = createParams(); if (loginToken != null) { // Here we send the information to the server and login postResults = conn.postData(url + "/etm/login.jsp", parameters); } else { showError("Error retrieving your login token"); return; } if (postResults != null && postResults.toLowerCase().contains("etmmenu.jsp") && !postResults.toLowerCase().contains("<font size=\"2\">")) { updateStatus("Retrieving schedule..."); postResults = conn.getData(url + "/etm/time/timesheet/etmTnsMonth.jsp"); } else { String error = parseError(postResults); if (error != null) { showError(error); } else { showError("Error logging in, please verify your username and password"); } return; } // If we successfully got the information, then parse out the schedule to read it properly String secToken = null; if (postResults != null) { updateStatus("Parsing schedule..."); workDays = parseSchedule(postResults); secToken = parseSecureToken(postResults); wbat = parseWbat(postResults); } else { showError("Could not obtain user schedule"); return; } if (secToken != null) { parameters = createSecondParams(secToken); postResults = conn.postData(url + "/etm/time/timesheet/etmTnsMonth.jsp", parameters); } else { String error = parseError(postResults); if (error != null) { showError(error); } else { showError("Error retrieving your security token"); } return; } List<String[]> secondMonth = null; if (postResults != null) { secondMonth = parseSchedule(postResults); } else { showError("Could not obtain user schedule"); return; } if (secondMonth != null) { if (workDays == null) { workDays = secondMonth; } else { workDays.addAll(secondMonth); } finalDays = workDays; } else { String error = parseError(postResults); if (error != null) { showError(error); } else { showError("There was an error retrieving your schedule"); } return; } // Add our shifts to the calendar updateStatus("Adding shifts to calendar..."); int numShifts = addDays(); if (finalDays != null && numShifts > -1) { // Report back that we're successful! Message msg = Message.obtain(); Bundle b = new Bundle(); b.putString("status", "DONE"); b.putInt("count", numShifts); msg.setData(b); try { messenger.send(msg); } catch (Exception e) { // Nothing } } else { showError("Couldn't add your shifts to your calendar"); } }
From source file:com.CloudRecognition.CloudReco.java
@Override public void onQCARUpdate(State state) { // Get the tracker manager: TrackerManager trackerManager = TrackerManager.getInstance(); // Get the image tracker: ImageTracker imageTracker = (ImageTracker) trackerManager.getTracker(ImageTracker.getClassType()); // Get the target finder: TargetFinder finder = imageTracker.getTargetFinder(); // Check if there are new results available: final int statusCode = finder.updateSearchResults(); // Show a message if we encountered an error: if (statusCode < 0) { boolean closeAppAfterError = (statusCode == UPDATE_ERROR_NO_NETWORK_CONNECTION || statusCode == UPDATE_ERROR_SERVICE_NOT_AVAILABLE); showErrorMessage(statusCode, state.getFrame().getTimeStamp(), closeAppAfterError); } else if (statusCode == TargetFinder.UPDATE_RESULTS_AVAILABLE) { // Process new search results if (finder.getResultCount() > 0) { TargetSearchResult result = finder.getResult(0); Message msg = new Message(); JSONObject json = comm.getInformacionOtroUsuario(result.getTargetName()); Bundle data = conversor(json); msg.setData(data); msg.what = USER_DETECTED;//from ww w. j a v a2 s . c om loadingDialogHandler.sendMessage(msg); // Check if this target is suitable for tracking: if (result.getTrackingRating() > 0) { Trackable trackable = finder.enableTracking(result); if (mExtendedTracking) trackable.startExtendedTracking(); } } } }
From source file:org.navitproject.navit.Navit.java
private void parseNavigationURI(String schemeSpecificPart) { String naviData[] = schemeSpecificPart.split("&"); Pattern p = Pattern.compile("(.*)=(.*)"); Map<String, String> params = new HashMap<String, String>(); for (int count = 0; count < naviData.length; count++) { Matcher m = p.matcher(naviData[count]); if (m.matches()) { params.put(m.group(1), m.group(2)); }//from www . j av a 2 s. c o m } // d: google.navigation:q=blabla-strasse # (this happens when you are offline, or from contacts) // a: google.navigation:ll=48.25676,16.643&q=blabla-strasse // c: google.navigation:ll=48.25676,16.643 // b: google.navigation:q=48.25676,16.643 Float lat; Float lon; Bundle b = new Bundle(); String geoString = params.get("ll"); if (geoString != null) { String address = params.get("q"); if (address != null) b.putString("q", address); } else { geoString = params.get("q"); } if (geoString != null) { if (geoString.matches("^[+-]{0,1}\\d+(|\\.\\d*),[+-]{0,1}\\d+(|\\.\\d*)$")) { String geo[] = geoString.split(","); if (geo.length == 2) { try { lat = Float.valueOf(geo[0]); lon = Float.valueOf(geo[1]); b.putFloat("lat", lat); b.putFloat("lon", lon); Message msg = Message.obtain(N_NavitGraphics.callback_handler, NavitGraphics.msg_type.CLB_SET_DESTINATION.ordinal()); msg.setData(b); msg.sendToTarget(); Log.e("Navit", "target found (b): " + geoString); } catch (NumberFormatException e) { } // nothing to do here } } else { start_targetsearch_from_intent(geoString); } } }
From source file:com.anton.gavel.ComplaintSubmission.java
public void submit() { //Body of your click handler Thread trd = new Thread(new Runnable() { @Override/*from w w w .jav a 2s. co m*/ public void run() { String formPath = "http://www.hamilton.ca/Hamilton.Portal/Templates/COHShell.aspx?NRMODE=Published&NRORIGINALURL=%2fCityDepartments%2fCorporateServices%2fITS%2fForms%2bin%2bDevelopment%2fMunicipal%2bLaw%2bEnforcement%2bOnline%2bComplaint%2bForm%2ehtm&NRNODEGUID=%7b4319AA7C-7E5E-4D65-9F46-CCBEC9AB86E0%7d&NRCACHEHINT=Guest"; String hideString = "document.getElementById('mainform').style.display = 'none';"; //this javascript will be added to the page if we are successful - we can look //for it to identify whether our form was successfully submitted // Create a new HttpClient and Post Header HttpClient httpClient = new DefaultHttpClient(); ArrayList<NameValuePair> parameters = new ArrayList<NameValuePair>(); for (String key : post_params.keySet()) { parameters.add(new BasicNameValuePair(key, post_params.get(key))); String value = post_params.get(key); if (value != null && value.length() > 0) { value = value.substring(0, Math.min(70, value.length())); } Log.d("Runs", "key: '" + key + "', value: '" + value); } //convert to a list of name-value pairs (dum, dee dum - duuuuumm...) HttpPost request = new HttpPost(formPath); //set up handler/bundle to give output to main thread Handler handler = ((GavelMain) mContext).submissionHandler; Message msg = handler.obtainMessage(); Bundle bundle = new Bundle(); try { request.setEntity(new UrlEncodedFormEntity(parameters)); HttpResponse httpResponse = httpClient.execute(request); HttpEntity responseEntity = httpResponse.getEntity(); String response = responseEntity == null ? "" : EntityUtils.toString(responseEntity, EntityUtils.getContentCharSet(responseEntity)); //read the html page posted in response to our request appendLog(response); // logs html page response to a text file on sd card bundle.putBoolean("succeeded", httpResponse.getStatusLine().getStatusCode() == 200 && response.contains(hideString)); msg.setData(bundle); handler.sendMessage(msg); } catch (ClientProtocolException e) { bundle.putBoolean("succeeded", false); msg.setData(bundle); handler.sendMessage(msg); } catch (IOException e) { bundle.putBoolean("succeeded", false); msg.setData(bundle); handler.sendMessage(msg); } //code to do the HTTP request } }); trd.start(); // return; }
From source file:com.psiphon3.psiphonlibrary.TunnelManager.java
private void sendClientMessage(int what, Bundle data) { if (m_incomingMessenger == null || m_outgoingMessenger == null) { return;// w w w. ja v a 2 s. co m } try { Message msg = Message.obtain(null, what); msg.replyTo = m_incomingMessenger; if (data != null) { msg.setData(data); } m_outgoingMessenger.send(msg); } catch (RemoteException e) { MyLog.g("sendClientMessage failed: %s", e.getMessage()); } }
From source file:fr.mixit.android.ui.fragments.SessionDetailsFragment.java
public void refreshSessionData() { if (mIsBound && mServiceReady) { setRefreshMode(true);//from w w w .ja va 2 s . co m final Message msg = Message.obtain(null, MixItContract.Sessions.FORMAT_LIGHTNING_TALK.equalsIgnoreCase(mSessionFormat) ? MixItService.MSG_LIGHTNING_TALK : MixItService.MSG_TALK, 0, 0); msg.replyTo = mMessenger; final Bundle b = new Bundle(); b.putInt(MixItService.EXTRA_ID, mSessionId); msg.setData(b); try { mService.send(msg); } catch (final RemoteException e) { e.printStackTrace(); } mIsFirstLoad = false; } }
From source file:ca.mudar.mtlaucasou.BaseMapActivity.java
/** * This runnable thread gets the Geocode search value in the background * (front activity is the Processing dialog). Results are sent to the * handler.//from w w w .j a v a 2s . c o m */ @Override public void run() { Location loc = null; try { /** * Geocode search. Takes time and not very reliable! */ loc = Helper.findLocatioFromName(getApplicationContext(), postalCode); } catch (IOException e) { Log.e(TAG, e.getMessage()); } Message msg = handler.obtainMessage(); Bundle b = new Bundle(); if (loc == null) { /** * Send error message to handler. */ b.putInt(Const.KEY_BUNDLE_SEARCH_ADDRESS, Const.BUNDLE_SEARCH_ADDRESS_ERROR); } else { /** * Send success message to handler with the found geocoordinates. */ b.putInt(Const.KEY_BUNDLE_SEARCH_ADDRESS, Const.BUNDLE_SEARCH_ADDRESS_SUCCESS); b.putDouble(Const.KEY_BUNDLE_ADDRESS_LAT, loc.getLatitude()); b.putDouble(Const.KEY_BUNDLE_ADDRESS_LNG, loc.getLongitude()); } msg.setData(b); handler.sendMessage(msg); }
From source file:activities.Activity_Main.java
/** Called when the activity is first created. */ @Override//from www . j av a 2 s . c o m public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); myself = this; setContentView(R.layout.activity_home); SP_params = PreferenceManager.getDefaultSharedPreferences(this); SP_prefEditor = SP_params.edit(); Tracer = tracerengine.getInstance(SP_params); //Added by Doume File storage = new File(Environment.getExternalStorageDirectory() + "/domodroid/.conf/"); if (!storage.exists()) storage.mkdirs(); //Configure Tracer tool initial state File logpath = new File(Environment.getExternalStorageDirectory() + "/domodroid/.log/"); if (!logpath.exists()) logpath.mkdirs(); String currlogpath = SP_params.getString("LOGNAME", ""); if (currlogpath.equals("")) { //Not yet existing prefs : Configure debugging by default, to configure Tracer currlogpath = Environment.getExternalStorageDirectory() + "/domodroid/.log/"; SP_prefEditor.putString("LOGPATH", currlogpath); SP_prefEditor.putString("LOGNAME", "Domodroid.txt"); SP_prefEditor.putBoolean("SYSTEMLOG", false); SP_prefEditor.putBoolean("TEXTLOG", false); SP_prefEditor.putBoolean("SCREENLOG", false); SP_prefEditor.putBoolean("LOGCHANGED", true); SP_prefEditor.putBoolean("LOGAPPEND", false); } else { SP_prefEditor.putBoolean("LOGCHANGED", true); //To force Tracer to consider current settings } //prefEditor.putBoolean("SYSTEMLOG", false); // For tests : no system logs.... SP_prefEditor.putBoolean("SYSTEMLOG", true); // For tests : with system logs.... SP_prefEditor.commit(); Tracer.set_profile(SP_params); // Create .nomedia file, that will prevent Android image gallery from showing domodroid file String nomedia = Environment.getExternalStorageDirectory() + "/domodroid/.nomedia"; try { if (!(new File(nomedia).exists())) { new FileOutputStream(nomedia).close(); } } catch (Exception e) { } appname = (ImageView) findViewById(R.id.app_name); LoadSelections(); // Prepare a listener to know when a sync dialog is closed... if (sync_listener == null) { sync_listener = new DialogInterface.OnDismissListener() { public void onDismiss(DialogInterface dialog) { Tracer.d(mytag, "sync dialog has been closed !"); // Is it success or fail ? if (((Dialog_Synchronize) dialog).need_refresh) { // Sync has been successful : Force to refresh current main view Tracer.d(mytag, "sync dialog requires a refresh !"); reload = true; // Sync being done, consider shared prefs are OK VG_parent.removeAllViews(); if (WU_widgetUpdate != null) { WU_widgetUpdate.resync(); } else { Tracer.i(mytag + ".onCreate", "WidgetUpdate is null startCacheengine!"); startCacheEngine(); } Bundle b = new Bundle(); //Notify sync complete to parent Dialog b.putInt("id", 0); b.putString("type", "root"); Message msg = new Message(); msg.setData(b); if (widgetHandler != null) widgetHandler.sendMessage(msg); // That should force to refresh Views /* */ if (WU_widgetUpdate != null) { WU_widgetUpdate.Disconnect(0); //That should disconnect all opened widgets from cache engine //widgetUpdate.dump_cache(); //For debug dont_kill = true; // to avoid engines kill when onDestroy() } onResume(); } else { Tracer.d(mytag, "sync dialog end with no refresh !"); } ((Dialog_Synchronize) dialog).need_refresh = false; } }; } //update thread sbanim = new Handler() { @Override public void handleMessage(Message msg) { if (msg.what == 0) { appname.setImageDrawable(getResources().getDrawable(R.drawable.app_name2)); } else if (msg.what == 1) { appname.setImageDrawable(getResources().getDrawable(R.drawable.app_name3)); } else if (msg.what == 2) { appname.setImageDrawable(getResources().getDrawable(R.drawable.app_name1)); } else if (msg.what == 3) { appname.setImageDrawable(getResources().getDrawable(R.drawable.app_name4)); } else if (msg.what == 8000) { Tracer.e(mytag, "Request to display message : 8000"); /* if(dialog_message == null) { Create_message_box(); } dialog_message.setMessage("Starting cache engine..."); dialog_message.show(); */ } else if (msg.what == 8999) { //Cache engine is ready for use.... if (Tracer != null) Tracer.e(mytag, "Cache engine has notified it's ready !"); cache_ready = true; if (end_of_init_requested) end_of_init(); PG_dialog_message.dismiss(); } } }; //power management final PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); this.PM_WakeLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, ""); this.PM_WakeLock.acquire(); //titlebar final FrameLayout titlebar = (FrameLayout) findViewById(R.id.TitleBar); titlebar.setBackgroundDrawable(Gradients_Manager.LoadDrawable("title", 40)); //Parent view VG_parent = (ViewGroup) findViewById(R.id.home_container); LL_house_map = new LinearLayout(this); LL_house_map .setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); LL_house_map.setOrientation(LinearLayout.HORIZONTAL); LL_house_map.setPadding(5, 5, 5, 5); house = new Basic_Graphical_zone(getApplicationContext(), 0, Graphics_Manager.Names_Agent(this, "House"), "", "house", 0, "", null); house.setPadding(0, 0, 5, 0); map = new Basic_Graphical_zone(getApplicationContext(), 0, Graphics_Manager.Names_Agent(this, "Map"), "", "map", 0, "", null); map.setPadding(5, 0, 0, 0); LinearLayout.LayoutParams param = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT, 1.0f); house.setLayoutParams(param); house.setOnClickListener(new OnClickListener() { public void onClick(View v) { if (SP_params.getBoolean("SYNC", false)) { loadWigets(0, "root"); historyPosition++; history.add(historyPosition, new String[] { "0", "root" }); } else { if (AD_notSyncAlert == null) createAlert(); AD_notSyncAlert.show(); } } }); map.setLayoutParams(param); map.setOnClickListener(new OnClickListener() { public void onClick(View v) { if (SP_params.getBoolean("SYNC", false)) { //dont_freeze=true; //To avoid WidgetUpdate engine freeze Tracer.w(mytag, "Before call to Map, Disconnect widgets from engine !"); if (WU_widgetUpdate != null) { WU_widgetUpdate.Disconnect(0); //That should disconnect all opened widgets from cache engine //widgetUpdate.dump_cache(); //For debug dont_kill = true; // to avoid engines kill when onDestroy() } INTENT_map = new Intent(Activity_Main.this, Activity_Map.class); Tracer.d(mytag, "Call to Map, run it now !"); Tracer.Map_as_main = false; startActivity(INTENT_map); } else { if (AD_notSyncAlert == null) createAlert(); AD_notSyncAlert.show(); } } }); LL_house_map.addView(house); LL_house_map.addView(map); init_done = false; // Detect if it's the 1st use after installation... if (!SP_params.getBoolean("SPLASH", false)) { // Yes, 1st use ! init_done = false; reload = false; if (backupprefs.exists()) { // A backup exists : Ask if reload it Tracer.v(mytag, "settings backup found after a fresh install..."); DialogInterface.OnClickListener reload_listener = new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { Tracer.e(mytag, "Reload dialog returns : " + which); if (which == dialog.BUTTON_POSITIVE) { reload = true; } else if (which == dialog.BUTTON_NEGATIVE) { reload = false; } check_answer(); dialog.dismiss(); } }; dialog_reload = new AlertDialog.Builder(this); dialog_reload.setMessage(getText(R.string.home_reload)); dialog_reload.setTitle(getText(R.string.reload_title)); dialog_reload.setPositiveButton(getText(R.string.reloadOK), reload_listener); dialog_reload.setNegativeButton(getText(R.string.reloadNO), reload_listener); dialog_reload.show(); init_done = false; //A choice is pending : Rest of init has to be completed... } else { //No settings backup found Tracer.v(mytag, "no settings backup found after fresh install..."); end_of_init_requested = true; // open server config view Intent helpI = new Intent(Activity_Main.this, Preference.class); startActivity(helpI); } } else { // It's not the 1st use after fresh install // This method will be followed by 'onResume()' end_of_init_requested = true; } if (SP_params.getBoolean("SYNC", false)) { //A config exists and a sync as been done by past. if (WU_widgetUpdate == null) { Tracer.i(mytag + ".onCreate", "Params splach is false and WidgetUpdate is null startCacheengine!"); startCacheEngine(); } } Tracer.e(mytag, "OnCreate() complete !"); // End of onCreate (UIThread) }
From source file:org.zywx.wbpalmstar.engine.universalex.EUExWidget.java
public void isAppInstalled(String[] params) { if (params == null || params.length < 1) { errorCallback(0, 0, "error params!"); return;/*w w w. j a v a2 s. co m*/ } Message msg = new Message(); msg.obj = this; msg.what = MSG_IS_APP_INSTALLED; Bundle bd = new Bundle(); bd.putStringArray(BUNDLE_DATA, params); msg.setData(bd); mHandler.sendMessage(msg); }