Depend on SettingsLib's version of lifecycle and FooterMixin.
The implementations have been imported into SettingsLib. Setting's copy can now be removed, which this change also does. Test: Manually check battery status, which uses FooterMixin, looks OK. make RunSettingsLibRobotTests && make RunSettingsRoboTests && make RunSettingsGoogleRoboTests Change-Id: I6539605fdad80d156ff5ff249e68df4a1c412067
This commit is contained in:
@@ -20,9 +20,9 @@ import android.content.Context;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.core.lifecycle.Lifecycle;
|
||||
import com.android.settings.core.lifecycle.LifecycleObserver;
|
||||
import com.android.settings.core.lifecycle.events.OnResume;
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
||||
import com.android.settingslib.core.lifecycle.events.OnResume;
|
||||
|
||||
public abstract class DynamicAvailabilityPreferenceController extends PreferenceController
|
||||
implements LifecycleObserver, OnResume {
|
||||
|
@@ -18,7 +18,7 @@ package com.android.settings.core;
|
||||
|
||||
import com.android.settings.core.instrumentation.Instrumentable;
|
||||
import com.android.settings.core.instrumentation.VisibilityLoggerMixin;
|
||||
import com.android.settings.core.lifecycle.ObservableActivity;
|
||||
import com.android.settingslib.core.lifecycle.ObservableActivity;
|
||||
|
||||
/**
|
||||
* Instrumented activity that logs visibility state.
|
||||
|
@@ -21,9 +21,9 @@ import android.content.Context;
|
||||
import com.android.settings.core.instrumentation.Instrumentable;
|
||||
import com.android.settings.core.instrumentation.MetricsFeatureProvider;
|
||||
import com.android.settings.core.instrumentation.VisibilityLoggerMixin;
|
||||
import com.android.settings.core.lifecycle.ObservableFragment;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settings.survey.SurveyMixin;
|
||||
import com.android.settingslib.core.lifecycle.ObservableFragment;
|
||||
|
||||
public abstract class InstrumentedFragment extends ObservableFragment implements Instrumentable {
|
||||
|
||||
@@ -49,4 +49,4 @@ public abstract class InstrumentedFragment extends ObservableFragment implements
|
||||
mVisibilityLoggerMixin.setSourceMetricsCategory(getActivity());
|
||||
super.onResume();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -22,9 +22,9 @@ import android.os.Bundle;
|
||||
import com.android.settings.core.instrumentation.Instrumentable;
|
||||
import com.android.settings.core.instrumentation.MetricsFeatureProvider;
|
||||
import com.android.settings.core.instrumentation.VisibilityLoggerMixin;
|
||||
import com.android.settings.core.lifecycle.ObservablePreferenceFragment;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settings.survey.SurveyMixin;
|
||||
import com.android.settingslib.core.lifecycle.ObservablePreferenceFragment;
|
||||
|
||||
/**
|
||||
* Instrumented fragment that logs visibility state.
|
||||
|
@@ -18,8 +18,8 @@ package com.android.settings.core.instrumentation;
|
||||
import android.content.Context;
|
||||
|
||||
import com.android.settings.DialogCreatable;
|
||||
import com.android.settings.core.lifecycle.ObservableDialogFragment;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settingslib.core.lifecycle.ObservableDialogFragment;
|
||||
|
||||
public abstract class InstrumentedDialogFragment extends ObservableDialogFragment
|
||||
implements Instrumentable {
|
||||
|
@@ -22,11 +22,11 @@ import android.content.Intent;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto;
|
||||
import com.android.settings.SettingsActivity;
|
||||
import com.android.settings.core.lifecycle.LifecycleObserver;
|
||||
import com.android.settings.core.lifecycle.events.OnAttach;
|
||||
import com.android.settings.core.lifecycle.events.OnPause;
|
||||
import com.android.settings.core.lifecycle.events.OnResume;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
||||
import com.android.settingslib.core.lifecycle.events.OnAttach;
|
||||
import com.android.settingslib.core.lifecycle.events.OnPause;
|
||||
import com.android.settingslib.core.lifecycle.events.OnResume;
|
||||
|
||||
import static com.android.settings.core.instrumentation.Instrumentable.METRICS_CATEGORY_UNKNOWN;
|
||||
|
||||
|
@@ -1,159 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2016 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.android.settings.core.lifecycle;
|
||||
|
||||
import android.annotation.UiThread;
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
|
||||
import com.android.settings.core.lifecycle.events.OnAttach;
|
||||
import com.android.settings.core.lifecycle.events.OnCreate;
|
||||
import com.android.settings.core.lifecycle.events.OnCreateOptionsMenu;
|
||||
import com.android.settings.core.lifecycle.events.OnDestroy;
|
||||
import com.android.settings.core.lifecycle.events.OnOptionsItemSelected;
|
||||
import com.android.settings.core.lifecycle.events.OnPause;
|
||||
import com.android.settings.core.lifecycle.events.OnPrepareOptionsMenu;
|
||||
import com.android.settings.core.lifecycle.events.OnResume;
|
||||
import com.android.settings.core.lifecycle.events.OnSaveInstanceState;
|
||||
import com.android.settings.core.lifecycle.events.OnStart;
|
||||
import com.android.settings.core.lifecycle.events.OnStop;
|
||||
import com.android.settings.core.lifecycle.events.SetPreferenceScreen;
|
||||
import com.android.settings.utils.ThreadUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Dispatcher for lifecycle events.
|
||||
*/
|
||||
public class Lifecycle {
|
||||
|
||||
protected final List<LifecycleObserver> mObservers = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Registers a new observer of lifecycle events.
|
||||
*/
|
||||
@UiThread
|
||||
public <T extends LifecycleObserver> T addObserver(T observer) {
|
||||
ThreadUtils.ensureMainThread();
|
||||
mObservers.add(observer);
|
||||
return observer;
|
||||
}
|
||||
|
||||
public void onAttach(Context context) {
|
||||
for (LifecycleObserver observer : mObservers) {
|
||||
if (observer instanceof OnAttach) {
|
||||
((OnAttach) observer).onAttach(context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
for (LifecycleObserver observer : mObservers) {
|
||||
if (observer instanceof OnCreate) {
|
||||
((OnCreate) observer).onCreate(savedInstanceState);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void onStart() {
|
||||
for (LifecycleObserver observer : mObservers) {
|
||||
if (observer instanceof OnStart) {
|
||||
((OnStart) observer).onStart();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setPreferenceScreen(PreferenceScreen preferenceScreen) {
|
||||
for (LifecycleObserver observer : mObservers) {
|
||||
if (observer instanceof SetPreferenceScreen) {
|
||||
((SetPreferenceScreen) observer).setPreferenceScreen(preferenceScreen);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void onResume() {
|
||||
for (LifecycleObserver observer : mObservers) {
|
||||
if (observer instanceof OnResume) {
|
||||
((OnResume) observer).onResume();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void onPause() {
|
||||
for (LifecycleObserver observer : mObservers) {
|
||||
if (observer instanceof OnPause) {
|
||||
((OnPause) observer).onPause();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
for (LifecycleObserver observer : mObservers) {
|
||||
if (observer instanceof OnSaveInstanceState) {
|
||||
((OnSaveInstanceState) observer).onSaveInstanceState(outState);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void onStop() {
|
||||
for (LifecycleObserver observer : mObservers) {
|
||||
if (observer instanceof OnStop) {
|
||||
((OnStop) observer).onStop();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void onDestroy() {
|
||||
for (LifecycleObserver observer : mObservers) {
|
||||
if (observer instanceof OnDestroy) {
|
||||
((OnDestroy) observer).onDestroy();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void onCreateOptionsMenu(final Menu menu, final @Nullable MenuInflater inflater) {
|
||||
for (LifecycleObserver observer : mObservers) {
|
||||
if (observer instanceof OnCreateOptionsMenu) {
|
||||
((OnCreateOptionsMenu) observer).onCreateOptionsMenu(menu, inflater);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void onPrepareOptionsMenu(final Menu menu) {
|
||||
for (LifecycleObserver observer : mObservers) {
|
||||
if (observer instanceof OnPrepareOptionsMenu) {
|
||||
((OnPrepareOptionsMenu) observer).onPrepareOptionsMenu(menu);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean onOptionsItemSelected(final MenuItem menuItem) {
|
||||
for (LifecycleObserver observer : mObservers) {
|
||||
if (observer instanceof OnOptionsItemSelected) {
|
||||
if (((OnOptionsItemSelected) observer).onOptionsItemSelected(menuItem)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
@@ -1,22 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2016 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.android.settings.core.lifecycle;
|
||||
|
||||
/**
|
||||
* Observer of lifecycle events.
|
||||
*/
|
||||
public interface LifecycleObserver {
|
||||
}
|
@@ -1,105 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2016 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.android.settings.core.lifecycle;
|
||||
|
||||
import android.annotation.Nullable;
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import android.os.PersistableBundle;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
|
||||
/**
|
||||
* {@link Activity} that has hooks to observe activity lifecycle events.
|
||||
*/
|
||||
public class ObservableActivity extends Activity {
|
||||
|
||||
private final Lifecycle mLifecycle = new Lifecycle();
|
||||
|
||||
protected Lifecycle getLifecycle() {
|
||||
return mLifecycle;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
mLifecycle.onAttach(this);
|
||||
super.onCreate(savedInstanceState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState,
|
||||
@Nullable PersistableBundle persistentState) {
|
||||
mLifecycle.onAttach(this);
|
||||
super.onCreate(savedInstanceState, persistentState);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart() {
|
||||
mLifecycle.onStart();
|
||||
super.onStart();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
mLifecycle.onResume();
|
||||
super.onResume();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
mLifecycle.onPause();
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
mLifecycle.onStop();
|
||||
super.onStop();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
mLifecycle.onDestroy();
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(final Menu menu) {
|
||||
if (super.onCreateOptionsMenu(menu)) {
|
||||
mLifecycle.onCreateOptionsMenu(menu, null);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPrepareOptionsMenu(final Menu menu) {
|
||||
if (super.onPrepareOptionsMenu(menu)) {
|
||||
mLifecycle.onPrepareOptionsMenu(menu);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(final MenuItem menuItem) {
|
||||
boolean lifecycleHandled = mLifecycle.onOptionsItemSelected(menuItem);
|
||||
if (!lifecycleHandled) {
|
||||
return super.onOptionsItemSelected(menuItem);
|
||||
}
|
||||
return lifecycleHandled;
|
||||
}
|
||||
}
|
@@ -1,94 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2016 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.android.settings.core.lifecycle;
|
||||
|
||||
import android.app.DialogFragment;
|
||||
import android.content.Context;
|
||||
import android.support.annotation.VisibleForTesting;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
|
||||
/**
|
||||
* {@link DialogFragment} that has hooks to observe fragment lifecycle events.
|
||||
*/
|
||||
public class ObservableDialogFragment extends DialogFragment {
|
||||
|
||||
protected final Lifecycle mLifecycle = createLifecycle();
|
||||
|
||||
@Override
|
||||
public void onAttach(Context context) {
|
||||
super.onAttach(context);
|
||||
mLifecycle.onAttach(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
mLifecycle.onStart();
|
||||
super.onStart();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
mLifecycle.onResume();
|
||||
super.onResume();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
mLifecycle.onPause();
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop() {
|
||||
mLifecycle.onStop();
|
||||
super.onStop();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
mLifecycle.onDestroy();
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(final Menu menu, final MenuInflater inflater) {
|
||||
mLifecycle.onCreateOptionsMenu(menu, inflater);
|
||||
super.onCreateOptionsMenu(menu, inflater);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPrepareOptionsMenu(final Menu menu) {
|
||||
mLifecycle.onPrepareOptionsMenu(menu);
|
||||
super.onPrepareOptionsMenu(menu);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(final MenuItem menuItem) {
|
||||
boolean lifecycleHandled = mLifecycle.onOptionsItemSelected(menuItem);
|
||||
if (!lifecycleHandled) {
|
||||
return super.onOptionsItemSelected(menuItem);
|
||||
}
|
||||
return lifecycleHandled;
|
||||
}
|
||||
|
||||
@VisibleForTesting(otherwise = VisibleForTesting.NONE)
|
||||
/** @return a new lifecycle. */
|
||||
public static Lifecycle createLifecycle() {
|
||||
return new Lifecycle();
|
||||
}
|
||||
}
|
@@ -1,114 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2016 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.core.lifecycle;
|
||||
|
||||
import android.annotation.CallSuper;
|
||||
import android.app.Fragment;
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
|
||||
public class ObservableFragment extends Fragment {
|
||||
|
||||
private final Lifecycle mLifecycle = new Lifecycle();
|
||||
|
||||
protected Lifecycle getLifecycle() {
|
||||
return mLifecycle;
|
||||
}
|
||||
|
||||
@CallSuper
|
||||
@Override
|
||||
public void onAttach(Context context) {
|
||||
super.onAttach(context);
|
||||
mLifecycle.onAttach(context);
|
||||
}
|
||||
|
||||
@CallSuper
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
mLifecycle.onCreate(savedInstanceState);
|
||||
super.onCreate(savedInstanceState);
|
||||
}
|
||||
|
||||
@CallSuper
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
mLifecycle.onSaveInstanceState(outState);
|
||||
}
|
||||
|
||||
@CallSuper
|
||||
@Override
|
||||
public void onStart() {
|
||||
mLifecycle.onStart();
|
||||
super.onStart();
|
||||
}
|
||||
|
||||
@CallSuper
|
||||
@Override
|
||||
public void onStop() {
|
||||
mLifecycle.onStop();
|
||||
super.onStop();
|
||||
}
|
||||
|
||||
@CallSuper
|
||||
@Override
|
||||
public void onResume() {
|
||||
mLifecycle.onResume();
|
||||
super.onResume();
|
||||
}
|
||||
|
||||
@CallSuper
|
||||
@Override
|
||||
public void onPause() {
|
||||
mLifecycle.onPause();
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
@CallSuper
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
mLifecycle.onDestroy();
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
@CallSuper
|
||||
@Override
|
||||
public void onCreateOptionsMenu(final Menu menu, final MenuInflater inflater) {
|
||||
mLifecycle.onCreateOptionsMenu(menu, inflater);
|
||||
super.onCreateOptionsMenu(menu, inflater);
|
||||
}
|
||||
|
||||
@CallSuper
|
||||
@Override
|
||||
public void onPrepareOptionsMenu(final Menu menu) {
|
||||
mLifecycle.onPrepareOptionsMenu(menu);
|
||||
super.onPrepareOptionsMenu(menu);
|
||||
}
|
||||
|
||||
@CallSuper
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(final MenuItem menuItem) {
|
||||
boolean lifecycleHandled = mLifecycle.onOptionsItemSelected(menuItem);
|
||||
if (!lifecycleHandled) {
|
||||
return super.onOptionsItemSelected(menuItem);
|
||||
}
|
||||
return lifecycleHandled;
|
||||
}
|
||||
}
|
@@ -1,124 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2016 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.android.settings.core.lifecycle;
|
||||
|
||||
|
||||
import android.annotation.CallSuper;
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.support.v14.preference.PreferenceFragment;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
|
||||
/**
|
||||
* {@link PreferenceFragment} that has hooks to observe fragment lifecycle events.
|
||||
*/
|
||||
public abstract class ObservablePreferenceFragment extends PreferenceFragment {
|
||||
|
||||
private final Lifecycle mLifecycle = new Lifecycle();
|
||||
|
||||
protected Lifecycle getLifecycle() {
|
||||
return mLifecycle;
|
||||
}
|
||||
|
||||
@CallSuper
|
||||
@Override
|
||||
public void onAttach(Context context) {
|
||||
super.onAttach(context);
|
||||
mLifecycle.onAttach(context);
|
||||
}
|
||||
|
||||
@CallSuper
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
mLifecycle.onCreate(savedInstanceState);
|
||||
super.onCreate(savedInstanceState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPreferenceScreen(PreferenceScreen preferenceScreen) {
|
||||
mLifecycle.setPreferenceScreen(preferenceScreen);
|
||||
super.setPreferenceScreen(preferenceScreen);
|
||||
}
|
||||
|
||||
@CallSuper
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
mLifecycle.onSaveInstanceState(outState);
|
||||
}
|
||||
|
||||
@CallSuper
|
||||
@Override
|
||||
public void onStart() {
|
||||
mLifecycle.onStart();
|
||||
super.onStart();
|
||||
}
|
||||
|
||||
@CallSuper
|
||||
@Override
|
||||
public void onStop() {
|
||||
mLifecycle.onStop();
|
||||
super.onStop();
|
||||
}
|
||||
|
||||
@CallSuper
|
||||
@Override
|
||||
public void onResume() {
|
||||
mLifecycle.onResume();
|
||||
super.onResume();
|
||||
}
|
||||
|
||||
@CallSuper
|
||||
@Override
|
||||
public void onPause() {
|
||||
mLifecycle.onPause();
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
@CallSuper
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
mLifecycle.onDestroy();
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
@CallSuper
|
||||
@Override
|
||||
public void onCreateOptionsMenu(final Menu menu, final MenuInflater inflater) {
|
||||
mLifecycle.onCreateOptionsMenu(menu, inflater);
|
||||
super.onCreateOptionsMenu(menu, inflater);
|
||||
}
|
||||
|
||||
@CallSuper
|
||||
@Override
|
||||
public void onPrepareOptionsMenu(final Menu menu) {
|
||||
mLifecycle.onPrepareOptionsMenu(menu);
|
||||
super.onPrepareOptionsMenu(menu);
|
||||
}
|
||||
|
||||
@CallSuper
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(final MenuItem menuItem) {
|
||||
boolean lifecycleHandled = mLifecycle.onOptionsItemSelected(menuItem);
|
||||
if (!lifecycleHandled) {
|
||||
return super.onOptionsItemSelected(menuItem);
|
||||
}
|
||||
return lifecycleHandled;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user