Revision 362807f0
Added by Leszek Koltunski over 5 years ago
| src/main/java/org/distorted/dialogs/RubikDialogScoresPagerAdapter.java | ||
|---|---|---|
| 24 | 24 | import androidx.fragment.app.FragmentActivity; | 
| 25 | 25 | import androidx.viewpager.widget.PagerAdapter; | 
| 26 | 26 | import androidx.viewpager.widget.ViewPager; | 
| 27 |  | |
| 28 | import android.util.DisplayMetrics; | |
| 27 | 29 | import android.view.View; | 
| 28 | 30 | import android.view.ViewGroup; | 
| 29 | 31 | import android.widget.LinearLayout; | 
| ... | ... | |
| 198 | 200 | @NonNull | 
| 199 | 201 | public Object instantiateItem(@NonNull ViewGroup collection, int position) | 
| 200 | 202 |     {
 | 
| 201 | mViews[position] = new RubikDialogScoresView(mAct, mIsSubmitting); | |
| 203 | DisplayMetrics metrics = mAct.getResources().getDisplayMetrics(); | |
| 204 |  | |
| 205 | mViews[position] = new RubikDialogScoresView(mAct, metrics.heightPixels, mIsSubmitting); | |
| 202 | 206 | collection.addView(mViews[position]); | 
| 203 | 207 |  | 
| 204 | 208 | boolean allCreated = true; | 
| src/main/java/org/distorted/dialogs/RubikDialogScoresView.java | ||
|---|---|---|
| 23 | 23 | import android.content.res.Resources; | 
| 24 | 24 | import androidx.fragment.app.FragmentActivity; | 
| 25 | 25 | import android.util.AttributeSet; | 
| 26 | import android.util.TypedValue; | |
| 26 | 27 | import android.view.View; | 
| 27 | 28 | import android.widget.FrameLayout; | 
| 28 | 29 | import android.widget.ImageView; | 
| ... | ... | |
| 30 | 31 | import android.widget.TextView; | 
| 31 | 32 |  | 
| 32 | 33 | import org.distorted.main.R; | 
| 34 | import org.distorted.main.RubikActivity; | |
| 33 | 35 | import org.distorted.objects.RubikObjectList; | 
| 34 | 36 | import org.distorted.scores.RubikScores; | 
| 35 | 37 |  | 
| ... | ... | |
| 39 | 41 |  | 
| 40 | 42 | public class RubikDialogScoresView extends FrameLayout | 
| 41 | 43 |   {
 | 
| 42 | LinearLayout mLayout; | |
| 44 | private LinearLayout mLayout; | |
| 45 | private int mWidth; | |
| 43 | 46 |  | 
| 44 | 47 | /////////////////////////////////////////////////////////////////////////////////////////////////// | 
| 45 | 48 |  | 
| ... | ... | |
| 57 | 60 |  | 
| 58 | 61 | /////////////////////////////////////////////////////////////////////////////////////////////////// | 
| 59 | 62 |  | 
| 60 | public RubikDialogScoresView(Context context, boolean isSubmitting) | |
| 63 |   public RubikDialogScoresView(Context context, int width, boolean isSubmitting)
 | |
| 61 | 64 |     {
 | 
| 62 | 65 | super(context); | 
| 63 | 66 |  | 
| 67 | mWidth = width; | |
| 68 |  | |
| 64 | 69 | View view = inflate(context, R.layout.dialog_scores_downloading, null); | 
| 65 | 70 | addView(view); | 
| 66 | 71 | TextView text = findViewById(R.id.message_text); | 
| ... | ... | |
| 75 | 80 | TextView text = levelLayout.findViewById(R.id.scoresScrambleTitle); | 
| 76 | 81 | text.setText(act.getString(R.string.lv_placeholder,level+1)); | 
| 77 | 82 |  | 
| 83 | int size = (int)(mWidth* RubikActivity.SCORES_LEVEL_TEXT); | |
| 84 | text.setTextSize(TypedValue.COMPLEX_UNIT_PX, size); | |
| 85 |  | |
| 78 | 86 | Resources res = act.getResources(); | 
| 79 | 87 | String packageName = act.getPackageName(); | 
| 80 | 88 |  | 
| ... | ... | |
| 93 | 101 | String theirTime; | 
| 94 | 102 | int theirCountryID; | 
| 95 | 103 |  | 
| 104 | int height = (int)(mWidth* RubikActivity.SCORES_ITEM_TEXT); | |
| 96 | 105 | int white = res.getColor(R.color.white); | 
| 97 | 106 | int red = res.getColor(R.color.red); | 
| 98 | 107 | boolean equals; | 
| ... | ... | |
| 104 | 113 | if( !mySubmitted && myRecordInSeconds<time[j] && !inserted ) | 
| 105 | 114 |           {
 | 
| 106 | 115 | inserted = true; | 
| 107 | View row = createRow(act, myCountryID, myName, myRecord, red); | |
| 116 |           View row = createRow(act, myCountryID, myName, myRecord, height, red);
 | |
| 108 | 117 | levelLayout.addView(row); | 
| 109 | 118 | } | 
| 110 | 119 |  | 
| ... | ... | |
| 115 | 124 | if( equals ) inserted=true; | 
| 116 | 125 | theirCountryID = res.getIdentifier( country[j], "drawable", packageName); | 
| 117 | 126 | theirTime = Float.toString(time[j]); | 
| 118 | View row = createRow(act, theirCountryID, name[j], theirTime, equals ? red:white); | |
| 127 |           View row = createRow(act, theirCountryID, name[j], theirTime, height, equals ? red:white);
 | |
| 119 | 128 | levelLayout.addView(row); | 
| 120 | 129 | } | 
| 121 | 130 | } | 
| ... | ... | |
| 123 | 132 |  | 
| 124 | 133 | if( !inserted ) | 
| 125 | 134 |       {
 | 
| 126 | View row = createRow(act, myCountryID, myName, myRecord, red); | |
| 135 |       View row = createRow(act, myCountryID, myName, myRecord, height, red);
 | |
| 127 | 136 | levelLayout.addView(row); | 
| 128 | 137 | } | 
| 129 | 138 |  | 
| ... | ... | |
| 132 | 141 |  | 
| 133 | 142 | /////////////////////////////////////////////////////////////////////////////////////////////////// | 
| 134 | 143 |  | 
| 135 | private View createRow(FragmentActivity act, int countryID, String name, String time, int color) | |
| 144 |   private View createRow(FragmentActivity act, int countryID, String name, String time, int height, int color)
 | |
| 136 | 145 |     {
 | 
| 137 | 146 | View row = inflate(act, R.layout.dialog_scores_scramble_row, null); | 
| 138 | 147 |  | 
| ... | ... | |
| 147 | 156 | textName.setTextColor(color); | 
| 148 | 157 | textTime.setTextColor(color); | 
| 149 | 158 |  | 
| 159 | textName.setTextSize(TypedValue.COMPLEX_UNIT_PX, height); | |
| 160 | textTime.setTextSize(TypedValue.COMPLEX_UNIT_PX, height); | |
| 161 |  | |
| 150 | 162 | return row; | 
| 151 | 163 | } | 
| 152 | 164 |  | 
| src/main/java/org/distorted/main/RubikActivity.java | ||
|---|---|---|
| 52 | 52 | public static final float MENU_ITEM_SIZE = 0.12f; | 
| 53 | 53 | public static final float PATTERN_GROUP_TEXT = 0.03f; | 
| 54 | 54 | public static final float PATTERN_CHILD_TEXT = 0.02f; | 
| 55 | public static final float SCORES_LEVEL_TEXT = 0.035f; | |
| 56 | public static final float SCORES_ITEM_TEXT = 0.030f; | |
| 55 | 57 |  | 
| 56 | 58 | public static final float MENU_BIG_TEXT_SIZE = 0.05f; | 
| 57 | 59 | public static final float MENU_MEDIUM_TEXT_SIZE= 0.04f; | 
| src/main/res/layout/dialog_scores_scramble_row.xml | ||
|---|---|---|
| 1 | 1 | <?xml version="1.0" encoding="utf-8"?> | 
| 2 | 2 | <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | 
| 3 | 3 | android:layout_width="fill_parent" | 
| 4 |     android:layout_height="0dp"
 | |
| 4 |     android:layout_height="wrap_content"
 | |
| 5 | 5 | android:paddingBottom="2dp" | 
| 6 | 6 | android:paddingTop="2dp" | 
| 7 | 7 | android:orientation="horizontal" > | 
| ... | ... | |
| 10 | 10 | android:id="@+id/scoresScrambleRowCountry" | 
| 11 | 11 | android:layout_width="match_parent" | 
| 12 | 12 | android:layout_height="match_parent" | 
| 13 | android:paddingBottom="3dp" | |
| 14 | android:paddingTop="3dp" | |
| 13 | 15 | android:layout_weight="1.5" | 
| 14 | android:textSize="20sp" | |
| 15 | 16 | android:gravity="start" | 
| 16 | 17 | android:background="@color/black" /> | 
| 17 | 18 |  | 
| src/main/res/layout/dialog_scores_scramble_title.xml | ||
|---|---|---|
| 14 | 14 | <TextView | 
| 15 | 15 | android:id="@+id/scoresScrambleTitle" | 
| 16 | 16 | android:layout_width="match_parent" | 
| 17 |         android:layout_height="32dp"
 | |
| 17 |         android:layout_height="wrap_content"
 | |
| 18 | 18 | android:textSize="24sp" | 
| 19 | 19 | android:gravity="center" | 
| 20 | 20 | android:background="@color/grey" | 
Also available in: Unified diff
Make the Scores Dialog screen-size invariant.