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 |
|
|
|
33 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
34 |
|
|
|
35 |
|
|
public class RubikDialogPatternView extends FrameLayout
|
36 |
|
|
{
|
37 |
|
|
LinearLayout mLayout;
|
38 |
|
|
|
39 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
40 |
|
|
|
41 |
176308f8
|
Leszek Koltunski
|
public RubikDialogPatternView(Context context, AttributeSet attrs, int defStyle)
|
42 |
d18993ac
|
Leszek Koltunski
|
{
|
43 |
176308f8
|
Leszek Koltunski
|
super(context, attrs, defStyle);
|
44 |
|
|
}
|
45 |
|
|
|
46 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
47 |
|
|
|
48 |
|
|
public RubikDialogPatternView(Context context, AttributeSet attrs)
|
49 |
|
|
{
|
50 |
|
|
super(context, attrs);
|
51 |
|
|
}
|
52 |
d18993ac
|
Leszek Koltunski
|
|
53 |
176308f8
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
54 |
|
|
|
55 |
|
|
public RubikDialogPatternView(FragmentActivity act, String[] categories)
|
56 |
|
|
{
|
57 |
|
|
super(act);
|
58 |
|
|
|
59 |
|
|
View tab = inflate( act, R.layout.dialog_tab, null);
|
60 |
d18993ac
|
Leszek Koltunski
|
mLayout = tab.findViewById(R.id.tabLayout);
|
61 |
176308f8
|
Leszek Koltunski
|
createSection(act,categories);
|
62 |
|
|
|
63 |
d18993ac
|
Leszek Koltunski
|
addView(tab);
|
64 |
|
|
}
|
65 |
|
|
|
66 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
67 |
|
|
|
68 |
176308f8
|
Leszek Koltunski
|
private void createSection(FragmentActivity act, final String[] categories)
|
69 |
d18993ac
|
Leszek Koltunski
|
{
|
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 |
176308f8
|
Leszek Koltunski
|
mLayout.addView(button);
|
94 |
|
|
}
|
95 |
d18993ac
|
Leszek Koltunski
|
}
|
96 |
|
|
}
|