1
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2
|
// Copyright 2022 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.bandaged;
|
21
|
|
22
|
import android.os.Bundle;
|
23
|
import android.view.LayoutInflater;
|
24
|
import android.view.View;
|
25
|
import android.widget.LinearLayout;
|
26
|
|
27
|
import org.distorted.dialogs.RubikDialogBandagedDelete;
|
28
|
import org.distorted.helpers.TransparentButton;
|
29
|
import org.distorted.helpers.TransparentImageButton;
|
30
|
import org.distorted.main.R;
|
31
|
import org.distorted.main.RubikActivity;
|
32
|
|
33
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
34
|
|
35
|
public class BandagedCreatorObjectView
|
36
|
{
|
37
|
static final float RATIO_PANE = 0.36f;
|
38
|
static final float RATIO_ICON = 0.15f;
|
39
|
|
40
|
private final LinearLayout mPane;
|
41
|
private final String mName;
|
42
|
|
43
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
44
|
|
45
|
public BandagedCreatorObjectView(final BandagedCreatorActivity act, String name, boolean leftmost)
|
46
|
{
|
47
|
mName = name;
|
48
|
LayoutInflater inflater = act.getLayoutInflater();
|
49
|
mPane = (LinearLayout) inflater.inflate(R.layout.bandaged_pane, null);
|
50
|
|
51
|
int width = act.getScreenWidthInPixels();
|
52
|
int margin = (int)(width*RubikActivity.LARGE_MARGIN);
|
53
|
int textSize = (int)(width*RubikActivity.BUTTON_TEXT_SIZE);
|
54
|
|
55
|
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams( (int)(width*RATIO_PANE), LinearLayout.LayoutParams.MATCH_PARENT);
|
56
|
params.bottomMargin = margin;
|
57
|
params.topMargin = margin;
|
58
|
params.leftMargin = leftmost ? margin : 0;
|
59
|
params.rightMargin = margin;
|
60
|
|
61
|
mPane.setLayoutParams(params);
|
62
|
|
63
|
LinearLayout bottom = mPane.findViewById(R.id.bandagedCreatorObjectLayout);
|
64
|
|
65
|
TransparentButton plaButton = new TransparentButton(act, R.string.play, textSize);
|
66
|
plaButton.setSingleLine();
|
67
|
|
68
|
final int icon = R.drawable.ui_trash;
|
69
|
LinearLayout.LayoutParams paramsB = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,3.0f);
|
70
|
TransparentImageButton delButton = new TransparentImageButton(act, icon, TransparentImageButton.GRAVITY_MIDDLE, paramsB);
|
71
|
|
72
|
int height = act.getScreenHeightInPixels();
|
73
|
int iconHeight = (int)(RATIO_ICON*(BandagedCreatorActivity.RATIO_SCROLL-2*RubikActivity.PADDING)*height);
|
74
|
delButton.setIconSize(iconHeight);
|
75
|
|
76
|
bottom.addView(plaButton);
|
77
|
bottom.addView(delButton);
|
78
|
|
79
|
plaButton.setOnClickListener( new View.OnClickListener()
|
80
|
{
|
81
|
@Override
|
82
|
public void onClick(View v)
|
83
|
{
|
84
|
act.playObject(mName);
|
85
|
}
|
86
|
});
|
87
|
|
88
|
delButton.setOnClickListener( new View.OnClickListener()
|
89
|
{
|
90
|
@Override
|
91
|
public void onClick(View v)
|
92
|
{
|
93
|
Bundle bundle = new Bundle();
|
94
|
bundle.putString("name", mName );
|
95
|
RubikDialogBandagedDelete dialog = new RubikDialogBandagedDelete();
|
96
|
dialog.setArguments(bundle);
|
97
|
dialog.show( act.getSupportFragmentManager(), RubikDialogBandagedDelete.getDialogTag() );
|
98
|
}
|
99
|
});
|
100
|
}
|
101
|
|
102
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
103
|
|
104
|
public LinearLayout getPane()
|
105
|
{
|
106
|
return mPane;
|
107
|
}
|
108
|
|
109
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
110
|
|
111
|
public String getName()
|
112
|
{
|
113
|
return mName;
|
114
|
}
|
115
|
}
|