Project

General

Profile

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

magiccube / src / main / java / org / distorted / bandaged / BandagedCreatorScreen.java @ 7cb8d4b0

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

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

    
31
///////////////////////////////////////////////////////////////////////////////////////////////////
32

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

    
39
///////////////////////////////////////////////////////////////////////////////////////////////////
40

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

    
46
///////////////////////////////////////////////////////////////////////////////////////////////////
47

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

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

    
64
///////////////////////////////////////////////////////////////////////////////////////////////////
65

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

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

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

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

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

    
102
///////////////////////////////////////////////////////////////////////////////////////////////////
103

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

    
108
    int width = act.getScreenWidthInPixels();
109

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

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

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

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

    
135
///////////////////////////////////////////////////////////////////////////////////////////////////
136

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

    
145
///////////////////////////////////////////////////////////////////////////////////////////////////
146

    
147
  void iconCreationDone(Bitmap bmp)
148
    {
149
    int numChildren = mObjectView.getChildCount();
150
    LinearLayout pane = (LinearLayout)mObjectView.getChildAt(numChildren-1);
151
    ImageView view = pane.findViewById(R.id.bandagedCreatorObjectIcon);
152

    
153
    if( view!=null )
154
      {
155
      view.setImageBitmap(bmp);
156
      }
157
    else
158
      {
159
      android.util.Log.e("D", "ImageView not found!");
160
      }
161
    }
162
}
(4-4/13)