Project

General

Profile

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

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

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 1f9772f3 Leszek Koltunski
package org.distorted.dialogs;
21 a7a7cc9c Leszek Koltunski
22 fdec60a3 Leszek Koltunski
import android.app.Dialog;
23
import android.content.DialogInterface;
24
import android.os.Bundle;
25 66e777b0 Leszek Koltunski
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 52d0a923 Leszek Koltunski
32
import android.util.DisplayMetrics;
33
import android.util.TypedValue;
34 fdec60a3 Leszek Koltunski
import android.view.LayoutInflater;
35
import android.view.View;
36 6e3fcb91 Leszek Koltunski
import android.view.ViewGroup;
37 4235de9b Leszek Koltunski
import android.view.Window;
38 52d0a923 Leszek Koltunski
import android.widget.Button;
39 fdec60a3 Leszek Koltunski
import android.widget.ImageView;
40
import android.widget.TextView;
41 a7a7cc9c Leszek Koltunski
42 1f9772f3 Leszek Koltunski
import org.distorted.main.R;
43 52d0a923 Leszek Koltunski
import org.distorted.main.RubikActivity;
44 d433b50e Leszek Koltunski
import org.distorted.objects.RubikObject;
45
import org.distorted.objects.RubikObjectList;
46 211b48f2 Leszek Koltunski
47 a7a7cc9c Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
48
49 0fd3ac1f Leszek Koltunski
public class RubikDialogScores extends AppCompatDialogFragment
50 a7a7cc9c Leszek Koltunski
  {
51 85248b04 Leszek Koltunski
  private RubikDialogScoresPagerAdapter mPagerAdapter;
52 4235de9b Leszek Koltunski
53 fdec60a3 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
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 52d0a923 Leszek Koltunski
    DisplayMetrics displaymetrics = new DisplayMetrics();
63
    act.getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
64 6e3fcb91 Leszek Koltunski
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 52d0a923 Leszek Koltunski
71 fdec60a3 Leszek Koltunski
    LayoutInflater layoutInflater = act.getLayoutInflater();
72 0fd3ac1f Leszek Koltunski
    TextView tv = (TextView) layoutInflater.inflate(R.layout.dialog_title, null);
73 52d0a923 Leszek Koltunski
    tv.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleSize);
74 4235de9b Leszek Koltunski
    tv.setText(R.string.scores);
75 fdec60a3 Leszek Koltunski
    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 4918f19c Leszek Koltunski
    Bundle args = getArguments();
88
    int curTab;
89 4895fff6 Leszek Koltunski
    boolean isSubmitting;
90 4918f19c Leszek Koltunski
91
    try
92
      {
93
      curTab = args.getInt("tab");
94 4895fff6 Leszek Koltunski
      isSubmitting = args.getBoolean("submitting");
95 4918f19c Leszek Koltunski
      }
96
    catch(Exception e)
97
      {
98
      curTab = 0;
99 4895fff6 Leszek Koltunski
      isSubmitting = false;
100 4918f19c Leszek Koltunski
      }
101
102 fdec60a3 Leszek Koltunski
    LayoutInflater inflater = act.getLayoutInflater();
103 d18993ac Leszek Koltunski
    final View view = inflater.inflate(R.layout.dialog_tabbed, null);
104 fdec60a3 Leszek Koltunski
    builder.setView(view);
105
106 946d9762 Leszek Koltunski
    ViewPager viewPager = view.findViewById(R.id.viewpager);
107 fdec60a3 Leszek Koltunski
    TabLayout tabLayout = view.findViewById(R.id.sliding_tabs);
108 f895e77a Leszek Koltunski
    mPagerAdapter = new RubikDialogScoresPagerAdapter(act,viewPager,isSubmitting, this);
109 946d9762 Leszek Koltunski
    tabLayout.setupWithViewPager(viewPager);
110 cc5ec229 Leszek Koltunski
111 4918f19c Leszek Koltunski
    viewPager.setCurrentItem(curTab);
112 d433b50e Leszek Koltunski
    int numObjects = RubikObjectList.getNumObjects();
113 6e3fcb91 Leszek Koltunski
    ViewGroup.LayoutParams paramsView = new ViewGroup.LayoutParams( tabWidth,tabHeight );
114 fdec60a3 Leszek Koltunski
115 d433b50e Leszek Koltunski
    for (int object=0; object<numObjects; object++)
116 fdec60a3 Leszek Koltunski
      {
117 d433b50e Leszek Koltunski
      RubikObject robject = RubikObjectList.getObject(object);
118 7ac0ee88 Leszek Koltunski
      ImageView imageView = new ImageView(act);
119 eb985085 Leszek Koltunski
      if( robject!=null ) robject.setIconTo(act,imageView);
120 6e3fcb91 Leszek Koltunski
      imageView.setLayoutParams(paramsView);
121 7ac0ee88 Leszek Koltunski
      TabLayout.Tab tab = tabLayout.getTabAt(object);
122
      if(tab!=null) tab.setCustomView(imageView);
123 fdec60a3 Leszek Koltunski
      }
124
125 85248b04 Leszek Koltunski
    Dialog dialog = builder.create();
126
    dialog.setCanceledOnTouchOutside(false);
127
    Window window = dialog.getWindow();
128
129
    if( window!=null )
130
      {
131 ffd68f35 Leszek Koltunski
      window.getDecorView().setSystemUiVisibility(RubikActivity.FLAGS);
132 85248b04 Leszek Koltunski
      }
133
134 52d0a923 Leszek Koltunski
    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 85248b04 Leszek Koltunski
    return dialog;
145 fdec60a3 Leszek Koltunski
    }
146 a7a7cc9c Leszek Koltunski
  }