| 1 |
package ${packageName}; |
| 2 |
|
| 3 |
import android.content.res.Configuration; |
| 4 |
import android.os.Bundle; |
| 5 |
import android.preference.PreferenceActivity; |
| 6 |
import android.support.annotation.LayoutRes; |
| 7 |
import android.support.annotation.Nullable; |
| 8 |
import android.support.v7.app.ActionBar; |
| 9 |
import android.support.v7.app.AppCompatDelegate; |
| 10 |
import android.support.v7.widget.Toolbar; |
| 11 |
import android.view.MenuInflater; |
| 12 |
import android.view.View; |
| 13 |
import android.view.ViewGroup; |
| 14 |
|
| 15 |
/** |
| 16 |
* A {@link android.preference.PreferenceActivity} which implements and proxies the necessary calls |
| 17 |
* to be used with AppCompat. |
| 18 |
*/ |
| 19 |
public abstract class AppCompatPreferenceActivity extends PreferenceActivity { |
| 20 |
|
| 21 |
private AppCompatDelegate mDelegate; |
| 22 |
|
| 23 |
@Override |
| 24 |
protected void onCreate(Bundle savedInstanceState) { |
| 25 |
getDelegate().installViewFactory(); |
| 26 |
getDelegate().onCreate(savedInstanceState); |
| 27 |
super.onCreate(savedInstanceState); |
| 28 |
} |
| 29 |
|
| 30 |
@Override |
| 31 |
protected void onPostCreate(Bundle savedInstanceState) { |
| 32 |
super.onPostCreate(savedInstanceState); |
| 33 |
getDelegate().onPostCreate(savedInstanceState); |
| 34 |
} |
| 35 |
|
| 36 |
public ActionBar getSupportActionBar() { |
| 37 |
return getDelegate().getSupportActionBar(); |
| 38 |
} |
| 39 |
|
| 40 |
public void setSupportActionBar(@Nullable Toolbar toolbar) { |
| 41 |
getDelegate().setSupportActionBar(toolbar); |
| 42 |
} |
| 43 |
|
| 44 |
@Override |
| 45 |
public MenuInflater getMenuInflater() { |
| 46 |
return getDelegate().getMenuInflater(); |
| 47 |
} |
| 48 |
|
| 49 |
@Override |
| 50 |
public void setContentView(@LayoutRes int layoutResID) { |
| 51 |
getDelegate().setContentView(layoutResID); |
| 52 |
} |
| 53 |
|
| 54 |
@Override |
| 55 |
public void setContentView(View view) { |
| 56 |
getDelegate().setContentView(view); |
| 57 |
} |
| 58 |
|
| 59 |
@Override |
| 60 |
public void setContentView(View view, ViewGroup.LayoutParams params) { |
| 61 |
getDelegate().setContentView(view, params); |
| 62 |
} |
| 63 |
|
| 64 |
@Override |
| 65 |
public void addContentView(View view, ViewGroup.LayoutParams params) { |
| 66 |
getDelegate().addContentView(view, params); |
| 67 |
} |
| 68 |
|
| 69 |
@Override |
| 70 |
protected void onPostResume() { |
| 71 |
super.onPostResume(); |
| 72 |
getDelegate().onPostResume(); |
| 73 |
} |
| 74 |
|
| 75 |
@Override |
| 76 |
protected void onTitleChanged(CharSequence title, int color) { |
| 77 |
super.onTitleChanged(title, color); |
| 78 |
getDelegate().setTitle(title); |
| 79 |
} |
| 80 |
|
| 81 |
@Override |
| 82 |
public void onConfigurationChanged(Configuration newConfig) { |
| 83 |
super.onConfigurationChanged(newConfig); |
| 84 |
getDelegate().onConfigurationChanged(newConfig); |
| 85 |
} |
| 86 |
|
| 87 |
@Override |
| 88 |
protected void onStop() { |
| 89 |
super.onStop(); |
| 90 |
getDelegate().onStop(); |
| 91 |
} |
| 92 |
|
| 93 |
@Override |
| 94 |
protected void onDestroy() { |
| 95 |
super.onDestroy(); |
| 96 |
getDelegate().onDestroy(); |
| 97 |
} |
| 98 |
|
| 99 |
public void invalidateOptionsMenu() { |
| 100 |
getDelegate().invalidateOptionsMenu(); |
| 101 |
} |
| 102 |
|
| 103 |
private AppCompatDelegate getDelegate() { |
| 104 |
if (mDelegate == null) { |
| 105 |
mDelegate = AppCompatDelegate.create(this, null); |
| 106 |
} |
| 107 |
return mDelegate; |
| 108 |
} |
| 109 |
} |