Project

General

Profile

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

magiccube / src / main / java / org / distorted / screens / RubikScreenPattern.java @ b600ccd9

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.LinearLayout;
29
import android.widget.TextView;
30

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

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

    
41
///////////////////////////////////////////////////////////////////////////////////////////////////
42

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

    
52
///////////////////////////////////////////////////////////////////////////////////////////////////
53

    
54
  RubikScreenPattern()
55
    {
56

    
57
    }
58

    
59
///////////////////////////////////////////////////////////////////////////////////////////////////
60

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

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

    
72
///////////////////////////////////////////////////////////////////////////////////////////////////
73

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

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

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

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

    
97
    setTrioState(false);
98

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

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

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

    
114
    setupBackButton(act);
115

    
116
    layoutRight.addView(mBackButton);
117

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

    
123
///////////////////////////////////////////////////////////////////////////////////////////////////
124

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

    
131
///////////////////////////////////////////////////////////////////////////////////////////////////
132

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

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

    
142
///////////////////////////////////////////////////////////////////////////////////////////////////
143

    
144
  private void setupBackButton(final RubikActivity act)
145
    {
146
    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);
147
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,1.0f);
148
    mBackButton = new TransparentImageButton(act, icon, TransparentImageButton.GRAVITY_MIDDLE, params);
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)
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
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(0,LinearLayout.LayoutParams.MATCH_PARENT,1.0f);
168
    mPrevButton = new TransparentImageButton(act,icon,TransparentImageButton.GRAVITY_MIDDLE,params);
169

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

    
184
///////////////////////////////////////////////////////////////////////////////////////////////////
185

    
186
  private void setupNextButton(final RubikActivity act)
187
    {
188
    int icon = RubikActivity.getDrawable(R.drawable.ui_small_right,R.drawable.ui_medium_right, R.drawable.ui_big_right, R.drawable.ui_huge_right);
189
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(0,LinearLayout.LayoutParams.MATCH_PARENT,1.0f);
190
    mNextButton = new TransparentImageButton(act,icon,TransparentImageButton.GRAVITY_MIDDLE,params);
191

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

    
206
///////////////////////////////////////////////////////////////////////////////////////////////////
207

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

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

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

    
228
///////////////////////////////////////////////////////////////////////////////////////////////////
229

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

    
236
    setTrioState(true);
237

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

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

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

    
248
///////////////////////////////////////////////////////////////////////////////////////////////////
249

    
250
  public void savePreferences(SharedPreferences.Editor editor)
251
    {
252

    
253
    }
254

    
255
///////////////////////////////////////////////////////////////////////////////////////////////////
256

    
257
  public void restorePreferences(SharedPreferences preferences)
258
    {
259

    
260
    }
261
  }
(4-4/10)