Project

General

Profile

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

magiccube / src / main / java / org / distorted / dialogs / RubikDialogScores.java @ 801b16db

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.dialogs;
21

    
22
import android.app.Dialog;
23
import android.content.DialogInterface;
24
import android.os.Bundle;
25
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
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.main.R;
39
import org.distorted.objects.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
    Dialog dialog = getDialog();
55

    
56
    if( dialog!=null )
57
      {
58
      dialog.setCanceledOnTouchOutside(false);
59

    
60
      Window window = dialog.getWindow();
61

    
62
      if( window!=null )
63
        {
64
        window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
65
        }
66
      }
67
    }
68

    
69
///////////////////////////////////////////////////////////////////////////////////////////////////
70

    
71
  @NonNull
72
  @Override
73
  public Dialog onCreateDialog(Bundle savedInstanceState)
74
    {
75
    FragmentActivity act = getActivity();
76
    AlertDialog.Builder builder = new AlertDialog.Builder(act);
77

    
78
    LayoutInflater layoutInflater = act.getLayoutInflater();
79
    TextView tv = (TextView) layoutInflater.inflate(R.layout.dialog_title, null);
80
    tv.setText(R.string.scores);
81
    builder.setCustomTitle(tv);
82

    
83
    builder.setCancelable(true);
84
    builder.setPositiveButton( R.string.ok, new DialogInterface.OnClickListener()
85
      {
86
      @Override
87
      public void onClick(DialogInterface dialog, int which)
88
        {
89

    
90
        }
91
      });
92

    
93
    Bundle args = getArguments();
94
    int curTab;
95
    boolean isSubmitting;
96

    
97
    try
98
      {
99
      curTab = args.getInt("tab");
100
      isSubmitting = args.getBoolean("submitting");
101
      }
102
    catch(Exception e)
103
      {
104
      curTab = 0;
105
      isSubmitting = false;
106
      }
107

    
108
    LayoutInflater inflater = act.getLayoutInflater();
109
    final View view = inflater.inflate(R.layout.dialog_tabbed, null);
110
    builder.setView(view);
111

    
112
    ViewPager viewPager = view.findViewById(R.id.viewpager);
113
    TabLayout tabLayout = view.findViewById(R.id.sliding_tabs);
114
    mPagerAdapter = new RubikDialogScoresPagerAdapter(act,viewPager,isSubmitting, this);
115
    tabLayout.setupWithViewPager(viewPager);
116

    
117
    viewPager.setCurrentItem(curTab);
118
    RubikObjectList list;
119

    
120
    for (int object=0; object<RubikObjectList.NUM_OBJECTS; object++)
121
      {
122
      list = RubikObjectList.getObject(object);
123
      int[] iconID = list.getIconIDs();
124
      int len = list.getSizes().length;
125

    
126
      for(int size=0; size<len; size++)
127
        {
128
        int t = RubikObjectList.pack(object,size);
129
        ImageView imageView = new ImageView(act);
130
        imageView.setImageResource(iconID[size]);
131
        TabLayout.Tab tab = tabLayout.getTabAt(t);
132
        if(tab!=null) tab.setCustomView(imageView);
133
        }
134
      }
135

    
136
    return builder.create();
137
    }
138
  }
(8-8/13)