use of com.google.samples.apps.topeka.model.Player in project android-topeka by googlesamples.
the class PreferencesHelperAndroidTest method performPreferenceCycle.
/**
* Creates a player and stores it to the preferences. Then tries to read it.
*/
@Test
public void performPreferenceCycle() throws Exception {
final Context context = InstrumentationRegistry.getTargetContext();
PreferencesHelper.signOut(context);
assertThat(PreferencesHelper.isSignedIn(context), is(false));
PreferencesHelper.writeToPreferences(context, TEST_PLAYER);
final Player resultingPlayer = PreferencesHelper.getPlayer(context);
assertThat(resultingPlayer, is(TEST_PLAYER));
assertThat(PreferencesHelper.isSignedIn(context), is(true));
}
use of com.google.samples.apps.topeka.model.Player in project android-topeka by googlesamples.
the class QuizFragment method setAvatarDrawable.
@SuppressWarnings("ConstantConditions")
private void setAvatarDrawable(AvatarView avatarView) {
Player player = PreferencesHelper.getPlayer(getActivity());
avatarView.setAvatar(player.getAvatar().getDrawableId());
ViewCompat.animate(avatarView).setInterpolator(new FastOutLinearInInterpolator()).setStartDelay(500).scaleX(1).scaleY(1).start();
}
use of com.google.samples.apps.topeka.model.Player in project android-topeka by googlesamples.
the class PreferencesHelper method getPlayer.
/**
* Retrieves a {@link com.google.samples.apps.topeka.model.Player} from preferences.
*
* @param context The Context which to obtain the SharedPreferences from.
* @return A previously saved player or <code>null</code> if none was saved previously.
*/
public static Player getPlayer(Context context) {
SharedPreferences preferences = getSharedPreferences(context);
final String firstName = preferences.getString(PREFERENCE_FIRST_NAME, null);
final String lastInitial = preferences.getString(PREFERENCE_LAST_INITIAL, null);
final String avatarPreference = preferences.getString(PREFERENCE_AVATAR, null);
final Avatar avatar;
if (null != avatarPreference) {
avatar = Avatar.valueOf(avatarPreference);
} else {
avatar = null;
}
if (null == firstName || null == lastInitial || null == avatar) {
return null;
}
return new Player(firstName, lastInitial, avatar);
}
use of com.google.samples.apps.topeka.model.Player in project android-topeka by googlesamples.
the class SignInFragment method savePlayer.
private void savePlayer(Activity activity) {
mPlayer = new Player(mFirstName.getText().toString(), mLastInitial.getText().toString(), mSelectedAvatar);
PreferencesHelper.writeToPreferences(activity, mPlayer);
}
use of com.google.samples.apps.topeka.model.Player in project android-topeka by googlesamples.
the class CategorySelectionActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ActivityCategorySelectionBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_category_selection);
Player player = getIntent().getParcelableExtra(EXTRA_PLAYER);
if (!PreferencesHelper.isSignedIn(this)) {
if (player == null) {
player = PreferencesHelper.getPlayer(this);
} else {
PreferencesHelper.writeToPreferences(this, player);
}
}
binding.setPlayer(player);
setUpToolbar();
if (savedInstanceState == null) {
attachCategoryGridFragment();
} else {
setProgressBarVisibility(View.GONE);
}
supportPostponeEnterTransition();
}
Aggregations