Project

General

Profile

« Previous | Next » 

Revision fb37b424

Added by Leszek Koltunski over 4 years ago

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

View differences:

src/main/java/org/distorted/dialogs/RubikDialogError.java
22 22
import android.app.Dialog;
23 23
import android.content.DialogInterface;
24 24
import android.os.Bundle;
25
import android.util.DisplayMetrics;
26
import android.util.TypedValue;
25 27
import android.view.LayoutInflater;
26 28
import android.view.View;
29
import android.widget.Button;
27 30
import android.widget.TextView;
28 31

  
29 32
import androidx.annotation.NonNull;
......
32 35
import androidx.fragment.app.FragmentActivity;
33 36

  
34 37
import org.distorted.main.R;
38
import org.distorted.main.RubikActivity;
35 39

  
36 40
///////////////////////////////////////////////////////////////////////////////////////////////////
37 41

  
......
45 49
    LayoutInflater inflater = act.getLayoutInflater();
46 50
    AlertDialog.Builder builder = new AlertDialog.Builder(act);
47 51

  
52
    DisplayMetrics displaymetrics = new DisplayMetrics();
53
    act.getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
54
    final float titleSize= displaymetrics.widthPixels * RubikActivity.MENU_BIG_TEXT_SIZE;
55
    final float okSize   = displaymetrics.widthPixels * RubikActivity.MENU_MEDIUM_TEXT_SIZE;
56

  
48 57
    Bundle args = getArguments();
49 58
    String error;
50 59

  
......
58 67
      }
59 68

  
60 69
    TextView tv = (TextView) inflater.inflate(R.layout.dialog_title, null);
70
    tv.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleSize);
61 71
    tv.setText(R.string.opengl_error);
62 72
    builder.setCustomTitle(tv);
63 73

  
......
81 91
    final Dialog dialog = builder.create();
82 92
    dialog.setCanceledOnTouchOutside(false);
83 93

  
94
    dialog.setOnShowListener(new DialogInterface.OnShowListener()
95
      {
96
      @Override
97
      public void onShow(DialogInterface dialog)
98
        {
99
        Button btnPositive = ((AlertDialog)dialog).getButton(Dialog.BUTTON_POSITIVE);
100
        btnPositive.setTextSize(TypedValue.COMPLEX_UNIT_PX, okSize);
101
        }
102
      });
103

  
84 104
    return dialog;
85 105
    }
86 106
  }
src/main/java/org/distorted/dialogs/RubikDialogNewRecord.java
26 26
import androidx.fragment.app.FragmentActivity;
27 27
import androidx.appcompat.app.AlertDialog;
28 28
import androidx.appcompat.app.AppCompatDialogFragment;
29

  
30
import android.util.DisplayMetrics;
31
import android.util.TypedValue;
29 32
import android.view.LayoutInflater;
30 33
import android.view.View;
31 34
import android.view.Window;
32 35
import android.view.WindowManager;
36
import android.widget.Button;
33 37
import android.widget.TextView;
34 38

  
35 39
import org.distorted.main.R;
......
73 77
    LayoutInflater inflater = act.getLayoutInflater();
74 78
    AlertDialog.Builder builder = new AlertDialog.Builder(act);
75 79

  
80
    DisplayMetrics displaymetrics = new DisplayMetrics();
81
    act.getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
82
    final float titleSize= displaymetrics.widthPixels * RubikActivity.MENU_BIG_TEXT_SIZE;
83
    final float okSize   = displaymetrics.widthPixels * RubikActivity.MENU_MEDIUM_TEXT_SIZE;
84
    final float textSize = displaymetrics.widthPixels * RubikActivity.MENU_BIG_TEXT_SIZE;
85

  
76 86
    TextView tv = (TextView) inflater.inflate(R.layout.dialog_title, null);
87
    tv.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleSize);
77 88
    tv.setText(R.string.new_record);
78 89
    builder.setCustomTitle(tv);
79 90
    builder.setCancelable(true);
......
138 149

  
139 150
    final View view = inflater.inflate(R.layout.dialog_new_record, null);
140 151
    TextView text = view.findViewById(R.id.new_record_time);
152
    text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
141 153
    text.setText(getString(R.string.ti_placeholder, (time/100)/10.0f));
