Project

General

Profile

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

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

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.DisplayMetrics;
25
import android.view.View;
26
import android.widget.Button;
27
import android.widget.FrameLayout;
28
import android.widget.LinearLayout;
29

    
30
import org.distorted.magic.R;
31

    
32
///////////////////////////////////////////////////////////////////////////////////////////////////
33

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

    
38
///////////////////////////////////////////////////////////////////////////////////////////////////
39

    
40
  public RubikDialogPatternView(Context context)
41
    {
42
    super(context);
43

    
44
    View tab = inflate( context, R.layout.dialog_tab, null);
45
    mLayout = tab.findViewById(R.id.tabLayout);
46
    addView(tab);
47
    }
48

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

    
51
  LinearLayout createSection(FragmentActivity act, final String[] categories)
52
    {
53
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
54
    LinearLayout layout = new LinearLayout(act);
55
    layout.setLayoutParams(params);
56
    layout.setOrientation(LinearLayout.VERTICAL);
57

    
58
    DisplayMetrics metrics = act.getResources().getDisplayMetrics();
59
    final float scale = metrics.density;
60
    int len = categories.length;
61
    int margin = (int)(3*scale + 0.5f);
62
    LinearLayout.LayoutParams bParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.WRAP_CONTENT);
63
    bParams.setMargins(margin, margin, margin, margin);
64

    
65
    for(int i=0; i<len; i++)
66
      {
67
      android.util.Log.e("view", "adding button "+i +" to layout!");
68

    
69

    
70
      final int fi = i;
71
      Button button = new Button(act);
72
      button.setLayoutParams(bParams);
73
      button.setText(categories[i]);
74

    
75
      button.setOnClickListener( new View.OnClickListener()
76
        {
77
        @Override
78
        public void onClick(View view)
79
          {
80
          android.util.Log.e("view", "category "+categories[fi]+" clicked");
81
          }
82
        });
83
      }
84

    
85
    return layout;
86
    }
87

    
88
///////////////////////////////////////////////////////////////////////////////////////////////////
89
// needs to run on UI thread
90

    
91
  void addSection(LinearLayout section)
92
    {
93
    android.util.Log.e("view", "adding section to tab!");
94

    
95
    mLayout.addView(section);
96
    }
97
  }
(7-7/12)