Project

General

Profile

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

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

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

    
22
///////////////////////////////////////////////////////////////////////////////////////////////////
23

    
24
public class BandagedCreatorObjectView
25
{
26
  private static final float MARGIN    = 0.015f;
27
  private static final float TEXT_SIZE = 0.032f;
28
  private static final float RATIO_ICON= 0.15f;
29

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

    
33
///////////////////////////////////////////////////////////////////////////////////////////////////
34

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

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

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

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

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

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

    
56
    bottom.addView(plaButton);
57
    bottom.addView(delButton);
58

    
59
    plaButton.setOnClickListener( new View.OnClickListener()
60
      {
61
      @Override
62
      public void onClick(View v)
63
        {
64
        act.playObject(mName);
65
        }
66
      });
67

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

    
82
///////////////////////////////////////////////////////////////////////////////////////////////////
83

    
84
  static LinearLayout.LayoutParams createPaneParams(int height, boolean leftmost, boolean rtl)
85
    {
86
    int margin = (int)(height*MARGIN);
87
    int length = (int)(height*BandagedCreatorActivity.RATIO_SCROLL*0.65f);
88

    
89
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams( length, LinearLayout.LayoutParams.MATCH_PARENT);
90
    params.bottomMargin = margin;
91
    params.topMargin    = margin;
92

    
93
    if( !rtl )
94
      {
95
      params.leftMargin   = leftmost ? margin : 0;
96
      params.rightMargin  = margin;
97
      }
98
    else
99
      {
100
      params.rightMargin  = leftmost ? margin : 0;
101
      params.leftMargin   = margin;
102
      }
103

    
104
    return params;
105
    }
106

    
107
///////////////////////////////////////////////////////////////////////////////////////////////////
108

    
109
  public LinearLayout getPane()
110
    {
111
    return mPane;
112
    }
113

    
114
///////////////////////////////////////////////////////////////////////////////////////////////////
115

    
116
  public String getName()
117
    {
118
    return mName;
119
    }
120
}
(2-2/12)