Project

General

Profile

« Previous | Next » 

Revision e3c74c0f

Added by Leszek Koltunski over 4 years ago

Improvements to the UI - make it proportional regardless of the physical screen size. (Part 1)

View differences:

src/main/java/org/distorted/main/RubikActivity.java
23 23
import android.os.Bundle;
24 24
import android.preference.PreferenceManager;
25 25
import androidx.appcompat.app.AppCompatActivity;
26

  
27
import android.util.DisplayMetrics;
26 28
import android.view.View;
27 29

  
28 30
import com.google.firebase.analytics.FirebaseAnalytics;
......
30 32
import org.distorted.dialogs.RubikDialogAbout;
31 33
import org.distorted.dialogs.RubikDialogError;
32 34
import org.distorted.dialogs.RubikDialogScores;
33
import org.distorted.dialogs.RubikDialogEffects;
34 35
import org.distorted.effects.BaseEffect;
35 36
import org.distorted.library.main.DistortedLibrary;
36 37

  
......
45 46

  
46 47
public class RubikActivity extends AppCompatActivity
47 48
{
49
    public static final float BUTTON_TEXT_SIZE = 0.05f;
50
    public static final float TITLE_TEXT_SIZE = 0.05f;
51

  
48 52
    private boolean mJustStarted;
49 53
    private FirebaseAnalytics mFirebaseAnalytics;
54
    private float mScreenWidth;
50 55

  
51 56
///////////////////////////////////////////////////////////////////////////////////////////////////
52 57

  
......
59 64

  
60 65
      mJustStarted = true;
61 66
      mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);
67

  
68
      DisplayMetrics displaymetrics = new DisplayMetrics();
69
      getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
70
      mScreenWidth=displaymetrics.widthPixels;
71

  
72
      android.util.Log.e("act", "screenWidth="+mScreenWidth);
62 73
      }
63 74

  
64 75
///////////////////////////////////////////////////////////////////////////////////////////////////
......
207 218
      return pre.getObject();
208 219
      }
209 220

  
221
///////////////////////////////////////////////////////////////////////////////////////////////////
222

  
223
    public float getScreenWidthInPixels()
224
      {
225
      return mScreenWidth;
226
      }
227

  
210 228
///////////////////////////////////////////////////////////////////////////////////////////////////
211 229

  
212 230
    public RubikPreRender getPreRender()
src/main/java/org/distorted/states/RubikStateDone.java
21 21

  
22 22
import android.content.SharedPreferences;
23 23
import android.util.DisplayMetrics;
24
import android.util.TypedValue;
24 25
import android.view.LayoutInflater;
25 26
import android.view.View;
26 27
import android.widget.Button;
......
43 44

  
44 45
  void enterState(final RubikActivity act)
45 46
    {
47
    float width = act.getScreenWidthInPixels();
48
    float buttonSize = width*RubikActivity.BUTTON_TEXT_SIZE;
49
    float titleSize = width*RubikActivity.TITLE_TEXT_SIZE;
50

  
46 51
    LayoutInflater inflater = act.getLayoutInflater();
47 52
    DisplayMetrics metrics = act.getResources().getDisplayMetrics();
48 53
    float scale = metrics.density;
......
51 56
    LinearLayout layoutTop = act.findViewById(R.id.upperBar);
52 57
    layoutTop.removeAllViews();
53 58
    TextView label = (TextView)inflater.inflate(R.layout.upper_text, null);
59
    label.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleSize);
54 60
    label.setText(R.string.solved);
55 61
    layoutTop.addView(label);
56 62

  
......
67 73
    Button back = new Button(act);
68 74
    back.setLayoutParams(params);
69 75
    back.setPadding(padding,0,padding,0);
76
    back.setTextSize(TypedValue.COMPLEX_UNIT_PX, buttonSize);
70 77
    back.setText(R.string.back);
