Project

General

Profile

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

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

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.dialog;
21

    
22
import android.app.Dialog;
23
import android.content.Context;
24
import android.content.DialogInterface;
25
import android.os.Bundle;
26
import android.support.annotation.NonNull;
27
import android.support.v4.app.FragmentActivity;
28
import android.support.v4.view.ViewPager;
29
import android.support.v7.app.AlertDialog;
30
import android.support.v7.app.AppCompatDialogFragment;
31
import android.support.design.widget.TabLayout;
32
import android.util.DisplayMetrics;
33
import android.view.LayoutInflater;
34
import android.view.View;
35
import android.view.Window;
36
import android.view.WindowManager;
37
import android.widget.ImageView;
38
import android.widget.TextView;
39

    
40
import org.distorted.magic.R;
41
import org.distorted.patterns.RubikPattern;
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.patterns);
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
    int[] iconID = { R.drawable.cube2, R.drawable.cube3, R.drawable.cube4, R.drawable.cube5 };
99

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

    
108
    return builder.create();
109
    }
110

    
111
///////////////////////////////////////////////////////////////////////////////////////////////////
112

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

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

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

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

    
133
///////////////////////////////////////////////////////////////////////////////////////////////////
134

    
135
  public static String getDialogTag()
136
    {
137
    return "DialogPattern";
138
    }
139
  }
(5-5/12)