Project

General

Profile

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

magiccube / src / main / java / org / distorted / states / RubikStateReady.java @ 6a76f80a

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2020 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.states;
21

    
22
import android.content.SharedPreferences;
23
import android.util.TypedValue;
24
import android.view.LayoutInflater;
25
import android.view.View;
26
import android.widget.ImageButton;
27
import android.widget.LinearLayout;
28
import android.widget.TextView;
29

    
30
import org.distorted.main.R;
31
import org.distorted.main.RubikActivity;
32

    
33
///////////////////////////////////////////////////////////////////////////////////////////////////
34

    
35
public class RubikStateReady extends RubikStateAbstract
36
  {
37
  private ImageButton mPrevButton, mLockButton, mBackButton;
38

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

    
41
  void leaveState(RubikActivity act)
42
    {
43

    
44
    }
45

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

    
48
  void enterState(final RubikActivity act)
49
    {
50
    float width = act.getScreenWidthInPixels();
51
    float titleSize  = width*RubikActivity.TITLE_TEXT_SIZE;
52

    
53
    LayoutInflater inflater = act.getLayoutInflater();
54

    
55
    // TOP ////////////////////////////
56
    LinearLayout layoutTop = act.findViewById(R.id.upperBar);
57
    layoutTop.removeAllViews();
58
    TextView label = (TextView)inflater.inflate(R.layout.upper_text, null);
59
    label.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleSize);
60
    label.setText(R.string.ready);
61
    layoutTop.addView(label);
62

    
63
    // BOT ////////////////////////////
64
    LinearLayout layoutBot = act.findViewById(R.id.lowerBar);
65
    layoutBot.removeAllViews();
66

    
67
    LinearLayout.LayoutParams paramsL = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,1);
68

    
69
    LinearLayout layoutLeft = new LinearLayout(act);
70
    layoutLeft.setLayoutParams(paramsL);
71
    LinearLayout layoutMid = new LinearLayout(act);
72
    layoutMid.setLayoutParams(paramsL);
73
    LinearLayout layoutRight = new LinearLayout(act);
74
    layoutRight.setLayoutParams(paramsL);
75

    
76
    setupPrevButtom(act,width);
77
    layoutLeft.addView(mPrevButton);
78
    setupLockButton(act,width);
79
    layoutMid.addView(mLockButton);
80
    setupBackButton(act,width);
81
    layoutRight.addView(mBackButton);
82

    
83
    layoutBot.addView(layoutLeft);
84
    layoutBot.addView(layoutMid);
85
    layoutBot.addView(layoutRight);
86
    }
87

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

    
90
  private void setupBackButton(final RubikActivity act, float width)
91
    {
92
    final int icon = RubikActivity.getDrawable(R.drawable.ui_small_back,R.drawable.ui_medium_back, R.drawable.ui_big_back, R.drawable.ui_huge_back);
93
    mBackButton = new TransparentImageButton(act, icon, width, LinearLayout.LayoutParams.MATCH_PARENT);
94

    
95
    mBackButton.setOnClickListener( new View.OnClickListener()
96
      {
97
      @Override
98
      public void onClick(View v)
99
        {
100
        StateList.goBack(act);
101
        }
102
      });
103
    }
104

    
105
///////////////////////////////////////////////////////////////////////////////////////////////////
106

    
107
  private void setupLockButton(final RubikActivity act, final float width)
108
    {
109
    final int icon = getLockIcon(act);
110
    mLockButton = new TransparentImageButton(act, icon, width,LinearLayout.LayoutParams.MATCH_PARENT);
111

    
112
    mLockButton.setOnClickListener( new View.OnClickListener()
113
      {
114
      @Override
115
      public void onClick(View v)
116
        {
117
        toggleLock(act);
118
        }
119
      });
120
    }
121

    
122
///////////////////////////////////////////////////////////////////////////////////////////////////
123

    
124
  private void setupPrevButtom(final RubikActivity act, float width)
125
    {
126
    int icon = RubikActivity.getDrawable(R.drawable.ui_small_cube_back,R.drawable.ui_medium_cube_back, R.drawable.ui_big_cube_back, R.drawable.ui_huge_cube_back);
127
    mPrevButton = new TransparentImageButton(act, icon, width, LinearLayout.LayoutParams.MATCH_PARENT);
128

    
129
    mPrevButton.setOnClickListener( new View.OnClickListener()
130
      {
131
      @Override
132
      public void onClick(View v)
133
        {
134
        // empty
135
        }
136
      });
137
    }
138

    
139
///////////////////////////////////////////////////////////////////////////////////////////////////
140

    
141
  private void toggleLock(RubikActivity act)
142
    {
143
    act.toggleLock();
144
    mLockButton.setImageResource(getLockIcon(act));
145
    }
146

    
147
///////////////////////////////////////////////////////////////////////////////////////////////////
148

    
149
  private int getLockIcon(RubikActivity act)
150
    {
151
    if( act.retLocked() )
152
      {
153
      return RubikActivity.getDrawable(R.drawable.ui_small_locked,R.drawable.ui_medium_locked, R.drawable.ui_big_locked, R.drawable.ui_huge_locked);
154
      }
155
    else
156
      {
157
      return RubikActivity.getDrawable(R.drawable.ui_small_unlocked,R.drawable.ui_medium_unlocked, R.drawable.ui_big_unlocked, R.drawable.ui_huge_unlocked);
158
      }
159
    }
160

    
161
///////////////////////////////////////////////////////////////////////////////////////////////////
162

    
163
  public void savePreferences(SharedPreferences.Editor editor)
164
    {
165

    
166
    }
167

    
168
///////////////////////////////////////////////////////////////////////////////////////////////////
169

    
170
  public void restorePreferences(SharedPreferences preferences)
171
    {
172

    
173
    }
174
  }
(5-5/9)