71 78

  
72 79
    back.setOnClickListener( new View.OnClickListener()
src/main/java/org/distorted/states/RubikStateMain.java
22 22
import android.content.SharedPreferences;
23 23
import androidx.fragment.app.FragmentManager;
24 24
import android.util.DisplayMetrics;
25
import android.util.TypedValue;
25 26
import android.view.LayoutInflater;
26 27
import android.view.View;
27 28
import android.widget.Button;
......
76 77

  
77 78
  void enterState(final RubikActivity act)
78 79
    {
80
    float width = act.getScreenWidthInPixels();
81
    float buttonSize = width*RubikActivity.BUTTON_TEXT_SIZE;
82
    float titleSize = width*RubikActivity.TITLE_TEXT_SIZE;
83

  
79 84
    FragmentManager mana = act.getSupportFragmentManager();
80 85
    RubikDialogMain diag = (RubikDialogMain) mana.findFragmentByTag(RubikDialogMain.getDialogTag());
81 86

  
......
91 96
    LinearLayout layoutTop = act.findViewById(R.id.upperBar);
92 97
    layoutTop.removeAllViews();
93 98
    final TextView text = (TextView)inflater.inflate(R.layout.upper_text, null);
99

  
100
    text.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleSize);
94 101
    text.setText(R.string.app_name);
95 102
    layoutTop.addView(text);
96 103

  
......
108 115
    Button buttonR = new Button(act);
109 116
    buttonR.setLayoutParams(params);
110 117
    buttonR.setPadding(padding,0,padding,0);
118
    buttonR.setTextSize(TypedValue.COMPLEX_UNIT_PX, buttonSize);
111 119
    buttonR.setText(R.string.exit);
112 120

  
113 121
    buttonR.setOnClickListener( new View.OnClickListener()
src/main/java/org/distorted/states/RubikStatePattern.java
23 23
import android.os.Bundle;
24 24
import androidx.fragment.app.FragmentManager;
25 25
import android.util.DisplayMetrics;
26
import android.util.TypedValue;
26 27
import android.view.Gravity;
27 28
import android.view.LayoutInflater;
28 29
import android.view.View;
......
49 50
  private TextView mMovesText;
50 51
  private int mNumMoves;
51 52
  private int mPatternOrdinal, mCategory, mPattern;
53
  private float mButtonSize, mTitleSize;
52 54

  
53 55
///////////////////////////////////////////////////////////////////////////////////////////////////
54 56

  
......
79 81

  
80 82
  void enterState(final RubikActivity act)
81 83
    {
84
    float width = act.getScreenWidthInPixels();
85
    mButtonSize = width*RubikActivity.BUTTON_TEXT_SIZE;
86
    mTitleSize  = width*RubikActivity.TITLE_TEXT_SIZE;
87

  
82 88
    RubikStatePlay play = (RubikStatePlay)RubikState.PLAY.getStateClass();
83 89
    int obj  = play.getObject();
84 90
    int size = play.getSize();
......
101 107
    LinearLayout layoutTop = act.findViewById(R.id.upperBar);
102 108
    layoutTop.removeAllViews();
103 109
    mText = (TextView)inflater.inflate(R.layout.upper_pattern_text, null);
110
    mText.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTitleSize);
104 111
    mText.setText(R.string.patterns);
105 112
    layoutTop.addView(mText);
106 113

  
......
158 165
    mBackButton = new Button(act);
159 166
    mBackButton.setLayoutParams(backParams);
160 167
    mBackButton.setPadding(padding,0,padding,0);
168
    mBackButton.setTextSize(TypedValue.COMPLEX_UNIT_PX, mButtonSize);
161 169
    mBackButton.setText(R.string.back);
162 170

  
163 171
    mBackButton.setOnClickListener( new View.OnClickListener()
......
245 253
    mMovesText.setLayoutParams(params);
246 254
    mMovesText.setPadding(padding,0,padding,0);
247 255
    mMovesText.setGravity(Gravity.CENTER);
256
    mMovesText.setTextSize(TypedValue.COMPLEX_UNIT_PX, mButtonSize);
248 257
    mMovesText.setText(act.getString(R.string.mo_placeholder,0,0));
249 258
    }
250 259

  
src/main/java/org/distorted/states/RubikStatePlay.java
24 24
import android.graphics.drawable.BitmapDrawable;
25 25
import android.os.Build;
26 26
import android.util.DisplayMetrics;
27
import android.util.TypedValue;
27 28
import android.view.Gravity;
28 29
import android.view.LayoutInflater;
29 30
import android.view.View;
......
33 34
import android.widget.ImageButton;
34 35
import android.widget.LinearLayout;
35 36
import android.widget.PopupWindow;
37
import android.widget.TextView;
38

  
36 39
import androidx.appcompat.widget.AppCompatSpinner;
37 40

  
38 41
import org.distorted.dialogs.RubikDialogEffects;
......
58 61
  private AppCompatSpinner mLevelSpinner;
59 62
  private ArrayAdapter<String> mSpinnerAdapter;
60 63
  private int mLevelValue;
64
  private float mButtonSize, mTitleSize;
61 65

  
62 66
///////////////////////////////////////////////////////////////////////////////////////////////////
63 67

  
......
73 77
    DisplayMetrics metrics = act.getResources().getDisplayMetrics();
74 78
    final float scale = metrics.density;
75 79

  
80
    float width = act.getScreenWidthInPixels();
81
    mButtonSize = width*RubikActivity.BUTTON_TEXT_SIZE;
82
    mTitleSize  = width*RubikActivity.TITLE_TEXT_SIZE;
83

  
76 84
    // TOP ////////////////////////////
77 85
    LinearLayout layoutTop = act.findViewById(R.id.upperBar);
78 86
    layoutTop.removeAllViews();
......
185 193
    mPlayButton = new Button(act);
186 194
    mPlayButton.setLayoutParams(backParams);
187 195
    mPlayButton.setPadding(padding,0,padding,0);
196
    mPlayButton.setTextSize(TypedValue.COMPLEX_UNIT_PX, mButtonSize);
188 197
    mPlayButton.setText(R.string.play);
189 198

  
190 199
    mPlayButton.setOnClickListener( new View.OnClickListener()
......
228 237
    mSolveButton = new Button(act);
229 238
    mSolveButton.setLayoutParams(backParams);
230 239
    mSolveButton.setPadding(padding,0,padding,0);
240
    mSolveButton.setTextSize(TypedValue.COMPLEX_UNIT_PX, mButtonSize);
241

  
231 242
    mSolveButton.setText(R.string.solve);
232 243

  
233 244
    mSolveButton.setOnClickListener( new View.OnClickListener()
......
249 260
    mBackButton = new Button(act);
250 261
    mBackButton.setLayoutParams(backParams);
251 262
    mBackButton.setPadding(padding,0,padding,0);
263
    mBackButton.setTextSize(TypedValue.COMPLEX_UNIT_PX, mButtonSize);
252 264
    mBackButton.setText(R.string.back);
253 265

  
254 266
    mBackButton.setOnClickListener( new View.OnClickListener()
......
415 427

  
416 428
  public void onItemSelected(AdapterView<?> parent, View view, int pos, long id)
417 429
    {
430
    ((TextView) parent.getChildAt(0)).setTextSize(TypedValue.COMPLEX_UNIT_PX, mButtonSize);
418 431
    mLevelValue = pos+1;
419 432
    }
420 433

  
src/main/java/org/distorted/states/RubikStateReady.java
21 21

  
22 22
import android.content.SharedPreferences;
23 23
import android.util.DisplayMetrics;
24
import android.util.TypedValue;
24 25
import android.view.LayoutInflater;
25 26
import android.view.View;
26 27
import android.widget.Button;
......
43 44

  
44 45
  void enterState(final RubikActivity act)
45 46
    {
47
    float width = act.getScreenWidthInPixels();
48
    float buttonSize = width*RubikActivity.BUTTON_TEXT_SIZE;
49
    float titleSize  = width*RubikActivity.TITLE_TEXT_SIZE;
50

  
46 51
    LayoutInflater inflater = act.getLayoutInflater();
47 52
    DisplayMetrics metrics = act.getResources().getDisplayMetrics();
48 53
    float scale = metrics.density;
......
51 56
    LinearLayout layoutTop = act.findViewById(R.id.upperBar);
52 57
    layoutTop.removeAllViews();
53 58
    TextView label = (TextView)inflater.inflate(R.layout.upper_text, null);
59
    label.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleSize);
54 60
    label.setText(R.string.ready);
55 61
    layoutTop.addView(label);
56 62

  
......
67 73
    Button back = new Button(act);
68 74
    back.setLayoutParams(params);
69 75
    back.setPadding(padding,0,padding,0);
76
    back.setTextSize(TypedValue.COMPLEX_UNIT_PX, buttonSize);
70 77
    back.setText(R.string.back);
71 78

  
72 79
    back.setOnClickListener( new View.OnClickListener()
src/main/java/org/distorted/states/RubikStateSolution.java
21 21

  
22 22
import android.content.SharedPreferences;
23 23
import android.util.DisplayMetrics;
24
import android.util.TypedValue;
24 25
import android.view.Gravity;
25 26
import android.view.LayoutInflater;
26 27
import android.view.View;
......
47 48
  private int[][] mMoves;
48 49
  private int mCurrMove, mNumMoves;
49 50
  private boolean mCanRotate;
51
  private float mButtonSize, mTitleSize;
50 52

  
51 53
///////////////////////////////////////////////////////////////////////////////////////////////////
52 54

  
......
60 62

  
61 63
  void enterState(final RubikActivity act)
62 64
    {
65
    float width = act.getScreenWidthInPixels();
66
    mButtonSize = width*RubikActivity.BUTTON_TEXT_SIZE;
67
    mTitleSize  = width*RubikActivity.TITLE_TEXT_SIZE;
68

  
63 69
    DisplayMetrics metrics = act.getResources().getDisplayMetrics();
64 70
    final float scale = metrics.density;
65 71
    LayoutInflater inflater = act.getLayoutInflater();
......
69 75
    layoutTop.removeAllViews();
70 76

  
71 77
    final TextView text = (TextView)inflater.inflate(R.layout.upper_text, null);
78
    text.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTitleSize);
72 79
    text.setText(R.string.solution);
73 80
    layoutTop.addView(text);
74 81

  
......
148 155
    mMovesText.setLayoutParams(params);
149 156
    mMovesText.setPadding(padding,0,padding,0);
150 157
    mMovesText.setGravity(Gravity.CENTER);
158
    mMovesText.setTextSize(TypedValue.COMPLEX_UNIT_PX, mButtonSize);
151 159
    mMovesText.setText(act.getString(R.string.mo_placeholder,mCurrMove,mNumMoves));
152 160
    }
153 161

  
......
160 168
    mBackButton = new Button(act);
161 169
    mBackButton.setLayoutParams(backParams);
162 170
    mBackButton.setPadding(padding,0,padding,0);
171
    mBackButton.setTextSize(TypedValue.COMPLEX_UNIT_PX, mButtonSize);
163 172
    mBackButton.setText(R.string.back);
164 173

  
165 174
    mBackButton.setOnClickListener( new View.OnClickListener()
src/main/java/org/distorted/states/RubikStateSolver.java
28 28
import android.os.Bundle;
29 29
import androidx.core.content.ContextCompat;
30 30
import android.util.DisplayMetrics;
31
import android.util.TypedValue;
31 32
import android.view.View;
32 33
import android.widget.Button;
33 34
import android.widget.ImageButton;
......
57 58
  private int mCurrentColor;
58 59
  private int[] mFaceColors;
59 60
  private int mNumFaces;
61
  private float mTitleSize, mButtonSize;
60 62

  
61 63
  private RubikObjectList mCurrentObject;
62 64
  private int mCurrentObjectSize;
......
74 76

  
75 77
  void enterState(final RubikActivity act)
76 78
    {
79
    float width = act.getScreenWidthInPixels();
80
    mButtonSize = width*RubikActivity.BUTTON_TEXT_SIZE;
81
    mTitleSize  = width*RubikActivity.TITLE_TEXT_SIZE;
82

  
77 83
    mWeakAct = new WeakReference<>(act);
78 84

  
79 85
    mSolving = false;
......
187 193
    mSolveButton = new Button(act);
188 194
    mSolveButton.setLayoutParams(backParams);
189 195
    mSolveButton.setPadding(padding,0,padding,0);
196
    mSolveButton.setTextSize(TypedValue.COMPLEX_UNIT_PX, mButtonSize);
190 197
    mSolveButton.setText(R.string.solve);
191 198

  
192 199
    mSolveButton.setOnClickListener( new View.OnClickListener()
......
215 222
    mBackButton = new Button(act);
216 223
    mBackButton.setLayoutParams(backParams);
217 224
    mBackButton.setPadding(padding,0,padding,0);
225
    mBackButton.setTextSize(TypedValue.COMPLEX_UNIT_PX, mButtonSize);
218 226
    mBackButton.setText(R.string.back);
219 227

  
220 228
    mBackButton.setOnClickListener( new View.OnClickListener()
src/main/java/org/distorted/states/RubikStateSolving.java
21 21

  
22 22
import android.content.SharedPreferences;
23 23
import android.util.DisplayMetrics;
24
import android.util.TypedValue;
24 25
import android.view.LayoutInflater;
25 26
import android.view.View;
26 27
import android.widget.Button;
......
85 86

  
86 87
  void enterState(final RubikActivity act)
87 88
    {
89
    float width = act.getScreenWidthInPixels();
90
    float buttonSize = width*RubikActivity.BUTTON_TEXT_SIZE;
91
    float titleSize  = width*RubikActivity.TITLE_TEXT_SIZE;
92

  
88 93
    mCanPrevMove = true;
89 94

  
90 95
    startCounting(act);
......
101 106
    layoutTop.removeAllViews();
102 107
    mTime = (TextView)inflater.inflate(R.layout.upper_text, null);
103 108
    int elapsed = (int)mElapsed/1000;
109
    mTime.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleSize);
104 110
    mTime.setText(act.getString(R.string.tm_placeholder,elapsed/60,elapsed%60));
105 111
    layoutTop.addView(mTime);
106 112

  
......
120 126
    Button back = new Button(act);
121 127
    back.setLayoutParams(params);
122 128
    back.setPadding(padding,0,padding,0);
129
    back.setTextSize(TypedValue.COMPLEX_UNIT_PX, buttonSize);
123 130
    back.setText(R.string.back);
124 131

  
125 132
    back.setOnClickListener( new View.OnClickListener()
src/main/res/layout/main.xml
7 7
    <LinearLayout
8 8
        android:id="@+id/upperBar"
9 9
        android:layout_width="fill_parent"
10
        android:layout_height="60dp"
10
        android:layout_height="0dp"
11
        android:layout_weight="0.1"
11 12
        android:gravity="center"
12 13
        android:orientation="horizontal">
13 14
    </LinearLayout>
......
20 21

  
21 22
    <LinearLayout
22 23
        android:layout_width="match_parent"
23
        android:layout_height="60dp"
24
        android:layout_height="0dp"
25
        android:layout_weight="0.1"
24 26
        android:orientation="horizontal">
25 27

  
26 28
        <LinearLayout

Also available in: Unified diff