List of usage examples for android.os PowerManager ON_AFTER_RELEASE
int ON_AFTER_RELEASE
To view the source code for android.os PowerManager ON_AFTER_RELEASE.
Click Source Link
From source file:com.googlecode.eyesfree.brailleback.DisplayManager.java
/** * Creates an instance of this class and starts the internal thread to * connect to the braille display service. {@code context} is used to * connect to the display service. {@code translator} is used for braille * translation. The various listeners will be called as appropriate and * on the same thread that was used to create this object. The current * thread must have a prepared looper./* w w w. j a v a2 s.co m*/ */ public DisplayManager(TranslatorManager translatorManager, Context context, OnPanOverflowListener panOverflowListener, Display.OnConnectionStateChangeListener connectionStateChangeListener, OnMappedInputEventListener mappedInputEventListener) { mTranslatorManager = translatorManager; mTranslatorManager.addOnTablesChangedListener(this); mContext = context; mPanOverflowListener = panOverflowListener; mConnectionStateChangeListener = connectionStateChangeListener; mMappedInputEventListener = mappedInputEventListener; PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); mWakeLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE, "BrailleBack"); mHandlerThread = new HandlerThread("DisplayManager") { @Override public void onLooperPrepared() { mDisplay = new OverlayDisplay(mContext, new DisplayClient(mContext)); mDisplay.setOnConnectionStateChangeListener(DisplayManager.this); mDisplay.setOnInputEventListener(DisplayManager.this); } }; mHandlerThread.start(); mDisplayHandler = new DisplayHandler(mHandlerThread.getLooper()); mCallbackHandler = new CallbackHandler(); }
From source file:net.czlee.debatekeeper.AlertManager.java
/** * Wakes up the screen to attract user attention *///from w w w .ja va 2 s . c o m public void wakeUpScreenForPause() { int flags = PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.FULL_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE; PowerManager.WakeLock temporaryWakeLock = mPowerManager.newWakeLock(flags, "Debatekeeper-pause"); temporaryWakeLock.acquire(3000); }
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//from w ww .j a v a2 s . c o m .newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE, TAG); wakeLock.acquire(); } }
From source file:com.devbrackets.android.exomedia.core.exoplayer.EMExoPlayer.java
/** * This function has the MediaPlayer access the low-level power manager * service to control the device's power usage while playing is occurring. * The parameter is a combination of {@link android.os.PowerManager} wake flags. * Use of this method requires {@link android.Manifest.permission#WAKE_LOCK} * permission./*from w ww . ja v a2s . com*/ * By default, no attempt is made to keep the device awake during playback. * * @param context the Context to use * @param mode the power/wake mode to set * @see android.os.PowerManager */ public void setWakeMode(Context context, int mode) { boolean wasHeld = false; if (wakeLock != null) { if (wakeLock.isHeld()) { wasHeld = true; wakeLock.release(); } wakeLock = null; } //Acquires the wakelock if we have permissions to if (context.getPackageManager().checkPermission(Manifest.permission.WAKE_LOCK, context.getPackageName()) == PackageManager.PERMISSION_GRANTED) { PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); wakeLock = pm.newWakeLock(mode | PowerManager.ON_AFTER_RELEASE, EMExoPlayer.class.getName()); wakeLock.setReferenceCounted(false); } else { Log.w(TAG, "Unable to acquire WAKE_LOCK due to missing manifest permission"); } stayAwake(wasHeld); }
From source file:com.TwentyCodes.android.IOIOTruck.NavigationActivity.java
/** * (non-Javadoc)//from w w w. j a va 2s. co m * @see android.support.v4.app.FragmentActivity#onResume() */ @Override protected void onResume() { super.onResume(); mMap = (MapFragment) this.getSupportFragmentManager().findFragmentById(R.id.map_fragment); mMap.setCompassListener(this); mMap.setGeoPointLocationListener(this); mMap.setLocationSelectedListener(this); mMap.setDirectionsCompleteListener(this); mMap.setRadius((int) (Debug.RADIUS * 1E3)); mMap.enableGPSProgess(); PowerManager pm = (PowerManager) this.getSystemService(Context.POWER_SERVICE); mWakeLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE, TAG); mWakeLock.acquire(); }
From source file:org.navitproject.navit.Navit.java
/** Called when the activity is first created. */ @Override//from ww w. ja v a 2s . c om public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB) this.requestWindowFeature(Window.FEATURE_NO_TITLE); else this.getActionBar().hide(); dialogs = new NavitDialogs(this); NavitResources = getResources(); // only take arguments here, onResume gets called all the time (e.g. when screenblanks, etc.) Navit.startup_intent = this.getIntent(); // hack! Remember time stamps, and only allow 4 secs. later in onResume to set target! Navit.startup_intent_timestamp = System.currentTimeMillis(); Log.e("Navit", "**1**A " + startup_intent.getAction()); Log.e("Navit", "**1**D " + startup_intent.getDataString()); // init translated text NavitTextTranslations.init(); // NOTIFICATION // Setup the status bar notification // This notification is removed in the exit() function NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); // Grab a handle to the NotificationManager Notification NavitNotification = new Notification(R.drawable.ic_notify, getString(R.string.notification_ticker), System.currentTimeMillis()); // Create a new notification, with the text string to show when the notification first appears PendingIntent appIntent = PendingIntent.getActivity(getApplicationContext(), 0, getIntent(), 0); // FIXME : needs a fix for sdk 23 // NavitNotification.setLatestEventInfo(getApplicationContext(), "Navit", getString(R.string.notification_event_default), appIntent); // Set the text in the notification // NavitNotification.flags|=Notification.FLAG_ONGOING_EVENT; // Ensure that the notification appears in Ongoing // nm.notify(R.string.app_name, NavitNotification); // Set the notification // Status and navigation bar sizes // These are platform defaults and do not change with rotation, but we have to figure out which ones apply // (is the navigation bar visible? on the side or at the bottom?) Resources resources = getResources(); int shid = resources.getIdentifier("status_bar_height", "dimen", "android"); int adhid = resources.getIdentifier("action_bar_default_height", "dimen", "android"); int nhid = resources.getIdentifier("navigation_bar_height", "dimen", "android"); int nhlid = resources.getIdentifier("navigation_bar_height_landscape", "dimen", "android"); int nwid = resources.getIdentifier("navigation_bar_width", "dimen", "android"); status_bar_height = (shid > 0) ? resources.getDimensionPixelSize(shid) : 0; action_bar_default_height = (adhid > 0) ? resources.getDimensionPixelSize(adhid) : 0; navigation_bar_height = (nhid > 0) ? resources.getDimensionPixelSize(nhid) : 0; navigation_bar_height_landscape = (nhlid > 0) ? resources.getDimensionPixelSize(nhlid) : 0; navigation_bar_width = (nwid > 0) ? resources.getDimensionPixelSize(nwid) : 0; Log.d(TAG, String.format( "status_bar_height=%d, action_bar_default_height=%d, navigation_bar_height=%d, navigation_bar_height_landscape=%d, navigation_bar_width=%d", status_bar_height, action_bar_default_height, navigation_bar_height, navigation_bar_height_landscape, navigation_bar_width)); if ((ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) || (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED)) { Log.d(TAG, "ask for permission(s)"); ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.ACCESS_FINE_LOCATION }, MY_PERMISSIONS_REQUEST_ALL); } // get the local language ------------- Locale locale = java.util.Locale.getDefault(); String lang = locale.getLanguage(); String langu = lang; String langc = lang; Log.e("Navit", "lang=" + lang); int pos = langu.indexOf('_'); if (pos != -1) { langc = langu.substring(0, pos); NavitLanguage = langc + langu.substring(pos).toUpperCase(locale); Log.e("Navit", "substring lang " + NavitLanguage.substring(pos).toUpperCase(locale)); // set lang. for translation NavitTextTranslations.main_language = langc; NavitTextTranslations.sub_language = NavitLanguage.substring(pos).toUpperCase(locale); } else { String country = locale.getCountry(); Log.e("Navit", "Country1 " + country); Log.e("Navit", "Country2 " + country.toUpperCase(locale)); NavitLanguage = langc + "_" + country.toUpperCase(locale); // set lang. for translation NavitTextTranslations.main_language = langc; NavitTextTranslations.sub_language = country.toUpperCase(locale); } Log.e("Navit", "Language " + lang); SharedPreferences prefs = getSharedPreferences(NAVIT_PREFS, MODE_PRIVATE); map_filename_path = prefs.getString("filenamePath", Environment.getExternalStorageDirectory().getPath() + "/navit/"); // make sure the new path for the navitmap.bin file(s) exist!! File navit_maps_dir = new File(map_filename_path); navit_maps_dir.mkdirs(); // make sure the share dir exists File navit_data_share_dir = new File(NAVIT_DATA_SHARE_DIR); navit_data_share_dir.mkdirs(); Display display_ = getWindowManager().getDefaultDisplay(); int width_ = display_.getWidth(); int height_ = display_.getHeight(); metrics = new DisplayMetrics(); display_.getMetrics(Navit.metrics); int densityDpi = (int) ((Navit.metrics.density * 160) - .5f); Log.e("Navit", "Navit -> pixels x=" + width_ + " pixels y=" + height_); Log.e("Navit", "Navit -> dpi=" + densityDpi); Log.e("Navit", "Navit -> density=" + Navit.metrics.density); Log.e("Navit", "Navit -> scaledDensity=" + Navit.metrics.scaledDensity); ActivityResults = new NavitActivityResult[16]; setVolumeControlStream(AudioManager.STREAM_MUSIC); PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE, "NavitDoNotDimScreen"); if (!extractRes(langc, NAVIT_DATA_DIR + "/locale/" + langc + "/LC_MESSAGES/navit.mo")) { Log.e("Navit", "Failed to extract language resource " + langc); } if (densityDpi <= 120) { my_display_density = "ldpi"; } else if (densityDpi <= 160) { my_display_density = "mdpi"; } else if (densityDpi < 240) { my_display_density = "hdpi"; } else if (densityDpi < 320) { my_display_density = "xhdpi"; } else if (densityDpi < 480) { my_display_density = "xxhdpi"; } else if (densityDpi < 640) { my_display_density = "xxxhdpi"; } else { Log.e("Navit", "found device of very high density (" + densityDpi + ")"); Log.e("Navit", "using xxxhdpi values"); my_display_density = "xxxhdpi"; } if (!extractRes("navit" + my_display_density, NAVIT_DATA_DIR + "/share/navit.xml")) { Log.e("Navit", "Failed to extract navit.xml for " + my_display_density); } // --> dont use android.os.Build.VERSION.SDK_INT, needs API >= 4 Log.e("Navit", "android.os.Build.VERSION.SDK_INT=" + Integer.valueOf(android.os.Build.VERSION.SDK)); NavitMain(this, NavitLanguage, Integer.valueOf(android.os.Build.VERSION.SDK), my_display_density, NAVIT_DATA_DIR + "/bin/navit", map_filename_path); showInfos(); Navit.mgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); }
From source file:com.devbrackets.android.exomedia.core.exoplayer.ExoMediaPlayer.java
/** * This function has the MediaPlayer access the low-level power manager * service to control the device's power usage while playing is occurring. * The parameter is a combination of {@link android.os.PowerManager} wake flags. * Use of this method requires {@link android.Manifest.permission#WAKE_LOCK} * permission./*from www.j ava 2s . c o m*/ * By default, no attempt is made to keep the device awake during playback. * * @param context the Context to use * @param mode the power/wake mode to set * @see android.os.PowerManager */ public void setWakeMode(Context context, int mode) { boolean wasHeld = false; if (wakeLock != null) { if (wakeLock.isHeld()) { wasHeld = true; wakeLock.release(); } wakeLock = null; } //Acquires the wakelock if we have permissions to if (context.getPackageManager().checkPermission(Manifest.permission.WAKE_LOCK, context.getPackageName()) == PackageManager.PERMISSION_GRANTED) { PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); wakeLock = pm.newWakeLock(mode | PowerManager.ON_AFTER_RELEASE, ExoMediaPlayer.class.getName()); wakeLock.setReferenceCounted(false); } else { Log.w(TAG, "Unable to acquire WAKE_LOCK due to missing manifest permission"); } stayAwake(wasHeld); }
From source file:goo.TeaTimer.TimerActivity.java
/** * Only aquires the wake lock _if_ it is set in the settings. *//*w w w . ja v a 2 s. c o m*/ private void aquireWakeLock() { // We're going to start a wakelock if (mSettings.getBoolean("WakeLock", false)) { if (LOG) Log.v(TAG, "Issuing a wakelock..."); PowerManager pm = (PowerManager) getSystemService(POWER_SERVICE); if (mWakeLock != null) Log.e(TAG, "There's already a wakelock... Shouldn't be there!"); mWakeLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE, TAG); mWakeLock.acquire(); } }
From source file:com.entertailion.android.slideshow.utils.Utils.java
/** * Prevent the screensave from activating on Google TV devices. * //w w w . j a v a 2 s .com * @param context */ public static void wakeUp(Context context) { PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE, "tag"); wl.acquire(); wl.release(); }
From source file:com.ternup.caddisfly.fragment.DetailsFragment.java
public void postResult(String folderName) { RequestParams params = new RequestParams(); TimeZone tz = TimeZone.getTimeZone("UTC"); final DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm'Z'"); df.setTimeZone(tz);// w ww . j a v a 2 s . co m final ArrayList<String> filePaths = FileUtils.getFilePaths(getActivity(), folderName, "/small/", mLocationId); File myFile = new File(filePaths.get(0)); String date = df.format(DateUtils.getDateFromFilename(myFile.getName())); params.put("date", date); String deviceId = Build.MANUFACTURER + " " + Build.MODEL; if (deviceId.length() > 32) { deviceId = deviceId.substring(1, 32); } params.put("deviceId", deviceId); params.put("type", String.valueOf(mTestTypeId + 1)); if (wakeLock == null || !wakeLock.isHeld()) { PowerManager pm = (PowerManager) getActivity().getApplicationContext() .getSystemService(Context.POWER_SERVICE); wakeLock = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE, "MyWakeLock"); wakeLock.acquire(); } WebClient.post("tests", params, new AsyncHttpResponseHandler() { @Override public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) { String response = responseBody == null ? null : new String(responseBody); try { JSONObject json = new JSONObject(response); final int newId = json.getInt("id"); if (filePaths.size() > 0) { count = 0; totalCount = filePaths.size(); postItem(newId, filePaths); } } catch (JSONException e) { e.printStackTrace(); } } @Override public void onFailure(int statusCode, Header[] headers, byte[] responseBody, final Throwable error) { Log.d(Globals.DEBUG_TAG, "fail: " + error.getMessage()); getActivity().runOnUiThread(new Runnable() { public void run() { if (progressDialog != null) { progressDialog.dismiss(); } if (wakeLock != null && wakeLock.isHeld()) { wakeLock.release(); } AlertUtils.showAlert(getActivity(), R.string.error, error.getMessage(), R.string.ok, null, null); } }); } }); }