Project

General

Profile

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

magiccube / src / main / java / org / distorted / magic / RubikDialogScores.java @ 4235de9b

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.magic;
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
///////////////////////////////////////////////////////////////////////////////////////////////////
39

    
40
public class RubikDialogScores extends AppCompatDialogFragment
41
  {
42
  RubikDialogScoresPagerAdapter mPagerAdapter;
43

    
44
///////////////////////////////////////////////////////////////////////////////////////////////////
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
///////////////////////////////////////////////////////////////////////////////////////////////////
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
    TextView tv = (TextView) layoutInflater.inflate(R.layout.dialog_title, null);
68
    tv.setText(R.string.scores);
69
    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
    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
    LayoutInflater inflater = act.getLayoutInflater();
94
    final View view = inflater.inflate(R.layout.dialog_scores, null);
95
    builder.setView(view);
96

    
97
    ViewPager viewPager = view.findViewById(R.id.viewpager);
98
    TabLayout tabLayout = view.findViewById(R.id.sliding_tabs);
99
    mPagerAdapter = new RubikDialogScoresPagerAdapter(act,viewPager);
100
    tabLayout.setupWithViewPager(viewPager);
101

    
102
    viewPager.setCurrentItem(curTab);
103

    
104
    for (int i = 0; i< RubikSize.LENGTH; i++)
105
      {
106
      ImageView imageView = new ImageView(act);
107
      imageView.setImageResource(RubikSize.getSize(i).getIconID());
108
      TabLayout.Tab tab = tabLayout.getTabAt(i);
109
      if(tab!=null) tab.setCustomView(imageView);
110
      }
111

    
112
    return builder.create();
113
    }
114
  }
(4-4/11)