Example usage for android.os PowerManager SCREEN_BRIGHT_WAKE_LOCK

List of usage examples for android.os PowerManager SCREEN_BRIGHT_WAKE_LOCK

Introduction

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

Prototype

int SCREEN_BRIGHT_WAKE_LOCK

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

Click Source Link

Document

Wake lock level: Ensures that the screen is on at full brightness; the keyboard backlight will be allowed to go off.

Usage

From source file:Main.java

/**
 * Wake ups the phone./*from  ww  w  . ja v a 2 s  .  co m*/
 * @param context
 */
public static void partialWakeUpLock(Context context) {
    PowerManager pm = (PowerManager) context.getApplicationContext().getSystemService(Context.POWER_SERVICE);
    PowerManager.WakeLock wakeLock = pm.newWakeLock((PowerManager.SCREEN_BRIGHT_WAKE_LOCK
            | PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP), "TAG");
    wakeLock.acquire();
}

From source file:org.deviceconnect.android.deviceplugin.wear.activity.WearTouchProfileActivity.java

@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE);
    mWakeLock = powerManager.newWakeLock((PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.FULL_WAKE_LOCK
            | PowerManager.ACQUIRE_CAUSES_WAKEUP), "TouchWakelockTag");

    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    if (!mWakeLock.isHeld()) {
        mWakeLock.acquire();/*from w  w w .ja  v a 2  s. c  o  m*/
    }

    // Get intent data.
    setRegisterEvent(getIntent());
    setContentView(R.layout.activity_wear_touch_profile);
    mGestureDetector = new GestureDetector(this, mSimpleOnGestureListener);

    // For service destruction suppression.
    Intent i = new Intent(WearConst.ACTION_WEAR_PING_SERVICE);
    LocalBroadcastManager.getInstance(this).sendBroadcast(i);
}

From source file:uk.co.workingedge.phonegap.plugin.PowerManagement.java

@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {

    Log.d(LOG_TAG, "Plugin execute called - " + this.toString());
    Log.d(LOG_TAG, "Action is " + action);

    try {//from w  w  w  .j a v  a 2  s  .  c  om
        if (action.equals("acquire")) {
            String type = args.optString(0);
            if (type.equals("dim")) {
                Log.d(LOG_TAG, "Type: dim wakelock");
                this.acquire(PowerManager.SCREEN_DIM_WAKE_LOCK);
            } else if (type.equals("bright")) {
                Log.d(LOG_TAG, "Type: bright wakelock");
                this.acquire(PowerManager.SCREEN_BRIGHT_WAKE_LOCK);
            } else if (type.equals("partial")) {
                Log.d(LOG_TAG, "Type: partial wakelock");
                this.acquire(PowerManager.PARTIAL_WAKE_LOCK);
            } else {
                Log.d(LOG_TAG, "Type: full wakelock");
                this.acquire(PowerManager.FULL_WAKE_LOCK);
            }
        } else if (action.equals("release")) {
            this.release();
        }
    } catch (Exception e) {
        return false;
    }

    callbackContext.success();
    return true;
}

From source file:org.deviceconnect.android.deviceplugin.wear.activity.WearKeyEventProfileActivity.java

