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