|
| 1 | +/* |
| 2 | + * The MIT License (MIT) |
| 3 | + * |
| 4 | + * Copyright (c) 2016 Shengjie Sim Sun |
| 5 | + * |
| 6 | + * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | + * of this software and associated documentation files (the "Software"), to deal |
| 8 | + * in the Software without restriction, including without limitation the rights |
| 9 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 10 | + * copies of the Software, and to permit persons to whom the Software is |
| 11 | + * furnished to do so, subject to the following conditions: |
| 12 | + * |
| 13 | + * The above copyright notice and this permission notice shall be included in |
| 14 | + * all copies or substantial portions of the Software. |
| 15 | + * |
| 16 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 19 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 22 | + * THE SOFTWARE. |
| 23 | + */ |
| 24 | + |
| 25 | +package com.tinker.debug; |
| 26 | + |
| 27 | +import android.content.res.Configuration; |
| 28 | +import android.os.Bundle; |
| 29 | +import android.preference.PreferenceActivity; |
| 30 | +import android.support.annotation.LayoutRes; |
| 31 | +import android.support.annotation.Nullable; |
| 32 | +import android.support.v7.app.ActionBar; |
| 33 | +import android.support.v7.app.AppCompatDelegate; |
| 34 | +import android.support.v7.widget.Toolbar; |
| 35 | +import android.view.MenuInflater; |
| 36 | +import android.view.View; |
| 37 | +import android.view.ViewGroup; |
| 38 | + |
| 39 | +/** |
| 40 | + * A {@link android.preference.PreferenceActivity} which implements and proxies the necessary calls |
| 41 | + * to be used with AppCompat. |
| 42 | + */ |
| 43 | +public abstract class AppCompatPreferenceActivity extends PreferenceActivity { |
| 44 | + |
| 45 | + private AppCompatDelegate mDelegate; |
| 46 | + |
| 47 | + @Override |
| 48 | + protected void onCreate(Bundle savedInstanceState) { |
| 49 | + getDelegate().installViewFactory(); |
| 50 | + getDelegate().onCreate(savedInstanceState); |
| 51 | + super.onCreate(savedInstanceState); |
| 52 | + } |
| 53 | + |
| 54 | + @Override |
| 55 | + protected void onPostCreate(Bundle savedInstanceState) { |
| 56 | + super.onPostCreate(savedInstanceState); |
| 57 | + getDelegate().onPostCreate(savedInstanceState); |
| 58 | + } |
| 59 | + |
| 60 | + public ActionBar getSupportActionBar() { |
| 61 | + return getDelegate().getSupportActionBar(); |
| 62 | + } |
| 63 | + |
| 64 | + public void setSupportActionBar(@Nullable Toolbar toolbar) { |
| 65 | + getDelegate().setSupportActionBar(toolbar); |
| 66 | + } |
| 67 | + |
| 68 | + @Override |
| 69 | + public MenuInflater getMenuInflater() { |
| 70 | + return getDelegate().getMenuInflater(); |
| 71 | + } |
| 72 | + |
| 73 | + @Override |
| 74 | + public void setContentView(@LayoutRes int layoutResID) { |
| 75 | + getDelegate().setContentView(layoutResID); |
| 76 | + } |
| 77 | + |
| 78 | + @Override |
| 79 | + public void setContentView(View view) { |
| 80 | + getDelegate().setContentView(view); |
| 81 | + } |
| 82 | + |
| 83 | + @Override |
| 84 | + public void setContentView(View view, ViewGroup.LayoutParams params) { |
| 85 | + getDelegate().setContentView(view, params); |
| 86 | + } |
| 87 | + |
| 88 | + @Override |
| 89 | + public void addContentView(View view, ViewGroup.LayoutParams params) { |
| 90 | + getDelegate().addContentView(view, params); |
| 91 | + } |
| 92 | + |
| 93 | + @Override |
| 94 | + protected void onPostResume() { |
| 95 | + super.onPostResume(); |
| 96 | + getDelegate().onPostResume(); |
| 97 | + } |
| 98 | + |
| 99 | + @Override |
| 100 | + protected void onTitleChanged(CharSequence title, int color) { |
| 101 | + super.onTitleChanged(title, color); |
| 102 | + getDelegate().setTitle(title); |
| 103 | + } |
| 104 | + |
| 105 | + @Override |
| 106 | + public void onConfigurationChanged(Configuration newConfig) { |
| 107 | + super.onConfigurationChanged(newConfig); |
| 108 | + getDelegate().onConfigurationChanged(newConfig); |
| 109 | + } |
| 110 | + |
| 111 | + @Override |
| 112 | + protected void onStop() { |
| 113 | + super.onStop(); |
| 114 | + getDelegate().onStop(); |
| 115 | + } |
| 116 | + |
| 117 | + @Override |
| 118 | + protected void onDestroy() { |
| 119 | + super.onDestroy(); |
| 120 | + getDelegate().onDestroy(); |
| 121 | + } |
| 122 | + |
| 123 | + public void invalidateOptionsMenu() { |
| 124 | + getDelegate().invalidateOptionsMenu(); |
| 125 | + } |
| 126 | + |
| 127 | + private AppCompatDelegate getDelegate() { |
| 128 | + if (mDelegate == null) { |
| 129 | + mDelegate = AppCompatDelegate.create(this, null); |
| 130 | + } |
| 131 | + return mDelegate; |
| 132 | + } |
| 133 | +} |
0 commit comments