Example usage for android.os PowerManager ON_AFTER_RELEASE

List of usage examples for android.os PowerManager ON_AFTER_RELEASE

Introduction

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

Prototype

int ON_AFTER_RELEASE

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

Click Source Link

Document

Wake lock flag: When this wake lock is released, poke the user activity timer so the screen stays on for a little longer.

Usage

From source file:org.interactiverobotics.headset_launcher.LauncherService.java

/**
 *    ?.//  ww w .  j  av a2s .c  om
 *
 */
@SuppressWarnings("deprecation")
private void unlockScreen() {

    final KeyguardManager keyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);

    mKeyguardLock = keyguardManager.newKeyguardLock("HeadsetLauncherLock");

    mKeyguardLock.disableKeyguard();

    final PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);

    mWakeLock = powerManager.newWakeLock(
            PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE,
            "HeadsetLauncherWakeLock");

    mWakeLock.acquire();

    // ?  ?  ?

    mTimeoutHandler.postDelayed(mTimeoutRunnable, Constants.NOTIFICATION_TIMEOUT * 1000);
}

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

@SuppressWarnings("deprecation")
@Override/*from  w w w  .  j a  v a  2  s. c  o  m*/
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    //handler.setActivityInstance(this);
    Log.i(TAG, "######## onCreate");
    getWindow().requestFeature(Window.FEATURE_NO_TITLE);
    this.setFinishOnTouchOutside(false);
    setContentView(R.layout.call_dialog);

    targetName = getIntent().getStringExtra(SipManager.CALLEE_NAME_INTENT_KEY);
    if (targetName != null) {
        Log.i(TAG, "targetName: " + targetName);
    }

    SipCallSession initialSession = getIntent().getParcelableExtra(SipManager.EXTRA_CALL_INFO);
    synchronized (callMutex) {
        callsInfo = new SipCallSession[1];
        callsInfo[0] = initialSession;
    }

    bindService(new Intent(this, SipService.class), connection, Context.BIND_AUTO_CREATE);
    prefsWrapper = new PreferencesProviderWrapper(this);

    // Log.d(TAG, "Creating call handler for " +
    // callInfo.getCallId()+" state "+callInfo.getRemoteContact());
    powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
    wakeLock = powerManager.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK
            | PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE,
            "com.csipsimple.onIncomingCall");
    wakeLock.setReferenceCounted(false);

    takeKeyEvents(true);

    // Cache findViews
    mainFrame = (ViewGroup) findViewById(R.id.mainFrame);
    //inCallControls = (InCallControls) findViewById(R.id.inCallControls);
    inCallAnswerControls = (InCallAnswerControls) findViewById(R.id.inCallAnswerControls);
    activeCallsGrid = (InCallInfoGrid) findViewById(R.id.activeCallsGrid);
    heldCallsGrid = (InCallInfoGrid) findViewById(R.id.heldCallsGrid);

    // Bind
    attachVideoPreview();

    //inCallControls.setOnTriggerListener(this);
    inCallAnswerControls.setOnTriggerListener(this);

    if (activeCallsAdapter == null) {
        activeCallsAdapter = new CallsAdapter(true);
    }
    activeCallsGrid.setAdapter(activeCallsAdapter);

    if (heldCallsAdapter == null) {
        heldCallsAdapter = new CallsAdapter(false);
    }
    heldCallsGrid.setAdapter(heldCallsAdapter);

    ScreenLocker lockOverlay = (ScreenLocker) findViewById(R.id.lockerOverlay);
    lockOverlay.setActivity(this);
    lockOverlay.setOnLeftRightListener(this);

    /*
    middleAddCall = (Button) findViewById(R.id.add_call_button);
    middleAddCall.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View arg0) {
        onTrigger(ADD_CALL, null);
    }
    });
    if (!prefsWrapper.getPreferenceBooleanValue(SipConfigManager.SUPPORT_MULTIPLE_CALLS)) {
    middleAddCall.setEnabled(false);
    middleAddCall.setText(R.string.not_configured_multiple_calls);
    }
    */

    // Listen to media & sip events to update the UI
    registerReceiver(callStateReceiver, new IntentFilter(SipManager.ACTION_SIP_CALL_CHANGED));
    registerReceiver(callStateReceiver, new IntentFilter(SipManager.ACTION_SIP_MEDIA_CHANGED));
    registerReceiver(callStateReceiver, new IntentFilter(SipManager.ACTION_ZRTP_SHOW_SAS));

    proximityManager = new CallProximityManager(this, this, lockOverlay);
    keyguardManager = KeyguardWrapper.getKeyguardManager(this);

    dialFeedback = new DialingFeedback(this, true);

    if (prefsWrapper.getPreferenceBooleanValue(SipConfigManager.PREVENT_SCREEN_ROTATION)) {
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    }

    if (quitTimer == null) {
        quitTimer = new Timer("Quit-timer");
    }

    useAutoDetectSpeaker = prefsWrapper.getPreferenceBooleanValue(SipConfigManager.AUTO_DETECT_SPEAKER);

    applyTheme();
    proximityManager.startTracking();

    //inCallControls.setCallState(initialSession);
    inCallAnswerControls.setCallState(initialSession);
}

