Project

General

Profile

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

magiccube / src / main / java / org / distorted / dialog / RubikDialogPattern.java @ 6f2a942e

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.patterns.RubikPattern;
41

    
42
///////////////////////////////////////////////////////////////////////////////////////////////////
43

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

    
48
///////////////////////////////////////////////////////////////////////////////////////////////////
49

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

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

    
61
///////////////////////////////////////////////////////////////////////////////////////////////////
62

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

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

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

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

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

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

    
97
    int[] iconID = { R.drawable.cube2, R.drawable.cube3, R.drawable.cube4, R.drawable.cube5 };
98

    
99
    for(int i=0; i< RubikPattern.NUM_CUBES; i++)
100
      {
101
      ImageView imageView = new ImageView(act);
102
      imageView.setImageResource(iconID[i]);
103
      TabLayout.Tab tab = tabLayout.getTabAt(i);
104
      if(tab!=null) tab.setCustomView(imageView);
105
      }
106

    
107
    return builder.create();
108
    }
109

    
110
///////////////////////////////////////////////////////////////////////////////////////////////////
111

    
112
  @Override
113
  public void onResume()
114
    {
115
    super.onResume();
116

    
117
    Window window = getDialog().getWindow();
118
    Context context = getContext();
119

    
120
    if( window!=null && context!=null )
121
      {
122
      DisplayMetrics metrics = context.getResources().getDisplayMetrics();
123
      final float height= metrics.heightPixels;
124

    
125
      WindowManager.LayoutParams params = window.getAttributes();
126
      params.width = WindowManager.LayoutParams.WRAP_CONTENT;
127
      params.height = (int)(0.75f*height);
128
      window.setAttributes(params);
129
      }
130
    }
131

    
132
///////////////////////////////////////////////////////////////////////////////////////////////////
133

    
134
  public void rememberCategories()
135
    {
136
    mPagerAdapter.rememberCategories();
137
    }
138

    
139
///////////////////////////////////////////////////////////////////////////////////////////////////
140

    
141
  public static String getDialogTag()
142
    {
143
    return "DialogPattern";
144
    }
145
  }
(5-5/12)