Example usage for android.app PendingIntent getActivity

List of usage examples for android.app PendingIntent getActivity

Introduction

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

Prototype

public static PendingIntent getActivity(Context context, int requestCode, Intent intent, @Flags int flags) 

Source Link

Document

Retrieve a PendingIntent that will start a new activity, like calling Context#startActivity(Intent) Context.startActivity(Intent) .

Usage

From source file:com.bonsai.wallet32.WalletService.java

private void showStatusNotification() {
    CharSequence started_txt = getText(R.string.wallet_service_started);
    CharSequence info_txt = getText(R.string.wallet_service_info);

    Notification note = new Notification(R.drawable.ic_stat_notify, started_txt, System.currentTimeMillis());

    Intent intent = new Intent(this, MainActivity.class);

    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);

    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent, 0);

    // Set the info for the views that show in the notification panel.
    note.setLatestEventInfo(this, getText(R.string.wallet_service_label), info_txt, contentIntent);

    note.flags |= Notification.FLAG_NO_CLEAR;

    startForeground(NOTIFICATION, note);
}

From source file:github.daneren2005.dsub.util.Util.java

public static void showPlayingNotification(final Context context, final DownloadServiceImpl downloadService,
        Handler handler, MusicDirectory.Entry song) {
    // Set the icon, scrolling text and timestamp
    final Notification notification = new Notification(R.drawable.stat_notify_playing, song.getTitle(),
            System.currentTimeMillis());
    notification.flags |= Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT;

    boolean playing = downloadService.getPlayerState() == PlayerState.STARTED;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        RemoteViews expandedContentView = new RemoteViews(context.getPackageName(),
                R.layout.notification_expanded);
        setupViews(expandedContentView, context, song, playing);
        notification.bigContentView = expandedContentView;
    }// w w  w  .  java 2  s  . c  om

    RemoteViews smallContentView = new RemoteViews(context.getPackageName(), R.layout.notification);
    setupViews(smallContentView, context, song, playing);
    notification.contentView = smallContentView;

    Intent notificationIntent = new Intent(context, DownloadActivity.class);
    notification.contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);

    handler.post(new Runnable() {
        @Override
        public void run() {
            downloadService.startForeground(Constants.NOTIFICATION_ID_PLAYING, notification);
        }
    });

    // Update widget
    DSubWidgetProvider.getInstance().notifyChange(context, downloadService, true);
}

From source file:org.csploit.android.core.UpdateService.java

/**
 * if mContentIntent is null delete our notification,
 * else assign it to the notification onClick
 *///  w w w. j  a  v a  2s.  c o m
private void finishNotification() {
    boolean errorOccurred;
    Intent contentIntent;

    synchronized (mCurrentTask) {
        errorOccurred = mCurrentTask.errorOccurred;
        contentIntent = mCurrentTask.contentIntent;
    }

    if (errorOccurred || contentIntent == null) {
        Logger.debug("deleting notifications");
        if (mNotificationManager != null)
            mNotificationManager.cancel(NOTIFICATION_ID);
    } else {
        Logger.debug("assign '" + contentIntent.toString() + "' to notification");
        if (mBuilder != null && mNotificationManager != null) {
            mBuilder.setContentIntent(
                    PendingIntent.getActivity(this, DOWNLOAD_COMPLETE_CODE, contentIntent, 0));
            mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
        }
    }
    if (mReceiver != null)
        unregisterReceiver(mReceiver);
    mReceiver = null;
    mBuilder = null;
    mNotificationManager = null;
}

From source file:com.piusvelte.taplock.client.core.TapLockSettings.java

