Open GoogleCodeExporter opened 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
I'll give that a try. Thanks!
Original comment by ninjanee...@gmail.com
on 30 Oct 2014 at 6:09
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
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
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
Original issue reported on code.google.com by
ninjanee...@gmail.com
on 29 Oct 2014 at 3:41