2 * Copyright © 2019 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 androidx.annotation.LayoutRes;
24 import androidx.annotation.NonNull;
25 import androidx.annotation.Nullable;
26 import androidx.appcompat.app.ActionBar;
27 import androidx.appcompat.app.AppCompatDelegate;
28 import androidx.appcompat.widget.Toolbar;
29 import android.view.MenuInflater;
30 import android.view.View;
31 import android.view.ViewGroup;
33 import net.ktnx.mobileledger.utils.Colors;
36 * A {@link android.preference.PreferenceActivity} which implements and proxies the necessary calls
37 * to be used with AppCompat.
39 public abstract class AppCompatPreferenceActivity extends PreferenceActivity {
41 private AppCompatDelegate mDelegate;
44 protected void onCreate(Bundle savedInstanceState) {
45 getDelegate().installViewFactory();
46 getDelegate().onCreate(savedInstanceState);
47 super.onCreate(savedInstanceState);
48 Colors.setupTheme(this);
52 protected void onPostCreate(Bundle savedInstanceState) {
53 super.onPostCreate(savedInstanceState);
54 getDelegate().onPostCreate(savedInstanceState);
57 public ActionBar getSupportActionBar() {
58 return getDelegate().getSupportActionBar();
61 public void setSupportActionBar(@Nullable Toolbar toolbar) {
62 getDelegate().setSupportActionBar(toolbar);
67 public MenuInflater getMenuInflater() {
68 return getDelegate().getMenuInflater();
72 public void setContentView(@LayoutRes int layoutResID) {
73 getDelegate().setContentView(layoutResID);
77 public void setContentView(View view) {
78 getDelegate().setContentView(view);
82 public void setContentView(View view, ViewGroup.LayoutParams params) {
83 getDelegate().setContentView(view, params);
87 public void addContentView(View view, ViewGroup.LayoutParams params) {
88 getDelegate().addContentView(view, params);
92 protected void onPostResume() {
94 getDelegate().onPostResume();
98 protected void onTitleChanged(CharSequence title, int color) {
99 super.onTitleChanged(title, color);
100 getDelegate().setTitle(title);
104 public void onConfigurationChanged(Configuration newConfig) {
105 super.onConfigurationChanged(newConfig);
106 getDelegate().onConfigurationChanged(newConfig);
110 protected void onStop() {
112 getDelegate().onStop();
116 protected void onDestroy() {
118 getDelegate().onDestroy();
121 public void invalidateOptionsMenu() {
122 getDelegate().invalidateOptionsMenu();
125 private AppCompatDelegate getDelegate() {
126 if (mDelegate == null) {
127 mDelegate = AppCompatDelegate.create(this, null);