Added README.txt and GPL Header to Source Files
[DHBWCampusApp.git] / app / src / main / java / de / dhbwloe / campusapp / AppCompatPreferenceActivity.java
1 /* AppCompatPreferenceActivity.java
2  *
3  * This program is free software: you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License as published by
5  * the Free Software Foundation, either version 3 of the License, or
6  * (at your option) any later version.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  */
16 package de.dhbwloe.campusapp;
17
18 import android.content.res.Configuration;
19 import android.os.Bundle;
20 import android.preference.PreferenceActivity;
21 import android.support.annotation.LayoutRes;
22 import android.support.annotation.Nullable;
23 import android.support.v7.app.ActionBar;
24 import android.support.v7.app.AppCompatDelegate;
25 import android.support.v7.widget.Toolbar;
26 import android.view.MenuInflater;
27 import android.view.View;
28 import android.view.ViewGroup;
29
30 /**
31  * A {@link android.preference.PreferenceActivity} which implements and proxies the necessary calls
32  * to be used with AppCompat.
33  */
34 public abstract class AppCompatPreferenceActivity extends PreferenceActivity {
35
36     private AppCompatDelegate mDelegate;
37
38     @Override
39     protected void onCreate(Bundle savedInstanceState) {
40         getDelegate().installViewFactory();
41         getDelegate().onCreate(savedInstanceState);
42         super.onCreate(savedInstanceState);
43     }
44
45     @Override
46     protected void onPostCreate(Bundle savedInstanceState) {
47         super.onPostCreate(savedInstanceState);
48         getDelegate().onPostCreate(savedInstanceState);
49     }
50
51     public ActionBar getSupportActionBar() {
52         return getDelegate().getSupportActionBar();
53     }
54
55     public void setSupportActionBar(@Nullable Toolbar toolbar) {
56         getDelegate().setSupportActionBar(toolbar);
57     }
58
59     @Override
60     public MenuInflater getMenuInflater() {
61         return getDelegate().getMenuInflater();
62     }
63
64     @Override
65     public void setContentView(@LayoutRes int layoutResID) {
66         getDelegate().setContentView(layoutResID);
67     }
68
69     @Override
70     public void setContentView(View view) {
71         getDelegate().setContentView(view);
72     }
73
74     @Override
75     public void setContentView(View view, ViewGroup.LayoutParams params) {
76         getDelegate().setContentView(view, params);
77     }
78
79     @Override
80     public void addContentView(View view, ViewGroup.LayoutParams params) {
81         getDelegate().addContentView(view, params);
82     }
83
84     @Override
85     protected void onPostResume() {
86         super.onPostResume();
87         getDelegate().onPostResume();
88     }
89
90     @Override
91     protected void onTitleChanged(CharSequence title, int color) {
92         super.onTitleChanged(title, color);
93         getDelegate().setTitle(title);
94     }
95
96     @Override
97     public void onConfigurationChanged(Configuration newConfig) {
98         super.onConfigurationChanged(newConfig);
99         getDelegate().onConfigurationChanged(newConfig);
100     }
101
102     @Override
103     protected void onStop() {
104         super.onStop();
105         getDelegate().onStop();
106     }
107
108     @Override
109     protected void onDestroy() {
110         super.onDestroy();
111         getDelegate().onDestroy();
112     }
113
114     public void invalidateOptionsMenu() {
115         getDelegate().invalidateOptionsMenu();
116     }
117
118     private AppCompatDelegate getDelegate() {
119         if (mDelegate == null) {
120             mDelegate = AppCompatDelegate.create(this, null);
121         }
122         return mDelegate;
123     }
124 }