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 android.content.DialogInterface;
|
14
|
import android.os.Bundle;
|
15
|
import androidx.annotation.NonNull;
|
16
|
import androidx.fragment.app.FragmentActivity;
|
17
|
import androidx.viewpager.widget.ViewPager;
|
18
|
import androidx.appcompat.app.AlertDialog;
|
19
|
import androidx.appcompat.app.AppCompatDialogFragment;
|
20
|
import com.google.android.material.tabs.TabLayout;
|
21
|
|
22
|
import android.util.DisplayMetrics;
|
23
|
import android.util.TypedValue;
|
24
|
import android.view.LayoutInflater;
|
25
|
import android.view.View;
|
26
|
import android.view.ViewGroup;
|
27
|
import android.view.Window;
|
28
|
import android.widget.Button;
|
29
|
import android.widget.ImageView;
|
30
|
import android.widget.TextView;
|
31
|
|
32
|
import org.distorted.main.R;
|
33
|
import org.distorted.main.RubikActivity;
|
34
|
import org.distorted.objects.RubikObject;
|
35
|
import org.distorted.objects.RubikObjectList;
|
36
|
|
37
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
38
|
|
39
|
public class RubikDialogScores extends AppCompatDialogFragment
|
40
|
{
|
41
|
private RubikDialogScoresPagerAdapter mPagerAdapter;
|
42
|
|
43
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
44
|
|
45
|
@NonNull
|
46
|
@Override
|
47
|
public Dialog onCreateDialog(Bundle savedInstanceState)
|
48
|
{
|
49
|
FragmentActivity act = getActivity();
|
50
|
AlertDialog.Builder builder = new AlertDialog.Builder(act);
|
51
|
|
52
|
DisplayMetrics displaymetrics = new DisplayMetrics();
|
53
|
act.getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
|
54
|
|
55
|
int scrWidth = displaymetrics.widthPixels;
|
56
|
final float titleSize= scrWidth*RubikActivity.MENU_BIG_TEXT_SIZE;
|
57
|
final float okSize = scrWidth*RubikActivity.DIALOG_BUTTON_SIZE;
|
58
|
final int tabHeight= (int)(scrWidth*RubikActivity.TAB_HEIGHT);
|
59
|
final int tabWidth = (int)(scrWidth*RubikActivity.TAB_WIDTH);
|
60
|
|
61
|
LayoutInflater layoutInflater = act.getLayoutInflater();
|
62
|
TextView tv = (TextView) layoutInflater.inflate(R.layout.dialog_title, null);
|
63
|
tv.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleSize);
|
64
|
tv.setText(R.string.scores);
|
65
|
builder.setCustomTitle(tv);
|
66
|
|
67
|
builder.setCancelable(true);
|
68
|
builder.setPositiveButton( R.string.ok, new DialogInterface.OnClickListener()
|
69
|
{
|
70
|
@Override
|
71
|
public void onClick(DialogInterface dialog, int which)
|
72
|
{
|
73
|
|
74
|
}
|
75
|
});
|
76
|
|
77
|
Bundle args = getArguments();
|
78
|
int curTab;
|
79
|
boolean isSubmitting;
|
80
|
|
81
|
try
|
82
|
{
|
83
|
curTab = args.getInt("tab");
|
84
|
isSubmitting = args.getBoolean("submitting");
|
85
|
}
|
86
|
catch(Exception e)
|
87
|
{
|
88
|
curTab = 0;
|
89
|
isSubmitting = false;
|
90
|
}
|
91
|
|
92
|
LayoutInflater inflater = act.getLayoutInflater();
|
93
|
final View view = inflater.inflate(R.layout.dialog_tabbed, null);
|
94
|
builder.setView(view);
|
95
|
|
96
|
ViewPager viewPager = view.findViewById(R.id.viewpager);
|
97
|
TabLayout tabLayout = view.findViewById(R.id.sliding_tabs);
|
98
|
mPagerAdapter = new RubikDialogScoresPagerAdapter(act,viewPager,isSubmitting, this);
|
99
|
tabLayout.setupWithViewPager(viewPager);
|
100
|
|
101
|
viewPager.setCurrentItem(curTab);
|
102
|
int numObjects = RubikObjectList.getNumObjects();
|
103
|
ViewGroup.LayoutParams paramsView = new ViewGroup.LayoutParams( tabWidth,tabHeight );
|
104
|
|
105
|
for (int object=0; object<numObjects; object++)
|
106
|
{
|
107
|
RubikObject robject = RubikObjectList.getObject(object);
|
108
|
ImageView imageView = new ImageView(act);
|
109
|
if( robject!=null ) robject.setIconTo(act,imageView);
|
110
|
imageView.setLayoutParams(paramsView);
|
111
|
TabLayout.Tab tab = tabLayout.getTabAt(object);
|
112
|
if(tab!=null) tab.setCustomView(imageView);
|
113
|
}
|
114
|
|
115
|
Dialog dialog = builder.create();
|
116
|
dialog.setCanceledOnTouchOutside(false);
|
117
|
Window window = dialog.getWindow();
|
118
|
|
119
|
if( window!=null )
|
120
|
{
|
121
|
window.getDecorView().setSystemUiVisibility(RubikActivity.FLAGS);
|
122
|
}
|
123
|
|
124
|
dialog.setOnShowListener(new DialogInterface.OnShowListener()
|
125
|
{
|
126
|
@Override
|
127
|
public void onShow(DialogInterface dialog)
|
128
|
{
|
129
|
Button btnPositive = ((AlertDialog)dialog).getButton(Dialog.BUTTON_POSITIVE);
|
130
|
btnPositive.setTextSize(TypedValue.COMPLEX_UNIT_PX, okSize);
|
131
|
}
|
132
|
});
|
133
|
|
134
|
return dialog;
|
135
|
}
|
136
|
}
|