public class CircleProgressBarActivity extends AppCompatActivity implements
        AdapterView.OnItemSelectedListener, SeekBar.OnSeekBarChangeListener,
        CompoundButton.OnCheckedChangeListener, View.OnClickListener {

    private CircleProgressBar mProgress;
    private float density;

    public CircleProgressBarActivity() {
        super(R.layout.activity_circleprogressbar);
    }

    public static void start(Context context) {
        context.startActivity(new Intent(context, CircleProgressBarActivity.class));
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setSupportActionBar(R.id.cpb_toolbar);
        mProgress = findViewById(R.id.cpb_cpb_bar);
        density = getResources().getDisplayMetrics().density;

        this.<Spinner>findViewById(R.id.cpb_sp_gravity).setOnItemSelectedListener(this);
        this.<SeekBar>findViewById(R.id.cpb_sb_radius).setOnSeekBarChangeListener(this);
        this.<Spinner>findViewById(R.id.cpb_sp_scale_type).setOnItemSelectedListener(this);

        this.<Switch>findViewById(R.id.cpb_sh_progress_mode).setOnCheckedChangeListener(this);
        this.<SeekBar>findViewById(R.id.cpb_sb_loading_start_angle)
                .setOnSeekBarChangeListener(this);
        this.<SeekBar>findViewById(R.id.cpb_sb_loading_sweep_angle)
                .setOnSeekBarChangeListener(this);
        this.<SeekBar>findViewById(R.id.cpb_sb_loading_duration)
                .setOnSeekBarChangeListener(this);
        this.<Switch>findViewById(R.id.cpb_sh_loading_repeat_mode).setOnCheckedChangeListener(this);
        this.<Switch>findViewById(R.id.cpb_sh_loading_draw_other).setOnCheckedChangeListener(this);

        this.<SeekBar>findViewById(R.id.cpb_sb_start_angle).setOnSeekBarChangeListener(this);
        this.<SeekBar>findViewById(R.id.cpb_sb_sweep_angle).setOnSeekBarChangeListener(this);
        this.<SeekBar>findViewById(R.id.cpb_sb_background_size).setOnSeekBarChangeListener(this);
        this.<SeekBar>findViewById(R.id.cpb_sb_progress_size).setOnSeekBarChangeListener(this);
        this.<SeekBar>findViewById(R.id.cpb_sb_progress).setOnSeekBarChangeListener(this);
        this.<Switch>findViewById(R.id.cpb_sh_gradient).setOnCheckedChangeListener(this);
        this.<Switch>findViewById(R.id.cpb_sh_progress_value).setOnCheckedChangeListener(this);
        this.<SeekBar>findViewById(R.id.cpb_sb_progress_value_text_size)
                .setOnSeekBarChangeListener(this);

        this.<SeekBar>findViewById(R.id.cpb_sb_top_text_gap).setOnSeekBarChangeListener(this);
        this.<SeekBar>findViewById(R.id.cpb_sb_top_text_size).setOnSeekBarChangeListener(this);
        this.<SeekBar>findViewById(R.id.cpb_sb_bottom_text_gap).setOnSeekBarChangeListener(this);
        this.<SeekBar>findViewById(R.id.cpb_sb_bottom_text_size).setOnSeekBarChangeListener(this);
        this.<SeekBar>findViewById(R.id.cpb_sb_progress_duration).setOnSeekBarChangeListener(this);

        this.<Spinner>findViewById(R.id.cpb_sp_dial_visibility).setOnItemSelectedListener(this);
        this.<SeekBar>findViewById(R.id.cpb_sb_dial_gap).setOnSeekBarChangeListener(this);
        this.<SeekBar>findViewById(R.id.cpb_sb_dial_angle).setOnSeekBarChangeListener(this);
        this.<SeekBar>findViewById(R.id.cpb_sb_dial_height).setOnSeekBarChangeListener(this);
        this.<SeekBar>findViewById(R.id.cpb_sb_dial_width).setOnSeekBarChangeListener(this);
        this.<SeekBar>findViewById(R.id.cpb_sb_dial_special_unit).setOnSeekBarChangeListener(this);
        this.<SeekBar>findViewById(R.id.cpb_sb_dial_special_height).setOnSeekBarChangeListener(this);
        this.<SeekBar>findViewById(R.id.cpb_sb_dial_special_width).setOnSeekBarChangeListener(this);
        this.<Spinner>findViewById(R.id.cpb_sp_dial_gravity).setOnItemSelectedListener(this);
        this.<Switch>findViewById(R.id.cpb_sh_special_dial_value).setOnCheckedChangeListener(this);
        this.<SeekBar>findViewById(R.id.cpb_sb_special_dial_value_gap).setOnSeekBarChangeListener(this);
        this.<SeekBar>findViewById(R.id.cpb_sb_special_dial_value_text_size)
                .setOnSeekBarChangeListener(this);
        findViewById(R.id.cpb_btn_progress_animator).setOnClickListener(this);
    }

    // Listener
    @SuppressLint("RtlHardcoded")
    @Override
    public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
        switch (parent.getId()) {
            case R.id.cpb_sp_gravity:
                switch (position) {
                    default:
                    case 0:
                        mProgress.setGravity(Gravity.CENTER);
                        break;
                    case 1:
                        mProgress.setGravity(Gravity.LEFT);
                        break;
                    case 2:
                        mProgress.setGravity(Gravity.CENTER_HORIZONTAL);
                        break;
                    case 3:
                        mProgress.setGravity(Gravity.RIGHT);
                        break;
                    case 4:
                        mProgress.setGravity(Gravity.CENTER_VERTICAL);
                        break;
                    case 5:
                        mProgress.setGravity(Gravity.CENTER_VERTICAL | Gravity.RIGHT);
                        break;
                    case 6:
                        mProgress.setGravity(Gravity.BOTTOM);
                        break;
                    case 7:
                        mProgress.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL);
                        break;
                    case 8:
                        mProgress.setGravity(Gravity.BOTTOM | Gravity.RIGHT);
                        break;
                }
                break;
            case R.id.cpb_sp_scale_type:
                switch (position) {
                    default:
                    case 0:
                        mProgress.setScaleType(CircleProgressBar.ST_INSIDE);
                        break;
                    case 1:
                        mProgress.setScaleType(CircleProgressBar.ST_CROP);
                        break;
                    case 2:
                        mProgress.setScaleType(
                                CircleProgressBar.ST_INSIDE | CircleProgressBar.ST_CROP);
                        break;
                    case 3:
                        mProgress.setScaleType(CircleProgressBar.ST_NONE);
                        break;
                }
                break;
            case R.id.cpb_sp_dial_visibility:
                switch (position) {
                    default:
                    case 0:
                        mProgress.setDialVisibility(View.VISIBLE);
                        break;
                    case 1:
                        mProgress.setDialVisibility(View.INVISIBLE);
                        break;
                    case 2:
                        mProgress.setDialVisibility(View.GONE);
                        break;
                }
                break;
            case R.id.cpb_sp_dial_gravity:
                switch (position) {
                    default:
                    case 0:
                        mProgress.setDialGravity(Gravity.CENTER);
                        break;
                    case 1:
                        mProgress.setDialGravity(Gravity.TOP);
                        break;
                    case 2:
                        mProgress.setDialGravity(Gravity.BOTTOM);
                        break;
                }
                break;
        }
    }

    @Override
    public void onNothingSelected(AdapterView<?> parent) {
        // do nothing
    }

    @Override
    public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
        switch (seekBar.getId()) {
            case R.id.cpb_sb_radius:
                mProgress.setRadius(density * (progress + 100));
                break;
            case R.id.cpb_sb_loading_start_angle:
                mProgress.setLoadingStartAngle(progress);
                break;
            case R.id.cpb_sb_loading_sweep_angle:
                mProgress.setLoadingSweepAngle(progress);
                break;
            case R.id.cpb_sb_loading_duration:
                mProgress.setLoadingDuration(100 * (progress + 1));
                break;
            case R.id.cpb_sb_start_angle:
                mProgress.setStartAngle(progress);
                break;
            case R.id.cpb_sb_sweep_angle:
                mProgress.setSweepAngle(progress);
                break;
            case R.id.cpb_sb_background_size:
                mProgress.setBackgroundSize(density * progress);
                break;
            case R.id.cpb_sb_progress_size:
                mProgress.setProgressSize(density * progress);
                break;
            case R.id.cpb_sb_progress:
                mProgress.animationToProgress(progress);
                break;
            case R.id.cpb_sb_progress_value_text_size:
                mProgress.setProgressValueTextSize(density * (progress + 50));
                break;
            case R.id.cpb_sb_top_text_gap:
                mProgress.setTopTextGap(density * progress);
                break;
            case R.id.cpb_sb_top_text_size:
                mProgress.setTopTextSize(density * (progress + 10));
                break;
            case R.id.cpb_sb_bottom_text_gap:
                mProgress.setBottomTextGap(density * progress);
                break;
            case R.id.cpb_sb_bottom_text_size:
                mProgress.setBottomTextSize(density * (progress + 10));
                break;
            case R.id.cpb_sb_progress_duration:
                mProgress.setProgressDuration(100 * (progress + 1));
                break;
            case R.id.cpb_sb_dial_gap:
                mProgress.setDialGap(density * progress);
                break;
            case R.id.cpb_sb_dial_angle:
                mProgress.setDialAngle(progress);
                break;
            case R.id.cpb_sb_dial_height:
                mProgress.setDialHeight(density * progress);
                break;
            case R.id.cpb_sb_dial_width:
                mProgress.setDialWidth(density * progress);
                break;
            case R.id.cpb_sb_dial_special_unit:
                mProgress.setDialSpecialUnit(progress);
                break;
            case R.id.cpb_sb_dial_special_height:
                mProgress.setDialSpecialHeight(density * progress);
                break;
            case R.id.cpb_sb_dial_special_width:
                mProgress.setDialSpecialWidth(density * progress);
                break;
            case R.id.cpb_sb_special_dial_value_gap:
                mProgress.setSpecialDialValueGap(density * progress);
                break;
            case R.id.cpb_sb_special_dial_value_text_size:
                mProgress.setSpecialDialValueTextSize(density * (progress + 5));
                break;
        }
    }

    @Override
    public void onStartTrackingTouch(SeekBar seekBar) {
        // do nothing
    }

    @Override
    public void onStopTrackingTouch(SeekBar seekBar) {
        // do nothing
    }

    @Override
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
        switch (buttonView.getId()) {
            case R.id.cpb_sh_progress_mode:
                mProgress.setProgressMode(isChecked ?
                        CircleProgressBar.ProgressMode.LOADING :
                        CircleProgressBar.ProgressMode.PROGRESS);
                break;
            case R.id.cpb_sh_loading_repeat_mode:
                mProgress.setLoadingRepeatMode(isChecked ? ValueAnimator.REVERSE :
                        ValueAnimator.RESTART);
                break;
            case R.id.cpb_sh_loading_draw_other:
                mProgress.setLoadingDrawOther(isChecked);
                break;
            case R.id.cpb_sh_gradient:
                if (isChecked)
                    mProgress.setGradientColors(0xff33b5e5, 0xff99cc00, 0xffffbb33,
                            0xffff4444, 0xff33b5e5);
                else
                    mProgress.setGradientColors(0xffff4444);
                break;
            case R.id.cpb_sh_progress_value:
                mProgress.setShowSpecialDialValue(isChecked);
                break;
            case R.id.cpb_sh_special_dial_value:
                mProgress.setShowSpecialDialValue(isChecked);
                break;
        }
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.cpb_btn_progress_animator:
                mProgress.animationToProgress(0, mProgress.getProgress());
                break;
        }
    }
} public class DrawableRatingBarActivity extends AppCompatActivity implements
        AdapterView.OnItemSelectedListener, CompoundButton.OnCheckedChangeListener,
        SeekBar.OnSeekBarChangeListener {

    private DrawableRatingBar mVRating;

    public DrawableRatingBarActivity() {
        super(R.layout.activity_drawableratingbar);
    }

    public static void start(Context context) {
        context.startActivity(new Intent(context, DrawableRatingBarActivity.class));
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setSupportActionBar(R.id.drb_toolbar);
        mVRating = findViewById(R.id.drb_rb_stars);
        final SeekBar max = findViewById(R.id.drb_sb_max);
        final SeekBar min = findViewById(R.id.drb_sb_min);

        this.<Spinner>findViewById(R.id.drb_sp_gravity).setOnItemSelectedListener(this);
        this.<SwitchMaterial>findViewById(R.id.drb_sh_manually).setOnCheckedChangeListener(this);
        this.<SwitchMaterial>findViewById(R.id.drb_sh_touchable).setOnCheckedChangeListener(this);
        max.setOnSeekBarChangeListener(this);
        max.setProgress(0);
        min.setOnSeekBarChangeListener(this);
        min.setProgress(1);
    }

    // Listener
    @SuppressLint("RtlHardcoded")
    @Override
    public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
        switch (position) {
            default:
            case 0:
                mVRating.setGravity(Gravity.CENTER);
                break;
            case 1:
                mVRating.setGravity(Gravity.LEFT);
                break;
            case 2:
                mVRating.setGravity(Gravity.CENTER_HORIZONTAL);
                break;
            case 3:
                mVRating.setGravity(Gravity.RIGHT);
                break;
            case 4:
                mVRating.setGravity(Gravity.CENTER_VERTICAL);
                break;
            case 5:
                mVRating.setGravity(Gravity.CENTER_VERTICAL | Gravity.RIGHT);
                break;
            case 6:
                mVRating.setGravity(Gravity.BOTTOM);
                break;
            case 7:
                mVRating.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL);
                break;
            case 8:
                mVRating.setGravity(Gravity.BOTTOM | Gravity.RIGHT);
                break;
        }
    }

    @Override
    public void onNothingSelected(AdapterView<?> parent) {

    }

    @Override
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
        int id = buttonView.getId();
        if (id == R.id.drb_sh_manually) {
            mVRating.setManually(isChecked);
        } else if (id == R.id.drb_sh_touchable) {
            mVRating.setOnlyItemTouchable(isChecked);
        }
    }

    @Override
    public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
        int id = seekBar.getId();
        if (id == R.id.drb_sb_max) {
            mVRating.setMax(6 + progress);
        } else if (id == R.id.drb_sb_min) {
            mVRating.setMin(progress);
        }
    }

    @Override
    public void onStartTrackingTouch(SeekBar seekBar) {

    }

    @Override
    public void onStopTrackingTouch(SeekBar seekBar) {

    }
} public class GradientTabStripActivity extends AppCompatActivity {

    public GradientTabStripActivity() {
        super(R.layout.activity_gradienttabstrip);
    }

    public static void start(Context context) {
        context.startActivity(new Intent(context, GradientTabStripActivity.class));
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setSupportActionBar(R.id.gts_toolbar);
        ((ViewPager) findViewById(R.id.gts_vp_pagers))
                .setAdapter(new PagerAdapter(getPagers()));
        ((GradientTabStrip) findViewById(R.id.gts_gts_tabs))
                .setAdapter(new TabAdapter(this));
    }

    private ArrayList<View> getPagers() {
        ArrayList<View> views = new ArrayList<>();
        for (int i = 0; i < 4; i++) {
            TextView text = new TextView(this);
            text.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 180);
            text.setText(String.format(Locale.getDefault(), "%d", i + 1));
            text.setGravity(Gravity.CENTER);
            text.setTextColor(0xff000000);
            views.add(text);
        }
        return views;
    }

    private static class PagerAdapter extends ViewsPagerAdapter {
        PagerAdapter(List<View> views) {
            super(views);
        }

        @Nullable
        @Override
        public CharSequence getPageTitle(int position) {
            switch (position) {
                default:
                    return "标签" + position;
                case 0:
                    return "微信";
                case 1:
                    return "通讯录";
                case 2:
                    return "发现";
                case 3:
                    return "我";
            }
        }
    }

    private static class TabAdapter extends GradientTabStrip.Adapter {

        private final Drawable mNormal0;
        private final Drawable mNormal1;
        private final Drawable mNormal2;
        private final Drawable mNormal3;
        private final Drawable mSelected0;
        private final Drawable mSelected1;
        private final Drawable mSelected2;
        private final Drawable mSelected3;

        TabAdapter(Context context) {
            mNormal0 = ContextCompat.getDrawable(context,
                    R.drawable.ic_gradienttabstrip_chat_normal);
            mNormal1 = ContextCompat.getDrawable(context,
                    R.drawable.ic_gradienttabstrip_contacts_normal);
            mNormal2 = ContextCompat.getDrawable(context,
                    R.drawable.ic_gradienttabstrip_discovery_normal);
            mNormal3 = ContextCompat.getDrawable(context,
                    R.drawable.ic_gradienttabstrip_account_normal);
            mSelected0 = ContextCompat.getDrawable(context,
                    R.drawable.ic_gradienttabstrip_chat_selected);
            mSelected1 = ContextCompat.getDrawable(context,
                    R.drawable.ic_gradienttabstrip_contacts_selected);
            mSelected2 = ContextCompat.getDrawable(context,
                    R.drawable.ic_gradienttabstrip_discovery_selected);
            mSelected3 = ContextCompat.getDrawable(context,
                    R.drawable.ic_gradienttabstrip_account_selected);
        }

        @Nullable
        @Override
        public Drawable getDrawableNormal(int position, int count) {
            switch (position) {
                default:
                case 0:
                    return mNormal0;
                case 1:
                    return mNormal1;
                case 2:
                    return mNormal2;
                case 3:
                    return mNormal3;
            }
        }

        @Nullable
        @Override
        public Drawable getDrawableSelected(int position, int count) {
            switch (position) {
                default:
                case 0:
                    return mSelected0;
                case 1:
                    return mSelected1;
                case 2:
                    return mSelected2;
                case 3:
                    return mSelected3;
            }
        }

        @Override
        public String getDotText(int position, int count) {
            switch (position) {
                default:
                    return null;
                case 0:
                    return "999";
                case 1:
                    return "1";
                case 2:
                    return "";
            }
        }
    }
} public class HeaderFooterGridViewActivity extends AppCompatActivity implements
        CompoundButton.OnCheckedChangeListener, SeekBar.OnSeekBarChangeListener,
        View.OnClickListener, AdapterView.OnItemClickListener {

    private final Adapter mAdapter = new Adapter();
    private HeaderFooterGridView mVContent;
    private TextView tvHeaderView1, tvHeaderView2, tvHeaderView3;
    private TextView tvHeaderItem1, tvHeaderItem2, tvHeaderItem3;
    private TextView tvFooterView1, tvFooterView2, tvFooterView3;
    private TextView tvFooterItem1, tvFooterItem2, tvFooterItem3;

    public HeaderFooterGridViewActivity() {
        super(R.layout.activity_headerfootergridview);
    }

    public static void start(Context context) {
        context.startActivity(new Intent(context, HeaderFooterGridViewActivity.class));
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setSupportActionBar(R.id.hfg_toolbar);
        mVContent = findViewById(R.id.hfg_hfg_content);
        tvHeaderView1 = createTextView(this);
        tvHeaderView2 = createTextView(this);
        tvHeaderView3 = createTextView(this);
        tvHeaderItem1 = createTextView(this);
        tvHeaderItem2 = createTextView(this);
        tvHeaderItem3 = createTextView(this);
        tvFooterView1 = createTextView(this);
        tvFooterView2 = createTextView(this);
        tvFooterView3 = createTextView(this);
        tvFooterItem1 = createTextView(this);
        tvFooterItem2 = createTextView(this);
        tvFooterItem3 = createTextView(this);

        tvHeaderView1.setText(String.format(Locale.getDefault(),
                getString(R.string.hfg_hv), 1));
        tvHeaderView2.setText(String.format(Locale.getDefault(),
                getString(R.string.hfg_hv), 2));
        tvHeaderView3.setText(String.format(Locale.getDefault(),
                getString(R.string.hfg_hv), 3));
        tvHeaderItem1.setText(String.format(Locale.getDefault(),
                getString(R.string.hfg_header), 1));
        tvHeaderItem2.setText(String.format(Locale.getDefault(),
                getString(R.string.hfg_header), 2));
        tvHeaderItem3.setText(String.format(Locale.getDefault(),
                getString(R.string.hfg_header), 3));
        tvFooterView1.setText(String.format(Locale.getDefault(),
                getString(R.string.hfg_fv), 1));
        tvFooterView2.setText(String.format(Locale.getDefault(),
                getString(R.string.hfg_fv), 2));
        tvFooterView3.setText(String.format(Locale.getDefault(),
                getString(R.string.hfg_fv), 3));
        tvFooterItem1.setText(String.format(Locale.getDefault(),
                getString(R.string.hfg_footer), 1));
        tvFooterItem2.setText(String.format(Locale.getDefault(),
                getString(R.string.hfg_footer), 2));
        tvFooterItem3.setText(String.format(Locale.getDefault(),
                getString(R.string.hfg_footer), 3));


        tvHeaderView1.setOnClickListener(this);
        tvHeaderView2.setOnClickListener(this);
        tvHeaderView3.setOnClickListener(this);
        tvFooterView1.setOnClickListener(this);
        tvFooterView2.setOnClickListener(this);
        tvFooterView3.setOnClickListener(this);

        ((CheckBox) findViewById(R.id.hfg_cb_hv)).setOnCheckedChangeListener(this);
        ((CheckBox) findViewById(R.id.hfg_cb_hi)).setOnCheckedChangeListener(this);
        ((CheckBox) findViewById(R.id.hfg_cb_fv)).setOnCheckedChangeListener(this);
        ((CheckBox) findViewById(R.id.hfg_cb_fi)).setOnCheckedChangeListener(this);
        ((SeekBar) findViewById(R.id.hfg_sb_number)).setOnSeekBarChangeListener(this);

        mVContent.setAdapter(mAdapter);
        mVContent.setOnItemClickListener(this);

    }

    private AppCompatTextView createTextView(Context context) {
        final float density = context.getResources().getDisplayMetrics().density;
        AppCompatTextView text = new AppCompatTextView(context);
        text.setTextColor(0xff999999);
        text.setGravity(Gravity.CENTER);
        text.setMinimumWidth((int) (64 * density));
        text.setMinimumHeight((int) (48 * density));
        text.setBackgroundResource(R.drawable.bg_headerfootergridview_item);
        return text;
    }

    // Listener
    @Override
    public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
        final int id = compoundButton.getId();
        if (id == R.id.hfg_cb_hv) {
            changeHeaderView(checked);
        } else if (id == R.id.hfg_cb_hi) {
            changeHeaderItem(checked);
        } else if (id == R.id.hfg_cb_fv) {
            changeFooterView(checked);
        } else if (id == R.id.hfg_cb_fi) {
            changeFooterItem(checked);
        }
    }

    private void changeHeaderView(boolean add) {
        if (add) {
            mVContent.addHeaderView(tvHeaderView1);
            mVContent.addHeaderView(tvHeaderView2);
            mVContent.addHeaderView(tvHeaderView3);
        } else {
            mVContent.removeHeaderView(tvHeaderView1);
            mVContent.removeHeaderView(tvHeaderView2);
            mVContent.removeHeaderView(tvHeaderView3);
        }
    }

    private void changeHeaderItem(boolean add) {
        if (add) {
            mVContent.addHeaderItem(tvHeaderItem1, null, true);
            mVContent.addHeaderItem(tvHeaderItem2, null, true);
            mVContent.addHeaderItem(tvHeaderItem3, null, true);
        } else {
            mVContent.removeHeaderItem(tvHeaderItem1);
            mVContent.removeHeaderItem(tvHeaderItem2);
            mVContent.removeHeaderItem(tvHeaderItem3);
        }
    }

    private void changeFooterView(boolean add) {
        if (add) {
            mVContent.addFooterView(tvFooterView1);
            mVContent.addFooterView(tvFooterView2);
            mVContent.addFooterView(tvFooterView3);
        } else {
            mVContent.removeFooterView(tvFooterView1);
            mVContent.removeFooterView(tvFooterView2);
            mVContent.removeFooterView(tvFooterView3);
        }
    }

    private void changeFooterItem(boolean add) {
        if (add) {
            mVContent.addFooterItem(tvFooterItem1, null, true);
            mVContent.addFooterItem(tvFooterItem2, null, true);
            mVContent.addFooterItem(tvFooterItem3, null, true);
        } else {
            mVContent.removeFooterItem(tvFooterItem1);
            mVContent.removeFooterItem(tvFooterItem2);
            mVContent.removeFooterItem(tvFooterItem3);
        }
    }

    @Override
    public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
        mAdapter.setCount(progress);
    }

    @Override
    public void onStartTrackingTouch(SeekBar seekBar) {

    }

    @Override
    public void onStopTrackingTouch(SeekBar seekBar) {

    }

    @Override
    public void onClick(View view) {
        if (view instanceof TextView) {
            TextView tv = (TextView) view;
            Toast.makeText(getApplicationContext(), tv.getText(), Toast.LENGTH_SHORT).show();
        }
    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        onClick(view);
    }

    private class Adapter extends BaseAdapter {

        private int count;

        @Override
        public int getCount() {
            return count;
        }

        void setCount(int count) {
            this.count = count;
            notifyDataSetChanged();
        }

        @Override
        public Object getItem(int position) {
            return position;
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(int position, View view, ViewGroup parent) {
            final Context context = parent.getContext();
            if (view == null)
                view = createTextView(context);
            final TextView tvItem = (TextView) view;
            tvItem.setText(String.format(Locale.getDefault(),
                    context.getString(R.string.hfg_item), position + 1));
            return view;
        }
    }
} public class IndicatorTabStripActivity extends AppCompatActivity {

    public IndicatorTabStripActivity() {
        super(R.layout.activity_indicatortabstrip);
    }

    public static void start(Context context) {
        context.startActivity(new Intent(context, IndicatorTabStripActivity.class));
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setSupportActionBar(R.id.its_toolbar);
        ((ViewPager) findViewById(R.id.its_vp_content)).setAdapter(new PagerAdapter(getPagers()));
        ((IndicatorTabStrip) findViewById(R.id.its_its_tabs)).setAdapter(new TabAdapter());
    }

    private ArrayList<View> getPagers() {
        ArrayList<View> views = new ArrayList<>();
        for (int i = 0; i < 3; i++) {
            TextView text = new TextView(this);
            text.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 180);
            text.setText(String.format(Locale.getDefault(), "%d", i + 1));
            text.setGravity(Gravity.CENTER);
            text.setTextColor(0xff000000);
            views.add(text);
        }
        return views;
    }

    private static class PagerAdapter extends ViewsPagerAdapter {

        PagerAdapter(List<View> views) {
            super(views);
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return "Tab" + (position + 1);
        }
    }

    private static class TabAdapter extends IndicatorTabStrip.Adapter {
        @Override
        public String getDotText(int position, int count) {
            switch (position) {
                default:
                case 0:
                    return "1";
                case 1:
                    return "";
                case 2:
                    return "888";
                case 3:
                    return "new";
            }
        }
    }
} public class MultiActionTextViewActivity extends AppCompatActivity implements View.OnClickListener,
        MultiActionClickableSpan.OnTextClickedListener {

    public MultiActionTextViewActivity() {
        super(R.layout.activity_multiactiontextview);
    }

    public static void start(Context context) {
        context.startActivity(new Intent(context, MultiActionTextViewActivity.class));
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setSupportActionBar(R.id.mat_toolbar);
        final MultiActionTextView text = findViewById(R.id.mat_tv_content);
        final int colorPrimary = ContextCompat.getColor(this, R.color.colorPrimary);
        final int colorAccent = ContextCompat.getColor(this, R.color.colorAccent);
        final int colorRipple = ContextCompat.getColor(this, R.color.colorRipple);
        MultiActionClickableSpan action1 = new MultiActionClickableSpan(
                0, 7, colorPrimary, true, false, this);
        MultiActionClickableSpan action2 = new MultiActionClickableSpan(
                10, 15, colorAccent, false, true, this);
        MultiActionClickableSpan action3 = new MultiActionClickableSpan(
                134, 140, colorRipple, false, true, this);
        MultiActionClickableSpan action4 = new MultiActionClickableSpan(
                181, 189, colorRipple, false, true, this);
        MultiActionClickableSpan action5 = new MultiActionClickableSpan(
                214, 230, colorRipple, false, true, this);
        MultiActionClickableSpan action6 = new MultiActionClickableSpan(
                346, 356, colorRipple, false, true, this);
        MultiActionClickableSpan action7 = new MultiActionClickableSpan(
                382, 392, colorRipple, false, true, this);
        text.setText(R.string.mat_content,
                action1, action2, action3, action4, action5, action6, action7);
        text.setOnClickListener(this);
    }

    // Listener
    @Override
    public void onClick(View view) {
        Toast.makeText(this, R.string.mat_toast, Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onTextClicked(View view, MultiActionClickableSpan span) {
        String text = ((TextView) view).getText().toString();
        Toast.makeText(this, text.substring(span.getStart(), span.getEnd()),
                Toast.LENGTH_SHORT).show();
    }
} public class MultifunctionalImageViewActivity extends AppCompatActivity implements
        CompoundButton.OnCheckedChangeListener, SeekBar.OnSeekBarChangeListener,
        AdapterView.OnItemSelectedListener {

    private final RoundRectClipOutlineProvider mRoundRect =
            new RoundRectClipOutlineProvider(0);
    private MultifunctionalImageView mVImage;

    public MultifunctionalImageViewActivity() {
        super(R.layout.activity_multifunctionalimageview);
    }

    public static void start(Context context) {
        context.startActivity(new Intent(context, MultifunctionalImageViewActivity.class));
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setSupportActionBar(R.id.miv_toolbar);
        mVImage = findViewById(R.id.miv_image);
        final SwitchMaterial crop = findViewById(R.id.miv_sw_crop);
        final SeekBar radius = findViewById(R.id.miv_sb_radius);
        final SeekBar height = findViewById(R.id.miv_sb_height);
        final SeekBar border = findViewById(R.id.miv_sb_border);
        final SeekBar padding = findViewById(R.id.miv_sb_padding);

        crop.setOnCheckedChangeListener(this);
        crop.setChecked(true);
        radius.setOnSeekBarChangeListener(this);
        radius.setProgress(10);
        height.setOnSeekBarChangeListener(this);
        height.setProgress(0);
        border.setOnSeekBarChangeListener(this);
        border.setProgress(2);
        padding.setOnSeekBarChangeListener(this);
        padding.setProgress(0);
        this.<Spinner>findViewById(R.id.miv_sp_scale_type).setOnItemSelectedListener(this);
    }

    // Listener
    @Override
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
        if (isChecked) {
            mVImage.setClipOutlineProvider(ClipOutlineProvider.CIRCLE);
        } else {
            mVImage.setClipOutlineProvider(mRoundRect);
        }
    }

    @Override
    public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
        final int id = seekBar.getId();
        if (id == R.id.miv_sb_height) {
            mVImage.setFixedSize(100, 100 - progress);
        } else if (id == R.id.miv_sb_border) {
            mVImage.setBorderWidth((int) (progress *
                    getResources().getDisplayMetrics().density));
        } else if (id == R.id.miv_sb_radius) {
            mRoundRect.setRadius(progress * getResources().getDisplayMetrics().density);
            mVImage.invalidateClipOutline();
        } else if (id == R.id.miv_sb_padding) {
            final int padding = (int) (progress * getResources().getDisplayMetrics().density);
            mVImage.setPadding(padding, padding, padding, padding);
        }
    }

    @Override
    public void onStartTrackingTouch(SeekBar seekBar) {
        // do nothing
    }

    @Override
    public void onStopTrackingTouch(SeekBar seekBar) {
        // do nothing
    }

    @Override
    public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
        switch (position) {
            default:
            case 0:
                mVImage.setScaleType(ImageView.ScaleType.CENTER);
                break;
            case 1:
                mVImage.setScaleType(ImageView.ScaleType.CENTER_CROP);
                break;
            case 2:
                mVImage.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
                break;
            case 3:
                mVImage.setScaleType(ImageView.ScaleType.FIT_CENTER);
                break;
            case 4:
                mVImage.setScaleType(ImageView.ScaleType.FIT_END);
                break;
            case 5:
                mVImage.setScaleType(ImageView.ScaleType.FIT_START);
                break;
            case 6:
                mVImage.setScaleType(ImageView.ScaleType.FIT_XY);
                break;
            case 7:
                mVImage.setScaleType(ImageView.ScaleType.MATRIX);
                break;
        }
    }

    @Override
    public void onNothingSelected(AdapterView<?> parent) {

    }
} public class MultifunctionalRecyclerViewActivity extends AppCompatActivity {

    private final Adapter mAdapter = new Adapter();
    private MultifunctionalRecyclerView mVContent;
    private MultifunctionalLinearLayoutManager mManager;

    public MultifunctionalRecyclerViewActivity() {
        super(R.layout.activity_multifunctionalrecyclerview);
    }

    public static void start(Context context) {
        context.startActivity(new Intent(context, MultifunctionalRecyclerViewActivity.class));
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setSupportActionBar(R.id.mrv_toolbar);
        mVContent = findViewById(R.id.mrv_rv_content);
        final int gap = 20;
        mManager = new MultifunctionalLinearLayoutManager(this);
        mManager.setLayoutInCenter(true);
        mManager.setChildMaxSize(mAdapter.getChildMaxWidth(), mAdapter.getChildMaxHeight());
        mManager.setDecorationMaxWidthOfChildWithMaxSize(gap, gap, gap, gap);
        mVContent.setLayoutManager(mManager);
        mVContent.addItemDecoration(new ItemDecoration(gap));
        mVContent.setScaleEnable(true);
        mVContent.setScaleRange(1, 6);

        mVContent.setAdapter(mAdapter);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        super.onCreateOptionsMenu(menu);
        getMenuInflater().inflate(R.menu.menu_multifunctionalrecyckerview, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case R.id.mrv_vertical_continuity:
                mManager.setOrientation(RecyclerView.VERTICAL);
                mManager.setPagingEnable(false);
                mVContent.invalidateItemDecorations();
                return true;
            case R.id.mrv_vertical_singular:
                mManager.setOrientation(RecyclerView.VERTICAL);
                mManager.setPagingEnable(true);
                mVContent.invalidateItemDecorations();
                return true;
            case R.id.mrv_horizontal_continuity:
                mManager.setOrientation(RecyclerView.HORIZONTAL);
                mManager.setPagingEnable(false);
                mVContent.invalidateItemDecorations();
                return true;
            case R.id.mrv_horizontal_singular:
                mManager.setOrientation(RecyclerView.HORIZONTAL);
                mManager.setPagingEnable(true);
                mVContent.invalidateItemDecorations();
                return true;
            default:
                return super.onOptionsItemSelected(item);
        }
    }
} public class RecyclePagerActivity extends AppCompatActivity implements View.OnClickListener {

    private final Adapter mAdapter = new Adapter();
    private TextView mVPage;
    private TextView mVTitle;

    public RecyclePagerActivity() {
        super(R.layout.activity_recyclepager);
    }

    public static void start(Context context) {
        context.startActivity(new Intent(context, RecyclePagerActivity.class));
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setSupportActionBar(R.id.rp_toolbar);
        final ViewPager pager = findViewById(R.id.rp_vp_content);
        mVPage = findViewById(R.id.rp_tv_page_value);
        mVTitle = findViewById(R.id.rp_tv_offset_value);
        pager.setAdapter(mAdapter);
        findViewById(R.id.rp_btn_reduce_page).setOnClickListener(this);
        findViewById(R.id.rp_btn_add_page).setOnClickListener(this);
        findViewById(R.id.rp_btn_reduce_offset).setOnClickListener(this);
        findViewById(R.id.rp_btn_add_offset).setOnClickListener(this);
        findViewById(R.id.rp_btn_exchange).setOnClickListener(this);
        mVPage.setText(String.format(Locale.getDefault(), "%d", mAdapter.mCount));
        mVTitle.setText(String.format(Locale.getDefault(), "%d", mAdapter.mOffset));
    }

    // Listener
    @Override
    public void onClick(View v) {
        final int id = v.getId();
        if (id == R.id.rp_btn_reduce_page) {
            mAdapter.reducePage();
            mVPage.setText(String.format(Locale.getDefault(), "%d", mAdapter.mCount));
        } else if (id == R.id.rp_btn_add_page) {
            mAdapter.addPage();
            mVPage.setText(String.format(Locale.getDefault(), "%d", mAdapter.mCount));
        } else if (id == R.id.rp_btn_reduce_offset) {
            mAdapter.reduceOffset();
            mVTitle.setText(String.format(Locale.getDefault(), "%d", mAdapter.mOffset));
        } else if (id == R.id.rp_btn_add_offset) {
            mAdapter.addOffset();
            mVTitle.setText(String.format(Locale.getDefault(), "%d", mAdapter.mOffset));
        } else if (id == R.id.rp_btn_exchange) {
            mAdapter.exchange();
        }
    }

    private static class Holder extends RecyclePagerAdapter.PagerViewHolder {

        Holder(Context context) {
            super(new AppCompatTextView(context));
            final AppCompatTextView text = (AppCompatTextView) itemView;
            text.setGravity(Gravity.CENTER);
            text.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 128);
        }

        void setData(String data) {
            ((AppCompatTextView) itemView).setText(data);
        }
    }

    private static class RedHolder extends Holder {
        RedHolder(Context context) {
            super(context);
            ((AppCompatTextView) itemView).setTextColor(
                    ContextCompat.getColor(context, R.color.colorAccent));
        }
    }

    private static class BlueHolder extends Holder {

        BlueHolder(Context context) {
            super(context);
            ((AppCompatTextView) itemView).setTextColor(
                    ContextCompat.getColor(context, R.color.colorPrimary));
        }
    }

    private static class Adapter extends RecyclePagerAdapter<Holder> {

        private static final int TYPE_RED = 1;
        private static final int TYPE_BLUE = 2;
        private int mCount = 5;
        private int mOffset = 1;
        private boolean mExchanged = false;

        @Override
        public int getItemCount() {
            return mCount;
        }

        @Override
        public int getItemViewType(int position) {
            if (mExchanged)
                return position % 2 == 0 ? TYPE_RED : TYPE_BLUE;
            return position % 2 == 0 ? TYPE_BLUE : TYPE_RED;
        }

        @Override
        public Holder onCreateViewHolder(ViewGroup parent, int viewType) {
            if (viewType == TYPE_RED)
                return new RedHolder(parent.getContext());
            return new BlueHolder(parent.getContext());
        }

        @Override
        public void onBindViewHolder(Holder holder, int position) {
            holder.setData(String.format(Locale.getDefault(), "%d",
                    position + mOffset));
        }

        void addPage() {
            mCount++;
            notifyItemInserted(mCount - 1);
        }

        void reducePage() {
            mCount--;
            mCount = Math.max(mCount, 0);
            notifyItemRemoved(mCount);
        }

        void addOffset() {
            mOffset++;
            notifyItemRangeChanged(0, mCount);
        }

        void reduceOffset() {
            mOffset--;
            notifyItemRangeChanged(0, mCount);
        }

        void exchange() {
            mExchanged = !mExchanged;
            notifyItemRangeChanged(0, mCount);
        }
    }
} public class SmoothInputLayoutActivity extends AppCompatActivity implements View.OnClickListener,
        View.OnTouchListener, TextWatcher, SmoothInputLayout.OnVisibilityChangeListener {

    private SmoothInputLayout lytContent;
    private View btnVoice;
    private EditText edtInput;
    private View btnEmoji;
    private View btnSendVoice;
    private View btnMore;
    private View btnSend;
    private View vEmoji;
    private View vMore;

    public SmoothInputLayoutActivity() {
        super(R.layout.activity_smoothinputlayout);
    }

    public static void start(Context context) {
        context.startActivity(new Intent(context, SmoothInputLayoutActivity.class));
    }

    @SuppressLint("ClickableViewAccessibility")
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setSupportActionBar(R.id.sil_toolbar);
        lytContent = findViewById(R.id.sil_lyt_content);
        btnVoice = findViewById(R.id.sil_ibtn_voice);
        edtInput = findViewById(R.id.sil_edt_input);
        btnEmoji = findViewById(R.id.sil_ibtn_emoji);
        btnSendVoice = findViewById(R.id.sil_btn_send_voice);
        btnMore = findViewById(R.id.sil_ibtn_more);
        btnSend = findViewById(R.id.sil_ibtn_send);
        vEmoji = findViewById(R.id.sil_lyt_emoji);
        vMore = findViewById(R.id.sil_lyt_more);
        lytContent.setOnVisibilityChangeListener(this);
        btnVoice.setOnClickListener(this);
        edtInput.addTextChangedListener(this);
        btnEmoji.setOnClickListener(this);
        btnSendVoice.setOnClickListener(this);
        btnMore.setOnClickListener(this);
        btnSend.setOnClickListener(this);
        edtInput.setOnTouchListener(this);
        findViewById(R.id.sil_v_list).setOnTouchListener(this);
    }

    @Override
    public void onBackPressed() {
        if (lytContent.isInputPaneOpen()) {
            lytContent.closeInputPane();
            return;
        }
        super.onBackPressed();
    }

    // Listener
    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.sil_ibtn_voice:
                btnMore.setSelected(false);
                btnEmoji.setSelected(false);
                if (btnVoice.isSelected()) {
                    btnVoice.setSelected(false);
                    showInputWidget();
                } else {
                    btnVoice.setSelected(true);
                    lytContent.closeInputPane();
                    lytContent.closeKeyboard(true);
                    showVoiceWidget();
                }
                break;
            case R.id.sil_btn_send_voice:
                Toast.makeText(getApplicationContext(), R.string.sil_voice,
                        Toast.LENGTH_SHORT).show();
                break;
            case R.id.sil_ibtn_emoji:
                btnMore.setSelected(false);
                if (btnEmoji.isSelected()) {
                    btnEmoji.setSelected(false);
                    showInput();
                } else {
                    btnEmoji.setSelected(true);
                    showEmoji();
                }
                break;
            case R.id.sil_ibtn_more:
                btnEmoji.setSelected(false);
                btnVoice.setSelected(false);
                if (btnMore.isSelected()) {
                    btnMore.setSelected(false);
                    showInput();
                } else {
                    btnMore.setSelected(true);
                    showMore();
                }
                break;
            case R.id.sil_ibtn_send:
                sendMessage();
                break;
        }
    }

    /**
     * 显示输入控件
     */
    private void showInputWidget() {
        edtInput.setVisibility(View.VISIBLE);
        btnEmoji.setVisibility(View.VISIBLE);
        btnSendVoice.setVisibility(View.GONE);
        afterTextChanged(edtInput.getText());
        showInput();
    }

    /**
     * 显示语音控件
     */
    private void showVoiceWidget() {
        edtInput.setVisibility(View.GONE);
        btnEmoji.setVisibility(View.GONE);
        btnSendVoice.setVisibility(View.VISIBLE);
        btnMore.setVisibility(View.VISIBLE);
        btnSend.setVisibility(View.GONE);
    }

    /**
     * 显示输入面板
     */
    private void showInput() {
        lytContent.showKeyboard();
        afterTextChanged(edtInput.getText());
    }

    /**
     * 显示Emoji面板
     */
    private void showEmoji() {
        vEmoji.setVisibility(View.VISIBLE);
        vMore.setVisibility(View.GONE);
        lytContent.showInputPane(true);
    }

    /**
     * 显示更多面板
     */
    private void showMore() {
        edtInput.setVisibility(View.VISIBLE);
        btnEmoji.setVisibility(View.VISIBLE);
        btnSendVoice.setVisibility(View.GONE);
        vEmoji.setVisibility(View.GONE);
        vMore.setVisibility(View.VISIBLE);
        lytContent.showInputPane(false);
    }

    private void sendMessage() {
        Toast.makeText(getApplicationContext(), edtInput.getText().toString().trim(),
                Toast.LENGTH_SHORT).show();
        edtInput.setText(null);
    }

    @Override
    public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

    }

    @Override
    public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {

    }

    @Override
    public void afterTextChanged(Editable editable) {
        if (editable.toString().trim().length() > 0) {
            btnMore.setVisibility(View.GONE);
            btnSend.setVisibility(View.VISIBLE);
        } else {
            btnMore.setVisibility(View.VISIBLE);
            btnSend.setVisibility(View.GONE);
        }
    }

    @Override
    public void onVisibilityChange(int visibility) {
        if (visibility == View.GONE) {
            btnEmoji.setSelected(false);
        } else {
            btnEmoji.setSelected(vEmoji.getVisibility() == View.VISIBLE);
        }
    }

    @Override
    public boolean onTouch(View view, MotionEvent motionEvent) {
        switch (view.getId()) {
            case R.id.sil_v_list:
                btnVoice.setSelected(false);
                btnEmoji.setSelected(false);
                btnMore.setSelected(false);
                lytContent.closeKeyboard(true);
                lytContent.closeInputPane();
                break;
            case R.id.sil_edt_input:
                btnVoice.setSelected(false);
                btnEmoji.setSelected(false);
                btnMore.setSelected(false);
                afterTextChanged(edtInput.getText());
                break;
        }

        return false;
    }
} public class StateLayoutActivity extends AppCompatActivity implements
        RadioGroup.OnCheckedChangeListener, View.OnClickListener {

    private StateFrameLayout mVState;
    private Drawable mDLoading;
    private Drawable mDError;
    private Drawable mDEmpty;
    private View mVLoading;
    private View mVError;
    private View mVEmpty;

    public StateLayoutActivity() {
        super(R.layout.activity_statelayout);
    }

    public static void start(Context context) {
        context.startActivity(new Intent(context, StateLayoutActivity.class));
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setSupportActionBar(R.id.sl_toolbar);
        mVState = findViewById(R.id.sl_lyt_state);
        final RadioGroup state = findViewById(R.id.sl_rg_state);
        final RadioGroup mode = findViewById(R.id.sl_rg_mode);
        mDLoading = ContextCompat.getDrawable(this, R.drawable.ic_statelayout_loading);
        mDError = ContextCompat.getDrawable(this, R.drawable.ic_statelayout_error);
        mDEmpty = ContextCompat.getDrawable(this, R.drawable.ic_statelayout_empty);
        final CircularProgressImageView loading = new CircularProgressImageView(this);
        loading.setColorSchemeColors(
                ContextCompat.getColor(this, android.R.color.holo_red_light),
                ContextCompat.getColor(this, android.R.color.holo_blue_light),
                ContextCompat.getColor(this, android.R.color.holo_green_light),
                ContextCompat.getColor(this, android.R.color.holo_orange_light),
                ContextCompat.getColor(this, android.R.color.holo_purple));
        mVLoading = loading;
        final AppCompatTextView error = new AppCompatTextView(this);
        error.setText(R.string.sl_change_state_error);
        error.setTextColor(0xffff4081);
        error.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 64);
        mVError = error;
        final AppCompatTextView empty = new AppCompatTextView(this);
        empty.setText(R.string.sl_change_state_empty);
        empty.setTextColor(0xff092d6d);
        empty.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 64);
        mVEmpty = empty;

        state.setOnCheckedChangeListener(this);
        state.check(R.id.sl_rb_normal);
        mode.setOnCheckedChangeListener(this);
        mode.check(R.id.sl_rb_drawable);

        mVState.setOnClickListener(this);
    }

    // Listener
    @Override
    public void onClick(View v) {
        if (v == mVState) {
            if (mVState.isNormal())
                Toast.makeText(getApplicationContext(), R.string.sl_change_state_normal,
                        Toast.LENGTH_SHORT).show();
            else if (mVState.isLoading())
                Toast.makeText(getApplicationContext(), R.string.sl_change_state_loading,
                        Toast.LENGTH_SHORT).show();
            else if (mVState.isEmpty())
                Toast.makeText(getApplicationContext(), R.string.sl_change_state_empty,
                        Toast.LENGTH_SHORT).show();
            else if (mVState.isError())
                Toast.makeText(getApplicationContext(), R.string.sl_change_state_error,
                        Toast.LENGTH_SHORT).show();
        }
    }

    @Override
    public void onCheckedChanged(RadioGroup group, int checkedId) {
        switch (checkedId) {
            case R.id.sl_rb_normal:
                mVState.normal();
                break;
            case R.id.sl_rb_loading:
                mVState.loading();
                break;
            case R.id.sl_rb_error:
                mVState.error();
                break;
            case R.id.sl_rb_empty:
                mVState.empty();
                break;
            case R.id.sl_rb_drawable:
                mVState.removeView(mVLoading);
                mVState.removeView(mVError);
                mVState.removeView(mVEmpty);
                mVState.setDrawable(mDLoading, mDError, mDEmpty);
                break;
            case R.id.sl_rb_view:
                mVState.setDrawable(null, null, null);
                if (mVEmpty.getParent() != null)
                    return;
                if (mVEmpty.getLayoutParams() != null)
                    mVState.addView(mVEmpty);
                else
                    mVState.addView(mVEmpty, new StateFrameLayout.LayoutParams(
                            ViewGroup.LayoutParams.WRAP_CONTENT,
                            ViewGroup.LayoutParams.WRAP_CONTENT,
                            Gravity.CENTER, StateFrameLayout.STATE_EMPTY));
                if (mVError.getLayoutParams() != null)
                    mVState.addView(mVError);
                else
                    mVState.addView(mVError, new StateFrameLayout.LayoutParams(
                            ViewGroup.LayoutParams.WRAP_CONTENT,
                            ViewGroup.LayoutParams.WRAP_CONTENT,
                            Gravity.CENTER, StateFrameLayout.STATE_ERROR));
                if (mVLoading.getLayoutParams() != null)
                    mVState.addView(mVLoading);
                else
                    mVState.addView(mVLoading, new StateFrameLayout.LayoutParams(
                            ViewGroup.LayoutParams.WRAP_CONTENT,
                            ViewGroup.LayoutParams.WRAP_CONTENT,
                            Gravity.CENTER, StateFrameLayout.STATE_LOADING));
                break;
        }
    }
} public class TagTabStripActivity extends AppCompatActivity {

    public TagTabStripActivity() {
        super(R.layout.activity_tagtabstrip);
    }

    public static void start(Context context) {
        context.startActivity(new Intent(context, TagTabStripActivity.class));
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setSupportActionBar(R.id.tts_toolbar);
        ((ViewPager) findViewById(R.id.tts_vp_pagers))
                .setAdapter(new ViewsPagerAdapter(getPagers()));
    }

    private ArrayList<View> getPagers() {
        ArrayList<View> views = new ArrayList<>();
        for (int i = 0; i < 5; i++) {
            TextView text = new TextView(this);
            text.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 180);
            text.setText(String.format(Locale.getDefault(), "%d", i + 1));
            text.setGravity(Gravity.CENTER);
            text.setTextColor(0xff000000);
            views.add(text);
        }
        return views;
    }
} public class WrapLayoutActivity extends AppCompatActivity implements RadioGroup.OnCheckedChangeListener,
        SeekBar.OnSeekBarChangeListener {

    private WrapLayout mVContent;

    public WrapLayoutActivity() {
        super(R.layout.activity_wraplayout);
    }

    public static void start(Context context) {
        context.startActivity(new Intent(context, WrapLayoutActivity.class));
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setSupportActionBar(R.id.wl_toolbar);
        mVContent = findViewById(R.id.wl_wl_content);
        final RadioGroup gravity = findViewById(R.id.wl_rg_gravity);
        final SeekBar horizontal = findViewById(R.id.wl_sb_horizontal);
        final SeekBar vertical = findViewById(R.id.wl_sb_vertical);

        gravity.setOnCheckedChangeListener(this);
        gravity.check(R.id.wl_rb_top);
        horizontal.setOnSeekBarChangeListener(this);
        horizontal.setProgress(15);
        vertical.setOnSeekBarChangeListener(this);
        vertical.setProgress(15);
    }

    // Listener
    @Override
    public void onCheckedChanged(RadioGroup group, int checkedId) {
        if (checkedId == R.id.wl_rb_top) {
            mVContent.setGravity(Gravity.TOP);
        } else if (checkedId == R.id.wl_rb_center) {
            mVContent.setGravity(Gravity.CENTER);
        } else if (checkedId == R.id.wl_rb_bottom) {
            mVContent.setGravity(Gravity.BOTTOM);
        }
    }

    @Override
    public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
        int id = seekBar.getId();
        if (id == R.id.wl_sb_horizontal) {
            mVContent.setHorizontalSpacing(
                    (int) (progress * getResources().getDisplayMetrics().density));
        } else if (id == R.id.wl_sb_vertical) {
            mVContent.setVerticalSpacing(
                    (int) (progress * getResources().getDisplayMetrics().density));
        }
    }

    @Override
    public void onStartTrackingTouch(SeekBar seekBar) {

    }

    @Override
    public void onStopTrackingTouch(SeekBar seekBar) {

    }
} public class ZxingScanViewActivity extends AppCompatActivity implements ZxingScanView.OnScanListener {

    private static final int PERMISSIONS_REQUEST_CAMERA = 108;
    private static final Collection<ResultMetadataType> DISPLAYABLE_METADATA_TYPES =
            EnumSet.of(ResultMetadataType.ISSUE_NUMBER,
                    ResultMetadataType.SUGGESTED_PRICE,
                    ResultMetadataType.ERROR_CORRECTION_LEVEL,
                    ResultMetadataType.POSSIBLE_COUNTRY);
    private ZxingScanView mVScan;
    private ZxingForegroundView mVForeground;

    public ZxingScanViewActivity() {
        super(R.layout.activity_zxingscanview);
    }

    public static void start(Context context) {
        context.startActivity(new Intent(context, ZxingScanViewActivity.class));
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setSupportActionBar(R.id.zsv_toolbar);
        mVScan = findViewById(R.id.zsv_zsv_scan);
        mVForeground = findViewById(R.id.zsv_zfv_foreground);
        mVScan.addOnScanListener(this);
    }

    // Listener
    @Override
    public void onError(ZxingScanView scanView) {
        switch (scanView.getErrorCode()) {
            case ZxingScanView.ERROR_CODE_0:
                // 相机无法打开
                Toast.makeText(this, R.string.zsv_error, Toast.LENGTH_SHORT).show();
                break;
            case ZxingScanView.ERROR_CODE_1:
                // 缺少打开相机的权限
                if (!ActivityCompat.shouldShowRequestPermissionRationale(this,
                        Manifest.permission.CAMERA)) {
                    ActivityCompat.requestPermissions(this,
                            new String[]{Manifest.permission.CAMERA},
                            PERMISSIONS_REQUEST_CAMERA);
                }
                break;
        }
    }

    @Override
    public void onResult(ZxingScanView scanView, Result result, Bitmap barcode,
                         float scaleFactor) {
        ParsedResult parsedResult = ResultParser.parseResult(result);
        final String format = "format:" + result.getBarcodeFormat().toString();
        final String type = "type:" + parsedResult.getType().toString();
        DateFormat formatter = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
        final String date = "date:" + formatter.format(new Date(result.getTimestamp()));
        String meta = "";
        Map<ResultMetadataType, Object> metadata = result.getResultMetadata();
        if (metadata != null) {
            StringBuilder metadataText = new StringBuilder(20);
            for (Map.Entry<ResultMetadataType, Object> entry : metadata.entrySet()) {
                if (DISPLAYABLE_METADATA_TYPES.contains(entry.getKey())) {
                    metadataText.append(entry.getValue()).append('\n');
                }
            }
            if (metadataText.length() > 0) {
                metadataText.setLength(metadataText.length() - 1);
                meta = metadataText.toString();
            }
        }
        CharSequence displayContents = parsedResult.getDisplayResult();
        Toast.makeText(this, format + "\n" + type + "\n" + date + "\n" + meta + "\n" + displayContents,
                Toast.LENGTH_SHORT).show();
        // 重新扫描
        scanView.restartScanDelay(3000);
    }

    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
                                           @NonNull int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        switch (requestCode) {
            case PERMISSIONS_REQUEST_CAMERA: {
                if (grantResults.length > 0
                        && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                    mVScan.open();
                } else {
                    mVForeground.setMode(ZxingForegroundView.MODE_ERROR);
                }
            }
        }
    }
}
import android.os.Bundle;
import android.view.View;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.am.appcompat.app.Fragment;
import am.project.x.R;
import am.project.x.business.widgets.circleprogressbar.CircleProgressBarActivity;
import am.project.x.business.widgets.drawableratingbar.DrawableRatingBarActivity;
import am.project.x.business.widgets.gradienttabstrip.GradientTabStripActivity;
import am.project.x.business.widgets.headerfootergridview.HeaderFooterGridViewActivity;
import am.project.x.business.widgets.indicatortabstrip.IndicatorTabStripActivity;
import am.project.x.business.widgets.multiactiontextview.MultiActionTextViewActivity;
import am.project.x.business.widgets.multifunctionalimageview.MultifunctionalImageViewActivity;
import am.project.x.business.widgets.multifunctionalrecyclerview.MultifunctionalRecyclerViewActivity;
import am.project.x.business.widgets.recyclepager.RecyclePagerActivity;
import am.project.x.business.widgets.smoothinputlayout.SmoothInputLayoutActivity;
import am.project.x.business.widgets.statelayout.StateLayoutActivity;
import am.project.x.business.widgets.tagtabstrip.TagTabStripActivity;
import am.project.x.business.widgets.wraplayout.WrapLayoutActivity;
import am.project.x.business.widgets.zxingscanview.ZxingScanViewActivity;
/*
 * Copyright (C) 2018 AlexMofer
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package am.project.x.business.main.fragments;





public class WidgetsFragment extends Fragment {

    public static WidgetsFragment newInstance() {
        return new WidgetsFragment();
    }

    public WidgetsFragment() {
        super(R.layout.fragment_main_widgets);
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        findViewById(R.id.widget_btn_gradienttabstrip).setOnClickListener(this::open);
        findViewById(R.id.widget_btn_tagtabstrip).setOnClickListener(this::open);
        findViewById(R.id.widget_btn_indicatortabstrip).setOnClickListener(this::open);
        findViewById(R.id.widget_btn_shapeimageview).setOnClickListener(this::open);
        findViewById(R.id.widget_btn_statelayout).setOnClickListener(this::open);
        findViewById(R.id.widget_btn_wraplayout).setOnClickListener(this::open);
        findViewById(R.id.widget_btn_drawableratingbar).setOnClickListener(this::open);
        findViewById(R.id.widget_btn_headerfootergridview).setOnClickListener(this::open);
        findViewById(R.id.widget_btn_multiactiontextview).setOnClickListener(this::open);
        findViewById(R.id.widget_btn_recyclepager).setOnClickListener(this::open);
        findViewById(R.id.widget_btn_circleprogressbar).setOnClickListener(this::open);
        findViewById(R.id.widget_btn_zxingscanview).setOnClickListener(this::open);
        findViewById(R.id.widget_btn_smoothinputlayout).setOnClickListener(this::open);
        findViewById(R.id.widget_btn_multifunctionalrecyclerview).setOnClickListener(this::open);
    }

    private void open(View v) {
        switch (v.getId()) {
            case R.id.widget_btn_gradienttabstrip:
                GradientTabStripActivity.start(requireContext());
                break;
            case R.id.widget_btn_tagtabstrip:
                TagTabStripActivity.start(requireContext());
                break;
            case R.id.widget_btn_indicatortabstrip:
                IndicatorTabStripActivity.start(requireContext());
                break;
            case R.id.widget_btn_shapeimageview:
                MultifunctionalImageViewActivity.start(requireContext());
                break;
            case R.id.widget_btn_statelayout:
                StateLayoutActivity.start(requireContext());
                break;
            case R.id.widget_btn_wraplayout:
                WrapLayoutActivity.start(requireContext());
                break;
            case R.id.widget_btn_drawableratingbar:
                DrawableRatingBarActivity.start(requireContext());
                break;
            case R.id.widget_btn_headerfootergridview:
                HeaderFooterGridViewActivity.start(requireContext());
                break;
            case R.id.widget_btn_multiactiontextview:
                MultiActionTextViewActivity.start(requireContext());
                break;
            case R.id.widget_btn_recyclepager:
                RecyclePagerActivity.start(requireContext());
                break;
            case R.id.widget_btn_circleprogressbar:
                CircleProgressBarActivity.start(requireContext());
                break;
            case R.id.widget_btn_zxingscanview:
                ZxingScanViewActivity.start(requireContext());