@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE);
    mWakeLock = powerManager.newWakeLock((PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.FULL_WAKE_LOCK
            | PowerManager.ACQUIRE_CAUSES_WAKEUP), "TouchWakelockTag");

    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    if (!mWakeLock.isHeld()) {
        mWakeLock.acquire();// w  w w .ja  va 2 s.com
    }
    setRegisterEvent(getIntent());
    setContentView(R.layout.activity_wear_keyevent_profile);

    WatchViewStub stub = (WatchViewStub) findViewById(R.id.watch_view_stub);
    stub.setOnLayoutInflatedListener(new WatchViewStub.OnLayoutInflatedListener() {
        @Override
        public void onLayoutInflated(final WatchViewStub stub) {
            mBtnKeyMode = (Button) stub.findViewById(R.id.button_key_mode);
            mBtnKeyMode.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(final View v) {
                    // Update Key Mode.
                    mKeyMode++;
                    if (mKeyMode >= KM_MAX_CNT) {
                        mKeyMode = KM_STD_KEY;
                    }

                    String keyMode;
                    switch (mKeyMode) {
                    case KM_MEDIA_CTRL:
                        keyMode = getString(R.string.key_mode_media_ctrl);
                        break;
                    case KM_DPAD_BUTTON:
                        keyMode = getString(R.string.key_mode_dpad_button);
                        break;
                    case KM_USER:
                        keyMode = getString(R.string.key_mode_user);
                        break;
                    case KM_STD_KEY:
                    default:
                        keyMode = getString(R.string.key_mode_std_key);
                        break;
                    }
                    mBtnKeyMode.setText(keyMode);
                }
            });

            mBtnCancel = (Button) stub.findViewById(R.id.button_cancel);
            mBtnCancel.setOnTouchListener(new View.OnTouchListener() {
                @Override
                public boolean onTouch(final View view, final MotionEvent event) {
                    int action = event.getAction();
                    switch (action) {
                    case MotionEvent.ACTION_DOWN:
                    case MotionEvent.ACTION_UP:
                        sendMessageData(action, KEYCODE_CANCEL);
                        break;
                    default:
                        break;
                    }
                    return false;
                }
            });

            mBtnOk = (Button) stub.findViewById(R.id.button_ok);
            mBtnOk.setOnTouchListener(new View.OnTouchListener() {
                @Override
                public boolean onTouch(final View view, final MotionEvent event) {
                    int action = event.getAction();
                    switch (action) {
                    case MotionEvent.ACTION_DOWN:
                    case MotionEvent.ACTION_UP:
                        sendMessageData(action, KEYCODE_OK);
                        break;
                    default:
                        break;
                    }
                    return false;
                }
            });

        }
    });

    Intent i = new Intent(WearConst.ACTION_WEAR_PING_SERVICE);
    LocalBroadcastManager.getInstance(this).sendBroadcast(i);
}

From source file:org.ligi.android.dubwise_mk.BaseActivity.java

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

    DUBwisePrefs.init(this);

    if (DUBwisePrefs.keepLightNow()) {
        if (mWakeLock == null) {
            final PowerManager pm = (PowerManager) (getSystemService(Context.POWER_SERVICE));
            mWakeLock = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, "DUBwise");
        }//from   w ww  . j av a  2 s.  c  o  m
        mWakeLock.acquire();
    }

    // do only once
    if (!did_init) {
        //BluetoothMaster.init(activity);
        VoicePrefs.init(this);
        StatusVoice.getInstance().init(this);
        BlackBoxPrefs.init(this);

        // start the default connection
        StartupConnectionService.start(this);

        if (BlackBoxPrefs.isBlackBoxEnabled()) {
            DUBwiseBackgroundHandler.getInstance().addAndStartTask(BlackBox.getInstance());
        }

        did_init = true;
    }

    if (VoicePrefs.isVoiceEnabled() && !DUBwiseBackgroundHandler.getInstance().getBackgroundTasks()
            .contains(StatusVoice.getInstance())) {
        DUBwiseBackgroundHandler.getInstance().addAndStartTask(StatusVoice.getInstance());
    }

    setContentView(R.layout.base_layout);
    contentView = (ViewGroup) findViewById(R.id.content_frame);

    drawerList = (ListView) findViewById(R.id.left_drawer);

    drawerList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            IconicMenuItem item = ((IconicMenuItem) (drawerList.getAdapter().getItem(position)));

            if (item.intent != null) {
                startActivity(item.intent);
            }

        }
    });
    refresh_list();

    //mTitle = mDrawerTitle = getTitle();
    drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    drawerToggle = new ActionBarDrawerToggle(this, drawerLayout, R.drawable.ic_drawer, R.string.drawer_open,
            R.string.drawer_close) {

        /** Called when a drawer has settled in a completely closed state. */
        public void onDrawerClosed(View view) {
            //getActionBar().setTitle(mTitle);
            invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
        }

        /** Called when a drawer has settled in a completely open state. */
        public void onDrawerOpened(View drawerView) {
            //getActionBar().setTitle(mDrawerTitle);
            invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
        }
    };

    drawerLayout.setDrawerListener(drawerToggle);

    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setHomeButtonEnabled(true);

    // a little hack because I strongly disagree with the style guide here
    // ;-)
    // not having the Actionbar overfow menu also with devices with hardware
    // key really helps discoverability
    // http://stackoverflow.com/questions/9286822/how-to-force-use-of-overflow-menu-on-devices-with-menu-button
    try {
        ViewConfiguration config = ViewConfiguration.get(this);
        Field menuKeyField = ViewConfiguration.class.getDeclaredField("sHasPermanentMenuKey");
        if (menuKeyField != null) {
            menuKeyField.setAccessible(true);
            menuKeyField.setBoolean(config, false);
        }
    } catch (Exception ex) {
        // Ignore - but at least we tried ;-)
    }

}

