Example usage for android.os PowerManager ACQUIRE_CAUSES_WAKEUP

List of usage examples for android.os PowerManager ACQUIRE_CAUSES_WAKEUP

Introduction

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

Prototype

int ACQUIRE_CAUSES_WAKEUP

To view the source code for android.os PowerManager ACQUIRE_CAUSES_WAKEUP.

Click Source Link

Document

Wake lock flag: Turn the screen on when the wake lock is acquired.

Usage

From source file:com.ternup.caddisfly.fragment.ResultFragment.java

public void postResult(final String url) {

    RequestParams params = new RequestParams();
    TimeZone tz = TimeZone.getTimeZone("UTC");
    final DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm'Z'");
    df.setTimeZone(tz);/* w ww. j  av a2 s  .c o m*/

    final ArrayList<String> filePaths = FileUtils.getFilePaths(getActivity(), folderName, "/small/",
            mLocationId);
    File myFile = new File(filePaths.get(0));
    String date = df.format(DateUtils.getDateFromFilename(myFile.getName()));

    params.put("date", date);
    String deviceId = Build.MANUFACTURER + " " + Build.MODEL;
    if (deviceId.length() > 32) {
        deviceId = deviceId.substring(1, 32);
    }
    params.put("deviceId", deviceId);
    params.put("type", String.valueOf(mTestTypeId + 1));

    if (wakeLock == null || !wakeLock.isHeld()) {
        PowerManager pm = (PowerManager) getActivity().getApplicationContext()
                .getSystemService(Context.POWER_SERVICE);
        wakeLock = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP
                | PowerManager.ON_AFTER_RELEASE, "MyWakeLock");
        wakeLock.acquire();
    }

    WebClient.post("tests", params, new AsyncHttpResponseHandler() {
        @Override
        public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
            String response = responseBody == null ? null : new String(responseBody);
            try {
                JSONObject json = new JSONObject(response);
                final int newId = json.getInt("id");
                if (filePaths.size() > 0) {
                    count = 0;
                    totalCount = filePaths.size();
                    postItem(newId, filePaths);
                }

            } catch (JSONException e) {
                e.printStackTrace();
            }
        }

        @Override
        public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) {
            Log.d(Globals.DEBUG_TAG, "fail: " + error.getMessage());
            getActivity().runOnUiThread(new Runnable() {
                public void run() {
                    if (progressDialog != null) {
                        progressDialog.dismiss();
                    }

                    if (wakeLock != null && wakeLock.isHeld()) {
                        wakeLock.release();
                    }
                }
            });

        }
    });
}

From source file:com.csipsimple.ui.incall.CallActivity.java

@SuppressWarnings("deprecation")
private void attachVideoPreview() {
    // Video stuff
    if (prefsWrapper.getPreferenceBooleanValue(SipConfigManager.USE_VIDEO)) {
        if (cameraPreview == null) {
            Log.d(TAG, "Create Local Renderer");
            cameraPreview = ViERenderer.CreateLocalRenderer(this);
            RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(256, 256);
            //lp.leftMargin = 2;
            //lp.topMargin= 4;
            lp.addRule(RelativeLayout.ALIGN_PARENT_TOP, RelativeLayout.TRUE);
            cameraPreview.setVisibility(View.GONE);
            mainFrame.addView(cameraPreview, lp);
        } else {/*  ww  w. ja va 2  s . c o m*/
            Log.d(TAG, "NO NEED TO Create Local Renderer");
        }

        if (videoWakeLock == null) {
            videoWakeLock = powerManager.newWakeLock(
                    PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP,
                    "com.csipsimple.videoCall");
            videoWakeLock.setReferenceCounted(false);
        }
    }

    if (videoWakeLock != null && videoWakeLock.isHeld()) {
        videoWakeLock.release();
    }
}

From source file:net.czlee.debatekeeper.AlertManager.java

/**
 * Wakes up the screen to attract user attention
 *///from  w w  w.j  av a  2  s .  c  om
public void wakeUpScreenForPause() {
    int flags = PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.FULL_WAKE_LOCK
            | PowerManager.ON_AFTER_RELEASE;
    PowerManager.WakeLock temporaryWakeLock = mPowerManager.newWakeLock(flags, "Debatekeeper-pause");
    temporaryWakeLock.acquire(3000);
}

From source file:com.inloc.dr.StepService.java

private void acquireWakeLock() {
    PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
    int wakeFlags;
    if (mPedometerSettings.wakeAggressively()) {
        wakeFlags = PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP;
    } else if (mPedometerSettings.keepScreenOn()) {
        wakeFlags = PowerManager.SCREEN_DIM_WAKE_LOCK;
    } else {//from  w  ww.  ja v a  2s  .  c  o  m
        wakeFlags = PowerManager.PARTIAL_WAKE_LOCK;
    }
    wakeLock = pm.newWakeLock(wakeFlags, TAG);
    wakeLock.acquire();
}

From source file:name.setup.dance.StepService.java

private void acquireWakeLock() {
    PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
    int wakeFlags;
    if (mDanceStepAppSettings.wakeAggressively()) {
        wakeFlags = PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP;
    } else if (mDanceStepAppSettings.keepScreenOn()) {
        wakeFlags = PowerManager.SCREEN_DIM_WAKE_LOCK;
    } else {/* w ww . java2 s.c  o  m*/
        wakeFlags = PowerManager.PARTIAL_WAKE_LOCK;
    }
    wakeLock = pm.newWakeLock(wakeFlags, TAG);
    wakeLock.acquire();
}

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

