Search in sources :

Example 6 with PlayerColorView

use of com.nolanlawson.keepscore.widget.PlayerColorView in project KeepScore by nolanlawson.

the class DialogHelper method createColorChooserView.

private static View createColorChooserView(Context context, final Callback<PlayerColor> onColorChanged, final PlayerColor selectedColor) {
    LayoutInflater inflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
    final View view = inflater.inflate(R.layout.color_chooser_dialog, null, false);
    final List<PlayerColorView> playerColorViews = getSquareImages(view);
    for (int i = 0; i < playerColorViews.size(); i++) {
        PlayerColorView playerColorView = playerColorViews.get(i);
        PlayerColor playerColor = PlayerColor.BUILT_INS[i % PlayerColor.BUILT_INS.length];
        playerColorView.setSelected(playerColor.equals(selectedColor));
        playerColorView.setPlayerColor(playerColor);
        playerColorView.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                PlayerColor playerColor = ((PlayerColorView) v).getPlayerColor();
                onColorChanged.onCallback(playerColor);
                for (PlayerColorView otherSquareImage : playerColorViews) {
                    otherSquareImage.setSelected(otherSquareImage.getPlayerColor() == playerColor);
                }
            }
        });
    }
    return view;
}
Also used : CustomPlayerColor(com.nolanlawson.keepscore.helper.PlayerColor.CustomPlayerColor) PlayerColorView(com.nolanlawson.keepscore.widget.PlayerColorView) LayoutInflater(android.view.LayoutInflater) OnClickListener(android.view.View.OnClickListener) View(android.view.View) AutoCompleteTextView(android.widget.AutoCompleteTextView) TextView(android.widget.TextView) PlayerColorView(com.nolanlawson.keepscore.widget.PlayerColorView)

Aggregations

PlayerColorView (com.nolanlawson.keepscore.widget.PlayerColorView)6 View (android.view.View)4 AutoCompleteTextView (android.widget.AutoCompleteTextView)3 TextView (android.widget.TextView)3 PlayerColor (com.nolanlawson.keepscore.helper.PlayerColor)3 LayoutInflater (android.view.LayoutInflater)2 OnClickListener (android.view.View.OnClickListener)2 ImageButton (android.widget.ImageButton)1 LinearLayout (android.widget.LinearLayout)1 PlayerScore (com.nolanlawson.keepscore.db.PlayerScore)1 CustomPlayerColor (com.nolanlawson.keepscore.helper.PlayerColor.CustomPlayerColor)1 Callback (com.nolanlawson.keepscore.util.Callback)1 ArrayList (java.util.ArrayList)1