Project

General

Profile

Download (4.92 KB) Statistics
| Branch: | Tag: | Revision:

magiccube / src / main / java / org / distorted / dialog / RubikDialogScores.java @ 4888e97c

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 211b48f2 Leszek Koltunski
package org.distorted.dialog;
21 a7a7cc9c Leszek Koltunski
22 fdec60a3 Leszek Koltunski
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 946d9762 Leszek Koltunski
import android.support.v4.view.ViewPager;
28 fdec60a3 Leszek Koltunski
import android.support.v7.app.AlertDialog;
29 a7a7cc9c Leszek Koltunski
import android.support.v7.app.AppCompatDialogFragment;
30 fdec60a3 Leszek Koltunski
import android.support.design.widget.TabLayout;
31
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 211b48f2 Leszek Koltunski
import org.distorted.magic.R;
39 27a70eae Leszek Koltunski
import org.distorted.object.RubikObjectList;
40 211b48f2 Leszek Koltunski
41 a7a7cc9c Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
42
43 0fd3ac1f Leszek Koltunski
public class RubikDialogScores extends AppCompatDialogFragment
44 a7a7cc9c Leszek Koltunski
  {
45 0fd3ac1f Leszek Koltunski
  RubikDialogScoresPagerAdapter mPagerAdapter;
46 a7a7cc9c Leszek Koltunski
47 4235de9b Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
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 fdec60a3 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
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 0fd3ac1f Leszek Koltunski
    TextView tv = (TextView) layoutInflater.inflate(R.layout.dialog_title, null);
71 4235de9b Leszek Koltunski
    tv.setText(R.string.scores);
72 fdec60a3 Leszek Koltunski
    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 4918f19c Leszek Koltunski
    Bundle args = getArguments();
85
    int curTab;
86
87
    try
88
      {
89
      curTab = args.getInt("tab");
90
      }
91
    catch(Exception e)
92
      {
93
      curTab = 0;
94
      }
95
96 fdec60a3 Leszek Koltunski
    LayoutInflater inflater = act.getLayoutInflater();
97 0fd3ac1f Leszek Koltunski
    final View view = inflater.inflate(R.layout.dialog_scores, null);
98 fdec60a3 Leszek Koltunski
    builder.setView(view);
99
100 946d9762 Leszek Koltunski
    ViewPager viewPager = view.findViewById(R.id.viewpager);
101 fdec60a3 Leszek Koltunski
    TabLayout tabLayout = view.findViewById(R.id.sliding_tabs);
102 0fd3ac1f Leszek Koltunski
    mPagerAdapter = new RubikDialogScoresPagerAdapter(act,viewPager);
103 946d9762 Leszek Koltunski
    tabLayout.setupWithViewPager(viewPager);
104 cc5ec229 Leszek Koltunski
105 4918f19c Leszek Koltunski
    viewPager.setCurrentItem(curTab);
106 4888e97c Leszek Koltunski
    RubikObjectList list;
107 fdec60a3 Leszek Koltunski
108 4888e97c Leszek Koltunski
    for (int object=0; object<RubikObjectList.NUM_OBJECTS; object++)
109 fdec60a3 Leszek Koltunski
      {
110 4888e97c Leszek Koltunski
      list = RubikObjectList.getObject(object);
111
      int[] iconID = list.getIconIDs();
112
      int len = list.getSizes().length;
113
114
      for(int size=0; size<len; size++)
115
        {
116
        int t = RubikObjectList.pack(object,size);
117
        ImageView imageView = new ImageView(act);
118
        imageView.setImageResource(iconID[size]);
119
        TabLayout.Tab tab = tabLayout.getTabAt(t);
120
        if(tab!=null) tab.setCustomView(imageView);
121
        }
122 fdec60a3 Leszek Koltunski
      }
123
124
    return builder.create();
125
    }
126 a7a7cc9c Leszek Koltunski
  }