Project

General

Profile

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

magiccube / src / main / java / org / distorted / screens / RubikScreenPattern.java @ 1ba56d95

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2020 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6
// Magic Cube is proprietary software licensed under an EULA which you should have received      //
7
// along with the code. If not, check https://distorted.org/magic/License-Magic-Cube.html        //
8
///////////////////////////////////////////////////////////////////////////////////////////////////
9

    
10
package org.distorted.screens;
11

    
12
import android.content.SharedPreferences;
13
import androidx.fragment.app.FragmentManager;
14
import android.util.TypedValue;
15
import android.view.Gravity;
16
import android.view.LayoutInflater;
17
import android.view.View;
18
import android.widget.LinearLayout;
19
import android.widget.TextView;
20

    
21
import org.distorted.objectlib.main.ObjectControl;
22

    
23
import org.distorted.main.R;
24
import org.distorted.dialogs.RubikDialogPattern;
25
import org.distorted.helpers.TransparentImageButton;
26
import org.distorted.main.RubikActivity;
27
import org.distorted.objects.RubikObjectList;
28
import org.distorted.patterns.RubikPattern;
29
import org.distorted.patterns.RubikPatternList;
30

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

    
33
public class RubikScreenPattern extends RubikScreenAbstract
34
  {
35
  private TextView mText;
36
  private TransparentImageButton mPrevButton, mNextButton, mBackButton;
37
  private TextView mMovesText;
38
  private int mNumMoves;
39
  private int mPatternOrdinal, mCategory, mPattern;
40
  private float mButtonSize;
41

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

    
44
  RubikScreenPattern()
45
    {
46

    
47
    }
48

    
49
///////////////////////////////////////////////////////////////////////////////////////////////////
50

    
51
  void leaveScreen(RubikActivity act)
52
    {
53
    int object = RubikPatternList.getObject(mPatternOrdinal);
54

    
55
    if( !RubikObjectList.setCurrObject(object) )
56
      {
57
      act.changeObject(object,false);
58
      }
59
    }
60

    
61
///////////////////////////////////////////////////////////////////////////////////////////////////
62

    
63
  void enterScreen(final RubikActivity act)
64
    {
65
    float width = act.getScreenWidthInPixels();
66
    mButtonSize = width*RubikActivity.BUTTON_TEXT_SIZE;
67
    float titleSize  = width*RubikActivity.TITLE_TEXT_SIZE;
68
    LayoutInflater inflater = act.getLayoutInflater();
69

    
70
    // TOP ////////////////////////////
71
    LinearLayout layoutTop = act.findViewById(R.id.upperBar);
72
    layoutTop.removeAllViews();
73
    mText = (TextView)inflater.inflate(R.layout.upper_pattern_text, null);
74
    mText.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleSize);
75
    mText.setText(R.string.patterns);
76
    layoutTop.addView(mText);
77

    
78
    // BOT ////////////////////////////
79
    LinearLayout layoutBot = act.findViewById(R.id.lowerBar);
80
    layoutBot.removeAllViews();
81

    
82
    setupPrevButton(act);
83
    setupNextButton(act);
84
    setupTextView(act,width);
85

    
86
    setTrioState(false);
87

    
88
    LinearLayout.LayoutParams paramsL = new LinearLayout.LayoutParams((int)(width/2),LinearLayout.LayoutParams.MATCH_PARENT);
89
    LinearLayout.LayoutParams paramsM = new LinearLayout.LayoutParams((int)(width/6),LinearLayout.LayoutParams.MATCH_PARENT);
90
    LinearLayout.LayoutParams paramsR = new LinearLayout.LayoutParams((int)(width/3),LinearLayout.LayoutParams.MATCH_PARENT);
91

    
92
    LinearLayout layoutLeft = new LinearLayout(act);
93
    layoutLeft.setLayoutParams(paramsL);
94
    LinearLayout layoutMid = new LinearLayout(act);
95
    layoutMid.setLayoutParams(paramsM);
96
    LinearLayout layoutRight = new LinearLayout(act);
97
    layoutRight.setLayoutParams(paramsR);
98

    
99
    layoutLeft.addView(mPrevButton);
100
    layoutLeft.addView(mMovesText);
101
    layoutLeft.addView(mNextButton);
102

    
103
    setupBackButton(act);
104

    
105
    layoutRight.addView(mBackButton);
106

    
107
    layoutBot.addView(layoutLeft);
108
    layoutBot.addView(layoutMid);
109
    layoutBot.addView(layoutRight);
110
    }
111

    
112
///////////////////////////////////////////////////////////////////////////////////////////////////
113

    
114
  private void showDialog(FragmentManager manager)
115
    {
116
    RubikDialogPattern diag = new RubikDialogPattern();
117
    diag.show( manager, RubikDialogPattern.getDialogTag() );
118
    }
119

    
120
///////////////////////////////////////////////////////////////////////////////////////////////////
121

    
122
  private void setTrioState(boolean enable)
123
    {
124
    int state = enable ? View.VISIBLE : View.INVISIBLE;
125

    
126
    if( mPrevButton!=null ) mPrevButton.setVisibility(state);
127
    if( mNextButton!=null ) mNextButton.setVisibility(state);
128
    if( mMovesText !=null ) mMovesText.setVisibility(state);
129
    }
