List of usage examples for android.os PowerManager SCREEN_BRIGHT_WAKE_LOCK
int SCREEN_BRIGHT_WAKE_LOCK
To view the source code for android.os PowerManager SCREEN_BRIGHT_WAKE_LOCK.
Click Source Link
From source file:ca.nehil.rter.streamingapp2.StreamingActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Orientation listenever implementation myOrientationEventListener = new OrientationEventListener(this, SensorManager.SENSOR_DELAY_NORMAL) { @Override/*from w w w . j a v a 2 s . c om*/ public void onOrientationChanged(int orientation) { int rotation = getWindowManager().getDefaultDisplay().getRotation(); if (rotation == Surface.ROTATION_270) { flipVideo = true; } else { flipVideo = false; } } }; myOrientationEventListener.enable(); // stopService(new Intent(StreamingActivity.this, // BackgroundService.class)); Log.e(TAG, "onCreate"); AndroidId = Settings.Secure.getString(getContentResolver(), Settings.Secure.ANDROID_ID); frameInfo = new FrameInfo(); // openGL overlay overlay = new OverlayController(this); // orientation mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE); mAcc = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); mMag = mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD); //setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); setContentView(R.layout.activity_streaming); // Find the total number of cameras available numberOfCameras = Camera.getNumberOfCameras(); cookies = getSharedPreferences("RterUserCreds", MODE_PRIVATE); prefEditor = cookies.edit(); setUsername = cookies.getString("Username", "not-set"); setRterCredentials = cookies.getString("RterCreds", "not-set"); if (setRterCredentials.equalsIgnoreCase("not-set") || setRterCredentials == null) { Log.e("PREFS", "Login Not successful, please restart"); } Log.d("PREFS", "Prefs ==> rter_Creds:" + setRterCredentials); // Get the location manager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); // Define the criteria how to select the location provider -> use // default if (!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) { Log.e(TAG, "GPS not available"); } Criteria criteria = new Criteria(); provider = locationManager.getBestProvider(criteria, true); Log.d(TAG, "Requesting location"); locationManager.requestLocationUpdates(provider, 0, 1, this); // register the overlay control for location updates as well, so we get // the geomagnetic field locationManager.requestLocationUpdates(provider, 0, 1000, overlay); if (provider != null) { Location location = locationManager.getLastKnownLocation(provider); // Initialize the location fields if (location != null) { System.out.println("Provider " + provider + " has been selected. and location " + location); onLocationChanged(location); } else { Toast toast = Toast.makeText(this, "Location not available", Toast.LENGTH_LONG); toast.setGravity(Gravity.TOP, 0, 0); toast.show(); lati = (float) (45.505958f); longi = (float) (-73.576254f); Log.d(TAG, "Location not available"); } } // power manager PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); mWakeLock = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, CLASS_LABEL); mWakeLock.acquire(); // test, set desired orienation to north overlay.letFreeRoam(false); overlay.setDesiredOrientation(0.0f); // CharSequence text = "Tap to start.."; // int duration = Toast.LENGTH_SHORT; // // Toast toast = Toast.makeText(this, text, duration); // toast.setGravity(Gravity.TOP|Gravity.RIGHT, 0, 0); // toast.show(); }
From source file:org.petero.droidfish.DroidFish.java
/** Called when the activity is first created. */ @Override/*from ww w .j a v a 2s . c om*/ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Pair<String, String> pair = getPgnOrFenIntent(); String intentPgnOrFen = pair.first; String intentFilename = pair.second; createDirectories(); PreferenceManager.setDefaultValues(this, R.xml.preferences, false); settings = PreferenceManager.getDefaultSharedPreferences(this); settings.registerOnSharedPreferenceChangeListener(new OnSharedPreferenceChangeListener() { @Override public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { handlePrefsChange(); } }); PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); setWakeLock(false); wakeLock = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, "droidfish"); wakeLock.setReferenceCounted(false); custom1ButtonActions = new ButtonActions("custom1", CUSTOM1_BUTTON_DIALOG, R.string.select_action); custom2ButtonActions = new ButtonActions("custom2", CUSTOM2_BUTTON_DIALOG, R.string.select_action); custom3ButtonActions = new ButtonActions("custom3", CUSTOM3_BUTTON_DIALOG, R.string.select_action); figNotation = Typeface.createFromAsset(getAssets(), "fonts/DroidFishChessNotationDark.otf"); setPieceNames(PGNOptions.PT_LOCAL); requestWindowFeature(Window.FEATURE_NO_TITLE); initUI(); gameTextListener = new PgnScreenText(this, pgnOptions); if (ctrl != null) ctrl.shutdownEngine(); ctrl = new DroidChessController(this, gameTextListener, pgnOptions); egtbForceReload = true; readPrefs(); TimeControlData tcData = new TimeControlData(); tcData.setTimeControl(timeControl, movesPerSession, timeIncrement); ctrl.newGame(gameMode, tcData); setAutoMode(AutoMode.OFF); { byte[] data = null; int version = 1; if (savedInstanceState != null) { data = savedInstanceState.getByteArray("gameState"); version = savedInstanceState.getInt("gameStateVersion", version); } else { String dataStr = settings.getString("gameState", null); version = settings.getInt("gameStateVersion", version); if (dataStr != null) data = strToByteArr(dataStr); } if (data != null) ctrl.fromByteArray(data, version); } ctrl.setGuiPaused(true); ctrl.setGuiPaused(false); ctrl.startGame(); if (intentPgnOrFen != null) { try { ctrl.setFENOrPGN(intentPgnOrFen); setBoardFlip(true); } catch (ChessParseError e) { // If FEN corresponds to illegal chess position, go into edit board mode. try { TextIO.readFEN(intentPgnOrFen); } catch (ChessParseError e2) { if (e2.pos != null) startEditBoard(intentPgnOrFen); } } } else if (intentFilename != null) { if (intentFilename.toLowerCase(Locale.US).endsWith(".fen") || intentFilename.toLowerCase(Locale.US).endsWith(".epd")) loadFENFromFile(intentFilename); else loadPGNFromFile(intentFilename); } }
From source file:ca.nehil.rter.streamingapp2.StreamingActivity.java
@Override protected void onResume() { super.onResume(); if (mWakeLock == null) { PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); mWakeLock = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, CLASS_LABEL); mWakeLock.acquire();//from w w w . j a va 2s . c om } locationManager.requestLocationUpdates(provider, 0, 1, this); // register the overlay control for location updates as well, so we get // the geomagnetic field locationManager.requestLocationUpdates(provider, 0, 1000, overlay); // sensors mSensorManager.registerListener(overlay, mAcc, SensorManager.SENSOR_DELAY_NORMAL); mSensorManager.registerListener(overlay, mMag, SensorManager.SENSOR_DELAY_NORMAL); initLayout(); }
From source file:im.vector.notifications.NotificationUtils.java
/** * Add the notification sound.//from w w w .ja v a 2 s .c o m * * @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(); } } }
From source file:com.trailbehind.android.iburn.map.MapActivity.java
/** * Register receiver.//w w w .jav a 2s .c o m */ private void registerReceivers() { if (mWakeLock == null) { final PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); mWakeLock = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, TAG); } mWakeLock.acquire(); mCompassView.registerReceiver(); }
From source file:com.ucmap.dingdinghelper.services.DingDingHelperAccessibilityService.java
private void wakeAndUnlock() { //???//ww w . j ava 2 s.c om PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); //?PowerManager.WakeLock???|??Tag PowerManager.WakeLock wl = pm .newWakeLock(PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.SCREEN_BRIGHT_WAKE_LOCK, "bright"); //? wl.acquire(1000); //?? KeyguardManager km = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE); kl = km.newKeyguardLock("unLock"); //? kl.disableKeyguard(); }
From source file:com.if3games.chessonline.DroidFish.java
/** Called when the activity is first created. */ @Override/*from ww w. j a va 2 s . c om*/ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); int isGMS = getIntent().getExtras().getInt("gms"); if (isGMS != 1) { isSinglePlayer = true; } else { isSinglePlayer = false; GoogleApiClient.Builder builder = new GoogleApiClient.Builder(this); builder.addApi(Games.API).addApi(Plus.API).addApi(AppStateManager.API).addScope(Games.SCOPE_GAMES) .addScope(Plus.SCOPE_PLUS_LOGIN).addScope(AppStateManager.SCOPE_APP_STATE); mClient = builder.build(); loadLocal(); if (isSignedIn()) { //onFetchPlayerScoreAndAchive(); //displayPlayerNameScoreRank(); //Toast.makeText(this, "I Connected", Toast.LENGTH_SHORT).show(); } } Pair<String, String> pair = getPgnOrFenIntent(); String intentPgnOrFen = pair.first; String intentFilename = pair.second; createDirectories(); PreferenceManager.setDefaultValues(this, R.xml.preferences, false); settings = PreferenceManager.getDefaultSharedPreferences(this); settings.registerOnSharedPreferenceChangeListener(new OnSharedPreferenceChangeListener() { @Override public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { try { handlePrefsChange(); } catch (Exception e) { // TODO: handle exception } } }); PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); setWakeLock(false); wakeLock = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, "droidfish"); wakeLock.setReferenceCounted(false); custom1ButtonActions = new ButtonActions("custom1", CUSTOM1_BUTTON_DIALOG, R.string.select_action); custom2ButtonActions = new ButtonActions("custom2", CUSTOM2_BUTTON_DIALOG, R.string.select_action); custom3ButtonActions = new ButtonActions("custom3", CUSTOM3_BUTTON_DIALOG, R.string.select_action); figNotation = Typeface.createFromAsset(getAssets(), "fonts/DroidFishChessNotationDark.otf"); setPieceNames(PGNOptions.PT_LOCAL); //requestWindowFeature(Window.FEATURE_NO_TITLE); initUI(); gameTextListener = new PgnScreenText(pgnOptions); if (ctrl != null) ctrl.shutdownEngine(); ctrl = new DroidChessController(this, gameTextListener, pgnOptions); egtbForceReload = true; readPrefs(); TimeControlData tcData = new TimeControlData(); tcData.setTimeControl(timeControl, movesPerSession, timeIncrement); if (isSinglePlayer) { myTurn = true; ctrl.newGame(gameMode, tcData); { byte[] data = null; int version = 1; if (savedInstanceState != null) { data = savedInstanceState.getByteArray("gameState"); version = savedInstanceState.getInt("gameStateVersion", version); } else { String dataStr = settings.getString("gameState", null); version = settings.getInt("gameStateVersion", version); if (dataStr != null) data = strToByteArr(dataStr); } if (data != null) ctrl.fromByteArray(data, version); } ctrl.setGuiPaused(true); ctrl.setGuiPaused(false); ctrl.startGame(); //startNewGame(0); if (intentPgnOrFen != null) { try { ctrl.setFENOrPGN(intentPgnOrFen); setBoardFlip(true); } catch (ChessParseError e) { // If FEN corresponds to illegal chess position, go into edit board mode. try { TextIO.readFEN(intentPgnOrFen); } catch (ChessParseError e2) { if (e2.pos != null) startEditBoard(intentPgnOrFen); } } } else if (intentFilename != null) { if (intentFilename.toLowerCase(Locale.US).endsWith(".fen") || intentFilename.toLowerCase(Locale.US).endsWith(".epd")) loadFENFromFile(intentFilename); else loadPGNFromFile(intentFilename); } } else { int rnd = new Random().nextInt(2); startMultiplayerGameMode(rnd); } }
From source file:com.daiv.android.twitter.utils.NotificationUtils.java
public static void makeFavsNotification(ArrayList<String[]> tweets, Context context, boolean toDrawer) { String shortText;//from www . j a v a2 s .c o m String longText; String title; int smallIcon = R.drawable.ic_stat_icon; Bitmap largeIcon; PendingIntent resultPendingIntent = PendingIntent.getActivity(context, 0, null, 0); NotificationCompat.InboxStyle inbox = null; if (tweets.size() == 1) { title = tweets.get(0)[0]; shortText = tweets.get(0)[1]; longText = shortText; largeIcon = getImage(context, tweets.get(0)[2]); } else { inbox = new NotificationCompat.InboxStyle(); title = context.getResources().getString(R.string.favorite_users); shortText = tweets.size() + " " + context.getResources().getString(R.string.fav_user_tweets); longText = ""; try { inbox.setBigContentTitle(shortText); } catch (Exception e) { } if (tweets.size() <= 5) { for (String[] s : tweets) { inbox.addLine(Html.fromHtml("<b>" + s[0] + ":</b> " + s[1])); } } else { for (int i = 0; i < 5; i++) { inbox.addLine(Html.fromHtml("<b>" + tweets.get(i)[0] + ":</b> " + tweets.get(i)[1])); } inbox.setSummaryText("+" + (tweets.size() - 5) + " " + context.getString(R.string.tweets)); } largeIcon = BitmapFactory.decodeResource(context.getResources(), R.drawable.drawer_user_dark); } NotificationCompat.Builder mBuilder; AppSettings settings = AppSettings.getInstance(context); if (shortText.contains("@" + settings.myScreenName)) { // return because there is a mention notification for this already return; } Intent deleteIntent = new Intent(context, NotificationDeleteReceiverOne.class); mBuilder = new NotificationCompat.Builder(context).setContentTitle(title) .setContentText(TweetLinkUtils.removeColorHtml(shortText, settings)).setSmallIcon(smallIcon) .setLargeIcon(largeIcon).setContentIntent(resultPendingIntent).setAutoCancel(true) .setDeleteIntent(PendingIntent.getBroadcast(context, 0, deleteIntent, 0)) .setPriority(NotificationCompat.PRIORITY_HIGH); if (inbox == null) { mBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(Html.fromHtml( settings.addonTheme ? longText.replaceAll("FF8800", settings.accentColor) : longText))); } else { mBuilder.setStyle(inbox); } if (settings.vibrate) { mBuilder.setDefaults(Notification.DEFAULT_VIBRATE); } if (settings.sound) { try { mBuilder.setSound(Uri.parse(settings.ringtone)); } catch (Exception e) { mBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)); } } if (settings.led) mBuilder.setLights(0xFFFFFF, 1000, 1000); if (settings.notifications) { NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context); notificationManager.notify(2, mBuilder.build()); // if we want to wake the screen on a new message if (settings.wakeScreen) { PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); final PowerManager.WakeLock wakeLock = pm.newWakeLock((PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP), "TAG"); wakeLock.acquire(5000); } // Pebble notification if (context .getSharedPreferences("com.daiv.android.twitter_world_preferences", Context.MODE_WORLD_READABLE + Context.MODE_WORLD_WRITEABLE) .getBoolean("pebble_notification", false)) { sendAlertToPebble(context, title, shortText); } // Light Flow notification sendToLightFlow(context, title, shortText); } }
From source file:com.klinker.android.twitter.utils.NotificationUtils.java
public static void makeFavsNotification(ArrayList<String[]> tweets, Context context, boolean toDrawer) { String shortText;//from w ww. j a va 2 s .co m String longText; String title; int smallIcon = R.drawable.ic_stat_icon; Bitmap largeIcon; Intent resultIntent; if (toDrawer) { resultIntent = new Intent(context, RedirectToDrawer.class); } else { resultIntent = new Intent(context, NotiTweetPager.class); } PendingIntent resultPendingIntent = PendingIntent.getActivity(context, 0, resultIntent, 0); NotificationCompat.InboxStyle inbox = null; if (tweets.size() == 1) { title = tweets.get(0)[0]; shortText = tweets.get(0)[1]; longText = shortText; largeIcon = getImage(context, tweets.get(0)[2]); } else { inbox = new NotificationCompat.InboxStyle(); title = context.getResources().getString(R.string.favorite_users); shortText = tweets.size() + " " + context.getResources().getString(R.string.fav_user_tweets); longText = ""; try { inbox.setBigContentTitle(shortText); } catch (Exception e) { } if (tweets.size() <= 5) { for (String[] s : tweets) { inbox.addLine(Html.fromHtml("<b>" + s[0] + ":</b> " + s[1])); } } else { for (int i = 0; i < 5; i++) { inbox.addLine(Html.fromHtml("<b>" + tweets.get(i)[0] + ":</b> " + tweets.get(i)[1])); } inbox.setSummaryText("+" + (tweets.size() - 5) + " " + context.getString(R.string.tweets)); } largeIcon = BitmapFactory.decodeResource(context.getResources(), R.drawable.drawer_user_dark); } NotificationCompat.Builder mBuilder; AppSettings settings = AppSettings.getInstance(context); if (shortText.contains("@" + settings.myScreenName)) { // return because there is a mention notification for this already return; } Intent deleteIntent = new Intent(context, NotificationDeleteReceiverOne.class); mBuilder = new NotificationCompat.Builder(context).setContentTitle(title) .setContentText(TweetLinkUtils.removeColorHtml(shortText, settings)).setSmallIcon(smallIcon) .setLargeIcon(largeIcon).setContentIntent(resultPendingIntent).setAutoCancel(true) .setDeleteIntent(PendingIntent.getBroadcast(context, 0, deleteIntent, 0)) .setPriority(NotificationCompat.PRIORITY_HIGH); if (inbox == null) { mBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(Html.fromHtml( settings.addonTheme ? longText.replaceAll("FF8800", settings.accentColor) : longText))); } else { mBuilder.setStyle(inbox); } if (settings.vibrate) { mBuilder.setDefaults(Notification.DEFAULT_VIBRATE); } if (settings.sound) { try { mBuilder.setSound(Uri.parse(settings.ringtone)); } catch (Exception e) { mBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)); } } if (settings.led) mBuilder.setLights(0xFFFFFF, 1000, 1000); if (settings.notifications) { NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context); notificationManager.notify(2, mBuilder.build()); // if we want to wake the screen on a new message if (settings.wakeScreen) { PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); final PowerManager.WakeLock wakeLock = pm.newWakeLock((PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP), "TAG"); wakeLock.acquire(5000); } // Pebble notification if (context .getSharedPreferences("com.klinker.android.twitter_world_preferences", Context.MODE_WORLD_READABLE + Context.MODE_WORLD_WRITEABLE) .getBoolean("pebble_notification", false)) { sendAlertToPebble(context, title, shortText); } // Light Flow notification sendToLightFlow(context, title, shortText); } }
From source file:org.geometerplus.android.fbreader.FBReader.java
public final void createWakeLock() { if (myWakeLockToCreate) { synchronized (this) { if (myWakeLockToCreate) { myWakeLockToCreate = false; myWakeLock = ((PowerManager) getSystemService(POWER_SERVICE)) .newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, "FBReader"); myWakeLock.acquire();/* ww w.j a va2s .co m*/ } } } if (myStartTimer) { myFBReaderApp.startTimer(); myStartTimer = false; } }