Created
November 4, 2016 23:36
-
-
Save hector6872/4612f2349d8ba82a454fc90c4f62f2d3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public abstract class AppCompatPreferenceActivity extends PreferenceActivity { | |
private AppCompatDelegate appCompatDelegate; | |
@Override protected void onCreate(Bundle savedInstanceState) { | |
getDelegate().installViewFactory(); | |
getDelegate().onCreate(savedInstanceState); | |
super.onCreate(savedInstanceState); | |
} | |
@Override protected void onPostCreate(Bundle savedInstanceState) { | |
super.onPostCreate(savedInstanceState); | |
getDelegate().onPostCreate(savedInstanceState); | |
} | |
@Override public View onCreateView(String name, Context context, AttributeSet attrs) { | |
final View result = super.onCreateView(name, context, attrs); | |
if (result != null) { | |
return result; | |
} | |
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { | |
switch (name) { | |
case "Switch": | |
return new SwitchCompat(this, attrs); | |
case "TextView": | |
return new AppCompatTextView(context, attrs); | |
case "ImageView": | |
return new AppCompatImageView(context, attrs); | |
case "Button": | |
return new AppCompatButton(context, attrs); | |
case "EditText": | |
return new AppCompatEditText(context, attrs); | |
case "Spinner": | |
return new AppCompatSpinner(context, attrs); | |
case "ImageButton": | |
return new AppCompatImageButton(context, attrs); | |
case "CheckBox": | |
return new AppCompatCheckBox(context, attrs); | |
case "RadioButton": | |
return new AppCompatRadioButton(context, attrs); | |
case "CheckedTextView": | |
return new AppCompatCheckedTextView(context, attrs); | |
case "AutoCompleteTextView": | |
return new AppCompatAutoCompleteTextView(context, attrs); | |
case "MultiAutoCompleteTextView": | |
return new AppCompatMultiAutoCompleteTextView(context, attrs); | |
case "RatingBar": | |
return new AppCompatRatingBar(context, attrs); | |
case "SeekBar": | |
return new AppCompatSeekBar(context, attrs); | |
} | |
} | |
return null; | |
} | |
protected ActionBar getSupportActionBar() { | |
return getDelegate().getSupportActionBar(); | |
} | |
@NonNull @Override public MenuInflater getMenuInflater() { | |
return getDelegate().getMenuInflater(); | |
} | |
@Override public void setContentView(@LayoutRes int layoutResID) { | |
getDelegate().setContentView(layoutResID); | |
} | |
@Override public void setContentView(View view) { | |
getDelegate().setContentView(view); | |
} | |
@Override public void setContentView(View view, ViewGroup.LayoutParams params) { | |
getDelegate().setContentView(view, params); | |
} | |
@Override public void addContentView(View view, ViewGroup.LayoutParams params) { | |
getDelegate().addContentView(view, params); | |
} | |
@Override protected void onPostResume() { | |
super.onPostResume(); | |
getDelegate().onPostResume(); | |
} | |
@Override protected void onTitleChanged(CharSequence title, int color) { | |
super.onTitleChanged(title, color); | |
getDelegate().setTitle(title); | |
} | |
@Override public void onConfigurationChanged(Configuration newConfig) { | |
super.onConfigurationChanged(newConfig); | |
getDelegate().onConfigurationChanged(newConfig); | |
} | |
@Override protected void onStop() { | |
super.onStop(); | |
getDelegate().onStop(); | |
} | |
@Override protected void onDestroy() { | |
super.onDestroy(); | |
getDelegate().onDestroy(); | |
} | |
public void invalidateOptionsMenu() { | |
getDelegate().invalidateOptionsMenu(); | |
} | |
private AppCompatDelegate getDelegate() { | |
if (appCompatDelegate == null) { | |
appCompatDelegate = AppCompatDelegate.create(this, null); | |
} | |
return appCompatDelegate; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment