Search in sources :

Example 1 with PlayerColorView

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

the class NamePlayersActivity method onRestoreInstanceState.

@Override
protected void onRestoreInstanceState(final Bundle savedInstanceState) {
    super.onRestoreInstanceState(savedInstanceState);
    numPlayers = savedInstanceState.getInt(EXTRA_NUM_PLAYERS);
    String[] playerNames = savedInstanceState.getStringArray(GameActivity.EXTRA_PLAYER_NAMES);
    String[] playerColors = savedInstanceState.getStringArray(GameActivity.EXTRA_PLAYER_COLORS);
    for (int i = 0; i < numPlayers; i++) {
        playerEditTexts.get(i).setText(playerNames[i]);
        PlayerColor playerColor = PlayerColor.deserialize(playerColors[i]);
        PlayerColorView playerColorView = playerColorViews.get(i);
        playerColorView.setPlayerColor(playerColor);
    }
    if (savedInstanceState.getBoolean("colorChooserDialog")) {
        runOnUiThread(new Runnable() {

            @Override
            public void run() {
                showColorChooserDialog(playerColorViews.get(savedInstanceState.getInt("colorChooserDialogSquareImage")), PlayerColor.deserialize(savedInstanceState.getString("colorChooserDialogChosenColor")));
            }
        });
    }
}
Also used : PlayerColor(com.nolanlawson.keepscore.helper.PlayerColor) PlayerColorView(com.nolanlawson.keepscore.widget.PlayerColorView)

Example 2 with PlayerColorView

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

the class NamePlayersActivity method onClick.

@Override
public void onClick(View v) {
    switch(v.getId()) {
        case android.R.id.button1:
            // ok button clicked
            String[] playerNames = getPlayerNames();
            String[] playerColors = getPlayerColors();
            GameActivityHelper.newGame(this, playerNames, playerColors);
            break;
        default:
            // color square clicked
            PlayerColorView playerColorView = (PlayerColorView) v;
            showColorChooserDialog(playerColorView, playerColorView.getPlayerColor());
            break;
    }
}
Also used : PlayerColorView(com.nolanlawson.keepscore.widget.PlayerColorView)

Example 3 with PlayerColorView

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

the class NamePlayersActivity method setUpWidgets.

private void setUpWidgets() {
    okButton = (Button) findViewById(android.R.id.button1);
    for (int i = 0; i < numPlayers; i++) {
        int id = PLAYER_VIEW_IDS[i];
        View view = getPlayerAndColorView(id);
        playerViews.add(view);
        playerEditTexts.add((AutoCompleteTextView) view.findViewById(R.id.player_name_edit_text));
        PlayerColor playerColor = PlayerColor.BUILT_INS[i % PlayerColor.BUILT_INS.length];
        PlayerColorView playerColorView = (PlayerColorView) view.findViewById(R.id.player_color_image);
        playerColorView.setVisibility(PreferenceHelper.getShowColors(this) ? View.VISIBLE : View.GONE);
        playerColorView.setPlayerColor(playerColor);
        playerColorView.setOnClickListener(this);
        playerColorViews.add(playerColorView);
    }
    for (int i = 0; i < playerEditTexts.size(); i++) {
        AutoCompleteTextView playerEditText = playerEditTexts.get(i);
        if (playerEditText == null) {
            continue;
        }
        String hint = getString(R.string.text_player) + ' ' + (i + 1);
        playerEditText.setHint(hint);
        // final edit text does "action done"
        if (i == numPlayers - 1) {
            playerEditText.setImeOptions(EditorInfo.IME_ACTION_DONE);
        }
    }
    okButton.setOnClickListener(this);
    fetchPlayerNameSuggestions();
}
Also used : PlayerColor(com.nolanlawson.keepscore.helper.PlayerColor) PlayerColorView(com.nolanlawson.keepscore.widget.PlayerColorView) AutoCompleteTextView(android.widget.AutoCompleteTextView) View(android.view.View) PlayerColorView(com.nolanlawson.keepscore.widget.PlayerColorView) AutoCompleteTextView(android.widget.AutoCompleteTextView)

Example 4 with PlayerColorView

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

the class EditablePlayerAdapter method getView.

