Project

General

Profile

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

magiccube / src / main / java / org / distorted / magic / RubikDialogScores.java @ 6918030e

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
package org.distorted.magic;
21
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
///////////////////////////////////////////////////////////////////////////////////////////////////
39
40 0fd3ac1f Leszek Koltunski
public class RubikDialogScores extends AppCompatDialogFragment
41 a7a7cc9c Leszek Koltunski
  {
42 0fd3ac1f Leszek Koltunski
  RubikDialogScoresPagerAdapter mPagerAdapter;
43 a7a7cc9c Leszek Koltunski
44 4235de9b Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
45
46
  @Override
47
  public void onStart()
48
    {
49
    super.onStart();
50
51
    Window window = getDialog().getWindow();
52
    window.setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL,
53
                    WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);
54
    window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
55
    }
56
57 fdec60a3 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
58
59
  @NonNull
60
  @Override
61
  public Dialog onCreateDialog(Bundle savedInstanceState)
62
    {
63
    FragmentActivity act = getActivity();
64
    AlertDialog.Builder builder = new AlertDialog.Builder(act);
65
66
    LayoutInflater layoutInflater = act.getLayoutInflater();
67 0fd3ac1f Leszek Koltunski
    TextView tv = (TextView) layoutInflater.inflate(R.layout.dialog_title, null);
68 4235de9b Leszek Koltunski
    tv.setText(R.string.scores);
69 fdec60a3 Leszek Koltunski
    builder.setCustomTitle(tv);
70
71
    builder.setCancelable(true);
72
    builder.setPositiveButton( R.string.ok, new DialogInterface.OnClickListener()
73
      {
74
      @Override
75
      public void onClick(DialogInterface dialog, int which)
76
        {
77
78
        }
79
      });
80
81 4918f19c Leszek Koltunski
    Bundle args = getArguments();
82
    int curTab;
83
84
    try
85
      {
86
      curTab = args.getInt("tab");
87
      }
88
    catch(Exception e)
89
      {
90
      curTab = 0;
91
      }
92
93 fdec60a3 Leszek Koltunski
    LayoutInflater inflater = act.getLayoutInflater();
94 0fd3ac1f Leszek Koltunski
    final View view = inflater.inflate(R.layout.dialog_scores, null);
95 fdec60a3 Leszek Koltunski
    builder.setView(view);
96
97 946d9762 Leszek Koltunski
    ViewPager viewPager = view.findViewById(R.id.viewpager);
98 fdec60a3 Leszek Koltunski
    TabLayout tabLayout = view.findViewById(R.id.sliding_tabs);
99 0fd3ac1f Leszek Koltunski
    mPagerAdapter = new RubikDialogScoresPagerAdapter(act,viewPager);
100 946d9762 Leszek Koltunski
    tabLayout.setupWithViewPager(viewPager);
101 cc5ec229 Leszek Koltunski
102 4918f19c Leszek Koltunski
    viewPager.setCurrentItem(curTab);
103 fdec60a3 Leszek Koltunski
104 dd73fdab Leszek Koltunski
    for (int i = 0; i< RubikSize.LENGTH; i++)
105 fdec60a3 Leszek Koltunski
      {
106
      ImageView imageView = new ImageView(act);
107 f3e12931 Leszek Koltunski
      imageView.setImageResource(RubikSize.getSize(i).getIconID());
108 fdec60a3 Leszek Koltunski
      TabLayout.Tab tab = tabLayout.getTabAt(i);
109
      if(tab!=null) tab.setCustomView(imageView);
110
      }
111
112
    return builder.create();
113
    }
114 a7a7cc9c Leszek Koltunski
  }