Force Screen On

Force Screen On

PLEASE DO NOT USE A WAKE LOCK

This requires that you give your app an additional permission, and it is very easy to introduce bugs where you accidentally remain holding the wake lock and thus leave the screen on.

It is far, far better to use the window flag FLAG_KEEP_SCREEN_ON, which you can enable on your activity's window in your onCreate() like this:

@Override
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);

getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
}

This will make sure that the screen stays on while your window is in the foreground, and only while it is in the foreground. It greatly simplifies this common use case, eliminating any juggling you need to do as your app transitions between states.

How to force screen on at all activities?

Create a abstract class BaseActivity
that calls in start()

getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

then make all the activities in your app extend the BaseActivity.

Keep screen on in external applications

You can set it programmatically with:

     getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

If you only want Activity B to keep the screen on when it's launched from Activity A you can achieve it like this:

When A launches B, send an extra value on the intent, On B, onCreate() check if there is a value sent and only if it founds something it's because came from A.

    public class ActivityB extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_b);

Bundle extras = getIntent().getExtras();
if(extras != null)
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
}
}

Force Screen Reader to Read When A Component Is Removed

I've done this in the past by creating an element with aria-live="assertive", using some CSS trickery to have it hidden except for screen readers, and then setting its innerHTML. Something along these lines:

const $message = document.createElement('span');
$message.classList.add('visuallyhidden'); // <-- Some method of making sure this element is only seen by screen readers
$message.setAttribute('aria-live', 'assertive');

document.body.appendChild($message);

const speak = function (message) {
$message.innerHTML = '';
window.setTimeout(() => {
$message.innerHTML = message;
}, 100);
};

You may also want to take some measures to ensure people using screen readers can't manually navigate to the alert message element as well, such as by clearing its content after the fact or perhaps by controlling its aria-hidden attribute.

Force screen reader to read acronym by his full name

The wording of your question suggests using <abbr>.
You may use it, but in this case you cannot force screen readers to always read the full expanded text instead of the abbreviation.

Screen readers generally provide options whether to expand abbreviations all the time automatically, only on demand, depending on context, or never.
This is something under control of the user, who can choose what is the best for him/her. You shouldn't dictate it at his/her place.

However, looking at your particular case, you are in fact probably not looking for abbreviation and <abbr>.
As you have well identified, you are more looking for a kind of label that has to be read full text all the time.

As you have well identified too, you can't use aria-label, since aria-label is reserved for interactive elements, what your element is precisely not.

IN that kind of circunstances when you need a kind of label outside of interactive elements, a good solution is to use visually hidden text, like this:

<div>
<span aria-hidden="true">M</span>
<span class="sr_only">Monday</span>
</div>

Where sr_only is a CSS class which puts the text off screen.
You can find the CSS code of .sr_only in bootstrap. Many other frameworks have similar visually hidden text CSS classes with other names.

Windows 7 : How to force a program to display on main screen?

Hold down the Windows key on your keyboard, and press the Left or Right arrow. This should move the focused window to the left or right side of the monitor.

BTW, if you have multiple monitors, also holding down Shift will move the focused window between monitors.



Related Topics



Leave a reply



Submit