1 package ro
.ieval
.fonbot
;
3 import static ro
.ieval
.fonbot
.R
.string
.*;
5 import static ro
.ieval
.fonbot
.Utils
.toNonNull
;
7 import org
.eclipse
.jdt
.annotation
.Nullable
;
9 import android
.app
.Activity
;
10 import android
.os
.Bundle
;
11 import android
.view
.View
;
12 import android
.view
.View
.OnClickListener
;
13 import android
.widget
.Button
;
14 import android
.widget
.LinearLayout
;
15 import android
.widget
.TextView
;
18 * Copyright © 2013 Marius Gavrilescu
20 * This file is part of FonBot.
22 * FonBot is free software: you can redistribute it and/or modify
23 * it under the terms of the GNU General Public License as published by
24 * the Free Software Foundation, either version 3 of the License, or
25 * (at your option) any later version.
27 * FonBot is distributed in the hope that it will be useful,
28 * but WITHOUT ANY WARRANTY; without even the implied warranty of
29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30 * GNU General Public License for more details.
32 * You should have received a copy of the GNU General Public License
33 * along with FonBot. If not, see <http://www.gnu.org/licenses/>.
37 * A dialog created by the {@link Utils.Command#DIALOG DIALOG} command. Includes a message and a list of buttons, all user-defined
39 * @author Marius Gavrilescu <marius@ieval.ro>
41 public final class DialogActivity
extends Activity
{
42 /** Extra: string array of dialog buttons */
43 public static final String EXTRA_BUTTONS
= "buttons";
44 /** Extra: dialog message */
45 public static final String EXTRA_MESSAGE
= "message";
46 /** Extra: reply Address */
47 public static final String EXTRA_REPLYTO
= "replyto";
49 /** true if the dialog is finishing because the user tapped a button, false otherwise */
50 private boolean gotAnswer
=false;
52 private Address address
;
55 protected void onCreate(@Nullable final Bundle icicle
) {
56 super.onCreate(icicle
);
57 address
=new Address(toNonNull(getIntent().getStringExtra(EXTRA_REPLYTO
)));
58 final LinearLayout layout
=new LinearLayout(this);
59 layout
.setOrientation(LinearLayout
.VERTICAL
);
60 if(getIntent().hasExtra(EXTRA_MESSAGE
)){
61 final String text
=getIntent().getStringExtra(EXTRA_MESSAGE
);
62 final TextView tv
=new TextView(this);
66 final String
[] buttonLabels
=getIntent().getStringArrayExtra(EXTRA_BUTTONS
);
68 final OnClickListener buttonListener
=new OnClickListener() {
70 public void onClick(@Nullable final View v
) {
74 Utils
.sendMessage(DialogActivity
.this, toNonNull(address
),
75 toNonNull(getString(user_tapped_fmt
, ((Button
)v
).getText())));
80 for(final String label
: buttonLabels
){
81 final Button b
=new Button(this);//NOPMD buttons must be different
83 b
.setOnClickListener(buttonListener
);
86 setContentView(layout
);
90 protected void onStop() {
93 Utils
.sendMessage(this, toNonNull(address
),
94 toNonNull(getString(user_navigated_away_from_dialog
)));
101 public void onBackPressed() {
103 Utils
.sendMessage(this, toNonNull(address
),
104 toNonNull(getString(user_canceled_dialog
)));