Project

General

Profile

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

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

1
///////////////////////////////////////////////////////////////////////////////////////////////////
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
import android.content.Intent;
25
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
import org.distorted.objects.TwistyObject;
42
import org.distorted.tutorial.TutorialActivity;
43

    
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
    TwistyObject object = getObject();
61
    int numLayers = object.getNumLayers();
62

    
63
    TextView tv = (TextView) inflater.inflate(R.layout.dialog_title, null);
64
    tv.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleSize);
65
    tv.setText(object.getObjectName(numLayers));
66
    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
    text.setText(R.string.tutorial);
71

    
72
    builder.setPositiveButton( R.string.yes, new DialogInterface.OnClickListener()
73
      {
74
      @Override
75
      public void onClick(DialogInterface dialog, int which)
76
        {
77
        RubikActivity ract = (RubikActivity)getContext();
78
        Intent myIntent = new Intent(ract, TutorialActivity.class);
79
        //myIntent.putExtra("", value); //Optional parameters
80

    
81
        if( ract!=null ) ract.startActivity(myIntent);
82
        }
83
      });
84

    
85
    builder.setNegativeButton( R.string.no, new DialogInterface.OnClickListener()
86
      {
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
        Button btnNegative = ((AlertDialog)dialog).getButton(Dialog.BUTTON_NEGATIVE);
114
        btnNegative.setTextSize(TypedValue.COMPLEX_UNIT_PX, okSize);
115
        }
116
      });
117

    
118
    return dialog;
119
    }
120

    
121
///////////////////////////////////////////////////////////////////////////////////////////////////
122

    
123
  private TwistyObject getObject()
124
    {
125
    RubikActivity act = (RubikActivity)getContext();
126
    return act.getObject();
127
    }
128
  }
(4-4/16)