Project

General

Profile

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

magiccube / src / main / java / org / distorted / bandaged / BandagedCreatorObjectView.java @ f404152d

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2022 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6
// 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
///////////////////////////////////////////////////////////////////////////////////////////////////
9

    
10
package org.distorted.bandaged;
11

    
12
import android.os.Bundle;
13
import android.view.LayoutInflater;
14
import android.view.View;
15
import android.widget.LinearLayout;
16

    
17
import org.distorted.dialogs.RubikDialogBandagedDelete;
18
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
  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

    
31
  private final LinearLayout mPane;
32
  private final String mName;
33

    
34
///////////////////////////////////////////////////////////////////////////////////////////////////
35

    
36
  public BandagedCreatorObjectView(final BandagedCreatorActivity act, String name, boolean leftmost)
37
    {
38
    mName = name;
39
    LayoutInflater inflater = act.getLayoutInflater();
40
    mPane = (LinearLayout) inflater.inflate(R.layout.bandaged_pane, null);
41

    
42
    int height   = act.getScreenHeightInPixels();
43
    int textSize = (int)(height*TEXT_SIZE);
44

    
45
    LinearLayout.LayoutParams params = createPaneParams(height,leftmost,act.isRTL());
46
    mPane.setLayoutParams(params);
47

    
48
    LinearLayout bottom = mPane.findViewById(R.id.bandagedCreatorObjectLayout);
49

    
50
    TransparentButton plaButton = new TransparentButton(act, R.string.play, textSize);
51
    plaButton.setSingleLine();
52

    
53
    final int icon = R.drawable.ui_trash;
54
    LinearLayout.LayoutParams paramsB = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,3.0f);
55
    TransparentImageButton delButton = new TransparentImageButton(act, icon, TransparentImageButton.GRAVITY_MIDDLE, paramsB);
56

    
57
    int iconHeight = (int)(RATIO_ICON*(BandagedCreatorActivity.RATIO_SCROLL-2*RubikActivity.PADDING)*height);
58
    delButton.setIconSize(iconHeight);
59

    
60
    bottom.addView(plaButton);
61
    bottom.addView(delButton);
62

    
63
    plaButton.setOnClickListener( new View.OnClickListener()
64
      {
65
      @Override
66
      public void onClick(View v)
67
        {
68
        act.playObject(mName);
69
        }
70
      });
71

    
72
    delButton.setOnClickListener( new View.OnClickListener()
73
      {
74
      @Override
75
      public void onClick(View v)
76
        {
77
        Bundle bundle = new Bundle();
78
        bundle.putString("argument", mName );
79
        RubikDialogBandagedDelete dialog = new RubikDialogBandagedDelete();
80
        dialog.setArguments(bundle);
81
        dialog.show( act.getSupportFragmentManager(), RubikDialogBandagedDelete.getDialogTag() );
82
        }
83
      });
84
    }
85

    
86
///////////////////////////////////////////////////////////////////////////////////////////////////
87

    
88
  static LinearLayout.LayoutParams createPaneParams(int height, boolean leftmost, boolean rtl)
89
    {
90
    int margin = (int)(height*MARGIN);
91
    int length = (int)(height*BandagedCreatorActivity.RATIO_SCROLL*0.65f);
92

    
93
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams( length, LinearLayout.LayoutParams.MATCH_PARENT);
94
    params.bottomMargin = margin;
95
    params.topMargin    = margin;
96

    
97
    if( !rtl )
98
      {
99
      params.leftMargin   = leftmost ? margin : 0;
100
      params.rightMargin  = margin;
101
      }
102
    else
103
      {
104
      params.rightMargin  = leftmost ? margin : 0;
105
      params.leftMargin   = margin;
106
      }
107

    
108
    return params;
109
    }
110

    
111
///////////////////////////////////////////////////////////////////////////////////////////////////
112

    
113
  public LinearLayout getPane()
114
    {
115
    return mPane;
116
    }
117

    
118
///////////////////////////////////////////////////////////////////////////////////////////////////
119

    
120
  public String getName()
121
    {
122
    return mName;
123
    }
124
}
(2-2/14)