From source file:fr.bmartel.android.iotf.app.BaseActivity.java

protected void onCreate(Bundle savedInstance) {
    super.onCreate(savedInstance);

    sharedpreferences = getSharedPreferences(StorageConst.STORAGE_PROFILE, Context.MODE_PRIVATE);

    notifyMgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

    try {/*from w w  w .j a  va2  s .  c o  m*/
        Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
        ringtone = RingtoneManager.getRingtone(getApplicationContext(), notification);

    } catch (Exception e) {
        e.printStackTrace();
        ringtone = null;
    }

    screenLock = ((PowerManager) getSystemService(POWER_SERVICE))
            .newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "TAG");
}

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 ww  w.j a va  2 s  .c o m*/
                    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.google.android.marvin.mytalkback.ProcessorVolumeStream.java

@SuppressWarnings("deprecation")
public ProcessorVolumeStream(TalkBackService service) {
    mContext = service;/* ww  w.j  ava 2  s  . c o  m*/
    mAudioManager = (AudioManager) service.getSystemService(Context.AUDIO_SERVICE);
    mCursorController = service.getCursorController();
    mLongPressHandler = new LongPressHandler(this);

    final PowerManager pm = (PowerManager) service.getSystemService(Context.POWER_SERVICE);
    mWakeLock = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE, WL_TAG);
}

From source file:com.smart.taxi.GcmIntentService.java

@Override
protected void onHandleIntent(Intent intent) {
    Bundle extras = intent.getExtras();//from  w w w .j  av  a 2  s.c  o m
    GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this);
    // The getMessageType() intent parameter must be the intent you received
    // in your BroadcastReceiver.
    String messageType = gcm.getMessageType(intent);

    if (!extras.isEmpty()) { // has effect of unparcelling Bundle
        String msg = extras.toString();
        /*
         * Filter messages based on message type. Since it is likely that GCM
         * will be extended in the future with new message types, just ignore
         * any message types you're not interested in, or that you don't
         * recognize.
         */
        if (GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR.equals(messageType)) {
            sendNotification("Send error: " + extras.toString());
        } else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)) {
            sendNotification("Deleted messages on server: " + extras.toString());
            // If it's a regular GCM message, do some work.
        } else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) {
            // This loop represents the service doing some work.
            /*for (int i=0; i<0; i++) {
            Log.i(TAG, "Working... " + (i+1)
                    + "/5 @ " + SystemClock.elapsedRealtime());
            try {
                Thread.sleep(500);
            } catch (InterruptedException e) {
            }
            }*/
            Log.i(TAG, "Completed work @ " + SystemClock.elapsedRealtime());
            // Post notification of received message.
            sendNotification(extras);
            try {

                PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
                PowerManager.WakeLock wl = pm.newWakeLock(
                        PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.SCREEN_BRIGHT_WAKE_LOCK, "My Tag");
                wl.acquire();
                wl.release();

            } catch (Exception ex) {
                Log.e("Wake lock acquire error:", ex.toString());
            }
            // Log.i(TAG, "Received: " + extras.toString());

        }
    }
    // Release the wake lock provided by the WakefulBroadcastReceiver.
    GcmBroadcastReceiver.completeWakefulIntent(intent);
}

From source file:org.madebcn.android.compass.CompassActivity.java

/** Called when the activity is first created. */
@Override//from w  ww  .j  ava  2 s  . c  om
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
    StrictMode.setThreadPolicy(policy);

    // Get an instance of the SensorManager
    mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);

    // Get an instance of the PowerManager
    mPowerManager = (PowerManager) getSystemService(POWER_SERVICE);

    // Get an instance of the WindowManager

    // Create a bright wake lock
    mWakeLock = mPowerManager.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, getClass().getName());

    // instantiate our simulation view and set it as the activity's content
    mSimulationView = new SimulationView(this);
    setContentView(R.layout.main);

    angleField = (TextView) findViewById(R.id.textView2);
    serverField = (EditText) findViewById(R.id.editText1); //editText1
    switchButton = (Switch) findViewById(R.id.switch1); //Switch1
    setangleButton = (Button) findViewById(R.id.button2);//button2
    statusField = (TextView) findViewById(R.id.textView3); //textview3

}