Project

General

Profile

Download (5.25 KB) Statistics
| Branch: | Tag: | Revision:

magiccube / src / main / java / org / distorted / dialogs / RubikDialogInfo.java @ af88bf2e

1 a8576d91 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2020 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6
// Magic Cube is free software: you can redistribute it and/or modify                            //
7
// it under the terms of the GNU General Public License as published by                          //
8
// the Free Software Foundation, either version 2 of the License, or                             //
9
// (at your option) any later version.                                                           //
10
//                                                                                               //
11
// Magic Cube is distributed in the hope that it will be useful,                                 //
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
14
// GNU General Public License for more details.                                                  //
15
//                                                                                               //
16
// You should have received a copy of the GNU General Public License                             //
17
// along with Magic Cube.  If not, see <http://www.gnu.org/licenses/>.                           //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19
20
package org.distorted.dialogs;
21
22
import android.app.Dialog;
23
import android.content.DialogInterface;
24 af88bf2e Leszek Koltunski
import android.content.Intent;
25 a8576d91 Leszek Koltunski
import android.os.Bundle;
26
import android.util.DisplayMetrics;
27
import android.util.TypedValue;
28
import android.view.LayoutInflater;
29
import android.view.View;
30
import android.view.Window;
31
import android.widget.Button;
32
import android.widget.TextView;
33
34
import androidx.annotation.NonNull;
35
import androidx.appcompat.app.AlertDialog;
36
import androidx.appcompat.app.AppCompatDialogFragment;
37
import androidx.fragment.app.FragmentActivity;
38
39
import org.distorted.main.R;
40
import org.distorted.main.RubikActivity;
41 80218b07 Leszek Koltunski
import org.distorted.objects.TwistyObject;
42 af88bf2e Leszek Koltunski
import org.distorted.tutorial.TutorialActivity;
43 a8576d91 Leszek Koltunski
44
///////////////////////////////////////////////////////////////////////////////////////////////////
45
46
public class RubikDialogInfo extends AppCompatDialogFragment
47
  {
48
  @NonNull
49
  @Override
50
  public Dialog onCreateDialog(Bundle savedInstanceState)
51
    {
52
    final FragmentActivity act = getActivity();
53
    LayoutInflater inflater = act.getLayoutInflater();
54
    AlertDialog.Builder builder = new AlertDialog.Builder(act);
55
56
    DisplayMetrics displaymetrics = new DisplayMetrics();
57
    act.getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
58
    final float titleSize= displaymetrics.widthPixels * RubikActivity.MENU_BIG_TEXT_SIZE;
59
    final float okSize   = displaymetrics.widthPixels * RubikActivity.DIALOG_BUTTON_SIZE;
60 80218b07 Leszek Koltunski
    TwistyObject object = getObject();
61
    int numLayers = object.getNumLayers();
62 a8576d91 Leszek Koltunski
63
    TextView tv = (TextView) inflater.inflate(R.layout.dialog_title, null);
64
    tv.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleSize);
65 80218b07 Leszek Koltunski
    tv.setText(object.getObjectName(numLayers));
66 a8576d91 Leszek Koltunski
    builder.setCustomTitle(tv);
67
68
    final View view = inflater.inflate(R.layout.dialog_error, null);
69
    TextView text = view.findViewById(R.id.error_string);
70 80218b07 Leszek Koltunski
    text.setText(R.string.tutorial);
71 a8576d91 Leszek Koltunski
72 80218b07 Leszek Koltunski
    builder.setPositiveButton( R.string.yes, new DialogInterface.OnClickListener()
73
      {
74
      @Override
75
      public void onClick(DialogInterface dialog, int which)
76
        {
77 af88bf2e Leszek Koltunski
        RubikActivity ract = (RubikActivity)getContext();
78
        Intent myIntent = new Intent(ract, TutorialActivity.class);
79
        //myIntent.putExtra("", value); //Optional parameters
80 80218b07 Leszek Koltunski
81 af88bf2e Leszek Koltunski
        if( ract!=null ) ract.startActivity(myIntent);
82 80218b07 Leszek Koltunski
        }
83
      });
84
85
    builder.setNegativeButton( R.string.no, new DialogInterface.OnClickListener()
86 a8576d91 Leszek Koltunski
      {
87
      @Override
88
      public void onClick(DialogInterface dialog, int which)
89
        {
90
91
        }
92
      });
93
94
    builder.setView(view);
95
96
    final Dialog dialog = builder.create();
97
    dialog.setCanceledOnTouchOutside(false);
98
99
    Window window = dialog.getWindow();
100
101
    if( window!=null )
102
      {
103
      window.getDecorView().setSystemUiVisibility(RubikActivity.FLAGS);
104
      }
105
106
    dialog.setOnShowListener(new DialogInterface.OnShowListener()
107
      {
108
      @Override
109
      public void onShow(DialogInterface dialog)
110
        {
111
        Button btnPositive = ((AlertDialog)dialog).getButton(Dialog.BUTTON_POSITIVE);
112
        btnPositive.setTextSize(TypedValue.COMPLEX_UNIT_PX, okSize);
113 80218b07 Leszek Koltunski
        Button btnNegative = ((AlertDialog)dialog).getButton(Dialog.BUTTON_NEGATIVE);
114
        btnNegative.setTextSize(TypedValue.COMPLEX_UNIT_PX, okSize);
115 a8576d91 Leszek Koltunski
        }
116
      });
117
118
    return dialog;
119
    }
120 80218b07 Leszek Koltunski
121
///////////////////////////////////////////////////////////////////////////////////////////////////
122
123
  private TwistyObject getObject()
124
    {
125
    RubikActivity act = (RubikActivity)getContext();
126
    return act.getObject();
127
    }
128 a8576d91 Leszek Koltunski
  }