Project

General

Profile

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

magiccube / src / main / java / org / distorted / bandaged / BandagedCreatorScreen.java @ 13a3dfa9

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 java.util.ArrayList;
23

    
24
import android.app.Activity;
25
import android.graphics.Bitmap;
26
import android.view.View;
27
import android.widget.ImageView;
28
import android.widget.LinearLayout;
29

    
30
import org.distorted.helpers.TransparentImageButton;
31
import org.distorted.main.R;
32
import org.distorted.main.RubikActivity;
33

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

    
36
public class BandagedCreatorScreen
37
{
38
  private TransparentImageButton mBackButton, mResetButton, mDoneButton;
39
  private LinearLayout mObjectView;
40
  private int mNumObjects;
41
  private ArrayList<BandagedCreatorObjectView> mViews;
42

    
43
///////////////////////////////////////////////////////////////////////////////////////////////////
44

    
45
  public BandagedCreatorScreen()
46
    {
47
    mNumObjects = 0;
48
    mViews = new ArrayList<>();
49
    }
50

    
51
///////////////////////////////////////////////////////////////////////////////////////////////////
52

    
53
  private void setupBackButton(final BandagedCreatorActivity act)
54
    {
55
    int icon = RubikActivity.getDrawable(R.drawable.ui_small_smallback,R.drawable.ui_medium_smallback, R.drawable.ui_big_smallback, R.drawable.ui_huge_smallback);
56
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT);
57
    mBackButton = new TransparentImageButton(act, icon, TransparentImageButton.GRAVITY_MIDDLE, params);
58

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

    
69
///////////////////////////////////////////////////////////////////////////////////////////////////
70

    
71
  private void setupDoneButton(final BandagedCreatorActivity act)
72
    {
73
    int icon = RubikActivity.getDrawable(R.drawable.ui_small_done,R.drawable.ui_medium_done, R.drawable.ui_big_done, R.drawable.ui_huge_done);
74
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT);
75
    mDoneButton = new TransparentImageButton(act, icon, TransparentImageButton.GRAVITY_MIDDLE, params);
76

    
77
    mDoneButton.setOnClickListener( new View.OnClickListener()
78
      {
79
      @Override
80
      public void onClick(View v)
81
        {
82
        BandagedCreatorRenderer renderer = act.getRenderer();
83
        if( !renderer.isBusy() ) renderer.displaySavingDialog();
84
        }
85
      });
86
    }
87

    
88
///////////////////////////////////////////////////////////////////////////////////////////////////
89

    
90
  private void setupResetButton(final BandagedCreatorActivity act)
91
    {
92
    int icon = RubikActivity.getDrawable(R.drawable.ui_small_reset,R.drawable.ui_medium_reset, R.drawable.ui_big_reset, R.drawable.ui_huge_reset);
93
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT);
94
    mResetButton = new TransparentImageButton(act, icon, TransparentImageButton.GRAVITY_MIDDLE, params);
95

    
96
    mResetButton.setOnClickListener( new View.OnClickListener()
97
      {
98
      @Override
99
      public void onClick(View v)
100
        {
101
        BandagedCreatorRenderer renderer = act.getRenderer();
102
        if( !renderer.isBusy() ) renderer.setupReset();
103
        }
104
      });
105
    }
106

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

    
109
  void onAttachedToWindow(final BandagedCreatorActivity act)
110
    {
111
    mObjectView = act.findViewById(R.id.bandagedCreatorView);
112

    
113
    int width = act.getScreenWidthInPixels();
114

    
115
    LinearLayout.LayoutParams paramsL = new LinearLayout.LayoutParams(width/4, LinearLayout.LayoutParams.MATCH_PARENT);
116
    LinearLayout.LayoutParams paramsM = new LinearLayout.LayoutParams(width/2, LinearLayout.LayoutParams.MATCH_PARENT);
117
    LinearLayout.LayoutParams paramsR = new LinearLayout.LayoutParams(width/4, LinearLayout.LayoutParams.MATCH_PARENT);
118

    
119
    LinearLayout layoutLeft = new LinearLayout(act);
120
    layoutLeft.setLayoutParams(paramsL);
121
    LinearLayout layoutMid  = new LinearLayout(act);
122
    layoutMid.setLayoutParams(paramsM);
123
    LinearLayout layoutRight= new LinearLayout(act);
124
    layoutRight.setLayoutParams(paramsR);
125

    
126
    setupBackButton(act);
127
    layoutRight.addView(mBackButton);
128
    setupDoneButton(act);
129
    layoutMid.addView(mDoneButton);
130
    setupResetButton(act);
131
    layoutLeft.addView(mResetButton);
132

    
133
    LinearLayout layout = act.findViewById(R.id.lowerBar);
134
    layout.removeAllViews();
135
    layout.addView(layoutLeft);
136
    layout.addView(layoutMid);
137
    layout.addView(layoutRight);
138
    }
139

    
140
///////////////////////////////////////////////////////////////////////////////////////////////////
141

    
142
  void addObject(BandagedCreatorActivity act, String name)
143
    {
144
    BandagedCreatorObjectView view = new BandagedCreatorObjectView(act,name,mNumObjects==0);
145
    LinearLayout pane = view.getPane();
146
    mObjectView.addView(pane);
147
    mNumObjects++;
148
    mViews.add(view);
149
    }
150

    
151
///////////////////////////////////////////////////////////////////////////////////////////////////
152

    
153
  void deleteObject(BandagedCreatorActivity act, String name)
154
    {
155
    for(int v=0; v<mNumObjects; v++)
156
      {
157
      BandagedCreatorObjectView view = mViews.get(v);
158

    
159
      if( view.objectNameIs(name) )
160
        {
161
        LinearLayout pane = view.getPane();
162
        mObjectView.removeView(pane);
163
        mViews.remove(view);
164
        mNumObjects--;
165

    
166
        if( v==0 && mNumObjects>0 )
167
          {
168
          int width = act.getScreenWidthInPixels();
169
          BandagedCreatorObjectView v2 = mViews.get(v);
170
          LinearLayout p2 = v2.getPane();
171
          int lMargin = (int)(width*RubikActivity.LARGE_MARGIN);;
172

    
173
          LinearLayout.LayoutParams params = new LinearLayout.LayoutParams( (int)(width*0.36f), LinearLayout.LayoutParams.MATCH_PARENT);
174
          params.bottomMargin = lMargin;
175
          params.topMargin    = lMargin;
176
          params.leftMargin   = lMargin;
177
          params.rightMargin  = lMargin;
178

    
179
          p2.setLayoutParams(params);
180
          }
181

    
182
        break;
183
        }
184
      }
185
    }
186

    
187
///////////////////////////////////////////////////////////////////////////////////////////////////
188

    
189
  void iconCreationDone(Activity act, Bitmap bmp)
190
    {
191
    int numChildren = mObjectView.getChildCount();
192

    
193
    if( numChildren>0 )
194
      {
195
      LinearLayout pane = (LinearLayout)mObjectView.getChildAt(numChildren-1);
196
      ImageView view = pane.findViewById(R.id.bandagedCreatorObjectIcon);
197

    
198
      if( view!=null )
199
        {
200
        act.runOnUiThread(new Runnable()
201
          {
202
          @Override
203
          public void run()
204
          {
205
          view.setImageBitmap(bmp);
206
          }
207
          });
208
        }
209
      else
210
        {
211
        android.util.Log.e("D", "ImageView not found!");
212
        }
213
      }
214
    }
215
}
(4-4/13)