Project

General

Profile

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

magiccube / src / main / java / org / distorted / bandaged / BandagedCreatorScreen.java @ e48ad1af

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2022 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6
// Magic Cube is free software: you can redistribute it and/or modify                            //
7
// it under the terms of the GNU General Public License as published by                          //
8
// the Free Software Foundation, either version 2 of the License, or                             //
9
// (at your option) any later version.                                                           //
10
//                                                                                               //
11
// Magic Cube is distributed in the hope that it will be useful,                                 //
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
14
// GNU General Public License for more details.                                                  //
15
//                                                                                               //
16
// You should have received a copy of the GNU General Public License                             //
17
// along with Magic Cube.  If not, see <http://www.gnu.org/licenses/>.                           //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19

    
20
package org.distorted.bandaged;
21

    
22
import android.view.View;
23
import android.widget.LinearLayout;
24

    
25
import org.distorted.helpers.TransparentImageButton;
26
import org.distorted.main.R;
27
import org.distorted.main.RubikActivity;
28

    
29
///////////////////////////////////////////////////////////////////////////////////////////////////
30

    
31
public class BandagedCreatorScreen
32
{
33
  private TransparentImageButton mBackButton, mResetButton, mDoneButton;
34
  private LinearLayout mObjectView;
35
  private int mNumObjects;
36

    
37
///////////////////////////////////////////////////////////////////////////////////////////////////
38

    
39
  public BandagedCreatorScreen()
40
    {
41
    mNumObjects = 0;
42
    }
43

    
44
///////////////////////////////////////////////////////////////////////////////////////////////////
45

    
46
  private void setupBackButton(final BandagedCreatorActivity act)
47
    {
48
    int icon = RubikActivity.getDrawable(R.drawable.ui_small_smallback,R.drawable.ui_medium_smallback, R.drawable.ui_big_smallback, R.drawable.ui_huge_smallback);
49
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT);
50
    mBackButton = new TransparentImageButton(act, icon, TransparentImageButton.GRAVITY_MIDDLE, params);
51

    
52
    mBackButton.setOnClickListener( new View.OnClickListener()
53
      {
54
      @Override
55
      public void onClick(View v)
56
        {
57
        act.finish();
58
        }
59
      });
60
    }
61

    
62
///////////////////////////////////////////////////////////////////////////////////////////////////
63

    
64
  private void setupDoneButton(final BandagedCreatorActivity act)
65
    {
66
    int icon = RubikActivity.getDrawable(R.drawable.ui_small_done,R.drawable.ui_medium_done, R.drawable.ui_big_done, R.drawable.ui_huge_done);
67
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT);
68
    mDoneButton = new TransparentImageButton(act, icon, TransparentImageButton.GRAVITY_MIDDLE, params);
69

    
70
    mDoneButton.setOnClickListener( new View.OnClickListener()
71
      {
72
      @Override
73
      public void onClick(View v)
74
        {
75
        BandagedCreatorRenderer renderer = act.getRenderer();
76
        if( !renderer.isBusy() ) renderer.displaySavingDialog();
77
        }
78
      });
79
    }
80

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

    
83
  private void setupResetButton(final BandagedCreatorActivity act)
84
    {
85
    int icon = RubikActivity.getDrawable(R.drawable.ui_small_reset,R.drawable.ui_medium_reset, R.drawable.ui_big_reset, R.drawable.ui_huge_reset);
86
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT);
87
    mResetButton = new TransparentImageButton(act, icon, TransparentImageButton.GRAVITY_MIDDLE, params);
88

    
89
    mResetButton.setOnClickListener( new View.OnClickListener()
90
      {
91
      @Override
92
      public void onClick(View v)
93
        {
94
        BandagedCreatorRenderer renderer = act.getRenderer();
95
        if( !renderer.isBusy() ) renderer.setupReset();
96
        }
97
      });
98
    }
99

    
100
///////////////////////////////////////////////////////////////////////////////////////////////////
101

    
102
  void onAttachedToWindow(final BandagedCreatorActivity act)
103
    {
104
    mObjectView = act.findViewById(R.id.bandagedCreatorView);
105

    
106
    int width = act.getScreenWidthInPixels();
107

    
108
    LinearLayout.LayoutParams paramsL = new LinearLayout.LayoutParams(width/4, LinearLayout.LayoutParams.MATCH_PARENT);
109
    LinearLayout.LayoutParams paramsM = new LinearLayout.LayoutParams(width/2, LinearLayout.LayoutParams.MATCH_PARENT);
110
    LinearLayout.LayoutParams paramsR = new LinearLayout.LayoutParams(width/4, LinearLayout.LayoutParams.MATCH_PARENT);
111

    
112
    LinearLayout layoutLeft = new LinearLayout(act);
113
    layoutLeft.setLayoutParams(paramsL);
114
    LinearLayout layoutMid  = new LinearLayout(act);
115
    layoutMid.setLayoutParams(paramsM);
116
    LinearLayout layoutRight= new LinearLayout(act);
117
    layoutRight.setLayoutParams(paramsR);
118

    
119
    setupBackButton(act);
120
    layoutRight.addView(mBackButton);
121
    setupDoneButton(act);
122
    layoutMid.addView(mDoneButton);
123
    setupResetButton(act);
124
    layoutLeft.addView(mResetButton);
125

    
126
    LinearLayout layout = act.findViewById(R.id.lowerBar);
127
    layout.removeAllViews();
128
    layout.addView(layoutLeft);
129
    layout.addView(layoutMid);
130
    layout.addView(layoutRight);
131
    }
132

    
133
///////////////////////////////////////////////////////////////////////////////////////////////////
134

    
135
  void addObject(BandagedCreatorActivity act, String name)
136
    {
137
    BandagedCreatorObjectView view = new BandagedCreatorObjectView(act,name,mNumObjects==0);
138
    LinearLayout pane = view.getPane();
139
    mObjectView.addView(pane);
140
    mNumObjects++;
141
    }
142
}
(4-4/12)