Skip to content

Commit

Permalink
Fix deprecations and warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
andreynovikov committed Dec 28, 2023
1 parent 664e5e3 commit 1fe3a0f
Showing 1 changed file with 31 additions and 22 deletions.
53 changes: 31 additions & 22 deletions app/src/main/java/mobi/maptrek/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
import android.transition.TransitionValues;
import android.transition.Visibility;
import android.util.Pair;
import android.view.DisplayCutout;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.Menu;
Expand Down Expand Up @@ -452,7 +453,18 @@ protected void onCreate(Bundle savedInstanceState) {
mPanelBackground = resources.getColor(R.color.panelBackground, theme);
mPanelSolidBackground = resources.getColor(R.color.panelSolidBackground, theme);
mPanelExtendedBackground = resources.getColor(R.color.panelExtendedBackground, theme);
mStatusBarHeight = getStatusBarHeight();

mViews.getRoot().setOnApplyWindowInsetsListener((view, insets) -> {
mStatusBarHeight = insets.getSystemWindowInsetTop();
if (Build.VERSION.SDK_INT >= 28) {
DisplayCutout cutout = insets.getDisplayCutout();
if (cutout != null) {
// TODO: implement for bars
logger.error("DisplayCutout: {}", cutout.getSafeInsetTop());
}
}
return insets;
});

mMainHandler = new Handler(Looper.getMainLooper());
mBackgroundThread = new HandlerThread("BackgroundThread");
Expand Down Expand Up @@ -694,9 +706,6 @@ public void onChildViewRemoved(View parent, View child) {

setMapTheme();

//if (BuildConfig.DEBUG)
// StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectAll().penaltyLog().build());

mBackToast = Toast.makeText(this, R.string.msgBackQuit, Toast.LENGTH_SHORT);
mProgressHandler = new ProgressHandler(mViews.progressBar);

Expand Down Expand Up @@ -1724,17 +1733,27 @@ private void onMapsLongClicked() {
Resources resources = getResources();
String[] nightModes = resources.getStringArray(R.array.night_mode_array);
MenuItem item = menu.findItem(R.id.actionNightMode);
((TextView) item.getActionView()).setText(nightModes[AppCompatDelegate.getDefaultNightMode()]);
TextView view = (TextView) item.getActionView();
if (view != null)
view.setText(nightModes[AppCompatDelegate.getDefaultNightMode()]);
String[] mapStyles = resources.getStringArray(R.array.mapStyles);
item = menu.findItem(R.id.actionStyle);
((TextView) item.getActionView()).setText(mapStyles[Configuration.getMapStyle()]);
view = (TextView) item.getActionView();
if (view != null)
view.setText(mapStyles[Configuration.getMapStyle()]);
String[] sizes = resources.getStringArray(R.array.size_array);
item = menu.findItem(R.id.actionMapScale);
((TextView) item.getActionView()).setText(sizes[Configuration.getMapUserScale()]);
view = (TextView) item.getActionView();
if (view != null)
view.setText(sizes[Configuration.getMapUserScale()]);
item = menu.findItem(R.id.actionFontSize);
((TextView) item.getActionView()).setText(sizes[Configuration.getMapFontSize()]);
view = (TextView) item.getActionView();
if (view != null)
view.setText(sizes[Configuration.getMapFontSize()]);
item = menu.findItem(R.id.actionLanguage);
((TextView) item.getActionView()).setText(Configuration.getLanguage());
view = (TextView) item.getActionView();
if (view != null)
view.setText(Configuration.getLanguage());
menu.findItem(R.id.actionAutoTilt).setChecked(mAutoTilt != -1f);
});
showExtendPanel(PANEL_STATE.MAPS, "mapMenu", fragment);
Expand Down Expand Up @@ -4492,6 +4511,7 @@ public void onReceiveResult(int resultCode, Bundle resultData) {
}
}

/** @noinspection unused*/
@Subscribe
public void onConfigurationChanged(Configuration.ChangedEvent event) {
switch (event.key) {
Expand Down Expand Up @@ -4661,15 +4681,12 @@ private void hideSystemUI() {
Configuration.setHideSystemUI(true);
Configuration.accountFullScreen();

WindowInsetsControllerCompat windowInsetsController = ViewCompat.getWindowInsetsController(getWindow().getDecorView());
if (windowInsetsController == null)
return;
WindowInsetsControllerCompat windowInsetsController = WindowCompat.getInsetsController(getWindow(), getWindow().getDecorView());
// Configure the behavior of the hidden system bars
windowInsetsController.setSystemBarsBehavior(WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE);
// Hide the system bars.
windowInsetsController.hide(WindowInsetsCompat.Type.systemBars());

mStatusBarHeight = 0;
mMap.updateMap();
}

Expand All @@ -4681,18 +4698,9 @@ private void showSystemUI() {
// Show the system bars.
windowInsetsController.show(WindowInsetsCompat.Type.systemBars());

mStatusBarHeight = getStatusBarHeight();
mMap.updateMap();
}

private int getStatusBarHeight() {
int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
if (resourceId > 0)
return getResources().getDimensionPixelSize(resourceId);
else
return 0;
}

public boolean isOnline() {
// FIXME temporary
return false;
Expand Down Expand Up @@ -4723,6 +4731,7 @@ private double movingAverage(double current, double previous) {
return 0.2 * previous + 0.8 * current;
}

/** @noinspection unused*/
@Subscribe
public void onNewPluginEntry(Pair<String, Pair<Drawable, Intent>> entry) {
mPluginRepository.addPluginEntry(entry);
Expand Down

0 comments on commit 1fe3a0f

Please sign in to comment.