List of usage examples for android.os PowerManager PARTIAL_WAKE_LOCK
int PARTIAL_WAKE_LOCK
To view the source code for android.os PowerManager PARTIAL_WAKE_LOCK.
Click Source Link
From source file:com.aniruddhc.acemusic.player.AsyncTasks.AsyncGetGooglePlayMusicMetadataTask.java
@Override protected void onPreExecute() { super.onPreExecute(); //Hide the actionbar. mApp.setIsBuildingLibrary(true);// w w w . j av a 2s.c o m //Acquire a wakelock to prevent the CPU from sleeping while the process is running. pm = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE); wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "com.aniruddhc.acemusic.player.AsyncTasks.AsyncGetGooglePlayMusicMetadata"); wakeLock.acquire(); //Set the initial setting of the progressbar as indeterminate. currentTask = mContext.getResources().getString(R.string.contacting_google_play_music); }
From source file:com.androidzeitgeist.dashwatch.DashWatchService.java
/** * Asks extensions to provide data updates. *//*from w ww. j a va 2s .c o m*/ private void updateExtensions() { PowerManager pwm = (PowerManager) getSystemService(POWER_SERVICE); PowerManager.WakeLock lock = pwm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG); lock.acquire(UPDATE_WAKELOCK_TIMEOUT_MILLIS); int reason = DashClockExtension.UPDATE_REASON_INITIAL; try { for (ComponentName cn : mExtensionManager.getActiveExtensionNames()) { mExtensionHost.execute(cn, ExtensionHost.UPDATE_OPERATIONS.get(reason), ExtensionHost.UPDATE_COLLAPSE_TIME_MILLIS, reason); } } finally { lock.release(); } }
From source file:com.jams.music.player.AsyncTasks.AsyncGetGooglePlayMusicMetadataTask.java
@Override protected void onPreExecute() { super.onPreExecute(); //Hide the actionbar. mApp.setIsBuildingLibrary(true);//from w w w . j a v a 2 s . co m //Acquire a wakelock to prevent the CPU from sleeping while the process is running. pm = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE); wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "com.jams.music.player.AsyncTasks.AsyncGetGooglePlayMusicMetadata"); wakeLock.acquire(); //Set the initial setting of the progressbar as indeterminate. currentTask = mContext.getResources().getString(R.string.contacting_google_play_music); }
From source file:com.samknows.measurement.MainService.java
public void onBegin() { synchronized (sync) { isExecuting = true;// w w w . j a v a 2 s. co m } // obtain wake lock, other way our service may stop executing PowerManager pm = (PowerManager) getSystemService(POWER_SERVICE); wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, MainService.class.getName()); wakeLock.acquire(); // reschedule service in the beginning to ensure it will be started if // killed. OtherUtils.rescheduleRTC(this, appSettings.rescheduleServiceTime); collector.start(); }
From source file:com.digutsoft.metronome.DMFSetTempo.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { rootView = inflater.inflate(R.layout.settempo, container, false); sbTempo = (SeekBar) rootView.findViewById(R.id.sbTempo); tvTempo = (TextView) rootView.findViewById(R.id.tvTempo); final CircledImageView btStart = (CircledImageView) rootView.findViewById(R.id.btStart); final CircledImageView btPlus = (CircledImageView) rootView.findViewById(R.id.btPlus); final CircledImageView btMinus = (CircledImageView) rootView.findViewById(R.id.btMinus); mContext = getActivity().getApplicationContext(); final Context mContext = getActivity(); sharedPreferences = mContext.getSharedPreferences("dMetronome", 0); int defaultTempo = sharedPreferences.getInt("tempo", 80); setTempo(defaultTempo);//from w ww . j a v a2 s . co m Intent viewIntent = new Intent(getActivity(), DMAMain.class); PendingIntent viewPendingIntent = PendingIntent.getActivity(getActivity(), 0, viewIntent, 0); notificationBuilder = new NotificationCompat.Builder(getActivity()).setOngoing(true) .setSmallIcon(R.drawable.ic_launcher).setContentTitle(getString(R.string.app_name)) .setContentIntent(viewPendingIntent); notificationManager = NotificationManagerCompat.from(getActivity()); Vibrator vibrator = (Vibrator) mContext.getSystemService(Context.VIBRATOR_SERVICE); metronome = new DMCMetronome(getActivity(), vibrator, rootView.findViewById(R.id.bilBackground)); PowerManager powerManager = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE); wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, getString(R.string.app_name)); sbTempo.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int i, boolean b) { setTempo(i); } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onStopTrackingTouch(SeekBar seekBar) { } }); btStart.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (mTempo == 0) { Toast.makeText(getActivity(), R.string.tempo_zero, Toast.LENGTH_LONG).show(); return; } if (DMCMetronome.mRunning) { metronome.stopTick(); sbTempo.setEnabled(true); tvTempo.setText(Integer.toString(mTempo)); btStart.setImageDrawable(getResources().getDrawable(R.drawable.ic_start)); btStart.setCircleColor(getResources().getColor(R.color.green)); btPlus.setVisibility(View.VISIBLE); btMinus.setVisibility(View.VISIBLE); wakeLock.release(); notificationManager.cancel(1); } else { metronome.startTick(mTempo); sbTempo.setEnabled(false); btStart.setImageDrawable(getResources().getDrawable(R.drawable.ic_stop)); btStart.setCircleColor(getResources().getColor(R.color.red)); btPlus.setVisibility(View.GONE); btMinus.setVisibility(View.GONE); wakeLock.acquire(); notificationBuilder .setContentText(String.format(getString(R.string.notification_running), mTempo)); notificationManager.notify(1, notificationBuilder.build()); sharedPreferences.edit().putInt("tempo", mTempo).apply(); } } }); btPlus.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { setTempo(mTempo + 1); } }); btMinus.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { setTempo(mTempo - 1); } }); return rootView; }
From source file:org.kegbot.app.service.CheckinService.java
@Override public void onCreate() { super.onCreate(); mPrefsHelper = new PreferenceHelper(this); final PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE); mWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "kbcheckin"); mDeviceId = DeviceId.getDeviceId(this); try {//from w ww . j av a 2 s . com final PackageInfo pinfo = getPackageManager().getPackageInfo(getPackageName(), 0); mKegbotVersion = pinfo.versionCode; } catch (NameNotFoundException e) { Log.w(TAG, "Could not look up own package info."); } resetCheckinStateIfNeeded(); registerAlarm(); }
From source file:me.myatminsoe.myansms.SmsReceiver.java
static void handleOnReceive(final BroadcastReceiver receiver, final Context context, final Intent intent) { final String action = intent.getAction(); final PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); final PowerManager.WakeLock wakelock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG); wakelock.acquire();/* ww w.j a v a2 s .c om*/ try { Thread.sleep(SLEEP); } catch (InterruptedException e) { e.printStackTrace(); } String t = null; if (SenderActivity.MESSAGE_SENT_ACTION.equals(action)) { handleSent(context, intent, receiver.getResultCode()); } else { boolean silent = false; if (ACTION_SMS_OLD.equals(action) || ACTION_SMS_NEW.equals(action)) { Bundle b = intent.getExtras(); assert b != null; Object[] messages = (Object[]) b.get("pdus"); SmsMessage[] smsMessage = new SmsMessage[messages.length]; int l = messages.length; for (int i = 0; i < l; i++) { smsMessage[i] = SmsMessage.createFromPdu((byte[]) messages[i]); } t = null; if (l > 0) { // concatenate multipart SMS body StringBuilder sbt = new StringBuilder(); for (int i = 0; i < l; i++) { sbt.append(smsMessage[i].getMessageBody()); } t = sbt.toString(); // ! Check in blacklist db - filter spam String s = smsMessage[0].getDisplayOriginatingAddress(); // this code is used to strip a forwarding agent and display the orginated number as sender final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); if (prefs.getBoolean(PreferencesActivity.PREFS_FORWARD_SMS_CLEAN, false) && t.contains(":")) { Pattern smsPattern = Pattern.compile("([0-9a-zA-Z+]+):"); Matcher m = smsPattern.matcher(t); if (m.find()) { s = m.group(1); // now strip the sender from the message Pattern textPattern = Pattern.compile("^[0-9a-zA-Z+]+: (.*)"); Matcher m2 = textPattern.matcher(t); if (t.contains(":") && m2.find()) { t = m2.group(1); Log.d(TAG, "stripped the message"); } } } final SpamDB db = new SpamDB(context); db.open(); if (db.isInDB(smsMessage[0].getOriginatingAddress())) { silent = true; } db.close(); if (action.equals(ACTION_SMS_NEW)) { // API19+: save message to the database ContentValues values = new ContentValues(); values.put("address", s); values.put("body", t); context.getContentResolver().insert(Uri.parse("content://sms/inbox"), values); } } } else if (ACTION_MMS_OLD.equals(action) || ACTION_MMS_MEW.equals(action)) { t = MMS_BODY; // TODO API19+ MMS code } if (!silent) { int count = MAX_SPINS; do { try { Thread.sleep(SLEEP); } catch (InterruptedException e) { e.printStackTrace(); } --count; } while (updateNewMessageNotification(context, t) <= 0 && count > 0); if (count == 0) { // use messages as they are available updateNewMessageNotification(context, null); } } } wakelock.release(); Log.i(TAG, "wakelock released"); }
From source file:net.xisberto.work_schedule.alarm.AlarmMessageActivity.java
private void prepareSound(Context context, Uri alert) { mMediaPlayer = new MediaPlayer(); mMediaPlayer.setWakeMode(context, PowerManager.PARTIAL_WAKE_LOCK); try {/*w w w . jav a 2 s . c o m*/ mMediaPlayer.setDataSource(context, alert); final AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); if (audioManager.getStreamVolume(AudioManager.STREAM_ALARM) != 0) { mMediaPlayer.setAudioStreamType(AudioManager.STREAM_ALARM); mMediaPlayer.setLooping(true); mMediaPlayer.prepare(); } } catch (IOException e) { System.out.println("OOPS"); } }
From source file:app.wz.MainActivity.java
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); self = this;/*ww w . j a va 2 s . c o m*/ requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); setProgressBarIndeterminateVisibility(false); setContentView(R.layout.layout_main); // initialize your android device sensor capabilities mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE); powerManager = (PowerManager) getSystemService(POWER_SERVICE); wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "MyWakelockTag"); wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE); lock = wifiManager.createWifiLock(WifiManager.WIFI_MODE_FULL, "LockTag"); prefs = PreferenceManager.getDefaultSharedPreferences(this.getApplicationContext()); textScroll = (ScrollView) findViewById(R.id.textScroll); textRead = (TextView) findViewById(R.id.textRead); commStatus = (TextView) findViewById(R.id.commStatus); pingStatus = (TextView) findViewById(R.id.pingStatus); inputCmd = (EditText) findViewById(R.id.inputCmd); inputVal = (EditText) findViewById(R.id.inputVal); gb = (GlobalApp) getApplication(); gb.bt = new BluetoothSPP(this); bt = gb.bt; gb.arduino = new ArduinoFirmata(this, bt); arduino = gb.arduino; gb.neuro = new NeuroInterface(prefs, gb); neuro = gb.neuro; if (prefs.getBoolean("autoload", false)) { if (neuro.loadWeights(prefs.getString("last_save", ""))) { textRead.append("Restored Weights at Step " + neuro.count + "\n"); textScroll.fullScroll(View.FOCUS_DOWN); } } if (!bt.isBluetoothAvailable()) { Toast.makeText(getApplicationContext(), "Bluetooth is not available", Toast.LENGTH_SHORT).show(); finish(); } bt.setOnDataReceivedListener(new OnDataReceivedListener() { public void onDataReceived(byte[] data, String message) { gb.lastResponseBT = System.currentTimeMillis(); arduino.processInput(data); } }); bt.setBluetoothConnectionListener(new BluetoothConnectionListener() { public void onDeviceDisconnected() { haltNeuro(); commStatus.setText("Status : Not Connected"); menu.clear(); getMenuInflater().inflate(R.menu.connection, menu); } public void onDeviceConnectionFailed() { commStatus.setText("Status : Connection Failed"); } public void onDeviceConnected(String name, String address) { commStatus.setText("Status : Connected to " + name); menu.clear(); getMenuInflater().inflate(R.menu.disconnection, menu); } }); // bt.setAutoConnectionListener(new BluetoothSPP.AutoConnectionListener() { // public void onNewConnection(String name, String address) { // Log.i("Check", "New Connection - " + name + " - " + address); // } // // public void onAutoConnectionStarted() { // Log.i("Check", "Auto connection started"); // } // }); if (!bt.isBluetoothEnabled()) { Intent intent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); startActivityForResult(intent, BluetoothState.REQUEST_ENABLE_BT); } else { if (!bt.isServiceAvailable()) { bt.setupService(); bt.startService(BluetoothState.DEVICE_ANDROID); setup(); } } refreshPing.start(); neuroThread.start(); new Thread() { public void run() { while (true) { try { Thread.sleep(500); } catch (InterruptedException e) { e.printStackTrace(); } if (neuro.count > neuro.lastDisplay) { neuro.lastDisplay = neuro.count; runOnUiThread(new Runnable() { @Override public void run() { if (!neuro.halt) { textRead.append( "P err: " + (new DecimalFormat("0.000E0")).format(neuro.avg_error) + " O err: " + (new DecimalFormat("0.000E0")).format(neuro.avg_obj_error) + " stp: " + neuro.count + "\n"); textScroll.fullScroll(View.FOCUS_DOWN); } } }); } } } }.start(); new Thread() { public void run() { while (true) { try { Thread.sleep(10000); } catch (InterruptedException e) { e.printStackTrace(); } runOnUiThread(new Runnable() { @Override public void run() { if (textRead.length() > 20000) textRead.setText(""); } }); } } }.start(); }
From source file:com.mishiranu.dashchan.content.service.AudioPlayerService.java
@TargetApi(Build.VERSION_CODES.LOLLIPOP) @Override/*from w ww. j a v a2 s .c om*/ public void onCreate() { super.onCreate(); audioManager = (AudioManager) getSystemService(AUDIO_SERVICE); notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); int notificationColor = 0; if (C.API_LOLLIPOP) { Context themedContext = new ContextThemeWrapper(this, Preferences.getThemeResource()); notificationColor = ResourceUtils.getColor(themedContext, android.R.attr.colorAccent); } this.notificationColor = notificationColor; PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE); wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "AudioPlayerWakeLock"); wakeLock.setReferenceCounted(false); context = new ContextThemeWrapper(this, R.style.Theme_Special_Notification); }