1
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2
|
// Copyright 2019 Leszek Koltunski //
|
3
|
// //
|
4
|
// This file is part of Magic Cube. //
|
5
|
// //
|
6
|
// Magic Cube is free software: you can redistribute it and/or modify //
|
7
|
// it under the terms of the GNU General Public License as published by //
|
8
|
// the Free Software Foundation, either version 2 of the License, or //
|
9
|
// (at your option) any later version. //
|
10
|
// //
|
11
|
// Magic Cube is distributed in the hope that it will be useful, //
|
12
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
13
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
14
|
// GNU General Public License for more details. //
|
15
|
// //
|
16
|
// You should have received a copy of the GNU General Public License //
|
17
|
// along with Magic Cube. If not, see <http://www.gnu.org/licenses/>. //
|
18
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
19
|
|
20
|
package org.distorted.dialogs;
|
21
|
|
22
|
import android.app.Dialog;
|
23
|
import android.content.DialogInterface;
|
24
|
import android.os.Bundle;
|
25
|
import androidx.annotation.NonNull;
|
26
|
import androidx.fragment.app.FragmentActivity;
|
27
|
import androidx.viewpager.widget.ViewPager;
|
28
|
import androidx.appcompat.app.AlertDialog;
|
29
|
import androidx.appcompat.app.AppCompatDialogFragment;
|
30
|
import com.google.android.material.tabs.TabLayout;
|
31
|
|
32
|
import android.util.DisplayMetrics;
|
33
|
import android.util.TypedValue;
|
34
|
import android.view.LayoutInflater;
|
35
|
import android.view.View;
|
36
|
import android.view.Window;
|
37
|
import android.view.WindowManager;
|
38
|
import android.widget.Button;
|
39
|
import android.widget.ImageView;
|
40
|
import android.widget.TextView;
|
41
|
|
42
|
import org.distorted.main.R;
|
43
|
import org.distorted.main.RubikActivity;
|
44
|
import org.distorted.objects.RubikObjectList;
|
45
|
|
46
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
47
|
|
48
|
public class RubikDialogScores extends AppCompatDialogFragment
|
49
|
{
|
50
|
private RubikDialogScoresPagerAdapter mPagerAdapter;
|
51
|
|
52
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
53
|
|
54
|
@NonNull
|
55
|
@Override
|
56
|
public Dialog onCreateDialog(Bundle savedInstanceState)
|
57
|
{
|
58
|
FragmentActivity act = getActivity();
|
59
|
AlertDialog.Builder builder = new AlertDialog.Builder(act);
|
60
|
|
61
|
DisplayMetrics displaymetrics = new DisplayMetrics();
|
62
|
act.getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
|
63
|
final float titleSize= displaymetrics.widthPixels * RubikActivity.MENU_BIG_TEXT_SIZE;
|
64
|
final float okSize = displaymetrics.widthPixels * RubikActivity.MENU_MEDIUM_TEXT_SIZE;
|
65
|
|
66
|
LayoutInflater layoutInflater = act.getLayoutInflater();
|
67
|
TextView tv = (TextView) layoutInflater.inflate(R.layout.dialog_title, null);
|
68
|
tv.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleSize);
|
69
|
tv.setText(R.string.scores);
|
70
|
builder.setCustomTitle(tv);
|
71
|
|
72
|
builder.setCancelable(true);
|
73
|
builder.setPositiveButton( R.string.ok, new DialogInterface.OnClickListener()
|
74
|
{
|
75
|
@Override
|
76
|
public void onClick(DialogInterface dialog, int which)
|
77
|
{
|
78
|
|
79
|
}
|
80
|
});
|
81
|
|
82
|
Bundle args = getArguments();
|
83
|
int curTab;
|
84
|
boolean isSubmitting;
|
85
|
|
86
|
try
|
87
|
{
|
88
|
curTab = args.getInt("tab");
|
89
|
isSubmitting = args.getBoolean("submitting");
|
90
|
}
|
91
|
catch(Exception e)
|
92
|
{
|
93
|
curTab = 0;
|
94
|
isSubmitting = false;
|
95
|
}
|
96
|
|
97
|
LayoutInflater inflater = act.getLayoutInflater();
|
98
|
final View view = inflater.inflate(R.layout.dialog_tabbed, null);
|
99
|
builder.setView(view);
|
100
|
|
101
|
ViewPager viewPager = view.findViewById(R.id.viewpager);
|
102
|
TabLayout tabLayout = view.findViewById(R.id.sliding_tabs);
|
103
|
mPagerAdapter = new RubikDialogScoresPagerAdapter(act,viewPager,isSubmitting, this);
|
104
|
tabLayout.setupWithViewPager(viewPager);
|
105
|
|
106
|
viewPager.setCurrentItem(curTab);
|
107
|
RubikObjectList list;
|
108
|
|
109
|
for (int object=0; object<RubikObjectList.NUM_OBJECTS; object++)
|
110
|
{
|
111
|
list = RubikObjectList.getObject(object);
|
112
|
int[] iconID = list.getIconIDs();
|
113
|
int len = list.getSizes().length;
|
114
|
|
115
|
for(int size=0; size<len; size++)
|
116
|
{
|
117
|
int t = RubikObjectList.pack(object,size);
|
118
|
ImageView imageView = new ImageView(act);
|
119
|
imageView.setImageResource(iconID[size]);
|
120
|
TabLayout.Tab tab = tabLayout.getTabAt(t);
|
121
|
if(tab!=null) tab.setCustomView(imageView);
|
122
|
}
|
123
|
}
|
124
|
|
125
|
Dialog dialog = builder.create();
|
126
|
|
127
|
dialog.setCanceledOnTouchOutside(false);
|
128
|
|
129
|
Window window = dialog.getWindow();
|
130
|
|
131
|
if( window!=null )
|
132
|
{
|
133
|
window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
|
134
|
}
|
135
|
|
136
|
dialog.setOnShowListener(new DialogInterface.OnShowListener()
|
137
|
{
|
138
|
@Override
|
139
|
public void onShow(DialogInterface dialog)
|
140
|
{
|
141
|
Button btnPositive = ((AlertDialog)dialog).getButton(Dialog.BUTTON_POSITIVE);
|
142
|
btnPositive.setTextSize(TypedValue.COMPLEX_UNIT_PX, okSize);
|
143
|
}
|
144
|
});
|
145
|
|
146
|
return dialog;
|
147
|
}
|
148
|
}
|