| 
 | 1 | +/*  | 
 | 2 | + * Copyright 2013 Inmite s.r.o. (www.inmite.eu).  | 
 | 3 | + *  | 
 | 4 | + * Licensed under the Apache License, Version 2.0 (the "License");  | 
 | 5 | + * you may not use this file except in compliance with the License.  | 
 | 6 | + * You may obtain a copy of the License at  | 
 | 7 | + *  | 
 | 8 | + *     http://www.apache.org/licenses/LICENSE-2.0  | 
 | 9 | + *  | 
 | 10 | + * Unless required by applicable law or agreed to in writing, software  | 
 | 11 | + * distributed under the License is distributed on an "AS IS" BASIS,  | 
 | 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  | 
 | 13 | + * See the License for the specific language governing permissions and  | 
 | 14 | + * limitations under the License.  | 
 | 15 | + */  | 
 | 16 | + | 
 | 17 | +package com.avast.dialogs;  | 
 | 18 | + | 
 | 19 | +import java.text.DateFormat;  | 
 | 20 | +import java.util.Date;  | 
 | 21 | + | 
 | 22 | +import android.os.Bundle;  | 
 | 23 | +import android.support.v7.app.ActionBarActivity;  | 
 | 24 | +import android.view.View;  | 
 | 25 | +import android.widget.Toast;  | 
 | 26 | + | 
 | 27 | +import com.avast.android.dialogs.fragment.*;  | 
 | 28 | +import com.avast.android.dialogs.iface.IDateDialogListener;  | 
 | 29 | +import com.avast.android.dialogs.iface.IListDialogListener;  | 
 | 30 | +import com.avast.android.dialogs.iface.ISimpleDialogCancelListener;  | 
 | 31 | +import com.avast.android.dialogs.iface.ISimpleDialogListener;  | 
 | 32 | + | 
 | 33 | +public class DemoActivity extends ActionBarActivity implements  | 
 | 34 | +    ISimpleDialogListener,  | 
 | 35 | +    IDateDialogListener,  | 
 | 36 | +    ISimpleDialogCancelListener,  | 
 | 37 | +    IListDialogListener {  | 
 | 38 | + | 
 | 39 | +    private static final int REQUEST_PROGRESS = 1;  | 
 | 40 | + | 
 | 41 | +    DemoActivity c = this;  | 
 | 42 | + | 
 | 43 | +    @Override  | 
 | 44 | +    public void onCreate(Bundle savedInstanceState) {  | 
 | 45 | +        super.onCreate(savedInstanceState);  | 
 | 46 | +        setContentView(R.layout.main);  | 
 | 47 | +        findViewById(R.id.message_dialog).setOnClickListener(new View.OnClickListener() {  | 
 | 48 | +            @Override  | 
 | 49 | +            public void onClick(View v) {  | 
 | 50 | +                SimpleDialogFragment.createBuilder(c, getSupportFragmentManager())  | 
 | 51 | +                    .setMessage("Love. Can know all the math in the \'verse but take a boat in the air that you don\'t " +  | 
 | 52 | +                        "love? She\'ll shake you off just as sure as a turn in the worlds. Love keeps her in the air when " +  | 
 | 53 | +                        "she oughtta fall down...tell you she\'s hurtin\' \'fore she keens...makes her a home.").show();  | 
 | 54 | +            }  | 
 | 55 | +        });  | 
 | 56 | +        findViewById(R.id.message_title_dialog).setOnClickListener(new View.OnClickListener() {  | 
 | 57 | +            @Override  | 
 | 58 | +            public void onClick(View v) {  | 
 | 59 | +                SimpleDialogFragment.createBuilder(c, getSupportFragmentManager())  | 
 | 60 | +                    .setTitle("More Firefly quotes:").setMessage  | 
 | 61 | +                    ("Wash: \"Psychic, though? That sounds like something out of science fiction.\"\n\nZoe: \"We live" +  | 
 | 62 | +                        " " +  | 
 | 63 | +                        "in a space ship, dear.\"\nWash: \"Here lies my beloved Zoe, " +  | 
 | 64 | +                        ("my autumn flower ... somewhat less attractive now that she's all corpsified and gross" +  | 
 | 65 | +                            ".\"\n\nRiver Tam: \"Also? I can kill you with my brain.\"\n\nKayle: \"Going on a year now, nothins twixed my neathers not run on batteries.\" \n" +  | 
 | 66 | +                            "Mal: \"I can't know that.\" \n" +  | 
 | 67 | +                            "Jayne: \"I can stand to hear a little more.\"\n\nWash: \"I've been under fire before. " +  | 
 | 68 | +                            "Well ... I've been in a fire. Actually, I was fired. I can handle myself.\""))  | 
 | 69 | +                    .setNegativeButtonText("Close")  | 
 | 70 | +                    .show();  | 
 | 71 | +            }  | 
 | 72 | +        });  | 
 | 73 | +        findViewById(R.id.message_title_buttons_dialog)  | 
 | 74 | +            .setOnClickListener(new View.OnClickListener() {  | 
 | 75 | +                @Override  | 
 | 76 | +                public void onClick(View v) {  | 
 | 77 | +                    SimpleDialogFragment.createBuilder(c, getSupportFragmentManager())  | 
 | 78 | +                        .setTitle("Do you like this quote?")  | 
 | 79 | +                        .setMessage("Jayne: \"Shiny. Let's be bad guys.\"")  | 
 | 80 | +                        .setPositiveButtonText("Love")  | 
 | 81 | +                        .setNegativeButtonText("Hate").setNeutralButtonText("WTF?").setRequestCode(42)  | 
 | 82 | +                        .show();  | 
 | 83 | +                }  | 
 | 84 | +            });  | 
 | 85 | +        findViewById(R.id.long_buttons).setOnClickListener(new View.OnClickListener() {  | 
 | 86 | +            @Override  | 
 | 87 | +            public void onClick(View v) {  | 
 | 88 | +                SimpleDialogFragment.createBuilder(c, getSupportFragmentManager()).setMessage("How will you decide?")  | 
 | 89 | +                    .setPositiveButtonText("Time for some thrillin' heroics!").setNegativeButtonText("Misbehave")  | 
 | 90 | +                    .setNeutralButtonText("Keep flying").show();  | 
 | 91 | +            }  | 
 | 92 | +        });  | 
 | 93 | +        findViewById(R.id.progress_dialog).setOnClickListener(new View.OnClickListener() {  | 
 | 94 | +            @Override  | 
 | 95 | +            public void onClick(View v) {  | 
 | 96 | +                ProgressDialogFragment.createBuilder(c, getSupportFragmentManager())  | 
 | 97 | +                    .setMessage("Mal: I\'m just waiting to see if I pass out. Long story.")  | 
 | 98 | +                    .setRequestCode(REQUEST_PROGRESS)  | 
 | 99 | +                    .show();  | 
 | 100 | +            }  | 
 | 101 | +        });  | 
 | 102 | +        findViewById(R.id.list_dialog).setOnClickListener(new View.OnClickListener() {  | 
 | 103 | +            @Override  | 
 | 104 | +            public void onClick(View v) {  | 
 | 105 | +                ListDialogFragment  | 
 | 106 | +                    .createBuilder(c, getSupportFragmentManager())  | 
 | 107 | +                    .setTitle("Your favorite character:")  | 
 | 108 | +                    .setItems(new String[]{"Jayne", "Malcolm", "Kaylee",  | 
 | 109 | +                        "Wash", "Zoe", "River"})  | 
 | 110 | +                    .show();  | 
 | 111 | + | 
 | 112 | +            }  | 
 | 113 | +        });  | 
 | 114 | +        findViewById(R.id.custom_dialog).setOnClickListener(new View.OnClickListener() {  | 
 | 115 | +            @Override  | 
 | 116 | +            public void onClick(View v) {  | 
 | 117 | +                JayneHatDialogFragment.show(c);  | 
 | 118 | +            }  | 
 | 119 | +        });  | 
 | 120 | +        findViewById(R.id.time_picker).setOnClickListener(new View.OnClickListener() {  | 
 | 121 | +            @Override  | 
 | 122 | +            public void onClick(View v) {  | 
 | 123 | +                TimePickerDialogFragment  | 
 | 124 | +                    .createBuilder(DemoActivity.this, getSupportFragmentManager())  | 
 | 125 | +                    .setDate(new Date())  | 
 | 126 | +                    .set24hour(true)  | 
 | 127 | +                    .setPositiveButtonText(android.R.string.ok)  | 
 | 128 | +                    .setNegativeButtonText(android.R.string.cancel)  | 
 | 129 | +                    .setRequestCode(13)  | 
 | 130 | +                    .show();  | 
 | 131 | +            }  | 
 | 132 | +        });  | 
 | 133 | +        findViewById(R.id.date_picker).setOnClickListener(new View.OnClickListener() {  | 
 | 134 | +            @Override  | 
 | 135 | +            public void onClick(View v) {  | 
 | 136 | +                DatePickerDialogFragment  | 
 | 137 | +                    .createBuilder(DemoActivity.this, getSupportFragmentManager())  | 
 | 138 | +                    .setDate(new Date())  | 
 | 139 | +                    .set24hour(true)  | 
 | 140 | +                    .setPositiveButtonText(android.R.string.ok)  | 
 | 141 | +                    .setNegativeButtonText(android.R.string.cancel)  | 
 | 142 | +                    .setRequestCode(12)  | 
 | 143 | +                    .show();  | 
 | 144 | +            }  | 
 | 145 | +        });  | 
 | 146 | +    }  | 
 | 147 | + | 
 | 148 | +    // IListDialogListener  | 
 | 149 | + | 
 | 150 | +    @Override  | 
 | 151 | +    public void onListItemSelected(String value, int number) {  | 
 | 152 | +        Toast.makeText(c, "Selected: " + value, Toast.LENGTH_SHORT).show();  | 
 | 153 | +    }  | 
 | 154 | + | 
 | 155 | +    @Override  | 
 | 156 | +    public void onCancelled() {  | 
 | 157 | +        Toast.makeText(c, "Nothing selected", Toast.LENGTH_SHORT).show();  | 
 | 158 | +    }  | 
 | 159 | + | 
 | 160 | +    // ISimpleDialogCancelListener  | 
 | 161 | + | 
 | 162 | +    @Override  | 
 | 163 | +    public void onCancelled(int requestCode) {  | 
 | 164 | +        if (requestCode == 42) {  | 
 | 165 | +            Toast.makeText(c, "Dialog cancelled", Toast.LENGTH_SHORT).show();  | 
 | 166 | +        } else if (requestCode == REQUEST_PROGRESS) {  | 
 | 167 | +            Toast.makeText(c, "Progress dialog cancelled", Toast.LENGTH_SHORT).show();  | 
 | 168 | +        }  | 
 | 169 | +    }  | 
 | 170 | + | 
 | 171 | +    // ISimpleDialogListener  | 
 | 172 | + | 
 | 173 | +    @Override  | 
 | 174 | +    public void onPositiveButtonClicked(int requestCode) {  | 
 | 175 | +        if (requestCode == 42) {  | 
 | 176 | +            Toast.makeText(c, "Positive button clicked", Toast.LENGTH_SHORT).show();  | 
 | 177 | +        }  | 
 | 178 | +    }  | 
 | 179 | + | 
 | 180 | +    @Override  | 
 | 181 | +    public void onNegativeButtonClicked(int requestCode) {  | 
 | 182 | +        if (requestCode == 42) {  | 
 | 183 | +            Toast.makeText(c, "Negative button clicked", Toast.LENGTH_SHORT).show();  | 
 | 184 | +        }  | 
 | 185 | +    }  | 
 | 186 | + | 
 | 187 | +    @Override  | 
 | 188 | +    public void onNeutralButtonClicked(int requestCode) {  | 
 | 189 | +        if (requestCode == 42) {  | 
 | 190 | +            Toast.makeText(c, "Neutral button clicked", Toast.LENGTH_SHORT).show();  | 
 | 191 | +        }  | 
 | 192 | +    }  | 
 | 193 | + | 
 | 194 | +    // IDateDialogListener  | 
 | 195 | + | 
 | 196 | +    @Override  | 
 | 197 | +    public void onNegativeButtonClicked(int resultCode, Date date) {  | 
 | 198 | +        String text = "";  | 
 | 199 | +        if (resultCode == 12) {  | 
 | 200 | +            text = "Date ";  | 
 | 201 | +        } else if (resultCode == 13) {  | 
 | 202 | +            text = "Time ";  | 
 | 203 | +        }  | 
 | 204 | + | 
 | 205 | +        DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.DEFAULT);  | 
 | 206 | +        Toast.makeText(this, text + "Cancelled " + dateFormat.format(date), Toast.LENGTH_SHORT).show();  | 
 | 207 | +    }  | 
 | 208 | + | 
 | 209 | +    @Override  | 
 | 210 | +    public void onPositiveButtonClicked(int resultCode, Date date) {  | 
 | 211 | +        String text = "";  | 
 | 212 | +        if (resultCode == 12) {  | 
 | 213 | +            text = "Date ";  | 
 | 214 | +        } else if (resultCode == 13) {  | 
 | 215 | +            text = "Time ";  | 
 | 216 | +        }  | 
 | 217 | + | 
 | 218 | +        DateFormat dateFormat = DateFormat.getDateTimeInstance();  | 
 | 219 | +        Toast.makeText(this, text + "Success! " + dateFormat.format(date), Toast.LENGTH_SHORT).show();  | 
 | 220 | +    }  | 
 | 221 | +}  | 
0 commit comments