List of usage examples for android.os Message sendToTarget
public void sendToTarget()
From source file:de.unwesen.packrat.api.FeedReader.java
private void updateFeed(Uri uri, Handler handler) { // Log.d(LTAG, "Fetching feed: " + uri); // Convert Uri to URI... yes, it sucks. URI feed_uri = null;/* w ww. ja v a 2s. c o m*/ try { feed_uri = new URI(uri.toString()); } catch (URISyntaxException ex) { Log.e(LTAG, "Invalid feed URI: " + uri); Message m = handler.obtainMessage(FR_INVALID_FEED_URI); m.sendToTarget(); return; } // Construct request HttpGet request = new HttpGet(feed_uri); request.addHeader("Referer", REFERER_URL); HttpResponse response; try { response = sClient.execute(request); // Read response HttpEntity entity = response.getEntity(); if (null == entity) { Log.e(LTAG, "Feed is empty: " + uri); Message m = handler.obtainMessage(FR_EMPTY_FEED); m.sendToTarget(); return; } MediaParser parser = new MediaParser(); MediaParser.AtomFeed feed = parser.parse(entity.getContent()); if (null == feed) { Log.e(LTAG, "Unable to parse feed, exiting: " + uri); Message m = handler.obtainMessage(FR_FEED_PARSE_FAILURE); m.sendToTarget(); return; } LinkedList<Media> result = parseFeed(feed); if (null != result && result.size() > 0) { Message m = handler.obtainMessage(FR_SUCCESS, result); m.sendToTarget(); } else { Message m = handler.obtainMessage(FR_EMPTY_FEED); m.sendToTarget(); } } catch (IOException ex) { Log.w(LTAG, "IO exception: " + ex); Message m = handler.obtainMessage(FR_NETWORK_ERROR); m.sendToTarget(); } catch (Exception ex) { Log.e(LTAG, "An exception occurred when reading the feed: " + ex); Message m = handler.obtainMessage(FR_UNKNOWN_ERROR); m.sendToTarget(); } }
From source file:de.ub0r.android.callmeter.data.RuleMatcher.java
/** * Match all unmatched logs./*from ww w .j a v a2s .co m*/ * * @param context {@link Context} * @param showStatus post status to dialog/handler * @return true if a log was matched */ static synchronized boolean match(final Context context, final boolean showStatus) { Log.d(TAG, "match(ctx, ", showStatus, ")"); long start = System.currentTimeMillis(); boolean ret = false; load(context); final ContentResolver cr = context.getContentResolver(); final Cursor cursor = cr.query(DataProvider.Logs.CONTENT_URI, DataProvider.Logs.PROJECTION, DataProvider.Logs.PLAN_ID + " = " + DataProvider.NO_ID, null, DataProvider.Logs.DATE + " ASC"); if (cursor != null && cursor.moveToFirst()) { final int l = cursor.getCount(); Handler h; if (showStatus) { h = Plans.getHandler(); if (h != null) { final Message m = h.obtainMessage(Plans.MSG_BACKGROUND_PROGRESS_MATCHER); m.arg1 = 0; m.arg2 = l; m.sendToTarget(); } } try { ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>(); int i = 1; do { ret |= matchLog(cr, ops, cursor); if (i % PROGRESS_STEPS == 0 || (i < PROGRESS_STEPS && i % CallMeter.TEN == 0)) { h = Plans.getHandler(); if (h != null) { final Message m = h.obtainMessage(Plans.MSG_BACKGROUND_PROGRESS_MATCHER); m.arg1 = i; m.arg2 = l; Log.d(TAG, "send progress: ", i, "/", l); m.sendToTarget(); } else { Log.d(TAG, "send progress: ", i, " handler=null"); } Log.d(TAG, "save logs.."); cr.applyBatch(DataProvider.AUTHORITY, ops); ops.clear(); Log.d(TAG, "sleeping.."); try { Thread.sleep(CallMeter.MILLIS); } catch (InterruptedException e) { Log.e(TAG, "sleep interrupted", e); } Log.d(TAG, "sleep finished"); } ++i; } while (cursor.moveToNext()); if (ops.size() > 0) { cr.applyBatch(DataProvider.AUTHORITY, ops); } } catch (IllegalStateException e) { Log.e(TAG, "illegal state in RuleMatcher's loop", e); } catch (OperationApplicationException e) { Log.e(TAG, "illegal operation in RuleMatcher's loop", e); } catch (RemoteException e) { Log.e(TAG, "remote exception in RuleMatcher's loop", e); } } try { if (cursor != null && !cursor.isClosed()) { cursor.close(); } } catch (IllegalStateException e) { Log.e(TAG, "illegal state while closing cursor", e); } if (ret) { final SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(context); final boolean a80 = p.getBoolean(Preferences.PREFS_ALERT80, true); final boolean a100 = p.getBoolean(Preferences.PREFS_ALERT100, true); // check for alerts if ((a80 || a100) && plans != null && plans.size() > 0) { final long now = System.currentTimeMillis(); int alert = 0; Plan alertPlan = null; int l = plans.size(); for (int i = 0; i < l; i++) { final Plan plan = plans.valueAt(i); if (plan == null) { continue; } if (plan.nextAlert > now) { Log.d(TAG, "%s: skip alert until: %d now=%d", plan, plan.nextAlert, now); continue; } int used = DataProvider.Plans.getUsed(plan.type, plan.limitType, plan.billedAmount, plan.billedCost); int usedRate = plan.limit > 0 ? (int) ((used * CallMeter.HUNDRED) / plan.limit) : 0; if (a100 && usedRate >= CallMeter.HUNDRED) { alert = usedRate; alertPlan = plan; } else if (a80 && alert < CallMeter.EIGHTY && usedRate >= CallMeter.EIGHTY) { alert = usedRate; alertPlan = plan; } } if (alert > 0) { final NotificationManager mNotificationMgr = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); final String t = String.format(context.getString(R.string.alerts_message), alertPlan.name, alert); NotificationCompat.Builder b = new NotificationCompat.Builder(context); b.setSmallIcon(android.R.drawable.stat_notify_error); b.setTicker(t); b.setWhen(now); b.setContentTitle(context.getString(R.string.alerts_title)); b.setContentText(t); Intent i = new Intent(context, Plans.class); i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); b.setContentIntent(PendingIntent.getActivity(context, 0, i, PendingIntent.FLAG_CANCEL_CURRENT)); mNotificationMgr.notify(0, b.build()); // set nextAlert to beginning of next day Calendar cal = Calendar.getInstance(); cal.add(Calendar.DAY_OF_MONTH, 1); cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); alertPlan.nextAlert = cal.getTimeInMillis(); final ContentValues cv = new ContentValues(); cv.put(DataProvider.Plans.NEXT_ALERT, alertPlan.nextAlert); cr.update(DataProvider.Plans.CONTENT_URI, cv, DataProvider.Plans.ID + " = ?", new String[] { String.valueOf(alertPlan.id) }); } } } long end = System.currentTimeMillis(); Log.i(TAG, "match(): ", end - start, "ms"); return ret; }
From source file:com.sai.b2blogistic.RegisterActivity.java
/** */ @Override/* w w w . ja v a 2s . c o m*/ protected void onActivityResult(int requestCode, int resultCode, final Intent data) { if (resultCode == RESULT_OK) { switch (requestCode) { case R.id.reg_pic1_btn: // // lodingView.setVisibility(View.VISIBLE); lodingText.setText(""); // new Thread() { @Override public void run() { String resultStr = uploadPic(data.getStringExtra("path")); Message msg = uploadFileHandler.obtainMessage(); RestResult<String> result = gson.fromJson(resultStr, new TypeToken<RestResult<String>>() { }.getType()); handlerMsg = result.getMessage(); if ("1".equals(result.getStatus())) { pic1_path = result.getData(); } msg.sendToTarget(); } }.start(); break; case R.id.reg_pic2_btn: // // lodingView.setVisibility(View.VISIBLE); lodingText.setText(""); // new Thread() { @Override public void run() { String resultStr = uploadPic(data.getStringExtra("path")); Message msg = uploadFileHandler.obtainMessage(); RestResult<String> result = gson.fromJson(resultStr, new TypeToken<RestResult<String>>() { }.getType()); handlerMsg = result.getMessage(); if ("1".equals(result.getStatus())) { pic2_path = result.getData(); } msg.sendToTarget(); } }.start(); break; case R.id.reg_pic3_btn: // // lodingView.setVisibility(View.VISIBLE); lodingText.setText(""); // new Thread() { @Override public void run() { String resultStr = uploadPic(data.getStringExtra("path")); Message msg = uploadFileHandler.obtainMessage(); RestResult<String> result = gson.fromJson(resultStr, new TypeToken<RestResult<String>>() { }.getType()); handlerMsg = result.getMessage(); if ("1".equals(result.getStatus())) { pic3_path = result.getData(); } msg.sendToTarget(); } }.start(); break; default: break; } } else { switch (requestCode) { case R.id.reg_pic1_btn: case R.id.reg_pic2_btn: case R.id.reg_pic3_btn: // ToolKits.showAlertDialog(this, "", ""); break; default: break; } } }
From source file:org.zywx.wbpalmstar.engine.EBrowserActivity.java
public final void exitApp(boolean showDilog) { Message msg = mEHandler.obtainMessage(EHandler.F_MSG_EXIT_APP, showDilog); msg.sendToTarget(); }
From source file:org.harleydroid.HarleyDroidService.java
public void setSendData(String type[], String ta[], String sa[], String command[], String expect[], int timeout[], int delay) { if (D)// www . java 2 s . com Log.d(TAG, "setSendData()"); Message m = mServiceHandler.obtainMessage(MSG_SET_SEND); Bundle b = new Bundle(); b.putStringArray("type", type); b.putStringArray("ta", ta); b.putStringArray("sa", sa); b.putStringArray("command", command); b.putStringArray("expect", expect); b.putIntArray("timeout", timeout); b.putInt("delay", delay); m.setData(b); //mServiceHandler.removeCallbacksAndMessages(null); m.sendToTarget(); }
From source file:org.harleydroid.HarleyDroidService.java
public void startSend(String type[], String ta[], String sa[], String command[], String expect[], int timeout[], int delay) { if (D)//from w w w . ja v a 2 s.com Log.d(TAG, "send()"); Message m = mServiceHandler.obtainMessage(MSG_START_SEND); Bundle b = new Bundle(); b.putStringArray("type", type); b.putStringArray("ta", ta); b.putStringArray("sa", sa); b.putStringArray("command", command); b.putStringArray("expect", expect); b.putIntArray("timeout", timeout); b.putInt("delay", delay); m.setData(b); //mServiceHandler.removeCallbacksAndMessages(null); m.sendToTarget(); }
From source file:de.androvdr.activities.AndroVDR.java
public void initWorkspaceView(Bundle savedInstanceState) { if (!Preferences.alternateLayout) setTheme(R.style.Theme_Original); logger.debug("Model: {}", Build.MODEL); logger.debug("SDK Version: {}", Build.VERSION.SDK_INT); DisplayMetrics metrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(metrics); logger.debug("Width: {}", metrics.widthPixels); logger.debug("Height: {}", metrics.heightPixels); logger.debug("Density: {}", metrics.densityDpi); Configuration conf = getResources().getConfiguration(); boolean screenSmall = ((conf.screenLayout & Configuration.SCREENLAYOUT_SIZE_SMALL) == Configuration.SCREENLAYOUT_SIZE_SMALL); boolean screenNormal = ((conf.screenLayout & Configuration.SCREENLAYOUT_SIZE_NORMAL) == Configuration.SCREENLAYOUT_SIZE_NORMAL); boolean screenLong = ((conf.screenLayout & Configuration.SCREENLAYOUT_LONG_YES) == Configuration.SCREENLAYOUT_LONG_YES); boolean screenLarge = ((conf.screenLayout & Configuration.SCREENLAYOUT_SIZE_LARGE) == Configuration.SCREENLAYOUT_SIZE_LARGE); boolean screenXLarge = ((conf.screenLayout & Configuration.SCREENLAYOUT_SIZE_XLARGE) == Configuration.SCREENLAYOUT_SIZE_XLARGE); logger.debug("Screen Small: {}", screenSmall); logger.debug("Screen Normal: {}", screenNormal); logger.debug("Screen Long: {}", screenLong); logger.debug("Screen Large: {}", screenLarge); logger.debug("Screen XLarge: {}", screenXLarge); if (screenSmall) Preferences.screenSize = Preferences.SCREENSIZE_SMALL; if (screenNormal) Preferences.screenSize = Preferences.SCREENSIZE_NORMAL; if (screenLong) Preferences.screenSize = Preferences.SCREENSIZE_LONG; if (screenLarge) Preferences.screenSize = Preferences.SCREENSIZE_LARGE; if (screenXLarge) Preferences.screenSize = Preferences.SCREENSIZE_XLARGE; logger.trace("Screen size: {}", Preferences.screenSize); // --- init default text size for buttons --- TextResizeButton.resetDefaultTextSize(); TextResizeButton rb = (TextResizeButton) LayoutInflater.from(this).inflate(R.layout.reference_button, null); if ((Preferences.screenSize >= Preferences.SCREENSIZE_LARGE) && (metrics.widthPixels > metrics.heightPixels)) rb.setTextSizeAsDefault(metrics.widthPixels / 2 / 5, 100); else//from w ww.j a v a2 s. co m rb.setTextSizeAsDefault(Math.min(metrics.widthPixels, metrics.heightPixels) / 4, 100); logger.debug("Default TextSize (px): {}", rb.getTextSize()); // --- landscape mode only on large displays --- if (Preferences.screenSize < Preferences.SCREENSIZE_LARGE) { logger.trace("setting SCREEN_ORIENTATION_PORTRAIT"); setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); } setContentView(R.layout.remote_pager); mPagerAdapter = new PagerAdapter(getSupportFragmentManager()); mPager = (ViewPager) findViewById(R.id.pager); mPager.setAdapter(mPagerAdapter); LinePageIndicator indicator = (LinePageIndicator) findViewById(R.id.titles); if (mPagerAdapter.getCount() > 1) { SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this); int last = sp.getInt("remote_last_page", 0); if (last < mPagerAdapter.getCount()) indicator.setViewPager(mPager, last); else indicator.setViewPager(mPager); } else { indicator.setVisibility(View.GONE); } // --- show current channel in status bar --- if (Preferences.screenSize < Preferences.SCREENSIZE_XLARGE) mDevices.addOnSensorChangeListener("VDR.channel", 1, new OnSensorChangeListener() { @Override public void onChange(String result) { logger.trace("Channel: {}", result); Message msg = Message.obtain(mSensorHandler, SENSOR_CHANNEL); Bundle bundle = new Bundle(); bundle.putString(MSG_RESULT, result); msg.setData(bundle); msg.sendToTarget(); } }); mDevices.startSensorUpdater(0); }
From source file:org.zywx.wbpalmstar.widgetone.WidgetOneApplication.java
public final void initApp(final Context ctx, final Message resultMsg) { new Thread("Appcan-WidgetOneInit") { public void run() { resultMsg.arg1 = 0;// default fail initPlugin();/*from w w w. j a va 2s . c o m*/ WDataManager wDataManager = new WDataManager(ctx); WWidgetData widgetData = wDataManager.getWidgetData(); if (widgetData != null && widgetData.m_indexUrl != null) { resultMsg.arg1 = 1;// success resultMsg.obj = widgetData; BUtility.initWidgetOneFile(ctx, widgetData.m_appId); } resultMsg.sendToTarget(); }; }.start(); }
From source file:info.guardianproject.otr.app.im.service.RemoteImService.java
public void showToast(CharSequence text, int duration) { Message msg = Message.obtain(mServiceHandler, EVENT_SHOW_TOAST, duration, 0, text); msg.sendToTarget(); }
From source file:org.navitproject.navit.Navit.java
protected void onActivityResult(int requestCode, int resultCode, Intent data) { switch (requestCode) { case Navit.NavitDownloaderSelectMap_id: if (resultCode == Activity.RESULT_OK) { Message msg = dialogs.obtainMessage(NavitDialogs.MSG_START_MAP_DOWNLOAD, data.getIntExtra("map_index", -1), 0); msg.sendToTarget(); }//from w w w . j a va 2s. c o m break; case NavitAddressSearch_id: if (resultCode == Activity.RESULT_OK) { Bundle destination = data.getExtras(); Toast.makeText(getApplicationContext(), getString(R.string.address_search_set_destination) + "\n" + destination.getString(("q")), Toast.LENGTH_LONG).show(); //TRANS Message msg = Message.obtain(N_NavitGraphics.callback_handler, NavitGraphics.msg_type.CLB_SET_DESTINATION.ordinal()); msg.setData(destination); msg.sendToTarget(); } break; case NavitSelectStorage_id: if (resultCode == RESULT_OK) { String newDir = data.getStringExtra(FileBrowserActivity.returnDirectoryParameter); Log.d(TAG, "selected path= " + newDir); if (!newDir.contains("/navit")) newDir = newDir + "/navit/"; else newDir = newDir + "/"; SharedPreferences prefs = this.getSharedPreferences(NAVIT_PREFS, MODE_PRIVATE); SharedPreferences.Editor prefs_editor = prefs.edit(); prefs_editor.putString("filenamePath", newDir); prefs_editor.commit(); Toast.makeText(this, String .format(Navit._("New location set to %s\nRestart Navit to apply the changes."), newDir), Toast.LENGTH_LONG).show(); } else Log.w(TAG, "select path failed"); break; default: //Log.e("Navit", "onActivityResult " + requestCode + " " + resultCode); ActivityResults[requestCode].onActivityResult(requestCode, resultCode, data); break; } }