public void soundAlarm() {
    mAlarm = true;/*from   w  w  w .  java2 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.ternup.caddisfly.fragment.DetailsFragment.java

public void postResult(String folderName) {

    RequestParams params = new RequestParams();
    TimeZone tz = TimeZone.getTimeZone("UTC");
    final DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm'Z'");
    df.setTimeZone(tz);/* w  ww  . ja  v a2 s  . c  o m*/

    final ArrayList<String> filePaths = FileUtils.getFilePaths(getActivity(), folderName, "/small/",
            mLocationId);
    File myFile = new File(filePaths.get(0));
    String date = df.format(DateUtils.getDateFromFilename(myFile.getName()));

    params.put("date", date);
    String deviceId = Build.MANUFACTURER + " " + Build.MODEL;
    if (deviceId.length() > 32) {
        deviceId = deviceId.substring(1, 32);
    }
    params.put("deviceId", deviceId);
    params.put("type", String.valueOf(mTestTypeId + 1));

    if (wakeLock == null || !wakeLock.isHeld()) {
        PowerManager pm = (PowerManager) getActivity().getApplicationContext()
                .getSystemService(Context.POWER_SERVICE);
        wakeLock = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP
                | PowerManager.ON_AFTER_RELEASE, "MyWakeLock");
        wakeLock.acquire();
    }

    WebClient.post("tests", params, new AsyncHttpResponseHandler() {
        @Override
        public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
            String response = responseBody == null ? null : new String(responseBody);
            try {
                JSONObject json = new JSONObject(response);
                final int newId = json.getInt("id");
                if (filePaths.size() > 0) {
                    count = 0;
                    totalCount = filePaths.size();
                    postItem(newId, filePaths);
                }

            } catch (JSONException e) {
                e.printStackTrace();
            }
        }

        @Override
        public void onFailure(int statusCode, Header[] headers, byte[] responseBody, final Throwable error) {
            Log.d(Globals.DEBUG_TAG, "fail: " + error.getMessage());

            getActivity().runOnUiThread(new Runnable() {
                public void run() {
                    if (progressDialog != null) {
                        progressDialog.dismiss();
                    }

                    if (wakeLock != null && wakeLock.isHeld()) {
                        wakeLock.release();
                    }
                    AlertUtils.showAlert(getActivity(), R.string.error, error.getMessage(), R.string.ok, null,
                            null);
                }
            });
        }
    });
}

From source file:net.czlee.debatekeeper.AlertManager.java

/**
 * Wakes up the screen to attract user attention
 *//*from ww  w  . j  av a2  s  .c  om*/
private void wakeUpScreenForBell(long wakeTime) {
    if (mActivityActive) {
        int flags = PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.FULL_WAKE_LOCK;
        PowerManager.WakeLock temporaryWakeLock = mPowerManager.newWakeLock(flags, "Debatekeeper-bell");
        temporaryWakeLock.acquire(wakeTime);
    }
}

From source file:com.saulcintero.moveon.services.MoveOnService.java

@SuppressWarnings("deprecation")
private void acquireWakeLock() {
    PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
    int wakeFlags;

    if (prefs.getString("operation_level", "run_in_background").equals("wake_up"))
        wakeFlags = PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP;
    else if (prefs.getString("operation_level", "run_in_background").equals("keep_screen_on"))
        wakeFlags = PowerManager.SCREEN_DIM_WAKE_LOCK;
    else//from   w  w  w. j a  v a2  s  .c  o m
        wakeFlags = PowerManager.PARTIAL_WAKE_LOCK;

    wakeLock = pm.newWakeLock(wakeFlags, TAG);
    wakeLock.acquire();
}

From source file:im.vector.notifications.NotificationUtils.java

/**
 * Add the notification sound./*from   www  .  ja  va 2  s. com*/
 *
 * @param context      the context
 * @param builder      the notification builder
 * @param isBackground true if the notification is a background one
 * @param isBing       true if the notification should play sound
 */
@SuppressLint("NewApi")
private static void manageNotificationSound(Context context, NotificationCompat.Builder builder,
        boolean isBackground, boolean isBing) {
    @ColorInt
    int highlightColor = ContextCompat.getColor(context, R.color.vector_fuchsia_color);
    int defaultColor = Color.TRANSPARENT;

    if (isBackground) {
        builder.setPriority(NotificationCompat.PRIORITY_DEFAULT);
        builder.setColor(defaultColor);
    } else if (isBing) {
        builder.setPriority(NotificationCompat.PRIORITY_HIGH);
        builder.setColor(highlightColor);
    } else {
        builder.setPriority(NotificationCompat.PRIORITY_DEFAULT);
        builder.setColor(Color.TRANSPARENT);
    }

    if (!isBackground) {
        builder.setDefaults(Notification.DEFAULT_LIGHTS);

        if (isBing && (null != PreferencesManager.getNotificationRingTone(context))) {
            builder.setSound(PreferencesManager.getNotificationRingTone(context));

            if (Build.VERSION.SDK_INT >= 26) {
                builder.setChannelId(NOISY_NOTIFICATION_CHANNEL_ID);
            }
        }

        // turn the screen on for 3 seconds
        if (Matrix.getInstance(VectorApp.getInstance()).getSharedGCMRegistrationManager().isScreenTurnedOn()) {
            PowerManager pm = (PowerManager) VectorApp.getInstance().getSystemService(Context.POWER_SERVICE);
            PowerManager.WakeLock wl = pm.newWakeLock(
                    PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP,
                    "manageNotificationSound");
            wl.acquire(3000);
            wl.release();
        }
    }
}