Project

General

Profile

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

magiccube / src / main / java / org / distorted / bandaged / BandagedCreatorObjectView.java @ 70688a23

1 e48ad1af Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2022 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6 44fec653 Leszek Koltunski
// Magic Cube is proprietary software licensed under an EULA which you should have received      //
7
// along with the code. If not, check https://distorted.org/magic/License-Magic-Cube.html        //
8 e48ad1af Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
9
10
package org.distorted.bandaged;
11
12 6647b730 Leszek Koltunski
import android.os.Bundle;
13 e48ad1af Leszek Koltunski
import android.view.LayoutInflater;
14 7cb8d4b0 Leszek Koltunski
import android.view.View;
15 e48ad1af Leszek Koltunski
import android.widget.LinearLayout;
16
17 6647b730 Leszek Koltunski
import org.distorted.dialogs.RubikDialogBandagedDelete;
18 e48ad1af Leszek Koltunski
import org.distorted.helpers.TransparentButton;
19
import org.distorted.helpers.TransparentImageButton;
20
import org.distorted.main.R;
21
import org.distorted.main.RubikActivity;
22
23
///////////////////////////////////////////////////////////////////////////////////////////////////
24
25
public class BandagedCreatorObjectView
26
{
27 35e32f0c Leszek Koltunski
  private static final float MARGIN    = 0.015f;
28
  private static final float TEXT_SIZE = 0.032f;
29
  private static final float RATIO_ICON= 0.15f;
30 66cbab36 Leszek Koltunski
31 e48ad1af Leszek Koltunski
  private final LinearLayout mPane;
32
  private final String mName;
33
34 7cb8d4b0 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
35
36 d3d639b1 Leszek Koltunski
  public BandagedCreatorObjectView(final BandagedCreatorActivity act, String name, boolean leftmost)
37 e48ad1af Leszek Koltunski
    {
38
    mName = name;
39
    LayoutInflater inflater = act.getLayoutInflater();
40
    mPane = (LinearLayout) inflater.inflate(R.layout.bandaged_pane, null);
41
42 35e32f0c Leszek Koltunski
    int height   = act.getScreenHeightInPixels();
43
    int textSize = (int)(height*TEXT_SIZE);
44 e48ad1af Leszek Koltunski
45 2ceeb6b5 Leszek Koltunski
    LinearLayout.LayoutParams params = createPaneParams(height,leftmost,act.isRTL());
46 e48ad1af Leszek Koltunski
    mPane.setLayoutParams(params);
47
48
    LinearLayout bottom = mPane.findViewById(R.id.bandagedCreatorObjectLayout);
49
50 c41c5ae3 Leszek Koltunski
    TransparentButton plaButton = new TransparentButton(act, R.string.play, textSize);
51 83e021c5 Leszek Koltunski
    plaButton.setSingleLine();
52 e48ad1af Leszek Koltunski
53 83e021c5 Leszek Koltunski
    final int icon = R.drawable.ui_trash;
54 c41c5ae3 Leszek Koltunski
    LinearLayout.LayoutParams paramsB = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,3.0f);
55 464ade4a leszek
    TransparentImageButton delButton = new TransparentImageButton(act,icon,paramsB);
56 83e021c5 Leszek Koltunski
57 e48ad1af Leszek Koltunski
    bottom.addView(plaButton);
58
    bottom.addView(delButton);
59 7cb8d4b0 Leszek Koltunski
60
    plaButton.setOnClickListener( new View.OnClickListener()
61
      {
62
      @Override
63
      public void onClick(View v)
64
        {
65 d3d639b1 Leszek Koltunski
        act.playObject(mName);
66 7cb8d4b0 Leszek Koltunski
        }
67
      });
68
69
    delButton.setOnClickListener( new View.OnClickListener()
70
      {
71
      @Override
72
      public void onClick(View v)
73
        {
74 6647b730 Leszek Koltunski
        Bundle bundle = new Bundle();
75 c02fa107 Leszek Koltunski
        bundle.putString("argument", mName );
76 6647b730 Leszek Koltunski
        RubikDialogBandagedDelete dialog = new RubikDialogBandagedDelete();
77
        dialog.setArguments(bundle);
78
        dialog.show( act.getSupportFragmentManager(), RubikDialogBandagedDelete.getDialogTag() );
79 7cb8d4b0 Leszek Koltunski
        }
80
      });
81 e48ad1af Leszek Koltunski
    }
82
83 35e32f0c Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
84
85 2ceeb6b5 Leszek Koltunski
  static LinearLayout.LayoutParams createPaneParams(int height, boolean leftmost, boolean rtl)
86 35e32f0c Leszek Koltunski
    {
87
    int margin = (int)(height*MARGIN);
88 788701a7 Leszek Koltunski
    int length = (int)(height*BandagedCreatorActivity.RATIO_SCROLL*0.65f);
89 35e32f0c Leszek Koltunski
90
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams( length, LinearLayout.LayoutParams.MATCH_PARENT);
91
    params.bottomMargin = margin;
92
    params.topMargin    = margin;
93 2ceeb6b5 Leszek Koltunski
94
    if( !rtl )
95
      {
96
      params.leftMargin   = leftmost ? margin : 0;
97
      params.rightMargin  = margin;
98
      }
99
    else
100
      {
101
      params.rightMargin  = leftmost ? margin : 0;
102
      params.leftMargin   = margin;
103
      }
104 35e32f0c Leszek Koltunski
105
    return params;
106
    }
107
108 e48ad1af Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
109
110
  public LinearLayout getPane()
111
    {
112
    return mPane;
113
    }
114 d3d639b1 Leszek Koltunski
115
///////////////////////////////////////////////////////////////////////////////////////////////////
116
117 66cbab36 Leszek Koltunski
  public String getName()
118 d3d639b1 Leszek Koltunski
    {
119 66cbab36 Leszek Koltunski
    return mName;
120 d3d639b1 Leszek Koltunski
    }
121 e48ad1af Leszek Koltunski
}