Project

General

Profile

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

magiccube / src / main / java / org / distorted / dialogs / RubikDialogAbout.java @ ffd68f35

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2019 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.pm.PackageInfo;
25
import android.content.pm.PackageManager;
26
import android.os.Bundle;
27
import androidx.annotation.NonNull;
28
import androidx.fragment.app.FragmentActivity;
29
import androidx.appcompat.app.AlertDialog;
30
import androidx.appcompat.app.AppCompatDialogFragment;
31

    
32
import android.text.method.LinkMovementMethod;
33
import android.text.method.MovementMethod;
34
import android.util.DisplayMetrics;
35
import android.util.TypedValue;
36
import android.view.LayoutInflater;
37
import android.view.View;
38
import android.view.Window;
39
import android.view.WindowManager;
40
import android.widget.Button;
41
import android.widget.TextView;
42

    
43
import org.distorted.main.R;
44
import org.distorted.main.RubikActivity;
45

    
46
///////////////////////////////////////////////////////////////////////////////////////////////////
47

    
48
public class RubikDialogAbout extends AppCompatDialogFragment
49
  {
50
  @NonNull
51
  @Override
52
  public Dialog onCreateDialog(Bundle savedInstanceState)
53
    {
54
    FragmentActivity act = getActivity();
55
    LayoutInflater inflater = act.getLayoutInflater();
56
    AlertDialog.Builder builder = new AlertDialog.Builder(act);
57

    
58
    DisplayMetrics displaymetrics = new DisplayMetrics();
59
    act.getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
60
    final float titleSize= displaymetrics.widthPixels * RubikActivity.MENU_BIG_TEXT_SIZE;
61
    final float okSize   = displaymetrics.widthPixels * RubikActivity.MENU_MEDIUM_TEXT_SIZE;
62
    final float textSize = displaymetrics.widthPixels * RubikActivity.MENU_SMALL_TEXT_SIZE;
63

    
64
    TextView tv = (TextView) inflater.inflate(R.layout.dialog_title, null);
65
    tv.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleSize);
66
    tv.setText(R.string.about);
67
    builder.setCustomTitle(tv);
68

    
69
    builder.setCancelable(true);
70
    builder.setPositiveButton( R.string.ok, new DialogInterface.OnClickListener()
71
      {
72
      @Override
73
      public void onClick(DialogInterface dialog, int which)
74
        {
75

    
76
        }
77
      });
78

    
79
    final View view = inflater.inflate(R.layout.dialog_about, null);
80
    TextView text = view.findViewById(R.id.about_version);
81
    String appName = getString(R.string.app_name);
82

    
83

    
84
    text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
85
    text.setText(getString(R.string.ap_placeholder,appName, getAppVers(act)));
86

    
87
    MovementMethod mm = LinkMovementMethod.getInstance();
88
    TextView text1 = view.findViewById(R.id.about_section1);
89
    text1.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
90
    text1.setMovementMethod(mm);
91
    TextView text2 = view.findViewById(R.id.about_section2);
92
    text2.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
93
    text2.setMovementMethod(mm);
94
    TextView text3 = view.findViewById(R.id.about_section3);
95
    text3.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
96
    text3.setMovementMethod(mm);
97

    
98
    TextView text4 = view.findViewById(R.id.about_section4);
99

    
100
    if( RubikActivity.localeIsChinese() )
101
      {
102
      text4.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
103
      text4.setMovementMethod(mm);
104
      }
105
    else
106
      {
107
      text4.setVisibility(View.GONE);
108
      }
109

    
110
    builder.setView(view);
111

    
112
    Dialog dialog = builder.create();
113
    dialog.setCanceledOnTouchOutside(false);
114
    Window window = dialog.getWindow();
115

    
116
    if( window!=null )
117
      {
118
      window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
119
      window.setFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE);
120
      window.getDecorView().setSystemUiVisibility(RubikActivity.FLAGS);
121
      }
122

    
123
    dialog.setOnShowListener(new DialogInterface.OnShowListener()
124
      {
125
      @Override
126
      public void onShow(DialogInterface dialog)
127
        {
128
        Button btnPositive = ((AlertDialog)dialog).getButton(Dialog.BUTTON_POSITIVE);
129
        btnPositive.setTextSize(TypedValue.COMPLEX_UNIT_PX, okSize);
130
        }
131
      });
132

    
133
    return dialog;
134
    }
135

    
136
///////////////////////////////////////////////////////////////////////////////////////////////////
137

    
138
  private String getAppVers(FragmentActivity act)
139
    {
140
    try
141
      {
142
      PackageInfo pInfo = act.getPackageManager().getPackageInfo( act.getPackageName(), 0);
143
      return pInfo.versionName;
144
      }
145
    catch (PackageManager.NameNotFoundException e)
146
      {
147
      return "unknown";
148
      }
149
    }
150
  }
(1-1/15)