From source file:com.nanostuffs.yurdriver.GCMIntentService.java

/**
 * Issues a notification to inform the user that server has sent a message.
 *///from  w  ww .j  av  a  2 s . co m
private void generateNotification(Context context, String message) {
    int icon = R.drawable.ic_launcher;
    long when = System.currentTimeMillis();
    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    Notification notification = new Notification(icon, message, when);
    String title = context.getString(R.string.app_name);
    Intent notificationIntent = new Intent(context, MapActivity.class);
    notificationIntent.putExtra("fromNotification", "notification");
    // set intent so it does not start a new activity
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    notification.setLatestEventInfo(context, title, message, intent);
    notification.flags |= Notification.FLAG_AUTO_CANCEL;
    System.out.println("notification====>" + message);
    notification.defaults |= Notification.DEFAULT_SOUND;
    notification.defaults |= Notification.DEFAULT_VIBRATE;
    // notification.defaults |= Notification.DEFAULT_LIGHTS;
    notification.flags |= Notification.FLAG_SHOW_LIGHTS;
    notification.ledARGB = 0x00000000;
    notification.ledOnMS = 0;
    notification.ledOffMS = 0;
    notificationManager.notify(AndyConstants.NOTIFICATION_ID, notification);
    PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
    PowerManager.WakeLock wakeLock = pm.newWakeLock(
            PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE,
            "WakeLock");
    wakeLock.acquire();
    wakeLock.release();

}

From source file:org.akvo.caddisfly.sensor.colorimetry.liquid.ColorimetryLiquidActivity.java

/**
 * Acquire a wake lock to prevent the screen from turning off during the analysis process.
 *//*from ww w  . j a v a 2  s  .  co  m*/
private void acquireWakeLock() {
    if (wakeLock == null || !wakeLock.isHeld()) {
        PowerManager pm = (PowerManager) getApplicationContext().getSystemService(Context.POWER_SERVICE);
        //noinspection deprecation
        wakeLock = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP
                | PowerManager.ON_AFTER_RELEASE, "CameraSensorWakeLock");
        wakeLock.acquire();
    }
}

From source file:cm.aptoide.pt.services.ServiceDownloadManager.java

@Override
public void onCreate() {
    if (!isRunning) {
        PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
        keepScreenOn = powerManager//  ww  w  .j a v  a2  s .com
                .newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE, "Full Power");

        ongoingDownloads = new HashMap<Integer, ViewDownloadManagement>();
        completedDownloads = new HashMap<Integer, ViewDownloadManagement>();
        failedDownloads = new HashMap<Integer, ViewDownloadManagement>();

        globaDownloadStatus = new ViewDownload("local:\\GLOBAL");

        cachedThreadPool = Executors.newCachedThreadPool();

        helperDownload = new HelperDownload(this);
        isRunning = true;
    }
    super.onCreate();
}