130

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

    
133
  private void setupBackButton(final RubikActivity act)
134
    {
135
    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);
136
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,1.0f);
137
    mBackButton = new TransparentImageButton(act, icon, TransparentImageButton.GRAVITY_MIDDLE, params);
138

    
139
    mBackButton.setOnClickListener( new View.OnClickListener()
140
      {
141
      @Override
142
      public void onClick(View v)
143
        {
144
        FragmentManager mana = act.getSupportFragmentManager();
145
        ScreenList.goBack(act);
146
        showDialog(mana);
147
        }
148
      });
149
    }
150

    
151
///////////////////////////////////////////////////////////////////////////////////////////////////
152

    
153
  private void setupPrevButton(final RubikActivity act)
154
    {
155
    int icon = RubikActivity.getDrawable(R.drawable.ui_small_left,R.drawable.ui_medium_left, R.drawable.ui_big_left, R.drawable.ui_huge_left);
156
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(0,LinearLayout.LayoutParams.MATCH_PARENT,1.0f);
157
    mPrevButton = new TransparentImageButton(act,icon,TransparentImageButton.GRAVITY_MIDDLE,params);
158

    
159
    mPrevButton.setOnClickListener( new View.OnClickListener()
160
      {
161
      @Override
162
      public void onClick(View v)
163
        {
164
        RubikPattern pattern = RubikPattern.getInstance();
165
        ObjectControl control = act.getControl();
166
        pattern.backMove( control, mPatternOrdinal, mCategory, mPattern);
167
        int currMove = pattern.getCurMove(mPatternOrdinal, mCategory, mPattern);
168
        mMovesText.setText(act.getString(R.string.mo_placeholder,currMove,mNumMoves));
169
        }
170
      });
171
    }
172

    
173
///////////////////////////////////////////////////////////////////////////////////////////////////
174

    
175
  private void setupNextButton(final RubikActivity act)
176
    {
177
    int icon = RubikActivity.getDrawable(R.drawable.ui_small_right,R.drawable.ui_medium_right, R.drawable.ui_big_right, R.drawable.ui_huge_right);
178
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(0,LinearLayout.LayoutParams.MATCH_PARENT,1.0f);
179
    mNextButton = new TransparentImageButton(act,icon,TransparentImageButton.GRAVITY_MIDDLE,params);
180

    
181
    mNextButton.setOnClickListener( new View.OnClickListener()
182
      {
183
      @Override
184
      public void onClick(View v)
185
        {
186
        RubikPattern pattern = RubikPattern.getInstance();
187
        ObjectControl control = act.getControl();
188
        pattern.makeMove( control, mPatternOrdinal, mCategory, mPattern);
189
        int currMove = pattern.getCurMove(mPatternOrdinal, mCategory, mPattern);
190
        mMovesText.setText(act.getString(R.string.mo_placeholder,currMove,mNumMoves));
191
        }
192
      });
193
    }
194

    
195
///////////////////////////////////////////////////////////////////////////////////////////////////
196

    
197
  private void setupTextView(final RubikActivity act, final float width)
198
    {
199
    int padding = (int)(width*RubikActivity.PADDING);
200
    int margin  = (int)(width*RubikActivity.SMALL_MARGIN);
201

    
202
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(0,LinearLayout.LayoutParams.MATCH_PARENT,2.0f);
203
    params.topMargin    = margin;
204
    params.bottomMargin = margin;
205
    params.leftMargin   = margin;
206
    params.rightMargin  = margin;
207

    
208
    mMovesText = new TextView(act);
209
    mMovesText.setTextSize(20);
210
    mMovesText.setLayoutParams(params);
211
    mMovesText.setPadding(padding,0,padding,0);
212
    mMovesText.setGravity(Gravity.CENTER);
213
    mMovesText.setTextSize(TypedValue.COMPLEX_UNIT_PX, mButtonSize);
214
    mMovesText.setText(act.getString(R.string.mo_placeholder,0,0));
215
    }
216

    
217
///////////////////////////////////////////////////////////////////////////////////////////////////
218

    
219
  public void setPattern(final RubikActivity act, int ordinal, int category, int pattern)
220
    {
221
    mPatternOrdinal = ordinal;
222
    mCategory       = category;
223
    mPattern        = pattern;
224

    
225
    setTrioState(true);
226

    
227
    RubikPattern patt = RubikPattern.getInstance();
228
    String patternName = patt.getPatternName(ordinal,category,pattern);
229
    mText.setText(patternName);
230

    
231
    mNumMoves   = patt.getNumMoves(ordinal,category,pattern);
232
    int currMove= patt.getCurMove(ordinal,category,pattern);
233

    
234
    mMovesText.setText(act.getString(R.string.mo_placeholder,currMove,mNumMoves));
235
    }
236

    
237
///////////////////////////////////////////////////////////////////////////////////////////////////
238

    
239
  public void savePreferences(SharedPreferences.Editor editor)
240
    {
241

    
242
    }
243

    
244
///////////////////////////////////////////////////////////////////////////////////////////////////
245

    
246
  public void restorePreferences(SharedPreferences preferences)
247
    {
248

    
249
    }
250
  }
(4-4/10)