Example usage for android.os PowerManager isScreenOn

List of usage examples for android.os PowerManager isScreenOn

Introduction

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

Prototype

@Deprecated
public boolean isScreenOn() 

Source Link

Document

Returns true if the device is in an interactive state.

Usage

From source file:com.metinkale.prayerapp.vakit.AlarmReceiver.java

public void fireAlarm(Intent intent) throws InterruptedException {

    Context c = App.getContext();

    if ((intent == null) || !intent.hasExtra("json")) {

        return;//from  w w w  . j  av a  2s.  c  o  m
    }
    Alarm next = Alarm.fromString(intent.getStringExtra("json"));
    intent.removeExtra("json");

    if (next.city == 0) {
        return;
    }

    Times t = Times.getTimes(next.city);
    if (t == null)
        return;
    boolean active;
    if (next.cuma) {
        active = t.isCumaActive();
    } else if (next.early) {
        active = t.isEarlyNotificationActive(next.vakit);
    } else {
        active = t.isNotificationActive(next.vakit);
    }
    if (!active) {
        return;
    }

    boolean vibrate;
    String sound;
    String dua;
    long silenter;
    if (next.cuma) {
        vibrate = t.hasCumaVibration();
        sound = t.getCumaSound();
        dua = "silent";
        silenter = t.getCumaSilenterDuration();
    } else if (next.early) {
        vibrate = t.hasEarlyVibration(next.vakit);
        sound = t.getEarlySound(next.vakit);
        dua = "silent";
        silenter = t.getEarlySilenterDuration(next.vakit);
    } else {
        vibrate = t.hasVibration(next.vakit);
        sound = t.getSound(next.vakit);
        dua = t.getDua(next.vakit);
        silenter = t.getSilenterDuration(next.vakit);
    }

    NotificationManager nm = (NotificationManager) c.getSystemService(Context.NOTIFICATION_SERVICE);

    nm.cancel(next.city + "", NotIds.ALARM);
    String text;

    text = t.getName() + " (" + t.getSource() + ")";

    String txt = "";
    if (next.early) {
        String[] left_part = App.getContext().getResources().getStringArray(R.array.lefttext_part);
        txt = App.getContext().getString(R.string.earlyText, left_part[next.vakit.index],
                "" + t.getEarlyTime(next.vakit));
    } else if (next.cuma) {
        String[] left_part = App.getContext().getResources().getStringArray(R.array.lefttext_part);
        txt = App.getContext().getString(R.string.earlyText, left_part[next.vakit.index], "" + t.getCumaTime());
    } else if (next.vakit != null) {
        txt = next.vakit.getString();
    }

    NotificationCompat.Builder builder = new NotificationCompat.Builder(c).setContentTitle(text)
            .setContentText(txt).setContentIntent(Main.getPendingIntent(t)).setSmallIcon(R.drawable.ic_abicon);
    Notification not = builder.build();

    if (vibrate) {
        not.vibrate = VibrationPreference.getPattern(c, "vibration");
    }

    AudioManager am = (AudioManager) c.getSystemService(Context.AUDIO_SERVICE);

    class MPHolder {
        MediaPlayer mp;
    }
    not.deleteIntent = PendingIntent.getBroadcast(c, 0, new Intent(c, Audio.class),
            PendingIntent.FLAG_UPDATE_CURRENT);

    nm.notify(next.city + "", NotIds.ALARM, not);

    final MPHolder mp = new MPHolder();

    if (Prefs.showNotificationScreen() && (sound != null) && !sound.startsWith("silent")) {
        PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
        if (!pm.isScreenOn()) {
            Intent i = new Intent(c, NotificationPopup.class);
            i.putExtra("city", next.city);
            i.putExtra("name", text);
            i.putExtra("vakit", txt);
            i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP
                    | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
            c.startActivity(i);

            Thread.sleep(1000);
        }
    }

    sInterrupt = false;
    boolean hasSound = false;
    while ((sound != null) && !sound.startsWith("silent") && !sInterrupt) {
        int volume = -2;
        hasSound = true;

        if (!sound.startsWith("silent") && !sound.startsWith("picker")) {

            if (sound.contains("$volume")) {
                volume = Integer.parseInt(sound.substring(sound.indexOf("$volume") + 7));
                sound = sound.substring(0, sound.indexOf("$volume"));
            }
            if (volume != -2) {
                int oldvalue = am.getStreamVolume(getStreamType(c));
                am.setStreamVolume(getStreamType(c), volume, 0);
                volume = oldvalue;
            }

            try {
                mp.mp = play(c, sound);
            } catch (IOException e) {
                e.printStackTrace();
                if (next.cuma) {
                    t.setCumaSound("silent");
                } else if (next.early) {
                    t.setEarlySound(next.vakit, "silent");
                } else {
                    if ("sound".equals(t.getSound(next.vakit))) {
                        t.setSound(next.vakit, "silent");
                    } else {
                        t.setDua(next.vakit, "silent");
                    }
                }
                mp.mp = null;
            }

            if (mp.mp != null) {

                mp.mp.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
                    @Override
                    public void onCompletion(MediaPlayer mediaPlayer) {
                        if (mp.mp == null) {
                            return;
                        }
                        mp.mp.stop();
                        mp.mp.release();
                        mp.mp = null;
                    }
                });

                mp.mp.setOnSeekCompleteListener(new MediaPlayer.OnSeekCompleteListener() {
                    @Override
                    public void onSeekComplete(MediaPlayer mediaPlayer) {
                        if (mp.mp == null) {
                            return;
                        }
                        mp.mp.stop();
                        mp.mp.release();
                        mp.mp = null;
                    }
                });

            }

            sInterrupt = false;

            while ((mp.mp != null) && mp.mp.isPlaying()) {
                if (sInterrupt) {
                    mp.mp.stop();
                    mp.mp.release();
                    mp.mp = null;

                    dua = null;
                } else {
                    try {
                        Thread.sleep(500);
                    } catch (InterruptedException ignore) {
                    }
                }
            }
            sInterrupt = false;

        }

        if (volume != -2) {
            am.setStreamVolume(getStreamType(c), volume, 0);
        }
        sound = dua;
        dua = null;
    }

    if (hasSound && Prefs.autoRemoveNotification()) {
        nm.cancel(next.city + "", NotIds.ALARM);
    }
    if (silenter != 0) {
        silenter(c, silenter);
    }

}

