List of usage examples for android.content Context NOTIFICATION_SERVICE
String NOTIFICATION_SERVICE
To view the source code for android.content Context NOTIFICATION_SERVICE.
Click Source Link
From source file:net.ben.subsonic.androidapp.util.Util.java
public static void hidePlayingNotification(final Context context, Handler handler) { handler.post(new Runnable() { @Override//from w w w . ja va2 s. c o m public void run() { NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.cancel(Constants.NOTIFICATION_ID_PLAYING); } }); // Update widget DownloadService service = DownloadServiceImpl.getInstance(); if (service != null) { SubsonicAppWidgetProvider.getInstance().notifyChange(context, service, false); } }
From source file:gov.nasa.arc.geocam.geocam.GeoCamService.java
@Override public void onCreate() { Log.d(GeoCamMobile.DEBUG_ID, "GeoCamService::onCreate called"); super.onCreate(); // Prevent this service from being prematurely killed to reclaim memory buildNotification("GeoCam uploader starting...", "Starting..."); Reflect.Service.startForeground(this, NOTIFICATION_ID, mNotification); // Location Manager mLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); registerListener();/* ww w . j av a 2 s .co m*/ mLocationManager.addGpsStatusListener(mGpsStatusListener); // Notification Manager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); // Upload queue and thread // Initialize with mCv open so we immediately try to upload when the thread is spawned // This is important on service restart with non-zero length queue // The thread will close mCv if the queue is empty mCv = new ConditionVariable(true); mIsUploading = new AtomicBoolean(false); mLastStatus = new AtomicInteger(0); if (mUploadQueue == null) { mUploadQueue = new GeoCamDbAdapter(this); mUploadQueue.open(); } if (mGpsLog == null) { mGpsLog = new GpsDbAdapter(this); mGpsLog.open(); } mPrefListener = new SharedPreferences.OnSharedPreferenceChangeListener() { public void onSharedPreferenceChanged(SharedPreferences prefs, String key) { // wake up upload thread if upload was just enabled boolean isUploadEnabled = prefs.getBoolean(GeoCamMobile.SETTINGS_SERVER_UPLOAD_ENABLED, true); Log.d(GeoCamMobile.DEBUG_ID, "GeoCamService.mPrefListener.onSharedPreferenceChanged" + " key=" + key + " isUploadEnabled=" + Boolean.toString(isUploadEnabled)); if (key.equals(GeoCamMobile.SETTINGS_SERVER_UPLOAD_ENABLED) && isUploadEnabled) { Log.d(GeoCamMobile.DEBUG_ID, "GeoCamService.mPrefListener.onSharedPreferenceChanged" + " waking up upload thread"); mCv.open(); } } }; SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this); settings.registerOnSharedPreferenceChangeListener(mPrefListener); mUploadThread = new Thread(null, uploadTask, "UploadThread"); mUploadThread.start(); }
From source file:androidVNC.VncCanvasActivity.java
@Override public void onCreate(Bundle icicle) { super.onCreate(icicle); requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); database = new VncDatabase(this); connection = new ConnectionBean(); Intent i = getIntent();//from w w w . j a v a 2 s .co m Uri data = i.getData(); if ((data != null) && (data.getScheme().equals("vnc"))) { String host = data.getHost(); // This should not happen according to Uri contract, but bug introduced in Froyo (2.2) // has made this parsing of host necessary int index = host.indexOf(':'); int port; if (index != -1) { try { port = Integer.parseInt(host.substring(index + 1)); } catch (NumberFormatException nfe) { port = 0; } host = host.substring(0, index); } else { port = data.getPort(); } if (host.equals(VncConstants.CONNECTION)) { if (connection.Gen_read(database.getReadableDatabase(), port)) { MostRecentBean bean = androidVNC.getMostRecent(database.getReadableDatabase()); if (bean != null) { bean.setConnectionId(connection.get_Id()); bean.Gen_update(database.getWritableDatabase()); } } } else { connection.setAddress(host); connection.setNickname(connection.getAddress()); connection.setPort(port); List<String> path = data.getPathSegments(); if (path.size() >= 1) { connection.setColorModel(path.get(0)); } if (path.size() >= 2) { connection.setPassword(path.get(1)); } connection.save(database.getWritableDatabase()); } } else { Bundle extras = i.getExtras(); if (extras != null) { connection.Gen_populate((ContentValues) extras.getParcelable(VncConstants.CONNECTION)); } if (connection.getPort() == 0) connection.setPort(5900); // Parse a HOST:PORT entry String host = connection.getAddress(); if (host.indexOf(':') > -1) { String p = host.substring(host.indexOf(':') + 1); try { connection.setPort(Integer.parseInt(p)); } catch (Exception e) { } connection.setAddress(host.substring(0, host.indexOf(':'))); } } try { setContentView(fi.aalto.openoranges.project1.mcc.R.layout.canvas); vncCanvas = (VncCanvas) findViewById(fi.aalto.openoranges.project1.mcc.R.id.vnc_canvas); zoomer = (ZoomControls) findViewById(R.id.zoomer); } catch (Exception e) { e.printStackTrace(); } vncCanvas.initializeVncCanvas(connection, new Runnable() { public void run() { setModes(); } }); vncCanvas.setOnGenericMotionListener(this); zoomer.hide(); zoomer.setOnZoomInClickListener(new View.OnClickListener() { /* * (non-Javadoc) * * @see android.view.View.OnClickListener#onClick(android.view.View) */ @Override public void onClick(View v) { showZoomer(true); vncCanvas.scaling.zoomIn(VncCanvasActivity.this); } }); zoomer.setOnZoomOutClickListener(new View.OnClickListener() { /* * (non-Javadoc) * * @see android.view.View.OnClickListener#onClick(android.view.View) */ @Override public void onClick(View v) { showZoomer(true); vncCanvas.scaling.zoomOut(VncCanvasActivity.this); } }); zoomer.setOnZoomKeyboardClickListener(new View.OnClickListener() { /* * (non-Javadoc) * * @see android.view.View.OnClickListener#onClick(android.view.View) */ @Override public void onClick(View v) { InputMethodManager inputMgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); inputMgr.toggleSoftInput(0, 0); } }); panner = new Panner(this, vncCanvas.handler); inputHandler = getInputHandlerById(fi.aalto.openoranges.project1.mcc.R.id.itemInputFitToScreen); mToken = getIntent().getStringExtra("token"); mId = getIntent().getStringExtra("id"); mName = getIntent().getStringExtra("name"); //listener for the back-button registerClickCallback(); //Notification in status bar NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(VncCanvasActivity.this) .setSmallIcon(R.drawable.icon_white).setContentTitle(mName + " running") .setContentText("Click to open the application screen"); // Creates an explicit intent for an Activity in your app Intent resultIntent = new Intent(VncCanvasActivity.this, VncCanvasActivity.class); resultIntent.setAction(Long.toString(System.currentTimeMillis())); mBuilder.setContentIntent(PendingIntent.getActivity(VncCanvasActivity.this, 0, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT)); NotificationManager mNotificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); // mNotifyID allows you to update the notification later on. mNotificationManager.notify(mNotifyId, mBuilder.build()); startService(); }
From source file:net.ben.subsonic.androidapp.util.Util.java
public static void showErrorNotification(final Context context, Handler handler, String title, Exception error) {/*w w w . j a va2s . c o m*/ final NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); StringBuilder text = new StringBuilder(); if (error.getMessage() != null) { text.append(error.getMessage()).append(" ("); } text.append(error.getClass().getSimpleName()); if (error.getMessage() != null) { text.append(")"); } // Set the icon, scrolling text and timestamp final Notification notification = new Notification(android.R.drawable.stat_sys_warning, title, System.currentTimeMillis()); notification.flags |= Notification.FLAG_AUTO_CANCEL; // The PendingIntent to launch our activity if the user selects this notification Intent intent = new Intent(context, ErrorActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.putExtra(Constants.INTENT_EXTRA_NAME_ERROR, title + ".\n\n" + text); PendingIntent contentIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); notification.setLatestEventInfo(context, title, text, contentIntent); // Send the notification. handler.post(new Runnable() { @Override public void run() { notificationManager.cancel(Constants.NOTIFICATION_ID_ERROR); notificationManager.notify(Constants.NOTIFICATION_ID_ERROR, notification); } }); }
From source file:com.androidquery.simplefeed.activity.PostActivity.java
private void notify(String ticker, String title, String message, Intent intent) { String ns = Context.NOTIFICATION_SERVICE; NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns); int icon = R.drawable.launcher; long when = System.currentTimeMillis(); Notification notification = new Notification(icon, ticker, when); Context context = getApplicationContext(); CharSequence contentText = message; int id = getNotifyId(); PendingIntent contentIntent = PendingIntent.getActivity(this, id, intent, 0); notification.setLatestEventInfo(context, title, contentText, contentIntent); mNotificationManager.cancelAll();//from w w w. j a v a 2 s. c om AQUtility.debug("notify id", id); mNotificationManager.notify(id, notification); }
From source file:com.amazonaws.mobileconnectors.pinpoint.targeting.notification.NotificationClient.java
private boolean displayNotification(final Bundle pushBundle, final Class<?> targetClass, String imageUrl, String iconImageUrl, String iconSmallImageUrl, Map<String, String> campaignAttributes, String intentAction) {//w w w . j a v a 2 s . co m log.info("Display Notification: " + pushBundle.toString()); final String title = pushBundle.getString(NOTIFICATION_TITLE_PUSH_KEY); final String message = pushBundle.getString(NOTIFICATION_BODY_PUSH_KEY); final String campaignId = campaignAttributes.get(CAMPAIGN_ID_ATTRIBUTE_KEY); final String activityId = campaignAttributes.get(CAMPAIGN_ACTIVITY_ID_ATTRIBUTE_KEY); final int requestID = (campaignId + ":" + activityId + ":" + System.currentTimeMillis()).hashCode(); final int iconResId = getNotificationIconResourceId(pushBundle.getString(NOTIFICATION_ICON_PUSH_KEY)); if (iconResId == 0) { return false; } final Notification notification = createNotification(iconResId, title, message, imageUrl, iconImageUrl, iconSmallImageUrl, this.createOpenAppPendingIntent(pushBundle, targetClass, campaignId, requestID, intentAction)); notification.flags |= Notification.FLAG_AUTO_CANCEL; notification.defaults |= Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE; if (android.os.Build.VERSION.SDK_INT >= ANDROID_LOLLIPOP) { log.info("SDK greater than 21 detected: " + android.os.Build.VERSION.SDK_INT); final String colorString = pushBundle.getString(NOTIFICATION_COLOR_PUSH_KEY); if (colorString != null) { int color; try { color = Color.parseColor(colorString); } catch (final IllegalArgumentException ex) { log.warn("Couldn't parse campaign notification color.", ex); color = 0; } Exception exception = null; try { final Field colorField = notification.getClass().getDeclaredField("color"); colorField.setAccessible(true); colorField.set(notification, color); } catch (final IllegalAccessException ex) { exception = ex; } catch (final NoSuchFieldException ex) { exception = ex; } if (exception != null) { log.error("Couldn't set campaign notification color : " + exception.getMessage(), exception); } } } final NotificationManager notificationManager = (NotificationManager) pinpointContext .getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(requestID, notification); return true; }
From source file:com.dwdesign.tweetings.service.TweetingsService.java
@Override public void onCreate() { super.onCreate(); mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); mAlarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE); mAsyncTaskManager = ((TweetingsApplication) getApplication()).getAsyncTaskManager(); mPreferences = getSharedPreferences(SHARED_PREFERENCES_NAME, MODE_PRIVATE); mResolver = getContentResolver();// w ww . j av a 2 s. co m mPendingRefreshHomeTimelineIntent = PendingIntent.getBroadcast(this, 0, new Intent(BROADCAST_REFRESH_HOME_TIMELINE), 0); mPendingRefreshMentionsIntent = PendingIntent.getBroadcast(this, 0, new Intent(BROADCAST_REFRESH_MENTIONS), 0); mPendingRefreshDirectMessagesIntent = PendingIntent.getBroadcast(this, 0, new Intent(BROADCAST_REFRESH_DIRECT_MESSAGES), 0); final IntentFilter filter = new IntentFilter(BROADCAST_REFRESHSTATE_CHANGED); filter.addAction(BROADCAST_NOTIFICATION_CLEARED); filter.addAction(BROADCAST_REFRESH_HOME_TIMELINE); filter.addAction(BROADCAST_REFRESH_MENTIONS); filter.addAction(BROADCAST_REFRESH_DIRECT_MESSAGES); filter.addAction(Intent.ACTION_BATTERY_LOW); filter.addAction(Intent.ACTION_BATTERY_OKAY); registerReceiver(mStateReceiver, filter); startAutoRefresh(); }
From source file:keyboard.ecloga.com.eclogakeyboard.EclogaKeyboard.java
@Override public void onStartInputView(EditorInfo info, boolean restarting) { initializeKeyboard();//from w w w . j av a2 s . com 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:com.dmbstream.android.util.Util.java
private static void startForeground(Service service, int notificationId, Notification notification) { // Service.startForeground() was introduced in Android 2.0. // Use reflection to maintain compatibility with 1.5. try {/*ww w . j a va2 s. c om*/ Method method = Service.class.getMethod("startForeground", int.class, Notification.class); method.invoke(service, notificationId, notification); Log.i(TAG, "Successfully invoked Service.startForeground()"); } catch (Throwable x) { NotificationManager notificationManager = (NotificationManager) service .getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(Constants.NOTIFICATION_ID_PLAYING, notification); Log.i(TAG, "Service.startForeground() not available. Using work-around."); } }