Project

General

Profile

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

magiccube / src / main / java / org / distorted / bandaged / BandagedCreatorObjectView.java @ 13a3dfa9

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.view.LayoutInflater;
23
import android.view.View;
24
import android.widget.LinearLayout;
25

    
26
import org.distorted.helpers.TransparentButton;
27
import org.distorted.helpers.TransparentImageButton;
28
import org.distorted.main.R;
29
import org.distorted.main.RubikActivity;
30

    
31
///////////////////////////////////////////////////////////////////////////////////////////////////
32

    
33
public class BandagedCreatorObjectView
34
{
35
  private final LinearLayout mPane;
36
  private final String mName;
37

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

    
40
  public BandagedCreatorObjectView(final BandagedCreatorActivity act, String name, boolean leftmost)
41
    {
42
    mName = name;
43
    LayoutInflater inflater = act.getLayoutInflater();
44
    mPane = (LinearLayout) inflater.inflate(R.layout.bandaged_pane, null);
45

    
46
    int width    = act.getScreenWidthInPixels();
47
    int lMargin  = (int)(width*RubikActivity.LARGE_MARGIN);
48
    int textSize = (int)(width*RubikActivity.BUTTON_TEXT_SIZE);
49

    
50
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams( (int)(width*0.36f), LinearLayout.LayoutParams.MATCH_PARENT);
51
    params.bottomMargin = lMargin;
52
    params.topMargin    = lMargin;
53
    params.leftMargin   = leftmost ? lMargin : 0;
54
    params.rightMargin  = lMargin;
55

    
56
    mPane.setLayoutParams(params);
57

    
58
    LinearLayout bottom = mPane.findViewById(R.id.bandagedCreatorObjectLayout);
59

    
60
    TransparentButton plaButton = new TransparentButton(act, R.string.play, textSize);
61
    plaButton.setSingleLine();
62

    
63
    final int icon = R.drawable.ui_trash;
64
    LinearLayout.LayoutParams paramsB = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,3.0f);
65
    TransparentImageButton delButton = new TransparentImageButton(act, icon, TransparentImageButton.GRAVITY_MIDDLE, paramsB);
66

    
67
    int height = act.getScreenHeightInPixels();
68
    int iconHeight = (int)(0.15f*(BandagedCreatorActivity.RATIO_SCROLL-2*RubikActivity.PADDING)*height);
69
    delButton.setIconSize(iconHeight);
70

    
71
    bottom.addView(plaButton);
72
    bottom.addView(delButton);
73

    
74
    plaButton.setOnClickListener( new View.OnClickListener()
75
      {
76
      @Override
77
      public void onClick(View v)
78
        {
79
        act.playObject(mName);
80
        }
81
      });
82

    
83
    delButton.setOnClickListener( new View.OnClickListener()
84
      {
85
      @Override
86
      public void onClick(View v)
87
        {
88
        act.deleteObject(mName);
89
        }
90
      });
91
    }
92

    
93
///////////////////////////////////////////////////////////////////////////////////////////////////
94

    
95
  public LinearLayout getPane()
96
    {
97
    return mPane;
98
    }
99

    
100
///////////////////////////////////////////////////////////////////////////////////////////////////
101

    
102
  public boolean objectNameIs(String name)
103
    {
104
    return mName.equals(name);
105
    }
106
}
(2-2/13)