Project

General

Profile

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

magiccube / src / main / java / org / distorted / screens / RubikScreenPattern.java @ 52547ba7

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.screens;
21

    
22
import android.content.SharedPreferences;
23
import androidx.fragment.app.FragmentManager;
24
import android.util.TypedValue;
25
import android.view.Gravity;
26
import android.view.LayoutInflater;
27
import android.view.View;
28
import android.widget.ImageButton;
29
import android.widget.LinearLayout;
30
import android.widget.TextView;
31

    
32
import org.distorted.objectlib.main.ObjectControl;
33
import org.distorted.objectlib.main.ObjectType;
34

    
35
import org.distorted.main.R;
36
import org.distorted.dialogs.RubikDialogPattern;
37
import org.distorted.helpers.TransparentImageButton;
38
import org.distorted.main.RubikActivity;
39
import org.distorted.patterns.RubikPattern;
40
import org.distorted.patterns.RubikPatternList;
41

    
42
///////////////////////////////////////////////////////////////////////////////////////////////////
43

    
44
public class RubikScreenPattern extends RubikScreenAbstract
45
  {
46
  private TextView mText;
47
  private ImageButton mPrevButton, mNextButton, mBackButton;
48
  private TextView mMovesText;
49
  private int mNumMoves;
50
  private int mPatternOrdinal, mCategory, mPattern;
51
  private float mButtonSize;
52

    
53
///////////////////////////////////////////////////////////////////////////////////////////////////
54

    
55
  RubikScreenPattern()
56
    {
57

    
58
    }
59

    
60
///////////////////////////////////////////////////////////////////////////////////////////////////
61

    
62
  void leaveScreen(RubikActivity act)
63
    {
64
    RubikScreenPlay play = (RubikScreenPlay) ScreenList.PLAY.getScreenClass();
65
    ObjectType object = RubikPatternList.getObject(mPatternOrdinal);
66

    
67
    if( !play.setObject(act,object) )
68
      {
69
      act.changeObject(play.getObject(),false);
70
      }
71
    }
72

    
73
///////////////////////////////////////////////////////////////////////////////////////////////////
74

    
75
  void enterScreen(final RubikActivity act)
76
    {
77
    float width = act.getScreenWidthInPixels();
78
    mButtonSize = width*RubikActivity.BUTTON_TEXT_SIZE;
79
    float titleSize  = width*RubikActivity.TITLE_TEXT_SIZE;
80
    LayoutInflater inflater = act.getLayoutInflater();
81

    
82
    // TOP ////////////////////////////
83
    LinearLayout layoutTop = act.findViewById(R.id.upperBar);
84
    layoutTop.removeAllViews();
85
    mText = (TextView)inflater.inflate(R.layout.upper_pattern_text, null);
86
    mText.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleSize);
87
    mText.setText(R.string.patterns);
88
    layoutTop.addView(mText);
89

    
90
    // BOT ////////////////////////////
91
    LinearLayout layoutBot = act.findViewById(R.id.lowerBar);
92
    layoutBot.removeAllViews();
93

    
94
    setupPrevButton(act,width);
95
    setupNextButton(act,width);
96
    setupTextView(act,width);
97

    
98
    setTrioState(false);
99

    
100
    LinearLayout.LayoutParams paramsL = new LinearLayout.LayoutParams((int)(width/2),LinearLayout.LayoutParams.MATCH_PARENT);
101
    LinearLayout.LayoutParams paramsM = new LinearLayout.LayoutParams((int)(width/6),LinearLayout.LayoutParams.MATCH_PARENT);
102
    LinearLayout.LayoutParams paramsR = new LinearLayout.LayoutParams((int)(width/3),LinearLayout.LayoutParams.MATCH_PARENT);
103

    
104
    LinearLayout layoutLeft = new LinearLayout(act);
105
    layoutLeft.setLayoutParams(paramsL);
106
    LinearLayout layoutMid = new LinearLayout(act);
107
    layoutMid.setLayoutParams(paramsM);
108
    LinearLayout layoutRight = new LinearLayout(act);
109
    layoutRight.setLayoutParams(paramsR);
110

    
111
    layoutLeft.addView(mPrevButton);
112
    layoutLeft.addView(mMovesText);
113
    layoutLeft.addView(mNextButton);
114

    
115
    setupBackButton(act,width);
116

    
117
    layoutRight.addView(mBackButton);
118

    
119
    layoutBot.addView(layoutLeft);
120
    layoutBot.addView(layoutMid);
121
    layoutBot.addView(layoutRight);
122
    }
123

    
124
///////////////////////////////////////////////////////////////////////////////////////////////////
125

    
126
  private void showDialog(FragmentManager manager)
127
    {
128
    RubikDialogPattern diag = new RubikDialogPattern();
129
    diag.show( manager, RubikDialogPattern.getDialogTag() );
130
    }
131

    
132
///////////////////////////////////////////////////////////////////////////////////////////////////
133

    
134
  private void setTrioState(boolean enable)
