Project

General

Profile

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

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

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,paramsB);
56

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

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

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

    
83
///////////////////////////////////////////////////////////////////////////////////////////////////
84

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

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

    
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

    
105
    return params;
106
    }
107

    
108
///////////////////////////////////////////////////////////////////////////////////////////////////
109

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

    
115
///////////////////////////////////////////////////////////////////////////////////////////////////
116

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