Example usage for android.os PowerManager newWakeLock

List of usage examples for android.os PowerManager newWakeLock

Introduction

In this page you can find the example usage for android.os PowerManager newWakeLock.

Prototype

public WakeLock newWakeLock(int levelAndFlags, String tag) 

Source Link

Document

Creates a new wake lock with the specified level and flags.

Usage

From source file:com.volosyukivan.WiFiInputMethod.java

@Override
public void onCreate() {
    super.onCreate();
    PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
    wakeLock = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE,
            "wifikeyboard");
    //    Debug.d("WiFiInputMethod started");
    serviceConnection = new ServiceConnection() {
        //@Override
        public void onServiceConnected(ComponentName name, IBinder service) {
            //        Debug.d("WiFiInputMethod connected to HttpService.");
            try {
                remoteKeyboard = RemoteKeyboard.Stub.asInterface(service);
                keyboardListener = new RemoteKeyListener.Stub() {
                    @Override//from  w  ww .  ja  v  a 2 s  .com
                    public void keyEvent(int code, boolean pressed) throws RemoteException {
                        // Debug.d("got key in WiFiInputMethod");
                        receivedKey(code, pressed);
                    }

                    @Override
                    public void charEvent(int code) throws RemoteException {
                        // Debug.d("got key in WiFiInputMethod");
                        receivedChar(code);
                    }

                    @Override
                    public boolean setText(String text) throws RemoteException {
                        return WiFiInputMethod.this.setText(text);
                    }

                    @Override
                    public String getText() throws RemoteException {
                        return WiFiInputMethod.this.getText();
                    }
                };
                RemoteKeyboard.Stub.asInterface(service).registerKeyListener(keyboardListener);
            } catch (RemoteException e) {
                throw new RuntimeException("WiFiInputMethod failed to connected to HttpService.", e);
            }
        }

        //@Override
        public void onServiceDisconnected(ComponentName name) {
            //        Debug.d("WiFiInputMethod disconnected from HttpService.");
        }
    };
    if (this.bindService(new Intent(this, HttpService.class), serviceConnection, BIND_AUTO_CREATE) == false) {
        throw new RuntimeException("failed to connect to HttpService");
    }
}

From source file:com.klinker.android.twitter.utils.NotificationUtils.java

