@SuppressWarnings("ResourceType") @Override public Dialog onCreateDialog(Bundle savedInstanceState) { assert getArguments() != null; MaterialDialog dialog = new MaterialDialog.Builder(getActivity()) .title(getArguments().getInt(KEY_TITLE)) .customView(R.layout.dialog_textsize, true) .negativeText(android.R.string.cancel) .positiveText(android.R.string.ok) .neutralText(R.string.defaultValue) .autoDismiss(false) .onAny(this) .build(); final View view = dialog.getCustomView(); assert view != null; mPreview = (TextView) view.findViewById(R.id.preview); mSeeker = (SeekBar) view.findViewById(R.id.seeker); mValue = (TextView) view.findViewById(R.id.value); final int defaultValue = Config.textSizeForMode( getActivity(), getArguments().getString(KEY_ATEKEY), getArguments().getString(KEY_MODE)); mPreview.setTextSize(TypedValue.COMPLEX_UNIT_PX, defaultValue); mSeeker.setMax(111); final int dpValue = pxToSp(this, defaultValue); mSeeker.setProgress(dpValue - 1); mValue.setText(String.format("%dsp", dpValue)); mSeeker.setOnSeekBarChangeListener( new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { progress++; if (fromUser) { final int pxValue = spToPx(progress); mPreview.setTextSize(TypedValue.COMPLEX_UNIT_PX, pxValue); mValue.setText(String.format("%dsp", progress)); } } @Override public void onStartTrackingTouch(SeekBar seekBar) {} @Override public void onStopTrackingTouch(SeekBar seekBar) {} }); ATE.apply(view, getArguments().getString(KEY_ATEKEY)); return dialog; }
@SuppressWarnings("ConstantConditions") @Override protected void onCreate(Bundle savedInstanceState) { // Default config if (!ATE.config(this, "light_theme").isConfigured(2)) { ATE.config(this, "light_theme") .activityTheme(R.style.AppTheme) .primaryColorRes(R.color.colorPrimaryLightDefault) .accentColorRes(R.color.colorAccentLightDefault) .coloredNavigationBar(false) .navigationViewSelectedIconRes(R.color.colorAccentLightDefault) .navigationViewSelectedTextRes(R.color.colorAccentLightDefault) .commit(); } if (!ATE.config(this, "dark_theme").isConfigured(2)) { ATE.config(this, "dark_theme") .activityTheme(R.style.AppThemeDark) .primaryColorRes(R.color.colorPrimaryDarkDefault) .accentColorRes(R.color.colorAccentDarkDefault) .coloredNavigationBar(true) .navigationViewSelectedIconRes(R.color.colorAccentDarkDefault) .navigationViewSelectedTextRes(R.color.colorAccentDarkDefault) .commit(); } super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); final Toolbar toolbar = (Toolbar) findViewById(R.id.appbar_toolbar); setSupportActionBar(toolbar); toolbar.setTitle(R.string.app_name); toolbar.setNavigationIcon(R.drawable.ic_menu); mDrawer = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawer.setDrawerListener( new ActionBarDrawerToggle( this, mDrawer, toolbar, R.string.drawer_open, R.string.drawer_close)); final NavigationView navView = (NavigationView) findViewById(R.id.navigation_view); navView.setNavigationItemSelectedListener(this); }
@SuppressWarnings("ResourceType") @Override public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) { if (which == DialogAction.POSITIVE) { dismiss(); if (getActivity() == null) return; ATE.config(getActivity(), getArguments().getString(KEY_ATEKEY)) .textSizeSpForMode(mSeeker.getProgress() + 1, getArguments().getString(KEY_MODE)) .apply(getActivity()); if (getArguments().getBoolean(KEY_RECREATE)) getActivity().recreate(); } else if (which == DialogAction.NEUTRAL) { @Config.TextSizeMode final String mode = getArguments().getString(KEY_MODE); assert mode != null; int size; switch (mode) { default: case Config.TEXTSIZE_CAPTION: size = getResources().getDimensionPixelSize(R.dimen.ate_default_textsize_caption); break; case Config.TEXTSIZE_BODY: size = getResources().getDimensionPixelSize(R.dimen.ate_default_textsize_body); break; case Config.TEXTSIZE_SUBHEADING: size = getResources().getDimensionPixelSize(R.dimen.ate_default_textsize_subheading); break; case Config.TEXTSIZE_TITLE: size = getResources().getDimensionPixelSize(R.dimen.ate_default_textsize_title); break; case Config.TEXTSIZE_HEADLINE: size = getResources().getDimensionPixelSize(R.dimen.ate_default_textsize_headline); break; case Config.TEXTSIZE_DISPLAY1: size = getResources().getDimensionPixelSize(R.dimen.ate_default_textsize_display1); break; case Config.TEXTSIZE_DISPLAY2: size = getResources().getDimensionPixelSize(R.dimen.ate_default_textsize_display2); break; case Config.TEXTSIZE_DISPLAY3: size = getResources().getDimensionPixelSize(R.dimen.ate_default_textsize_display3); break; case Config.TEXTSIZE_DISPLAY4: size = getResources().getDimensionPixelSize(R.dimen.ate_default_textsize_display4); break; } mPreview.setTextSize(TypedValue.COMPLEX_UNIT_PX, size); final int dpValue = pxToSp(this, size); mValue.setText(String.format("%dsp", dpValue)); mSeeker.setProgress(dpValue - 1); } else { dismiss(); } }
private void init(Context context, AttributeSet attrs) { setTag("text_primary"); String key = null; if (attrs != null) { TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.ATEPrimaryTextView, 0, 0); try { key = a.getString(R.styleable.ATEPrimaryTextView_ateKey_primaryTextView); } finally { a.recycle(); } } ATE.apply(context, this, key); }