I have a few user preferences, mostly simple check-boxes, in my Glass GDK app. I could not find a glass specific preference paradigm, so I used PreferenceFragment and it worked fine on XE12.
FYI: When I implemented it, it initially looked bad, but I improved that by using the following style in the AndroidManifest for my SettingsActivity:
<style name="Theme.Preferences" parent="@android:style/Theme.Holo.NoActionBar.Fullscreen" />
I had no option to not update to XE16 (other than turning off network connectivity). After the update I tweaked my app's API usages for the few XE16 changes. Everything mostly worked.
The first thing I noticed was that my swiping down in my immersion's MainActivity would no longer go back to the Live Card. I fixed this by having my MainActivity's onGesture handler return false for Gesture.SWIPE_DOWN.
The second thing I noticed is the purpose of this question: My SettingsActivity that wraps a PreferenceFragment no longer allows me to move up and down the preference list using the swipe left and right. My code is at the end of this post. I added a GestureDetector to help debug this problem after it was noticed. I can see the SWIPE_LEFT and SWIPE_RIGHT being logged, but no matter what I return, or even if I remove the gesture code, the preference list selection never moves from the first item. The first item is a CheckBoxPreference, which does toggle when I tap.
I have seen several other Glass apps that use Android Preferences (either PreferenceActivity or PreferenceFragment), and they all also seem to now be broken.
How to properly implement Preferences on Glass, or how to get PreferenceFragment to work?
public class SettingsActivity //
extends Activity //
implements GestureDetector.BaseListener
{
private static final String TAG = WtcLog.TAG(SettingsActivity.class);
public static final int RESULT_SIGN_OUT = RESULT_FIRST_USER + 1;
private static final String TAG_PREFERENCES = "preferences";
private GestureDetector mGestureDetector;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
mGestureDetector = new GestureDetector(this);
mGestureDetector.setBaseListener(this);
getFragmentManager() //
.beginTransaction() //
.replace(android.R.id.content, new FragmentSettings(), TAG_PREFERENCES) //
.commit();
}
public static class FragmentSettings extends PreferenceFragment
{
private ApplicationGlass mApplication;
private WavePreferences mPreferences;
private PreferenceScreen mScreenTop;
private PreferenceCategory mCategoryDebug;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
Activity activity = getActivity();
mApplication = (ApplicationGlass) activity.getApplication();
mPreferences = mApplication.getPreferences();
addPreferencesFromResource(R.xml.preferences);
mScreenTop = (PreferenceScreen) findPreference("screen_top");
//
// Remember Password
//
CheckBoxPreference prefRememberPassword = (CheckBoxPreference) findPreference("pref_remember_password");
prefRememberPassword.setChecked(mPreferences.getRememberPassword());
prefRememberPassword.setOnPreferenceChangeListener(new OnPreferenceChangeListener()
{
@Override
public boolean onPreferenceChange(Preference preference, Object newValue)
{
boolean rememberPassword = (Boolean) newValue;
String password = null;
if (rememberPassword)
{
password = mApplication.getSessionManager().getLastStartConnectInfo().getPassword();
}
mPreferences.setRememberPassword(rememberPassword);
mPreferences.setPassword(password);
return true;
}
});
...
}
}
@Override
public boolean onGenericMotionEvent(MotionEvent event)
{
if (mGestureDetector != null)
{
return mGestureDetector.onMotionEvent(event);
}
return false;
}
@Override
public boolean onGesture(Gesture gesture)
{
WtcLog.debug(TAG, "onGesture(" + gesture + ")");
switch (gesture)
{
case LONG_PRESS:
WtcLog.debug(TAG, "onGesture: LONG_PRESS");
break;
case TAP:
WtcLog.debug(TAG, "onGesture: TAP");
break;
case TWO_TAP:
WtcLog.debug(TAG, "onGesture: TWO_TAP");
break;
case SWIPE_RIGHT:
WtcLog.debug(TAG, "onGesture: SWIPE_RIGHT");
break;
case SWIPE_LEFT:
WtcLog.debug(TAG, "onGesture: SWIPE_LEFT");
break;
case SWIPE_DOWN:
WtcLog.debug(TAG, "onGesture: SWIPE_DOWN");
break;
case SWIPE_UP:
WtcLog.debug(TAG, "onGesture: SWIPE_UP");
break;
case THREE_LONG_PRESS:
WtcLog.debug(TAG, "onGesture: THREE_LONG_PRESS");
break;
case THREE_TAP:
WtcLog.debug(TAG, "onGesture: THREE_TAP");
break;
case TWO_LONG_PRESS:
WtcLog.debug(TAG, "onGesture: TWO_LONG_PRESS");
break;
case TWO_SWIPE_DOWN:
WtcLog.debug(TAG, "onGesture: TWO_SWIPE_DOWN");
break;
case TWO_SWIPE_LEFT:
WtcLog.debug(TAG, "onGesture: TWO_SWIPE_LEFT");
break;
case TWO_SWIPE_RIGHT:
WtcLog.debug(TAG, "onGesture: TWO_SWIPE_RIGHT");
break;
case TWO_SWIPE_UP:
WtcLog.debug(TAG, "onGesture: TWO_SWIPE_UP");
break;
default:
WtcLog.error(TAG, "onGesture: unknown gesture \"" + gesture + "\"");
break;
}
return false;
}
}
ListView
scrolling on XE16 and 16.1 here - code.google.com/p/google-glass-api/issues/detail?id=484 – Sean Barbeau