public static void makeFavsNotification(ArrayList<String[]> tweets, Context context, boolean toDrawer) {
    String shortText;//from w w w  .  ja v a  2  s. c o  m
    String longText;
    String title;
    int smallIcon = R.drawable.ic_stat_icon;
    Bitmap largeIcon;

    Intent resultIntent;

    if (toDrawer) {
        resultIntent = new Intent(context, RedirectToDrawer.class);
    } else {
        resultIntent = new Intent(context, NotiTweetPager.class);
    }

    PendingIntent resultPendingIntent = PendingIntent.getActivity(context, 0, resultIntent, 0);

    NotificationCompat.InboxStyle inbox = null;

    if (tweets.size() == 1) {
        title = tweets.get(0)[0];
        shortText = tweets.get(0)[1];
        longText = shortText;

        largeIcon = getImage(context, tweets.get(0)[2]);
    } else {
        inbox = new NotificationCompat.InboxStyle();

        title = context.getResources().getString(R.string.favorite_users);
        shortText = tweets.size() + " " + context.getResources().getString(R.string.fav_user_tweets);
        longText = "";

        try {
            inbox.setBigContentTitle(shortText);
        } catch (Exception e) {

        }

        if (tweets.size() <= 5) {
            for (String[] s : tweets) {
                inbox.addLine(Html.fromHtml("<b>" + s[0] + ":</b> " + s[1]));
            }
        } else {
            for (int i = 0; i < 5; i++) {
                inbox.addLine(Html.fromHtml("<b>" + tweets.get(i)[0] + ":</b> " + tweets.get(i)[1]));
            }

            inbox.setSummaryText("+" + (tweets.size() - 5) + " " + context.getString(R.string.tweets));
        }

        largeIcon = BitmapFactory.decodeResource(context.getResources(), R.drawable.drawer_user_dark);
    }

    NotificationCompat.Builder mBuilder;

    AppSettings settings = AppSettings.getInstance(context);

    if (shortText.contains("@" + settings.myScreenName)) {
        // return because there is a mention notification for this already
        return;
    }

    Intent deleteIntent = new Intent(context, NotificationDeleteReceiverOne.class);

    mBuilder = new NotificationCompat.Builder(context).setContentTitle(title)
            .setContentText(TweetLinkUtils.removeColorHtml(shortText, settings)).setSmallIcon(smallIcon)
            .setLargeIcon(largeIcon).setContentIntent(resultPendingIntent).setAutoCancel(true)
            .setDeleteIntent(PendingIntent.getBroadcast(context, 0, deleteIntent, 0))
            .setPriority(NotificationCompat.PRIORITY_HIGH);

    if (inbox == null) {
        mBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(Html.fromHtml(
                settings.addonTheme ? longText.replaceAll("FF8800", settings.accentColor) : longText)));
    } else {
        mBuilder.setStyle(inbox);
    }
    if (settings.vibrate) {
        mBuilder.setDefaults(Notification.DEFAULT_VIBRATE);
    }

    if (settings.sound) {
        try {
            mBuilder.setSound(Uri.parse(settings.ringtone));
        } catch (Exception e) {
            mBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
        }
    }

    if (settings.led)
        mBuilder.setLights(0xFFFFFF, 1000, 1000);

    if (settings.notifications) {

        NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);

        notificationManager.notify(2, mBuilder.build());

        // if we want to wake the screen on a new message
        if (settings.wakeScreen) {
            PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
            final PowerManager.WakeLock wakeLock = pm.newWakeLock((PowerManager.SCREEN_BRIGHT_WAKE_LOCK
                    | PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP), "TAG");
            wakeLock.acquire(5000);
        }

        // Pebble notification
        if (context
                .getSharedPreferences("com.klinker.android.twitter_world_preferences",
                        Context.MODE_WORLD_READABLE + Context.MODE_WORLD_WRITEABLE)
                .getBoolean("pebble_notification", false)) {
            sendAlertToPebble(context, title, shortText);
        }

        // Light Flow notification
        sendToLightFlow(context, title, shortText);
    }
}

From source file:com.klinker.android.twitter.utils.NotificationUtils.java

