honoru88 / google-glass-api

Automatically exported from code.google.com/p/google-glass-api
0 stars 0 forks source link

Screen-dim wake locks do not handle user input properly #625

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. In a running activity, create and hold a wake lock with the 
SCREEN_DIM_WAKE_LOCK flag
2. Attempt to keep the Glass awake with user inputs (swipe gestures)
3. After the screen dims, attempt to wake Glass up with user inputs

What is the expected output? What do you see instead?

User inputs are expected to keep Glass awake, or to wake it up if it has 
dimmed. Instead, the screen dims regardless of an inputs, and once dim, it 
refuses to wake up on user inputs and does not pass any input events to the 
activity.

What version of the product are you using? On what operating system?

This was reproduced on Glass XE22, using Xamarin.Android

Please provide any additional information below.

The issue does not occur with any other kind of wake lock. Partial, Screen 
Bright, and Full wake locks work as expected.

Original issue reported on code.google.com by ninjanee...@gmail.com on 29 Oct 2014 at 3:41

GoogleCodeExporter commented 9 years ago
Hello,

Have you tried using the FLAG_KEEP_SCREEN_ON flag instead of the wakelock? This 
should be enough to control the screen dimness.

Here's an example Activity that does the job:

[ACTIVITY]
public class MainActivity extends Activity {

    /** {@link CardScrollView} to use as the main content view. */
    private CardScrollView mCardScroller;

    private View mView;
    private Window mWindow;

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

        mWindow = getWindow();
        mWindow.addFlags(LayoutParams.FLAG_KEEP_SCREEN_ON);

        mView = buildView();

        mCardScroller = new CardScrollView(this);
        mCardScroller.setAdapter(new CardScrollAdapter() {
            @Override
            public int getCount() {
                return 1;
            }

            @Override
            public Object getItem(int position) {
                return mView;
            }

            @Override
            public View getView(int position, View convertView, ViewGroup parent) {
                return mView;
            }

            @Override
            public int getPosition(Object item) {
                if (mView.equals(item)) {
                    return 0;
                }
                return AdapterView.INVALID_POSITION;
            }
        });
        // Handle the TAP event.
        mCardScroller.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                AudioManager am = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
                am.playSoundEffect(Sounds.TAP);

                // Toggle the dimness value.
                setDimness(mWindow.getAttributes().screenBrightness > 0 ? 0 : 1);
            }
        });
        setContentView(mCardScroller);
    }

    @Override
    protected void onResume() {
        super.onResume();
        mCardScroller.activate();
    }

    @Override
    protected void onPause() {
        mCardScroller.deactivate();
        super.onPause();
    }

    @Override
    protected void onDestroy() {
        setDimness(-1);
        super.onPause();
    }

    /**
     * Builds a Glass styled "Hello World!" view using the {@link CardBuilder} class.
     */
    private View buildView() {
        CardBuilder card = new CardBuilder(this, CardBuilder.Layout.TEXT);

        card.setText(R.string.tap_to_toggle);
        return card.getView();
    }

    private void setDimness(float value) {
        LayoutParams layoutpars = mWindow.getAttributes();

        layoutpars.screenBrightness = value;
        mWindow.setAttributes(layoutpars);
    }

}
[/ACTIVITY]

Best,
Alain

Original comment by ala...@google.com on 30 Oct 2014 at 3:39

GoogleCodeExporter commented 9 years ago
I'll give that a try. Thanks!

Original comment by ninjanee...@gmail.com on 30 Oct 2014 at 6:09

GoogleCodeExporter commented 9 years ago
This does not work.  As long as the FLAG_KEEP_SCREEN_ON flag is added the 
screen stays full bright regardless of the screenBrightness setting used.  If 
the FLAG_KEEP_SCREEN_ON flag is not used, then dimming occurs, however the 
screen will shutoff after a few seconds of inactivity, resulting in the glass 
being back at the home screen when the woken back up.  There doesn't seem to be 
a way to keep a glass app running with the screen on and dimming the screen.  

Original comment by Ariem...@gmail.com on 4 Nov 2014 at 2:18

GoogleCodeExporter commented 9 years ago
Hello,

Sorry I misunderstood your issue, I though you wanted to programmatically 
change the dimness of the screen.

If what you're looking for is for Glass to stay on your Activity, even when the 
screen turns off, then simply use the android:immersive="true" flag in your 
AndroidManifest.xml for your Activity:
  https://developers.google.com/glass/develop/gdk/immersions#creating_immersions

Best,
Alain

Original comment by ala...@google.com on 4 Nov 2014 at 5:15

GoogleCodeExporter commented 9 years ago
Perhaps unrelated, but similar,  I have found that in XE22, holding a Screen 
Dim Wakelock can cause the touchpad to become totally unresponsive to user 
input. 

I will have to try to modify a GDK sample project to reproduce, but essentially 
launch into a live card, on tapping a live card open an Activity. In onStart 
method of Activity, acquire a screen dim wakelock and then call 
openOptionsMenu. 

Result: user cannot swipe between menu items, and cannot even swipe down to 
exit, touch pad completely unresponsive.

This is new in XE22 to my knowledge. 

Original comment by idi...@gmail.com on 17 Nov 2014 at 2:07