1 |
a7a7cc9c
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2 |
|
|
// Copyright 2019 Leszek Koltunski //
|
3 |
|
|
// //
|
4 |
fdec60a3
|
Leszek Koltunski
|
// This file is part of Magic Cube. //
|
5 |
a7a7cc9c
|
Leszek Koltunski
|
// //
|
6 |
68191e7d
|
Leszek Koltunski
|
// 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 |
a7a7cc9c
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
9 |
|
|
|
10 |
1f9772f3
|
Leszek Koltunski
|
package org.distorted.dialogs;
|
11 |
a7a7cc9c
|
Leszek Koltunski
|
|
12 |
fdec60a3
|
Leszek Koltunski
|
import android.app.Dialog;
|
13 |
66e777b0
|
Leszek Koltunski
|
import androidx.fragment.app.FragmentActivity;
|
14 |
|
|
import androidx.viewpager.widget.ViewPager;
|
15 |
|
|
import com.google.android.material.tabs.TabLayout;
|
16 |
52d0a923
|
Leszek Koltunski
|
|
17 |
fdec60a3
|
Leszek Koltunski
|
import android.view.View;
|
18 |
6e3fcb91
|
Leszek Koltunski
|
import android.view.ViewGroup;
|
19 |
4235de9b
|
Leszek Koltunski
|
import android.view.Window;
|
20 |
b6cce523
|
Leszek Koltunski
|
import android.view.WindowManager;
|
21 |
fdec60a3
|
Leszek Koltunski
|
import android.widget.ImageView;
|
22 |
a7a7cc9c
|
Leszek Koltunski
|
|
23 |
1f9772f3
|
Leszek Koltunski
|
import org.distorted.main.R;
|
24 |
d433b50e
|
Leszek Koltunski
|
import org.distorted.objects.RubikObject;
|
25 |
|
|
import org.distorted.objects.RubikObjectList;
|
26 |
211b48f2
|
Leszek Koltunski
|
|
27 |
a7a7cc9c
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
28 |
|
|
|
29 |
f8a21f6b
|
Leszek Koltunski
|
public class RubikDialogScores extends RubikDialogAbstract
|
30 |
a7a7cc9c
|
Leszek Koltunski
|
{
|
31 |
7bb30586
|
leszek
|
private static final float TAB_WIDTH = 0.066f;
|
32 |
|
|
private static final float TAB_HEIGHT= 0.066f;
|
33 |
|
|
|
34 |
85248b04
|
Leszek Koltunski
|
private RubikDialogScoresPagerAdapter mPagerAdapter;
|
35 |
4235de9b
|
Leszek Koltunski
|
|
36 |
c02235d5
|
leszek
|
public interface ScoresInvoker
|
37 |
|
|
{
|
38 |
|
|
int getObjectOrdinal();
|
39 |
|
|
}
|
40 |
|
|
|
41 |
fdec60a3
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
42 |
|
|
|
43 |
|
|
@Override
|
44 |
f8a21f6b
|
Leszek Koltunski
|
public void onResume()
|
45 |
fdec60a3
|
Leszek Koltunski
|
{
|
46 |
f8a21f6b
|
Leszek Koltunski
|
super.onResume();
|
47 |
fdec60a3
|
Leszek Koltunski
|
|
48 |
f8a21f6b
|
Leszek Koltunski
|
Window window = getDialog().getWindow();
|
49 |
4918f19c
|
Leszek Koltunski
|
|
50 |
f8a21f6b
|
Leszek Koltunski
|
if( window!=null )
|
51 |
4918f19c
|
Leszek Koltunski
|
{
|
52 |
f8a21f6b
|
Leszek Koltunski
|
WindowManager.LayoutParams params = window.getAttributes();
|
53 |
|
|
params.width = (int)Math.min( mHeight*0.65f,mWidth*0.98f );
|
54 |
1c04d054
|
leszek
|
params.height = (int)( mHeight*0.90f);
|
55 |
f8a21f6b
|
Leszek Koltunski
|
window.setAttributes(params);
|
56 |
4918f19c
|
Leszek Koltunski
|
}
|
57 |
f8a21f6b
|
Leszek Koltunski
|
}
|
58 |
|
|
|
59 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
60 |
4918f19c
|
Leszek Koltunski
|
|
61 |
f8a21f6b
|
Leszek Koltunski
|
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 |
10d04892
|
leszek
|
public void positiveAction() { RubikDialogScoresThread.getInstance().exit(); }
|
67 |
|
|
public void negativeAction() { }
|
68 |
f8a21f6b
|
Leszek Koltunski
|
|
69 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
70 |
|
|
|
71 |
|
|
public void prepareBody(Dialog dialog, View view, FragmentActivity act, float size)
|
72 |
|
|
{
|
73 |
7bb30586
|
leszek
|
final int tabHeight= (int)(mHeight*TAB_HEIGHT);
|
74 |
|
|
final int tabWidth = (int)(mHeight*TAB_WIDTH);
|
75 |
fdec60a3
|
Leszek Koltunski
|
|
76 |
946d9762
|
Leszek Koltunski
|
ViewPager viewPager = view.findViewById(R.id.viewpager);
|
77 |
fdec60a3
|
Leszek Koltunski
|
TabLayout tabLayout = view.findViewById(R.id.sliding_tabs);
|
78 |
f8a21f6b
|
Leszek Koltunski
|
mPagerAdapter = new RubikDialogScoresPagerAdapter(act,viewPager,mArgument.equals("true"), this);
|
79 |
946d9762
|
Leszek Koltunski
|
tabLayout.setupWithViewPager(viewPager);
|
80 |
cc5ec229
|
Leszek Koltunski
|
|
81 |
c02235d5
|
leszek
|
ScoresInvoker si = (ScoresInvoker) act;
|
82 |
|
|
int objectOrdinal = si.getObjectOrdinal();
|
83 |
|
|
|
84 |
|
|
viewPager.setCurrentItem(objectOrdinal);
|
85 |
d433b50e
|
Leszek Koltunski
|
int numObjects = RubikObjectList.getNumObjects();
|
86 |
6e3fcb91
|
Leszek Koltunski
|
ViewGroup.LayoutParams paramsView = new ViewGroup.LayoutParams( tabWidth,tabHeight );
|
87 |
fdec60a3
|
Leszek Koltunski
|
|
88 |
d433b50e
|
Leszek Koltunski
|
for (int object=0; object<numObjects; object++)
|
89 |
fdec60a3
|
Leszek Koltunski
|
{
|
90 |
d433b50e
|
Leszek Koltunski
|
RubikObject robject = RubikObjectList.getObject(object);
|
91 |
7ac0ee88
|
Leszek Koltunski
|
ImageView imageView = new ImageView(act);
|
92 |
eb985085
|
Leszek Koltunski
|
if( robject!=null ) robject.setIconTo(act,imageView);
|
93 |
6e3fcb91
|
Leszek Koltunski
|
imageView.setLayoutParams(paramsView);
|
94 |
7ac0ee88
|
Leszek Koltunski
|
TabLayout.Tab tab = tabLayout.getTabAt(object);
|
95 |
|
|
if(tab!=null) tab.setCustomView(imageView);
|
96 |
fdec60a3
|
Leszek Koltunski
|
}
|
97 |
b6cce523
|
Leszek Koltunski
|
}
|
98 |
a7a7cc9c
|
Leszek Koltunski
|
}
|