142 154
    builder.setView(view);
143 155

  
156
    TextView submit = view.findViewById(R.id.new_record_submit);
157
    submit.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
158

  
144 159
    Dialog dialog = builder.create();
145 160

  
146 161
    dialog.setCanceledOnTouchOutside(false);
......
152 167
      window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
153 168
      }
154 169

  
170
    dialog.setOnShowListener(new DialogInterface.OnShowListener()
171
      {
172
      @Override
173
      public void onShow(DialogInterface dialog)
174
        {
175
        Button btnPositive = ((AlertDialog)dialog).getButton(Dialog.BUTTON_POSITIVE);
176
        btnPositive.setTextSize(TypedValue.COMPLEX_UNIT_PX, okSize);
177
        Button btnNegative = ((AlertDialog)dialog).getButton(Dialog.BUTTON_NEGATIVE);
178
        btnNegative.setTextSize(TypedValue.COMPLEX_UNIT_PX, okSize);
179
        }
180
      });
181

  
155 182
    return dialog;
156 183
    }
157 184
  }
src/main/java/org/distorted/dialogs/RubikDialogSetName.java
28 28
import androidx.appcompat.app.AppCompatDialogFragment;
29 29
import android.text.Editable;
30 30
import android.text.TextWatcher;
31
import android.util.DisplayMetrics;
32
import android.util.TypedValue;
31 33
import android.view.LayoutInflater;
32 34
import android.view.View;
33 35
import android.view.Window;
......
81 83
    LayoutInflater inflater = act.getLayoutInflater();
82 84
    AlertDialog.Builder builder = new AlertDialog.Builder(act);
83 85

  
86
    DisplayMetrics displaymetrics = new DisplayMetrics();
87
    act.getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
88
    final float titleSize= displaymetrics.widthPixels * RubikActivity.MENU_BIG_TEXT_SIZE;
89
    final float okSize   = displaymetrics.widthPixels * RubikActivity.MENU_MEDIUM_TEXT_SIZE;
90
    final float textSize = displaymetrics.widthPixels * RubikActivity.MENU_SMALL_TEXT_SIZE;
91

  
84 92
    Bundle args = getArguments();
85 93
    String name;
86 94

  
......
96 104
    boolean first = name.length()==0;
97 105

  
98 106
    TextView tv = (TextView) inflater.inflate(R.layout.dialog_title, null);
107
    tv.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleSize);
99 108
    tv.setText( first ? R.string.choose_name : R.string.name_taken);
100 109
    builder.setCustomTitle(tv);
101 110

  
102 111
    final View view = inflater.inflate(R.layout.dialog_set_name, null);
103 112
    TextView text = view.findViewById(R.id.set_name_message);
113
    text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
104 114
    mEdit = view.findViewById(R.id.set_name);
115
    mEdit.setHeight( (int)(2*titleSize) );
116
    mEdit.setTextSize(TypedValue.COMPLEX_UNIT_PX, 1.5f*titleSize);
105 117

  
106 118
    if( first )
107 119
      {
......
179 191
      window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
180 192
      }
181 193

  
194
    dialog.setOnShowListener(new DialogInterface.OnShowListener()
195
      {
196
      @Override
197
      public void onShow(DialogInterface dialog)
198
        {
199
        Button btnPositive = ((AlertDialog)dialog).getButton(Dialog.BUTTON_POSITIVE);
200
        btnPositive.setTextSize(TypedValue.COMPLEX_UNIT_PX, okSize);
201
        }
202
      });
203

  
182 204
    return dialog;
183 205
    }
184 206
  }
src/main/java/org/distorted/dialogs/RubikDialogSolved.java
26 26
import androidx.fragment.app.FragmentActivity;
27 27
import androidx.appcompat.app.AlertDialog;
28 28
import androidx.appcompat.app.AppCompatDialogFragment;
29

  
30
import android.util.DisplayMetrics;
31
import android.util.TypedValue;
29 32
import android.view.LayoutInflater;
30 33
import android.view.View;
31 34
import android.view.Window;
32 35
import android.view.WindowManager;
36
import android.widget.Button;
33 37
import android.widget.TextView;
34 38

  
35 39
import org.distorted.main.R;
......
48 52
    LayoutInflater inflater = act.getLayoutInflater();
