Project

General

Profile

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

magiccube / src / main / java / org / distorted / bandaged / BandagedCreatorScreen.java @ 83e021c5

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.app.Activity;
23
import android.graphics.Bitmap;
24
import android.view.View;
25
import android.widget.ImageView;
26
import android.widget.LinearLayout;
27

    
28
import org.distorted.helpers.TransparentImageButton;
29
import org.distorted.main.R;
30
import org.distorted.main.RubikActivity;
31

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

    
34
public class BandagedCreatorScreen
35
{
36
  private TransparentImageButton mBackButton, mResetButton, mDoneButton;
37
  private LinearLayout mObjectView;
38
  private int mNumObjects;
39

    
40
///////////////////////////////////////////////////////////////////////////////////////////////////
41

    
42
  public BandagedCreatorScreen()
43
    {
44
    mNumObjects = 0;
45
    }
46

    
47
///////////////////////////////////////////////////////////////////////////////////////////////////
48

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

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

    
65
///////////////////////////////////////////////////////////////////////////////////////////////////
66

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

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

    
84
///////////////////////////////////////////////////////////////////////////////////////////////////
85

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

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

    
103
///////////////////////////////////////////////////////////////////////////////////////////////////
104

    
105
  void onAttachedToWindow(final BandagedCreatorActivity act)
106
    {
107
    mObjectView = act.findViewById(R.id.bandagedCreatorView);
108

    
109
    int width = act.getScreenWidthInPixels();
110

    
111
    LinearLayout.LayoutParams paramsL = new LinearLayout.LayoutParams(width/4, LinearLayout.LayoutParams.MATCH_PARENT);
112
    LinearLayout.LayoutParams paramsM = new LinearLayout.LayoutParams(width/2, LinearLayout.LayoutParams.MATCH_PARENT);
113
    LinearLayout.LayoutParams paramsR = new LinearLayout.LayoutParams(width/4, LinearLayout.LayoutParams.MATCH_PARENT);
114

    
115
    LinearLayout layoutLeft = new LinearLayout(act);
116
    layoutLeft.setLayoutParams(paramsL);
117
    LinearLayout layoutMid  = new LinearLayout(act);
118
    layoutMid.setLayoutParams(paramsM);
119
    LinearLayout layoutRight= new LinearLayout(act);
120
    layoutRight.setLayoutParams(paramsR);
121

    
122
    setupBackButton(act);
123
    layoutRight.addView(mBackButton);
124
    setupDoneButton(act);
125
    layoutMid.addView(mDoneButton);
126
    setupResetButton(act);
127
    layoutLeft.addView(mResetButton);
128

    
129
    LinearLayout layout = act.findViewById(R.id.lowerBar);
130
    layout.removeAllViews();
131
    layout.addView(layoutLeft);
132
    layout.addView(layoutMid);
133
    layout.addView(layoutRight);
134
    }
135

    
136
///////////////////////////////////////////////////////////////////////////////////////////////////
137

    
138
  void addObject(BandagedCreatorActivity act, String name)
139
    {
140
    BandagedCreatorObjectView view = new BandagedCreatorObjectView(act,name,mNumObjects==0);
141
    LinearLayout pane = view.getPane();
142
    mObjectView.addView(pane);
143
    mNumObjects++;
144
    }
145

    
146
///////////////////////////////////////////////////////////////////////////////////////////////////
147

    
148
  void iconCreationDone(Activity act, Bitmap bmp)
149
    {
150
    int numChildren = mObjectView.getChildCount();
151

    
152
    if( numChildren>0 )
153
      {
154
      LinearLayout pane = (LinearLayout)mObjectView.getChildAt(numChildren-1);
155
      ImageView view = pane.findViewById(R.id.bandagedCreatorObjectIcon);
156

    
157
      if( view!=null )
158
        {
159
        act.runOnUiThread(new Runnable()
160
          {
161
          @Override
162
          public void run()
163
          {
164
          view.setImageBitmap(bmp);
165
          }
166
          });
167
        }
168
      else
169
        {
170
        android.util.Log.e("D", "ImageView not found!");
171
        }
172
      }
173
    }
174
}
(4-4/13)