Revision a5972f92
Added by Leszek Koltunski about 2 months ago
src/main/java/org/distorted/info/InfoActivity.java | ||
---|---|---|
11 | 11 |
|
12 | 12 |
import java.io.InputStream; |
13 | 13 |
|
14 |
import android.os.Build; |
|
15 | 14 |
import android.os.Bundle; |
16 |
import android.util.DisplayMetrics; |
|
17 |
import android.view.View; |
|
18 |
import android.view.ViewGroup; |
|
19 |
import android.view.WindowManager; |
|
20 |
import android.widget.LinearLayout; |
|
21 |
import androidx.appcompat.app.AppCompatActivity; |
|
22 | 15 |
|
16 |
import org.distorted.helpers.BaseActivity; |
|
23 | 17 |
import org.distorted.library.main.DistortedLibrary; |
24 |
import org.distorted.main.MainActivity; |
|
25 | 18 |
import org.distorted.objectlib.main.InitAssets; |
26 | 19 |
import org.distorted.objectlib.main.ObjectControl; |
27 | 20 |
import org.distorted.main.R; |
... | ... | |
32 | 25 |
|
33 | 26 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
34 | 27 |
|
35 |
public class InfoActivity extends AppCompatActivity
|
|
28 |
public class InfoActivity extends BaseActivity
|
|
36 | 29 |
{ |
37 | 30 |
private static final int ACTIVITY_NUMBER = 1; |
38 |
private static final float RATIO_BAR = MainActivity.RATIO_BAR; |
|
39 |
public static final int FLAGS = MainActivity.FLAGS; |
|
40 |
|
|
41 |
private static int mScreenWidth, mScreenHeight; |
|
42 |
private int mCurrentApiVersion; |
|
43 | 31 |
private InfoScreen mScreen; |
44 | 32 |
private int mObjectOrdinal; |
45 |
private int mHeightBar; |
|
46 | 33 |
|
47 | 34 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
48 | 35 |
|
49 | 36 |
@Override |
50 | 37 |
protected void onCreate(Bundle savedState) |
51 | 38 |
{ |
52 |
setTheme(R.style.MaterialThemeNoActionBar); |
|
53 | 39 |
super.onCreate(savedState); |
54 | 40 |
DistortedLibrary.onCreate(ACTIVITY_NUMBER); |
55 | 41 |
setContentView(R.layout.info); |
56 | 42 |
|
57 | 43 |
Bundle b = getIntent().getExtras(); |
58 |
|
|
59 | 44 |
if(b != null) mObjectOrdinal = b.getInt("obj"); |
60 | 45 |
|
61 |
DisplayMetrics displaymetrics = new DisplayMetrics(); |
|
62 |
getWindowManager().getDefaultDisplay().getRealMetrics(displaymetrics); |
|
63 |
mScreenWidth =displaymetrics.widthPixels; |
|
64 |
mScreenHeight=displaymetrics.heightPixels; |
|
65 |
|
|
46 |
computeScreenDimensions(); |
|
66 | 47 |
hideNavigationBar(); |
67 | 48 |
cutoutHack(); |
68 |
computeBarHeights(); |
|
69 |
} |
|
70 |
|
|
71 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
72 |
// this does not include possible insets |
|
73 |
|
|
74 |
private void computeBarHeights() |
|
75 |
{ |
|
76 |
int barHeight = (int)(mScreenHeight*RATIO_BAR); |
|
77 |
mHeightBar = barHeight; |
|
78 |
|
|
79 |
LinearLayout layout = findViewById(R.id.lowerBar); |
|
80 |
ViewGroup.LayoutParams params = layout.getLayoutParams(); |
|
81 |
params.height = barHeight; |
|
82 |
layout.setLayoutParams(params); |
|
83 |
} |
|
84 |
|
|
85 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
86 |
|
|
87 |
private void hideNavigationBar() |
|
88 |
{ |
|
89 |
mCurrentApiVersion = Build.VERSION.SDK_INT; |
|
90 |
|
|
91 |
if(mCurrentApiVersion >= Build.VERSION_CODES.KITKAT) |
|
92 |
{ |
|
93 |
final View decorView = getWindow().getDecorView(); |
|
94 |
|
|
95 |
decorView.setSystemUiVisibility(FLAGS); |
|
96 |
|
|
97 |
decorView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() |
|
98 |
{ |
|
99 |
@Override |
|
100 |
public void onSystemUiVisibilityChange(int visibility) |
|
101 |
{ |
|
102 |
if((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) |
|
103 |
{ |
|
104 |
decorView.setSystemUiVisibility(FLAGS); |
|
105 |
} |
|
106 |
} |
|
107 |
}); |
|
108 |
} |
|
109 |
} |
|
110 |
|
|
111 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
112 |
// do not avoid cutouts |
|
113 |
|
|
114 |
private void cutoutHack() |
|
115 |
{ |
|
116 |
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) |
|
117 |
{ |
|
118 |
getWindow().getAttributes().layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES; |
|
119 |
} |
|
120 |
} |
|
121 |
|
|
122 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
123 |
|
|
124 |
@Override |
|
125 |
public void onWindowFocusChanged(boolean hasFocus) |
|
126 |
{ |
|
127 |
super.onWindowFocusChanged(hasFocus); |
|
128 |
|
|
129 |
if(mCurrentApiVersion >= Build.VERSION_CODES.KITKAT && hasFocus) |
|
130 |
{ |
|
131 |
getWindow().getDecorView().setSystemUiVisibility(FLAGS); |
|
132 |
} |
|
49 |
computeLowerBarHeight(RATIO_BAR); |
|
133 | 50 |
} |
134 | 51 |
|
135 | 52 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
197 | 114 |
|
198 | 115 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
199 | 116 |
// PUBLIC API |
200 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
201 |
|
|
202 |
public void changeObject(int ordinal) |
|
203 |
{ |
|
204 |
mObjectOrdinal = ordinal; |
|
205 |
RubikObject object = RubikObjectList.getObject(ordinal); |
|
206 |
InfoSurfaceView view = findViewById(R.id.infoSurfaceView); |
|
207 |
ObjectControl control = view.getObjectControl(); |
|
208 |
changeIfDifferent(object,ordinal,control); |
|
209 |
} |
|
210 |
|
|
211 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
212 |
|
|
213 |
public int getHeightBar() |
|
214 |
{ |
|
215 |
return mHeightBar; |
|
216 |
} |
|
217 |
|
|
218 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
219 |
|
|
220 |
public int getScreenWidthInPixels() |
|
221 |
{ |
|
222 |
return mScreenWidth; |
|
223 |
} |
|
224 |
|
|
225 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
226 |
|
|
227 |
public int getScreenHeightInPixels() |
|
228 |
{ |
|
229 |
return mScreenHeight; |
|
230 |
} |
|
231 |
|
|
232 | 117 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
233 | 118 |
|
234 | 119 |
public ObjectControl getControl() |
Also available in: Unified diff
common code from all activities to one BaseActivity