Project

General

Profile

« Previous | Next » 

Revision 2eb74743

Added by Leszek Koltunski over 4 years ago

Improvements to the UI - make it proportional regardless of the physical screen size. (Part 5 - first 3 Dialogs)

View differences:

src/main/java/org/distorted/dialogs/RubikDialogAbout.java
31 31

  
32 32
import android.text.method.LinkMovementMethod;
33 33
import android.text.method.MovementMethod;
34
import android.util.DisplayMetrics;
35
import android.util.TypedValue;
34 36
import android.view.LayoutInflater;
35 37
import android.view.View;
36 38
import android.view.Window;
37 39
import android.view.WindowManager;
40
import android.widget.Button;
38 41
import android.widget.TextView;
39 42

  
40 43
import org.distorted.main.R;
44
import org.distorted.main.RubikActivity;
41 45

  
42 46
///////////////////////////////////////////////////////////////////////////////////////////////////
43 47

  
......
51 55
    LayoutInflater inflater = act.getLayoutInflater();
52 56
    AlertDialog.Builder builder = new AlertDialog.Builder(act);
53 57

  
58
    DisplayMetrics displaymetrics = new DisplayMetrics();
59
    act.getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
60
    final float titleSize= displaymetrics.widthPixels * RubikActivity.MENU_BIG_TEXT_SIZE;
61
    final float okSize   = displaymetrics.widthPixels * RubikActivity.MENU_MEDIUM_TEXT_SIZE;
62
    final float textSize = displaymetrics.widthPixels * RubikActivity.MENU_SMALL_TEXT_SIZE;
63

  
54 64
    TextView tv = (TextView) inflater.inflate(R.layout.dialog_title, null);
65
    tv.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleSize);
55 66
    tv.setText(R.string.about);
56 67
    builder.setCustomTitle(tv);
57 68

  
......
77 88
      }
78 89
    catch (PackageManager.NameNotFoundException e)
79 90
      {
80
      appVers = "1.1.1";
91
      appVers = "1.2.2";
81 92
      }
82 93

  
94
    text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
83 95
    text.setText(getString(R.string.ap_placeholder,appName, appVers));
84 96

  
85 97
    MovementMethod mm = LinkMovementMethod.getInstance();
86 98
    TextView text1 = view.findViewById(R.id.about_section1);
99
    text1.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
87 100
    text1.setMovementMethod(mm);
88 101
    TextView text2 = view.findViewById(R.id.about_section2);
102
    text2.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
89 103
    text2.setMovementMethod(mm);
90 104
    TextView text3 = view.findViewById(R.id.about_section3);
105
    text3.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
91 106
    text3.setMovementMethod(mm);
92 107

  
93 108
    builder.setView(view);
......
101 116
      window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
102 117
      }
103 118

  
119
    dialog.setOnShowListener(new DialogInterface.OnShowListener()
120
      {
121
      @Override
122
      public void onShow(DialogInterface dialog)
123
        {
124
        Button btnPositive = ((AlertDialog)dialog).getButton(Dialog.BUTTON_POSITIVE);
125
        btnPositive.setTextSize(TypedValue.COMPLEX_UNIT_PX, okSize);
126
        }
127
      });
128

  
104 129
    return dialog;
105 130
    }
106 131
  }
src/main/java/org/distorted/dialogs/RubikDialogEffects.java
28 28
import androidx.appcompat.app.AlertDialog;
29 29
import androidx.appcompat.app.AppCompatDialogFragment;
30 30
import android.util.DisplayMetrics;
31
import android.util.TypedValue;
31 32
import android.view.Gravity;
32 33
import android.view.LayoutInflater;
33 34
import android.view.View;
......
35 36
import android.view.WindowManager;
36 37
import android.widget.AdapterView;
37 38
import android.widget.ArrayAdapter;
39
import android.widget.Button;
38 40
import android.widget.LinearLayout;
39 41
import android.widget.SeekBar;
40 42
import android.widget.Spinner;
......
42 44

  
43 45
import org.distorted.effects.BaseEffect;
44 46
import org.distorted.main.R;
47
import org.distorted.main.RubikActivity;
45 48

  
46 49
///////////////////////////////////////////////////////////////////////////////////////////////////
47 50

  
48 51
public class RubikDialogEffects extends AppCompatDialogFragment implements SeekBar.OnSeekBarChangeListener, AdapterView.OnItemSelectedListener
49 52
  {
50 53
  private TextView[] mDurationText;
54
  private float mTextSize;
51 55

  
52 56
///////////////////////////////////////////////////////////////////////////////////////////////////
53 57

  
......
55 59
    {
56 60
    BaseEffect.Type beType = BaseEffect.Type.getType(index);
57 61
    DisplayMetrics metrics = act.getResources().getDisplayMetrics();
58
    float scale = metrics.density;
62
    final float scale = metrics.density;
63
    mTextSize = metrics.widthPixels * RubikActivity.MENU_SMALL_TEXT_SIZE;
59 64

  
60
    int textH=32;
61
    int layoH=36;
65
    int textH= (int)(mTextSize);
66
    int layoH= (int)(1.2f*mTextSize);
62 67
    int margH=10;
63 68

  
64 69
    ///// OUTER LAYOUT ///////////////////////////////////////////////////////////////////
......
86 91
    LinearLayout.LayoutParams textParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,layoutHeight);
87 92

  
88 93
    TextView textView = new TextView(act);
94
    textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTextSize);
89 95
    textView.setText(beType.getText());
90 96
    textView.setLayoutParams(textParams);
91 97
    textView.setGravity(Gravity.CENTER);
92 98
    textView.setPadding(padding,0,padding,0);
93
    textView.setTextAppearance(act,android.R.style.TextAppearance_Small);
