Project

General

Profile

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

magiccube / src / main / java / org / distorted / bandaged / BandagedCreatorObjectView.java @ 7fe59aa5

1 e48ad1af Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
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 6647b730 Leszek Koltunski
import android.os.Bundle;
23 e48ad1af Leszek Koltunski
import android.view.LayoutInflater;
24 7cb8d4b0 Leszek Koltunski
import android.view.View;
25 e48ad1af Leszek Koltunski
import android.widget.LinearLayout;
26
27 6647b730 Leszek Koltunski
import org.distorted.dialogs.RubikDialogBandagedDelete;
28 e48ad1af Leszek Koltunski
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 66cbab36 Leszek Koltunski
  static final float RATIO_PANE = 0.36f;
38
  static final float RATIO_ICON = 0.15f;
39
40 e48ad1af Leszek Koltunski
  private final LinearLayout mPane;
41
  private final String mName;
42
43 7cb8d4b0 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
44
45 d3d639b1 Leszek Koltunski
  public BandagedCreatorObjectView(final BandagedCreatorActivity act, String name, boolean leftmost)
46 e48ad1af Leszek Koltunski
    {
47
    mName = name;
48
    LayoutInflater inflater = act.getLayoutInflater();
49
    mPane = (LinearLayout) inflater.inflate(R.layout.bandaged_pane, null);
50
51 c41c5ae3 Leszek Koltunski
    int width    = act.getScreenWidthInPixels();
52 66cbab36 Leszek Koltunski
    int margin   = (int)(width*RubikActivity.LARGE_MARGIN);
53 c41c5ae3 Leszek Koltunski
    int textSize = (int)(width*RubikActivity.BUTTON_TEXT_SIZE);
54 e48ad1af Leszek Koltunski
55 66cbab36 Leszek Koltunski
    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 e48ad1af Leszek Koltunski
61
    mPane.setLayoutParams(params);
62
63
    LinearLayout bottom = mPane.findViewById(R.id.bandagedCreatorObjectLayout);
64
65 c41c5ae3 Leszek Koltunski
    TransparentButton plaButton = new TransparentButton(act, R.string.play, textSize);
66 83e021c5 Leszek Koltunski
    plaButton.setSingleLine();
67 e48ad1af Leszek Koltunski
68 83e021c5 Leszek Koltunski
    final int icon = R.drawable.ui_trash;
69 c41c5ae3 Leszek Koltunski
    LinearLayout.LayoutParams paramsB = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,3.0f);
70 e48ad1af Leszek Koltunski
    TransparentImageButton delButton = new TransparentImageButton(act, icon, TransparentImageButton.GRAVITY_MIDDLE, paramsB);
71
72 83e021c5 Leszek Koltunski
    int height = act.getScreenHeightInPixels();
73 66cbab36 Leszek Koltunski
    int iconHeight = (int)(RATIO_ICON*(BandagedCreatorActivity.RATIO_SCROLL-2*RubikActivity.PADDING)*height);
74 83e021c5 Leszek Koltunski
    delButton.setIconSize(iconHeight);
75
76 e48ad1af Leszek Koltunski
    bottom.addView(plaButton);
77
    bottom.addView(delButton);
78 7cb8d4b0 Leszek Koltunski
79
    plaButton.setOnClickListener( new View.OnClickListener()
80
      {
81
      @Override
82
      public void onClick(View v)
83
        {
84 d3d639b1 Leszek Koltunski
        act.playObject(mName);
85 7cb8d4b0 Leszek Koltunski
        }
86
      });
87
88
    delButton.setOnClickListener( new View.OnClickListener()
89
      {
90
      @Override
91
      public void onClick(View v)
92
        {
93 6647b730 Leszek Koltunski
        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 7cb8d4b0 Leszek Koltunski
        }
99
      });
100 e48ad1af Leszek Koltunski
    }
101
102
///////////////////////////////////////////////////////////////////////////////////////////////////
103
104
  public LinearLayout getPane()
105
    {
106
    return mPane;
107
    }
108 d3d639b1 Leszek Koltunski
109
///////////////////////////////////////////////////////////////////////////////////////////////////
110
111 66cbab36 Leszek Koltunski
  public String getName()
112 d3d639b1 Leszek Koltunski
    {
113 66cbab36 Leszek Koltunski
    return mName;
114 d3d639b1 Leszek Koltunski
    }
115 e48ad1af Leszek Koltunski
}