Project

General

Profile

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

magiccube / src / main / java / org / distorted / bandaged / BandagedObjectView.java @ 5ba1740c

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
22
///////////////////////////////////////////////////////////////////////////////////////////////////
23
24 7ee8337b leszek
public class BandagedObjectView
25 e48ad1af Leszek Koltunski
{
26 35e32f0c Leszek Koltunski
  private static final float MARGIN    = 0.015f;
27
  private static final float TEXT_SIZE = 0.032f;
28 66cbab36 Leszek Koltunski
29 e48ad1af Leszek Koltunski
  private final LinearLayout mPane;
30
  private final String mName;
31
32 7cb8d4b0 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
33
34 7ee8337b leszek
  public BandagedObjectView(final BandagedActivity act, String name, boolean leftmost)
35 e48ad1af Leszek Koltunski
    {
36
    mName = name;
37
    LayoutInflater inflater = act.getLayoutInflater();
38
    mPane = (LinearLayout) inflater.inflate(R.layout.bandaged_pane, null);
39
40 35e32f0c Leszek Koltunski
    int height   = act.getScreenHeightInPixels();
41
    int textSize = (int)(height*TEXT_SIZE);
42 e48ad1af Leszek Koltunski
43 2ceeb6b5 Leszek Koltunski
    LinearLayout.LayoutParams params = createPaneParams(height,leftmost,act.isRTL());
44 e48ad1af Leszek Koltunski
    mPane.setLayoutParams(params);
45
46
    LinearLayout bottom = mPane.findViewById(R.id.bandagedCreatorObjectLayout);
47
48 c41c5ae3 Leszek Koltunski
    TransparentButton plaButton = new TransparentButton(act, R.string.play, textSize);
49 83e021c5 Leszek Koltunski
    plaButton.setSingleLine();
50 e48ad1af Leszek Koltunski
51 83e021c5 Leszek Koltunski
    final int icon = R.drawable.ui_trash;
52 c41c5ae3 Leszek Koltunski
    LinearLayout.LayoutParams paramsB = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,3.0f);
53 464ade4a leszek
    TransparentImageButton delButton = new TransparentImageButton(act,icon,paramsB);
54 83e021c5 Leszek Koltunski
55 e48ad1af Leszek Koltunski
    bottom.addView(plaButton);
56
    bottom.addView(delButton);
57 7cb8d4b0 Leszek Koltunski
58
    plaButton.setOnClickListener( new View.OnClickListener()
59
      {
60
      @Override
61
      public void onClick(View v)
62
        {
63 d3d639b1 Leszek Koltunski
        act.playObject(mName);
64 7cb8d4b0 Leszek Koltunski
        }
65
      });
66
67
    delButton.setOnClickListener( new View.OnClickListener()
68
      {
69
      @Override
70
      public void onClick(View v)
71
        {
72 6647b730 Leszek Koltunski
        Bundle bundle = new Bundle();
73 c02fa107 Leszek Koltunski
        bundle.putString("argument", mName );
74 6647b730 Leszek Koltunski
        RubikDialogBandagedDelete dialog = new RubikDialogBandagedDelete();
75
        dialog.setArguments(bundle);
76
        dialog.show( act.getSupportFragmentManager(), RubikDialogBandagedDelete.getDialogTag() );
77 7cb8d4b0 Leszek Koltunski
        }
78
      });
79 e48ad1af Leszek Koltunski
    }
80
81 35e32f0c Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
82
83 2ceeb6b5 Leszek Koltunski
  static LinearLayout.LayoutParams createPaneParams(int height, boolean leftmost, boolean rtl)
84 35e32f0c Leszek Koltunski
    {
85
    int margin = (int)(height*MARGIN);
86 7ee8337b leszek
    int length = (int)(height*BandagedActivity.RATIO_SCROLL*0.65f);
87 35e32f0c Leszek Koltunski
88
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams( length, LinearLayout.LayoutParams.MATCH_PARENT);
89
    params.bottomMargin = margin;
90
    params.topMargin    = margin;
91 2ceeb6b5 Leszek Koltunski
92
    if( !rtl )
93
      {
94
      params.leftMargin   = leftmost ? margin : 0;
95
      params.rightMargin  = margin;
96
      }
97
    else
98
      {
99
      params.rightMargin  = leftmost ? margin : 0;
100
      params.leftMargin   = margin;
101
      }
102 35e32f0c Leszek Koltunski
103
    return params;
104
    }
105
106 e48ad1af Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
107
108
  public LinearLayout getPane()
109
    {
110
    return mPane;
111
    }
112 d3d639b1 Leszek Koltunski
113
///////////////////////////////////////////////////////////////////////////////////////////////////
114
115 66cbab36 Leszek Koltunski
  public String getName()
116 d3d639b1 Leszek Koltunski
    {
117 66cbab36 Leszek Koltunski
    return mName;
118 d3d639b1 Leszek Koltunski
    }
119 e48ad1af Leszek Koltunski
}