Project

General

Profile

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

magiccube / src / main / java / org / distorted / dialogs / RubikDialogScores.java @ bdbbb4c5

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

    
32
import android.util.DisplayMetrics;
33
import android.util.TypedValue;
34
import android.view.LayoutInflater;
35
import android.view.View;
36
import android.view.Window;
37
import android.widget.Button;
38
import android.widget.ImageView;
39
import android.widget.TextView;
40

    
41
import org.distorted.main.R;
42
import org.distorted.main.RubikActivity;
43
import org.distorted.objectlb.ObjectList;
44

    
45
///////////////////////////////////////////////////////////////////////////////////////////////////
46

    
47
public class RubikDialogScores extends AppCompatDialogFragment
48
  {
49
  private RubikDialogScoresPagerAdapter mPagerAdapter;
50

    
51
///////////////////////////////////////////////////////////////////////////////////////////////////
52

    
53
  @NonNull
54
  @Override
55
  public Dialog onCreateDialog(Bundle savedInstanceState)
56
    {
57
    FragmentActivity act = getActivity();
58
    AlertDialog.Builder builder = new AlertDialog.Builder(act);
59

    
60
    DisplayMetrics displaymetrics = new DisplayMetrics();
61
    act.getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
62
    final float titleSize= displaymetrics.widthPixels * RubikActivity.MENU_BIG_TEXT_SIZE;
63
    final float okSize   = displaymetrics.widthPixels * RubikActivity.DIALOG_BUTTON_SIZE;
64

    
65
    LayoutInflater layoutInflater = act.getLayoutInflater();
66
    TextView tv = (TextView) layoutInflater.inflate(R.layout.dialog_title, null);
67
    tv.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleSize);
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
    boolean isSubmitting;
84

    
85
    try
86
      {
87
      curTab = args.getInt("tab");
88
      isSubmitting = args.getBoolean("submitting");
89
      }
90
    catch(Exception e)
91
      {
92
      curTab = 0;
93
      isSubmitting = false;
94
      }
95

    
96
    LayoutInflater inflater = act.getLayoutInflater();
97
    final View view = inflater.inflate(R.layout.dialog_tabbed, null);
98
    builder.setView(view);
99

    
100
    ViewPager viewPager = view.findViewById(R.id.viewpager);
101
    TabLayout tabLayout = view.findViewById(R.id.sliding_tabs);
102
    mPagerAdapter = new RubikDialogScoresPagerAdapter(act,viewPager,isSubmitting, this);
103
    tabLayout.setupWithViewPager(viewPager);
104

    
105
    viewPager.setCurrentItem(curTab);
106
    ObjectList list;
107

    
108
    for (int object = 0; object< ObjectList.NUM_OBJECTS; object++)
109
      {
110
      list = ObjectList.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 = ObjectList.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
      }
123

    
124
    Dialog dialog = builder.create();
125
    dialog.setCanceledOnTouchOutside(false);
126
    Window window = dialog.getWindow();
127

    
128
    if( window!=null )
129
      {
130
      window.getDecorView().setSystemUiVisibility(RubikActivity.FLAGS);
131
      }
132

    
133
    dialog.setOnShowListener(new DialogInterface.OnShowListener()
134
      {
135
      @Override
136
      public void onShow(DialogInterface dialog)
137
        {
138
        Button btnPositive = ((AlertDialog)dialog).getButton(Dialog.BUTTON_POSITIVE);
139
        btnPositive.setTextSize(TypedValue.COMPLEX_UNIT_PX, okSize);
140
        }
141
      });
142

    
143
    return dialog;
144
    }
145
  }
(11-11/19)