Example usage for android.app NotificationManager notify

List of usage examples for android.app NotificationManager notify

Introduction

In this page you can find the example usage for android.app NotificationManager notify.

Prototype

public void notify(int id, Notification notification) 

Source Link

Document

Post a notification to be shown in the status bar.

Usage

From source file:jahirfiquitiva.iconshowcase.services.NotificationsService.java

@SuppressWarnings("ResourceAsColor")
private void pushNotification(String content, int type, int ID) {

    Preferences mPrefs = new Preferences(this);

    String appName = Utils.getStringFromResources(this, R.string.app_name);

    String title = appName, notifContent = null;

    switch (type) {
    case 1:/*ww w .ja  v a 2s  .  co m*/
        title = getResources().getString(R.string.new_walls_notif_title, appName);
        notifContent = getResources().getString(R.string.new_walls_notif_content, content);
        break;
    case 2:
        title = appName + " " + getResources().getString(R.string.news).toLowerCase();
        notifContent = content;
        break;
    }

    // Send Notification
    NotificationManager notifManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    NotificationCompat.Builder notifBuilder = new NotificationCompat.Builder(this);
    notifBuilder.setAutoCancel(true);
    notifBuilder.setContentTitle(title);
    if (notifContent != null) {
        notifBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(notifContent));
        notifBuilder.setContentText(notifContent);
    }
    notifBuilder.setTicker(title);
    Uri ringtoneUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    notifBuilder.setSound(ringtoneUri);

    if (mPrefs.getNotifsVibrationEnabled()) {
        notifBuilder.setVibrate(new long[] { 500, 500 });
    } else {
        notifBuilder.setVibrate(null);
    }

    int ledColor = ThemeUtils.darkTheme ? ContextCompat.getColor(this, R.color.dark_theme_accent)
            : ContextCompat.getColor(this, R.color.light_theme_accent);

    notifBuilder.setColor(ledColor);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        notifBuilder.setPriority(Notification.PRIORITY_HIGH);
    }

    Class appLauncherActivity = getLauncherClass(getApplicationContext());

    if (appLauncherActivity != null) {
        Intent appIntent = new Intent(this, appLauncherActivity);
        appIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP
                | Intent.FLAG_ACTIVITY_CLEAR_TOP);
        appIntent.putExtra("notifType", type);

        TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
        stackBuilder.addParentStack(appLauncherActivity);

        // Adds the Intent that starts the Activity to the top of the stack
        stackBuilder.addNextIntent(appIntent);
        PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
        notifBuilder.setContentIntent(resultPendingIntent);
    }

    notifBuilder.setOngoing(false);

    notifBuilder.setSmallIcon(R.drawable.ic_notifications);

    Notification notif = notifBuilder.build();

    if (mPrefs.getNotifsLedEnabled()) {
        notif.ledARGB = ledColor;
    }

    notifManager.notify(ID, notif);
}

From source file:pt.up.mobile.syncadapter.SigarraSyncAdapter.java