public static void newInteractions(User interactor, Context context, SharedPreferences sharedPrefs,
        String type) {/*from   w w  w . j av a 2s.c  om*/
    String title = "";
    String text = "";
    String smallText = "";
    Bitmap icon = null;

    AppSettings settings = AppSettings.getInstance(context);

    Intent resultIntent = new Intent(context, RedirectToDrawer.class);
    PendingIntent resultPendingIntent = PendingIntent.getActivity(context, 0, resultIntent, 0);

    int newFollowers = sharedPrefs.getInt("new_followers", 0);
    int newRetweets = sharedPrefs.getInt("new_retweets", 0);
    int newFavorites = sharedPrefs.getInt("new_favorites", 0);
    int newQuotes = sharedPrefs.getInt("new_quotes", 0);

    // set title
    if (newFavorites + newRetweets + newFollowers > 1) {
        title = context.getResources().getString(R.string.new_interactions);
    } else {
        title = context.getResources().getString(R.string.new_interaction_upper);
    }

    // set text
    String currText = sharedPrefs.getString("old_interaction_text", "");
    if (!currText.equals("")) {
        currText += "<br>";
    }
    if (settings.displayScreenName) {
        text = currText + "<b>" + interactor.getScreenName() + "</b> " + type;
    } else {
        text = currText + "<b>" + interactor.getName() + "</b> " + type;
    }
    sharedPrefs.edit().putString("old_interaction_text", text).commit();

    // set icon
    int types = 0;
    if (newFavorites > 0) {
        types++;
    }
    if (newFollowers > 0) {
        types++;
    }
    if (newRetweets > 0) {
        types++;
    }
    if (newQuotes > 0) {
        types++;
    }

    if (types > 1) {
        icon = BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_stat_icon);
    } else {
        if (newFavorites > 0) {
            icon = BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_heart_dark);
        } else if (newRetweets > 0) {
            icon = BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_action_repeat_dark);
        } else {
            icon = BitmapFactory.decodeResource(context.getResources(), R.drawable.drawer_user_dark);
        }
    }

    // set shorter text
    int total = newFavorites + newFollowers + newRetweets + newQuotes;
    if (total > 1) {
        smallText = total + " " + context.getResources().getString(R.string.new_interactions_lower);
    } else {
        smallText = text;
    }

    Intent markRead = new Intent(context, ReadInteractionsService.class);
    PendingIntent readPending = PendingIntent.getService(context, 0, markRead, 0);

    Intent deleteIntent = new Intent(context, NotificationDeleteReceiverOne.class);

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context).setContentTitle(title)
            .setContentText(Html.fromHtml(
                    settings.addonTheme ? smallText.replaceAll("FF8800", settings.accentColor) : smallText))
            .setSmallIcon(R.drawable.ic_stat_icon).setLargeIcon(icon).setContentIntent(resultPendingIntent)
            .setTicker(title).setDeleteIntent(PendingIntent.getBroadcast(context, 0, deleteIntent, 0))
            .setPriority(NotificationCompat.PRIORITY_HIGH).setAutoCancel(true);

    if (context.getResources().getBoolean(R.bool.expNotifications)) {
        mBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(
                Html.fromHtml(settings.addonTheme ? text.replaceAll("FF8800", settings.accentColor) : text)));
    }

    if (settings.vibrate) {
        mBuilder.setDefaults(Notification.DEFAULT_VIBRATE);
    }

    if (settings.sound) {
        try {
            mBuilder.setSound(Uri.parse(settings.ringtone));
        } catch (Exception e) {
            mBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
        }
    }

    if (settings.led)
        mBuilder.setLights(0xFFFFFF, 1000, 1000);

    if (settings.notifications) {

        NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);

        notificationManager.notify(4, mBuilder.build());

        // if we want to wake the screen on a new message
        if (settings.wakeScreen) {
            PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
            final PowerManager.WakeLock wakeLock = pm.newWakeLock((PowerManager.SCREEN_BRIGHT_WAKE_LOCK
                    | PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP), "TAG");
            wakeLock.acquire(5000);
        }

        // Pebble notification
        if (sharedPrefs.getBoolean("pebble_notification", false)) {
            sendAlertToPebble(context, title, text);
        }

        // Light Flow notification
        sendToLightFlow(context, title, text);
    }
}

From source file:uk.co.spookypeanut.wake_me_at.WakeMeAtService.java

public void soundAlarm() {
    mAlarm = true;/*from www . ja v  a  2 s  .  c  o m*/
    // This method of waking up the device seems to be required on <= 4.0
    PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
    wl = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, LOG_NAME);
    if ((wl != null) && (wl.isHeld() == false)) {
        wl.acquire();
    }
    Intent alarmIntent = new Intent(WakeMeAtService.this.getApplication(), Alarm.class);
    alarmIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    alarmIntent.putExtra("rowId", mRowId);
    alarmIntent.putExtra("metresAway", mMetresAway);
    alarmIntent.putExtra("alarm", mAlarm);

    startActivity(alarmIntent);
    updateAlarm();
}

From source file:com.klinker.android.twitter.utils.NotificationUtils.java

