Welcome to mirror list, hosted at ThFree Co, Russian Federation.

StackedButtonsDialog.java « widget « maps « mapswithme « com « src « android - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 7e318395551e62098bbd7ef67a51efe3be27ab8f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
package com.mapswithme.maps.widget;

import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.StringRes;
import androidx.appcompat.app.AppCompatDialog;
import android.view.View;
import android.widget.TextView;

import com.mapswithme.maps.R;
import com.mapswithme.util.UiUtils;

public class StackedButtonsDialog extends AppCompatDialog implements View.OnClickListener
{
  @Nullable
  private final String mTitle;
  @Nullable
  private final String mMessage;
  @Nullable
  private final String mPositive;
  @Nullable
  private final DialogInterface.OnClickListener mPositiveListener;
  @Nullable
  private final String mNeutral;
  @Nullable
  private final DialogInterface.OnClickListener mNeutralListener;
  @Nullable
  private final String mNegative;
  @Nullable
  private final DialogInterface.OnClickListener mNegativeListener;
  private final boolean mCancelable;
  @Nullable
  private final OnCancelListener mCancelListener;

  private StackedButtonsDialog(Context context, @Nullable String title, @Nullable String message,
                               @Nullable String positive, @Nullable OnClickListener positiveListener,
                               @Nullable String neutral, @Nullable OnClickListener neutralListener,
                               @Nullable String negative, @Nullable OnClickListener negativeListener,
                               boolean cancelable, @Nullable OnCancelListener cancelListener)
  {
    super(context);
    mTitle = title;
    mMessage = message;
    mPositive = positive;
    mPositiveListener = positiveListener;
    mNeutral = neutral;
    mNeutralListener = neutralListener;
    mNegative = negative;
    mNegativeListener = negativeListener;
    mCancelable = cancelable;
    mCancelListener = cancelListener;
  }

  @Override
  protected void onCreate(Bundle savedInstanceState)
  {
    super.onCreate(savedInstanceState);

    setCancelable(mCancelable);
    setOnCancelListener(mCancelListener);
    setContentView(R.layout.dialog_stacked_buttons);

    TextView title = (TextView) findViewById(R.id.tv__title);
    UiUtils.setTextAndHideIfEmpty(title, mTitle);
    TextView message = (TextView) findViewById(R.id.tv__message);
    UiUtils.setTextAndHideIfEmpty(message, mMessage);
    TextView positive = (TextView) findViewById(R.id.btn__positive);
    positive.setOnClickListener(this);
    UiUtils.setTextAndHideIfEmpty(positive, mPositive);
    TextView neutral = (TextView) findViewById(R.id.btn__neutral);
    neutral.setOnClickListener(this);
    UiUtils.setTextAndHideIfEmpty(neutral, mNeutral);
    TextView negative = (TextView) findViewById(R.id.btn__negative);
    negative.setOnClickListener(this);
    UiUtils.setTextAndHideIfEmpty(negative, mNegative);
  }

  @Override
  public void onClick(View v)
  {
    switch (v.getId())
    {
      case R.id.btn__positive:
        if (mPositiveListener != null)
          mPositiveListener.onClick(this, DialogInterface.BUTTON_POSITIVE);
        dismiss();
        break;
      case R.id.btn__neutral:
        if (mNeutralListener != null)
          mNeutralListener.onClick(this, DialogInterface.BUTTON_NEUTRAL);
        dismiss();
        break;
      case R.id.btn__negative:
        if (mNegativeListener != null)
          mNegativeListener.onClick(this, DialogInterface.BUTTON_NEGATIVE);
        dismiss();
        break;
    }
  }

  public static final class Builder
  {
    @NonNull
    private final Context mContext;

    @Nullable
    private String mTitle;
    @Nullable
    private String mMessage;
    @Nullable
    private String mPositive;
    @Nullable
    private DialogInterface.OnClickListener mPositiveListener;
    @Nullable
    private String mNeutral;
    @Nullable
    private DialogInterface.OnClickListener mNeutralListener;
    @Nullable
    private String mNegative;
    @Nullable
    private DialogInterface.OnClickListener mNegativeListener;
    private boolean mCancelable = true;
    @Nullable
    private DialogInterface.OnCancelListener mCancelListener;

    public Builder(@NonNull Context context)
    {
      mContext = context;
      mTitle = mContext.getString(android.R.string.dialog_alert_title);
      mPositive = mContext.getString(android.R.string.ok);
      mNegative = mContext.getString(android.R.string.no);
    }

    @NonNull
    public Builder setTitle(@StringRes int titleId)
    {
      mTitle = mContext.getString(titleId);
      return this;
    }

    @NonNull
    public Builder setMessage(@StringRes int messageId)
    {
      mMessage = mContext.getString(messageId);
      return this;
    }

    @NonNull
    public Builder setPositiveButton(@StringRes int resId,
                                     @Nullable DialogInterface.OnClickListener listener)
    {
      mPositive = mContext.getString(resId);
      mPositiveListener = listener;
      return this;
    }

    @NonNull
    public Builder setNeutralButton(@StringRes int resId,
                                    @Nullable DialogInterface.OnClickListener listener)
    {
      mNeutral = mContext.getString(resId);
      mNeutralListener = listener;
      return this;
    }

    @NonNull
    public Builder setNegativeButton(@StringRes int resId,
                                     @Nullable DialogInterface.OnClickListener listener)
    {
      mNegative = mContext.getString(resId);
      mNegativeListener = listener;
      return this;
    }

    @NonNull
    public Builder setCancelable(boolean cancelable)
    {
      mCancelable = cancelable;
      return this;
    }

    @NonNull
    public Builder setCancelListener(@Nullable DialogInterface.OnCancelListener listener)
    {
      mCancelListener = listener;
      return this;
    }

    @NonNull
    public StackedButtonsDialog build()
    {
      return new StackedButtonsDialog(mContext, mTitle, mMessage, mPositive, mPositiveListener,
                                      mNeutral, mNeutralListener, mNegative, mNegativeListener,
                                      mCancelable, mCancelListener);
    }
  }
}