]> git.ktnx.net Git - mobile-ledger.git/blob - app/src/main/java/net/ktnx/mobileledger/ui/activity/AppCompatPreferenceActivity.java
migrate to AndroidX
[mobile-ledger.git] / app / src / main / java / net / ktnx / mobileledger / ui / activity / AppCompatPreferenceActivity.java
1 /*
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.
8  *
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.
13  *
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/>.
16  */
17
18 package net.ktnx.mobileledger.ui.activity;
19
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;
32
33 import net.ktnx.mobileledger.utils.Colors;
34
35 /**
36  * A {@link android.preference.PreferenceActivity} which implements and proxies the necessary calls
37  * to be used with AppCompat.
38  */
39 public abstract class AppCompatPreferenceActivity extends PreferenceActivity {
40
41     private AppCompatDelegate mDelegate;
42
43     @Override
44     protected void onCreate(Bundle savedInstanceState) {
45         getDelegate().installViewFactory();
46         getDelegate().onCreate(savedInstanceState);
47         super.onCreate(savedInstanceState);
48         Colors.setupTheme(this);
49     }
50
51     @Override
52     protected void onPostCreate(Bundle savedInstanceState) {
53         super.onPostCreate(savedInstanceState);
54         getDelegate().onPostCreate(savedInstanceState);
55     }
56
57     public ActionBar getSupportActionBar() {
58         return getDelegate().getSupportActionBar();
59     }
60
61     public void setSupportActionBar(@Nullable Toolbar toolbar) {
62         getDelegate().setSupportActionBar(toolbar);
63     }
64
65     @NonNull
66     @Override
67     public MenuInflater getMenuInflater() {
68         return getDelegate().getMenuInflater();
69     }
70
71     @Override
72     public void setContentView(@LayoutRes int layoutResID) {
73         getDelegate().setContentView(layoutResID);
74     }
75
76     @Override
77     public void setContentView(View view) {
78         getDelegate().setContentView(view);
79     }
80
81     @Override
82     public void setContentView(View view, ViewGroup.LayoutParams params) {
83         getDelegate().setContentView(view, params);
84     }
85
86     @Override
87     public void addContentView(View view, ViewGroup.LayoutParams params) {
88         getDelegate().addContentView(view, params);
89     }
90
91     @Override
92     protected void onPostResume() {
93         super.onPostResume();
94         getDelegate().onPostResume();
95     }
96
97     @Override
98     protected void onTitleChanged(CharSequence title, int color) {
99         super.onTitleChanged(title, color);
100         getDelegate().setTitle(title);
101     }
102
103     @Override
104     public void onConfigurationChanged(Configuration newConfig) {
105         super.onConfigurationChanged(newConfig);
106         getDelegate().onConfigurationChanged(newConfig);
107     }
108
109     @Override
110     protected void onStop() {
111         super.onStop();
112         getDelegate().onStop();
113     }
114
115     @Override
116     protected void onDestroy() {
117         super.onDestroy();
118         getDelegate().onDestroy();
119     }
120
121     public void invalidateOptionsMenu() {
122         getDelegate().invalidateOptionsMenu();
123     }
124
125     private AppCompatDelegate getDelegate() {
126         if (mDelegate == null) {
127             mDelegate = AppCompatDelegate.create(this, null);
128         }
129         return mDelegate;
130     }
131 }