public static void notifySecondMentions(Context context, int secondAccount) {
    MentionsDataSource data = MentionsDataSource.getInstance(context);
    int numberNew = data.getUnreadCount(secondAccount);

    int smallIcon = R.drawable.ic_stat_icon;
    Bitmap largeIcon;//from   w w w.j a  v  a  2 s  .c  o  m

    Intent resultIntent = new Intent(context, SwitchAccountsRedirect.class);

    PendingIntent resultPendingIntent = PendingIntent.getActivity(context, 0, resultIntent, 0);

    NotificationCompat.Builder mBuilder;

    String title = context.getResources().getString(R.string.app_name) + " - "
            + context.getResources().getString(R.string.sec_acc);
    ;
    String name = null;
    String message;
    String messageLong;

    String tweetText = null;
    NotificationCompat.Action replyAction = null;
    if (numberNew == 1) {
        name = data.getNewestName(secondAccount);

        SharedPreferences sharedPrefs = context.getSharedPreferences(
                "com.klinker.android.twitter_world_preferences",
                Context.MODE_WORLD_READABLE + Context.MODE_WORLD_WRITEABLE);
        // if they are muted, and you don't want them to show muted mentions
        // then just quit
        if (sharedPrefs.getString("muted_users", "").contains(name)
                && !sharedPrefs.getBoolean("show_muted_mentions", false)) {
            return;
        }

        message = context.getResources().getString(R.string.mentioned_by) + " @" + name;
        tweetText = data.getNewestMessage(secondAccount);
        messageLong = "<b>@" + name + "</b>: " + tweetText;
        largeIcon = getImage(context, name);

        Intent reply = new Intent(context, NotificationComposeSecondAcc.class);

        sharedPrefs.edit().putString("from_notification_second", "@" + name).commit();
        long id = data.getLastIds(secondAccount)[0];
        PendingIntent replyPending = PendingIntent.getActivity(context, 0, reply, 0);
        sharedPrefs.edit().putLong("from_notification_long_second", id).commit();
        sharedPrefs.edit()
                .putString("from_notification_text_second",
                        "@" + name + ": "
                                + TweetLinkUtils.removeColorHtml(tweetText, AppSettings.getInstance(context)))
                .commit();

        // Create the remote input
        RemoteInput remoteInput = new RemoteInput.Builder(EXTRA_VOICE_REPLY).setLabel("@" + name + " ").build();

        // Create the notification action
        replyAction = new NotificationCompat.Action.Builder(R.drawable.ic_action_reply_dark,
                context.getResources().getString(R.string.noti_reply), replyPending).addRemoteInput(remoteInput)
                        .build();

    } else { // more than one mention
        message = numberNew + " " + context.getResources().getString(R.string.new_mentions);
        messageLong = "<b>" + context.getResources().getString(R.string.mentions) + "</b>: " + numberNew + " "
                + context.getResources().getString(R.string.new_mentions);
        largeIcon = BitmapFactory.decodeResource(context.getResources(), R.drawable.drawer_user_dark);
    }

    Intent markRead = new Intent(context, MarkReadSecondAccService.class);
    PendingIntent readPending = PendingIntent.getService(context, 0, markRead, 0);

    AppSettings settings = AppSettings.getInstance(context);

    Intent deleteIntent = new Intent(context, NotificationDeleteReceiverTwo.class);

    mBuilder = new NotificationCompat.Builder(context).setContentTitle(title)
            .setContentText(TweetLinkUtils.removeColorHtml(message, settings)).setSmallIcon(smallIcon)
            .setLargeIcon(largeIcon).setContentIntent(resultPendingIntent).setAutoCancel(true)
            .setDeleteIntent(PendingIntent.getBroadcast(context, 0, deleteIntent, 0))
            .setPriority(NotificationCompat.PRIORITY_HIGH);

    if (numberNew == 1) {
        mBuilder.addAction(replyAction);
        mBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(Html.fromHtml(
                settings.addonTheme ? messageLong.replaceAll("FF8800", settings.accentColor) : messageLong)));
    } else {
        NotificationCompat.InboxStyle inbox = getMentionsInboxStyle(numberNew, secondAccount, context,
                TweetLinkUtils.removeColorHtml(message, settings));

        mBuilder.setStyle(inbox);
    }
    if (settings.vibrate) {
        mBuilder.setDefaults(Notification.DEFAULT_VIBRATE);
    }

    if (settings.sound) {
        try {
            mBuilder.setSound(Uri.parse(settings.ringtone));
        } catch (Exception e) {
            mBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
        }
    }

    if (settings.led)
        mBuilder.setLights(0xFFFFFF, 1000, 1000);

    if (settings.notifications) {

        NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);

        notificationManager.notify(9, mBuilder.build());

        // if we want to wake the screen on a new message
        if (settings.wakeScreen) {
            PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
            final PowerManager.WakeLock wakeLock = pm.newWakeLock((PowerManager.SCREEN_BRIGHT_WAKE_LOCK
                    | PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP), "TAG");
            wakeLock.acquire(5000);
        }

        // Pebble notification
        if (context
                .getSharedPreferences("com.klinker.android.twitter_world_preferences",
                        Context.MODE_WORLD_READABLE + Context.MODE_WORLD_WRITEABLE)
                .getBoolean("pebble_notification", false)) {
            sendAlertToPebble(context, title, messageLong);
        }

        // Light Flow notification
        sendToLightFlow(context, title, messageLong);
    }
}