94 99
    outerLayout.addView(textView);
95 100

  
96 101
    ///// INNER LAYOUT1 //////////////////////////////////////////////////////////////////
......
110 115
    LinearLayout.LayoutParams text1LayoutParams = new LinearLayout.LayoutParams(0,layoutHeight,0.25f);
111 116

  
112 117
    TextView text1View = new TextView(act);
118
    text1View.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTextSize);
113 119
    text1View.setText(R.string.duration);
114 120
    text1View.setLayoutParams(text1LayoutParams);
115 121
    text1View.setGravity(Gravity.START|Gravity.CENTER);
116 122
    text1View.setPadding(text1Padding,0,text1Padding,0);
117
    text1View.setTextAppearance(act,android.R.style.TextAppearance_Small);
118 123
    innerLayout1.addView(text1View);
119 124
    //////////////////////////////////////////////////////////////////
120 125
    int text2Padding = (int)(scale*5 + 0.5f);
121 126
    LinearLayout.LayoutParams text2LayoutParams = new LinearLayout.LayoutParams(0,layoutHeight,0.25f);
122 127

  
123 128
    mDurationText[index] = new TextView(act);
129
    mDurationText[index].setTextSize(TypedValue.COMPLEX_UNIT_PX, mTextSize);
124 130
    mDurationText[index].setLayoutParams(text2LayoutParams);
125 131
    mDurationText[index].setGravity(Gravity.START|Gravity.CENTER);
126 132
    mDurationText[index].setPadding(text2Padding,0,text2Padding,0);
127
    mDurationText[index].setTextAppearance(act,android.R.style.TextAppearance_Small);
128 133
    innerLayout1.addView(mDurationText[index]);
129 134
    //////////////////////////////////////////////////////////////////
130 135
    int seekPadding = (int)(scale*10 + 0.5f);
......
156 161
    LinearLayout.LayoutParams text3LayoutParams = new LinearLayout.LayoutParams(0,LinearLayout.LayoutParams.MATCH_PARENT,0.25f);
157 162

  
158 163
    TextView text3View = new TextView(act);
164
    text3View.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTextSize);
159 165
    text3View.setText(R.string.type);
160 166
    text3View.setLayoutParams(text3LayoutParams);
161 167
    text3View.setGravity(Gravity.START|Gravity.CENTER);
162 168
    text3View.setPadding(text3Padding,0,text3Padding,0);
163
    text3View.setTextAppearance(act,android.R.style.TextAppearance_Small);
164 169
    innerLayout2.addView(text3View);
165 170
    //////////////////////////////////////////////////////////////////
166 171
    int spinnerPadding = (int)(scale*10 + 0.5f);
......
207 212
    LayoutInflater inflater = act.getLayoutInflater();
208 213
    AlertDialog.Builder builder = new AlertDialog.Builder(act);
209 214
    TextView tv = (TextView) inflater.inflate(R.layout.dialog_title, null);
215

  
216
    DisplayMetrics displaymetrics = new DisplayMetrics();
217
    act.getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
218
    final float titleSize= displaymetrics.widthPixels * RubikActivity.MENU_BIG_TEXT_SIZE;
219
    final float okSize   = displaymetrics.widthPixels * RubikActivity.MENU_MEDIUM_TEXT_SIZE;
220

  
221
    tv.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleSize);
210 222
    tv.setText(R.string.effects);
211 223
    builder.setCustomTitle(tv);
212 224

  
......
248 260
      window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
249 261
      }
250 262

  
263
    dialog.setOnShowListener(new DialogInterface.OnShowListener()
264
      {
265
      @Override
266
      public void onShow(DialogInterface dialog)
267
        {
268
        Button btnPositive = ((AlertDialog)dialog).getButton(Dialog.BUTTON_POSITIVE);
269
        btnPositive.setTextSize(TypedValue.COMPLEX_UNIT_PX, okSize);
270
        }
271
      });
272

  
251 273
    return dialog;
252 274
    }
253 275

  
......
255 277

  
256 278
  public void onItemSelected(AdapterView<?> parent, View view, int pos, long id)
257 279
    {
280
    ((TextView) parent.getChildAt(0)).setTextSize(TypedValue.COMPLEX_UNIT_PX, mTextSize);
281

  
258 282
    int parentID = parent.getId();
259 283
    int len = BaseEffect.Type.LENGTH;
260 284

  
src/main/java/org/distorted/dialogs/RubikDialogMain.java
52 52

  
53 53
    DisplayMetrics displaymetrics = new DisplayMetrics();
54 54
    act.getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
55
    float textSize = displaymetrics.widthPixels * RubikActivity.MENU_TEXT_SIZE;
55
    float textSize = displaymetrics.widthPixels * RubikActivity.MENU_MEDIUM_TEXT_SIZE;
56 56
    int buttonSize = (int)(2.5f*textSize);
57 57

  
58 58
    Button play = view.findViewById(R.id.rubikPlay);
src/main/java/org/distorted/main/RubikActivity.java
49 49
    public static final float BUTTON_TEXT_SIZE = 0.05f;
50 50
    public static final float TITLE_TEXT_SIZE  = 0.06f;
51 51
    public static final float BITMAP_TEXT_SIZE = 0.09f;
52
    public static final float MENU_TEXT_SIZE   = 0.04f;
52

  
53
    public static final float MENU_BIG_TEXT_SIZE   = 0.05f;
54
    public static final float MENU_MEDIUM_TEXT_SIZE= 0.04f;
55
    public static final float MENU_SMALL_TEXT_SIZE = 0.035f;
53 56

  
54 57
    private boolean mJustStarted;
55 58
    private FirebaseAnalytics mFirebaseAnalytics;

Also available in: Unified diff