From source file:com.ericsun.duom.Framework.Activity.BaseActivity.java

public boolean isScreenLocked() {

    PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
    boolean isScreenOn = pm.isScreenOn();

    if (isScreenOn)
        return false;
    else/*  www. j ava2 s . co m*/
        return true;
}

From source file:com.brucegiese.perfectposture.OrientationService.java

/**
 * Send out all alerts associated with a bad posture event
 *///from  w w  w  . j av a  2s  . c o m
private void badPostureAlerts() {
    PowerManager pm = (PowerManager) getSystemService(POWER_SERVICE);
    // Only send out alerts if the screen is active.
    if (pm.isScreenOn()) { // This was deprecated in API level 20
        Log.d(TAG, "Posture is bad!");
        vibrate(true);
        sendNotification(NotificationType.BAD_POSTURE, true);
    }
}

From source file:com.brucegiese.perfectposture.OrientationService.java

/**
 * Send out all alerts associated with a good posture event
 *//*from   ww w. j a  va2s  .co m*/
private void goodPostureAlerts() {
    PowerManager pm = (PowerManager) getSystemService(POWER_SERVICE);
    // Only send out alerts if the screen is active.
    if (pm.isScreenOn()) { // This was deprecated in API level 20
        Log.d(TAG, "Posture just got good!");
        vibrate(false);
        sendNotification(NotificationType.BAD_POSTURE, false);
    }
}

From source file:de.tubs.ibr.dtn.chat.service.ChatService.java

