Example usage for android.app Notification Notification

List of usage examples for android.app Notification Notification

Introduction

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

Prototype

@Deprecated
public Notification(int icon, CharSequence tickerText, long when) 

Source Link

Document

Constructs a Notification object with the information needed to have a status bar icon without the standard expanded view.

Usage

From source file:com.mobiperf.MeasurementScheduler.java

@SuppressWarnings("unused")
private void updateNotificationBar(String notificationMsg) {
    // The intent to launch when the user clicks the expanded notification
    Intent intent = new Intent(this, SpeedometerApp.class);
    PendingIntent pendIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);

    // This constructor is deprecated in 3.x. But most phones still run 2.x systems
    Notification notice = new Notification(R.drawable.icon_statusbar, notificationMsg,
            System.currentTimeMillis());

    // This is deprecated in 3.x. But most phones still run 2.x systems
    notice.setLatestEventInfo(this, "Speedometer", notificationMsg, pendIntent);

    notificationManager.notify(NOTIFICATION_ID, notice);
}

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 .  ja v a2s  . c om*/
    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. ja va2  s . c o  m

    AQUtility.debug("notify id", id);
    mNotificationManager.notify(id, notification);

}

From source file:com.googlecode.android_scripting.facade.AndroidFacade.java

@Rpc(description = "Displays a notification that will be canceled when the user clicks on it.")
public void notify(@RpcParameter(name = "title", description = "title") String title,
        @RpcParameter(name = "message") String message) {
    Notification notification = new Notification(mResources.getLogo48(), message, System.currentTimeMillis());
    // This contentIntent is a noop.
    PendingIntent contentIntent = PendingIntent.getService(mService, 0, new Intent(), 0);
    notification.setLatestEventInfo(mService, title, message, contentIntent);
    notification.flags = Notification.FLAG_AUTO_CANCEL;

    // Get a unique notification id from the application.
    final int notificationId = NotificationIdFactory.create();
    mNotificationManager.notify(notificationId, notification);
}

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

@Override
public void onStartInputView(EditorInfo info, boolean restarting) {
    initializeKeyboard();//from  w w  w.  ja  v a 2  s  .c om
    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.attentec.AttentecService.java

/**
 * shows a notification in the status bar.
 *///w ww  . j a va2  s . com
private void showNotification() {
    //text for display in status bar
    CharSequence text;
    if (PreferencesHelper.getLocationUpdateEnabled(ctx)) {
        text = getText(R.string.service_started);
    } else {
        text = getText(R.string.service_started_no_position);
    }

    //get icon for display status bar
    Notification notification = new Notification(R.drawable.statusbar_icon, text, System.currentTimeMillis());

    //Intent to launch on click in notification list
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, Attentec.class), 0);

    //set notification settings
    notification.setLatestEventInfo(this, getText(R.string.service_label), text, contentIntent);

    //Send notification
    if (PreferencesHelper.getLocationUpdateEnabled(ctx)) {
        //Log.d(TAG, "Showing notifications: with locations");
        mNM.notify(R.string.service_started, notification);
    } else {
        //Log.d(TAG, "Showing notifications: no locations");
        mNM.notify(R.string.service_started_no_position, notification);
    }
}

From source file:de.mangelow.throughput.NotificationService.java

@SuppressWarnings("deprecation")
private void modifyNotification(int drawable, String ticker, String title, String subtitle, Intent i) {

    boolean showticker = MainActivity.loadBooleanPref(context, MainActivity.SHOWTICKER,
            MainActivity.SHOWTICKER_DEFAULT);
    if (!showticker)
        ticker = null;//w ww .j a v  a2  s.  c om

    NotificationManager nmanager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    PendingIntent pi = PendingIntent.getActivity(this, 0, i, NOTIFICATION_ID);
    Notification n = null;

    if (Build.VERSION.SDK_INT < 11) {

        n = new Notification(drawable, ticker, System.currentTimeMillis());
        n.flags |= Notification.FLAG_NO_CLEAR;
        n.setLatestEventInfo(this, title, subtitle, pi);

    } else {

        if (nb == null) {
            nb = new Notification.Builder(context);
            nb.setPriority(Notification.PRIORITY_LOW);
            nb.setAutoCancel(true);
        }

        nb.setSmallIcon(drawable);
        if (ticker != null)
            nb.setTicker(ticker);
        nb.setContentTitle(title);
        nb.setContentText(subtitle);
        nb.setContentIntent(pi);

        n = nb.build();
        n.flags = Notification.FLAG_NO_CLEAR;

    }

    nmanager.notify(NOTIFICATION_ID, n);

    //

    if (mResultReceiver != null) {

        Bundle bundle = new Bundle();
        bundle.putInt("drawable", drawable);
        bundle.putString("title", title);
        bundle.putString("subtitle", subtitle);
        mResultReceiver.send(0, bundle);

    }

}

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 w w.j a  v a2  s.com*/
                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:gov.nasa.arc.geocam.geocam.GeoCamService.java

private void buildNotification(CharSequence title, CharSequence notifyText) {
    Intent notificationIntent = new Intent(getApplication(), GeoCamMobile.class);
    //notificationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    notificationIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);

    if (mNotification == null) {
        mNotification = new Notification(R.drawable.camera_48x48, notifyText, System.currentTimeMillis());
        mNotification.flags |= Notification.FLAG_ONGOING_EVENT;
        mNotification.flags |= Notification.FLAG_NO_CLEAR;
    }/*from   ww w.j a v a  2 s .c o  m*/
    mNotification.setLatestEventInfo(getApplicationContext(), title, notifyText, contentIntent);
}