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.cellbots.eyes.EyesActivity.java

/** Called when the activity is first created. */
@Override/*from  w w w  .j a v a  2  s  . c  o m*/
public void onCreate(Bundle savedInstanceState) {
    Log.e("remote eyes", "started");
    super.onCreate(savedInstanceState);

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

    mTorchMode = false;

    out = new ByteArrayOutputStream();

    if ((getIntent() != null) && (getIntent().getData() != null)) {
        putUrl = getIntent().getData().toString();
        server = putUrl.replace("http://", "");
        server = server.substring(0, server.indexOf("/"));
        Bundle extras = getIntent().getExtras();
        if ((extras != null) && (extras.getBoolean("TORCH", false))) {
            mTorchMode = true;
        }
    } else {
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
        putUrl = prefs.getString("REMOTE_EYES_PUT_URL", "");
        Log.e("prefs", putUrl);
        if (putUrl.length() < 1) {
            Intent i = new Intent();
            i.setClass(this, PrefsActivity.class);
            startActivity(i);
            finish();
            return;
        } else {
            server = putUrl.replace("http://", "");
            server = server.substring(0, server.indexOf("/"));
        }
    }

    resetConnection();
    mHttpState = new HttpState();

    setContentView(R.layout.eyes_main);
    mPreview = (SurfaceView) 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);
        }
    };

    this.registerReceiver(mReceiver, new IntentFilter(EyesActivity.EYES_COMMAND));

    mFrame = (FrameLayout) findViewById(R.id.eyes_frame);
    mWebView = new WebView(this);
    mWebView.getSettings().setJavaScriptEnabled(true);
    // Use this if you want to load content locally
    // mWebView.loadUrl("content://com.cellbot.localpersonas/default/index.html");
    mWebView.loadUrl("http://personabots.appspot.com/expressions/tuby");

    mFrame.addView(mWebView);
}

From source file:com.allthingsgeek.celljoust.MainActivity.java

/** Called when the activity is first created. */
@Override/*from  w  w  w  .ja  va2s .c  om*/
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
    PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "ServoOn");
    // wl.acquire();
    // wl.release();

    wifiManager = (WifiManager) getSystemService(WIFI_SERVICE);
    WifiInfo wifiInfo = wifiManager.getConnectionInfo();

    noise = PulseGenerator.getInstance();
    mover = Movement.getInstance();

    loadPrefs();

    mTorchMode = false;

    out = new ByteArrayOutputStream();

    setContentView(R.layout.main);

    if (sensorManager == null) {
        sensorManager = (SensorManager) this.getSystemService(Context.SENSOR_SERVICE);
    }

    startListening();

    mPreview = (SurfaceView) findViewById(R.id.preview);
    mHolder = mPreview.getHolder();
    mHolder.addCallback(this);
    mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);

    noise.pause();

}