private void syncNotifications(Account account, SyncResult syncResult)
        throws AuthenticationException, IOException {
    final User user = AccountUtils.getUser(getContext(), account.name);
    final String notificationReply = SifeupAPI.getReply(SifeupAPI.getNotificationsUrl(user.getUserCode()),
            account, getContext());//from  w  ww  .ja  v a 2 s.c  o  m
    final Gson gson = GsonUtils.getGson();
    final Notification[] notifications = gson.fromJson(notificationReply, Notification[].class);
    if (notifications == null) {
        syncResult.stats.numParseExceptions++;
        LogUtils.trackException(getContext(), new RuntimeException(), notificationReply, true);
        return;
    }
    ArrayList<String> fetchedNotCodes = new ArrayList<String>();
    ArrayList<ContentValues> bulkValues = new ArrayList<ContentValues>();
    for (Notification not : notifications) {
        final ContentValues values = new ContentValues();
        values.put(SigarraContract.Notifcations.CONTENT, gson.toJson(not));
        fetchedNotCodes.add(not.getCode());
        if (getContext().getContentResolver().update(SigarraContract.Notifcations.CONTENT_URI, values,
                SigarraContract.Notifcations.UPDATE_NOTIFICATION,
                SigarraContract.Notifcations.getNotificationsSelectionArgs(account.name, not.getCode())) == 0) {
            values.put(SigarraContract.Notifcations.CODE, account.name);
            values.put(SigarraContract.Notifcations.ID_NOTIFICATION, not.getCode());
            values.put(SigarraContract.Notifcations.STATE, SigarraContract.Notifcations.NEW);
            values.put(SigarraContract.Notifcations.CODE, account.name);
            bulkValues.add(values);
        }

    }
    // inserting the values
    if (bulkValues.size() > 0) {
        getContext().getContentResolver().bulkInsert(SigarraContract.Notifcations.CONTENT_URI,
                bulkValues.toArray(new ContentValues[0]));
        // if the account being synced is the current active accout
        // display notification
        if (AccountUtils.getActiveUserName(getContext()).equals(account.name)) {
            final NotificationManager mNotificationManager = (NotificationManager) getContext()
                    .getSystemService(Context.NOTIFICATION_SERVICE);
            NotificationCompat.Builder notBuilder = new NotificationCompat.Builder(getContext());
            notBuilder.setAutoCancel(true).setOnlyAlertOnce(true)
                    .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
            if (bulkValues.size() == 1) {
                final Notification notification = gson.fromJson(
                        bulkValues.get(0).getAsString(SigarraContract.Notifcations.CONTENT),
                        Notification.class);
                Intent notifyIntent = new Intent(getContext(), NotificationsDescActivity.class)
                        .putExtra(NotificationsDescFragment.NOTIFICATION, notification);
                // Creates the PendingIntent
                PendingIntent notifyPendingIntent = PendingIntent.getActivity(getContext(), 0, notifyIntent,
                        PendingIntent.FLAG_UPDATE_CURRENT);

                // Sets the Activity to start in a new, empty task
                notifyIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
                notBuilder.setSmallIcon(R.drawable.icon).setTicker(notification.getMessage())
                        .setContentTitle(notification.getSubject()).setContentText(notification.getMessage())
                        .setContentIntent(notifyPendingIntent)
                        .setStyle(new NotificationCompat.BigTextStyle().bigText(notification.getMessage())
                                .setBigContentTitle(notification.getSubject())
                                .setSummaryText(notification.getMessage()));
                mNotificationManager.notify(notification.getCode().hashCode(), notBuilder.build());
            } else {
                final String notTitle = getContext().getString(R.string.new_notifications, bulkValues.size());

                Intent notifyIntent = new Intent(getContext(), NotificationsActivity.class);
                // Sets the Activity to start in a new, empty task
                notifyIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
                // Creates the PendingIntent
                PendingIntent notifyPendingIntent = PendingIntent.getActivity(getContext(), 0, notifyIntent,
                        PendingIntent.FLAG_UPDATE_CURRENT);
                NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
                // Sets a title for the Inbox style big view
                inboxStyle.setBigContentTitle(notTitle);
                // Moves events into the big view
                for (ContentValues value : bulkValues) {
                    final Notification notification = gson.fromJson(
                            value.getAsString(SigarraContract.Notifcations.CONTENT), Notification.class);
                    inboxStyle.addLine(notification.getSubject());
                }
                // Moves the big view style object into the notification
                // object.
                notBuilder.setStyle(inboxStyle);
                notBuilder.setSmallIcon(R.drawable.icon).setTicker(notTitle).setContentTitle(notTitle)
                        .setContentText("").setContentIntent(notifyPendingIntent);
                mNotificationManager.notify(NotificationsFragment.class.getName().hashCode(),
                        notBuilder.build());
            }

        }
    }
    final Cursor syncState = getContext().getContentResolver().query(SigarraContract.LastSync.CONTENT_URI,
            SigarraContract.LastSync.COLUMNS, SigarraContract.LastSync.PROFILE,
            SigarraContract.LastSync.getLastSyncSelectionArgs(AccountUtils.getActiveUserName(getContext())),
            null);
    try {
        if (syncState.moveToFirst()) {
            if (syncState.getLong(syncState.getColumnIndex(SigarraContract.LastSync.NOTIFICATIONS)) == 0) {
                // Report that we have checked the notifications
                final ContentValues values = new ContentValues();
                values.put(SigarraContract.LastSync.NOTIFICATIONS, System.currentTimeMillis());
                getContext().getContentResolver().update(SigarraContract.LastSync.CONTENT_URI, values,
                        SigarraContract.LastSync.PROFILE,
                        SigarraContract.LastSync.getLastSyncSelectionArgs(account.name));
            }
        }
    } finally {
        syncState.close();
    }
    ArrayList<String> notToDelete = new ArrayList<String>();
    final Cursor cursor = getContext().getContentResolver().query(SigarraContract.Notifcations.CONTENT_URI,
            new String[] { SigarraContract.Notifcations.ID_NOTIFICATION }, SigarraContract.Notifcations.PROFILE,
            SigarraContract.Notifcations.getNotificationsSelectionArgs(account.name), null);
    try {
        if (cursor.moveToFirst()) {
            do {
                final String code = cursor.getString(0);
                if (!fetchedNotCodes.contains(code))
                    notToDelete.add(code);
            } while (cursor.moveToNext());
        } else {
            // no notifications
            getContext().getContentResolver().notifyChange(SigarraContract.Notifcations.CONTENT_URI, null);
        }
    } finally {
        cursor.close();
    }
    if (notToDelete.size() > 0)
        getContext().getContentResolver().delete(SigarraContract.Notifcations.CONTENT_URI,
                SigarraContract.Notifcations.getNotificationsDelete(notToDelete.toArray(new String[0])),
                SigarraContract.Notifcations.getNotificationsSelectionArgs(account.name,
                        notToDelete.toArray(new String[0])));
    syncResult.stats.numEntries += notifications.length;
}

