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