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 |
234a7582
|
Leszek Koltunski
|
import android.content.Context;
|
24 |
a8576d91
|
Leszek Koltunski
|
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 |
6e3fcb91
|
Leszek Koltunski
|
import android.view.ViewGroup;
|
31 |
a8576d91
|
Leszek Koltunski
|
import android.view.Window;
|
32 |
234a7582
|
Leszek Koltunski
|
import android.view.WindowManager;
|
33 |
a8576d91
|
Leszek Koltunski
|
import android.widget.Button;
|
34 |
234a7582
|
Leszek Koltunski
|
import android.widget.ImageView;
|
35 |
a8576d91
|
Leszek Koltunski
|
import android.widget.TextView;
|
36 |
|
|
|
37 |
|
|
import androidx.annotation.NonNull;
|
38 |
|
|
import androidx.appcompat.app.AlertDialog;
|
39 |
|
|
import androidx.appcompat.app.AppCompatDialogFragment;
|
40 |
|
|
import androidx.fragment.app.FragmentActivity;
|
41 |
234a7582
|
Leszek Koltunski
|
import androidx.viewpager.widget.ViewPager;
|
42 |
|
|
|
43 |
|
|
import com.google.android.material.tabs.TabLayout;
|
44 |
a8576d91
|
Leszek Koltunski
|
|
45 |
|
|
import org.distorted.main.R;
|
46 |
|
|
import org.distorted.main.RubikActivity;
|
47 |
804293f0
|
Leszek Koltunski
|
import org.distorted.objects.RubikObject;
|
48 |
400ff34d
|
Leszek Koltunski
|
import org.distorted.objects.RubikObjectList;
|
49 |
a8576d91
|
Leszek Koltunski
|
|
50 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
51 |
|
|
|
52 |
234a7582
|
Leszek Koltunski
|
public class RubikDialogTutorial extends AppCompatDialogFragment
|
53 |
a8576d91
|
Leszek Koltunski
|
{
|
54 |
234a7582
|
Leszek Koltunski
|
private RubikDialogTutorialPagerAdapter mPagerAdapter;
|
55 |
|
|
|
56 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
57 |
|
|
|
58 |
a8576d91
|
Leszek Koltunski
|
@NonNull
|
59 |
|
|
@Override
|
60 |
|
|
public Dialog onCreateDialog(Bundle savedInstanceState)
|
61 |
|
|
{
|
62 |
|
|
final FragmentActivity act = getActivity();
|
63 |
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(act);
|
64 |
|
|
|
65 |
|
|
DisplayMetrics displaymetrics = new DisplayMetrics();
|
66 |
|
|
act.getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
|
67 |
6e3fcb91
|
Leszek Koltunski
|
int scrWidth = displaymetrics.widthPixels;
|
68 |
|
|
final float titleSize= scrWidth*RubikActivity.MENU_BIG_TEXT_SIZE;
|
69 |
|
|
final float okSize = scrWidth*RubikActivity.DIALOG_BUTTON_SIZE;
|
70 |
|
|
final int tabHeight= (int)(scrWidth*RubikActivity.TAB_HEIGHT);
|
71 |
|
|
final int tabWidth = (int)(scrWidth*RubikActivity.TAB_WIDTH);
|
72 |
a8576d91
|
Leszek Koltunski
|
|
73 |
234a7582
|
Leszek Koltunski
|
LayoutInflater layoutInflater = act.getLayoutInflater();
|
74 |
|
|
TextView tv = (TextView) layoutInflater.inflate(R.layout.dialog_title, null);
|
75 |
a8576d91
|
Leszek Koltunski
|
tv.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleSize);
|
76 |
234a7582
|
Leszek Koltunski
|
tv.setText(R.string.tutorials);
|
77 |
a8576d91
|
Leszek Koltunski
|
builder.setCustomTitle(tv);
|
78 |
|
|
|
79 |
234a7582
|
Leszek Koltunski
|
builder.setPositiveButton( R.string.ok, new DialogInterface.OnClickListener()
|
80 |
80218b07
|
Leszek Koltunski
|
{
|
81 |
|
|
@Override
|
82 |
|
|
public void onClick(DialogInterface dialog, int which)
|
83 |
|
|
{
|
84 |
234a7582
|
Leszek Koltunski
|
|
85 |
80218b07
|
Leszek Koltunski
|
}
|
86 |
|
|
});
|
87 |
|
|
|
88 |
234a7582
|
Leszek Koltunski
|
LayoutInflater inflater = act.getLayoutInflater();
|
89 |
|
|
final View view = inflater.inflate(R.layout.dialog_tabbed, null);
|
90 |
a8576d91
|
Leszek Koltunski
|
builder.setView(view);
|
91 |
|
|
|
92 |
234a7582
|
Leszek Koltunski
|
ViewPager viewPager = view.findViewById(R.id.viewpager);
|
93 |
|
|
TabLayout tabLayout = view.findViewById(R.id.sliding_tabs);
|
94 |
5b4eaf7e
|
Leszek Koltunski
|
mPagerAdapter = new RubikDialogTutorialPagerAdapter(act,viewPager);
|
95 |
234a7582
|
Leszek Koltunski
|
tabLayout.setupWithViewPager(viewPager);
|
96 |
52547ba7
|
Leszek Koltunski
|
viewPager.setCurrentItem(getTutorialOrdinal());
|
97 |
a8576d91
|
Leszek Koltunski
|
|
98 |
6e3fcb91
|
Leszek Koltunski
|
ViewGroup.LayoutParams paramsView = new ViewGroup.LayoutParams( tabWidth,tabHeight );
|
99 |
804293f0
|
Leszek Koltunski
|
int numObjects = RubikObjectList.getNumTutorialObjects();
|
100 |
6e3fcb91
|
Leszek Koltunski
|
|
101 |
804293f0
|
Leszek Koltunski
|
for(int i=0; i<numObjects; i++)
|
102 |
234a7582
|
Leszek Koltunski
|
{
|
103 |
84d746d7
|
Leszek Koltunski
|
int oOrdinal = RubikObjectList.getObjectOrdinal(i);
|
104 |
|
|
RubikObject object = RubikObjectList.getObject(oOrdinal);
|
105 |
234a7582
|
Leszek Koltunski
|
ImageView imageView = new ImageView(act);
|
106 |
6e3fcb91
|
Leszek Koltunski
|
imageView.setLayoutParams(paramsView);
|
107 |
eb985085
|
Leszek Koltunski
|
if( object!=null ) object.setIconTo(act,imageView);
|
108 |
234a7582
|
Leszek Koltunski
|
TabLayout.Tab tab = tabLayout.getTabAt(i);
|
109 |
|
|
if(tab!=null) tab.setCustomView(imageView);
|
110 |
|
|
}
|
111 |
|
|
|
112 |
|
|
Dialog dialog = builder.create();
|
113 |
|
|
dialog.setCanceledOnTouchOutside(false);
|
114 |
a8576d91
|
Leszek Koltunski
|
Window window = dialog.getWindow();
|
115 |
|
|
|
116 |
|
|
if( window!=null )
|
117 |
|
|
{
|
118 |
|
|
window.getDecorView().setSystemUiVisibility(RubikActivity.FLAGS);
|
119 |
|
|
}
|
120 |
|
|
|
121 |
|
|
dialog.setOnShowListener(new DialogInterface.OnShowListener()
|
122 |
|
|
{
|
123 |
|
|
@Override
|
124 |
|
|
public void onShow(DialogInterface dialog)
|
125 |
|
|
{
|
126 |
|
|
Button btnPositive = ((AlertDialog)dialog).getButton(Dialog.BUTTON_POSITIVE);
|
127 |
|
|
btnPositive.setTextSize(TypedValue.COMPLEX_UNIT_PX, okSize);
|
128 |
|
|
}
|
129 |
|
|
});
|
130 |
|
|
|
131 |
|
|
return dialog;
|
132 |
|
|
}
|
133 |
80218b07
|
Leszek Koltunski
|
|
134 |
52547ba7
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
135 |
|
|
|
136 |
|
|
private int getTutorialOrdinal()
|
137 |
|
|
{
|
138 |
400ff34d
|
Leszek Koltunski
|
int obj = RubikObjectList.getCurrObject();
|
139 |
804293f0
|
Leszek Koltunski
|
return RubikObjectList.getTutorialOrdinal(obj);
|
140 |
52547ba7
|
Leszek Koltunski
|
}
|
141 |
|
|
|
142 |
80218b07
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
143 |
|
|
|
144 |
234a7582
|
Leszek Koltunski
|
@Override
|
145 |
|
|
public void onResume()
|
146 |
|
|
{
|
147 |
|
|
super.onResume();
|
148 |
|
|
|
149 |
a84c3a25
|
Leszek Koltunski
|
if( mPagerAdapter!=null ) mPagerAdapter.clickPossible();
|
150 |
|
|
|
151 |
234a7582
|
Leszek Koltunski
|
Window window = getDialog().getWindow();
|
152 |
|
|
Context context = getContext();
|
153 |
|
|
|
154 |
|
|
if( window!=null && context!=null )
|
155 |
|
|
{
|
156 |
|
|
DisplayMetrics metrics = context.getResources().getDisplayMetrics();
|
157 |
|
|
WindowManager.LayoutParams params = window.getAttributes();
|
158 |
|
|
params.width = WindowManager.LayoutParams.WRAP_CONTENT;
|
159 |
de43f86a
|
Leszek Koltunski
|
params.height = (int)Math.min( 0.85f*metrics.heightPixels,1.3f*metrics.widthPixels );
|
160 |
234a7582
|
Leszek Koltunski
|
window.setAttributes(params);
|
161 |
|
|
}
|
162 |
|
|
}
|
163 |
|
|
|
164 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
165 |
|
|
|
166 |
|
|
public static String getDialogTag()
|
167 |
80218b07
|
Leszek Koltunski
|
{
|
168 |
234a7582
|
Leszek Koltunski
|
return "DialogTutorial";
|
169 |
80218b07
|
Leszek Koltunski
|
}
|
170 |
a8576d91
|
Leszek Koltunski
|
}
|