Project

General

Profile

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

magiccube / src / main / java / org / distorted / bandaged / BandagedObjectView.java @ 7ee8337b

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 BandagedObjectView
25
{
26
  private static final float MARGIN    = 0.015f;
27
  private static final float TEXT_SIZE = 0.032f;
28

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

    
32
///////////////////////////////////////////////////////////////////////////////////////////////////
33

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

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

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

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

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

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

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

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

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

    
81
///////////////////////////////////////////////////////////////////////////////////////////////////
82

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

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

    
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

    
103
    return params;
104
    }
105

    
106
///////////////////////////////////////////////////////////////////////////////////////////////////
107

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

    
113
///////////////////////////////////////////////////////////////////////////////////////////////////
114

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