@Override
protected void onHandleIntent(Intent intent) {
    String action = intent.getAction();

    // create a task to process concurrently
    if (ACTION_PRESENCE_ALARM.equals(action)) {
        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(ChatService.this);

        // check if the screen is active
        PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
        Boolean screenOn = pm.isScreenOn();

        String presence_tag = preferences.getString("presencetag", "auto");
        String presence_nick = preferences.getString("editNickname", "Nobody");
        String presence_text = preferences.getString("statustext", "");

        if (presence_tag.equals("auto")) {
            if (screenOn) {
                presence_tag = "chat";
            } else {
                presence_tag = "away";
            }//  ww w .ja  v  a 2  s.c o m
        }

        Log.i(TAG, "push out presence; " + presence_tag);
        actionRefreshPresence(presence_tag, presence_nick, presence_text);

        Editor edit = preferences.edit();
        edit.putLong("lastpresenceupdate", (new Date().getTime()));
        edit.commit();
    }
    // create a task to check for messages
    else if (de.tubs.ibr.dtn.Intent.RECEIVE.equals(action)) {
        try {
            while (_client.getSession().queryNext())
                ;
        } catch (SessionDestroyedException e) {
            Log.e(TAG, "Can not query for bundle", e);
        } catch (InterruptedException e) {
            Log.e(TAG, "Can not query for bundle", e);
        }
    } else if (MARK_DELIVERED_INTENT.equals(action)) {
        actionMarkDelivered(intent);
    } else if (REPORT_DELIVERED_INTENT.equals(action)) {
        actionReportDelivered(intent);
    } else if (ACTION_SEND_MESSAGE.equals(action)) {
        Long buddyId = intent.getLongExtra(ChatService.EXTRA_BUDDY_ID, -1);
        String text = intent.getStringExtra(ChatService.EXTRA_TEXT_BODY);

        // abort if there is no buddyId
        if (buddyId < 0)
            return;

        actionSendMessage(buddyId, text);
    } else if (ACTION_REFRESH_PRESENCE.equals(action)) {
        String presence = intent.getStringExtra(ChatService.EXTRA_PRESENCE);
        String nickname = intent.getStringExtra(ChatService.EXTRA_DISPLAY_NAME);
        String status = intent.getStringExtra(ChatService.EXTRA_STATUS);

        actionRefreshPresence(presence, nickname, status);
    } else if (ACTION_NEW_MESSAGE.equals(action)) {
        showNotification(intent);
    }
}

From source file:com.dattasmoon.pebble.plugin.FireReceiver.java