From source file:com.andrew.apolloMod.service.ApolloService.java

private void gotoIdleState() {
    mDelayedStopHandler.removeCallbacksAndMessages(null);
    Message msg = mDelayedStopHandler.obtainMessage();
    mDelayedStopHandler.sendMessageDelayed(msg, IDLE_DELAY);
    stopForeground(false);//from w  ww . jav  a 2 s  .c om
    if (status != null) {
        if (Constants.isApi16Supported()) {
            status.contentView.setImageViewResource(R.id.status_bar_play,
                    mIsSupposedToBePlaying ? R.drawable.apollo_holo_dark_play
                            : R.drawable.apollo_holo_dark_pause);

            status.bigContentView.setImageViewResource(R.id.status_bar_play,
                    mIsSupposedToBePlaying ? R.drawable.apollo_holo_dark_play
                            : R.drawable.apollo_holo_dark_pause);
        } else {
            //TODO:Add support for lower APis
        }

        NotificationManager mManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        mManager.notify(PLAYBACKSERVICE_STATUS, status);
    }
}

From source file:es.javocsoft.android.lib.toolbox.ToolBox.java

/**
 * Creates a system notification./*from   w w  w.  j  a v  a2 s  .  c o m*/
 *    
 * @param context            Context.
 * @param notSound            Enable or disable the sound
 * @param notSoundRawId         Custom raw sound id. If enabled and not set 
 *                         default notification sound will be used. Set to -1 to 
 *                         default system notification.
 * @param multipleNot         Setting to True allows showing multiple notifications.
 * @param groupMultipleNotKey   If is set, multiple notifications can be grupped by this key.
 * @param notAction            Action for this notification
 * @param notTitle            Title
 * @param notMessage         Message
 * @param notClazz            Class to be executed
 * @param extras            Extra information
 * 
 */