From source file:com.cubic9.android.droidglove.Main.java

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

    // prevent sleep
    PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
    mWakeLock = powerManager.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "DroidGlove");

    // vibrator//from ww  w  .  j av  a2 s .  c  o  m
    mVibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE);

    // sensor
    mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);

    // show error dialog if Wi-Fi off and Tethering off.
    WifiManager wifi = (WifiManager) getSystemService(WIFI_SERVICE);
    if ((!wifi.isWifiEnabled()) && (!isTethering(wifi))) {
        new AlertDialog.Builder(Main.this).setIcon(android.R.drawable.ic_dialog_alert)
                .setTitle(getString(R.string.dialog_error_title))
                .setMessage(getString(R.string.dialog_error_wifi_off))
                .setPositiveButton(R.string.dialog_error_ok, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        appEnd();
                    }
                }).create().show();
    }

    // get IP address
    getPreferences();

    // check IP address
    if (ip.equals("")) {
        showToast(R.string.toast_error_ip_null);
        Intent intent = new Intent(this, Settings.class);
        startActivityForResult(intent, 0);
    } else if (!ip.matches("^([0-9]{1,3}\\.){3}[0-9]{1,3}$")) {
        showToast(R.string.toast_error_ip_wrong);
        Intent intent = new Intent(this, Settings.class);
        startActivityForResult(intent, 0);
    }

    // init angle
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < AVERAGE_AMOUNT; j++) {
            mOrigAngles[i][j] = 0;
        }
    }

    // show screen
    setContentView(R.layout.main);

    // find views
    mTextViewMessage = (TextView) findViewById(R.id.textViewMessage);
    mTextViewIp = (TextView) findViewById(R.id.textViewIp);
    /*
     * textViewX = (TextView) findViewById(R.id.textViewX); textViewY =
     * (TextView) findViewById(R.id.textViewY); textViewZ = (TextView)
     * findViewById(R.id.textViewZ); textViewGrip = (TextView)
     * findViewById(R.id.textViewGrip);
     */
    Button button = (Button) findViewById(R.id.buttonReset);
    button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mInitirizedSensor = false;
            mTextViewMessage.setText(R.string.message_swipe_down);
        }
    });
}

From source file:butter.droid.base.torrent.TorrentService.java

public void streamTorrent(@NonNull final String torrentUrl) {
    Timber.d("streamTorrent");
    mStopped = false;// ww  w .j  av  a2s .  c  o  m

    if (mTorrentStream.isStreaming())
        return;

    Timber.d("Starting streaming");

    PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
    if (mWakeLock != null && mWakeLock.isHeld()) {
        mWakeLock.release();
        mWakeLock = null;
    }
    mWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, WAKE_LOCK);
    mWakeLock.acquire();

    TorrentOptions options = mTorrentStream.getOptions();
    options.setRemoveFilesAfterStop(true);
    options.setMaxConnections(PrefUtils.get(this, Prefs.LIBTORRENT_CONNECTION_LIMIT, 200));
    options.setMaxDownloadSpeed(PrefUtils.get(this, Prefs.LIBTORRENT_DOWNLOAD_LIMIT, 0));
    options.setMaxUploadSpeed(PrefUtils.get(this, Prefs.LIBTORRENT_UPLOAD_LIMIT, 0));
    options.setSaveLocation(PrefUtils.get(this, Prefs.STORAGE_LOCATION, ButterApplication.getStreamDir()));
    mTorrentStream.setOptions(options);

    mIsReady = false;
    mTorrentStream.addListener(this);
    mTorrentStream.startStream(torrentUrl);
}

From source file:com.putlocker.upload.DownloadService.java

@Override
protected void onHandleIntent(Intent intent) {
    PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
    PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "Download Wakelock");
    wl.acquire();/*from  w  w  w. j  a v  a2 s . c  o  m*/

    ConnectivityManager connManager = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
    NetworkInfo mWifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    WifiLock wifiLock = null;
    // We only want to aquire the wifi wake lock
    if (mWifi.isConnected()) {
        wifiLock = ((WifiManager) this.getSystemService(Context.WIFI_SERVICE))
                .createWifiLock(WifiManager.WIFI_MODE_SCAN_ONLY, "WlanSilencerScanLock");
        wifiLock.acquire();
    }

    if (intent.hasExtra(JOB_EXTRA_DOWNLOAD)) {
        handleDownloadIntent(intent);
    } else {
        handleUploadIntent(intent);
    }

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

    wl.release();
}

From source file:com.google.android.apps.watchme.StreamerActivity.java