@Override
public void onReceive(final Context context, final Intent intent) {
    if (com.twofortyfouram.locale.Intent.ACTION_FIRE_SETTING.equals(intent.getAction())) {
        // fetch this for later, we may need it in case we change things
        // around and we need to know what version of the code they were
        // running when they saved the action
        int bundleVersionCode = intent.getIntExtra(Constants.BUNDLE_EXTRA_INT_VERSION_CODE, 1);

        Type type = Type.values()[intent.getIntExtra(Constants.BUNDLE_EXTRA_INT_TYPE,
                Type.NOTIFICATION.ordinal())];
        PowerManager pm;
        switch (type) {
        case NOTIFICATION:
            SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(context);

            // handle screen DND
            boolean notifScreenOn = sharedPref.getBoolean(Constants.PREFERENCE_NOTIF_SCREEN_ON, true);
            pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
            if (Constants.IS_LOGGABLE) {
                Log.d(Constants.LOG_TAG, "FireReceiver.onReceive: notifScreenOn=" + notifScreenOn + "  screen="
                        + pm.isScreenOn());
            }//w ww  . j  a va  2  s  .  c  o  m
            if (!notifScreenOn && pm.isScreenOn()) {
                break;
            }

            //handle quiet hours DND
            boolean quiet_hours = sharedPref.getBoolean(Constants.PREFERENCE_QUIET_HOURS, false);
            //we only need to pull this if quiet hours are enabled. Save the cycles for the cpu! (haha)
            if (quiet_hours) {
                String[] pieces = sharedPref.getString(Constants.PREFERENCE_QUIET_HOURS_BEFORE, "00:00")
                        .split(":");
                Date quiet_hours_before = new Date(0, 0, 0, Integer.parseInt(pieces[0]),
                        Integer.parseInt(pieces[1]));
                pieces = sharedPref.getString(Constants.PREFERENCE_QUIET_HOURS_AFTER, "23:59").split(":");
                Date quiet_hours_after = new Date(0, 0, 0, Integer.parseInt(pieces[0]),
                        Integer.parseInt(pieces[1]));
                Calendar c = Calendar.getInstance();
                Date now = new Date(0, 0, 0, c.get(Calendar.HOUR_OF_DAY), c.get(Calendar.MINUTE));
                if (Constants.IS_LOGGABLE) {
                    Log.i(Constants.LOG_TAG, "Checking quiet hours. Now: " + now.toString() + " vs "
                            + quiet_hours_before.toString() + " and " + quiet_hours_after.toString());
                }
                if (now.before(quiet_hours_before) || now.after(quiet_hours_after)) {
                    if (Constants.IS_LOGGABLE) {
                        Log.i(Constants.LOG_TAG, "Time is before or after the quiet hours time. Returning.");
                    }
                    break;
                }
            }

            String title = intent.getStringExtra(Constants.BUNDLE_EXTRA_STRING_TITLE);
            String body = intent.getStringExtra(Constants.BUNDLE_EXTRA_STRING_BODY);

            sendAlertToPebble(context, bundleVersionCode, title, body);
            break;
        case SETTINGS:
            Mode mode = Mode.values()[intent.getIntExtra(Constants.BUNDLE_EXTRA_INT_MODE, Mode.OFF.ordinal())];
            String packageList = intent.getStringExtra(Constants.BUNDLE_EXTRA_STRING_PACKAGE_LIST);

            setNotificationSettings(context, bundleVersionCode, mode, packageList);
            break;
        }
    }
}

From source file:com.socialdisasters.other.service.ChatService.java

@Override
protected void onHandleIntent(Intent intent) {
    // stop processing if the session is not assigned
    if (_session == null)
        return;/*  w w w.  j  ava  2  s  .  com*/

    String action = intent.getAction();

    // create a task to process concurrently
    if (ACTION_PRESENCE_ALARM.equals(action)) {
        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(ChatService.this);

        // check if the screen is active
        PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
        Boolean screenOn = pm.isScreenOn();

        String presence_tag = preferences.getString("presencetag", "unavailable");
        String presence_nick = getLocalNickname();
        String presence_text = preferences.getString("statustext", "");

        if (presence_tag.equals("auto")) {
            if (screenOn) {
                presence_tag = "chat";
            } else {
                presence_tag = "away";
            }
        }

        Log.i(TAG, "push out presence; " + presence_tag);
        actionRefreshPresence(presence_tag, presence_nick, presence_text);

        Editor edit = preferences.edit();
        edit.putLong("lastpresenceupdate", (new Date().getTime()));
        edit.commit();
    }
    // create a task to check for messages
    else if (de.tubs.ibr.dtn.Intent.RECEIVE.equals(action)) {
        // wait until connected
        try {
            while (_session.queryNext())
                ;
        } catch (SessionDestroyedException e) {
            Log.e(TAG, "Can not query for bundle", e);
        }
    } else if (MARK_DELIVERED_INTENT.equals(action)) {
        BundleID bundleid = intent.getParcelableExtra("bundleid");
        if (bundleid == null) {
            Log.e(TAG, "Intent to mark a bundle as delivered, but no bundle ID given");
            return;
        }

        try {
            _session.delivered(bundleid);
        } catch (Exception e) {
            Log.e(TAG, "Can not mark bundle as delivered.", e);
        }
    } else if (REPORT_DELIVERED_INTENT.equals(action)) {
        SingletonEndpoint source = intent.getParcelableExtra("source");
        BundleID bundleid = intent.getParcelableExtra("bundleid");

        if (bundleid == null) {
            Log.e(TAG, "Intent to mark a bundle as delivered, but no bundle ID given");
            return;
        }

        synchronized (this.roster) {
            // report delivery to the roster
            getRoster().reportDelivery(source, bundleid);
        }
    } else if (ACTION_SEND_MESSAGE.equals(action)) {
        Long buddyId = intent.getLongExtra(ChatService.EXTRA_BUDDY_ID, -1);
        String text = intent.getStringExtra(ChatService.EXTRA_TEXT_BODY);

        // abort if there is no buddyId
        if (buddyId < 0)
            return;

        actionSendMessage(buddyId, text);
    } else if (ACTION_REFRESH_PRESENCE.equals(action)) {
        String presence = intent.getStringExtra(ChatService.EXTRA_PRESENCE);
        String nickname = intent.getStringExtra(ChatService.EXTRA_DISPLAY_NAME);
        String status = intent.getStringExtra(ChatService.EXTRA_STATUS);

        actionRefreshPresence(presence, nickname, status);
    } else if (ACTION_NEW_MESSAGE.equals(action)) {
        showNotification(intent);
    }
}

