List of usage examples for android.content Context POWER_SERVICE
String POWER_SERVICE
To view the source code for android.content Context POWER_SERVICE.
Click Source Link
From source file:com.android.dialer.voicemail.VoicemailPlaybackPresenter.java
/** * Initialize variables which are activity-independent and state-independent. *//* w w w .ja v a2 s . c o m*/ protected VoicemailPlaybackPresenter(Activity activity) { Context context = activity.getApplicationContext(); mAsyncTaskExecutor = AsyncTaskExecutors.createAsyncTaskExecutor(); mVoicemailAudioManager = new VoicemailAudioManager(context, this); mVoicemailAsyncTaskUtil = new VoicemailAsyncTaskUtil(context.getContentResolver()); PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE); if (powerManager.isWakeLockLevelSupported(PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK)) { mProximityWakeLock = powerManager.newWakeLock(PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK, TAG); } }
From source file:com.ericsun.duom.Framework.Activity.BaseActivity.java
public boolean isScreenLocked() { PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); boolean isScreenOn = pm.isScreenOn(); if (isScreenOn) return false; else//from w w w .j a v a 2 s. c om return true; }
From source file:dk.nota.lyt.libvlc.PlaybackService.java
@Override public void onCreate() { super.onCreate(); mSettings = PreferenceManager.getDefaultSharedPreferences(this); mMediaPlayer = newMediaPlayer();/*w w w. j a va2 s .co m*/ if (!Utils.testCompatibleCPU(this)) { stopSelf(); return; } mDetectHeadset = mSettings.getBoolean("enable_headset_detection", true); mCurrentIndex = -1; mPrevIndex = -1; mNextIndex = -1; mPrevious = new Stack<Integer>(); mRemoteControlClientReceiverComponent = new ComponentName(this.getApplicationContext(), RemoteControlEventReceiver.class.getName()); // Make sure the audio player will acquire a wake-lock while playing. If we don't do // that, the CPU might go to sleep while the song is playing, causing playback to stopService. PowerManager pm = (PowerManager) this.getApplicationContext().getSystemService(Context.POWER_SERVICE); mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG); IntentFilter filter = new IntentFilter(); filter.setPriority(Integer.MAX_VALUE); filter.addAction(ACTION_REMOTE_BACKWARD); filter.addAction(ACTION_REMOTE_PLAYPAUSE); filter.addAction(ACTION_REMOTE_PLAY); filter.addAction(ACTION_REMOTE_PAUSE); filter.addAction(ACTION_REMOTE_STOP); filter.addAction(ACTION_REMOTE_FORWARD); filter.addAction(Intent.ACTION_HEADSET_PLUG); filter.addAction(AudioManager.ACTION_AUDIO_BECOMING_NOISY); registerReceiver(mReceiver, filter); }
From source file:org.ado.minesync.gui.MineSyncMainActivity.java
private boolean isScreenOn() { return ((PowerManager) getApplicationContext().getSystemService(Context.POWER_SERVICE)).isScreenOn(); }
From source file:org.awesomeapp.messenger.service.RemoteImService.java
@Override public void onCreate() { debug("ImService started"); final String prev = Debug.getTrail(this, SERVICE_CREATE_TRAIL_KEY); if (prev != null) Debug.recordTrail(this, PREV_SERVICE_CREATE_TRAIL_TAG, prev); Debug.recordTrail(this, SERVICE_CREATE_TRAIL_KEY, new Date()); final String prevConnections = Debug.getTrail(this, CONNECTIONS_TRAIL_TAG); if (prevConnections != null) Debug.recordTrail(this, PREV_CONNECTIONS_TRAIL_TAG, prevConnections); Debug.recordTrail(this, CONNECTIONS_TRAIL_TAG, "0"); mConnections = new Hashtable<Long, ImConnectionAdapter>(); mConnectionsByUser = new Hashtable<String, ImConnectionAdapter>(); mHandler = new Handler(); Debug.onServiceStart();/*from w ww. j a va 2 s. c om*/ //startForegroundCompat(); PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE); mWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "IM_WAKELOCK"); // Clear all account statii to logged-out, since we just got started and we don't want // leftovers from any previous crash. clearConnectionStatii(); mStatusBarNotifier = new StatusBarNotifier(this); mServiceHandler = new ServiceHandler(); mPluginHelper = ImPluginHelper.getInstance(this); mPluginHelper.loadAvailablePlugins(); // Have the heartbeat start autoLogin, unless onStart turns this off mNeedCheckAutoLogin = true; HeartbeatService.startBeating(getApplicationContext()); SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this); startForeground(notifyId, getForegroundNotification()); }
From source file:com.achep.acdisplay.services.activemode.ActiveModeService.java
private void pingConsumingSensorsInternal() { // Find maximum remaining time. int remainingTime = -1; for (ActiveModeSensor ams : mSensors) { if (ams.isAttached() && ams instanceof ActiveModeSensor.Consuming) { ActiveModeSensor.Consuming sensor = (ActiveModeSensor.Consuming) ams; remainingTime = Math.max(remainingTime, sensor.getRemainingTime()); }/*from w w w . j a va2s .co m*/ } long now = SystemClock.elapsedRealtime(); int delta = (int) (now - mConsumingPingTimestamp); remainingTime -= delta; if (remainingTime < 0) { return; // Too late } // Acquire wake lock to be sure that sensors will be fine. releaseWakeLock(); PowerManager pm = (PowerManager) getContext().getSystemService(Context.POWER_SERVICE); mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, WAKE_LOCK_TAG); mWakeLock.acquire(remainingTime); // Ping sensors for (ActiveModeSensor ams : mSensors) { if (ams.isAttached() && ams instanceof ActiveModeSensor.Consuming) { ActiveModeSensor.Consuming sensor = (ActiveModeSensor.Consuming) ams; int sensorRemainingTime = sensor.getRemainingTime() - delta; if (sensorRemainingTime > 0) { sensor.ping(sensorRemainingTime); } } } }
From source file:org.sipdroid.sipua.ui.Receiver.java
public static void onState(int state, String caller) { if (ccCall == null) { ccCall = new Call(); ccConn = new Connection(); ccCall.setConn(ccConn);/*from www. j a v a 2 s . com*/ ccConn.setCall(ccCall); } if (call_state != state) { if (state != UserAgent.UA_STATE_IDLE) call_end_reason = -1; call_state = state; switch (call_state) { case UserAgent.UA_STATE_INCOMING_CALL: enable_wifi(true); RtpStreamReceiver.good = RtpStreamReceiver.lost = RtpStreamReceiver.loss = RtpStreamReceiver.late = 0; RtpStreamReceiver.speakermode = speakermode(); bluetooth = -1; String text = caller.toString(); if (text.indexOf("<sip:") >= 0 && text.indexOf("@") >= 0) text = text.substring(text.indexOf("<sip:") + 5, text.indexOf("@")); String text2 = caller.toString(); if (text2.indexOf("\"") >= 0) text2 = text2.substring(text2.indexOf("\"") + 1, text2.lastIndexOf("\"")); broadcastCallStateChanged("RINGING", caller); mContext.sendBroadcast(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS)); ccCall.setState(Call.State.INCOMING); ccConn.setUserData(null); ccConn.setAddress(text, text2); ccConn.setIncoming(true); ccConn.date = System.currentTimeMillis(); ccCall.base = 0; AudioManager am = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE); int rm = am.getRingerMode(); int vs = am.getVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER); KeyguardManager mKeyguardManager = (KeyguardManager) mContext .getSystemService(Context.KEYGUARD_SERVICE); if (v == null) v = (Vibrator) mContext.getSystemService(Context.VIBRATOR_SERVICE); if ((pstn_state == null || pstn_state.equals("IDLE")) && PreferenceManager.getDefaultSharedPreferences(mContext).getBoolean( org.sipdroid.sipua.ui.Settings.PREF_AUTO_ON, org.sipdroid.sipua.ui.Settings.DEFAULT_AUTO_ON) && !mKeyguardManager.inKeyguardRestrictedInputMode()) v.vibrate(vibratePattern, 1); else { if ((pstn_state == null || pstn_state.equals("IDLE")) && (rm == AudioManager.RINGER_MODE_VIBRATE || (rm == AudioManager.RINGER_MODE_NORMAL && vs == AudioManager.VIBRATE_SETTING_ON))) v.vibrate(vibratePattern, 1); if (am.getStreamVolume(AudioManager.STREAM_RING) > 0) { String sUriSipRingtone = PreferenceManager.getDefaultSharedPreferences(mContext).getString( org.sipdroid.sipua.ui.Settings.PREF_SIPRINGTONE, Settings.System.DEFAULT_RINGTONE_URI.toString()); if (!TextUtils.isEmpty(sUriSipRingtone)) { oRingtone = RingtoneManager.getRingtone(mContext, Uri.parse(sUriSipRingtone)); if (oRingtone != null) oRingtone.play(); } } } moveTop(); if (wl == null) { PowerManager pm = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE); wl = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "Sipdroid.onState"); } wl.acquire(); Checkin.checkin(true); break; case UserAgent.UA_STATE_OUTGOING_CALL: RtpStreamReceiver.good = RtpStreamReceiver.lost = RtpStreamReceiver.loss = RtpStreamReceiver.late = 0; RtpStreamReceiver.speakermode = speakermode(); bluetooth = -1; onText(MISSED_CALL_NOTIFICATION, null, 0, 0); engine(mContext).register(); broadcastCallStateChanged("OFFHOOK", caller); ccCall.setState(Call.State.DIALING); ccConn.setUserData(null); ccConn.setAddress(caller, caller); ccConn.setIncoming(false); ccConn.date = System.currentTimeMillis(); ccCall.base = 0; moveTop(); Checkin.checkin(true); break; case UserAgent.UA_STATE_IDLE: broadcastCallStateChanged("IDLE", null); onText(CALL_NOTIFICATION, null, 0, 0); ccCall.setState(Call.State.DISCONNECTED); if (listener_video != null) listener_video.onHangup(); stopRingtone(); if (wl != null && wl.isHeld()) wl.release(); mContext.startActivity(createIntent(InCallScreen.class)); ccConn.log(ccCall.base); ccConn.date = 0; engine(mContext).listen(); break; case UserAgent.UA_STATE_INCALL: broadcastCallStateChanged("OFFHOOK", null); if (ccCall.base == 0) { ccCall.base = SystemClock.elapsedRealtime(); } progress(); ccCall.setState(Call.State.ACTIVE); stopRingtone(); if (wl != null && wl.isHeld()) wl.release(); mContext.startActivity(createIntent(InCallScreen.class)); break; case UserAgent.UA_STATE_HOLD: onText(CALL_NOTIFICATION, mContext.getString(R.string.card_title_on_hold), android.R.drawable.stat_sys_phone_call_on_hold, ccCall.base); ccCall.setState(Call.State.HOLDING); if (InCallScreen.started && (pstn_state == null || !pstn_state.equals("RINGING"))) mContext.startActivity(createIntent(InCallScreen.class)); break; } pos(true); RtpStreamReceiver.ringback(false); } }
From source file:com.iamplus.musicplayer.MusicService.java
@Override public void onCreate() { Log.i(TAG, "debug: Creating service"); // Create the Wifi lock (this does not acquire the lock, this just creates it) // mWifiLock = ((WifiManager) getSystemService(Context.WIFI_SERVICE)) // .createWifiLock(WifiManager.WIFI_MODE_FULL, "mylock"); PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, this.getClass().getName()); mWakeLock.setReferenceCounted(false); //mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); mAudioManager = (AudioManager) getSystemService(AUDIO_SERVICE); // create the Audio Focus Helper, if the Audio Focus feature is available (SDK 8 or above) if (android.os.Build.VERSION.SDK_INT >= 8) mAudioFocusHelper = new AudioFocusHelper(getApplicationContext(), this); else/* www . j ava 2s. c o m*/ mAudioFocus = AudioFocus.Focused; // no focus feature, so we always "have" audio focus //mDummyAlbumArt = BitmapFactory.decodeResource(getResources(), R.drawable.albumart_mp_unknown); mMediaButtonReceiverComponent = new ComponentName(this, MusicIntentReceiver.class); e_play_mode emode = MusicRetriever.getPlayModePref(this, e_play_mode.e_play_mode_normal); MusicRetriever.getInstance().setPlayMode(emode); }
From source file:org.mozilla.gecko.tests.BaseRobocopTest.java
/** * Ensure that the screen on the test device is powered on during tests. *//*from www .j a va2s . com*/ public void throwIfScreenNotOn() { final PowerManager pm = (PowerManager) getActivity().getSystemService(Context.POWER_SERVICE); mAsserter.ok(pm.isScreenOn(), "Robocop tests need the test device screen to be powered on.", ""); }
From source file:com.parttime.activity.ChatActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.chat);//ww w .jav a 2s . c o m mContext = this; toChatUsername = getIntent().getStringExtra("userid"); // if(toChatUsername==null) // { // toChatUsername=""; // } flag = getIntent().getStringExtra("flag"); if (flag != null && flag.equals("commnuication")) { Utils.CommitPageFlagToShared(this, Constant.FINISH_ACTIVITY_FLAG_COMMUNICATION); } Utils.HxUserNames.add(toChatUsername); initView(); iv_emoticons_normal.setOnClickListener(this); iv_emoticons_checked.setOnClickListener(this); // position = getIntent().getIntExtra("position", -1); clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE); manager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); wakeLock = ((PowerManager) getSystemService(Context.POWER_SERVICE)) .newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "demo"); conversation = EMChatManager.getInstance().getConversation(toChatUsername); // ?0 conversation.resetUnreadMsgCount(); adapter = new MessageAdapter(this, toChatUsername, chatType); // ? listView.setAdapter(adapter); listView.setOnScrollListener(new ListScrollListener()); int count = listView.getCount(); if (count > 0) { listView.setSelection(count - 1); } listView.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { hideKeyboard(); more.setVisibility(View.GONE); iv_emoticons_normal.setVisibility(View.VISIBLE); iv_emoticons_checked.setVisibility(View.INVISIBLE); emojiIconContainer.setVisibility(View.GONE); btnContainer.setVisibility(View.GONE); return false; } }); // ? receiver = new NewMessageBroadcastReceiver(); IntentFilter intentFilter = new IntentFilter(EMChatManager.getInstance().getNewMessageBroadcastAction()); // Mainacitivity,??chat?????? intentFilter.setPriority(5); registerReceiver(receiver, intentFilter); // ack?BroadcastReceiver IntentFilter ackMessageIntentFilter = new IntentFilter( EMChatManager.getInstance().getAckMessageBroadcastAction()); ackMessageIntentFilter.setPriority(5); registerReceiver(ackMessageReceiver, ackMessageIntentFilter); // ??BroadcastReceiver IntentFilter deliveryAckMessageIntentFilter = new IntentFilter( EMChatManager.getInstance().getDeliveryAckMessageBroadcastAction()); deliveryAckMessageIntentFilter.setPriority(5); registerReceiver(deliveryAckMessageReceiver, deliveryAckMessageIntentFilter); // show forward message if the message is not null String forward_msg_id = getIntent().getStringExtra("forward_msg_id"); if (forward_msg_id != null) { // ????? forwardMessage(forward_msg_id); } // setUpView(); }