Project

General

Profile

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

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

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.ViewGroup;
37
import android.view.Window;
38
import android.widget.Button;
39
import android.widget.ImageView;
40
import android.widget.TextView;
41

    
42
import org.distorted.main.R;
43
import org.distorted.main.RubikActivity;
44
import org.distorted.objects.RubikObject;
45
import org.distorted.objects.RubikObjectList;
46

    
47
///////////////////////////////////////////////////////////////////////////////////////////////////
48

    
49
public class RubikDialogScores extends AppCompatDialogFragment
50
  {
51
  private RubikDialogScoresPagerAdapter mPagerAdapter;
52

    
53
///////////////////////////////////////////////////////////////////////////////////////////////////
54

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

    
62
    DisplayMetrics displaymetrics = new DisplayMetrics();
63
    act.getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
64

    
65
    int scrWidth = displaymetrics.widthPixels;
66
    final float titleSize= scrWidth*RubikActivity.MENU_BIG_TEXT_SIZE;
67
    final float okSize   = scrWidth*RubikActivity.DIALOG_BUTTON_SIZE;
68
    final int   tabHeight= (int)(scrWidth*RubikActivity.TAB_HEIGHT);
69
    final int   tabWidth = (int)(scrWidth*RubikActivity.TAB_WIDTH);
70

    
71
    LayoutInflater layoutInflater = act.getLayoutInflater();
72
    TextView tv = (TextView) layoutInflater.inflate(R.layout.dialog_title, null);
73
    tv.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleSize);
74
    tv.setText(R.string.scores);
75
    builder.setCustomTitle(tv);
76

    
77
    builder.setCancelable(true);
78
    builder.setPositiveButton( R.string.ok, new DialogInterface.OnClickListener()
79
      {
80
      @Override
81
      public void onClick(DialogInterface dialog, int which)
82
        {
83

    
84
        }
85
      });
86

    
87
    Bundle args = getArguments();
88
    int curTab;
89
    boolean isSubmitting;
90

    
91
    try
92
      {
93
      curTab = args.getInt("tab");
94
      isSubmitting = args.getBoolean("submitting");
95
      }
96
    catch(Exception e)
97
      {
98
      curTab = 0;
99
      isSubmitting = false;
100
      }
101

    
102
    LayoutInflater inflater = act.getLayoutInflater();
103
    final View view = inflater.inflate(R.layout.dialog_tabbed, null);
104
    builder.setView(view);
105

    
106
    ViewPager viewPager = view.findViewById(R.id.viewpager);
107
    TabLayout tabLayout = view.findViewById(R.id.sliding_tabs);
108
    mPagerAdapter = new RubikDialogScoresPagerAdapter(act,viewPager,isSubmitting, this);
109
    tabLayout.setupWithViewPager(viewPager);
110

    
111
    viewPager.setCurrentItem(curTab);
112
    int numObjects = RubikObjectList.getNumObjects();
113
    ViewGroup.LayoutParams paramsView = new ViewGroup.LayoutParams( tabWidth,tabHeight );
114

    
115
    for (int object=0; object<numObjects; object++)
116
      {
117
      RubikObject robject = RubikObjectList.getObject(object);
118
      ImageView imageView = new ImageView(act);
119
      if( robject!=null ) robject.setIconTo(act,imageView);
120
      imageView.setLayoutParams(paramsView);
121
      TabLayout.Tab tab = tabLayout.getTabAt(object);
122
      if(tab!=null) tab.setCustomView(imageView);
123
      }
124

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

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

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

    
144
    return dialog;
145
    }
146
  }
(11-11/21)