Revision a5972f92
Added by Leszek Koltunski about 2 months ago
src/main/java/org/distorted/playui/PlayActivity.java | ||
---|---|---|
14 | 14 |
import android.content.SharedPreferences; |
15 | 15 |
import android.os.Build; |
16 | 16 |
import android.os.Bundle; |
17 |
import android.util.DisplayMetrics; |
|
18 | 17 |
import android.view.DisplayCutout; |
19 |
import android.view.View; |
|
20 | 18 |
import android.view.ViewGroup; |
21 |
import android.view.WindowManager; |
|
22 | 19 |
import android.widget.LinearLayout; |
23 | 20 |
|
24 |
import androidx.appcompat.app.AppCompatActivity; |
|
25 | 21 |
import androidx.preference.PreferenceManager; |
26 | 22 |
|
27 | 23 |
import com.google.firebase.analytics.FirebaseAnalytics; |
28 | 24 |
|
29 | 25 |
import org.distorted.dialogs.RubikDialogScores; |
30 | 26 |
import org.distorted.external.RubikScores; |
27 |
import org.distorted.helpers.BaseActivity; |
|
31 | 28 |
import org.distorted.library.main.DistortedLibrary; |
32 | 29 |
import org.distorted.objectlib.main.InitAssets; |
33 | 30 |
import org.distorted.objectlib.main.ObjectControl; |
34 | 31 |
import org.distorted.objectlib.main.TwistyObject; |
35 | 32 |
import org.distorted.dialogs.RubikDialogError; |
36 | 33 |
import org.distorted.external.RubikFiles; |
37 |
import org.distorted.main.MainActivity; |
|
38 | 34 |
import org.distorted.main.R; |
39 | 35 |
import org.distorted.objects.RubikObject; |
40 | 36 |
import org.distorted.objects.RubikObjectList; |
... | ... | |
42 | 38 |
|
43 | 39 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
44 | 40 |
|
45 |
public class PlayActivity extends AppCompatActivity implements RubikDialogScores.ScoresInvoker
|
|
41 |
public class PlayActivity extends BaseActivity implements RubikDialogScores.ScoresInvoker
|
|
46 | 42 |
{ |
47 |
public static final int FLAGS = MainActivity.FLAGS; |
|
48 | 43 |
public static final float TITLE_TEXT_SIZE= 0.060f; |
49 | 44 |
private static final int ACTIVITY_NUMBER = 6; |
50 |
private static final float RATIO_BAR = MainActivity.RATIO_BAR; |
|
51 | 45 |
private static final float RATIO_INSET = 0.09f; |
52 | 46 |
|
53 | 47 |
private static final String KEY_FREE = "movesController_free"; |
54 | 48 |
private static final String KEY_SOLV = "movesController_solv"; |
55 | 49 |
|
56 |
private static int mScreenWidth, mScreenHeight; |
|
57 |
private int mCurrentApiVersion; |
|
58 | 50 |
private String mObjectName; |
59 | 51 |
private int mNumScrambles; |
60 |
private int mHeightUpperBar; |
|
61 | 52 |
private boolean mObjectLocal; |
62 | 53 |
private int mObjectOrdinal; |
63 | 54 |
private int mLevel; |
... | ... | |
70 | 61 |
@Override |
71 | 62 |
protected void onCreate(Bundle savedState) |
72 | 63 |
{ |
73 |
setTheme(R.style.MaterialThemeNoActionBar); |
|
74 | 64 |
super.onCreate(savedState); |
75 | 65 |
DistortedLibrary.onCreate(ACTIVITY_NUMBER); |
76 | 66 |
setContentView(R.layout.play); |
... | ... | |
99 | 89 |
|
100 | 90 |
mModeFree = (mLevel<0); |
101 | 91 |
|
102 |
DisplayMetrics displaymetrics = new DisplayMetrics(); |
|
103 |
getWindowManager().getDefaultDisplay().getRealMetrics(displaymetrics); |
|
104 |
mScreenWidth =displaymetrics.widthPixels; |
|
105 |
mScreenHeight=displaymetrics.heightPixels; |
|
106 |
|
|
92 |
computeScreenDimensions(); |
|
107 | 93 |
hideNavigationBar(); |
108 | 94 |
cutoutHack(); |
109 |
computeBarHeights(); |
|
110 |
} |
|
111 |
|
|
112 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
113 |
// this does not include possible insets |
|
114 |
|
|
115 |
private void computeBarHeights() |
|
116 |
{ |
|
117 |
int barHeight = (int)(mScreenHeight*RATIO_BAR); |
|
118 |
mHeightUpperBar = barHeight; |
|
119 |
|
|
120 |
LinearLayout layoutTop = findViewById(R.id.upperBar); |
|
121 |
LinearLayout layoutBot = findViewById(R.id.lowerBar); |
|
122 |
|
|
123 |
ViewGroup.LayoutParams paramsTop = layoutTop.getLayoutParams(); |
|
124 |
paramsTop.height = mHeightUpperBar; |
|
125 |
layoutTop.setLayoutParams(paramsTop); |
|
126 |
ViewGroup.LayoutParams paramsBot = layoutBot.getLayoutParams(); |
|
127 |
paramsBot.height = barHeight; |
|
128 |
layoutBot.setLayoutParams(paramsBot); |
|
129 |
} |
|
130 |
|
|
131 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
132 |
|
|
133 |
private void hideNavigationBar() |
|
134 |
{ |
|
135 |
mCurrentApiVersion = Build.VERSION.SDK_INT; |
|
136 |
|
|
137 |
if(mCurrentApiVersion >= Build.VERSION_CODES.KITKAT) |
|
138 |
{ |
|
139 |
final View decorView = getWindow().getDecorView(); |
|
140 |
|
|
141 |
decorView.setSystemUiVisibility(FLAGS); |
|
142 |
|
|
143 |
decorView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() |
|
144 |
{ |
|
145 |
@Override |
|
146 |
public void onSystemUiVisibilityChange(int visibility) |
|
147 |
{ |
|
148 |
if((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) |
|
149 |
{ |
|
150 |
decorView.setSystemUiVisibility(FLAGS); |
|
151 |
} |
|
152 |
} |
|
153 |
}); |
|
154 |
} |
|
95 |
computeUpperBarHeight(RATIO_BAR); |
|
96 |
computeLowerBarHeight(RATIO_BAR); |
|
155 | 97 |
} |
156 | 98 |
|
157 | 99 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
170 | 112 |
ViewGroup.LayoutParams paramsHid = layoutHid.getLayoutParams(); |
171 | 113 |
paramsHid.height = (int)(insetHeight*RATIO_INSET); |
172 | 114 |
layoutHid.setLayoutParams(paramsHid); |
173 |
mHeightUpperBar += paramsHid.height; |
|
174 |
} |
|
175 |
} |
|
176 |
|
|
177 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
178 |
// do not avoid cutouts |
|
179 |
|
|
180 |
private void cutoutHack() |
|
181 |
{ |
|
182 |
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) |
|
183 |
{ |
|
184 |
getWindow().getAttributes().layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES; |
|
185 |
} |
|
186 |
} |
|
187 |
|
|
188 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
189 |
|
|
190 |
@Override |
|
191 |
public void onWindowFocusChanged(boolean hasFocus) |
|
192 |
{ |
|
193 |
super.onWindowFocusChanged(hasFocus); |
|
194 |
|
|
195 |
if(mCurrentApiVersion >= Build.VERSION_CODES.KITKAT && hasFocus) |
|
196 |
{ |
|
197 |
getWindow().getDecorView().setSystemUiVisibility(FLAGS); |
|
198 | 115 |
} |
199 | 116 |
} |
200 | 117 |
|
... | ... | |
369 | 286 |
return mFirebaseAnalytics; |
370 | 287 |
} |
371 | 288 |
|
372 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
373 |
|
|
374 |
public int getScreenWidthInPixels() |
|
375 |
{ |
|
376 |
return mScreenWidth; |
|
377 |
} |
|
378 |
|
|
379 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
380 |
|
|
381 |
public int getScreenHeightInPixels() |
|
382 |
{ |
|
383 |
return mScreenHeight; |
|
384 |
} |
|
385 |
|
|
386 | 289 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
387 | 290 |
|
388 | 291 |
public int getNumScrambles() |
Also available in: Unified diff
common code from all activities to one BaseActivity