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 |
fdec60a3
|
Leszek Koltunski
|
// Magic Cube is free software: you can redistribute it and/or modify //
|
7 |
a7a7cc9c
|
Leszek Koltunski
|
// 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 |
fdec60a3
|
Leszek Koltunski
|
// Magic Cube is distributed in the hope that it will be useful, //
|
12 |
a7a7cc9c
|
Leszek Koltunski
|
// 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 |
fdec60a3
|
Leszek Koltunski
|
// along with Magic Cube. If not, see <http://www.gnu.org/licenses/>. //
|
18 |
a7a7cc9c
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
19 |
|
|
|
20 |
1f9772f3
|
Leszek Koltunski
|
package org.distorted.dialogs;
|
21 |
a7a7cc9c
|
Leszek Koltunski
|
|
22 |
fdec60a3
|
Leszek Koltunski
|
import android.app.Dialog;
|
23 |
|
|
import android.content.DialogInterface;
|
24 |
|
|
import android.os.Bundle;
|
25 |
66e777b0
|
Leszek Koltunski
|
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 |
52d0a923
|
Leszek Koltunski
|
|
32 |
|
|
import android.util.DisplayMetrics;
|
33 |
|
|
import android.util.TypedValue;
|
34 |
fdec60a3
|
Leszek Koltunski
|
import android.view.LayoutInflater;
|
35 |
|
|
import android.view.View;
|
36 |
4235de9b
|
Leszek Koltunski
|
import android.view.Window;
|
37 |
52d0a923
|
Leszek Koltunski
|
import android.widget.Button;
|
38 |
fdec60a3
|
Leszek Koltunski
|
import android.widget.ImageView;
|
39 |
|
|
import android.widget.TextView;
|
40 |
a7a7cc9c
|
Leszek Koltunski
|
|
41 |
318c0a7d
|
Leszek Koltunski
|
import org.distorted.objectlib.main.ObjectType;
|
42 |
3f7a4363
|
Leszek Koltunski
|
|
43 |
1f9772f3
|
Leszek Koltunski
|
import org.distorted.main.R;
|
44 |
52d0a923
|
Leszek Koltunski
|
import org.distorted.main.RubikActivity;
|
45 |
211b48f2
|
Leszek Koltunski
|
|
46 |
a7a7cc9c
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
47 |
|
|
|
48 |
0fd3ac1f
|
Leszek Koltunski
|
public class RubikDialogScores extends AppCompatDialogFragment
|
49 |
a7a7cc9c
|
Leszek Koltunski
|
{
|
50 |
85248b04
|
Leszek Koltunski
|
private RubikDialogScoresPagerAdapter mPagerAdapter;
|
51 |
4235de9b
|
Leszek Koltunski
|
|
52 |
fdec60a3
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
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 |
52d0a923
|
Leszek Koltunski
|
DisplayMetrics displaymetrics = new DisplayMetrics();
|
62 |
|
|
act.getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
|
63 |
|
|
final float titleSize= displaymetrics.widthPixels * RubikActivity.MENU_BIG_TEXT_SIZE;
|
64 |
eb376d3a
|
Leszek Koltunski
|
final float okSize = displaymetrics.widthPixels * RubikActivity.DIALOG_BUTTON_SIZE;
|
65 |
52d0a923
|
Leszek Koltunski
|
|
66 |
fdec60a3
|
Leszek Koltunski
|
LayoutInflater layoutInflater = act.getLayoutInflater();
|
67 |
0fd3ac1f
|
Leszek Koltunski
|
TextView tv = (TextView) layoutInflater.inflate(R.layout.dialog_title, null);
|
68 |
52d0a923
|
Leszek Koltunski
|
tv.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleSize);
|
69 |
4235de9b
|
Leszek Koltunski
|
tv.setText(R.string.scores);
|
70 |
fdec60a3
|
Leszek Koltunski
|
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 |
4918f19c
|
Leszek Koltunski
|
Bundle args = getArguments();
|
83 |
|
|
int curTab;
|
84 |
4895fff6
|
Leszek Koltunski
|
boolean isSubmitting;
|
85 |
4918f19c
|
Leszek Koltunski
|
|
86 |
|
|
try
|
87 |
|
|
{
|
88 |
|
|
curTab = args.getInt("tab");
|
89 |
4895fff6
|
Leszek Koltunski
|
isSubmitting = args.getBoolean("submitting");
|
90 |
4918f19c
|
Leszek Koltunski
|
}
|
91 |
|
|
catch(Exception e)
|
92 |
|
|
{
|
93 |
|
|
curTab = 0;
|
94 |
4895fff6
|
Leszek Koltunski
|
isSubmitting = false;
|
95 |
4918f19c
|
Leszek Koltunski
|
}
|
96 |
|
|
|
97 |
fdec60a3
|
Leszek Koltunski
|
LayoutInflater inflater = act.getLayoutInflater();
|
98 |
d18993ac
|
Leszek Koltunski
|
final View view = inflater.inflate(R.layout.dialog_tabbed, null);
|
99 |
fdec60a3
|
Leszek Koltunski
|
builder.setView(view);
|
100 |
|
|
|
101 |
946d9762
|
Leszek Koltunski
|
ViewPager viewPager = view.findViewById(R.id.viewpager);
|
102 |
fdec60a3
|
Leszek Koltunski
|
TabLayout tabLayout = view.findViewById(R.id.sliding_tabs);
|
103 |
f895e77a
|
Leszek Koltunski
|
mPagerAdapter = new RubikDialogScoresPagerAdapter(act,viewPager,isSubmitting, this);
|
104 |
946d9762
|
Leszek Koltunski
|
tabLayout.setupWithViewPager(viewPager);
|
105 |
cc5ec229
|
Leszek Koltunski
|
|
106 |
4918f19c
|
Leszek Koltunski
|
viewPager.setCurrentItem(curTab);
|
107 |
318c0a7d
|
Leszek Koltunski
|
ObjectType list;
|
108 |
7ac0ee88
|
Leszek Koltunski
|
int iconSize = RubikActivity.getDrawableSize();
|
109 |
fdec60a3
|
Leszek Koltunski
|
|
110 |
318c0a7d
|
Leszek Koltunski
|
for (int object = 0; object< ObjectType.NUM_OBJECTS; object++)
|
111 |
fdec60a3
|
Leszek Koltunski
|
{
|
112 |
318c0a7d
|
Leszek Koltunski
|
list = ObjectType.getObject(object);
|
113 |
7ac0ee88
|
Leszek Koltunski
|
int iconID = list.getIconID(iconSize);
|
114 |
|
|
ImageView imageView = new ImageView(act);
|
115 |
|
|
imageView.setImageResource(iconID);
|
116 |
|
|
TabLayout.Tab tab = tabLayout.getTabAt(object);
|
117 |
|
|
if(tab!=null) tab.setCustomView(imageView);
|
118 |
fdec60a3
|
Leszek Koltunski
|
}
|
119 |
|
|
|
120 |
85248b04
|
Leszek Koltunski
|
Dialog dialog = builder.create();
|
121 |
|
|
dialog.setCanceledOnTouchOutside(false);
|
122 |
|
|
Window window = dialog.getWindow();
|
123 |
|
|
|
124 |
|
|
if( window!=null )
|
125 |
|
|
{
|
126 |
ffd68f35
|
Leszek Koltunski
|
window.getDecorView().setSystemUiVisibility(RubikActivity.FLAGS);
|
127 |
85248b04
|
Leszek Koltunski
|
}
|
128 |
|
|
|
129 |
52d0a923
|
Leszek Koltunski
|
dialog.setOnShowListener(new DialogInterface.OnShowListener()
|
130 |
|
|
{
|
131 |
|
|
@Override
|
132 |
|
|
public void onShow(DialogInterface dialog)
|
133 |
|
|
{
|
134 |
|
|
Button btnPositive = ((AlertDialog)dialog).getButton(Dialog.BUTTON_POSITIVE);
|
135 |
|
|
btnPositive.setTextSize(TypedValue.COMPLEX_UNIT_PX, okSize);
|
136 |
|
|
}
|
137 |
|
|
});
|
138 |
|
|
|
139 |
85248b04
|
Leszek Koltunski
|
return dialog;
|
140 |
fdec60a3
|
Leszek Koltunski
|
}
|
141 |
a7a7cc9c
|
Leszek Koltunski
|
}
|