public static void notification_generate(Context context, boolean notSound, int notSoundRawId,
        boolean multipleNot, String groupMultipleNotKey, String notAction, String notTitle, String notMessage,
        Class<?> notClazz, Bundle extras, boolean wakeUp) {

    try {
        int iconResId = notification_getApplicationIcon(context);
        long when = System.currentTimeMillis();

        Notification notification = new Notification(iconResId, notMessage, when);

        // Hide the notification after its selected
        notification.flags |= Notification.FLAG_AUTO_CANCEL;

        if (notSound) {
            if (notSoundRawId > 0) {
                try {
                    notification.sound = Uri.parse("android.resource://"
                            + context.getApplicationContext().getPackageName() + "/" + notSoundRawId);
                } catch (Exception e) {
                    if (LOG_ENABLE) {
                        Log.w(TAG, "Custom sound " + notSoundRawId + "could not be found. Using default.");
                    }
                    notification.defaults |= Notification.DEFAULT_SOUND;
                    notification.sound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
                }
            } else {
                notification.defaults |= Notification.DEFAULT_SOUND;
                notification.sound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
            }
        }

        Intent notificationIntent = new Intent(context, notClazz);
        notificationIntent.setAction(notClazz.getName() + "." + notAction);
        if (extras != null) {
            notificationIntent.putExtras(extras);
        }

        //Set intent so it does not start a new activity
        //
        //Notes:
        //   - The flag FLAG_ACTIVITY_SINGLE_TOP makes that only one instance of the activity exists(each time the
        //      activity is summoned no onCreate() method is called instead, onNewIntent() is called.
        //  - If we use FLAG_ACTIVITY_CLEAR_TOP it will make that the last "snapshot"/TOP of the activity it will 
        //     be this called this intent. We do not want this because the HOME button will call this "snapshot". 
        //     To avoid this behaviour we use FLAG_ACTIVITY_BROUGHT_TO_FRONT that simply takes to foreground the 
        //     activity.
        //
        //See http://developer.android.com/reference/android/content/Intent.html           
        notificationIntent.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT | Intent.FLAG_ACTIVITY_SINGLE_TOP);

        PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent,
                PendingIntent.FLAG_UPDATE_CURRENT);

        int REQUEST_UNIQUE_ID = 0;
        if (multipleNot) {
            if (groupMultipleNotKey != null && groupMultipleNotKey.length() > 0) {
                REQUEST_UNIQUE_ID = groupMultipleNotKey.hashCode();
            } else {
                if (random == null) {
                    random = new Random();
                }
                REQUEST_UNIQUE_ID = random.nextInt();
            }
            PendingIntent.getActivity(context, REQUEST_UNIQUE_ID, notificationIntent,
                    PendingIntent.FLAG_ONE_SHOT);
        }

        notification.setLatestEventInfo(context, notTitle, notMessage, intent);

        //This makes the device to wake-up is is idle with the screen off.
        if (wakeUp) {
            powersaving_wakeUp(context);
        }

        NotificationManager notificationManager = (NotificationManager) context
                .getSystemService(Context.NOTIFICATION_SERVICE);

        //We check if the sound is disabled to enable just for a moment
        AudioManager amanager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
        int previousAudioMode = amanager.getRingerMode();
        ;
        if (notSound && previousAudioMode != AudioManager.RINGER_MODE_NORMAL) {
            amanager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
        }

        notificationManager.notify(REQUEST_UNIQUE_ID, notification);

        //We restore the sound setting
        if (previousAudioMode != AudioManager.RINGER_MODE_NORMAL) {
            //We wait a little so sound is played
            try {
                Thread.sleep(3000);
            } catch (Exception e) {
            }
        }
        amanager.setRingerMode(previousAudioMode);

        Log.d(TAG, "Android Notification created.");

    } catch (Exception e) {
        if (LOG_ENABLE)
            Log.e(TAG, "The notification could not be created (" + e.getMessage() + ")", e);
    }
}