From source file:com.xunlei.shortvideo.activity.VideoPublishLocal3Activity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    super.onCreate(savedInstanceState);
    //        if (TextUtils.isEmpty(mVideoPath) || !checkExistLocalFile(mVideoPath)) {
    //            Toast.makeText(this, R.string.file_not_exist, Toast.LENGTH_SHORT).show();
    //            finish();
    //        }/*from  w w w.  j  a  v a 2 s.  c om*/
    mManager = VideoUploadManager.getInstance(this);
    VideoWorkSpaceManager manager = VideoWorkSpaceManager.getInstance(this);
    mConfig = manager.getConfig("", VideoWorkSpaceManager.VideoType.local);
    mConfig.setUploadType(VideoWorkSpaceConfig.WORK_SPACE_MISC_UPLOADTYPE_SELF);
    mUserId = UserContext.getInstance(this).getLoginUid();
    mWakeLock = ((PowerManager) getSystemService(POWER_SERVICE))
            .newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE, TAG);
    //add qupai.
    initQupaiEditor();
}

From source file:at.alladin.rmbt.android.test.RMBTLoopService.java

@Override
public void onCreate() {
    Log.d(TAG, "created");
    super.onCreate();

    partialWakeLock = ((PowerManager) getApplicationContext().getSystemService(Context.POWER_SERVICE))
            .newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "RMBTLoopWakeLock");
    partialWakeLock.acquire();/*from  w  w w .ja  v a2s  . c  o  m*/

    alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
    notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

    readConfig();

    geoLocation = new LocalGeoLocation(this);
    geoLocation.start();

    notificationBuilder = createNotificationBuilder();

    startForeground(NotificationIDs.LOOP_ACTIVE, notificationBuilder.build());
    final IntentFilter actionFilter = new IntentFilter(RMBTService.BROADCAST_TEST_FINISHED);
    actionFilter.addAction(RMBTService.BROADCAST_TEST_ABORTED);
    registerReceiver(receiver, actionFilter);

    final IntentFilter rmbtTaskActionFilter = new IntentFilter(RMBTTask.BROADCAST_TEST_START);
    registerReceiver(rmbtTaskReceiver, rmbtTaskActionFilter);

    final Intent alarmIntent = new Intent(ACTION_ALARM, null, this, getClass());
    alarm = PendingIntent.getService(this, 0, alarmIntent, 0);

    if (ConfigHelper.isLoopModeWakeLock(this)) {
        Log.d(TAG, "using dimWakeLock");
        dimWakeLock = ((PowerManager) getApplicationContext().getSystemService(Context.POWER_SERVICE))
                .newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP
                        | PowerManager.ON_AFTER_RELEASE, "RMBTLoopDimWakeLock");
        dimWakeLock.acquire();

        final Intent wakeupAlarmIntent = new Intent(ACTION_WAKEUP_ALARM, null, this, getClass());
        wakeupAlarm = PendingIntent.getService(this, 0, wakeupAlarmIntent, 0);

        final long now = SystemClock.elapsedRealtime();
        alarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, now + 10000, 10000, wakeupAlarm);
    }

    bindService(new Intent(getApplicationContext(), RMBTService.class), this, BIND_AUTO_CREATE);
}

From source file:com.nbplus.vbroadlauncher.service.BroadcastChatHeadService.java

public void acquireCpuWakeLock() {
    Log.e(TAG, "Acquiring cpu wake lock");
    if (mCpuWakeLock != null) {
        return;//  w w  w. j a  v  a2 s .c  om
    }

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

    mCpuWakeLock = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP
            | PowerManager.ON_AFTER_RELEASE, "I'm your father");
    mCpuWakeLock.acquire();
}

From source file:com.oo58.game.texaspoker.AppActivity.java

@Override
public void onResume() {
    super.onResume();
    PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
    //mWakeLock = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK,
    //      "<span><span class='string'>MyLock</span></span>");
    mWakeLock = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE, "ATAAW");
    mWakeLock.acquire();/* w w w.  j a  v a 2 s.co m*/

    MobclickAgent.onResume(this);

    XGPushClickedResult click = XGPushManager.onActivityStarted(this);
    Log.d("TPush", "onResumeXGPushClickedResult:" + click);
    if (click != null) { // 
        //         Toast.makeText(this, ":" + click.toString(),
        //               Toast.LENGTH_SHORT).show();
    }
}

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);//from   w  ww .j a va2 s.  co  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();
                    }
                }
            });

        }
    });
}