From source file:com.dattasmoon.pebble.plugin.NotificationService.java

@Override
public void onAccessibilityEvent(AccessibilityEvent event) {
    // handle the prefs changing, because of how accessibility services
    // work, sharedprefsonchange listeners don't work
    if (watchFile.lastModified() > lastChange) {
        loadPrefs();/* ww w .  j a  v a 2 s . c  om*/
    }
    if (Constants.IS_LOGGABLE) {
        Log.i(Constants.LOG_TAG, "Service: Mode is: " + String.valueOf(mode.ordinal()));
    }
    // if we are off, don't do anything.
    if (mode == Mode.OFF) {
        if (Constants.IS_LOGGABLE) {
            Log.i(Constants.LOG_TAG, "Service: Mode is off, not sending any notifications");
        }
        return;
    }

    //handle quiet hours
    if (quiet_hours) {

        Calendar c = Calendar.getInstance();
        Date now = new Date(0, 0, 0, c.get(Calendar.HOUR_OF_DAY), c.get(Calendar.MINUTE));
        if (Constants.IS_LOGGABLE) {
            Log.i(Constants.LOG_TAG, "Checking quiet hours. Now: " + now.toString() + " vs "
                    + quiet_hours_before.toString() + " and " + quiet_hours_after.toString());
        }

        if (quiet_hours_before.after(quiet_hours_after)) {
            if (now.after(quiet_hours_after) && now.before(quiet_hours_before)) {
                if (Constants.IS_LOGGABLE) {
                    Log.i(Constants.LOG_TAG, "Time is during quiet time. Returning.");
                }
                return;
            }

        } else if (now.before(quiet_hours_before) || now.after(quiet_hours_after)) {
            if (Constants.IS_LOGGABLE) {
                Log.i(Constants.LOG_TAG, "Time is before or after the quiet hours time. Returning.");
            }
            return;
        }

    }

    // handle if they only want notifications
    if (notifications_only) {
        if (event != null) {
            Parcelable parcelable = event.getParcelableData();
            if (!(parcelable instanceof Notification)) {

                if (Constants.IS_LOGGABLE) {
                    Log.i(Constants.LOG_TAG,
                            "Event is not a notification and notifications only is enabled. Returning.");
                }
                return;
            }
        }
    }
    if (no_ongoing_notifs) {
        Parcelable parcelable = event.getParcelableData();
        if (parcelable instanceof Notification) {
            Notification notif = (Notification) parcelable;
            if ((notif.flags & Notification.FLAG_ONGOING_EVENT) == Notification.FLAG_ONGOING_EVENT) {
                if (Constants.IS_LOGGABLE) {
                    Log.i(Constants.LOG_TAG,
                            "Event is a notification, notification flag contains ongoing, and no ongoing notification is true. Returning.");
                }
                return;
            }
        } else {
            if (Constants.IS_LOGGABLE) {
                Log.i(Constants.LOG_TAG, "Event is not a notification.");
            }
        }
    }

    // Handle the do not disturb screen on settings
    PowerManager powMan = (PowerManager) this.getSystemService(Context.POWER_SERVICE);
    if (Constants.IS_LOGGABLE) {
        Log.d(Constants.LOG_TAG, "NotificationService.onAccessibilityEvent: notifScreenOn=" + notifScreenOn
                + "  screen=" + powMan.isScreenOn());
    }
    if (!notifScreenOn && powMan.isScreenOn()) {
        return;
    }

    if (event == null) {
        if (Constants.IS_LOGGABLE) {
            Log.i(Constants.LOG_TAG, "Event is null. Returning.");
        }
        return;
    }
    if (Constants.IS_LOGGABLE) {
        Log.i(Constants.LOG_TAG, "Event: " + event.toString());
    }

    // main logic
    PackageManager pm = getPackageManager();

    String eventPackageName;
    if (event.getPackageName() != null) {
        eventPackageName = event.getPackageName().toString();
    } else {
        eventPackageName = "";
    }
    if (Constants.IS_LOGGABLE) {
        Log.i(Constants.LOG_TAG, "Service package list is: ");
        for (String strPackage : packages) {
            Log.i(Constants.LOG_TAG, strPackage);
        }
        Log.i(Constants.LOG_TAG, "End Service package list");
    }

    switch (mode) {
    case EXCLUDE:
        // exclude functionality
        if (Constants.IS_LOGGABLE) {
            Log.i(Constants.LOG_TAG, "Mode is set to exclude");
        }

        for (String packageName : packages) {
            if (packageName.equalsIgnoreCase(eventPackageName)) {
                if (Constants.IS_LOGGABLE) {
                    Log.i(Constants.LOG_TAG, packageName + " == " + eventPackageName
                            + " which is on the exclude list. Returning.");
                }
                return;
            }
        }
        break;
    case INCLUDE:
        // include only functionality
        if (Constants.IS_LOGGABLE) {
            Log.i(Constants.LOG_TAG, "Mode is set to include only");
        }
        boolean found = false;
        for (String packageName : packages) {
            if (packageName.equalsIgnoreCase(eventPackageName)) {
                found = true;
                break;
            }
        }
        if (!found) {
            Log.i(Constants.LOG_TAG, eventPackageName + " was not found in the include list. Returning.");
            return;
        }
        break;
    }

    // get the title
    String title = "";
    try {
        boolean renamed = false;
        for (int i = 0; i < pkg_renames.length(); i++) {
            if (pkg_renames.getJSONObject(i).getString("pkg").equalsIgnoreCase(eventPackageName)) {
                renamed = true;
                title = pkg_renames.getJSONObject(i).getString("to");
            }
        }
        if (!renamed) {
            title = pm.getApplicationLabel(pm.getApplicationInfo(eventPackageName, 0)).toString();
        }
    } catch (NameNotFoundException e) {
        title = eventPackageName;
    } catch (JSONException e) {
        title = eventPackageName;
    }

    // get the notification text
    String notificationText = event.getText().toString();
    // strip the first and last characters which are [ and ]
    notificationText = notificationText.substring(1, notificationText.length() - 1);

    if (notification_extras) {
        if (Constants.IS_LOGGABLE) {
            Log.i(Constants.LOG_TAG, "Fetching extras from notification");
        }
        Parcelable parcelable = event.getParcelableData();
        if (parcelable instanceof Notification) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
                notificationText += "\n" + getExtraBigData((Notification) parcelable, notificationText.trim());
            } else {
                notificationText += "\n" + getExtraData((Notification) parcelable, notificationText.trim());
            }

        }
    }

    // Check ignore lists
    for (int i = 0; i < ignores.length(); i++) {
        try {
            JSONObject ignore = ignores.getJSONObject(i);
            String app = ignore.getString("app");
            boolean exclude = ignore.optBoolean("exclude", true);
            boolean case_insensitive = ignore.optBoolean("insensitive", true);
            if ((!app.equals("-1")) && (!eventPackageName.equalsIgnoreCase(app))) {
                //this rule doesn't apply to all apps and this isn't the app we're looking for.
                continue;
            }
            String regex = "";
            if (case_insensitive) {
                regex += "(?i)";
            }
            if (!ignore.getBoolean("raw")) {
                regex += Pattern.quote(ignore.getString("match"));
            } else {
                regex += ignore.getString("match");
            }
            Pattern p = Pattern.compile(regex);
            Matcher m = p.matcher(notificationText);
            if (m.find()) {
                if (exclude) {
                    if (Constants.IS_LOGGABLE) {
                        Log.i(Constants.LOG_TAG, "Notification text of '" + notificationText + "' matches: '"
                                + regex + "' and exclude is on. Returning");
                    }
                    return;
                }
            } else {
                if (!exclude) {
                    if (Constants.IS_LOGGABLE) {
                        Log.i(Constants.LOG_TAG, "Notification text of '" + notificationText
                                + "' does not match: '" + regex + "' and include is on. Returning");
                    }
                    return;
                }

            }
        } catch (JSONException e) {
            continue;
        }
    }

    // Send the alert to Pebble

    sendToPebble(title, notificationText);

    if (Constants.IS_LOGGABLE) {
        Log.i(Constants.LOG_TAG, event.toString());
        Log.i(Constants.LOG_TAG, event.getPackageName().toString());
    }
}

