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