Project

General

Profile

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

magiccube / src / main / java / org / distorted / dialogs / RubikDialogTutorial.java @ eaf87d1d

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.Context;
24
import android.content.DialogInterface;
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.view.WindowManager;
32
import android.widget.Button;
33
import android.widget.ImageView;
34
import android.widget.TextView;
35

    
36
import androidx.annotation.NonNull;
37
import androidx.appcompat.app.AlertDialog;
38
import androidx.appcompat.app.AppCompatDialogFragment;
39
import androidx.fragment.app.FragmentActivity;
40
import androidx.viewpager.widget.ViewPager;
41

    
42
import com.google.android.material.tabs.TabLayout;
43

    
44
import org.distorted.main.R;
45
import org.distorted.main.RubikActivity;
46
import org.distorted.tutorials.TutorialList;
47

    
48
///////////////////////////////////////////////////////////////////////////////////////////////////
49

    
50
public class RubikDialogTutorial extends AppCompatDialogFragment
51
  {
52
  private RubikDialogTutorialPagerAdapter mPagerAdapter;
53

    
54
///////////////////////////////////////////////////////////////////////////////////////////////////
55

    
56
  @NonNull
57
  @Override
58
  public Dialog onCreateDialog(Bundle savedInstanceState)
59
    {
60
    final FragmentActivity act = getActivity();
61
    AlertDialog.Builder builder = new AlertDialog.Builder(act);
62

    
63
    DisplayMetrics displaymetrics = new DisplayMetrics();
64
    act.getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
65
    final float titleSize= displaymetrics.widthPixels * RubikActivity.MENU_BIG_TEXT_SIZE;
66
    final float okSize   = displaymetrics.widthPixels * RubikActivity.DIALOG_BUTTON_SIZE;
67

    
68
    LayoutInflater layoutInflater = act.getLayoutInflater();
69
    TextView tv = (TextView) layoutInflater.inflate(R.layout.dialog_title, null);
70
    tv.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleSize);
71
    tv.setText(R.string.tutorials);
72
    builder.setCustomTitle(tv);
73

    
74
    builder.setPositiveButton( R.string.ok, new DialogInterface.OnClickListener()
75
      {
76
      @Override
77
      public void onClick(DialogInterface dialog, int which)
78
        {
79

    
80
        }
81
      });
82

    
83
    Bundle args = getArguments();
84
    int curTab;
85

    
86
    try
87
      {
88
      curTab = args.getInt("tab");
89
      }
90
    catch(Exception e)
91
      {
92
      curTab = 0;
93
      }
94

    
95
    LayoutInflater inflater = act.getLayoutInflater();
96
    final View view = inflater.inflate(R.layout.dialog_tabbed, null);
97
    builder.setView(view);
98

    
99
    ViewPager viewPager = view.findViewById(R.id.viewpager);
100
    TabLayout tabLayout = view.findViewById(R.id.sliding_tabs);
101
    mPagerAdapter = new RubikDialogTutorialPagerAdapter(act,viewPager);
102
    tabLayout.setupWithViewPager(viewPager);
103
    viewPager.setCurrentItem(curTab);
104

    
105
    for(int i=0; i<TutorialList.NUM_OBJECTS; i++)
106
      {
107
      TutorialList list = TutorialList.getObject(i);
108
      int iconID        = list.getIconID();
109
      ImageView imageView = new ImageView(act);
110
      imageView.setImageResource(iconID);
111
      TabLayout.Tab tab = tabLayout.getTabAt(i);
112
      if(tab!=null) tab.setCustomView(imageView);
113
      }
114

    
115
    Dialog dialog = builder.create();
116
    dialog.setCanceledOnTouchOutside(false);
117
    Window window = dialog.getWindow();
118

    
119
    if( window!=null )
120
      {
121
      window.getDecorView().setSystemUiVisibility(RubikActivity.FLAGS);
122
      }
123

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

    
134
    return dialog;
135
    }
136

    
137
///////////////////////////////////////////////////////////////////////////////////////////////////
138

    
139
  @Override
140
  public void onResume()
141
    {
142
    super.onResume();
143

    
144
    Window window = getDialog().getWindow();
145
    Context context = getContext();
146

    
147
    if( window!=null && context!=null )
148
      {
149
      DisplayMetrics metrics = context.getResources().getDisplayMetrics();
150
      final float height= metrics.heightPixels;
151

    
152
      WindowManager.LayoutParams params = window.getAttributes();
153
      params.width  = WindowManager.LayoutParams.WRAP_CONTENT;
154
      params.height = (int)(0.6f*height);
155
      window.setAttributes(params);
156
      }
157
    }
158

    
159
///////////////////////////////////////////////////////////////////////////////////////////////////
160

    
161
  public static String getDialogTag()
162
    {
163
    return "DialogTutorial";
164
    }
165
  }
(16-16/18)