| 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 | 
 | 
 
Improvements to the UI - make it proportional regardless of the physical screen size. (Part 5 - first 3 Dialogs)