Search in sources :

Example 1 with Callback

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();
}
Also used : AlertDialog(android.app.AlertDialog) Callback(com.nolanlawson.keepscore.util.Callback) TextWithDeleteAdapter(com.nolanlawson.keepscore.data.TextWithDeleteAdapter)

Example 2 with Callback

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;
}
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)

Aggregations

Callback (com.nolanlawson.keepscore.util.Callback)2 AlertDialog (android.app.AlertDialog)1 LayoutInflater (android.view.LayoutInflater)1 View (android.view.View)1 OnClickListener (android.view.View.OnClickListener)1 ImageButton (android.widget.ImageButton)1 TextView (android.widget.TextView)1 TextWithDeleteAdapter (com.nolanlawson.keepscore.data.TextWithDeleteAdapter)1 PlayerScore (com.nolanlawson.keepscore.db.PlayerScore)1 PlayerColor (com.nolanlawson.keepscore.helper.PlayerColor)1 PlayerColorView (com.nolanlawson.keepscore.widget.PlayerColorView)1