Project

General

Profile

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

magiccube / src / main / java / org / distorted / dialog / RubikDialogPatternView.java @ 176308f8

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

    
33
///////////////////////////////////////////////////////////////////////////////////////////////////
34

    
35
public class RubikDialogPatternView extends FrameLayout
36
  {
37
  LinearLayout mLayout;
38

    
39
///////////////////////////////////////////////////////////////////////////////////////////////////
40

    
41
  public RubikDialogPatternView(Context context, AttributeSet attrs, int defStyle)
42
    {
43
    super(context, attrs, defStyle);
44
    }
45

    
46
///////////////////////////////////////////////////////////////////////////////////////////////////
47

    
48
  public RubikDialogPatternView(Context context, AttributeSet attrs)
49
    {
50
    super(context, attrs);
51
    }
52

    
53
///////////////////////////////////////////////////////////////////////////////////////////////////
54

    
55
  public RubikDialogPatternView(FragmentActivity act, String[] categories)
56
    {
57
    super(act);
58

    
59
    View tab = inflate( act, R.layout.dialog_tab, null);
60
    mLayout = tab.findViewById(R.id.tabLayout);
61
    createSection(act,categories);
62

    
63
    addView(tab);
64
    }
65

    
66
///////////////////////////////////////////////////////////////////////////////////////////////////
67

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

    
77
    for(int i=0; i<len; i++)
78
      {
79
      final int fi = i;
80
      Button button = new Button(act);
81
      button.setLayoutParams(bParams);
82
      button.setText(categories[i]);
83

    
84
      button.setOnClickListener( new View.OnClickListener()
85
        {
86
        @Override
87
        public void onClick(View view)
88
          {
89
          android.util.Log.e("view", "category "+categories[fi]+" clicked");
90
          }
91
        });
92

    
93
      mLayout.addView(button);
94
      }
95
    }
96
  }
(7-7/12)