List of usage examples for android.os PowerManager newWakeLock
public WakeLock newWakeLock(int levelAndFlags, String tag)
From source file:nuclei.media.playback.ExoPlayerPlayback.java
public ExoPlayerPlayback(MediaService service) { mService = service;//from w ww .j a va 2 s. co m mHandler = new Handler(); final Context ctx = service.getApplicationContext(); mAudioManager = (AudioManager) ctx.getSystemService(Context.AUDIO_SERVICE); PowerManager powerManager = (PowerManager) ctx.getSystemService(Context.POWER_SERVICE); WifiManager wifiManager = (WifiManager) ctx.getSystemService(Context.WIFI_SERVICE); // Create the Wifi lock (this does not acquire the lock, this just creates it) mWifiLock = wifiManager.createWifiLock(WifiManager.WIFI_MODE_FULL, "nuclei_media_wifi_lock"); mWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "nuclei_media_cpu_lock"); }
From source file:com.bonsai.wallet32.WalletService.java
@Override public void onCreate() { mNM = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); mLBM = LocalBroadcastManager.getInstance(this); mLogger.info("WalletService created"); mApp = (WalletApplication) getApplicationContext(); mContext = getApplicationContext();//from ww w . j a v a 2 s. com mRes = mContext.getResources(); mTimeoutWorker = Executors.newSingleThreadScheduledExecutor(); final String lockName = getPackageName() + " blockchain sync"; final PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, lockName); mPrefs = PreferenceManager.getDefaultSharedPreferences(this); String fiatRateSource = mPrefs.getString(SettingsActivity.KEY_FIAT_RATE_SOURCE, ""); setFiatRateSource(fiatRateSource); // Register for future preference changes. mPrefs.registerOnSharedPreferenceChangeListener(this); // Register with the WalletApplication. mApp.setWalletService(this); }
From source file:activities.Activity_Main.java
/** Called when the activity is first created. */ @Override//w ww. j a va2 s . com public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); myself = this; setContentView(R.layout.activity_home); SP_params = PreferenceManager.getDefaultSharedPreferences(this); SP_prefEditor = SP_params.edit(); Tracer = tracerengine.getInstance(SP_params); //Added by Doume File storage = new File(Environment.getExternalStorageDirectory() + "/domodroid/.conf/"); if (!storage.exists()) storage.mkdirs(); //Configure Tracer tool initial state File logpath = new File(Environment.getExternalStorageDirectory() + "/domodroid/.log/"); if (!logpath.exists()) logpath.mkdirs(); String currlogpath = SP_params.getString("LOGNAME", ""); if (currlogpath.equals("")) { //Not yet existing prefs : Configure debugging by default, to configure Tracer currlogpath = Environment.getExternalStorageDirectory() + "/domodroid/.log/"; SP_prefEditor.putString("LOGPATH", currlogpath); SP_prefEditor.putString("LOGNAME", "Domodroid.txt"); SP_prefEditor.putBoolean("SYSTEMLOG", false); SP_prefEditor.putBoolean("TEXTLOG", false); SP_prefEditor.putBoolean("SCREENLOG", false); SP_prefEditor.putBoolean("LOGCHANGED", true); SP_prefEditor.putBoolean("LOGAPPEND", false); } else { SP_prefEditor.putBoolean("LOGCHANGED", true); //To force Tracer to consider current settings } //prefEditor.putBoolean("SYSTEMLOG", false); // For tests : no system logs.... SP_prefEditor.putBoolean("SYSTEMLOG", true); // For tests : with system logs.... SP_prefEditor.commit(); Tracer.set_profile(SP_params); // Create .nomedia file, that will prevent Android image gallery from showing domodroid file String nomedia = Environment.getExternalStorageDirectory() + "/domodroid/.nomedia"; try { if (!(new File(nomedia).exists())) { new FileOutputStream(nomedia).close(); } } catch (Exception e) { } appname = (ImageView) findViewById(R.id.app_name); LoadSelections(); // Prepare a listener to know when a sync dialog is closed... if (sync_listener == null) { sync_listener = new DialogInterface.OnDismissListener() { public void onDismiss(DialogInterface dialog) { Tracer.d(mytag, "sync dialog has been closed !"); // Is it success or fail ? if (((Dialog_Synchronize) dialog).need_refresh) { // Sync has been successful : Force to refresh current main view Tracer.d(mytag, "sync dialog requires a refresh !"); reload = true; // Sync being done, consider shared prefs are OK VG_parent.removeAllViews(); if (WU_widgetUpdate != null) { WU_widgetUpdate.resync(); } else { Tracer.i(mytag + ".onCreate", "WidgetUpdate is null startCacheengine!"); startCacheEngine(); } Bundle b = new Bundle(); //Notify sync complete to parent Dialog b.putInt("id", 0); b.putString("type", "root"); Message msg = new Message(); msg.setData(b); if (widgetHandler != null) widgetHandler.sendMessage(msg); // That should force to refresh Views /* */ if (WU_widgetUpdate != null) { WU_widgetUpdate.Disconnect(0); //That should disconnect all opened widgets from cache engine //widgetUpdate.dump_cache(); //For debug dont_kill = true; // to avoid engines kill when onDestroy() } onResume(); } else { Tracer.d(mytag, "sync dialog end with no refresh !"); } ((Dialog_Synchronize) dialog).need_refresh = false; } }; } //update thread sbanim = new Handler() { @Override public void handleMessage(Message msg) { if (msg.what == 0) { appname.setImageDrawable(getResources().getDrawable(R.drawable.app_name2)); } else if (msg.what == 1) { appname.setImageDrawable(getResources().getDrawable(R.drawable.app_name3)); } else if (msg.what == 2) { appname.setImageDrawable(getResources().getDrawable(R.drawable.app_name1)); } else if (msg.what == 3) { appname.setImageDrawable(getResources().getDrawable(R.drawable.app_name4)); } else if (msg.what == 8000) { Tracer.e(mytag, "Request to display message : 8000"); /* if(dialog_message == null) { Create_message_box(); } dialog_message.setMessage("Starting cache engine..."); dialog_message.show(); */ } else if (msg.what == 8999) { //Cache engine is ready for use.... if (Tracer != null) Tracer.e(mytag, "Cache engine has notified it's ready !"); cache_ready = true; if (end_of_init_requested) end_of_init(); PG_dialog_message.dismiss(); } } }; //power management final PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); this.PM_WakeLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, ""); this.PM_WakeLock.acquire(); //titlebar final FrameLayout titlebar = (FrameLayout) findViewById(R.id.TitleBar); titlebar.setBackgroundDrawable(Gradients_Manager.LoadDrawable("title", 40)); //Parent view VG_parent = (ViewGroup) findViewById(R.id.home_container); LL_house_map = new LinearLayout(this); LL_house_map .setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); LL_house_map.setOrientation(LinearLayout.HORIZONTAL); LL_house_map.setPadding(5, 5, 5, 5); house = new Basic_Graphical_zone(getApplicationContext(), 0, Graphics_Manager.Names_Agent(this, "House"), "", "house", 0, "", null); house.setPadding(0, 0, 5, 0); map = new Basic_Graphical_zone(getApplicationContext(), 0, Graphics_Manager.Names_Agent(this, "Map"), "", "map", 0, "", null); map.setPadding(5, 0, 0, 0); LinearLayout.LayoutParams param = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT, 1.0f); house.setLayoutParams(param); house.setOnClickListener(new OnClickListener() { public void onClick(View v) { if (SP_params.getBoolean("SYNC", false)) { loadWigets(0, "root"); historyPosition++; history.add(historyPosition, new String[] { "0", "root" }); } else { if (AD_notSyncAlert == null) createAlert(); AD_notSyncAlert.show(); } } }); map.setLayoutParams(param); map.setOnClickListener(new OnClickListener() { public void onClick(View v) { if (SP_params.getBoolean("SYNC", false)) { //dont_freeze=true; //To avoid WidgetUpdate engine freeze Tracer.w(mytag, "Before call to Map, Disconnect widgets from engine !"); if (WU_widgetUpdate != null) { WU_widgetUpdate.Disconnect(0); //That should disconnect all opened widgets from cache engine //widgetUpdate.dump_cache(); //For debug dont_kill = true; // to avoid engines kill when onDestroy() } INTENT_map = new Intent(Activity_Main.this, Activity_Map.class); Tracer.d(mytag, "Call to Map, run it now !"); Tracer.Map_as_main = false; startActivity(INTENT_map); } else { if (AD_notSyncAlert == null) createAlert(); AD_notSyncAlert.show(); } } }); LL_house_map.addView(house); LL_house_map.addView(map); init_done = false; // Detect if it's the 1st use after installation... if (!SP_params.getBoolean("SPLASH", false)) { // Yes, 1st use ! init_done = false; reload = false; if (backupprefs.exists()) { // A backup exists : Ask if reload it Tracer.v(mytag, "settings backup found after a fresh install..."); DialogInterface.OnClickListener reload_listener = new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { Tracer.e(mytag, "Reload dialog returns : " + which); if (which == dialog.BUTTON_POSITIVE) { reload = true; } else if (which == dialog.BUTTON_NEGATIVE) { reload = false; } check_answer(); dialog.dismiss(); } }; dialog_reload = new AlertDialog.Builder(this); dialog_reload.setMessage(getText(R.string.home_reload)); dialog_reload.setTitle(getText(R.string.reload_title)); dialog_reload.setPositiveButton(getText(R.string.reloadOK), reload_listener); dialog_reload.setNegativeButton(getText(R.string.reloadNO), reload_listener); dialog_reload.show(); init_done = false; //A choice is pending : Rest of init has to be completed... } else { //No settings backup found Tracer.v(mytag, "no settings backup found after fresh install..."); end_of_init_requested = true; // open server config view Intent helpI = new Intent(Activity_Main.this, Preference.class); startActivity(helpI); } } else { // It's not the 1st use after fresh install // This method will be followed by 'onResume()' end_of_init_requested = true; } if (SP_params.getBoolean("SYNC", false)) { //A config exists and a sync as been done by past. if (WU_widgetUpdate == null) { Tracer.i(mytag + ".onCreate", "Params splach is false and WidgetUpdate is null startCacheengine!"); startCacheEngine(); } } Tracer.e(mytag, "OnCreate() complete !"); // End of onCreate (UIThread) }
From source file:org.videolan.vlc.AudioService.java
@Override public void onCreate() { super.onCreate(); // Get libVLC instance try {// w w w .ja va 2s. c o m mLibVLC = Util.getLibVlcInstance(); } catch (LibVlcException e) { e.printStackTrace(); } Thread.setDefaultUncaughtExceptionHandler(new VlcCrashHandler()); mCallback = new HashMap<IAudioServiceCallback, Integer>(); mMediaList = new ArrayList<Media>(); mPrevious = new Stack<Media>(); mEventHandler = EventHandler.getInstance(); mRemoteControlClientReceiverComponent = new ComponentName(getPackageName(), RemoteControlClientReceiver.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 stop. PowerManager pm = (PowerManager) 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(ACTION_REMOTE_LAST_PLAYLIST); filter.addAction(Intent.ACTION_HEADSET_PLUG); filter.addAction(AudioManager.ACTION_AUDIO_BECOMING_NOISY); filter.addAction(VLCApplication.SLEEP_INTENT); registerReceiver(serviceReceiver, filter); final SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(this); boolean stealRemoteControl = pref.getBoolean("enable_steal_remote_control", false); if (!Util.isFroyoOrLater() || stealRemoteControl) { /* Backward compatibility for API 7 */ filter = new IntentFilter(); if (stealRemoteControl) filter.setPriority(Integer.MAX_VALUE); filter.addAction(Intent.ACTION_MEDIA_BUTTON); mRemoteControlClientReceiver = new RemoteControlClientReceiver(); registerReceiver(mRemoteControlClientReceiver, filter); } AudioUtil.prepareCacheFolder(this); }
From source file:com.android.dialer.voicemail.VoicemailPlaybackPresenter.java
/** * Initialize variables which are activity-independent and state-independent. */// w w w .j a v a 2 s . co 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:org.zeroxlab.benchmark.Benchmark.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); orientation = getResources().getConfiguration().orientation; PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); mWakeLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, TAG); mWakeLock.acquire();/* w w w .j a v a 2 s. c o m*/ sTexture = new BitmapShader(BitmapFactory.decodeResource(getResources(), R.drawable.crate), TileMode.REPEAT, TileMode.REPEAT); setContentView(R.layout.main); mCases = new LinkedList<Case>(); Case arith = new CaseArithmetic(); Case javascript = new CaseJavascript(); Case scimark2 = new CaseScimark2(); Case glcube = new CaseGLCube(); Case nehe08 = new CaseNeheLesson08(); Case nehe16 = new CaseNeheLesson16(); Case teapot = new CaseTeapot(); Case gc = new CaseGC(); Case libMicro = new NativeCaseMicro(); Case libUbench = new NativeCaseUbench(); Case canvas = new CaseCanvas(true, false, false); Case dc2 = new CaseDrawCircle2(); Case dr = new CaseDrawRect(); Case da = new CaseDrawArc(); Case di = new CaseDrawImage(); Case dt = new CaseDrawText(); mCategory.put(D2, new HashSet<Case>()); mCategory.put(D2HW, new HashSet<Case>()); mCategory.put(D2SW1, new HashSet<Case>()); mCategory.put(D2SW2, new HashSet<Case>()); mCategory.put(D3, new HashSet<Case>()); mCategory.put(MATH, new HashSet<Case>()); mCategory.put(VM, new HashSet<Case>()); mCategory.put(NATIVE, new HashSet<Case>()); mCategory.put(MISC, new HashSet<Case>()); // mflops mCases.add(arith); mCases.add(scimark2); mCases.add(javascript); mCategory.get(MATH).add(arith); mCategory.get(MATH).add(scimark2); mCategory.get(MISC).add(javascript); // 2d mCases.add(canvas); mCases.add(dc2); mCases.add(dr); mCases.add(da); mCases.add(di); mCases.add(dt); mCategory.get(D2).add(canvas); mCategory.get(D2).add(dc2); mCategory.get(D2).add(dr); mCategory.get(D2).add(da); mCategory.get(D2).add(di); mCategory.get(D2).add(dt); Case canvas2 = new CaseCanvas(false, false, false);//HW Case canvas3 = new CaseCanvas(false, true, false);//SW Window Case canvas4 = new CaseCanvas(false, false, true);//SW Layer Case circle = new CaseDrawCircle(false, false, false);//HW Case circle2 = new CaseDrawCircle(false, true, false);//SW Window Case circle3 = new CaseDrawCircle(false, false, true);//SW Layer Case dc22 = new CaseDrawCircle2(false, false, false);//HW Case dc23 = new CaseDrawCircle2(false, true, false);//SW Window Case dc24 = new CaseDrawCircle2(false, false, true);//SW Layer Case dr2 = new CaseDrawRect(false, false, false);//HW Case dr3 = new CaseDrawRect(false, true, false);//SW Window Case dr4 = new CaseDrawRect(false, false, true);//SW Layer Case da2 = new CaseDrawArc(false, false, false);//HW Case da3 = new CaseDrawArc(false, true, false);//SW Window Case da4 = new CaseDrawArc(false, false, true);//SW Layer Case di2 = new CaseDrawImage(false, false, false);//HW Case di3 = new CaseDrawImage(false, true, false);//SW Window Case di4 = new CaseDrawImage(false, false, true);//SW Layer Case dt2 = new CaseDrawText(false, false, false);//HW Case dt3 = new CaseDrawText(false, true, false);//SW Window Case dt4 = new CaseDrawText(false, false, true);//SW Layer mCases.add(canvas2); mCases.add(circle); mCases.add(dc22); mCases.add(dr2); mCases.add(da2); mCases.add(di2); mCases.add(dt2); mCases.add(canvas3); mCases.add(circle2); mCases.add(dc23); mCases.add(dr3); mCases.add(da3); mCases.add(di3); mCases.add(dt3); mCases.add(canvas4); mCases.add(circle3); mCases.add(dc24); mCases.add(dr4); mCases.add(da4); mCases.add(di4); mCases.add(dt4); //2d(HW) mCategory.get(D2HW).add(canvas2); mCategory.get(D2HW).add(circle); mCategory.get(D2HW).add(dc22); mCategory.get(D2HW).add(da2); mCategory.get(D2HW).add(dr2); mCategory.get(D2HW).add(di2); mCategory.get(D2HW).add(dt2); //2d(SW1) mCategory.get(D2SW1).add(canvas3); mCategory.get(D2SW1).add(circle2); mCategory.get(D2SW1).add(dc23); mCategory.get(D2SW1).add(da3); mCategory.get(D2SW1).add(dr3); mCategory.get(D2SW1).add(di3); mCategory.get(D2SW1).add(dt3); //2d(SW2) mCategory.get(D2SW2).add(canvas4); mCategory.get(D2SW2).add(circle3); mCategory.get(D2SW2).add(dc24); mCategory.get(D2SW2).add(da4); mCategory.get(D2SW2).add(dr4); mCategory.get(D2SW2).add(di4); mCategory.get(D2SW2).add(dt4); // 3d mCases.add(glcube); mCases.add(nehe08); mCases.add(nehe16); mCases.add(teapot); mCategory.get(D3).add(glcube); mCategory.get(D3).add(nehe08); mCategory.get(D3).add(nehe16); mCategory.get(D3).add(teapot); // vm mCases.add(gc); mCategory.get(VM).add(gc); // native mCases.add(libMicro); mCases.add(libUbench); mCategory.get(NATIVE).add(libMicro); mCategory.get(NATIVE).add(libUbench); initViews(); Intent intent = getIntent(); Bundle bundle = intent.getExtras(); if (bundle != null) { mAutoRun = bundle.getBoolean("autorun"); mCheckMath = bundle.getBoolean("math"); mCheck2D = bundle.getBoolean("2d"); mCheck3D = bundle.getBoolean("3d"); mCheckVM = bundle.getBoolean("vm"); mCheckNative = bundle.getBoolean("native"); mAutoUpload = bundle.getBoolean("autoupload"); } if (mCheckMath && !mathCheckBox.isChecked()) { mathCheckBox.performClick(); } if (mCheck2D && !d2CheckBox.isChecked()) { d2CheckBox.performClick(); } if (mCheck3D && !d3CheckBox.isChecked()) { d3CheckBox.performClick(); } if (mCheckVM && !vmCheckBox.isChecked()) { vmCheckBox.performClick(); } if (mCheckNative && !nativeCheckBox.isChecked()) { nativeCheckBox.performClick(); } if (mCheckMisc && !miscCheckBox.isChecked()) { miscCheckBox.performClick(); } /* if (intent.getBooleanExtra("AUTO", false)) { ImageView head = (ImageView)findViewById(R.id.banner_img); head.setImageResource(R.drawable.icon_auto); mTouchable = false; initAuto(); } */ if (mAutoRun) { onClick(mRun); } }
From source file:com.android.dragonkeyboardfirmwareupdater.KeyboardFirmwareUpdateService.java
private void startDfuService(String keyboardName, String keyboardAddress) { Log.d(TAG, "startDfuService"); changeDfuStatus(DFU_STATE_UPDATING); PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG); mWakeLock.acquire();/*w w w .j ava 2 s . c o m*/ String packageName = getApplicationContext().getPackageName(); int initResourceId = getResources().getIdentifier(getString(R.string.target_firmware_init_file_name), "raw", packageName); int imageResourceId = getResources().getIdentifier(getString(R.string.target_firmware_image_file_name), "raw", packageName); boolean keepBond = true; Log.d(TAG, "Name: " + keyboardName + "\n" + "Address: " + keyboardAddress + "\n" + "Init file: " + getString(R.string.target_firmware_init_file_name) + "\n" + "Image file: " + getString(R.string.target_firmware_image_file_name) + "\n" + "Image type: Application(" + DfuService.TYPE_APPLICATION + ")\n" + "Keep bond: " + keepBond); final Intent service = new Intent(this, DfuService.class); service.putExtra(DfuService.EXTRA_DEVICE_NAME, keyboardName); service.putExtra(DfuService.EXTRA_DEVICE_ADDRESS, keyboardAddress); service.putExtra(DfuService.EXTRA_INIT_FILE_RES_ID, initResourceId); service.putExtra(DfuService.EXTRA_FILE_RES_ID, imageResourceId); service.putExtra(DfuService.EXTRA_FILE_TYPE, DfuService.TYPE_APPLICATION); service.putExtra(DfuService.EXTRA_KEEP_BOND, true); startService(service); }
From source file:org.restcomm.app.qoslib.Services.Intents.IntentHandler.java
/** * constructor/*from www.ja v a2 s . c om*/ */ public IntentHandler(MainService owner, DataMonitorStats dataMonitorStats) { this.owner = owner; this.dataMonitorStats = dataMonitorStats; PowerManager powerManager = (PowerManager) owner.getSystemService(owner.POWER_SERVICE); wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "MyWakelockTag"); gson = new Gson(); reportManager = owner.getReportManager(); }
From source file:com.almarsoft.GroundhogReader.MessageListActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.messagelist); Context context = getApplicationContext(); // Config checker alert dialog mConfigAlert = new AlertDialog.Builder(this).create(); mConfigAlert.setButton(getString(R.string.ok), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dlg, int sumthin) { startActivity(new Intent(MessageListActivity.this, OptionsActivity.class)); }/* w w w . j av a 2 s .c o m*/ }); mNumUnread = 0; // Loaded in OnResume || threadMessagesFromDB() mPrefs = PreferenceManager.getDefaultSharedPreferences(this); mOfflineMode = mPrefs.getBoolean("offlineMode", true); // Get the selected group from the GroupListActivity-passed bundle mTitleBar = (TextView) this.findViewById(R.id.topbar_text); mGroup = getIntent().getExtras().getString("selectedGroup"); mGroupID = DBUtils.getGroupIdFromName(mGroup, context); mGoGroups = (ImageButton) this.findViewById(R.id.btn_gogroups); mGoGroups.setOnClickListener(new OnClickListener() { public void onClick(View v) { MessageListActivity.this .startActivity(new Intent(MessageListActivity.this, GroupListActivity.class)); } }); mServerManager = new ServerManager(context); PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); mWakeLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE, "GroundhogThreading"); mMsgList = (ListView) this.findViewById(R.id.list_msgs); mMsgList.setOnItemClickListener(mListItemClickListener); registerForContextMenu(mMsgList); Drawable dw = getResources().getDrawable(R.drawable.greyline2); mMsgList.setDivider(dw); // Show the progress dialog, get messages from server, write to DB // and call the loading of message from DB and threading when it ends mWakeLock.acquire(); threadMessagesFromDB(); }
From source file:org.spontaneous.trackservice.RemoteService.java
private void updateWakeLock() { if (this.mLoggingState == TrackingServiceConstants.LOGGING) { // PreferenceManager.getDefaultSharedPreferences(this).registerOnSharedPreferenceChangeListener(mSharedPreferenceChangeListener); PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); if (this.mWakeLock != null) { this.mWakeLock.release(); this.mWakeLock = null; }/*from www .j av a 2s . c om*/ this.mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG); this.mWakeLock.acquire(); } else { if (this.mWakeLock != null) { this.mWakeLock.release(); this.mWakeLock = null; } } }