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.elekso.potfix.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); PowerManager pm = (PowerManager) getApplicationContext() .getSystemService(getApplicationContext().POWER_SERVICE); PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, " POTFIX holding wake lock"); wl.acquire();/* w w w . ja v a 2 s. co m*/ Globals.getInstance().setFlexiblemap(true); // // // new Thread(new Runnable(){ // @Override // public void run() { // try { // LALpotfixservicePortBinding service = new LALpotfixservicePortBinding(); // try { // globaldata_test=service.CheckWS("mandar"); // // } catch (Exception e) { // e.printStackTrace(); // } // } catch (Exception ex) { // ex.printStackTrace(); // } // } // }).start(); String login = ""; // Config.getInstance(getBaseContext(),getCacheDir()).setProfile("df","asd"); login = Config.getInstance(getBaseContext(), getCacheDir()).getProfileName(); if (login == null || login.isEmpty()) { Intent intent = new Intent(this, LoginActivity.class); startActivity(intent); return; } //remove // Stetho.initializeWithDefaults(this); // Toolbar Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); // Drawer drawer = (DrawerLayout) findViewById(R.id.drawer_layout); ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); drawer.setDrawerListener(toggle); toggle.syncState(); tusername = (TextView) drawer.findViewById(R.id.tvusername); // tuseremail =(TextView) findViewById(R.id.tvuseremail); // // if(login!=null) // tusername.setText("jhjhjhjh"); // if(Config.getInstance().getProfileEmail()!=null) //tuseremail.setText(Config.getInstance().getProfileEmail()); // FAB fab = (FloatingActionButton) findViewById(R.id.fab); fab.setRippleColor(Color.parseColor("#78D6F3")); fab.setBackgroundTintList(ColorStateList.valueOf(Color.parseColor("#039FDC"))); fab.setImageResource(R.drawable.ic_gps_fixed_white_24dp); fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { switch (currentFragment) { case 1: //profile Snackbar.make(view, "Updating Information", Snackbar.LENGTH_LONG).setAction("Action", null) .show(); Fragment frg = new ProfileFragment(); FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); transaction.replace(R.id.frame_containerone, frg); transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); transaction.commit(); break; case 2: //map if (Globals.getInstance().getFlexiblemap()) { Snackbar.make(view, "Free to Scroll", Snackbar.LENGTH_LONG).setAction("Action", null) .show(); Globals.getInstance().setFlexiblemap(false); fab.setRippleColor(Color.parseColor("#FFE082")); fab.setBackgroundTintList(ColorStateList.valueOf(Color.parseColor("#FFB300"))); fab.setImageResource(R.drawable.ic_gps_off_white_24dp); } else { Snackbar.make(view, "Follow Potfix", Snackbar.LENGTH_LONG).setAction("Action", null).show(); Globals.getInstance().setFlexiblemap(true); fab.setRippleColor(Color.parseColor("#78D6F3")); fab.setBackgroundTintList(ColorStateList.valueOf(Color.parseColor("#039FDC"))); fab.setImageResource(R.drawable.ic_gps_fixed_white_24dp); } break; case 3: //share //Snackbar.make(view, "Some sharing action", Snackbar.LENGTH_LONG).setAction("Action", null).show(); String[] TO = { "aziz@potfix.com" }; String[] CC = { "" }; Intent emailIntent = new Intent(Intent.ACTION_SEND); emailIntent.setData(Uri.parse("mailto:")); emailIntent.setType("text/plain"); emailIntent.putExtra(Intent.EXTRA_EMAIL, TO); emailIntent.putExtra(Intent.EXTRA_CC, CC); emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Potfix Communication"); emailIntent.putExtra(Intent.EXTRA_TEXT, "Email message..."); try { startActivity(Intent.createChooser(emailIntent, "Send mail...")); finish(); } catch (android.content.ActivityNotFoundException ex) { Toast.makeText(MainActivity.this, "There is no email client installed.", Toast.LENGTH_SHORT) .show(); } break; case 4: //legal Snackbar.make(view, "Software License", Snackbar.LENGTH_LONG).setAction("Action", null).show(); drawer.openDrawer(Gravity.LEFT); break; } } }); NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view); navigationView.setNavigationItemSelectedListener(this); startService(new Intent(getBaseContext(), BackgroundService.class)); FragmentTransaction mTransaction = getSupportFragmentManager().beginTransaction(); MapsFragment mFRaFragment = new MapsFragment(); mTransaction.add(R.id.frame_containerone, mFRaFragment); mTransaction.commit(); LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE); if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) { Toast.makeText(this, "GPS is Enabled in your devide", Toast.LENGTH_SHORT).show(); } else { showGPSDisabledAlertToUser(); } // if (locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)){ // Toast.makeText(this, "Network is Enabled in your devide", Toast.LENGTH_SHORT).show(); // }else{ // showNetDisabledAlertToUser(); // } createNotification(); }
From source file:net.oddsoftware.android.feedscribe.data.Downloader.java
private Downloader(Context ctx) { mContext = ctx;/*from w w w . j a va2 s. c o m*/ mThreadPool = Executors.newFixedThreadPool(4); mFeedManager = FeedManager.getInstance(mContext); mDownloadCount = 0; mWakeLock = ((PowerManager) ctx.getSystemService(Context.POWER_SERVICE)) .newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "FeedScribe.Downloader"); mWakeLock.setReferenceCounted(false); mAwakeChecker = new Thread() { @Override public void run() { try { while (true) { Thread.sleep(mAwakeInterval); checkAwake(); } } catch (InterruptedException exc) { return; } } }; mAwakeChecker.start(); }
From source file:it.baywaylabs.jumpersumo.utility.FTPDownloadImage.java
/** * Method auto invoked pre execute the task.<br /> *///www .j a v a 2 s . c om @Override protected void onPreExecute() { super.onPreExecute(); // take CPU lock to prevent CPU from going off if the user // presses the power button during download PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, getClass().getName()); mWakeLock.acquire(); }
From source file:net.pmarks.chromadoze.NoiseService.java
@Override public void onCreate() { // Set up a message handler in the main thread. mPercentHandler = new PercentHandler(); AudioParams params = new AudioParams(); mSampleShuffler = new SampleShuffler(params); mSampleGenerator = new SampleGenerator(this, params, mSampleShuffler); PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "ChromaDoze Wake Lock"); mWakeLock.acquire();/*from ww w . j a v a2 s .c om*/ startForeground(NOTIFY_ID, makeNotify()); // Note: This leaks memory if I use "this" instead of "getApplicationContext()". mAudioFocusHelper = new AudioFocusHelper(getApplicationContext(), mSampleShuffler.getVolumeListener()); }
From source file:singh.amandeep.musicplayer.MediaButtonIntentReceiver.java
private static void acquireWakeLockAndSendMessage(Context context, Message msg, long delay) { if (mWakeLock == null) { Context appContext = context.getApplicationContext(); PowerManager pm = (PowerManager) appContext.getSystemService(Context.POWER_SERVICE); mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "Eleven headset button"); mWakeLock.setReferenceCounted(false); }// ww w .ja v a 2 s . c om // Make sure we don't indefinitely hold the wake lock under any circumstances mWakeLock.acquire(10000); mHandler.sendMessageDelayed(msg, delay); }
From source file:com.achow101.bitcointalkforum.NotificationService.java
private void handleIntent(Intent intent) { // obtain the wake lock PowerManager pm = (PowerManager) getSystemService(POWER_SERVICE); mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "NotificationService"); mWakeLock.acquire();//from ww w. j a va 2 s .c o m // get sessid and username from intent String sessId = intent.getStringExtra("SESSION ID"); String mUsername = intent.getStringExtra("Username"); // check the global background data setting ConnectivityManager cm = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE); if (!cm.getBackgroundDataSetting()) { stopSelf(); return; } // Get preferences SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); // Check that notifications are wanted boolean getNotifs = prefs.getBoolean("notifications_new_message", true); // do stuff if notifications are wanted if (getNotifs) { // get remaining booleans boolean getWatchlist = prefs.getBoolean("notifications_watchlist", true); boolean getUnreadposts = prefs.getBoolean("notifications_unreadposts", false); boolean getUnreadreplies = prefs.getBoolean("notifications_unreadreplies", false); boolean getMessages = prefs.getBoolean("notifications_messages", true); // Get notification settings stuff sound = prefs.getString("notifications_new_message_ringtone", "content://settings/system/notification_sound"); vibrate = prefs.getBoolean("notifications_new_message_vibrate", true); // do the actual work, in a separate thread new PollTask(getWatchlist, getUnreadposts, getUnreadreplies, getMessages, sessId, mUsername).execute(); } }
From source file:at.aec.solutions.checkmkagent.AgentService.java
@Override public void onCreate() { super.onCreate(); Log.v(TAG, "onCreate"); PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE); m_wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "MyWakelockTag"); m_wakeLock.acquire();//from ww w .ja va 2 s . c o m //Copy busybox binary to app directory if (!PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getBoolean("bbinstalled", false)) { PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).edit() .putBoolean("bbinstalled", true).commit(); // There is also String[] Build.SUPPORTED_ABIS from API 21 on and // before String Build.CPU_ABI String Build.CPU_ABI2, maybe i should investigate there String arch = System.getProperty("os.arch"); Log.v(TAG, arch); if (arch.equals("armv7l")) { copyAsset(getAssets(), "bbb/busybox", getApplicationInfo().dataDir + "/busybox"); } if (arch.equals("i686")) { copyAsset(getAssets(), "bbb/busybox-i686", getApplicationInfo().dataDir + "/busybox"); } // copyAsset(getAssets(), "bbb/busybox-x86_64", getApplicationInfo().dataDir+"/busybox-x86_64"); changeBusyboxPermission(); } socketServerThread = new Thread(new SocketServerThread()); socketServerThread.setName("CheckMK-Agent ServerThread"); socketServerThread.start(); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_launcher).setContentTitle("CheckMK Agent started.") .setContentText("Listening on Port " + SERVERPORT + ". Tap to configure."); Intent resultIntent = new Intent(this, ConfigureActivity.class); TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); // Adds the back stack for the Intent (but not the Intent itself) stackBuilder.addParentStack(ConfigureActivity.class); // Adds the Intent that starts the Activity to the top of the stack stackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(resultPendingIntent); NotificationManager mNotificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); // mId allows you to update the notification later on. Notification notify = mBuilder.build(); notify.flags |= Notification.FLAG_NO_CLEAR; mNotificationManager.notify(mId, notify); }
From source file:ws.logv.trainmonitor.GCMIntentService.java
@Override protected void onMessage(final Context context, Intent intent) { if (intent.hasExtra("command")) { String command = intent.getStringExtra("command"); if ("sync".equals(command)) { String type = intent.getStringExtra("type"); if ("subscription".equals(type)) { Workflow.getEventBus(context).post(new PullSubscriptionsEvent()); }// ww w.ja v a2 s . c o m } } else { String train = intent.getStringExtra("train"); if (wl == null) { PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "Refresh trains"); } wl.acquire(2000); EventBus bus = Workflow.getEventBus(context); bus.register(this, FetchTrainDetailsResult.class); bus.post(new FetchTrainDetailsCommand(train)); } }
From source file:de.schildbach.wallet.offline.AcceptBluetoothService.java
@Override public void onCreate() { serviceCreatedAt = System.currentTimeMillis(); log.debug(".onCreate()"); super.onCreate(); this.application = (WalletApplication) getApplication(); final BluetoothAdapter bluetoothAdapter = checkNotNull(BluetoothAdapter.getDefaultAdapter()); final PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, getClass().getName()); wakeLock.acquire();/*from w ww. ja v a2 s .c o m*/ registerReceiver(bluetoothStateChangeReceiver, new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED)); try { classicThread = new AcceptBluetoothThread.ClassicBluetoothThread(bluetoothAdapter) { @Override public boolean handleTx(final Transaction tx) { return AcceptBluetoothService.this.handleTx(tx); } }; paymentProtocolThread = new AcceptBluetoothThread.PaymentProtocolThread(bluetoothAdapter) { @Override public boolean handleTx(final Transaction tx) { return AcceptBluetoothService.this.handleTx(tx); } }; } catch (final IOException x) { new Toast(this).longToast(R.string.error_bluetooth, x.getMessage()); log.warn("problem with listening, stopping service", x); CrashReporter.saveBackgroundTrace(x, application.packageInfo()); stopSelf(); } wallet = new WalletLiveData(application); wallet.observe(this, new Observer<Wallet>() { @Override public void onChanged(final Wallet wallet) { classicThread.start(); paymentProtocolThread.start(); } }); }
From source file:edu.cens.loci.sensors.AccelerometerHandler.java
public void start() { if (mIsOn)//from w w w . j a v a 2 s . c om return; mCpuLock = cpu().newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "AccelerometerHandler.CpuLock"); mCpuLock.setReferenceCounted(false); mIsOn = true; if (mDuration > 0) { //mCpuLock.acquire(); mOnTimer = new Timer("sensorTurnOnTimer"); mOffTimer = new Timer("sensorTurnOffTimer"); mOnTimer.scheduleAtFixedRate(new TimerTask() { public void run() { mSensorService = (SensorManager) mCxt.getSystemService(Context.SENSOR_SERVICE); synchronized (this) { MyLog.i(LociConfig.D.ACC, TAG, "[ACC] ON "); mCpuLock.acquire(); mSensorOn = true; mSensorService.registerListener(sInstance, mSensorService.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), mRate); } } }, 0, mPeriod); mOffTimer.scheduleAtFixedRate(new TimerTask() { public void run() { synchronized (this) { MyLog.i(LociConfig.D.ACC, TAG, "[ACC] OFF "); mSensorOn = false; if (mCpuLock.isHeld()) mCpuLock.release(); mSensorService.unregisterListener(sInstance, mSensorService.getDefaultSensor(Sensor.TYPE_ACCELEROMETER)); } // time to turn off sensor -- somehow send data //mXArr.reset(); //mYArr.reset(); //mZArr.reset(); long time = Calendar.getInstance().getTime().getTime(); float magVar = getMagnitudeVariance(); //LociMobileManagerService.getInstance().eventAccelerometerResult(Calendar.getInstance().getTime().getTime(), magVar); mListener.onAccelerometerChanged(time, magVar); //if (LociMobileManagerService.getInstance().isMDOn()) // LociMobileManagerService.getInstance().getSystemDb().updatePowerRow(SystemLogDbAdapter.SENSOR_ACC, System.currentTimeMillis()); } }, mDuration, mPeriod); } else { mCpuLock.acquire(); mSensorService = (SensorManager) mCxt.getSystemService(Context.SENSOR_SERVICE); mSensorService.registerListener(this, mSensorService.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), mRate); mReportTimer = new Timer("SensorReportTimer"); mReportTimer.scheduleAtFixedRate(new TimerTask() { public void run() { // send data long time = Calendar.getInstance().getTime().getTime(); float magVar = getMagnitudeVariance(); mListener.onAccelerometerChanged(time, magVar); //LociMobileManagerService.getInstance().eventAccelerometerResult(Calendar.getInstance().getTime().getTime(), magVar); //if (LociMobileManagerService.getInstance().isMDOn()) // LociMobileManagerService.getInstance().getSystemDb().updatePowerRow(SystemLogDbAdapter.SENSOR_ACC, System.currentTimeMillis()); } }, 0, mDuration); } //LociMobileManagerService.getInstance().getSystemDb().addPowerRow(SystemLogDbAdapter.SENSOR_ACC, System.currentTimeMillis()); startChkTimer(); }