From source file:org.ohmage.reminders.types.location.LocTrigService.java

private static void acquireRecvrWakeLock(Context context) {

    if (mRecvrWakeLock == null) {
        PowerManager powerMan = (PowerManager) context.getSystemService(POWER_SERVICE);

        mRecvrWakeLock = powerMan.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, RECR_WAKE_LOCK_TAG);
        mRecvrWakeLock.setReferenceCounted(true);
    }//from  ww  w.ja v  a 2s  .c o m

    if (!mRecvrWakeLock.isHeld()) {
        mRecvrWakeLock.acquire();
    }
}

From source file:com.daiv.android.twitter.utils.NotificationUtils.java

public static void refreshNotification(Context context, boolean noTimeline) {
    AppSettings settings = AppSettings.getInstance(context);

    SharedPreferences sharedPrefs = context.getSharedPreferences("com.daiv.android.twitter_world_preferences",
            Context.MODE_WORLD_READABLE + Context.MODE_WORLD_WRITEABLE);
    int currentAccount = sharedPrefs.getInt("current_account", 1);

    //int[] unreadCounts = new int[] {4, 1, 2}; // for testing
    int[] unreadCounts = getUnreads(context);

    int timeline = unreadCounts[0];
    int realTimelineCount = timeline;

    // if they don't want that type of notification, simply set it to zero
    if (!settings.timelineNot || (settings.pushNotifications && settings.liveStreaming) || noTimeline) {
        unreadCounts[0] = 0;//w  ww. j a v a  2  s.  co  m
    }
    if (!settings.mentionsNot) {
        unreadCounts[1] = 0;
    }
    if (!settings.dmsNot) {
        unreadCounts[2] = 0;
    }

    if (unreadCounts[0] == 0 && unreadCounts[1] == 0 && unreadCounts[2] == 0) {

    } else {
        Intent markRead = new Intent(context, MarkReadService.class);
        PendingIntent readPending = PendingIntent.getService(context, 0, markRead, 0);

        String shortText = getShortText(unreadCounts, context, currentAccount);
        String longText = getLongText(unreadCounts, context, currentAccount);
        // [0] is the full title and [1] is the screenname
        String[] title = getTitle(unreadCounts, context, currentAccount);
        boolean useExpanded = useExp(context);
        boolean addButton = addBtn(unreadCounts);

        if (title == null) {
            return;
        }

        Intent resultIntent;

        if (unreadCounts[1] != 0 && unreadCounts[0] == 0) {
            // it is a mention notification (could also have a direct message)
            resultIntent = new Intent(context, RedirectToMentions.class);
        } else {
            resultIntent = new Intent(context, MaterialMainActivity.class);
        }

        PendingIntent resultPendingIntent = PendingIntent.getActivity(context, 0, resultIntent, 0);

        NotificationCompat.Builder mBuilder;

        Intent deleteIntent = new Intent(context, NotificationDeleteReceiverOne.class);

        mBuilder = new NotificationCompat.Builder(context).setContentTitle(title[0])
                .setContentText(TweetLinkUtils.removeColorHtml(shortText, settings))
                .setSmallIcon(R.drawable.ic_stat_icon).setLargeIcon(getIcon(context, unreadCounts, title[1]))
                .setContentIntent(resultPendingIntent).setAutoCancel(true)
                .setTicker(TweetLinkUtils.removeColorHtml(shortText, settings))
                .setDeleteIntent(PendingIntent.getBroadcast(context, 0, deleteIntent, 0))
                .setPriority(NotificationCompat.PRIORITY_HIGH);

        if (unreadCounts[1] > 1 && unreadCounts[0] == 0 && unreadCounts[2] == 0) {
            // inbox style notification for mentions
            mBuilder.setStyle(getMentionsInboxStyle(unreadCounts[1], currentAccount, context,
                    TweetLinkUtils.removeColorHtml(shortText, settings)));
        } else if (unreadCounts[2] > 1 && unreadCounts[0] == 0 && unreadCounts[1] == 0) {
            // inbox style notification for direct messages
            mBuilder.setStyle(getDMInboxStyle(unreadCounts[1], currentAccount, context,
                    TweetLinkUtils.removeColorHtml(shortText, settings)));
        } else {
            // big text style for an unread count on timeline, mentions, and direct messages
            mBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(Html.fromHtml(
                    settings.addonTheme ? longText.replaceAll("FF8800", settings.accentColor) : longText)));
        }

        // Pebble notification
        if (sharedPrefs.getBoolean("pebble_notification", false)) {
            sendAlertToPebble(context, title[0], shortText);
        }

        // Light Flow notification
        sendToLightFlow(context, title[0], shortText);

        int homeTweets = unreadCounts[0];
        int mentionsTweets = unreadCounts[1];
        int dmTweets = unreadCounts[2];

        int newC = 0;

        if (homeTweets > 0) {
            newC++;
        }
        if (mentionsTweets > 0) {
            newC++;
        }
        if (dmTweets > 0) {
            newC++;
        }

        if (settings.notifications && newC > 0) {

            if (settings.vibrate) {
                mBuilder.setDefaults(Notification.DEFAULT_VIBRATE);
            }

            if (settings.sound) {
                try {
                    mBuilder.setSound(Uri.parse(settings.ringtone));
                } catch (Exception e) {
                    mBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
                }
            }

            if (settings.led)
                mBuilder.setLights(0xFFFFFF, 1000, 1000);

            // Get an instance of the NotificationManager service
            NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);

            if (addButton) { // the reply and read button should be shown

                Log.v("username_for_noti", title[1]);
                sharedPrefs.edit().putString("from_notification", "@" + title[1] + " " + title[2]).commit();
                MentionsDataSource data = MentionsDataSource.getInstance(context);
                long id = data.getLastIds(currentAccount)[0];
                PendingIntent replyPending = PendingIntent.getActivity(context, 0, null, 0);
                sharedPrefs.edit().putLong("from_notification_long", id).commit();
                sharedPrefs.edit()
                        .putString("from_notification_text",
                                "@" + title[1] + ": " + TweetLinkUtils.removeColorHtml(shortText, settings))
                        .commit();

                // Create the remote input
                RemoteInput remoteInput = new RemoteInput.Builder(EXTRA_VOICE_REPLY)
                        .setLabel("@" + title[1] + " ").build();

                // Create the notification action
                NotificationCompat.Action replyAction = new NotificationCompat.Action.Builder(
                        R.drawable.ic_action_reply_dark, context.getResources().getString(R.string.noti_reply),
                        replyPending).addRemoteInput(remoteInput).build();

                NotificationCompat.Action.Builder action = new NotificationCompat.Action.Builder(
                        R.drawable.ic_action_read_dark, context.getResources().getString(R.string.mark_read),
                        readPending);

                mBuilder.addAction(replyAction);
                mBuilder.addAction(action.build());
            }

            // Build the notification and issues it with notification manager.
            notificationManager.notify(1, mBuilder.build());

            // if we want to wake the screen on a new message
            if (settings.wakeScreen) {
                PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
                final PowerManager.WakeLock wakeLock = pm.newWakeLock((PowerManager.SCREEN_BRIGHT_WAKE_LOCK
                        | PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP), "TAG");
                wakeLock.acquire(5000);
            }
        }

        // if there are unread tweets on the timeline, check them for favorite users
        if (settings.favoriteUserNotifications && realTimelineCount > 0) {
            favUsersNotification(currentAccount, context);
        }
    }

    try {

        ContentValues cv = new ContentValues();

        cv.put("tag", "com.daiv.android.twitter/com.daiv.android.twitter.ui.MainActivity");

        // add the direct messages and mentions
        cv.put("count", unreadCounts[1] + unreadCounts[2]);

        context.getContentResolver().insert(Uri.parse("content://com.teslacoilsw.notifier/unread_count"), cv);

    } catch (IllegalArgumentException ex) {

        /* Fine, TeslaUnread is not installed. */

    } catch (Exception ex) {

        /* Some other error, possibly because the format
           of the ContentValues are incorrect.
                
        Log but do not crash over this. */

        ex.printStackTrace();

    }
}

