[Settings] Do not use deprecated API, onBackPressed
Bug: 318313238 Test: manual Change-Id: I616ea3cf4b2b89905d85380305df4853d4d5d626
This commit is contained in:
@@ -16,6 +16,8 @@
|
|||||||
|
|
||||||
package com.android.settings.localepicker;
|
package com.android.settings.localepicker;
|
||||||
|
|
||||||
|
import static android.window.OnBackInvokedDispatcher.PRIORITY_DEFAULT;
|
||||||
|
|
||||||
import android.app.FragmentTransaction;
|
import android.app.FragmentTransaction;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
@@ -23,6 +25,7 @@ import android.os.LocaleList;
|
|||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
|
import android.window.OnBackInvokedCallback;
|
||||||
|
|
||||||
import androidx.core.view.ViewCompat;
|
import androidx.core.view.ViewCompat;
|
||||||
|
|
||||||
@@ -39,6 +42,10 @@ public class LocalePickerWithRegionActivity extends SettingsBaseActivity
|
|||||||
|
|
||||||
private LocalePickerWithRegion mSelector;
|
private LocalePickerWithRegion mSelector;
|
||||||
|
|
||||||
|
private final OnBackInvokedCallback mOnBackInvokedCallback = () -> {
|
||||||
|
handleBackPressed();
|
||||||
|
};
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
@@ -52,7 +59,8 @@ public class LocalePickerWithRegionActivity extends SettingsBaseActivity
|
|||||||
: bundle.getParcelable(Settings.EXTRA_EXPLICIT_LOCALES, LocaleList.class);
|
: bundle.getParcelable(Settings.EXTRA_EXPLICIT_LOCALES, LocaleList.class);
|
||||||
Log.i(TAG, "Has explicit locales : " + explicitLocales);
|
Log.i(TAG, "Has explicit locales : " + explicitLocales);
|
||||||
}
|
}
|
||||||
|
getOnBackInvokedDispatcher()
|
||||||
|
.registerOnBackInvokedCallback(PRIORITY_DEFAULT, mOnBackInvokedCallback);
|
||||||
mSelector = LocalePickerWithRegion.createLanguagePicker(
|
mSelector = LocalePickerWithRegion.createLanguagePicker(
|
||||||
this,
|
this,
|
||||||
LocalePickerWithRegionActivity.this,
|
LocalePickerWithRegionActivity.this,
|
||||||
@@ -68,6 +76,12 @@ public class LocalePickerWithRegionActivity extends SettingsBaseActivity
|
|||||||
.commit();
|
.commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDestroy() {
|
||||||
|
super.onDestroy();
|
||||||
|
getOnBackInvokedDispatcher().unregisterOnBackInvokedCallback(mOnBackInvokedCallback);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
if (item.getItemId() == android.R.id.home) {
|
if (item.getItemId() == android.R.id.home) {
|
||||||
@@ -85,11 +99,6 @@ public class LocalePickerWithRegionActivity extends SettingsBaseActivity
|
|||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onBackPressed() {
|
|
||||||
handleBackPressed();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void handleBackPressed() {
|
private void handleBackPressed() {
|
||||||
if (getFragmentManager().getBackStackEntryCount() > 1) {
|
if (getFragmentManager().getBackStackEntryCount() > 1) {
|
||||||
super.onBackPressed();
|
super.onBackPressed();
|
||||||
|
Reference in New Issue
Block a user