2 * Copyright © 2018 Damyan Ivanov.
3 * This file is part of MoLe.
4 * MoLe is free software: you can distribute it and/or modify it
5 * under the term of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your opinion), any later version.
9 * MoLe is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License terms for details.
14 * You should have received a copy of the GNU General Public License
15 * along with MoLe. If not, see <https://www.gnu.org/licenses/>.
18 package net.ktnx.mobileledger.ui.activity;
20 import android.content.res.Configuration;
21 import android.os.Bundle;
22 import android.preference.PreferenceActivity;
23 import android.support.annotation.LayoutRes;
24 import android.support.annotation.NonNull;
25 import android.support.annotation.Nullable;
26 import android.support.v7.app.ActionBar;
27 import android.support.v7.app.AppCompatDelegate;
28 import android.support.v7.widget.Toolbar;
29 import android.view.MenuInflater;
30 import android.view.View;
31 import android.view.ViewGroup;
34 * A {@link android.preference.PreferenceActivity} which implements and proxies the necessary calls
35 * to be used with AppCompat.
37 public abstract class AppCompatPreferenceActivity extends PreferenceActivity {
39 private AppCompatDelegate mDelegate;
42 protected void onCreate(Bundle savedInstanceState) {
43 getDelegate().installViewFactory();
44 getDelegate().onCreate(savedInstanceState);
45 super.onCreate(savedInstanceState);
49 protected void onPostCreate(Bundle savedInstanceState) {
50 super.onPostCreate(savedInstanceState);
51 getDelegate().onPostCreate(savedInstanceState);
54 public ActionBar getSupportActionBar() {
55 return getDelegate().getSupportActionBar();
58 public void setSupportActionBar(@Nullable Toolbar toolbar) {
59 getDelegate().setSupportActionBar(toolbar);
64 public MenuInflater getMenuInflater() {
65 return getDelegate().getMenuInflater();
69 public void setContentView(@LayoutRes int layoutResID) {
70 getDelegate().setContentView(layoutResID);
74 public void setContentView(View view) {
75 getDelegate().setContentView(view);
79 public void setContentView(View view, ViewGroup.LayoutParams params) {
80 getDelegate().setContentView(view, params);
84 public void addContentView(View view, ViewGroup.LayoutParams params) {
85 getDelegate().addContentView(view, params);
89 protected void onPostResume() {
91 getDelegate().onPostResume();
95 protected void onTitleChanged(CharSequence title, int color) {
96 super.onTitleChanged(title, color);
97 getDelegate().setTitle(title);
101 public void onConfigurationChanged(Configuration newConfig) {
102 super.onConfigurationChanged(newConfig);
103 getDelegate().onConfigurationChanged(newConfig);
107 protected void onStop() {
109 getDelegate().onStop();
113 protected void onDestroy() {
115 getDelegate().onDestroy();
118 public void invalidateOptionsMenu() {
119 getDelegate().invalidateOptionsMenu();
122 private AppCompatDelegate getDelegate() {
123 if (mDelegate == null) {
124 mDelegate = AppCompatDelegate.create(this, null);