@Override
public View getView(int position, View view, ViewGroup parent) {
    if (view == null) {
        LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        view = inflater.inflate(R.layout.editable_player, parent, false);
    }
    final PlayerScore playerScore = getItem(position);
    TextView nameTextView = (TextView) view.findViewById(R.id.text_player_name);
    TextView numberTextView = (TextView) view.findViewById(R.id.text_player_number);
    TextView scoreTextView = (TextView) view.findViewById(R.id.text_player_score);
    PlayerColorView playerColorView = (PlayerColorView) view.findViewById(R.id.player_color_image);
    playerColorView.setVisibility(PreferenceHelper.getShowColors(getContext()) ? View.VISIBLE : View.GONE);
    nameTextView.setText(playerScore.toDisplayName(getContext()));
    numberTextView.setText('#' + Integer.toString(playerScore.getPlayerNumber() + 1));
    scoreTextView.setText(Long.toString(playerScore.getScore()));
    playerColorView.setPlayerColor(playerScore.getPlayerColor());
    // listen for player color clicks
    playerColorView.setOnClickListener(new OnClickListener() {

        private PlayerColor chosenColor;

        @Override
        public void onClick(View v) {
            DialogHelper.showColorChooserDialog(getContext(), playerScore.getPlayerColor(), new Callback<PlayerColor>() {

                @Override
                public void onCallback(PlayerColor playerColor) {
                    // color changed
                    chosenColor = playerColor;
                }
            }, new Runnable() {

                @Override
                public void run() {
                    // color selected
                    if (chosenColor == null) {
                        return;
                    }
                    playerScore.setPlayerColor(chosenColor);
                    notifyDataSetChanged();
                }
            });
        }
    });
    // add listener to the delete button
    ImageButton deleteButton = (ImageButton) view.findViewById(R.id.button_delete_player);
    deleteButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // delete
            remove(playerScore);
            resetPlayerNumbers();
            notifyDataSetChanged();
            if (onDeleteListener != null) {
                onDeleteListener.onCallback(playerScore);
            }
        }
    });
    // user is not allowed to delete the final 2 users
    deleteButton.setEnabled(getCount() > OrganizePlayersActivity.MIN_NUM_PLAYERS);
    ImageButton editButton = (ImageButton) view.findViewById(R.id.button_edit_player);
    editButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // edit
            DialogHelper.showPlayerNameDialog(getContext(), R.string.title_change_name, playerScore.getName(), playerScore.getPlayerNumber(), new Callback<String>() {

                @Override
                public void onCallback(String input) {
                    playerScore.setName(input);
                    notifyDataSetChanged();
                }
            });
        }
    });
    view.setVisibility(currentlyDragging == view ? View.INVISIBLE : View.VISIBLE);
    return view;
}
Also used : ImageButton(android.widget.ImageButton) PlayerColor(com.nolanlawson.keepscore.helper.PlayerColor) Callback(com.nolanlawson.keepscore.util.Callback) PlayerColorView(com.nolanlawson.keepscore.widget.PlayerColorView) LayoutInflater(android.view.LayoutInflater) OnClickListener(android.view.View.OnClickListener) TextView(android.widget.TextView) TextView(android.widget.TextView) View(android.view.View) PlayerColorView(com.nolanlawson.keepscore.widget.PlayerColorView) PlayerScore(com.nolanlawson.keepscore.db.PlayerScore)

Example 5 with PlayerColorView

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

the class DialogHelper method getSquareImages.

private static List<PlayerColorView> getSquareImages(View view) {
    int[] rows = new int[] { R.id.row_1, R.id.row_2, R.id.row_3, R.id.row_4 };
    int[] columns = new int[] { R.id.column_1, R.id.column_2, R.id.column_3, R.id.column_4 };
    List<PlayerColorView> result = new ArrayList<PlayerColorView>();
    LinearLayout allRows = (LinearLayout) (view.findViewById(R.id.all_rows));
    boolean portraitOrdering = allRows.getOrientation() == LinearLayout.VERTICAL;
    if (portraitOrdering) {
        // when in portrait mode, rows are rows and columns are columns
        for (int rowId : rows) {
            View row = view.findViewById(rowId);
            for (int columnId : columns) {
                result.add((PlayerColorView) (row.findViewById(columnId)));
            }
        }
    } else {
        // when in landscape mode, rows are columns and columns are rows and hamburgers eat people
        for (int columnId : columns) {
            for (int rowId : rows) {
                View row = view.findViewById(rowId);
                result.add((PlayerColorView) (row.findViewById(columnId)));
            }
        }
    }
    return result;
}
Also used : PlayerColorView(com.nolanlawson.keepscore.widget.PlayerColorView) ArrayList(java.util.ArrayList) View(android.view.View) AutoCompleteTextView(android.widget.AutoCompleteTextView) TextView(android.widget.TextView) PlayerColorView(com.nolanlawson.keepscore.widget.PlayerColorView) LinearLayout(android.widget.LinearLayout)

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