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 androidx.fragment.app.FragmentActivity;
|
14
|
import androidx.viewpager.widget.ViewPager;
|
15
|
import com.google.android.material.tabs.TabLayout;
|
16
|
|
17
|
import android.view.View;
|
18
|
import android.view.ViewGroup;
|
19
|
import android.view.Window;
|
20
|
import android.view.WindowManager;
|
21
|
import android.widget.ImageView;
|
22
|
|
23
|
import org.distorted.main.R;
|
24
|
import org.distorted.main.RubikActivity;
|
25
|
import org.distorted.objects.RubikObject;
|
26
|
import org.distorted.objects.RubikObjectList;
|
27
|
import org.distorted.objectlib.patterns.RubikPatternList;
|
28
|
|
29
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
30
|
|
31
|
public class RubikDialogPattern extends RubikDialogAbstract
|
32
|
{
|
33
|
private RubikDialogPatternPagerAdapter mPagerAdapter;
|
34
|
|
35
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
36
|
|
37
|
@Override
|
38
|
public void onResume()
|
39
|
{
|
40
|
super.onResume();
|
41
|
|
42
|
Window window = getDialog().getWindow();
|
43
|
|
44
|
if( window!=null )
|
45
|
{
|
46
|
WindowManager.LayoutParams params = window.getAttributes();
|
47
|
params.width = (int)Math.min( mHeight*0.65f,mWidth*0.98f );
|
48
|
params.height = (int)Math.min( mHeight*0.85f,mWidth*1.30f );
|
49
|
window.setAttributes(params);
|
50
|
}
|
51
|
}
|
52
|
|
53
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
54
|
|
55
|
public int getResource() { return R.layout.dialog_tabbed; }
|
56
|
public int getTitleResource() { return R.string.choose_pattern; }
|
57
|
public boolean hasArgument() { return false; }
|
58
|
public int getPositive() { return R.string.ok; }
|
59
|
public int getNegative() { return -1; }
|
60
|
|
61
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
62
|
|
63
|
public void positiveAction()
|
64
|
{
|
65
|
|
66
|
}
|
67
|
|
68
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
69
|
|
70
|
public void negativeAction()
|
71
|
{
|
72
|
|
73
|
}
|
74
|
|
75
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
76
|
|
77
|
public void prepareBody(Dialog dialog, View view, FragmentActivity act, float size)
|
78
|
{
|
79
|
final int tabHeight= (int)(mHeight*RubikActivity.TAB_HEIGHT);
|
80
|
final int tabWidth = (int)(mHeight*RubikActivity.TAB_WIDTH);
|
81
|
|
82
|
ViewPager viewPager = view.findViewById(R.id.viewpager);
|
83
|
TabLayout tabLayout = view.findViewById(R.id.sliding_tabs);
|
84
|
mPagerAdapter = new RubikDialogPatternPagerAdapter(act, viewPager, this);
|
85
|
tabLayout.setupWithViewPager(viewPager);
|
86
|
|
87
|
int obj = RubikObjectList.getCurrObject();
|
88
|
int ord = RubikPatternList.getOrdinal(obj);
|
89
|
if( ord<0 ) ord = RubikPatternList.getOrdinal(RubikObjectList.DEF_OBJECT);
|
90
|
viewPager.setCurrentItem(ord);
|
91
|
|
92
|
ViewGroup.LayoutParams paramsView = new ViewGroup.LayoutParams( tabWidth,tabHeight );
|
93
|
|
94
|
for(int i=0; i< RubikPatternList.NUM_OBJECTS; i++)
|
95
|
{
|
96
|
int ordinal = RubikPatternList.getObject(i);
|
97
|
RubikObject object = RubikObjectList.getObject(ordinal);
|
98
|
ImageView imageView = new ImageView(act);
|
99
|
if( object!=null ) object.setIconTo(act,imageView);
|
100
|
imageView.setLayoutParams(paramsView);
|
101
|
TabLayout.Tab tab = tabLayout.getTabAt(i);
|
102
|
if(tab!=null) tab.setCustomView(imageView);
|
103
|
}
|
104
|
}
|
105
|
|
106
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
107
|
|
108
|
public void rememberState()
|
109
|
{
|
110
|
mPagerAdapter.rememberState();
|
111
|
}
|
112
|
|
113
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
114
|
|
115
|
public static String getDialogTag()
|
116
|
{
|
117
|
return "DialogPattern";
|
118
|
}
|
119
|
}
|