Project

General

Profile

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

magiccube / src / main / java / org / distorted / dialog / RubikDialogPattern.java @ b498f3f6

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2020 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.dialog;
21

    
22
import android.app.Dialog;
23
import android.content.Context;
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.util.DisplayMetrics;
32
import android.view.LayoutInflater;
33
import android.view.View;
34
import android.view.Window;
35
import android.view.WindowManager;
36
import android.widget.ImageView;
37
import android.widget.TextView;
38

    
39
import org.distorted.magic.R;
40
import org.distorted.object.RubikObjectList;
41
import org.distorted.patterns.RubikPatternList;
42

    
43
///////////////////////////////////////////////////////////////////////////////////////////////////
44

    
45
public class RubikDialogPattern extends AppCompatDialogFragment
46
  {
47
  RubikDialogPatternPagerAdapter mPagerAdapter;
48

    
49
///////////////////////////////////////////////////////////////////////////////////////////////////
50

    
51
  @Override
52
  public void onStart()
53
    {
54
    super.onStart();
55

    
56
    Window window = getDialog().getWindow();
57
    window.setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL,
58
                    WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);
59
    window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
60
    }
61

    
62
///////////////////////////////////////////////////////////////////////////////////////////////////
63

    
64
  @NonNull
65
  @Override
66
  public Dialog onCreateDialog(Bundle savedInstanceState)
67
    {
68
    FragmentActivity act = getActivity();
69
    AlertDialog.Builder builder = new AlertDialog.Builder(act);
70

    
71
    LayoutInflater layoutInflater = act.getLayoutInflater();
72
    TextView tv = (TextView) layoutInflater.inflate(R.layout.dialog_title, null);
73
    tv.setText(R.string.choose_pattern);
74
    builder.setCustomTitle(tv);
75

    
76
    Bundle args = getArguments();
77
    int curTab;
78

    
79
    try
80
      {
81
      curTab = args.getInt("tab");
82
      }
83
    catch(Exception e)
84
      {
85
      curTab = 0;
86
      }
87

    
88
    LayoutInflater inflater = act.getLayoutInflater();
89
    final View view = inflater.inflate(R.layout.dialog_tabbed, null);
90
    builder.setView(view);
91

    
92
    ViewPager viewPager = view.findViewById(R.id.viewpager);
93
    TabLayout tabLayout = view.findViewById(R.id.sliding_tabs);
94
    mPagerAdapter = new RubikDialogPatternPagerAdapter(act, viewPager, this);
95
    tabLayout.setupWithViewPager(viewPager);
96
    viewPager.setCurrentItem(curTab);
97

    
98
    for(int i=0; i< RubikPatternList.NUM_OBJECTS; i++)
99
      {
100
      RubikObjectList list = RubikPatternList.getObject(i);
101
      int size             = RubikPatternList.getSize(i);
102
      int sizeIndex        = RubikObjectList.getSizeIndex(list.ordinal(),size);
103
      int iconID           = list.getIconIDs()[sizeIndex];
104

    
105
      ImageView imageView = new ImageView(act);
106
      imageView.setImageResource(iconID);
107
      TabLayout.Tab tab = tabLayout.getTabAt(i);
108
      if(tab!=null) tab.setCustomView(imageView);
109
      }
110

    
111
    return builder.create();
112
    }
113

    
114
///////////////////////////////////////////////////////////////////////////////////////////////////
115

    
116
  @Override
117
  public void onResume()
118
    {
119
    super.onResume();
120

    
121
    Window window = getDialog().getWindow();
122
    Context context = getContext();
123

    
124
    if( window!=null && context!=null )
125
      {
126
      DisplayMetrics metrics = context.getResources().getDisplayMetrics();
127
      final float height= metrics.heightPixels;
128

    
129
      WindowManager.LayoutParams params = window.getAttributes();
130
      params.width = WindowManager.LayoutParams.WRAP_CONTENT;
131
      params.height = (int)(0.75f*height);
132
      window.setAttributes(params);
133
      }
134
    }
135

    
136
///////////////////////////////////////////////////////////////////////////////////////////////////
137

    
138
  public void rememberState()
139
    {
140
    mPagerAdapter.rememberState();
141
    }
142

    
143
///////////////////////////////////////////////////////////////////////////////////////////////////
144

    
145
  public static String getDialogTag()
146
    {
147
    return "DialogPattern";
148
    }
149
  }
(5-5/12)