1
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2
|
// Copyright 2019 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.objects.RubikObject;
|
25
|
import org.distorted.objects.RubikObjectList;
|
26
|
|
27
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
28
|
|
29
|
public class RubikDialogScores extends RubikDialogAbstract
|
30
|
{
|
31
|
private static final float TAB_WIDTH = 0.066f;
|
32
|
private static final float TAB_HEIGHT= 0.066f;
|
33
|
|
34
|
private RubikDialogScoresPagerAdapter mPagerAdapter;
|
35
|
|
36
|
public interface ScoresInvoker
|
37
|
{
|
38
|
int getObjectOrdinal();
|
39
|
}
|
40
|
|
41
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
42
|
|
43
|
@Override
|
44
|
public void onResume()
|
45
|
{
|
46
|
super.onResume();
|
47
|
|
48
|
Window window = getDialog().getWindow();
|
49
|
|
50
|
if( window!=null )
|
51
|
{
|
52
|
WindowManager.LayoutParams params = window.getAttributes();
|
53
|
params.width = (int)Math.min( mHeight*0.65f,mWidth*0.98f );
|
54
|
params.height = (int)( mHeight*0.90f);
|
55
|
window.setAttributes(params);
|
56
|
}
|
57
|
}
|
58
|
|
59
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
60
|
|
61
|
public int getResource() { return R.layout.dialog_tabbed; }
|
62
|
public int getTitleResource() { return R.string.scores; }
|
63
|
public boolean hasArgument() { return true; }
|
64
|
public int getPositive() { return R.string.ok; }
|
65
|
public int getNegative() { return -1; }
|
66
|
public void positiveAction() { RubikDialogScoresThread.getInstance().exit(); }
|
67
|
public void negativeAction() { }
|
68
|
|
69
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
70
|
|
71
|
public void prepareBody(Dialog dialog, View view, FragmentActivity act, float size)
|
72
|
{
|
73
|
final int tabHeight= (int)(mHeight*TAB_HEIGHT);
|
74
|
final int tabWidth = (int)(mHeight*TAB_WIDTH);
|
75
|
|
76
|
ViewPager viewPager = view.findViewById(R.id.viewpager);
|
77
|
TabLayout tabLayout = view.findViewById(R.id.sliding_tabs);
|
78
|
mPagerAdapter = new RubikDialogScoresPagerAdapter(act,viewPager,mArgument.equals("true"), this);
|
79
|
tabLayout.setupWithViewPager(viewPager);
|
80
|
|
81
|
ScoresInvoker si = (ScoresInvoker) act;
|
82
|
int objectOrdinal = si.getObjectOrdinal();
|
83
|
|
84
|
viewPager.setCurrentItem(objectOrdinal);
|
85
|
int numObjects = RubikObjectList.getNumObjects();
|
86
|
ViewGroup.LayoutParams paramsView = new ViewGroup.LayoutParams( tabWidth,tabHeight );
|
87
|
|
88
|
for( int object=0; object<numObjects; object++ )
|
89
|
{
|
90
|
RubikObject robject = RubikObjectList.getObject(object);
|
91
|
ImageView imageView = new ImageView(act);
|
92
|
if( robject!=null ) robject.setIconTo(act,imageView);
|
93
|
imageView.setLayoutParams(paramsView);
|
94
|
TabLayout.Tab tab = tabLayout.getTabAt(object);
|
95
|
if( tab!=null ) tab.setCustomView(imageView);
|
96
|
}
|
97
|
}
|
98
|
}
|