From source file:br.com.Utilitarios.WorkUpService.java

public void criarNotificacoes(Notificacoes n, String titulo, String texto, String ticker, String tipo,
        String extra) {//from   w ww  . j  av a  2 s.  c om

    // Build notification
    NotificationCompat.Builder noti = new NotificationCompat.Builder(this);
    noti.setContentTitle(titulo);
    noti.setContentText(texto);
    noti.setTicker(ticker);
    noti.setSmallIcon(R.drawable.ic_launcher);
    Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    noti.setSound(alarmSound);

    NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

    Intent resultIntent = null;
    if (tipo.equals("novoPersonal")) {
        // Creates an expnovaAvaliacaolicit intent for an Activity in your app
        resultIntent = new Intent(this, AceitarRejeitarAmigo.class);
        resultIntent.putExtra("usuario", n.getOrigemNotificacao());
        resultIntent.putExtra("tipo", "aluno");
    }

    if (tipo.equals("novoAluno")) {

        resultIntent = new Intent(this, AceitarRejeitarAmigo.class);
        resultIntent.putExtra("usuario", n.getOrigemNotificacao());
        resultIntent.putExtra("tipo", "personal");

    }

    if (tipo.equals("novaAula")) {
        // Creates an explicit intent for an Activity in your app
        resultIntent = new Intent(this, ConfirmarAula.class);
        resultIntent.putExtra("codAula", extra);
    }

    //This ensures that navigating backward from the Activity leads out of the app to Home page
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);

    if (tipo.equals("novoPersonal") || tipo.equals("novoAluno")) {
        // Adds the back stack for the Intent
        stackBuilder.addParentStack(AceitarRejeitarAmigo.class);

        // Adds the Intent that starts the Activity to the top of the stack
        stackBuilder.addNextIntent(resultIntent);
        PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_ONE_SHOT //can only be used once
        );
        // start the activity when the user clicks the notification text
        noti.setContentIntent(resultPendingIntent);
    }

    // pass the Notification object to the system
    notificationManager.notify(0, noti.build());

    n.visualizarNotificacao(n.getCodNotificacao());

    //----------------------------------------------------------------------------------
}

From source file:be.ppareit.swiftp.gui.FsNotification.java

private void setupNotification(Context context) {
    Cat.d("Setting up the notification");
    // Get NotificationManager reference
    String ns = Context.NOTIFICATION_SERVICE;
    NotificationManager nm = (NotificationManager) context.getSystemService(ns);

    // get ip address
    InetAddress address = FsService.getLocalInetAddress();
    if (address == null) {
        Cat.w("Unable to retrieve the local ip address");
        return;/*from   w  ww.  j  a v a  2s .c o  m*/
    }
    String iptext = "ftp://" + address.getHostAddress() + ":" + FsSettings.getPortNumber() + "/";

    // Instantiate a Notification
    int icon = R.mipmap.notification;
    CharSequence tickerText = String.format(context.getString(R.string.notification_server_starting), iptext);
    long when = System.currentTimeMillis();

    // Define Notification's message and Intent
    CharSequence contentTitle = context.getString(R.string.notification_title);
    CharSequence contentText = String.format(context.getString(R.string.notification_text), iptext);

    Intent notificationIntent = new Intent(context, MainActivity.class);
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);

    int stopIcon = android.R.drawable.ic_menu_close_clear_cancel;
    CharSequence stopText = context.getString(R.string.notification_stop_text);
    Intent stopIntent = new Intent(FsService.ACTION_STOP_FTPSERVER);
    PendingIntent stopPendingIntent = PendingIntent.getBroadcast(context, 0, stopIntent,
            PendingIntent.FLAG_ONE_SHOT);

    int preferenceIcon = android.R.drawable.ic_menu_preferences;
    CharSequence preferenceText = context.getString(R.string.notif_settings_text);
    Intent preferenceIntent = new Intent(context, MainActivity.class);
    preferenceIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent preferencePendingIntent = PendingIntent.getActivity(context, 0, preferenceIntent, 0);

    Notification notification = new NotificationCompat.Builder(context).setContentTitle(contentTitle)
            .setContentText(contentText).setContentIntent(contentIntent).setSmallIcon(icon)
            .setTicker(tickerText).setWhen(when).setOngoing(true)
            .setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
            .setCategory(NotificationCompat.CATEGORY_SERVICE).setPriority(NotificationCompat.PRIORITY_MAX)
            .addAction(stopIcon, stopText, stopPendingIntent)
            .addAction(preferenceIcon, preferenceText, preferencePendingIntent).setShowWhen(false).build();

    // Pass Notification to NotificationManager
    nm.notify(NOTIFICATION_ID, notification);

    Cat.d("Notification setup done");
}