@Override
protected void onListItemClick(ListView list, final View view, int position, final long id) {
    super.onListItemClick(list, view, position, id);
    mDialog = new AlertDialog.Builder(TapLockSettings.this)
            .setItems(R.array.actions_entries, new DialogInterface.OnClickListener() {
                @Override// w  w w. j a  va 2s . co m
                public void onClick(DialogInterface dialog, int which) {
                    String action = getResources().getStringArray(R.array.actions_values)[which];
                    int deviceIdx = (int) id;
                    JSONObject deviceJObj = mDevices.get(deviceIdx);
                    dialog.cancel();
                    if (ACTION_UNLOCK.equals(action) || ACTION_LOCK.equals(action)
                            || ACTION_TOGGLE.equals(action)) {
                        String name = "uknown";
                        try {
                            name = deviceJObj.getString(KEY_NAME);
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                        startActivity(TapLock.getPackageIntent(getApplicationContext(), TapLockToggle.class)
                                .setAction(action).putExtra(EXTRA_DEVICE_NAME, name));
                    } else if (ACTION_TAG.equals(action)) {
                        // write the device to a tag
                        mInWriteMode = true;
                        try {
                            mNfcAdapter.enableForegroundDispatch(TapLockSettings.this,
                                    PendingIntent.getActivity(TapLockSettings.this, 0,
                                            new Intent(TapLockSettings.this, TapLockSettings.this.getClass())
                                                    .addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP).putExtra(
                                                            EXTRA_DEVICE_NAME, deviceJObj.getString(KEY_NAME)),
                                            0),
                                    new IntentFilter[] { new IntentFilter(NfcAdapter.ACTION_TAG_DISCOVERED) },
                                    null);
                        } catch (JSONException e) {
                            Log.e(TAG, e.getMessage());
                        }
                        Toast.makeText(TapLockSettings.this, "Touch tag", Toast.LENGTH_LONG).show();
                    } else if (ACTION_REMOVE.equals(action)) {
                        mDevices.remove(deviceIdx);
                        storeDevices();
                    } else if (ACTION_PASSPHRASE.equals(action))
                        setPassphrase(deviceIdx);
                    else if (ACTION_COPY_DEVICE_URI.equals(action)) {
                        ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
                        ClipData clip;
                        try {
                            clip = ClipData.newPlainText(getString(R.string.app_name), String
                                    .format(getString(R.string.device_uri), deviceJObj.get(EXTRA_DEVICE_NAME)));
                            clipboard.setPrimaryClip(clip);
                            Toast.makeText(TapLockSettings.this, "copied to clipboard!", Toast.LENGTH_SHORT)
                                    .show();
                        } catch (JSONException e) {
                            Log.e(TAG, e.getMessage());
                            Toast.makeText(TapLockSettings.this, getString(R.string.msg_oops),
                                    Toast.LENGTH_SHORT).show();
                        }
                    }
                }
            }).create();
    mDialog.show();
}

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  a 2s  .  co m
    final NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);

    StringBuilder text = new StringBuilder();
    if (error.getMessage() != null) {
        text.append(error.getMessage()).append(" (");
    }
    text.append(error.getClass().getSimpleName());
    if (error.getMessage() != null) {
        text.append(")");
    }

    // Set the icon, scrolling text and timestamp
    final Notification notification = new Notification(android.R.drawable.stat_sys_warning, title,
            System.currentTimeMillis());
    notification.flags |= Notification.FLAG_AUTO_CANCEL;

    // The PendingIntent to launch our activity if the user selects this notification
    Intent intent = new Intent(context, ErrorActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.putExtra(Constants.INTENT_EXTRA_NAME_ERROR, title + ".\n\n" + text);
    PendingIntent contentIntent = PendingIntent.getActivity(context, 0, intent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    notification.setLatestEventInfo(context, title, text, contentIntent);

    // Send the notification.
    handler.post(new Runnable() {
        @Override
        public void run() {
            notificationManager.cancel(Constants.NOTIFICATION_ID_ERROR);
            notificationManager.notify(Constants.NOTIFICATION_ID_ERROR, notification);
        }
    });
}

From source file:com.androidquery.simplefeed.activity.PostActivity.java

private void notify(String ticker, String title, String message, Intent intent) {

    String ns = Context.NOTIFICATION_SERVICE;
    NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);

    int icon = R.drawable.launcher;
    long when = System.currentTimeMillis();

    Notification notification = new Notification(icon, ticker, when);

    Context context = getApplicationContext();
    CharSequence contentText = message;

    int id = getNotifyId();
    PendingIntent contentIntent = PendingIntent.getActivity(this, id, intent, 0);

    notification.setLatestEventInfo(context, title, contentText, contentIntent);

    mNotificationManager.cancelAll();/*from w  w w.  j av a 2 s.  co  m*/

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

}

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

