Project

General

Profile

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

magiccube / src / main / java / org / distorted / dialog / RubikDialogPatternView.java @ 4f470e00

1 d18993ac Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
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 176308f8 Leszek Koltunski
import android.util.AttributeSet;
25 d18993ac Leszek Koltunski
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 4f470e00 Leszek Koltunski
import org.distorted.magic.RubikActivity;
33
import org.distorted.uistate.RubikState;
34 d18993ac Leszek Koltunski
35
///////////////////////////////////////////////////////////////////////////////////////////////////
36
37
public class RubikDialogPatternView extends FrameLayout
38
  {
39 4f470e00 Leszek Koltunski
  private LinearLayout mLayout;
40
  private RubikDialogPattern mDialog;
41 d18993ac Leszek Koltunski
42
///////////////////////////////////////////////////////////////////////////////////////////////////
43
44 176308f8 Leszek Koltunski
  public RubikDialogPatternView(Context context, AttributeSet attrs, int defStyle)
45 d18993ac Leszek Koltunski
    {
46 176308f8 Leszek Koltunski
    super(context, attrs, defStyle);
47
    }
48
49
///////////////////////////////////////////////////////////////////////////////////////////////////
50
51
  public RubikDialogPatternView(Context context, AttributeSet attrs)
52
    {
53
    super(context, attrs);
54
    }
55 d18993ac Leszek Koltunski
56 176308f8 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
57
58 4f470e00 Leszek Koltunski
  public RubikDialogPatternView(FragmentActivity act, RubikDialogPattern dialog, String[] categories)
59 176308f8 Leszek Koltunski
    {
60
    super(act);
61
62 4f470e00 Leszek Koltunski
    mDialog = dialog;
63 176308f8 Leszek Koltunski
    View tab = inflate( act, R.layout.dialog_tab, null);
64 d18993ac Leszek Koltunski
    mLayout = tab.findViewById(R.id.tabLayout);
65 176308f8 Leszek Koltunski
    createSection(act,categories);
66
67 d18993ac Leszek Koltunski
    addView(tab);
68
    }
69
70
///////////////////////////////////////////////////////////////////////////////////////////////////
71
72 4f470e00 Leszek Koltunski
  private void createSection(final FragmentActivity act, final String[] categories)
73 d18993ac Leszek Koltunski
    {
74
    DisplayMetrics metrics = act.getResources().getDisplayMetrics();
75
    final float scale = metrics.density;
76
    int len = categories.length;
77
    int margin = (int)(3*scale + 0.5f);
78
    LinearLayout.LayoutParams bParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.WRAP_CONTENT);
79
    bParams.setMargins(margin, margin, margin, margin);
80
81 4f470e00 Leszek Koltunski
    final RubikActivity ract = (RubikActivity)getContext();
82
83 d18993ac Leszek Koltunski
    for(int i=0; i<len; i++)
84
      {
85
      final int fi = i;
86
      Button button = new Button(act);
87
      button.setLayoutParams(bParams);
88
      button.setText(categories[i]);
89
90
      button.setOnClickListener( new View.OnClickListener()
91
        {
92
        @Override
93
        public void onClick(View view)
94
          {
95 4f470e00 Leszek Koltunski
          RubikState.switchState(ract,RubikState.PATT);
96
          mDialog.dismiss();
97 d18993ac Leszek Koltunski
          }
98
        });
99
100 176308f8 Leszek Koltunski
      mLayout.addView(button);
101
      }
102 d18993ac Leszek Koltunski
    }
103
  }