49 53
    AlertDialog.Builder builder = new AlertDialog.Builder(act);
50 54

  
55
    DisplayMetrics displaymetrics = new DisplayMetrics();
56
    act.getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
57
    final float titleSize= displaymetrics.widthPixels * RubikActivity.MENU_BIG_TEXT_SIZE;
58
    final float okSize   = displaymetrics.widthPixels * RubikActivity.MENU_MEDIUM_TEXT_SIZE;
59
    final float textSize = displaymetrics.widthPixels * RubikActivity.MENU_BIG_TEXT_SIZE;
60

  
51 61
    TextView tv = (TextView) inflater.inflate(R.layout.dialog_title, null);
62
    tv.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleSize);
52 63
    tv.setText(R.string.solved);
53 64
    builder.setCustomTitle(tv);
54 65

  
......
77 88

  
78 89
    final View view = inflater.inflate(R.layout.dialog_solved, null);
79 90
    TextView text = view.findViewById(R.id.solved_time);
91
    text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
80 92
    text.setText(getString(R.string.ti_placeholder, (time/100)/10.0f));
81 93
    builder.setView(view);
82 94

  
......
91 103
      window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
92 104
      }
93 105

  
106
    dialog.setOnShowListener(new DialogInterface.OnShowListener()
107
      {
108
      @Override
109
      public void onShow(DialogInterface dialog)
110
        {
111
        Button btnPositive = ((AlertDialog)dialog).getButton(Dialog.BUTTON_POSITIVE);
112
        btnPositive.setTextSize(TypedValue.COMPLEX_UNIT_PX, okSize);
113
        }
114
      });
115

  
94 116
    return dialog;
95 117
    }
96 118
  }
src/main/java/org/distorted/dialogs/RubikDialogSolverError.java
26 26
import androidx.fragment.app.FragmentActivity;
27 27
import androidx.appcompat.app.AlertDialog;
28 28
import androidx.appcompat.app.AppCompatDialogFragment;
29

  
30
import android.util.DisplayMetrics;
31
import android.util.TypedValue;
29 32
import android.view.LayoutInflater;
30 33
import android.view.View;
31 34
import android.view.Window;
32 35
import android.view.WindowManager;
36
import android.widget.Button;
33 37
import android.widget.TextView;
34 38

  
35 39
import org.distorted.main.R;
40
import org.distorted.main.RubikActivity;
36 41

  
37 42
///////////////////////////////////////////////////////////////////////////////////////////////////
38 43

  
......
46 51
    LayoutInflater inflater = act.getLayoutInflater();
47 52
    AlertDialog.Builder builder = new AlertDialog.Builder(act);
48 53

  
54
    DisplayMetrics displaymetrics = new DisplayMetrics();
55
    act.getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
56
    final float titleSize= displaymetrics.widthPixels * RubikActivity.MENU_BIG_TEXT_SIZE;
57
    final float okSize   = displaymetrics.widthPixels * RubikActivity.MENU_MEDIUM_TEXT_SIZE;
58
    final float textSize = displaymetrics.widthPixels * RubikActivity.MENU_BIG_TEXT_SIZE;
59

  
49 60
    TextView tv = (TextView) inflater.inflate(R.layout.dialog_title, null);
61
    tv.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleSize);
50 62
    tv.setText(R.string.error);
51 63
    builder.setCustomTitle(tv);
52 64

  
......
74 86

  
75 87
    final View view = inflater.inflate(R.layout.dialog_solver_error, null);
76 88
    TextView text = view.findViewById(R.id.solver_error);
89
    text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
77 90
    text.setText(errorStr);
78 91
    builder.setView(view);
79 92

  
......
88 101
      window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
89 102
      }
90 103

  
104
    dialog.setOnShowListener(new DialogInterface.OnShowListener()
105
      {
106
      @Override
107
      public void onShow(DialogInterface dialog)
108
        {
109
        Button btnPositive = ((AlertDialog)dialog).getButton(Dialog.BUTTON_POSITIVE);
110
        btnPositive.setTextSize(TypedValue.COMPLEX_UNIT_PX, okSize);
111
        }
112
      });
113

  
91 114
    return dialog;
92 115
    }
93 116
  }

Also available in: Unified diff