From source file:keyboard.ecloga.com.eclogakeyboard.EclogaKeyboard.java

@Override
public void onKey(int primaryCode, int[] keyCodes) {
    final InputConnection ic = getCurrentInputConnection();

    playClick();// www . j av a 2 s  . c  o m
    printChar = true;

    if (primaryCode != 126 && primaryCode != -5 && primaryCode != -1
            && primaryCode != EmojiKeyboardView.KEYCODE_EMOJI_1
            && primaryCode != EmojiKeyboardView.KEYCODE_EMOJI_2
            && primaryCode != EmojiKeyboardView.KEYCODE_EMOJI_3
            && primaryCode != EmojiKeyboardView.KEYCODE_EMOJI_4
            && primaryCode != EmojiKeyboardView.KEYCODE_EMOJI_5) {

        keyPressCounter++;

        if (keyPressCounter > 100 && keyPressCounter <= 1000 && keypresscounter1.equals("false")) {
            NotificationManager notif = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
            Notification notify = new Notification(R.drawable.notify, "Ecloga Keyboard",
                    System.currentTimeMillis());
            PendingIntent pending = PendingIntent.getActivity(this, 0, new Intent(this, Home.class), 0);

            notify.setLatestEventInfo(getApplicationContext(), "Warming up!", "Type more than 100 characters",
                    pending);
            notif.notify(0, notify);

            Preferences.setDefaults("keypresscounter1", "true", getApplicationContext());
        } else if (keyPressCounter > 10000 && keyPressCounter <= 10000 && keypresscounter2.equals("false")) {
            NotificationManager notif = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
            Notification notify = new Notification(R.drawable.notify, "Ecloga Keyboard",
                    System.currentTimeMillis());
            PendingIntent pending = PendingIntent.getActivity(this, 0, new Intent(this, Home.class), 0);

            notify.setLatestEventInfo(getApplicationContext(), "Keep it up!", "Type more than 1000 characters",
                    pending);
            notif.notify(0, notify);

            Preferences.setDefaults("keypresscounter2", "true", getApplicationContext());
        } else if (keyPressCounter > 10000 && keypresscounter3.equals("false")) {
            NotificationManager notif = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
            Notification notify = new Notification(R.drawable.notify, "Ecloga Keyboard",
                    System.currentTimeMillis());
            PendingIntent pending = PendingIntent.getActivity(this, 0, new Intent(this, Home.class), 0);

            notify.setLatestEventInfo(getApplicationContext(), "Typing master!",
                    "Type more than 10000 characters", pending);
            notif.notify(0, notify);

            Preferences.setDefaults("keypresscounter3", "true", getApplicationContext());
        }

        Preferences.setDefaults("keypresses", String.valueOf(keyPressCounter), getApplicationContext());
    }

    switch (primaryCode) {
    case 58:
        ic.commitText(":", 1);

        if (autoSpacing) {
            ic.commitText(" ", 1);
        }
        break;
    case 59:
        ic.commitText(";", 1);

        if (autoSpacing) {
            ic.commitText(" ", 1);
        }
        break;
    case 33:
        ic.commitText("!", 1);

        if (autoSpacing) {
            ic.commitText(" ", 1);
        }

        if (autoCapitalize) {
            caps = true;
            keyboard.setShifted(caps);
            kv.invalidateAllKeys();
            printChar = false;
        }
        break;
    case 63:
        ic.commitText("?", 1);

        if (autoSpacing) {
            ic.commitText(" ", 1);
        }

        if (autoCapitalize) {
            caps = true;
            keyboard.setShifted(caps);
            kv.invalidateAllKeys();
            printChar = false;
        }
        break;
    case -5:
        if (lang.equals("seclang")) {
            if (orient.equals("portrait")) {
                keyboard = prilang;
            } else if (orient.equals("landscape")) {
                keyboard = prilang_landscape;
            }
            kv.setKeyboard(keyboard);
            kv.invalidateAllKeys();
            lang = "prilang";
        } else if (lang.equals("prilang")) {
            if (orient.equals("portrait")) {
                keyboard = seclang;
            } else if (orient.equals("landscape")) {
                keyboard = seclang_landscape;
            }
            kv.setKeyboard(keyboard);
            kv.invalidateAllKeys();
            lang = "seclang";
        }
        break;
    case 32:
        ic.commitText(" ", 1);

        if (autoCapitalize) {
            if (String.valueOf(ic.getTextBeforeCursor(2, 0)).equals(". ")) {
                caps = true;
                keyboard.setShifted(caps);
                kv.invalidateAllKeys();
                printChar = false;
            }
        }
        break;
    case 126:
        ic.deleteSurroundingText(1, 0);

        if (autoCapitalize) {
            if (String.valueOf(ic.getTextBeforeCursor(1, 0)).equals(".")
                    || String.valueOf(ic.getTextBeforeCursor(2, 0)).equals(". ")
                    || String.valueOf(ic.getTextBeforeCursor(2, 0)).equals("")) {
                caps = true;
                keyboard.setShifted(caps);
                kv.invalidateAllKeys();
                printChar = false;
            }
        }
        break;
    case 44:
        ic.commitText(",", 1);

        if (autoSpacing) {
            ic.commitText(" ", 1);
        }
        break;
    case 46:
        ic.commitText(".", 1);

        if (autoSpacing) {
            ic.commitText(" ", 1);
        }

        if (autoCapitalize) {
            caps = true;
            keyboard.setShifted(caps);
            kv.invalidateAllKeys();
            printChar = false;
        }
        break;
    case -1:
        ic.performEditorAction(EditorInfo.IME_ACTION_GO);
        break;
    case EmojiKeyboardView.KEYCODE_EMOJI_1:
        keyboard = new Keyboard(this, R.xml.emoji_a1);
        kv.setKeyboard(keyboard);
        kv.invalidateAllKeys();
        emoji = 1;
        eScreen = 1;
        break;
    case EmojiKeyboardView.KEYCODE_EMOJI_2:
        keyboard = new Keyboard(this, R.xml.emoji_b1);
        kv.setKeyboard(keyboard);
        kv.invalidateAllKeys();
        emoji = 2;
        eScreen = 1;
        break;
    case EmojiKeyboardView.KEYCODE_EMOJI_3:
        keyboard = new Keyboard(this, R.xml.emoji_c1);
        kv.setKeyboard(keyboard);
        kv.invalidateAllKeys();
        emoji = 3;
        eScreen = 1;
        break;
    case EmojiKeyboardView.KEYCODE_EMOJI_4:
        keyboard = new Keyboard(this, R.xml.emoji_d1);
        kv.setKeyboard(keyboard);
        kv.invalidateAllKeys();
        emoji = 4;
        eScreen = 1;
        break;
    case EmojiKeyboardView.KEYCODE_EMOJI_5:
        keyboard = new Keyboard(this, R.xml.emoji_e1);
        kv.setKeyboard(keyboard);
        kv.invalidateAllKeys();
        emoji = 5;
        eScreen = 1;
        break;
    default:
        char code = (char) primaryCode;

        if (allCaps) {
            if (Character.isLetter(code) && capsLock) {
                code = Character.toLowerCase(code);
            } else if (Character.isLetter(code) && !capsLock) {
                code = Character.toUpperCase(code);
            }
        } else {
            if (Character.isLetter(code) && caps) {
                code = Character.toUpperCase(code);
            }
        }

        String character = String.valueOf(code);
        ic.commitText(character, 1);
    }

    if (printedDifferent) {
        ic.deleteSurroundingText(1, 0);
    }

    if (printedDot) {
        ic.deleteSurroundingText(1, 0);

        if (autoCapitalize) {
            caps = true;
            keyboard.setShifted(caps);
            kv.invalidateAllKeys();
            printChar = false;
        }
    }

    if (doubleUp == 2) {
        capsChange();
    } else {
        changeCaps();
    }
}

