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: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();//from w w w .j ava 2 s . c om 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.klinker.android.twitter.utils.NotificationUtils.java
public static void refreshNotification(Context context, boolean noTimeline) { AppSettings settings = AppSettings.getInstance(context); SharedPreferences sharedPrefs = context.getSharedPreferences( "com.klinker.android.twitter_world_preferences", Context.MODE_WORLD_READABLE + Context.MODE_WORLD_WRITEABLE); int currentAccount = sharedPrefs.getInt("current_account", 1); //int[] unreadCounts = new int[] {4, 1, 2}; // for testing int[] unreadCounts = getUnreads(context); int timeline = unreadCounts[0]; int realTimelineCount = timeline; // if they don't want that type of notification, simply set it to zero if (!settings.timelineNot || (settings.pushNotifications && settings.liveStreaming) || noTimeline) { unreadCounts[0] = 0;// ww w .j ava 2s . c o m } if (!settings.mentionsNot) { unreadCounts[1] = 0; } if (!settings.dmsNot) { unreadCounts[2] = 0; } if (unreadCounts[0] == 0 && unreadCounts[1] == 0 && unreadCounts[2] == 0) { } else { Intent markRead = new Intent(context, MarkReadService.class); PendingIntent readPending = PendingIntent.getService(context, 0, markRead, 0); String shortText = getShortText(unreadCounts, context, currentAccount); String longText = getLongText(unreadCounts, context, currentAccount); // [0] is the full title and [1] is the screenname String[] title = getTitle(unreadCounts, context, currentAccount); boolean useExpanded = useExp(context); boolean addButton = addBtn(unreadCounts); if (title == null) { return; } Intent resultIntent; if (unreadCounts[1] != 0 && unreadCounts[0] == 0) { // it is a mention notification (could also have a direct message) resultIntent = new Intent(context, RedirectToMentions.class); } else if (unreadCounts[2] != 0 && unreadCounts[0] == 0 && unreadCounts[1] == 0) { // it is a direct message resultIntent = new Intent(context, RedirectToDMs.class); } else { resultIntent = new Intent(context, MainActivity.class); } PendingIntent resultPendingIntent = PendingIntent.getActivity(context, 0, resultIntent, 0); NotificationCompat.Builder mBuilder; Intent deleteIntent = new Intent(context, NotificationDeleteReceiverOne.class); mBuilder = new NotificationCompat.Builder(context).setContentTitle(title[0]) .setContentText(TweetLinkUtils.removeColorHtml(shortText, settings)) .setSmallIcon(R.drawable.ic_stat_icon).setLargeIcon(getIcon(context, unreadCounts, title[1])) .setContentIntent(resultPendingIntent).setAutoCancel(true) .setTicker(TweetLinkUtils.removeColorHtml(shortText, settings)) .setDeleteIntent(PendingIntent.getBroadcast(context, 0, deleteIntent, 0)) .setPriority(NotificationCompat.PRIORITY_HIGH); if (unreadCounts[1] > 1 && unreadCounts[0] == 0 && unreadCounts[2] == 0) { // inbox style notification for mentions mBuilder.setStyle(getMentionsInboxStyle(unreadCounts[1], currentAccount, context, TweetLinkUtils.removeColorHtml(shortText, settings))); } else if (unreadCounts[2] > 1 && unreadCounts[0] == 0 && unreadCounts[1] == 0) { // inbox style notification for direct messages mBuilder.setStyle(getDMInboxStyle(unreadCounts[1], currentAccount, context, TweetLinkUtils.removeColorHtml(shortText, settings))); } else { // big text style for an unread count on timeline, mentions, and direct messages mBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(Html.fromHtml( settings.addonTheme ? longText.replaceAll("FF8800", settings.accentColor) : longText))); } // Pebble notification if (sharedPrefs.getBoolean("pebble_notification", false)) { sendAlertToPebble(context, title[0], shortText); } // Light Flow notification sendToLightFlow(context, title[0], shortText); int homeTweets = unreadCounts[0]; int mentionsTweets = unreadCounts[1]; int dmTweets = unreadCounts[2]; int newC = 0; if (homeTweets > 0) { newC++; } if (mentionsTweets > 0) { newC++; } if (dmTweets > 0) { newC++; } if (settings.notifications && newC > 0) { 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); // Get an instance of the NotificationManager service NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context); if (addButton) { // the reply and read button should be shown Intent reply; if (unreadCounts[1] == 1) { reply = new Intent(context, NotificationCompose.class); } else { reply = new Intent(context, NotificationDMCompose.class); } Log.v("username_for_noti", title[1]); sharedPrefs.edit().putString("from_notification", "@" + title[1] + " " + title[2]).commit(); MentionsDataSource data = MentionsDataSource.getInstance(context); long id = data.getLastIds(currentAccount)[0]; PendingIntent replyPending = PendingIntent.getActivity(context, 0, reply, 0); sharedPrefs.edit().putLong("from_notification_long", id).commit(); sharedPrefs.edit() .putString("from_notification_text", "@" + title[1] + ": " + TweetLinkUtils.removeColorHtml(shortText, settings)) .commit(); // Create the remote input RemoteInput remoteInput = new RemoteInput.Builder(EXTRA_VOICE_REPLY) .setLabel("@" + title[1] + " ").build(); // Create the notification action NotificationCompat.Action replyAction = new NotificationCompat.Action.Builder( R.drawable.ic_action_reply_dark, context.getResources().getString(R.string.noti_reply), replyPending).addRemoteInput(remoteInput).build(); NotificationCompat.Action.Builder action = new NotificationCompat.Action.Builder( R.drawable.ic_action_read_dark, context.getResources().getString(R.string.mark_read), readPending); mBuilder.addAction(replyAction); mBuilder.addAction(action.build()); } else { // otherwise, if they can use the expanded notifications, the popup button will be shown Intent popup = new Intent(context, RedirectToPopup.class); popup.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK); popup.putExtra("from_notification", true); PendingIntent popupPending = PendingIntent.getActivity(context, 0, popup, 0); NotificationCompat.Action.Builder action = new NotificationCompat.Action.Builder( R.drawable.ic_popup, context.getResources().getString(R.string.popup), popupPending); mBuilder.addAction(action.build()); } // Build the notification and issues it with notification manager. notificationManager.notify(1, 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); } } // if there are unread tweets on the timeline, check them for favorite users if (settings.favoriteUserNotifications && realTimelineCount > 0) { favUsersNotification(currentAccount, context); } } try { ContentValues cv = new ContentValues(); cv.put("tag", "com.klinker.android.twitter/com.klinker.android.twitter.ui.MainActivity"); // add the direct messages and mentions cv.put("count", unreadCounts[1] + unreadCounts[2]); context.getContentResolver().insert(Uri.parse("content://com.teslacoilsw.notifier/unread_count"), cv); } catch (IllegalArgumentException ex) { /* Fine, TeslaUnread is not installed. */ } catch (Exception ex) { /* Some other error, possibly because the format of the ContentValues are incorrect. Log but do not crash over this. */ ex.printStackTrace(); } }
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 {/* www .j a v a 2s . 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:com.yi4all.rupics.ImageDetailActivity.java
public void startSlideShow() { Runnable slide = new Runnable() { @Override//from ww w . j a v a 2 s . c o m public void run() { PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, LOGTAG); wl.acquire(); while (isSlideshow) { if (imageSequence < imgList.size() - 1) { // back to the next image imageSequence++; setCurrentPage(); } else { // give a tip to user Utils.toastMsg(ImageDetailActivity.this, R.string.alreadyLast); isSlideshow = false; } try { Thread.sleep(2000); } catch (InterruptedException e) { Log.e(LOGTAG, "startSlideShow:" + ((e != null) ? e.getMessage() : "exception is null")); } // if(ImageDetailActivity.this.) } if (wl.isHeld()) wl.release(); } }; new Thread(slide).start(); }
From source file:com.example.gangzhang.myapplication.VideoPlayerActivity.java
@Override protected void onResume() { Log.d(TAG, "onResume"); super.onResume(); boolean enabled = sp.getBoolean(SettingFragment.KEY_WAKEUP_ENABLE, false); if (enabled) { powerManager = ((PowerManager) getSystemService(POWER_SERVICE)); wakeLock = powerManager/* ww w .j a va 2 s . com*/ .newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE, TAG); wakeLock.acquire(); } }
From source file:edu.mit.viral.shen.DroidFish.java
/** Called when the activity is first created. */ @Override/*from w w w. jav a 2s .co m*/ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); game_number = getIntent().getExtras().getInt("game_id", 0); // sendGame(); 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(pgnOptions); if (ctrl != null) ctrl.shutdownEngine(); ctrl = new DroidChessController(this, gameTextListener, pgnOptions); egtbForceReload = true; readPrefs(); TimeControlData tcData = new TimeControlData(); mDatabase = new SudokuDatabase(getApplicationContext()); game_id = Long.valueOf(game_number); ctrl = mDatabase.getSudoku(ctrl, game_id); startPosition = ctrl.getData(); tcData.setTimeControl(timeControl, movesPerSession, timeIncrement); int version = 1; version = settings.getInt("gameStateVersion", version); // System.out.println("this is the version" + version); ctrl.newGame(gameMode, tcData); if (game_number >= 37 && (startPosition.equals("8/8/8/8/8/8/8/8 w - - 0 1") | startPosition.equals("8/8/8/8/8/8/8/8 w KQkq - 0 1"))) { // System.out.println("greater than 37"); startEditBoard("8/8/8/8/8/8/8/8 w KQkq - 0 1"); } if (ctrl.getState() == DroidChessController.GAME_STATE_NOT_STARTED) { ctrl.start(); System.out.println("GAME_STATE_NOT_STARTED"); } else if (ctrl.getState() == DroidChessController.GAME_STATE_PLAYING) { System.out.println("GAME_STATE_PLAYING"); String dataStr = ctrl.getNote(); // System.out.println(ctrl.getNote()); byte[] data = strToByteArr(dataStr); // ctrl.newGame(gameMode, tcData, "8/8/8/8/8/8/8/8 w KQkq - 0 1"); ctrl.fromByteArray(data, 3); } 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); } // commented out 04/12/15 // sendDataone(startPosition, 1); utils = new Utils(getApplicationContext()); client = new WebSocketClient(URI.create(Const.URL_WEBSOCKET + URLEncoder.encode(name)), new WebSocketClient.Listener() { @Override public void onConnect() { } /** * On receiving the message from web socket server * */ @Override public void onMessage(String message) { Log.d(TAG, String.format("Got string message! %s", message)); parseMessage(message); } @Override public void onMessage(byte[] data) { Log.d(TAG, String.format("Got binary message! %s", bytesToHex(data))); parseMessage(bytesToHex(data)); // Message will be in JSON format } /** * Called when the connection is terminated * */ @Override public void onDisconnect(int code, String reason) { String message = String.format(Locale.US, "Disconnected! Code: %d Reason: %s", code, reason); // showToast(message); // clear the session id from shared preferences utils.storeSessionId(null); } @Override public void onError(Exception error) { Log.e(TAG, "Error! : " + error); } }, null); client.connect(); }
From source file:com.dragon4.owo.ar_trace.ARCore.MixView.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); DataSource.createIcons(getResources()); try {/*from w ww . j ava 2 s .c om*/ // ?? final PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); // ? ?? ? this.mWakeLock = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, "My Tag"); // ?? locationMgr = (LocationManager) getSystemService(Context.LOCATION_SERVICE); // ?? . 2 ?? (1/1000s), 3 ?? (m)? ? locationMgr.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 3, this); //orientation sensor sensorMgr_ori = (SensorManager) getSystemService(Context.SENSOR_SERVICE); orientationSensor = sensorMgr_ori.getDefaultSensor(Sensor.TYPE_ORIENTATION); killOnError(); // ? ? requestWindowFeature(Window.FEATURE_NO_TITLE); // ? ? // ?? FrameLayout frameLayout = new FrameLayout(this); // ? ?, ? frameLayout.setMinimumWidth(3000); frameLayout.setPadding(10, 0, 10, 10); // ? ? ? ?? ? camScreen = new CameraSurface(this); augScreen = new AugmentedView(this); setContentView(camScreen); // ? ?? ? ? // ? ?? ? addContentView(augScreen, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); // ? ? ? ? ?. // ? ? ? ?? ? ? ? addContentView(frameLayout, new FrameLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT, Gravity.BOTTOM)); topLayoutOnMixView = new TopLayoutOnMixView(this); RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT); addContentView(topLayoutOnMixView.mainArView, params); // ? ? ? topLayoutOnMixView ? ? handleIntent(getIntent()); // ?? // ? ? ? if (!isInited) { mixContext = new MixContext(this); // ? ? // ? ? mixContext.downloadManager = new DownloadManager(mixContext); //? ? ? navigator = new Navigator(mixContext, topLayoutOnMixView.naverFragment); // ? ? ?? ? ? dWindow = new PaintScreen(); dataView = new DataView(mixContext); isInited = true; // true } if (mixContext.isActualLocation() == false) { Toast.makeText(this, getString(DataView.CONNECTION_GPS_DIALOG_TEXT), Toast.LENGTH_LONG).show(); } } catch (Exception ex) { doError(ex); // ? ? } // ? IntentFilter naviBraodFilter = new IntentFilter(); naviBraodFilter.addAction("NAVI"); registerReceiver(naviRecevicer, naviBraodFilter); }
From source file:uk.co.spookypeanut.wake_me_at.WakeMeAtService.java
public void soundAlarm() { mAlarm = true;//from w w w. ja va2 s. com // 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.example.administrator.testscreenrecording.control.StreamingCamera2Fragment.java
@Override public void onResume() { super.onResume(); startBackgroundThread();// w w w . j ava2s .co m // When the screen is turned off and turned back on, the SurfaceTexture is already // available, and "onSurfaceTextureAvailable" will not be called. In that case, we can open // a camera and start preview from here (otherwise, we wait until the surface is ready in // the SurfaceTextureListener). if (mTextureView.isAvailable()) { openCamera(mTextureView.getWidth(), mTextureView.getHeight()); } else { mTextureView.setSurfaceTextureListener(mSurfaceTextureListener); } if (mWakeLock == null) { PowerManager pm = (PowerManager) getActivity().getSystemService(Context.POWER_SERVICE); mWakeLock = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, LOG_TAG); mWakeLock.acquire(); } }
From source file:nl.sogeti.android.gpstracker.viewer.LoggerMap.java
private void updateBlankingBehavior() { boolean disableblanking = mSharedPreferences.getBoolean(Constants.DISABLEBLANKING, false); boolean disabledimming = mSharedPreferences.getBoolean(Constants.DISABLEDIMMING, false); if (disableblanking) { if (mWakeLock == null) { PowerManager pm = (PowerManager) this.getSystemService(Context.POWER_SERVICE); if (disabledimming) { mWakeLock = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, WAKELOCK_TAG); } else { mWakeLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, WAKELOCK_TAG); }/*www . j a v a2 s . c o m*/ } if (mLoggerServiceManager.getLoggingState() == ExternalConstants.STATE_LOGGING && !mWakeLock.isHeld()) { mWakeLock.acquire(); Log.w(this, "Acquired lock to keep screen on!"); } } }