private void startStreaming() {
    Log.d(MainActivity.APP_NAME, "startStreaming");

    PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
    wakeLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, this.getClass().getName());
    wakeLock.acquire();//from w  w w  .  j  av a 2  s .c o  m

    if (!streamerService.isStreaming()) {

        String cameraPermission = Manifest.permission.CAMERA;
        String microphonePermission = Manifest.permission.RECORD_AUDIO;
        int hasCamPermission = checkSelfPermission(cameraPermission);
        int hasMicPermission = checkSelfPermission(microphonePermission);
        List<String> permissions = new ArrayList<String>();
        if (hasCamPermission != PackageManager.PERMISSION_GRANTED) {
            permissions.add(cameraPermission);
            if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.CAMERA)) {
                // Provide rationale in Snackbar to request permission
                //                    Snackbar.make(preview, R.string.permission_camera_rationale,
                //                            Snackbar.LENGTH_INDEFINITE).show();
            } else {
                // Explain in Snackbar to turn on permission in settings
                //                    Snackbar.make(preview, R.string.permission_camera_explain,
                //                            Snackbar.LENGTH_INDEFINITE).show();
            }
        }
        if (hasMicPermission != PackageManager.PERMISSION_GRANTED) {
            permissions.add(microphonePermission);
            if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.RECORD_AUDIO)) {
                // Provide rationale in Snackbar to request permission
                //                    Snackbar.make(preview, R.string.permission_microphone_rationale,
                //                            Snackbar.LENGTH_INDEFINITE).show();
            } else {
                // Explain in Snackbar to turn on permission in settings
                //                    Snackbar.make(preview, R.string.permission_microphone_explain,
                //                            Snackbar.LENGTH_INDEFINITE).show();
            }
        }
        if (!permissions.isEmpty()) {
            String[] params = permissions.toArray(new String[permissions.size()]);
            ActivityCompat.requestPermissions(this, params, REQUEST_CAMERA_MICROPHONE);
        } else {
            // We already have permission, so handle as normal
            streamerService.startStreaming(rtmpUrl);
        }
    }
}

From source file:com.mishiranu.dashchan.content.service.PostingService.java

@Override
public void onCreate() {
    super.onCreate();
    notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE);
    wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "PostingWakeLock");
    wakeLock.setReferenceCounted(false);
    notificationsWorker = new Thread(this, "PostingServiceNotificationThread");
    notificationsWorker.start();//from ww w .j  a v  a  2 s . co m
}

From source file:com.ichi2.async.Connection.java

public Connection() {
    sIsCancelled = false;/* w  w  w.ja  v  a 2  s .co m*/
    sIsCancellable = false;
    Context context = AnkiDroidApp.getInstance().getApplicationContext();
    PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
    mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "Connection");
}

From source file:de.qspool.clementineremote.backend.ClementinePlayerConnection.java

public void run() {
    // Start the thread
    mNotificationManager = (NotificationManager) App.mApp.getSystemService(Context.NOTIFICATION_SERVICE);

    Looper.prepare();//  w  w  w  . ja  v  a  2s  . c  o  m
    mHandler = new ClementineConnectionHandler(this);

    mPebble = new Pebble();

    // Get a Wakelock Object
    PowerManager pm = (PowerManager) App.mApp.getSystemService(Context.POWER_SERVICE);
    mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "Clementine");

    Resources res = App.mApp.getResources();
    mNotificationHeight = (int) res.getDimension(android.R.dimen.notification_large_icon_height);
    mNotificationWidth = (int) res.getDimension(android.R.dimen.notification_large_icon_width);

    mAudioManager = (AudioManager) App.mApp.getSystemService(Context.AUDIO_SERVICE);
    mClementineMediaButtonEventReceiver = new ComponentName(App.mApp.getPackageName(),
            ClementineMediaButtonEventReceiver.class.getName());

    mMediaButtonBroadcastReceiver = new ClementineMediaButtonEventReceiver();

    fireOnConnectionReady();

    Looper.loop();
}

From source file:net.exclaimindustries.geohashdroid.services.WikiService.java

@Override
public void onCreate() {
    super.onCreate();

    // WakeLock awaaaaaay!
    PowerManager pm = (PowerManager) getSystemService(POWER_SERVICE);
    mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "WikiService");

    // Also, get the NotificationManager on standby.
    mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
}