List of usage examples for android.app Notification setLatestEventInfo
@Deprecated public void setLatestEventInfo(Context context, CharSequence contentTitle, CharSequence contentText, PendingIntent contentIntent)
From source file:keyboard.ecloga.com.eclogakeyboard.EclogaKeyboard.java
@Override public void onStartInputView(EditorInfo info, boolean restarting) { initializeKeyboard();/* w w w . ja v a2 s . c o m*/ onRotate(); if (mVoiceRecognitionTrigger != null) { mVoiceRecognitionTrigger.onStartInputView(); } vbListenerPause = false; if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("random")) { Random rand = new Random(); int randInt = rand.nextInt(25); switch (randInt) { case 1: kv.setBackgroundColor(getResources().getColor(R.color.white)); break; case 2: kv.setBackgroundColor(getResources().getColor(R.color.black)); break; case 3: kv.setBackgroundColor(getResources().getColor(R.color.purple)); break; case 4: kv.setBackgroundColor(getResources().getColor(R.color.red)); break; case 5: kv.setBackgroundColor(getResources().getColor(R.color.pink)); break; case 6: kv.setBackgroundColor(getResources().getColor(R.color.blue)); break; case 7: kv.setBackgroundColor(getResources().getColor(R.color.green)); break; case 8: kv.setBackgroundColor(getResources().getColor(R.color.yellow)); break; case 9: kv.setBackgroundColor(getResources().getColor(R.color.orange)); break; case 10: kv.setBackgroundColor(getResources().getColor(R.color.grey)); break; case 11: kv.setBackgroundColor(getResources().getColor(R.color.lightpurple)); break; case 12: kv.setBackgroundColor(getResources().getColor(R.color.lightred)); break; case 13: kv.setBackgroundColor(getResources().getColor(R.color.lightpink)); break; case 14: kv.setBackgroundColor(getResources().getColor(R.color.lightblue)); break; case 15: kv.setBackgroundColor(getResources().getColor(R.color.lightgreen)); break; case 16: kv.setBackgroundColor(getResources().getColor(R.color.lightyellow)); break; case 17: kv.setBackgroundColor(getResources().getColor(R.color.lightgrey)); break; case 18: kv.setBackgroundColor(getResources().getColor(R.color.lightorange)); break; case 19: kv.setBackgroundColor(getResources().getColor(R.color.darkpurple)); break; case 20: kv.setBackgroundColor(getResources().getColor(R.color.darkorange)); break; case 21: kv.setBackgroundColor(getResources().getColor(R.color.darkblue)); break; case 22: kv.setBackgroundColor(getResources().getColor(R.color.darkgreen)); break; case 23: kv.setBackgroundColor(getResources().getColor(R.color.darkred)); break; case 24: kv.setBackgroundColor(getResources().getColor(R.color.darkyellow)); break; case 25: kv.setBackgroundColor(getResources().getColor(R.color.darkpink)); break; } } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("pattern_1")) { kv.setBackgroundResource(R.drawable.pattern_1); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("pattern_2")) { kv.setBackgroundResource(R.drawable.pattern_2); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("pattern_3")) { kv.setBackgroundResource(R.drawable.pattern_3); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("pattern_4")) { kv.setBackgroundResource(R.drawable.pattern_4); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("pattern_5")) { kv.setBackgroundResource(R.drawable.pattern_5); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("pattern_6")) { kv.setBackgroundResource(R.drawable.pattern_6); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("pattern_7")) { kv.setBackgroundResource(R.drawable.pattern_7); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("pattern_8")) { kv.setBackgroundResource(R.drawable.pattern_8); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("pattern_9")) { kv.setBackgroundResource(R.drawable.pattern_9); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("pattern_10")) { kv.setBackgroundResource(R.drawable.pattern_10); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("pattern_11")) { kv.setBackgroundResource(R.drawable.pattern_11); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("pattern_12")) { kv.setBackgroundResource(R.drawable.pattern_12); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("pattern_13")) { kv.setBackgroundResource(R.drawable.pattern_13); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("pattern_14")) { kv.setBackgroundResource(R.drawable.pattern_14); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("pattern_15")) { kv.setBackgroundResource(R.drawable.pattern_15); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("pattern_16")) { kv.setBackgroundResource(R.drawable.pattern_16); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("pattern_17")) { kv.setBackgroundResource(R.drawable.pattern_17); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("nature_1")) { kv.setBackgroundResource(R.drawable.nature_1); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("nature_2")) { kv.setBackgroundResource(R.drawable.nature_2); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("nature_3")) { kv.setBackgroundResource(R.drawable.nature_3); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("nature_4")) { kv.setBackgroundResource(R.drawable.nature_4); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("nature_5")) { kv.setBackgroundResource(R.drawable.nature_5); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("nature_6")) { kv.setBackgroundResource(R.drawable.nature_6); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("nature_7")) { kv.setBackgroundResource(R.drawable.nature_7); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("nature_8")) { kv.setBackgroundResource(R.drawable.nature_8); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("nature_9")) { kv.setBackgroundResource(R.drawable.nature_9); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("nature_10")) { kv.setBackgroundResource(R.drawable.nature_10); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("nature_11")) { kv.setBackgroundResource(R.drawable.nature_11); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("nature_12")) { kv.setBackgroundResource(R.drawable.nature_12); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("nature_13")) { kv.setBackgroundResource(R.drawable.nature_13); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("nature_14")) { kv.setBackgroundResource(R.drawable.nature_14); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("black")) { kv.setBackgroundColor(getResources().getColor(R.color.black)); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("white")) { kv.setBackgroundColor(getResources().getColor(R.color.white)); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("transparent")) { kv.setBackgroundColor(getResources().getColor(R.color.transparent)); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("gradient_1")) { kv.setBackgroundResource(R.drawable.gradient_1); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("gradient_2")) { kv.setBackgroundResource(R.drawable.gradient_2); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("gradient_3")) { kv.setBackgroundResource(R.drawable.gradient_3); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("gradient_4")) { kv.setBackgroundResource(R.drawable.gradient_4); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("gradient_5")) { kv.setBackgroundResource(R.drawable.gradient_5); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("gradient_6")) { kv.setBackgroundResource(R.drawable.gradient_6); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("gradient_7")) { kv.setBackgroundResource(R.drawable.gradient_7); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("gradient_8")) { kv.setBackgroundResource(R.drawable.gradient_8); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("gradient_9")) { kv.setBackgroundResource(R.drawable.gradient_9); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("gradient_10")) { kv.setBackgroundResource(R.drawable.gradient_10); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("red")) { kv.setBackgroundColor(getResources().getColor(R.color.red)); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("pink")) { kv.setBackgroundColor(getResources().getColor(R.color.pink)); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("purple")) { kv.setBackgroundColor(getResources().getColor(R.color.purple)); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("blue")) { kv.setBackgroundColor(getResources().getColor(R.color.blue)); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("green")) { kv.setBackgroundColor(getResources().getColor(R.color.green)); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("yellow")) { kv.setBackgroundColor(getResources().getColor(R.color.yellow)); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("orange")) { kv.setBackgroundColor(getResources().getColor(R.color.orange)); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("grey")) { kv.setBackgroundColor(getResources().getColor(R.color.grey)); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("lightred")) { kv.setBackgroundColor(getResources().getColor(R.color.lightred)); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("lightpink")) { kv.setBackgroundColor(getResources().getColor(R.color.lightpink)); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("lightpurple")) { kv.setBackgroundColor(getResources().getColor(R.color.lightpurple)); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("lightblue")) { kv.setBackgroundColor(getResources().getColor(R.color.lightblue)); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("lightgreen")) { kv.setBackgroundColor(getResources().getColor(R.color.lightgreen)); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("lightyellow")) { kv.setBackgroundColor(getResources().getColor(R.color.lightyellow)); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("lightorange")) { kv.setBackgroundColor(getResources().getColor(R.color.lightorange)); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("lightgrey")) { kv.setBackgroundColor(getResources().getColor(R.color.lightgrey)); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("darkred")) { kv.setBackgroundColor(getResources().getColor(R.color.darkred)); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("darkpink")) { kv.setBackgroundColor(getResources().getColor(R.color.darkpink)); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("darkpurple")) { kv.setBackgroundColor(getResources().getColor(R.color.darkpurple)); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("darkblue")) { kv.setBackgroundColor(getResources().getColor(R.color.darkblue)); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("darkgreen")) { kv.setBackgroundColor(getResources().getColor(R.color.darkgreen)); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("darkyellow")) { kv.setBackgroundColor(getResources().getColor(R.color.darkyellow)); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("darkorange")) { kv.setBackgroundColor(getResources().getColor(R.color.darkorange)); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("darkgrey")) { kv.setBackgroundColor(getResources().getColor(R.color.darkgrey)); } else { String uploadString = Preferences.getDefaults("bgcolor", getApplicationContext()); byte[] decodedString = Base64.decode(uploadString, Base64.URL_SAFE); Bitmap photo = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length); BitmapDrawable bdrawable = new BitmapDrawable(getApplication().getResources(), photo); kv.setBackgroundDrawable(bdrawable); } if (Preferences.getDefaults("autocapitalize", getApplicationContext()).equals("true")) { autoCapitalize = true; } else if (Preferences.getDefaults("autocapitalize", getApplicationContext()).equals("false")) { autoCapitalize = false; } if (Preferences.getDefaults("volumebuttons", getApplicationContext()).equals("true")) { volumeButtons = true; } else if (Preferences.getDefaults("volumebuttons", getApplicationContext()).equals("false")) { volumeButtons = false; } if (Preferences.getDefaults("allcaps", getApplicationContext()).equals("true")) { allCaps = true; } else if (Preferences.getDefaults("allcaps", getApplicationContext()).equals("false")) { allCaps = false; } if (Preferences.getDefaults("autospacing", getApplicationContext()).equals("true")) { autoSpacing = true; } else if (Preferences.getDefaults("autospacing", getApplicationContext()).equals("false")) { autoSpacing = false; } if (Preferences.getDefaults("changekeyboard", getApplicationContext()).equals("true")) { changeKeyboard = true; } else if (Preferences.getDefaults("changekeyboard", getApplicationContext()).equals("false")) { changeKeyboard = false; } if (Preferences.getDefaults("shakedelete", getApplicationContext()).equals("true")) { shakeDelete = true; } else if (Preferences.getDefaults("shakedelete", getApplicationContext()).equals("false")) { shakeDelete = false; } if (Preferences.getDefaults("doublespace", getApplicationContext()).equals("true")) { spaceDot = true; } else if (Preferences.getDefaults("doublespace", getApplicationContext()).equals("false")) { spaceDot = false; } if (Preferences.getDefaults("voiceinput", getApplicationContext()).equals("true")) { voiceInput = true; } else if (Preferences.getDefaults("voiceinout", getApplicationContext()).equals("false")) { voiceInput = false; } if (Preferences.getDefaults("popup", getApplicationContext()).equals("true")) { popupKeypress = true; } else if (Preferences.getDefaults("popup", getApplicationContext()).equals("false")) { popupKeypress = false; } if (Preferences.getDefaults("oppositecase", getApplicationContext()).equals("true")) { oppositeCase = true; } else if (Preferences.getDefaults("oppositecase", getApplicationContext()).equals("false")) { oppositeCase = false; } if (changeKeyboard) { MovementDetector.getInstance(getApplicationContext()).start(); MovementDetector.getInstance(getApplicationContext()).addListener(new MovementDetector.Listener() { @Override public void onMotionDetected(SensorEvent event, float acceleration) { if (MovementDetector.direction[1].equals("LEFT")) { playSwipeH(); onSwipeLeft(); } else if (MovementDetector.direction[1].equals("RIGHT")) { playSwipeH(); onSwipeRight(); } if (MovementDetector.direction[0].equals("UP")) { playSwipeV(); onSwipeUp(); } else if (MovementDetector.direction[0].equals("DOWN")) { playSwipeV(); onSwipeDown(); } } }); } keypresscounter1 = Preferences.getDefaults("keypresscounter1", getApplicationContext()); keypresscounter2 = Preferences.getDefaults("keypresscounter2", getApplicationContext()); keypresscounter3 = Preferences.getDefaults("keypresscounter3", getApplicationContext()); keyPressCounter = Integer.parseInt(Preferences.getDefaults("keypresses", getApplicationContext())); time1 = Preferences.getDefaults("time1", getApplicationContext()); time2 = Preferences.getDefaults("time2", getApplicationContext()); time3 = Preferences.getDefaults("time3", getApplicationContext()); time = Integer.parseInt(Preferences.getDefaults("time", getApplicationContext())); tTime = new CountDownTimer(60000, 1000) { @Override public void onTick(long millisUntilFinished) { time = time + 1; if (time > 300 && time <= 960 && time1.equals("false")) { NotificationManager notif = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); Notification notify = new Notification(R.drawable.notify, "Ecloga Keyboard", System.currentTimeMillis()); PendingIntent pending = PendingIntent.getActivity(getApplicationContext(), 0, new Intent(getApplicationContext(), Home.class), 0); notify.setLatestEventInfo(getApplicationContext(), "Warming up!", "Type more than 360 seconds", pending); notif.notify(0, notify); Preferences.setDefaults("time1", "true", getApplicationContext()); } else if (time > 960 && time <= 3600 && time2.equals("false")) { NotificationManager notif = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); Notification notify = new Notification(R.drawable.notify, "Ecloga Keyboard", System.currentTimeMillis()); PendingIntent pending = PendingIntent.getActivity(getApplicationContext(), 0, new Intent(getApplicationContext(), Home.class), 0); notify.setLatestEventInfo(getApplicationContext(), "Keep it up!", "Type more than 960 seconds", pending); notif.notify(0, notify); Preferences.setDefaults("time2", "true", getApplicationContext()); } else if (time > 3600 && time3.equals("false")) { NotificationManager notif = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); Notification notify = new Notification(R.drawable.notify, "Ecloga Keyboard", System.currentTimeMillis()); PendingIntent pending = PendingIntent.getActivity(getApplicationContext(), 0, new Intent(getApplicationContext(), Home.class), 0); notify.setLatestEventInfo(getApplicationContext(), "Typing master!", "Type more than 3600 seconds", pending); notif.notify(0, notify); Preferences.setDefaults("time3", "true", getApplicationContext()); } Preferences.setDefaults("time", String.valueOf(time), getApplicationContext()); } @Override public void onFinish() { tTime.start(); } }.start(); if (popupKeypress) { kv.setPreviewEnabled(true); } else { kv.setPreviewEnabled(false); } if (shakeDelete) { mShaker = new ShakeListener(this); mShaker.setOnShakeListener(new ShakeListener.OnShakeListener() { public void onShake() { InputConnection ic = getCurrentInputConnection(); ic.deleteSurroundingText(500, 500); } }); } super.onStartInputView(info, restarting); }
From source file:cl.iluminadoschile.pako.floatingdiv.CustomOverlayService.java
@Override protected Notification foregroundNotification(int notificationId) { Notification notification; if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && activation_method.equals(Constants.SETTINGS.ACTIVATION_METHOD_MANUAL)) { Intent settingsIntent = new Intent(Intent.ACTION_MAIN); settingsIntent.setClassName(Constants.ACTION.prefix, Constants.ACTION.prefix + ".SettingsActivity"); settingsIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, settingsIntent, 0); Intent startFgIntent = new Intent(this, CustomOverlayService.class); startFgIntent.setAction(Constants.ACTION.STARTFOREGROUND_ACTION); PendingIntent pstartFgIntent = PendingIntent.getService(this, 0, startFgIntent, 0); Intent pauseFgIntent = new Intent(this, CustomOverlayService.class); pauseFgIntent.setAction(Constants.ACTION.PAUSEFOREGROUND_ACTION); PendingIntent ppauseFgIntent = PendingIntent.getService(this, 0, pauseFgIntent, 0); Intent stopFgIntent = new Intent(this, CustomOverlayService.class); stopFgIntent.setAction(Constants.ACTION.STOPFOREGROUND_ACTION); PendingIntent pstopFgIntent = PendingIntent.getService(this, 0, stopFgIntent, 0); Bitmap icon = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher); notification = new NotificationCompat.Builder(this) .setContentTitle(getString(R.string.title_notification)) .setTicker(getString(R.string.title_notification)) .setContentText(getString(R.string.message_notification)).setSmallIcon(R.drawable.ic_launcher) .setLargeIcon(Bitmap.createScaledBitmap(icon, 128, 128, false)).setContentIntent(pendingIntent) .setOngoing(true).addAction(android.R.drawable.ic_media_play, "Start", pstartFgIntent) .addAction(android.R.drawable.ic_media_pause, "Pause", ppauseFgIntent) .addAction(android.R.drawable.ic_delete, "Stop", pstopFgIntent).build(); } else {/* w ww . ja va 2 s . co m*/ notification = new Notification(R.drawable.ic_launcher, getString(R.string.title_notification), System.currentTimeMillis()); notification.flags = notification.flags | Notification.FLAG_ONGOING_EVENT | Notification.FLAG_ONLY_ALERT_ONCE; notification.setLatestEventInfo(this, getString(R.string.title_notification), getString(R.string.message_notification_manual), notificationIntent()); } return notification; }
From source file:org.restcomm.app.qoslib.Services.LibPhoneStateListener.java
public void popupDropped(final EventType droptype, final int rating, final int evtId) { if (rating == 0) return;/* ww w.j a va 2 s . c om*/ owner.handler.post(new Runnable() { // @Override public void run() { String message = ""; int icon; icon = R.drawable.ic_stat_dropped; String title = ""; String msg = ""; // server can specify whether a confirmation can be invoked on a low rated potentially-dropped call int allowConfirm = PreferenceManager.getDefaultSharedPreferences(owner) .getInt(PreferenceKeys.Miscellaneous.ALLOW_CONFIRMATION, 5); String noConfirm = (owner.getResources().getString(R.string.NO_CONFIRMATION)); int allowPopup = PreferenceManager.getDefaultSharedPreferences(owner) .getInt(PreferenceKeys.Miscellaneous.ALLOW_DROP_POPUP, 2); if (allowPopup == 1 && !owner.getUseRadioLog()) allowPopup = 0; if (allowPopup == 0) return; if (noConfirm.equals("1")) allowConfirm = 0; if (allowConfirm > 0 && rating < allowConfirm && rating < 4) // if confirmation allow, must be above threshold or high rating dropped call return; else if (allowConfirm == 0 && rating < 4) // drop call silently if marginal with no confirmation return; // allowConfirm>=5 disables the confirmation because rating always <= 5 // allowConfirm=1 hits the 'else' and invokes confirmation if rating >= 1 and <5 // allowConfirm=3 hits the 'else' and invokes confirmation if rating >= 3 and <5 int expiry = 60000 * 2 * 60; int customText = (owner.getResources().getInteger(R.integer.CUSTOM_EVENTNAMES)); message = owner.getString((customText == 1) ? R.string.sharecustom_speedtest_wifi : R.string.sharemessage_speedtest_wifi); if (rating >= 5 || allowConfirm == 0) { title = Global.getAppName(owner); msg = "mmc detected "; if (droptype == EventType.EVT_CALLFAIL) message = owner.getString((customText == 1) ? R.string.Custom_Notification_call_failed : R.string.MMC_Notification_call_failed); else message = owner.getString((customText == 1) ? R.string.Custom_Notification_call_dropped : R.string.MMC_Notification_call_dropped); message += ": " + owner.getString(R.string.MMC_Notification_view_event); msg += message; } else if (rating >= allowConfirm && rating > 1) { if (droptype == EventType.EVT_CALLFAIL) { title = owner.getString((customText == 1) ? R.string.Custom_Notification_did_you_fail : R.string.MMC_Notification_did_you_fail); message = owner.getString((customText == 1) ? R.string.Custom_Notification_did_failed : R.string.MMC_Notification_did_failed); } else if (droptype == EventType.EVT_DROP) { title = owner.getString((customText == 1) ? R.string.Custom_Notification_did_you_drop : R.string.Custom_Notification_did_dropped); message = owner.getString((customText == 1) ? R.string.MMC_Notification_did_dropped : R.string.MMC_Notification_did_dropped); } else if (droptype == EventType.EVT_DISCONNECT || droptype == EventType.EVT_UNANSWERED) { expiry = 60000; icon = R.drawable.ic_stat_disconnect; title = owner.getString((customText == 1) ? R.string.Custom_Notification_did_you_disconnect : R.string.MMC_Notification_did_you_disconnect); message = owner.getString((customText == 1) ? R.string.Custom_Notification_did_disconnect : R.string.MMC_Notification_did_disconnect); } msg = message; } java.util.Date date = new java.util.Date(); String time = date.toLocaleString(); msg += " at " + time; //Toast toast = Toast.makeText(MainService.this, msg, Toast.LENGTH_LONG); //toast.show(); NotificationManager notificationManager = (NotificationManager) owner .getSystemService(Service.NOTIFICATION_SERVICE); Notification notification = new Notification(icon, message, System.currentTimeMillis()); notification.flags |= Notification.FLAG_AUTO_CANCEL; //Intent notificationIntent = new Intent(MainService.this, Dashboard.class); Intent notificationIntent = new Intent();//, "com.cortxt.app.mmcui.Activities.Dashboard"); notificationIntent.setClassName(owner, "com.cortxt.app.uilib.Activities.Dashboard"); notificationIntent.putExtra("eventId", evtId); notificationIntent.setData((Uri.parse("foobar://" + SystemClock.elapsedRealtime()))); notificationIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent pendingIntent = PendingIntent.getActivity(owner, MMC_DROPPED_NOTIFICATION + evtId, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); notification.setLatestEventInfo(owner, title, message, pendingIntent); notificationManager.notify(MMC_DROPPED_NOTIFICATION, notification); long expirytime = System.currentTimeMillis() + expiry; PreferenceManager.getDefaultSharedPreferences(owner).edit() .putLong(PreferenceKeys.Monitoring.NOTIFICATION_EXPIRY, expirytime).commit(); } }); }
From source file:com.xorcode.andtweet.AndTweetService.java
/** * Notify user of the commands Queue size * //from ww w.j a v a 2 s . c o m * @return total size of Queues */ private int notifyOfQueue(boolean clearNotification) { int count = mRetryQueue.size() + mCommands.size(); NotificationManager nM = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); if (count == 0 || clearNotification) { // Clear notification nM.cancel(CommandEnum.NOTIFY_QUEUE.ordinal()); } else if (mNotificationsEnabled) { if (mRetryQueue.size() > 0) { MyLog.d(TAG, mRetryQueue.size() + " commands in Retry Queue."); } if (mCommands.size() > 0) { MyLog.d(TAG, mCommands.size() + " commands in Main Queue."); } // Set up the notification to display to the user Notification notification = new Notification(R.drawable.notification_icon, (String) getText(R.string.notification_title), System.currentTimeMillis()); int messageTitle; String aMessage = ""; aMessage = I18n.formatQuantityMessage(getApplicationContext(), R.string.notification_queue_format, count, R.array.notification_queue_patterns, R.array.notification_queue_formats); messageTitle = R.string.notification_title_queue; // Set up the scrolling message of the notification notification.tickerText = aMessage; /** * Set the latest event information and send the notification * Actually don't start any intent * * @see http * ://stackoverflow.com/questions/4232006/android-notification * -pendingintent-problem */ // PendingIntent pi = PendingIntent.getActivity(this, 0, null, 0); /** * Kick the commands queue by sending empty command */ PendingIntent pi = PendingIntent.getBroadcast(this, 0, new CommandData(CommandEnum.EMPTY).toIntent(), 0); notification.setLatestEventInfo(this, getText(messageTitle), aMessage, pi); nM.notify(CommandEnum.NOTIFY_QUEUE.ordinal(), notification); } return count; }
From source file:com.molice.oneingdufs.androidpn.Notifier.java
public void notify(String notificationId, String apiKey, String title, String message, String uri) { Log.d(LOGTAG, "notify()..."); Log.d(LOGTAG, "notificationId=" + notificationId); Log.d(LOGTAG, "notificationApiKey=" + apiKey); Log.d(LOGTAG, "notificationTitle=" + title); Log.d(LOGTAG, "notificationMessage=" + message); Log.d(LOGTAG, "notificationUri=" + uri); if (SettingsActivity.getNotificationEnabled(context)) { // Show the toast // if (isNotificationToastEnabled()) { // Toast.makeText(context, message, Toast.LENGTH_LONG).show(); // } // Notification Notification notification = new Notification(); notification.icon = getNotificationIcon(); // notification.defaults = Notification.DEFAULT_LIGHTS; if (SettingsActivity.getNotificationSound(context)) { notification.defaults |= Notification.DEFAULT_SOUND; }/*from www . ja v a 2 s . c om*/ if (SettingsActivity.getNotificationVibrate(context)) { notification.defaults |= Notification.DEFAULT_VIBRATE; } notification.flags |= Notification.FLAG_AUTO_CANCEL; notification.when = System.currentTimeMillis(); notification.tickerText = message; // Intent intent; // if (uri != null // && uri.length() > 0 // && (uri.startsWith("http:") || uri.startsWith("https:") // || uri.startsWith("tel:") || uri.startsWith("geo:"))) { // intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri)); // } else { // String callbackActivityPackageName = sharedPrefs.getString( // Constants.CALLBACK_ACTIVITY_PACKAGE_NAME, ""); // String callbackActivityClassName = sharedPrefs.getString( // Constants.CALLBACK_ACTIVITY_CLASS_NAME, ""); // intent = new Intent().setClassName(callbackActivityPackageName, // callbackActivityClassName); // intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); // } Intent intent = new Intent(context, MessageDetailActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); JSONObject data = formatMetaFromTitle(title); try { data.putOpt("id", notificationId); data.putOpt("content", message); } catch (Exception e) { Log.d("JSON", "Notifier#notify, e=" + e.toString()); } intent.putExtra("data", data.toString()); intent.putExtra("fromNotification", true); // intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // intent.setFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); // intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); // intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); // intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent contentIntent = PendingIntent.getActivity(context, random.nextInt(), intent, PendingIntent.FLAG_UPDATE_CURRENT); notification.setLatestEventInfo(context, data.optString("title"), message, contentIntent); notificationManager.notify(random.nextInt(), notification); // Intent clickIntent = new Intent( // Constants.ACTION_NOTIFICATION_CLICKED); // clickIntent.putExtra(Constants.NOTIFICATION_ID, notificationId); // clickIntent.putExtra(Constants.NOTIFICATION_API_KEY, apiKey); // clickIntent.putExtra(Constants.NOTIFICATION_TITLE, title); // clickIntent.putExtra(Constants.NOTIFICATION_MESSAGE, message); // clickIntent.putExtra(Constants.NOTIFICATION_URI, uri); // // positiveIntent.setData(Uri.parse((new StringBuilder( // // "notif://notification.adroidpn.org/")).append(apiKey).append( // // "/").append(System.currentTimeMillis()).toString())); // PendingIntent clickPendingIntent = PendingIntent.getBroadcast( // context, 0, clickIntent, 0); // // notification.setLatestEventInfo(context, title, message, // clickPendingIntent); // // Intent clearIntent = new Intent( // Constants.ACTION_NOTIFICATION_CLEARED); // clearIntent.putExtra(Constants.NOTIFICATION_ID, notificationId); // clearIntent.putExtra(Constants.NOTIFICATION_API_KEY, apiKey); // // negativeIntent.setData(Uri.parse((new StringBuilder( // // "notif://notification.adroidpn.org/")).append(apiKey).append( // // "/").append(System.currentTimeMillis()).toString())); // PendingIntent clearPendingIntent = PendingIntent.getBroadcast( // context, 0, clearIntent, 0); // notification.deleteIntent = clearPendingIntent; // // notificationManager.notify(random.nextInt(), notification); } else { Log.w(LOGTAG, "Notificaitons disabled."); } }
From source file:com.plusot.senselib.SenseMain.java
@SuppressWarnings("deprecation") public void notifyMe() { String version = ""; try {/*w w w . j a v a 2 s . co m*/ PackageInfo info = Globals.appContext.getPackageManager() .getPackageInfo(Globals.appContext.getPackageName(), 0); version = " " + info.versionName; } catch (NameNotFoundException e) { e.printStackTrace(); } Notification note = new Notification(SenseGlobals.notifyIcon, Globals.TAG + version, System.currentTimeMillis()); //String[] hints = Globals.appContext.getResources().getStringArray(R.array.hint_items); //String hint = hints[(int)(Math.random() * (hints.length - 1))]; PendingIntent intent = PendingIntent.getActivity(Globals.appContext, 0, new Intent(Globals.appContext, SenseGlobals.mainClass), 0); note.setLatestEventInfo(Globals.appContext, Globals.TAG + version, Globals.appContext.getString(R.string.hello), intent); //note.ledOnMS = 1000; //note.ledOffMS = 1000; //note.ledARGB = 0xFFFFFFFF; //note.tickerText = hint; //note.number=++noteCount; note.flags |= Notification.FLAG_ONGOING_EVENT; //note.vibrate=new long[] {20L, 50L}; noteManager.notify(NOTIFY_ME_ID, note); }
From source file:com.piusvelte.sonet.core.SonetService.java
private void start(Intent intent) { if (intent != null) { String action = intent.getAction(); Log.d(TAG, "action:" + action); if (ACTION_REFRESH.equals(action)) { if (intent.hasExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS)) putValidatedUpdates(intent.getIntArrayExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS), 1); else if (intent.hasExtra(AppWidgetManager.EXTRA_APPWIDGET_ID)) putValidatedUpdates(new int[] { intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID) }, 1); else if (intent.getData() != null) putValidatedUpdates(new int[] { Integer.parseInt(intent.getData().getLastPathSegment()) }, 1); else/*from w ww . ja va 2s . c om*/ putValidatedUpdates(null, 0); } else if (LauncherIntent.Action.ACTION_READY.equals(action)) { if (intent.hasExtra(EXTRA_SCROLLABLE_VERSION) && intent.hasExtra(AppWidgetManager.EXTRA_APPWIDGET_ID)) { int scrollableVersion = intent.getIntExtra(EXTRA_SCROLLABLE_VERSION, 1); int appWidgetId = intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID); // check if the scrollable needs to be built Cursor widget = this.getContentResolver().query(Widgets.getContentUri(SonetService.this), new String[] { Widgets._ID, Widgets.SCROLLABLE }, Widgets.WIDGET + "=?", new String[] { Integer.toString(appWidgetId) }, null); if (widget.moveToFirst()) { if (widget.getInt(widget.getColumnIndex(Widgets.SCROLLABLE)) < scrollableVersion) { ContentValues values = new ContentValues(); values.put(Widgets.SCROLLABLE, scrollableVersion); // set the scrollable version this.getContentResolver().update(Widgets.getContentUri(SonetService.this), values, Widgets.WIDGET + "=?", new String[] { Integer.toString(appWidgetId) }); putValidatedUpdates(new int[] { appWidgetId }, 1); } else putValidatedUpdates(new int[] { appWidgetId }, 1); } else { ContentValues values = new ContentValues(); values.put(Widgets.SCROLLABLE, scrollableVersion); // set the scrollable version this.getContentResolver().update(Widgets.getContentUri(SonetService.this), values, Widgets.WIDGET + "=?", new String[] { Integer.toString(appWidgetId) }); putValidatedUpdates(new int[] { appWidgetId }, 1); } widget.close(); } else if (intent.hasExtra(AppWidgetManager.EXTRA_APPWIDGET_ID)) { // requery putValidatedUpdates(new int[] { intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID) }, 0); } } else if (SMS_RECEIVED.equals(action)) { // parse the sms, and notify any widgets which have sms enabled Bundle bundle = intent.getExtras(); Object[] pdus = (Object[]) bundle.get("pdus"); for (int i = 0; i < pdus.length; i++) { SmsMessage msg = SmsMessage.createFromPdu((byte[]) pdus[i]); AsyncTask<SmsMessage, String, int[]> smsLoader = new AsyncTask<SmsMessage, String, int[]>() { @Override protected int[] doInBackground(SmsMessage... msg) { // check if SMS is enabled anywhere Cursor widgets = getContentResolver().query( Widget_accounts_view.getContentUri(SonetService.this), new String[] { Widget_accounts_view._ID, Widget_accounts_view.WIDGET, Widget_accounts_view.ACCOUNT }, Widget_accounts_view.SERVICE + "=?", new String[] { Integer.toString(SMS) }, null); int[] appWidgetIds = new int[widgets.getCount()]; if (widgets.moveToFirst()) { // insert this message to the statuses db and requery scrollable/rebuild widget // check if this is a contact String phone = msg[0].getOriginatingAddress(); String friend = phone; byte[] profile = null; Uri content_uri = null; // unknown numbers crash here in the emulator Cursor phones = getContentResolver().query( Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, Uri.encode(phone)), new String[] { ContactsContract.PhoneLookup._ID }, null, null, null); if (phones.moveToFirst()) content_uri = ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, phones.getLong(0)); else { Cursor emails = getContentResolver().query( Uri.withAppendedPath( ContactsContract.CommonDataKinds.Email.CONTENT_FILTER_URI, Uri.encode(phone)), new String[] { ContactsContract.CommonDataKinds.Email._ID }, null, null, null); if (emails.moveToFirst()) content_uri = ContentUris.withAppendedId( ContactsContract.Contacts.CONTENT_URI, emails.getLong(0)); emails.close(); } phones.close(); if (content_uri != null) { // load contact Cursor contacts = getContentResolver().query(content_uri, new String[] { ContactsContract.Contacts.DISPLAY_NAME }, null, null, null); if (contacts.moveToFirst()) friend = contacts.getString(0); contacts.close(); profile = getBlob(ContactsContract.Contacts .openContactPhotoInputStream(getContentResolver(), content_uri)); } long accountId = widgets.getLong(2); long id; ContentValues values = new ContentValues(); values.put(Entities.ESID, phone); values.put(Entities.FRIEND, friend); values.put(Entities.PROFILE, profile); values.put(Entities.ACCOUNT, accountId); Cursor entity = getContentResolver().query( Entities.getContentUri(SonetService.this), new String[] { Entities._ID }, Entities.ACCOUNT + "=? and " + Entities.ESID + "=?", new String[] { Long.toString(accountId), mSonetCrypto.Encrypt(phone) }, null); if (entity.moveToFirst()) { id = entity.getLong(0); getContentResolver().update(Entities.getContentUri(SonetService.this), values, Entities._ID + "=?", new String[] { Long.toString(id) }); } else id = Long.parseLong(getContentResolver() .insert(Entities.getContentUri(SonetService.this), values) .getLastPathSegment()); entity.close(); values.clear(); Long created = msg[0].getTimestampMillis(); values.put(Statuses.CREATED, created); values.put(Statuses.ENTITY, id); values.put(Statuses.MESSAGE, msg[0].getMessageBody()); values.put(Statuses.SERVICE, SMS); while (!widgets.isAfterLast()) { int widget = widgets.getInt(1); appWidgetIds[widgets.getPosition()] = widget; // get settings boolean time24hr = true; int status_bg_color = Sonet.default_message_bg_color; int profile_bg_color = Sonet.default_message_bg_color; int friend_bg_color = Sonet.default_friend_bg_color; boolean icon = true; int status_count = Sonet.default_statuses_per_account; int notifications = 0; Cursor c = getContentResolver().query( Widgets_settings.getContentUri(SonetService.this), new String[] { Widgets.TIME24HR, Widgets.MESSAGES_BG_COLOR, Widgets.ICON, Widgets.STATUSES_PER_ACCOUNT, Widgets.SOUND, Widgets.VIBRATE, Widgets.LIGHTS, Widgets.PROFILES_BG_COLOR, Widgets.FRIEND_BG_COLOR }, Widgets.WIDGET + "=? and " + Widgets.ACCOUNT + "=?", new String[] { Integer.toString(widget), Long.toString(accountId) }, null); if (!c.moveToFirst()) { c.close(); c = getContentResolver().query( Widgets_settings.getContentUri(SonetService.this), new String[] { Widgets.TIME24HR, Widgets.MESSAGES_BG_COLOR, Widgets.ICON, Widgets.STATUSES_PER_ACCOUNT, Widgets.SOUND, Widgets.VIBRATE, Widgets.LIGHTS, Widgets.PROFILES_BG_COLOR, Widgets.FRIEND_BG_COLOR }, Widgets.WIDGET + "=? and " + Widgets.ACCOUNT + "=?", new String[] { Integer.toString(widget), Long.toString(Sonet.INVALID_ACCOUNT_ID) }, null); if (!c.moveToFirst()) { c.close(); c = getContentResolver().query( Widgets_settings.getContentUri(SonetService.this), new String[] { Widgets.TIME24HR, Widgets.MESSAGES_BG_COLOR, Widgets.ICON, Widgets.STATUSES_PER_ACCOUNT, Widgets.SOUND, Widgets.VIBRATE, Widgets.LIGHTS, Widgets.PROFILES_BG_COLOR, Widgets.FRIEND_BG_COLOR }, Widgets.WIDGET + "=? and " + Widgets.ACCOUNT + "=?", new String[] { Integer.toString(AppWidgetManager.INVALID_APPWIDGET_ID), Long.toString(Sonet.INVALID_ACCOUNT_ID) }, null); if (!c.moveToFirst()) initAccountSettings(SonetService.this, AppWidgetManager.INVALID_APPWIDGET_ID, Sonet.INVALID_ACCOUNT_ID); if (widget != AppWidgetManager.INVALID_APPWIDGET_ID) initAccountSettings(SonetService.this, widget, Sonet.INVALID_ACCOUNT_ID); } initAccountSettings(SonetService.this, widget, accountId); } if (c.moveToFirst()) { time24hr = c.getInt(0) == 1; status_bg_color = c.getInt(1); icon = c.getInt(2) == 1; status_count = c.getInt(3); if (c.getInt(4) == 1) notifications |= Notification.DEFAULT_SOUND; if (c.getInt(5) == 1) notifications |= Notification.DEFAULT_VIBRATE; if (c.getInt(6) == 1) notifications |= Notification.DEFAULT_LIGHTS; profile_bg_color = c.getInt(7); friend_bg_color = c.getInt(8); } c.close(); values.put(Statuses.CREATEDTEXT, Sonet.getCreatedText(created, time24hr)); // update the bg and icon // create the status_bg values.put(Statuses.STATUS_BG, createBackground(status_bg_color)); // friend_bg values.put(Statuses.FRIEND_BG, createBackground(friend_bg_color)); // profile_bg values.put(Statuses.PROFILE_BG, createBackground(profile_bg_color)); values.put(Statuses.ICON, icon ? getBlob(getResources(), map_icons[SMS]) : null); // insert the message values.put(Statuses.WIDGET, widget); values.put(Statuses.ACCOUNT, accountId); getContentResolver().insert(Statuses.getContentUri(SonetService.this), values); // check the status count, removing old sms Cursor statuses = getContentResolver().query( Statuses.getContentUri(SonetService.this), new String[] { Statuses._ID }, Statuses.WIDGET + "=? and " + Statuses.ACCOUNT + "=?", new String[] { Integer.toString(widget), Long.toString(accountId) }, Statuses.CREATED + " desc"); if (statuses.moveToFirst()) { while (!statuses.isAfterLast()) { if (statuses.getPosition() >= status_count) { getContentResolver().delete( Statuses.getContentUri(SonetService.this), Statuses._ID + "=?", new String[] { Long.toString(statuses .getLong(statuses.getColumnIndex(Statuses._ID))) }); } statuses.moveToNext(); } } statuses.close(); if (notifications != 0) publishProgress(Integer.toString(notifications), friend + " sent a message"); widgets.moveToNext(); } } widgets.close(); return appWidgetIds; } @Override protected void onProgressUpdate(String... updates) { int notifications = Integer.parseInt(updates[0]); if (notifications != 0) { Notification notification = new Notification(R.drawable.notification, updates[1], System.currentTimeMillis()); notification.setLatestEventInfo(getBaseContext(), "New messages", updates[1], PendingIntent.getActivity(SonetService.this, 0, (Sonet .getPackageIntent(SonetService.this, SonetNotifications.class)), 0)); notification.defaults |= notifications; ((NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE)) .notify(NOTIFY_ID, notification); } } @Override protected void onPostExecute(int[] appWidgetIds) { // remove self from thread list if (!mSMSLoaders.isEmpty()) mSMSLoaders.remove(this); putValidatedUpdates(appWidgetIds, 0); } }; mSMSLoaders.add(smsLoader); smsLoader.execute(msg); } } else if (ACTION_PAGE_DOWN.equals(action)) (new PagingTask()).execute(Integer.parseInt(intent.getData().getLastPathSegment()), intent.getIntExtra(ACTION_PAGE_DOWN, 0)); else if (ACTION_PAGE_UP.equals(action)) (new PagingTask()).execute(Integer.parseInt(intent.getData().getLastPathSegment()), intent.getIntExtra(ACTION_PAGE_UP, 0)); else { // this might be a widget update from the widget refresh button int appWidgetId; try { appWidgetId = Integer.parseInt(action); putValidatedUpdates(new int[] { appWidgetId }, 1); } catch (NumberFormatException e) { Log.d(TAG, "unknown action:" + action); } } } }
From source file:com.shafiq.myfeedle.core.MyfeedleService.java
private void start(Intent intent) { if (intent != null) { String action = intent.getAction(); Log.d(TAG, "action:" + action); if (ACTION_REFRESH.equals(action)) { if (intent.hasExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS)) putValidatedUpdates(intent.getIntArrayExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS), 1); else if (intent.hasExtra(AppWidgetManager.EXTRA_APPWIDGET_ID)) putValidatedUpdates(new int[] { intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID) }, 1); else if (intent.getData() != null) putValidatedUpdates(new int[] { Integer.parseInt(intent.getData().getLastPathSegment()) }, 1); else//from w w w .ja v a2 s .c om putValidatedUpdates(null, 0); } else if (LauncherIntent.Action.ACTION_READY.equals(action)) { if (intent.hasExtra(EXTRA_SCROLLABLE_VERSION) && intent.hasExtra(AppWidgetManager.EXTRA_APPWIDGET_ID)) { int scrollableVersion = intent.getIntExtra(EXTRA_SCROLLABLE_VERSION, 1); int appWidgetId = intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID); // check if the scrollable needs to be built Cursor widget = this.getContentResolver().query(Widgets.getContentUri(MyfeedleService.this), new String[] { Widgets._ID, Widgets.SCROLLABLE }, Widgets.WIDGET + "=?", new String[] { Integer.toString(appWidgetId) }, null); if (widget.moveToFirst()) { if (widget.getInt(widget.getColumnIndex(Widgets.SCROLLABLE)) < scrollableVersion) { ContentValues values = new ContentValues(); values.put(Widgets.SCROLLABLE, scrollableVersion); // set the scrollable version this.getContentResolver().update(Widgets.getContentUri(MyfeedleService.this), values, Widgets.WIDGET + "=?", new String[] { Integer.toString(appWidgetId) }); putValidatedUpdates(new int[] { appWidgetId }, 1); } else putValidatedUpdates(new int[] { appWidgetId }, 1); } else { ContentValues values = new ContentValues(); values.put(Widgets.SCROLLABLE, scrollableVersion); // set the scrollable version this.getContentResolver().update(Widgets.getContentUri(MyfeedleService.this), values, Widgets.WIDGET + "=?", new String[] { Integer.toString(appWidgetId) }); putValidatedUpdates(new int[] { appWidgetId }, 1); } widget.close(); } else if (intent.hasExtra(AppWidgetManager.EXTRA_APPWIDGET_ID)) { // requery putValidatedUpdates(new int[] { intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID) }, 0); } } else if (SMS_RECEIVED.equals(action)) { // parse the sms, and notify any widgets which have sms enabled Bundle bundle = intent.getExtras(); Object[] pdus = (Object[]) bundle.get("pdus"); for (int i = 0; i < pdus.length; i++) { SmsMessage msg = SmsMessage.createFromPdu((byte[]) pdus[i]); AsyncTask<SmsMessage, String, int[]> smsLoader = new AsyncTask<SmsMessage, String, int[]>() { @Override protected int[] doInBackground(SmsMessage... msg) { // check if SMS is enabled anywhere Cursor widgets = getContentResolver().query( Widget_accounts_view.getContentUri(MyfeedleService.this), new String[] { Widget_accounts_view._ID, Widget_accounts_view.WIDGET, Widget_accounts_view.ACCOUNT }, Widget_accounts_view.SERVICE + "=?", new String[] { Integer.toString(SMS) }, null); int[] appWidgetIds = new int[widgets.getCount()]; if (widgets.moveToFirst()) { // insert this message to the statuses db and requery scrollable/rebuild widget // check if this is a contact String phone = msg[0].getOriginatingAddress(); String friend = phone; byte[] profile = null; Uri content_uri = null; // unknown numbers crash here in the emulator Cursor phones = getContentResolver().query( Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, Uri.encode(phone)), new String[] { ContactsContract.PhoneLookup._ID }, null, null, null); if (phones.moveToFirst()) content_uri = ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, phones.getLong(0)); else { Cursor emails = getContentResolver().query( Uri.withAppendedPath( ContactsContract.CommonDataKinds.Email.CONTENT_FILTER_URI, Uri.encode(phone)), new String[] { ContactsContract.CommonDataKinds.Email._ID }, null, null, null); if (emails.moveToFirst()) content_uri = ContentUris.withAppendedId( ContactsContract.Contacts.CONTENT_URI, emails.getLong(0)); emails.close(); } phones.close(); if (content_uri != null) { // load contact Cursor contacts = getContentResolver().query(content_uri, new String[] { ContactsContract.Contacts.DISPLAY_NAME }, null, null, null); if (contacts.moveToFirst()) friend = contacts.getString(0); contacts.close(); profile = getBlob(ContactsContract.Contacts .openContactPhotoInputStream(getContentResolver(), content_uri)); } long accountId = widgets.getLong(2); long id; ContentValues values = new ContentValues(); values.put(Entities.ESID, phone); values.put(Entities.FRIEND, friend); values.put(Entities.PROFILE, profile); values.put(Entities.ACCOUNT, accountId); Cursor entity = getContentResolver().query( Entities.getContentUri(MyfeedleService.this), new String[] { Entities._ID }, Entities.ACCOUNT + "=? and " + Entities.ESID + "=?", new String[] { Long.toString(accountId), mMyfeedleCrypto.Encrypt(phone) }, null); if (entity.moveToFirst()) { id = entity.getLong(0); getContentResolver().update(Entities.getContentUri(MyfeedleService.this), values, Entities._ID + "=?", new String[] { Long.toString(id) }); } else id = Long.parseLong(getContentResolver() .insert(Entities.getContentUri(MyfeedleService.this), values) .getLastPathSegment()); entity.close(); values.clear(); Long created = msg[0].getTimestampMillis(); values.put(Statuses.CREATED, created); values.put(Statuses.ENTITY, id); values.put(Statuses.MESSAGE, msg[0].getMessageBody()); values.put(Statuses.SERVICE, SMS); while (!widgets.isAfterLast()) { int widget = widgets.getInt(1); appWidgetIds[widgets.getPosition()] = widget; // get settings boolean time24hr = true; int status_bg_color = Myfeedle.default_message_bg_color; int profile_bg_color = Myfeedle.default_message_bg_color; int friend_bg_color = Myfeedle.default_friend_bg_color; boolean icon = true; int status_count = Myfeedle.default_statuses_per_account; int notifications = 0; Cursor c = getContentResolver().query( Widgets_settings.getContentUri(MyfeedleService.this), new String[] { Widgets.TIME24HR, Widgets.MESSAGES_BG_COLOR, Widgets.ICON, Widgets.STATUSES_PER_ACCOUNT, Widgets.SOUND, Widgets.VIBRATE, Widgets.LIGHTS, Widgets.PROFILES_BG_COLOR, Widgets.FRIEND_BG_COLOR }, Widgets.WIDGET + "=? and " + Widgets.ACCOUNT + "=?", new String[] { Integer.toString(widget), Long.toString(accountId) }, null); if (!c.moveToFirst()) { c.close(); c = getContentResolver().query( Widgets_settings.getContentUri(MyfeedleService.this), new String[] { Widgets.TIME24HR, Widgets.MESSAGES_BG_COLOR, Widgets.ICON, Widgets.STATUSES_PER_ACCOUNT, Widgets.SOUND, Widgets.VIBRATE, Widgets.LIGHTS, Widgets.PROFILES_BG_COLOR, Widgets.FRIEND_BG_COLOR }, Widgets.WIDGET + "=? and " + Widgets.ACCOUNT + "=?", new String[] { Integer.toString(widget), Long.toString(Myfeedle.INVALID_ACCOUNT_ID) }, null); if (!c.moveToFirst()) { c.close(); c = getContentResolver().query( Widgets_settings.getContentUri(MyfeedleService.this), new String[] { Widgets.TIME24HR, Widgets.MESSAGES_BG_COLOR, Widgets.ICON, Widgets.STATUSES_PER_ACCOUNT, Widgets.SOUND, Widgets.VIBRATE, Widgets.LIGHTS, Widgets.PROFILES_BG_COLOR, Widgets.FRIEND_BG_COLOR }, Widgets.WIDGET + "=? and " + Widgets.ACCOUNT + "=?", new String[] { Integer.toString(AppWidgetManager.INVALID_APPWIDGET_ID), Long.toString(Myfeedle.INVALID_ACCOUNT_ID) }, null); if (!c.moveToFirst()) initAccountSettings(MyfeedleService.this, AppWidgetManager.INVALID_APPWIDGET_ID, Myfeedle.INVALID_ACCOUNT_ID); if (widget != AppWidgetManager.INVALID_APPWIDGET_ID) initAccountSettings(MyfeedleService.this, widget, Myfeedle.INVALID_ACCOUNT_ID); } initAccountSettings(MyfeedleService.this, widget, accountId); } if (c.moveToFirst()) { time24hr = c.getInt(0) == 1; status_bg_color = c.getInt(1); icon = c.getInt(2) == 1; status_count = c.getInt(3); if (c.getInt(4) == 1) notifications |= Notification.DEFAULT_SOUND; if (c.getInt(5) == 1) notifications |= Notification.DEFAULT_VIBRATE; if (c.getInt(6) == 1) notifications |= Notification.DEFAULT_LIGHTS; profile_bg_color = c.getInt(7); friend_bg_color = c.getInt(8); } c.close(); values.put(Statuses.CREATEDTEXT, Myfeedle.getCreatedText(created, time24hr)); // update the bg and icon // create the status_bg values.put(Statuses.STATUS_BG, createBackground(status_bg_color)); // friend_bg values.put(Statuses.FRIEND_BG, createBackground(friend_bg_color)); // profile_bg values.put(Statuses.PROFILE_BG, createBackground(profile_bg_color)); values.put(Statuses.ICON, icon ? getBlob(getResources(), map_icons[SMS]) : null); // insert the message values.put(Statuses.WIDGET, widget); values.put(Statuses.ACCOUNT, accountId); getContentResolver().insert(Statuses.getContentUri(MyfeedleService.this), values); // check the status count, removing old sms Cursor statuses = getContentResolver().query( Statuses.getContentUri(MyfeedleService.this), new String[] { Statuses._ID }, Statuses.WIDGET + "=? and " + Statuses.ACCOUNT + "=?", new String[] { Integer.toString(widget), Long.toString(accountId) }, Statuses.CREATED + " desc"); if (statuses.moveToFirst()) { while (!statuses.isAfterLast()) { if (statuses.getPosition() >= status_count) { getContentResolver().delete( Statuses.getContentUri(MyfeedleService.this), Statuses._ID + "=?", new String[] { Long.toString(statuses .getLong(statuses.getColumnIndex(Statuses._ID))) }); } statuses.moveToNext(); } } statuses.close(); if (notifications != 0) publishProgress(Integer.toString(notifications), friend + " sent a message"); widgets.moveToNext(); } } widgets.close(); return appWidgetIds; } @Override protected void onProgressUpdate(String... updates) { int notifications = Integer.parseInt(updates[0]); if (notifications != 0) { Notification notification = new Notification(R.drawable.notification, updates[1], System.currentTimeMillis()); notification.setLatestEventInfo(getBaseContext(), "New messages", updates[1], PendingIntent.getActivity(MyfeedleService.this, 0, (Myfeedle.getPackageIntent(MyfeedleService.this, MyfeedleNotifications.class)), 0)); notification.defaults |= notifications; ((NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE)) .notify(NOTIFY_ID, notification); } } @Override protected void onPostExecute(int[] appWidgetIds) { // remove self from thread list if (!mSMSLoaders.isEmpty()) mSMSLoaders.remove(this); putValidatedUpdates(appWidgetIds, 0); } }; mSMSLoaders.add(smsLoader); smsLoader.execute(msg); } } else if (ACTION_PAGE_DOWN.equals(action)) (new PagingTask()).execute(Integer.parseInt(intent.getData().getLastPathSegment()), intent.getIntExtra(ACTION_PAGE_DOWN, 0)); else if (ACTION_PAGE_UP.equals(action)) (new PagingTask()).execute(Integer.parseInt(intent.getData().getLastPathSegment()), intent.getIntExtra(ACTION_PAGE_UP, 0)); else { // this might be a widget update from the widget refresh button int appWidgetId; try { appWidgetId = Integer.parseInt(action); putValidatedUpdates(new int[] { appWidgetId }, 1); } catch (NumberFormatException e) { Log.d(TAG, "unknown action:" + action); } } } }
From source file:org.rti.rcd.ict.lgug.C2DMReceiver.java
@Override protected void onMessage(Context context, Intent intent) { //String accountName = intent.getExtras().getString(Config.C2DM_ACCOUNT_EXTRA); String accountName = intent.getStringExtra("account"); String message = intent.getExtras().getString(Config.C2DM_MESSAGE_EXTRA); Log.d(TAG, "Messaging request received for account " + accountName); // CoconutActivity c = CoconutActivity.getRef(); // c.displayMessage( message ); String ns = Context.NOTIFICATION_SERVICE; NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns); int icon = R.drawable.icon; CharSequence tickerText = "Olutindo"; long when = System.currentTimeMillis(); Notification notification = new Notification(icon, tickerText, when); notification.defaults |= Notification.DEFAULT_SOUND; notification.defaults |= Notification.DEFAULT_VIBRATE; notification.flags = Notification.FLAG_AUTO_CANCEL; notification.defaults |= Notification.DEFAULT_LIGHTS; notification.flags |= Notification.FLAG_SHOW_LIGHTS; notification.ledARGB = 0xff00ff00;/*from w ww. j a v a 2s . c om*/ notification.ledOnMS = 300; notification.ledOffMS = 1000; //Context context = getApplicationContext(); Log.d(TAG, "Triggering once_off replication upon receipt of notification: " + message); Properties properties = new Properties(); try { InputStream rawResource = getResources().openRawResource(R.raw.coconut); properties.load(rawResource); System.out.println("The properties are now loaded"); System.out.println("properties: " + properties); } catch (Resources.NotFoundException e) { System.err.println("Did not find raw resource: " + e); } catch (IOException e) { System.err.println("Failed to open microlog property file"); } String localDb = "http://localhost:" + properties.getProperty("local_couch_app_port") + "/" + properties.getProperty("app_db"); Log.d(TAG, "localDb: " + localDb); // String localReplicationDbUrl = "http://localhost:" + properties.getProperty("local_couch_app_port") +"/_replicate"; // String replicationMasterUrl = "http://" + properties.getProperty("master_server") + "/coconut"; // String replicationDataFromMaster = "{\"_id\": \"once_off_from_master\",\"target\":\"" + localDb + "\",\"source\":\"" + replicationMasterUrl + "\"}"; // String replicationDataToMaster = "{\"_id\": \"once_off_to_master\",\"target\":\"" + replicationMasterUrl + "\",\"source\":\"" + localDb + "\"}"; // // try { // HTTPRequest.post(localReplicationDbUrl, replicationDataFromMaster); // } catch (JSONException e) { // Log.d(TAG, "Problem installing replication target FromMaster. replicationMasterUrl: " + replicationMasterUrl + " Error:" + e.getMessage()); // e.printStackTrace(); // } catch (ConnectException e) { // Log.d(TAG, "Unable to connect to replicationMasterUrl: " + replicationMasterUrl + " Error:" + e.getMessage()); // } // try { // HTTPRequest.post(localReplicationDbUrl, replicationDataToMaster); // } catch (JSONException e) { // Log.d(TAG, "Problem installing replication target ToMaster. replicationMasterUrl: " + replicationMasterUrl + " Error:" + e.getMessage()); // e.printStackTrace(); // } catch (ConnectException e) { // Log.d(TAG, "Unable to connect to replicationMasterUrl: " + replicationMasterUrl + " Error:" + e.getMessage()); // } CharSequence contentTitle = "New Olutindo Message"; //CharSequence contentText = "Hello World!"; Intent notificationIntent = new Intent(this, CoconutActivity.class); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); notification.setLatestEventInfo(context, contentTitle, message, contentIntent); mNotificationManager.notify(HELLO_ID, notification); }
From source file:com.mozilla.SUTAgentAndroid.service.DoCommand.java
private void SendNotification(String tickerText, String expandedText) { NotificationManager notificationManager = (NotificationManager) contextWrapper .getSystemService(Context.NOTIFICATION_SERVICE); int icon = R.drawable.ateamlogo; long when = System.currentTimeMillis(); Notification notification = new Notification(icon, tickerText, when); notification.flags |= (Notification.FLAG_INSISTENT | Notification.FLAG_AUTO_CANCEL); notification.defaults |= Notification.DEFAULT_SOUND; notification.defaults |= Notification.DEFAULT_VIBRATE; notification.defaults |= Notification.DEFAULT_LIGHTS; Context context = contextWrapper.getApplicationContext(); // Intent to launch an activity when the extended text is clicked Intent intent2 = new Intent(contextWrapper, SUTAgentAndroid.class); PendingIntent launchIntent = PendingIntent.getActivity(context, 0, intent2, 0); notification.setLatestEventInfo(context, tickerText, expandedText, launchIntent); notificationManager.notify(1959, notification); }