use of com.nolanlawson.keepscore.helper.PlayerColor 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")));
}
});
}
}
use of com.nolanlawson.keepscore.helper.PlayerColor 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();
}
use of com.nolanlawson.keepscore.helper.PlayerColor 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;
}
Aggregations