From source file:com.morlunk.mumbleclient.service.PlumbleService.java

private void setProximitySensorOn(boolean on) {
    if (on) {//www .j ava  2  s . c  om
        PowerManager pm = (PowerManager) getSystemService(POWER_SERVICE);
        mProximityLock = pm.newWakeLock(PROXIMITY_SCREEN_OFF_WAKE_LOCK, "plumble_proximity");
        mProximityLock.acquire();
    } else {
        if (mProximityLock != null)
            mProximityLock.release();
        mProximityLock = null;
    }
}

From source file:net.olejon.spotcommander.AddComputerActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Power manager
    final PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);

    //noinspection deprecation
    mWakeLock = powerManager.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "wakeLock");

    // Allow landscape?
    if (!mTools.allowLandscape())
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

    // Layout//from w  w  w  .j a  v a 2s  . c  o m
    setContentView(R.layout.activity_add_computer);

    // Toolbar
    final Toolbar toolbar = (Toolbar) findViewById(R.id.add_computer_toolbar);
    toolbar.setTitleTextColor(ContextCompat.getColor(mContext, R.color.white));

    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    mAddComputerNameInputLayout = (TextInputLayout) findViewById(R.id.add_computer_text_input_name_layout);
    mAddComputerUriInputLayout = (TextInputLayout) findViewById(R.id.add_computer_text_input_uri_layout);
    mAddComputerNameInputLayout.setHintAnimationEnabled(true);
    mAddComputerUriInputLayout.setHintAnimationEnabled(true);

    // Progress bar
    mProgressBar = (ProgressBar) findViewById(R.id.add_computer_progressbar);

    // Information
    final TextView textView = (TextView) findViewById(R.id.add_computer_information);
    textView.setMovementMethod(LinkMovementMethod.getInstance());

    // Scan dialog
    new MaterialDialog.Builder(mContext).title(R.string.add_computer_scan_dialog_title)
            .content(getString(R.string.add_computer_scan_dialog_message))
            .positiveText(R.string.add_computer_scan_dialog_positive_button)
            .negativeText(R.string.add_computer_scan_dialog_negative_button)
            .onPositive(new MaterialDialog.SingleButtonCallback() {
                @Override
                public void onClick(@NonNull MaterialDialog materialDialog,
                        @NonNull DialogAction dialogAction) {
                    scanNetwork();
                }
            }).contentColorRes(R.color.black).negativeColorRes(R.color.black).show();
}

