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