use of com.nolanlawson.keepscore.util.Callback in project KeepScore by nolanlawson.
the class SettingsActivity method loadSettings.
private void loadSettings() {
Set<String> settingSets = SettingSetHelper.getAvailableSettingSets(this);
if (settingSets.isEmpty()) {
ToastHelper.showShort(this, R.string.toast_no_saved_settings);
return;
}
// TODO: figure out why I can't get the AlertDialog to make the items themselves clickable
final TextWithDeleteAdapter availableSetAdapter = createAvailableSettingSetsAdapter();
final AlertDialog dialog = new AlertDialog.Builder(this).setCancelable(true).setTitle(R.string.pref_load_settings_name).setNegativeButton(android.R.string.cancel, null).setAdapter(availableSetAdapter, null).create();
Callback<Integer> onClickListener = new Callback<Integer>() {
@Override
public void onCallback(Integer which) {
showSavedSettingSetDialog((String) availableSetAdapter.getItem(which), new Runnable() {
@Override
public void run() {
dialog.dismiss();
}
});
}
};
availableSetAdapter.setOnItemClickedListener(onClickListener);
dialog.show();
}
use of com.nolanlawson.keepscore.util.Callback 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