Project

General

Profile

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

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

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.content.Context;
23
import android.support.v4.app.FragmentActivity;
24
import android.util.AttributeSet;
25
import android.util.DisplayMetrics;
26
import android.view.View;
27
import android.widget.Button;
28
import android.widget.FrameLayout;
29
import android.widget.LinearLayout;
30

    
31
import org.distorted.magic.R;
32
import org.distorted.magic.RubikActivity;
33
import org.distorted.uistate.RubikState;
34

    
35
///////////////////////////////////////////////////////////////////////////////////////////////////
36

    
37
public class RubikDialogPatternView extends FrameLayout
38
  {
39
  private LinearLayout mLayout;
40
  private RubikDialogPattern mDialog;
41

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

    
44
  public RubikDialogPatternView(Context context, AttributeSet attrs, int defStyle)
45
    {
46
    super(context, attrs, defStyle);
47
    }
48

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

    
51
  public RubikDialogPatternView(Context context, AttributeSet attrs)
52
    {
53
    super(context, attrs);
54
    }
55

    
56
///////////////////////////////////////////////////////////////////////////////////////////////////
57

    
58
  public RubikDialogPatternView(FragmentActivity act, RubikDialogPattern dialog, String[] categories)
59
    {
60
    super(act);
61

    
62
    mDialog = dialog;
63
    View tab = inflate( act, R.layout.dialog_pattern_tab, null);
64
    mLayout = tab.findViewById(R.id.tabLayout);
65
    createSection(act,categories);
66

    
67
    addView(tab);
68
    }
69

    
70
///////////////////////////////////////////////////////////////////////////////////////////////////
71

    
72
  private void createSection(final FragmentActivity act, final String[] categories)
73
    {
74
    DisplayMetrics metrics = act.getResources().getDisplayMetrics();
75
    final float scale = metrics.density;
76
    int margin = (int)(3*scale + 0.5f);
77
    LinearLayout.LayoutParams bParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.WRAP_CONTENT);
78
    bParams.setMargins(margin, margin, margin, margin);
79

    
80
    final RubikActivity ract = (RubikActivity)getContext();
81

    
82
    for(String category: categories)
83
      {
84
      Button button = new Button(act);
85
      button.setLayoutParams(bParams);
86
      button.setText(category);
87

    
88
      button.setOnClickListener( new View.OnClickListener()
89
        {
90
        @Override
91
        public void onClick(View view)
92
          {
93
          RubikState.switchState(ract,RubikState.PATT);
94
          mDialog.dismiss();
95
          }
96
        });
97

    
98
      mLayout.addView(button);
99
      }
100
    }
101
  }
(7-7/12)