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 |
fdec60a3
|
Leszek Koltunski
|
import android.view.LayoutInflater;
|
32 |
|
|
import android.view.View;
|
33 |
4235de9b
|
Leszek Koltunski
|
import android.view.Window;
|
34 |
|
|
import android.view.WindowManager;
|
35 |
fdec60a3
|
Leszek Koltunski
|
import android.widget.ImageView;
|
36 |
|
|
import android.widget.TextView;
|
37 |
a7a7cc9c
|
Leszek Koltunski
|
|
38 |
1f9772f3
|
Leszek Koltunski
|
import org.distorted.main.R;
|
39 |
|
|
import org.distorted.objects.RubikObjectList;
|
40 |
211b48f2
|
Leszek Koltunski
|
|
41 |
a7a7cc9c
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
42 |
|
|
|
43 |
0fd3ac1f
|
Leszek Koltunski
|
public class RubikDialogScores extends AppCompatDialogFragment
|
44 |
a7a7cc9c
|
Leszek Koltunski
|
{
|
45 |
85248b04
|
Leszek Koltunski
|
private RubikDialogScoresPagerAdapter mPagerAdapter;
|
46 |
4235de9b
|
Leszek Koltunski
|
|
47 |
fdec60a3
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
48 |
|
|
|
49 |
|
|
@NonNull
|
50 |
|
|
@Override
|
51 |
|
|
public Dialog onCreateDialog(Bundle savedInstanceState)
|
52 |
|
|
{
|
53 |
|
|
FragmentActivity act = getActivity();
|
54 |
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(act);
|
55 |
|
|
|
56 |
|
|
LayoutInflater layoutInflater = act.getLayoutInflater();
|
57 |
0fd3ac1f
|
Leszek Koltunski
|
TextView tv = (TextView) layoutInflater.inflate(R.layout.dialog_title, null);
|
58 |
4235de9b
|
Leszek Koltunski
|
tv.setText(R.string.scores);
|
59 |
fdec60a3
|
Leszek Koltunski
|
builder.setCustomTitle(tv);
|
60 |
|
|
|
61 |
|
|
builder.setCancelable(true);
|
62 |
|
|
builder.setPositiveButton( R.string.ok, new DialogInterface.OnClickListener()
|
63 |
|
|
{
|
64 |
|
|
@Override
|
65 |
|
|
public void onClick(DialogInterface dialog, int which)
|
66 |
|
|
{
|
67 |
|
|
|
68 |
|
|
}
|
69 |
|
|
});
|
70 |
|
|
|
71 |
4918f19c
|
Leszek Koltunski
|
Bundle args = getArguments();
|
72 |
|
|
int curTab;
|
73 |
4895fff6
|
Leszek Koltunski
|
boolean isSubmitting;
|
74 |
4918f19c
|
Leszek Koltunski
|
|
75 |
|
|
try
|
76 |
|
|
{
|
77 |
|
|
curTab = args.getInt("tab");
|
78 |
4895fff6
|
Leszek Koltunski
|
isSubmitting = args.getBoolean("submitting");
|
79 |
4918f19c
|
Leszek Koltunski
|
}
|
80 |
|
|
catch(Exception e)
|
81 |
|
|
{
|
82 |
|
|
curTab = 0;
|
83 |
4895fff6
|
Leszek Koltunski
|
isSubmitting = false;
|
84 |
4918f19c
|
Leszek Koltunski
|
}
|
85 |
|
|
|
86 |
fdec60a3
|
Leszek Koltunski
|
LayoutInflater inflater = act.getLayoutInflater();
|
87 |
d18993ac
|
Leszek Koltunski
|
final View view = inflater.inflate(R.layout.dialog_tabbed, null);
|
88 |
fdec60a3
|
Leszek Koltunski
|
builder.setView(view);
|
89 |
|
|
|
90 |
946d9762
|
Leszek Koltunski
|
ViewPager viewPager = view.findViewById(R.id.viewpager);
|
91 |
fdec60a3
|
Leszek Koltunski
|
TabLayout tabLayout = view.findViewById(R.id.sliding_tabs);
|
92 |
f895e77a
|
Leszek Koltunski
|
mPagerAdapter = new RubikDialogScoresPagerAdapter(act,viewPager,isSubmitting, this);
|
93 |
946d9762
|
Leszek Koltunski
|
tabLayout.setupWithViewPager(viewPager);
|
94 |
cc5ec229
|
Leszek Koltunski
|
|
95 |
4918f19c
|
Leszek Koltunski
|
viewPager.setCurrentItem(curTab);
|
96 |
4888e97c
|
Leszek Koltunski
|
RubikObjectList list;
|
97 |
fdec60a3
|
Leszek Koltunski
|
|
98 |
4888e97c
|
Leszek Koltunski
|
for (int object=0; object<RubikObjectList.NUM_OBJECTS; object++)
|
99 |
fdec60a3
|
Leszek Koltunski
|
{
|
100 |
4888e97c
|
Leszek Koltunski
|
list = RubikObjectList.getObject(object);
|
101 |
|
|
int[] iconID = list.getIconIDs();
|
102 |
|
|
int len = list.getSizes().length;
|
103 |
|
|
|
104 |
|
|
for(int size=0; size<len; size++)
|
105 |
|
|
{
|
106 |
|
|
int t = RubikObjectList.pack(object,size);
|
107 |
|
|
ImageView imageView = new ImageView(act);
|
108 |
|
|
imageView.setImageResource(iconID[size]);
|
109 |
|
|
TabLayout.Tab tab = tabLayout.getTabAt(t);
|
110 |
|
|
if(tab!=null) tab.setCustomView(imageView);
|
111 |
|
|
}
|
112 |
fdec60a3
|
Leszek Koltunski
|
}
|
113 |
|
|
|
114 |
85248b04
|
Leszek Koltunski
|
Dialog dialog = builder.create();
|
115 |
|
|
|
116 |
|
|
dialog.setCanceledOnTouchOutside(false);
|
117 |
|
|
|
118 |
|
|
Window window = dialog.getWindow();
|
119 |
|
|
|
120 |
|
|
if( window!=null )
|
121 |
|
|
{
|
122 |
|
|
window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
|
123 |
|
|
}
|
124 |
|
|
|
125 |
|
|
return dialog;
|
126 |
fdec60a3
|
Leszek Koltunski
|
}
|
127 |
a7a7cc9c
|
Leszek Koltunski
|
}
|