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