From source file:com.halseyburgund.rwframework.core.RWService.java

/**
 * Updates the text in the RWService notification placed in the Android
 * notification bar on the screen of the device.
 * //w  w w .  jav  a  2s.c o m
 * @param message to be displayed
 */
public void setNotificationText(String message) {
    if ((mRwNotification != null) && (mNotificationPendingIntent != null)) {
        NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        if (nm != null) {
            if (message != null) {
                boolean debugMsg = message.startsWith(".");
                String msg = debugMsg ? message.subSequence(1, message.length()).toString() : message;

                boolean defaultMsg = message.equalsIgnoreCase(mNotificationDefaultText);

                if ((!debugMsg) || (mShowDetailedMessages)) {
                    mRwNotification.setLatestEventInfo(this, mNotificationTitle, msg,
                            mNotificationPendingIntent);
                    if (!defaultMsg) {
                        mRwNotification.tickerText = msg;
                    } else {
                        mRwNotification.tickerText = "";
                    }
                }
            }

            mRwNotification.when = System.currentTimeMillis();
            mRwNotification.number = RWActionQueue.instance().count();
            nm.notify(NOTIFICATION_ID, mRwNotification);
        }
    }
}

From source file:com.zertinteractive.wallpaper.MainActivity.java

@SuppressLint("NewApi")
public void setNotification() {
    String ns = Context.NOTIFICATION_SERVICE;
    NotificationManager notificationManager = (NotificationManager) getSystemService(ns);

    @SuppressWarnings("deprecation")
    Notification notification = new Notification(R.drawable.ic_launcher, "Ticker Text",
            System.currentTimeMillis());

    RemoteViews notificationView = new RemoteViews(getPackageName(), R.layout.romantic_wallpaper);

    //the intent that is started when the notification is clicked (works)
    Intent notificationIntent = new Intent(this, MainActivity.class);
    PendingIntent pendingNotificationIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);

    notification.contentView = notificationView;
    notification.contentIntent = pendingNotificationIntent;
    //        notification.flags |= Notification.FLAG_NO_CLEAR;
    notification.flags = Notification.FLAG_LOCAL_ONLY;

    //this is the intent that is supposed to be called when the button is clicked
    Intent switchIntent = new Intent(this, MainActivity.class);
    PendingIntent pendingSwitchIntent = PendingIntent.getBroadcast(this, 0, switchIntent, 0);
    //// w w w .j  av a  2s.c o m
    notificationView.setOnClickPendingIntent(R.id.download_notification, pendingSwitchIntent);
    notificationManager.notify(1, notification);
}

From source file:keyboard.ecloga.com.eclogakeyboard.EclogaKeyboard.java

@Override
public void onStartInputView(EditorInfo info, boolean restarting) {
    initializeKeyboard();//from  ww  w.j  a  v a2  s.  co 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);
}