135
    {
136
    int state = enable ? View.VISIBLE : View.INVISIBLE;
137

    
138
    if( mPrevButton!=null ) mPrevButton.setVisibility(state);
139
    if( mNextButton!=null ) mNextButton.setVisibility(state);
140
    if( mMovesText !=null ) mMovesText.setVisibility(state);
141
    }
142

    
143
///////////////////////////////////////////////////////////////////////////////////////////////////
144

    
145
  private void setupBackButton(final RubikActivity act, final float width)
146
    {
147
    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);
148
    mBackButton = new TransparentImageButton(act, icon, width, LinearLayout.LayoutParams.MATCH_PARENT);
149

    
150
    mBackButton.setOnClickListener( new View.OnClickListener()
151
      {
152
      @Override
153
      public void onClick(View v)
154
        {
155
        FragmentManager mana = act.getSupportFragmentManager();
156
        ScreenList.goBack(act);
157
        showDialog(mana);
158
        }
159
      });
160
    }
161

    
162
///////////////////////////////////////////////////////////////////////////////////////////////////
163

    
164
  private void setupPrevButton(final RubikActivity act, final float width)
165
    {
166
    int icon = RubikActivity.getDrawable(R.drawable.ui_small_left,R.drawable.ui_medium_left, R.drawable.ui_big_left, R.drawable.ui_huge_left);
167
    mPrevButton = new TransparentImageButton(act,icon,width,0);
168

    
169
    mPrevButton.setOnClickListener( new View.OnClickListener()
170
      {
171
      @Override
172
      public void onClick(View v)
173
        {
174
        RubikPattern pattern = RubikPattern.getInstance();
175
        ObjectControl control = act.getControl();
176
        pattern.backMove( control, mPatternOrdinal, mCategory, mPattern);
177
        int currMove = pattern.getCurMove(mPatternOrdinal, mCategory, mPattern);
178
        mMovesText.setText(act.getString(R.string.mo_placeholder,currMove,mNumMoves));
179
        }
180
      });
181
    }
182

    
183
///////////////////////////////////////////////////////////////////////////////////////////////////
184

    
185
  private void setupNextButton(final RubikActivity act, final float width)
186
    {
187
    int icon = RubikActivity.getDrawable(R.drawable.ui_small_right,R.drawable.ui_medium_right, R.drawable.ui_big_right, R.drawable.ui_huge_right);
188
    mNextButton = new TransparentImageButton(act,icon,width,0);
189

    
190
    mNextButton.setOnClickListener( new View.OnClickListener()
191
      {
192
      @Override
193
      public void onClick(View v)
194
        {
195
        RubikPattern pattern = RubikPattern.getInstance();
196
        ObjectControl control = act.getControl();
197
        pattern.makeMove( control, mPatternOrdinal, mCategory, mPattern);
198
        int currMove = pattern.getCurMove(mPatternOrdinal, mCategory, mPattern);
199
        mMovesText.setText(act.getString(R.string.mo_placeholder,currMove,mNumMoves));
200
        }
201
      });
202
    }
203

    
204
///////////////////////////////////////////////////////////////////////////////////////////////////
205

    
206
  private void setupTextView(final RubikActivity act, final float width)
207
    {
208
    int padding = (int)(width*RubikActivity.PADDING);
209
    int margin  = (int)(width*RubikActivity.MARGIN);
210

    
211
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(0,LinearLayout.LayoutParams.MATCH_PARENT,2.0f);
212
    params.topMargin    = margin;
213
    params.bottomMargin = margin;
214
    params.leftMargin   = margin;
215
    params.rightMargin  = margin;
216

    
217
    mMovesText = new TextView(act);
218
    mMovesText.setTextSize(20);
219
    mMovesText.setLayoutParams(params);
220
    mMovesText.setPadding(padding,0,padding,0);
221
    mMovesText.setGravity(Gravity.CENTER);
222
    mMovesText.setTextSize(TypedValue.COMPLEX_UNIT_PX, mButtonSize);
223
    mMovesText.setText(act.getString(R.string.mo_placeholder,0,0));
224
    }
225

    
226
///////////////////////////////////////////////////////////////////////////////////////////////////
227

    
228
  public void setPattern(final RubikActivity act, int ordinal, int category, int pattern)
229
    {
230
    mPatternOrdinal = ordinal;
231
    mCategory       = category;
232
    mPattern        = pattern;
233

    
234
    setTrioState(true);
235

    
236
    RubikPattern patt = RubikPattern.getInstance();
237
    String patternName = patt.getPatternName(ordinal,category,pattern);
238
    mText.setText(patternName);
239

    
240
    mNumMoves   = patt.getNumMoves(ordinal,category,pattern);
241
    int currMove= patt.getCurMove(ordinal,category,pattern);
242

    
243
    mMovesText.setText(act.getString(R.string.mo_placeholder,currMove,mNumMoves));
244
    }
245

    
246
///////////////////////////////////////////////////////////////////////////////////////////////////
247

    
248
  public void savePreferences(SharedPreferences.Editor editor)
249
    {
250

    
251
    }
252

    
253
///////////////////////////////////////////////////////////////////////////////////////////////////
254

    
255
  public void restorePreferences(SharedPreferences preferences)
256
    {
257

    
258
    }
259
  }
(4-4/10)