Revision a5972f92
Added by Leszek Koltunski about 2 months ago
src/main/java/org/distorted/main/MainActivity.java | ||
---|---|---|
16 | 16 |
import android.content.res.Configuration; |
17 | 17 |
import android.os.Build; |
18 | 18 |
import android.os.Bundle; |
19 |
import android.util.DisplayMetrics; |
|
20 | 19 |
import android.util.TypedValue; |
21 | 20 |
import android.view.DisplayCutout; |
22 | 21 |
import android.view.View; |
23 | 22 |
import android.view.ViewGroup; |
24 |
import android.view.WindowManager; |
|
25 | 23 |
import android.widget.LinearLayout; |
26 | 24 |
import android.widget.ScrollView; |
27 | 25 |
import android.widget.TextView; |
28 | 26 |
|
29 | 27 |
import androidx.annotation.NonNull; |
30 |
import androidx.appcompat.app.AppCompatActivity; |
|
31 | 28 |
import androidx.preference.PreferenceManager; |
32 | 29 |
|
33 | 30 |
import com.google.firebase.analytics.FirebaseAnalytics; |
... | ... | |
35 | 32 |
|
36 | 33 |
import org.distorted.bandaged.BandagedActivity; |
37 | 34 |
import org.distorted.config.ConfigActivity; |
35 |
import org.distorted.helpers.BaseActivity; |
|
38 | 36 |
import org.distorted.info.InfoActivity; |
39 | 37 |
import org.distorted.dialogs.RubikDialogAbout; |
40 | 38 |
import org.distorted.dialogs.RubikDialogCreators; |
... | ... | |
54 | 52 |
|
55 | 53 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
56 | 54 |
|
57 |
public class MainActivity extends AppCompatActivity implements RubikNetwork.Updatee, RubikDialogScores.ScoresInvoker
|
|
55 |
public class MainActivity extends BaseActivity implements RubikNetwork.Updatee, RubikDialogScores.ScoresInvoker
|
|
58 | 56 |
{ |
59 |
public static final float RATIO_BAR = 0.080f; |
|
60 |
public static final int FLAGS = View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |
|
61 |
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
|
62 |
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
|
63 |
| View.SYSTEM_UI_FLAG_FULLSCREEN |
|
64 |
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY; |
|
65 |
|
|
66 | 57 |
private boolean mJustStarted; |
67 | 58 |
private FirebaseAnalytics mFirebaseAnalytics; |
68 |
private int mCurrentApiVersion; |
|
69 | 59 |
private String mOldVersion, mCurrVersion; |
70 |
private int mScreenWidth, mScreenHeight; |
|
71 | 60 |
private TextView mBubbleUpdates; |
72 | 61 |
private int mNumUpdates; |
73 | 62 |
private int mCurrentObject; |
... | ... | |
79 | 68 |
@Override |
80 | 69 |
protected void onCreate(Bundle savedState) |
81 | 70 |
{ |
82 |
setTheme(R.style.MaterialThemeNoActionBar); |
|
83 | 71 |
super.onCreate(savedState); |
84 | 72 |
setContentView(R.layout.main); |
85 |
hideNavigationBar(); |
|
86 | 73 |
|
87 | 74 |
mCurrentObject = 0; |
88 | 75 |
mJustStarted = true; |
89 | 76 |
mFirebaseAnalytics = FirebaseAnalytics.getInstance(this); |
90 | 77 |
|
78 |
hideNavigationBar(); |
|
91 | 79 |
cutoutHack(); |
92 | 80 |
computeHeights(); |
93 | 81 |
|
... | ... | |
127 | 115 |
layoutBot.setLayoutParams(pL); |
128 | 116 |
} |
129 | 117 |
|
130 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
131 |
|
|
132 |
private void hideNavigationBar() |
|
133 |
{ |
|
134 |
mCurrentApiVersion = Build.VERSION.SDK_INT; |
|
135 |
|
|
136 |
if(mCurrentApiVersion >= Build.VERSION_CODES.KITKAT) |
|
137 |
{ |
|
138 |
final View decorView = getWindow().getDecorView(); |
|
139 |
|
|
140 |
decorView.setSystemUiVisibility(FLAGS); |
|
141 |
|
|
142 |
decorView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() |
|
143 |
{ |
|
144 |
@Override |
|
145 |
public void onSystemUiVisibilityChange(int visibility) |
|
146 |
{ |
|
147 |
if((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) |
|
148 |
{ |
|
149 |
decorView.setSystemUiVisibility(FLAGS); |
|
150 |
} |
|
151 |
} |
|
152 |
}); |
|
153 |
} |
|
154 |
} |
|
155 |
|
|
156 | 118 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
157 | 119 |
|
158 | 120 |
@Override |
... | ... | |
182 | 144 |
} |
183 | 145 |
} |
184 | 146 |
|
185 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
186 |
// do not avoid cutouts |
|
187 |
|
|
188 |
private void cutoutHack() |
|
189 |
{ |
|
190 |
if( Build.VERSION.SDK_INT >= Build.VERSION_CODES.P ) |
|
191 |
{ |
|
192 |
getWindow().getAttributes().layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES; |
|
193 |
} |
|
194 |
} |
|
195 |
|
|
196 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
197 |
|
|
198 |
private void getWindowWidth(Configuration conf) |
|
199 |
{ |
|
200 |
int dpi = getResources().getDisplayMetrics().densityDpi; |
|
201 |
float conv = ((float) dpi/DisplayMetrics.DENSITY_DEFAULT); |
|
202 |
|
|
203 |
mScreenWidth = (int) (conf.screenWidthDp*conv + 0.5f); |
|
204 |
mScreenHeight= (int) (conf.screenHeightDp*conv + 0.5f); |
|
205 |
} |
|
206 |
|
|
207 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
208 |
|
|
209 |
@Override |
|
210 |
public void onWindowFocusChanged(boolean hasFocus) |
|
211 |
{ |
|
212 |
super.onWindowFocusChanged(hasFocus); |
|
213 |
|
|
214 |
if( mCurrentApiVersion >= Build.VERSION_CODES.KITKAT && hasFocus ) |
|
215 |
{ |
|
216 |
getWindow().getDecorView().setSystemUiVisibility(FLAGS); |
|
217 |
} |
|
218 |
} |
|
219 |
|
|
220 | 147 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
221 | 148 |
|
222 | 149 |
@Override |
Also available in: Unified diff
common code from all activities to one BaseActivity