@Override
public void onStartInputView(EditorInfo info, boolean restarting) {
    initializeKeyboard();/* www  .  j  av  a  2s .  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:jp.co.conit.sss.sp.ex1.billing.BillingService.java

/**
 * ????//ww  w.ja  v  a  2 s. c om
 * 
 * @param purchases
 */
private void notificationVerifiedProduct(List<VerifiedProduct> purchases) {

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

    HashMap<String, VerifiedProduct> orderMap = new HashMap<String, VerifiedProduct>();
    int size = purchases.size() - 1;

    // ????Map???????????
    for (int i = size; i >= 0; i--) {
        VerifiedProduct vp = purchases.get(i);
        if (vp.getPurchaseState() == PurchaseState.PURCHASED) {
            orderMap.put(vp.getProductId(), vp);
        }
    }

    // ?????Notification??
    // ?????
    if (orderMap.size() > 0) {

        Notification notification = new Notification();
        notification.icon = R.drawable.ic_status;
        notification.tickerText = context.getString(R.string.notification_buy_result);
        notification.flags = Notification.FLAG_AUTO_CANCEL;

        Intent intent = new Intent();
        PendingIntent pendingintent = PendingIntent.getActivity(context, 0, intent, 0);

        String title = context.getString(R.string.notification_book);

        notification.setLatestEventInfo(context, context.getString(R.string.notification_buy_finish, title),
                context.getString(R.string.notification_urge_download), pendingintent);

        notificationManager.notify(0, notification);
    }

}

From source file:at.vcity.androidimsocket.services.IMService.java

/**
 * Show a notification while this service is running.
 * @param msg//from w  w w .j  ava 2s  .  com
 **/
private void showNotification(MessageInfo msg)//String userId, String msg, String msgtype)
{
    //FriendInfo f=FriendController.getFriendInfo(userId);
    // Set the icon, scrolling text and TIMESTAMP

    // Get User name from friend controller

    String title = "AndroidIM: You got a new Message! ";
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.stat_sample).setContentTitle(title).setAutoCancel(true);
    //.setContentText(text);

    FriendInfo friend = FriendController.getFriendInfo(msg.fromUserId);

    if (msg.type.equals(MessageInfo.MessageType.TEXT))
        mBuilder.setContentText("New message from " + friend.userName + ": " + msg.content);
    else if (msg.type.equals(MessageInfo.MessageType.IMAGE)) {
        mBuilder.setContentText("New image from " + friend.userName);
    } else {
        mBuilder.setContentText("New voice clip from " + friend.userName);
    }
    Intent i;

    String packagename = this.getPackageName();
    if (isForeground(packagename))
        i = new Intent(this, Messaging.class);
    else
        i = new Intent(this, Login.class);

    i.putExtra(MessageInfo.MESSAGE, msg);
    i.putExtra(FriendInfo.FRIEND, friend);
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, i, PendingIntent.FLAG_UPDATE_CURRENT);

    // Set the info for the views that show in the notification panel.
    // msg.length()>15 ? MSG : msg.substring(0, 15);
    mBuilder.setContentIntent(contentIntent);

    //TODO: it can be improved, for instance message coming from same user may be concatenated
    // next version

    // Send the notification.
    // We use a layout id because it is a unique number.  We use it later to cancel.
    mNM.notify((msg.fromUserId).hashCode(), mBuilder.build());
}