From source file:org.matrix.console.activity.HomeActivity.java

@SuppressLint("NewApi")
private boolean isScreenOn() {
    PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE);

    if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) {
        return powerManager.isInteractive();
    } else {//from  ww w  .  j  av a 2 s . c o m
        return powerManager.isScreenOn();
    }
}

From source file:org.computeforcancer.android.client.Monitor.java

@Override
public void onCreate() {

    Log.d(Logging.TAG, "Monitor onCreate()");

    // populate attributes with XML resource values
    boincWorkingDir = getString(R.string.client_path);
    fileNameClient = getString(R.string.client_name);
    fileNameCLI = getString(R.string.client_cli);
    fileNameCABundle = getString(R.string.client_cabundle);
    fileNameClientConfig = getString(R.string.client_config);
    fileNameGuiAuthentication = getString(R.string.auth_file_name);
    fileNameAllProjectsList = getString(R.string.all_projects_list);
    clientStatusInterval = getResources().getInteger(R.integer.status_update_interval_ms);
    deviceStatusIntervalScreenOff = getResources()
            .getInteger(R.integer.device_status_update_screen_off_every_X_loop);
    clientSocketAddress = getString(R.string.client_socket_address);

    // initialize singleton helper classes and provide application context
    clientStatus = new ClientStatus(this);
    getAppPrefs().readPrefs(this);
    deviceStatus = new DeviceStatus(this, getAppPrefs());
    if (Logging.ERROR)
        Log.d(Logging.TAG, "Monitor onCreate(): singletons initialized");

    // set current screen on/off status
    PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
    screenOn = pm.isScreenOn();

    // initialize DeviceStatus wrapper
    deviceStatus = new DeviceStatus(getApplicationContext(), getAppPrefs());

    // register screen on/off receiver
    IntentFilter onFilter = new IntentFilter(Intent.ACTION_SCREEN_ON);
    IntentFilter offFilter = new IntentFilter(Intent.ACTION_SCREEN_OFF);
    registerReceiver(screenOnOffReceiver, onFilter);
    registerReceiver(screenOnOffReceiver, offFilter);
}