aboutsummaryrefslogtreecommitdiff
path: root/src/com/cyanogenmod/filemanager/util/DialogHelper.java
blob: d357d1b3645690f8eba5d307f70dabe9cdb32abd (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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
/*
 * Copyright (C) 2012 The CyanogenMod Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.cyanogenmod.filemanager.util;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.text.InputFilter;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.widget.AbsListView;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListAdapter;
import android.widget.ListPopupWindow;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import com.cyanogenmod.filemanager.R;
import com.cyanogenmod.filemanager.activities.NavigationActivity;
import com.cyanogenmod.filemanager.adapters.CheckableListAdapter;
import com.cyanogenmod.filemanager.ui.ThemeManager;
import com.cyanogenmod.filemanager.ui.ThemeManager.Theme;

import java.util.ArrayList;
import java.util.List;

/**
 * A helper class with useful methods for deal with dialogs.
 */
public final class DialogHelper {

    /**
     * An interface to listen the selection make for the user.
     */
    public interface OnSelectChoiceListener {
        /**
         * Method invoked when the user select an option
         *
         * @param choice The selected option
         */
        public void onSelectChoice(int choice);
        /**
         * Method invoked when the user not select any option
         */
        public void onNoSelectChoice();
    }

    /**
     * Constructor of <code>DialogHelper</code>.
     */
    private DialogHelper() {
        super();
    }

    /**
     * Method that creates a new warning {@link AlertDialog}.
     *
     * @param context The current context
     * @param title The resource identifier of the title of the alert dialog
     * @param message The resource identifier of the message of the alert dialog
     * @return AlertDialog The alert dialog reference
     */
    public static AlertDialog createWarningDialog(Context context, int title, int message) {
        return createWarningDialog(context, title, context.getString(message));
    }

    /**
     * Method that creates a new warning {@link AlertDialog}.
     *
     * @param context The current context
     * @param title The resource identifier of the title of the alert dialog
     * @param message The message of the alert dialog
     * @return AlertDialog The alert dialog reference
     */
    public static AlertDialog createWarningDialog(Context context, int title, String message) {
        return createAlertDialog(
                context,
                0,
                title,
                message,
                false);
    }

    /**
     * Method that creates a new error {@link AlertDialog}.
     *
     * @param context The current context
     * @param title The resource identifier of the title of the alert dialog
     * @param message The resource identifier of the message of the alert dialog
     * @return AlertDialog The alert dialog reference
     */
    public static AlertDialog createErrorDialog(Context context, int title, int message) {
        return createErrorDialog(context, title, context.getString(message));
    }

    /**
     * Method that creates a new error {@link AlertDialog}.
     *
     * @param context The current context
     * @param title The resource identifier of the title of the alert dialog
     * @param message The message of the alert dialog
     * @return AlertDialog The alert dialog reference
     */
    public static AlertDialog createErrorDialog(Context context, int title, String message) {
        return createAlertDialog(
                context,
                0,
                title,
                message,
                false);
    }

    /**
     * Method that creates a new {@link AlertDialog}.
     *
     * @param context The current context
     * @param icon The icon resource
     * @param title The resource identifier of the title of the alert dialog
     * @param message The resource identifier of the message of the alert dialog
     * @param allCaps If the title must have his text in caps or not
     * @return AlertDialog The alert dialog reference
     */
    public static AlertDialog createAlertDialog(
            Context context, int icon, int title, int message, boolean allCaps) {
        return createAlertDialog(context, icon, title, context.getString(message), allCaps);
    }

    /**
     * Method that creates a new {@link AlertDialog}.
     *
     * @param context The current context
     * @param icon The icon resource
     * @param title The resource identifier of the title of the alert dialog
     * @param message The message of the alert dialog
     * @param allCaps If the title must have his text in caps or not
     * @return AlertDialog The alert dialog reference
     */
    public static AlertDialog createAlertDialog(
            Context context, int icon, int title, String message, boolean allCaps) {
        //Create the alert dialog
        AlertDialog.Builder builder = new AlertDialog.Builder(context);
        builder.setCustomTitle(createTitle(context, icon, context.getString(title), allCaps));
        builder.setView(createMessage(context, message));
        builder.setPositiveButton(context.getString(R.string.ok), null);
        return builder.create();
    }

    /**
     * Method that creates a new {@link AlertDialog} for choice between single options.
     *
     * @param context The current context
     * @param title The resource identifier of the title of the alert dialog
     * @param options An array with the options
     * @param defOption The default option
     * @param onSelectChoiceListener The listener for user choice
     * @return AlertDialog The alert dialog reference
     */
    public static AlertDialog createSingleChoiceDialog(
            Context context, int title,
            String[] options, int defOption,
            final OnSelectChoiceListener onSelectChoiceListener) {
        //Create the alert dialog
        final StringBuffer item = new StringBuffer().append(defOption);
        AlertDialog.Builder builder = new AlertDialog.Builder(context);
        builder.setCustomTitle(createTitle(context, 0, context.getString(title), false));

        // Create the adapter
        List<CheckableListAdapter.CheckableItem> items =
                new ArrayList<CheckableListAdapter.CheckableItem>(options.length);
        int cc = options.length;
        for (int i = 0; i < cc; i++) {
            boolean checked = (i == defOption);
            items.add(new CheckableListAdapter.CheckableItem(options[i], true, checked));
        }
        final CheckableListAdapter adapter = new CheckableListAdapter(context, items, true);

        // Create the list view and set as view
        final ListView listView = new ListView(context);
        LinearLayout.LayoutParams params =
                new LinearLayout.LayoutParams(
                        LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
        listView.setLayoutParams(params);
        listView.setAdapter(adapter);
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                item.delete(0, item.length());
                item.append(position);
                adapter.setSelectedItem(position);
            }
        });
        adapter.setSelectedItem(defOption);
        listView.setChoiceMode(AbsListView.CHOICE_MODE_SINGLE);
        builder.setView(listView);

        // Apply the current theme
        Theme theme = ThemeManager.getCurrentTheme(context);
        theme.setBackgroundDrawable(context, listView, "background_drawable"); //$NON-NLS-1$
        listView.setDivider(
                theme.getDrawable(context, "horizontal_divider_drawable")); //$NON-NLS-1$

        builder.setNegativeButton(context.getString(R.string.cancel), new OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                onSelectChoiceListener.onNoSelectChoice();
                dialog.cancel();
            }
        });
        builder.setPositiveButton(context.getString(R.string.ok), new OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                onSelectChoiceListener.onSelectChoice(Integer.parseInt(item.toString()));
                dialog.dismiss();
            }
        });
        return builder.create();
    }

    /**
     * Method that creates a new YES/NO {@link AlertDialog}.
     *
     * @param context The current context
     * @param title The resource identifier of the title of the alert dialog
     * @param message The resource identifier of the message of the alert dialog
     * @param onClickListener The listener where returns the button pressed
     * @return AlertDialog The alert dialog reference
     */
    public static AlertDialog createYesNoDialog(
            Context context, int title, int message, OnClickListener onClickListener) {
        return createYesNoDialog(context, title, context.getString(message), onClickListener);
    }

    /**
     * Method that creates a new YES/NO {@link AlertDialog}.
     *
     * @param context The current context
     * @param title The resource identifier of the title of the alert dialog
     * @param message The message of the alert dialog
     * @param onClickListener The listener where returns the button pressed
     * @return AlertDialog The alert dialog reference
     */
    public static AlertDialog createYesNoDialog(
            Context context, int title, String message, OnClickListener onClickListener) {
        //Create the alert dialog
        AlertDialog.Builder builder = new AlertDialog.Builder(context);
        builder.setCustomTitle(
                createTitle(
                        context,
                        0,
                        context.getString(title),
                        false));
        builder.setView(createMessage(context, message));
        AlertDialog dialog = builder.create();
        dialog.setButton(
                DialogInterface.BUTTON_POSITIVE, context.getString(R.string.yes), onClickListener);
        dialog.setButton(
                DialogInterface.BUTTON_NEGATIVE, context.getString(R.string.no), onClickListener);
        return dialog;
    }

    /**
     * Method that creates a new YES/ALL/NO {@link AlertDialog}.
     *
     * @param context The current context
     * @param title The resource identifier of the title of the alert dialog
     * @param message The resource identifier of the message of the alert dialog
     * @param onClickListener The listener where returns the button pressed
     * @return AlertDialog The alert dialog reference
     */
    public static AlertDialog createYesNoAllDialog(
            Context context, int title, int message, OnClickListener onClickListener) {
        return createYesNoAllDialog(context, title, context.getString(message), onClickListener);
    }

    /**
     * Method that creates a new YES/ALL/NO {@link AlertDialog}.
     *
     * @param context The current context
     * @param title The resource identifier of the title of the alert dialog
     * @param message The message of the alert dialog
     * @param onClickListener The listener where returns the button pressed
     * @return AlertDialog The alert dialog reference
     */
    public static AlertDialog createYesNoAllDialog(
            Context context, int title, String message, OnClickListener onClickListener) {
        //Create the alert dialog
        AlertDialog.Builder builder = new AlertDialog.Builder(context);
        builder.setCustomTitle(
                createTitle(
                        context,
                        0,
                        context.getString(title),
                        false));
        builder.setView(createMessage(context, message));
        AlertDialog dialog = builder.create();
        dialog.setButton(
                DialogInterface.BUTTON_POSITIVE, context.getString(R.string.yes), onClickListener);
        dialog.setButton(
                DialogInterface.BUTTON_NEGATIVE, context.getString(R.string.no), onClickListener);
        dialog.setButton(
                DialogInterface.BUTTON_NEUTRAL, context.getString(R.string.all), onClickListener);
        return dialog;
    }

    /**
     * Method that creates a two buttons question {@link AlertDialog}.
     *
     * @param context The current context
     * @param button1 The resource identifier of the text of the button 1 (POSITIVE)
     * @param button2 The resource identifier of the text of the button 2 (NEGATIVE)
     * @param title The resource id of the title of the alert dialog
     * @param message The message of the alert dialog
     * @param onClickListener The listener where returns the button pressed
     * @return AlertDialog The alert dialog reference
     */
    public static AlertDialog createTwoButtonsQuestionDialog(
            Context context, int button1, int button2,
            int title, String message, OnClickListener onClickListener) {
        //Create the alert dialog
        AlertDialog.Builder builder = new AlertDialog.Builder(context);
        builder.setCustomTitle(
                createTitle(
                        context,
                        0,
                        context.getString(title),
                        false));
        builder.setView(createMessage(context, message));
        AlertDialog dialog = builder.create();
        dialog.setButton(
                DialogInterface.BUTTON_POSITIVE, context.getString(button1), onClickListener);
        dialog.setButton(
                DialogInterface.BUTTON_NEGATIVE, context.getString(button2), onClickListener);
        return dialog;
    }

    /**
     * Method that creates a three buttons question {@link AlertDialog}.
     *
     * @param context The current context
     * @param button1 The resource identifier of the text of the button 1 (POSITIVE)
     * @param button2 The resource identifier of the text of the button 2 (NEUTRAL)
     * @param button3 The resource identifier of the text of the button 3 (NEGATIVE)
     * @param title The resource id of the title of the alert dialog
     * @param message The message of the alert dialog
     * @param onClickListener The listener where returns the button pressed
     * @return AlertDialog The alert dialog reference
     */
    public static AlertDialog createThreeButtonsQuestionDialog(
            Context context, int button1, int button2, int button3,
            int title, String message, OnClickListener onClickListener) {
        //Create the alert dialog
        AlertDialog.Builder builder = new AlertDialog.Builder(context);
        builder.setCustomTitle(
                createTitle(
                        context,
                        0,
                        context.getString(title),
                        false));
        builder.setView(createMessage(context, message));
        AlertDialog dialog = builder.create();
        dialog.setButton(
                DialogInterface.BUTTON_POSITIVE, context.getString(button1), onClickListener);
        dialog.setButton(
                DialogInterface.BUTTON_NEUTRAL, context.getString(button2), onClickListener);
        dialog.setButton(
                DialogInterface.BUTTON_NEGATIVE, context.getString(button3), onClickListener);
        return dialog;
    }

    /**
     * Method that creates a new {@link AlertDialog}.
     *
     * @param context The current context
     * @param icon The icon resource
     * @param title The resource identifier of the title of the alert dialog
     * @param content The content layout
     * @return AlertDialog The alert dialog reference
     */
    public static AlertDialog createDialog(Context context, int icon, int title, View content) {
        return createDialog(context, icon, context.getString(title), content);
    }

    /**
     * Method that creates a new {@link AlertDialog}.
     *
     * @param context The current context
     * @param icon The icon resource
     * @param title The title of the alert dialog
     * @param content The content layout
     * @return AlertDialog The alert dialog reference
     */
    public static AlertDialog createDialog(Context context, int icon, String title, View content) {
        //Create the alert dialog
        final AlertDialog.Builder builder = new AlertDialog.Builder(context);
        builder.setCustomTitle(createTitle(context, icon, title, false));
        builder.setView(content);
        return builder.create();
    }

    /**
     * Method that creates a new {@link AlertDialog} with one buttons.
     *
     * @param context The current context
     * @param button1 The resource identifier of the text of the button 1 (POSITIVE)
     * @param icon The icon resource
     * @param title The title of the alert dialog
     * @param content The content layout
     * @param onClickListener The listener where returns the button pressed
     * @return AlertDialog The alert dialog reference
     */
    public static AlertDialog createOneButtonsDialog(Context context, int button1,
            int icon, String title, View content, OnClickListener onClickListener) {
        //Create the alert dialog
        final AlertDialog.Builder builder = new AlertDialog.Builder(context);
        builder.setCustomTitle(createTitle(context, icon, title, false));
        builder.setView(content);
        AlertDialog dialog = builder.create();
        dialog.setButton(
                DialogInterface.BUTTON_POSITIVE, context.getString(button1), onClickListener);
        return dialog;
    }

    /**
     * Method that creates a new {@link AlertDialog} with two buttons.
     *
     * @param context The current context
     * @param button1 The resource identifier of the text of the button 1 (POSITIVE)
     * @param button2 The resource identifier of the text of the button 2 (NEUTRAL)
     * @param icon The icon resource
     * @param title The title of the alert dialog
     * @param content The content layout
     * @param onClickListener The listener where returns the button pressed
     * @return AlertDialog The alert dialog reference
     */
    public static AlertDialog createTwoButtonsDialog(Context context, int button1, int button2,
            int icon, String title, View content, OnClickListener onClickListener) {
        //Create the alert dialog
        final AlertDialog.Builder builder = new AlertDialog.Builder(context);
        builder.setCustomTitle(createTitle(context, icon, title, false));
        builder.setView(content);
        AlertDialog dialog = builder.create();
        dialog.setButton(
                DialogInterface.BUTTON_POSITIVE, context.getString(button1), onClickListener);
        dialog.setButton(
                DialogInterface.BUTTON_NEGATIVE, context.getString(button2), onClickListener);
        return dialog;
    }

    /**
     * Method that creates a new {@link AlertDialog} with three buttons.
     *
     * @param context The current context
     * @param button1 The resource identifier of the text of the button 1 (POSITIVE)
     * @param button2 The resource identifier of the text of the button 2 (NEUTRAL)
     * @param button3 The resource identifier of the text of the button 3 (NEGATIVE)
     * @param icon The icon resource
     * @param title The title of the alert dialog
     * @param content The content layout
     * @param onClickListener The listener where returns the button pressed
     * @return AlertDialog The alert dialog reference
     */
    public static AlertDialog createThreeButtonsDialog(Context context, int button1, int button2,
            int button3, int icon, String title, View content, OnClickListener onClickListener) {
        //Create the alert dialog
        final AlertDialog.Builder builder = new AlertDialog.Builder(context);
        builder.setCustomTitle(createTitle(context, icon, title, false));
        builder.setView(content);
        AlertDialog dialog = builder.create();
        dialog.setButton(
                DialogInterface.BUTTON_POSITIVE, context.getString(button1), onClickListener);
        dialog.setButton(
                DialogInterface.BUTTON_NEUTRAL, context.getString(button2), onClickListener);
        dialog.setButton(
                DialogInterface.BUTTON_NEGATIVE, context.getString(button3), onClickListener);
        return dialog;
    }

    /**
     * Method that creates and returns the title of the dialog.
     *
     * @param context The current context
     * @param icon The icon resource
     * @param title The resource identifier of the title of the alert dialog
     * @param allCaps If the title must have his text in caps or not
     * @return The title view
     */
    private static View createTitle(Context context, int icon, String title, boolean allCaps) {
        //Inflate the dialog layouts
        LayoutInflater li =
                (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View lyTitle = li.inflate(R.layout.dialog_title, null);
        ImageView vIcon = (ImageView)lyTitle.findViewById(R.id.dialog_title_icon);
        if (icon != 0) {
            vIcon.setBackgroundResource(icon);
        } else {
            vIcon.setVisibility(View.GONE);
        }
        TextView vText = (TextView)lyTitle.findViewById(R.id.dialog_title_text);
        if (allCaps) {
            vText.setFilters(new InputFilter[]{new InputFilter.AllCaps()});
        }
        vText.setText(title);

        // Apply the current theme
        Theme theme = ThemeManager.getCurrentTheme(context);
        theme.setBackgroundDrawable(context, lyTitle, "background_drawable"); //$NON-NLS-1$
        theme.setTextColor(context, vText, "dialog_text_color"); //$NON-NLS-1$

        return lyTitle;
    }

    /**
     * Method that creates and returns the title of the dialog.
     *
     * @param context The current context
     * @param message The the message of the alert dialog
     * @return The title view
     */
    private static View createMessage(Context context, String message) {
        //Inflate the dialog layouts
        LayoutInflater li =
                (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View lyMessage = li.inflate(
                            R.layout.dialog_message,
                            null);
        TextView vMsg = (TextView)lyMessage.findViewById(R.id.dialog_message);
        // Dialog need to be filled with at least two lines to fill the background dialog,
        // so we add a new additional line to the message
        vMsg.setText(message + "\n"); //$NON-NLS-1$

        // Apply the current theme
        Theme theme = ThemeManager.getCurrentTheme(context);
        theme.setBackgroundDrawable(context, lyMessage, "background_drawable"); //$NON-NLS-1$
        theme.setTextColor(context, vMsg, "text_color"); //$NON-NLS-1$

        return lyMessage;
    }

    /**
     * Method that creates and returns a {@list ListPopupWindow} reference.
     *
     * @param context The current context
     * @param adapter The adapter to associate with the popup
     * @param anchor The view that is used as an anchor to show the popup
     * @return ListPopupWindow The {@list ListPopupWindow} reference
     */
    public static ListPopupWindow createListPopupWindow(
            Context context, final ListAdapter adapter, View anchor) {
        final ListPopupWindow popup = new ListPopupWindow(context);
        popup.setAdapter(adapter);
        popup.setContentWidth(context.getResources().getDimensionPixelSize(R.dimen.popup_width));
        popup.setAnchorView(anchor);
        popup.setModal(true);

        // HACK: set the height to the size of the device screen width or height depending on
        // which is smaller.
        // Because we are handling the orientation change instead of letting
        // android do its thing, this never redraws. If we remove the orientation
        // change, then all the other popup dialogs break when rotating.
        // This isn't perfect, but without some significant changes to this app we cannot
        // properly do this.
        // Get the screen size, determine what number is lower, use that for the height
        DisplayMetrics dM = context.getResources().getDisplayMetrics();
        float width = dM.widthPixels / dM.density;
        float height = dM.heightPixels / dM.density;
        popup.setHeight((int)Math.min(height, width));

        return popup;
    }

    /**
     * Method that delegates the display of a dialog. This method applies the style to the
     * dialog, so all dialogs of the application MUST used this method to display the dialog.
     *
     * @param context The current context
     * @param dialog The dialog to show
     */
    public static void delegateDialogShow(Context context, AlertDialog dialog) {
        boolean isActivityFinishing = false;
        if (context instanceof Activity) {
            Activity activity = (Activity) context;
            if (activity instanceof NavigationActivity) {
                ((NavigationActivity) activity).updateActiveDialog(dialog);
            }
            isActivityFinishing = activity.isFinishing();
        }

        if (!isActivityFinishing) {
            // Show the dialog
            dialog.show();
        }

        // Apply theme
        Theme theme = ThemeManager.getCurrentTheme(context);
        theme.setDialogStyle(context, dialog);
    }

    /**
     * Method that creates and display a toast dialog.
     *
     * @param context The context to use.
     * @param msg The message to display.
     * @param duration How long to display the message.
     */
    public static void showToast(Context context, String msg, int duration) {
        Toast.makeText(context, msg, duration).show();
    }

    /**
     * Method that creates and display a toast dialog.
     *
     * @param context The context to use.
     * @param msgResourceId The resource id of the string resource to use.
     * @param duration How long to display the message.
     */
    public static void showToast(Context context, int msgResourceId, int duration) {
        showToast(context, context.getString(msgResourceId), duration);
    }

}