1
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2
|
// Copyright 2020 Leszek Koltunski //
|
3
|
// //
|
4
|
// This file is part of Magic Cube. //
|
5
|
// //
|
6
|
// Magic Cube is proprietary software licensed under an EULA which you should have received //
|
7
|
// along with the code. If not, check https://distorted.org/magic/License-Magic-Cube.html //
|
8
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
9
|
|
10
|
package org.distorted.dialogs;
|
11
|
|
12
|
import android.app.Dialog;
|
13
|
import android.content.Context;
|
14
|
import android.content.DialogInterface;
|
15
|
import android.os.Bundle;
|
16
|
import android.util.DisplayMetrics;
|
17
|
import android.util.TypedValue;
|
18
|
import android.view.LayoutInflater;
|
19
|
import android.view.View;
|
20
|
import android.view.ViewGroup;
|
21
|
import android.view.Window;
|
22
|
import android.view.WindowManager;
|
23
|
import android.widget.Button;
|
24
|
import android.widget.ImageView;
|
25
|
import android.widget.TextView;
|
26
|
|
27
|
import androidx.annotation.NonNull;
|
28
|
import androidx.appcompat.app.AlertDialog;
|
29
|
import androidx.appcompat.app.AppCompatDialogFragment;
|
30
|
import androidx.fragment.app.FragmentActivity;
|
31
|
import androidx.viewpager.widget.ViewPager;
|
32
|
|
33
|
import com.google.android.material.tabs.TabLayout;
|
34
|
|
35
|
import org.distorted.main.R;
|
36
|
import org.distorted.main.RubikActivity;
|
37
|
import org.distorted.objects.RubikObject;
|
38
|
import org.distorted.objects.RubikObjectList;
|
39
|
|
40
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
41
|
|
42
|
public class RubikDialogTutorial extends AppCompatDialogFragment
|
43
|
{
|
44
|
private RubikDialogTutorialPagerAdapter mPagerAdapter;
|
45
|
|
46
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
47
|
|
48
|
@NonNull
|
49
|
@Override
|
50
|
public Dialog onCreateDialog(Bundle savedInstanceState)
|
51
|
{
|
52
|
final FragmentActivity act = getActivity();
|
53
|
AlertDialog.Builder builder = new AlertDialog.Builder(act);
|
54
|
|
55
|
DisplayMetrics displaymetrics = new DisplayMetrics();
|
56
|
act.getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
|
57
|
int scrWidth = displaymetrics.widthPixels;
|
58
|
final float titleSize= scrWidth*RubikActivity.MENU_BIG_TEXT_SIZE;
|
59
|
final float okSize = scrWidth*RubikActivity.DIALOG_BUTTON_SIZE;
|
60
|
final int tabHeight= (int)(scrWidth*RubikActivity.TAB_HEIGHT);
|
61
|
final int tabWidth = (int)(scrWidth*RubikActivity.TAB_WIDTH);
|
62
|
|
63
|
LayoutInflater layoutInflater = act.getLayoutInflater();
|
64
|
TextView tv = (TextView) layoutInflater.inflate(R.layout.dialog_title, null);
|
65
|
tv.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleSize);
|
66
|
tv.setText(R.string.tutorials);
|
67
|
builder.setCustomTitle(tv);
|
68
|
|
69
|
builder.setPositiveButton( R.string.ok, new DialogInterface.OnClickListener()
|
70
|
{
|
71
|
@Override
|
72
|
public void onClick(DialogInterface dialog, int which)
|
73
|
{
|
74
|
|
75
|
}
|
76
|
});
|
77
|
|
78
|
LayoutInflater inflater = act.getLayoutInflater();
|
79
|
final View view = inflater.inflate(R.layout.dialog_tabbed, null);
|
80
|
builder.setView(view);
|
81
|
|
82
|
ViewPager viewPager = view.findViewById(R.id.viewpager);
|
83
|
TabLayout tabLayout = view.findViewById(R.id.sliding_tabs);
|
84
|
mPagerAdapter = new RubikDialogTutorialPagerAdapter(act,viewPager);
|
85
|
tabLayout.setupWithViewPager(viewPager);
|
86
|
viewPager.setCurrentItem(getTutorialOrdinal());
|
87
|
|
88
|
ViewGroup.LayoutParams paramsView = new ViewGroup.LayoutParams( tabWidth,tabHeight );
|
89
|
int numObjects = RubikObjectList.getNumTutorialObjects();
|
90
|
|
91
|
for(int i=0; i<numObjects; i++)
|
92
|
{
|
93
|
int oOrdinal = RubikObjectList.getObjectOrdinal(i);
|
94
|
RubikObject object = RubikObjectList.getObject(oOrdinal);
|
95
|
ImageView imageView = new ImageView(act);
|
96
|
imageView.setLayoutParams(paramsView);
|
97
|
if( object!=null ) object.setIconTo(act,imageView);
|
98
|
TabLayout.Tab tab = tabLayout.getTabAt(i);
|
99
|
if(tab!=null) tab.setCustomView(imageView);
|
100
|
}
|
101
|
|
102
|
Dialog dialog = builder.create();
|
103
|
dialog.setCanceledOnTouchOutside(false);
|
104
|
Window window = dialog.getWindow();
|
105
|
|
106
|
if( window!=null )
|
107
|
{
|
108
|
window.getDecorView().setSystemUiVisibility(RubikActivity.FLAGS);
|
109
|
}
|
110
|
|
111
|
dialog.setOnShowListener(new DialogInterface.OnShowListener()
|
112
|
{
|
113
|
@Override
|
114
|
public void onShow(DialogInterface dialog)
|
115
|
{
|
116
|
Button btnPositive = ((AlertDialog)dialog).getButton(Dialog.BUTTON_POSITIVE);
|
117
|
btnPositive.setTextSize(TypedValue.COMPLEX_UNIT_PX, okSize);
|
118
|
}
|
119
|
});
|
120
|
|
121
|
return dialog;
|
122
|
}
|
123
|
|
124
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
125
|
|
126
|
private int getTutorialOrdinal()
|
127
|
{
|
128
|
int obj = RubikObjectList.getCurrObject();
|
129
|
return RubikObjectList.getTutorialOrdinal(obj);
|
130
|
}
|
131
|
|
132
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
133
|
|
134
|
@Override
|
135
|
public void onResume()
|
136
|
{
|
137
|
super.onResume();
|
138
|
|
139
|
if( mPagerAdapter!=null ) mPagerAdapter.clickPossible();
|
140
|
|
141
|
Window window = getDialog().getWindow();
|
142
|
Context context = getContext();
|
143
|
|
144
|
if( window!=null && context!=null )
|
145
|
{
|
146
|
DisplayMetrics metrics = context.getResources().getDisplayMetrics();
|
147
|
WindowManager.LayoutParams params = window.getAttributes();
|
148
|
params.width = WindowManager.LayoutParams.WRAP_CONTENT;
|
149
|
params.height = (int)Math.min( 0.85f*metrics.heightPixels,1.3f*metrics.widthPixels );
|
150
|
window.setAttributes(params);
|
151
|
}
|
152
|
}
|
153
|
|
154
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
155
|
|
156
|
public static String getDialogTag()
|
157
|
{
|
158
|
return "DialogTutorial";
|
159
|
}
|
160
|
}
|