From source file:com.cellbots.local.EyesView.java

public EyesView(CellDroidActivity ct, String url, boolean torch) {
    Log.e("remote eyes", "started " + url);
    mParent = ct;/*from w  w  w  .j av a2 s  .co m*/
    putUrl = url;

    PowerManager pm = (PowerManager) ct.getSystemService(Context.POWER_SERVICE);
    mWakeLock = pm.newWakeLock(
            PowerManager.FULL_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE | PowerManager.ACQUIRE_CAUSES_WAKEUP,
            "Cellbot Eyes");
    mWakeLock.acquire();

    out = new ByteArrayOutputStream();

    if (putUrl != null) {
        isLocalUrl = putUrl.contains("127.0.0.1") || putUrl.contains("localhost");
        server = putUrl.replace("http://", "");
        server = server.substring(0, server.indexOf("/"));
        mTorchMode = torch;
        resetConnection();
        mHttpState = new HttpState();
    }

    ct.setContentView(R.layout.eyes_main);
    mPreview = (SurfaceView) ct.findViewById(R.id.eyes_preview);
    mHolder = mPreview.getHolder();
    mHolder.addCallback(this);
    mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);

    mPreview.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            setTorchMode(!mTorchMode);
        }
    });

    mReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            boolean useTorch = intent.getBooleanExtra("TORCH", false);
            boolean shouldTakePicture = intent.getBooleanExtra("PICTURE", false);
            setTorchMode(useTorch);
            setTakePicture(shouldTakePicture);
        }
    };

    ct.registerReceiver(mReceiver, new IntentFilter(EyesView.EYES_COMMAND));

    mFrame = (FrameLayout) ct.findViewById(R.id.eyes_frame);
    mImageView = new ImageView(ct);
    mImageView.setScaleType(ScaleType.FIT_CENTER);
    mImageView.setBackgroundColor(Color.BLACK);

    setPersona(PERSONA_READY);

    mFrame.addView(mImageView);
}