Search in sources :

Example 1 with Player

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));
}
Also used : Context(android.content.Context) Player(com.google.samples.apps.topeka.model.Player) SmallTest(android.test.suitebuilder.annotation.SmallTest) Test(org.junit.Test)

Example 2 with Player

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();
}
Also used : Player(com.google.samples.apps.topeka.model.Player) FastOutLinearInInterpolator(android.support.v4.view.animation.FastOutLinearInInterpolator)

Example 3 with Player

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);
}
Also used : Player(com.google.samples.apps.topeka.model.Player) SharedPreferences(android.content.SharedPreferences) Avatar(com.google.samples.apps.topeka.model.Avatar)

Example 4 with Player

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);
}
Also used : Player(com.google.samples.apps.topeka.model.Player)

Example 5 with Player

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();
}
Also used : ActivityCategorySelectionBinding(com.google.samples.apps.topeka.databinding.ActivityCategorySelectionBinding) Player(com.google.samples.apps.topeka.model.Player)

Aggregations

Player (com.google.samples.apps.topeka.model.Player)5 Context (android.content.Context)1 SharedPreferences (android.content.SharedPreferences)1 FastOutLinearInInterpolator (android.support.v4.view.animation.FastOutLinearInInterpolator)1 SmallTest (android.test.suitebuilder.annotation.SmallTest)1 ActivityCategorySelectionBinding (com.google.samples.apps.topeka.databinding.ActivityCategorySelectionBinding)1 Avatar (com.google.samples.apps.topeka.model.Avatar)1 Test (org.junit.Test)1