Search in sources :

Example 31 with SwitchCompat

use of android.support.v7.widget.SwitchCompat in project recyclerview-animators by wasabeef.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    findViewById(R.id.btn_animator_sample).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent i = new Intent(MainActivity.this, AnimatorSampleActivity.class);
            i.putExtra("GRID", enabledGrid);
            startActivity(i);
        }
    });
    findViewById(R.id.btn_adapter_sample).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent i = new Intent(MainActivity.this, AdapterSampleActivity.class);
            i.putExtra("GRID", enabledGrid);
            startActivity(i);
        }
    });
    ((SwitchCompat) findViewById(R.id.grid)).setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            enabledGrid = isChecked;
        }
    });
}
Also used : Intent(android.content.Intent) View(android.view.View) CompoundButton(android.widget.CompoundButton) SwitchCompat(android.support.v7.widget.SwitchCompat)

Example 32 with SwitchCompat

use of android.support.v7.widget.SwitchCompat in project LookLook by xinghongfei.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main_layout);
    ButterKnife.bind(this);
    setSupportActionBar(toolbar);
    IMainPresenter = new MainPresenterImpl(this, this);
    IMainPresenter.getBackground();
    toolbar.setOnMenuItemClickListener(onMenuItemClick);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        animateToolbar();
    }
    addfragmentsAndTitle();
    //        setStatusColor();
    drawer.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
    if (savedInstanceState == null) {
        nevigationId = SharePreferenceUtil.getNevigationItem(this);
        if (nevigationId != -1) {
            currentMenuItem = navView.getMenu().findItem(nevigationId);
        }
        if (currentMenuItem == null) {
            currentMenuItem = navView.getMenu().findItem(R.id.zhihuitem);
        }
        if (currentMenuItem != null) {
            currentMenuItem.setChecked(true);
            // TODO: 16/8/17 add a fragment and set toolbar title
            Fragment fragment = getFragmentById(currentMenuItem.getItemId());
            String title = mTitleArryMap.get((Integer) currentMenuItem.getItemId());
            if (fragment != null) {
                switchFragment(fragment, title);
            }
        }
    } else {
        if (currentMenuItem != null) {
            Fragment fragment = getFragmentById(currentMenuItem.getItemId());
            String title = mTitleArryMap.get((Integer) currentMenuItem.getItemId());
            if (fragment != null) {
                switchFragment(fragment, title);
            }
        } else {
            switchFragment(new ZhihuFragment(), " ");
            currentMenuItem = navView.getMenu().findItem(R.id.zhihuitem);
        }
    }
    navView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {

        @Override
        public boolean onNavigationItemSelected(MenuItem item) {
            if (currentMenuItem != item && currentMenuItem != null) {
                currentMenuItem.setChecked(false);
                int id = item.getItemId();
                SharePreferenceUtil.putNevigationItem(MainActivity.this, id);
                currentMenuItem = item;
                currentMenuItem.setChecked(true);
                switchFragment(getFragmentById(currentMenuItem.getItemId()), mTitleArryMap.get(currentMenuItem.getItemId()));
            }
            drawer.closeDrawer(GravityCompat.END, true);
            return true;
        }
    });
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        drawer.setOnApplyWindowInsetsListener(new View.OnApplyWindowInsetsListener() {

            @Override
            public WindowInsets onApplyWindowInsets(View v, WindowInsets insets) {
                // inset the toolbar down by the status bar height
                ViewGroup.MarginLayoutParams lpToolbar = (ViewGroup.MarginLayoutParams) toolbar.getLayoutParams();
                lpToolbar.topMargin += insets.getSystemWindowInsetTop();
                lpToolbar.rightMargin += insets.getSystemWindowInsetRight();
                toolbar.setLayoutParams(lpToolbar);
                // inset the grid top by statusbar+toolbar & the bottom by the navbar (don't clip)
                mFragmentContainer.setPadding(mFragmentContainer.getPaddingLeft(), insets.getSystemWindowInsetTop() + ViewUtils.getActionBarSize(MainActivity.this), // landscape
                mFragmentContainer.getPaddingRight() + insets.getSystemWindowInsetRight(), mFragmentContainer.getPaddingBottom() + insets.getSystemWindowInsetBottom());
                // we place a background behind the status bar to combine with it's semi-transparent
                // color to get the desired appearance.  Set it's height to the status bar height
                View statusBarBackground = findViewById(R.id.status_bar_background);
                FrameLayout.LayoutParams lpStatus = (FrameLayout.LayoutParams) statusBarBackground.getLayoutParams();
                lpStatus.height = insets.getSystemWindowInsetTop();
                statusBarBackground.setLayoutParams(lpStatus);
                // inset the filters list for the status bar / navbar
                // need to set the padding end for landscape case
                // clear this listener so insets aren't re-applied
                drawer.setOnApplyWindowInsetsListener(null);
                return insets.consumeSystemWindowInsets();
            }
        });
    }
    int[][] state = new int[][] { // unchecked
    new int[] { -android.R.attr.state_checked }, // pressed
    new int[] { android.R.attr.state_checked } };
    int[] color = new int[] { Color.BLACK, Color.BLACK };
    int[] iconcolor = new int[] { Color.GRAY, Color.BLACK };
    navView.setItemTextColor(new ColorStateList(state, color));
    navView.setItemIconTintList(new ColorStateList(state, iconcolor));
    //主题变色
    MenuItem item = navView.getMenu().findItem(R.id.nav_theme);
    mThemeSwitch = (SwitchCompat) MenuItemCompat.getActionView(item).findViewById(R.id.view_switch);
    mThemeSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            mThemeSwitch.setChecked(isChecked);
            if (isChecked) {
                setThemeColor(Color.GREEN);
            } else {
                setThemeColor(getResources().getColor(R.color.colorPrimaryDark));
            }
        }
    });
}
Also used : NavigationView(android.support.design.widget.NavigationView) ViewGroup(android.view.ViewGroup) ColorStateList(android.content.res.ColorStateList) MenuItem(android.view.MenuItem) MainPresenterImpl(com.looklook.xinghongfei.looklook.presenter.implPresenter.MainPresenterImpl) MeiziFragment(com.looklook.xinghongfei.looklook.fragment.MeiziFragment) ZhihuFragment(com.looklook.xinghongfei.looklook.fragment.ZhihuFragment) TopNewsFragment(com.looklook.xinghongfei.looklook.fragment.TopNewsFragment) Fragment(android.support.v4.app.Fragment) NavigationView(android.support.design.widget.NavigationView) BindView(butterknife.BindView) View(android.view.View) ActionMenuView(android.support.v7.widget.ActionMenuView) TextView(android.widget.TextView) WindowInsets(android.view.WindowInsets) FrameLayout(android.widget.FrameLayout) ZhihuFragment(com.looklook.xinghongfei.looklook.fragment.ZhihuFragment) CompoundButton(android.widget.CompoundButton)

Example 33 with SwitchCompat

use of android.support.v7.widget.SwitchCompat in project Notes by Elder-Wu.

the class IosBottomDialogFragment method onCreateView.

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    final View rootView = inflater.inflate(R.layout.fragment_bottom_dialog, container, false);
    rootView.findViewById(R.id.fragment_ios_bottom_dialog_btn1).setOnClickListener(this);
    rootView.findViewById(R.id.fragment_ios_bottom_dialog_btn2).setOnClickListener(this);
    rootView.findViewById(R.id.fragment_ios_bottom_dialog_btn3).setOnClickListener(this);
    rootView.findViewById(R.id.fragment_ios_bottom_dialog_btn4).setOnClickListener(this);
    rootView.findViewById(R.id.fragment_ios_bottom_dialog_btn5).setOnClickListener(this);
    rootView.findViewById(R.id.fragment_ios_bottom_dialog_btn6).setOnClickListener(this);
    String str1 = "Hello Shanbay";
    String str2 = ";a sh  *if iao;h";
    String str3 = "Hahahah ** he hei xi xiixi";
    String str4 = "**as;higoan* e;v**se;viauhfid*";
    handle(str1);
    handle(str2);
    handle(str3);
    handle(str4);
    Observable.timer(5, TimeUnit.SECONDS).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Action1<Long>() {

        @Override
        public void call(Long aLong) {
            TextView textView = (TextView) rootView.findViewById(R.id.xxxx);
            textView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
            AppUtils.showToast("成功了");
        }
    });
    final ProgressChartView chartView = (ProgressChartView) rootView.findViewById(R.id.chart);
    ArrayList<ProgressChartView.Data> mRawDataList = new ArrayList<>();
    mRawDataList.add(new ProgressChartView.Data("Mar 01", 3111));
    //		mRawDataList.add(new Data("Mar 02", 0));
    //		mRawDataList.add(new Data("Mar 03", 0));
    //		mRawDataList.add(new Data("Mar 04", 0));
    //		mRawDataList.add(new Data("Mar 05", 0));
    //		mRawDataList.add(new Data("Mar 06", 0));
    //		mRawDataList.add(new Data("Mar 07", 0));
    mRawDataList.add(new ProgressChartView.Data("Mar 02", 3115));
    mRawDataList.add(new ProgressChartView.Data("Mar 03", 3278));
    mRawDataList.add(new ProgressChartView.Data("Mar 04", 3376));
    mRawDataList.add(new ProgressChartView.Data("Mar 05", 3489));
    mRawDataList.add(new ProgressChartView.Data("Mar 06", 3789));
    mRawDataList.add(new ProgressChartView.Data("Mar 07", 3788));
    chartView.setData(mRawDataList);
    chartView.setColor(Color.RED);
    SwitchCompat switchCompat = (SwitchCompat) rootView.findViewById(R.id.switch_btn);
    switchCompat.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked) {
                chartView.showAllHintView();
            } else {
                chartView.removeAllHintView();
            }
        }
    });
    return rootView;
}
Also used : ArrayList(java.util.ArrayList) TextView(android.widget.TextView) ProgressChartView(com.wuzhanglao.niubi.widget.ProgressChartView) View(android.view.View) ProgressChartView(com.wuzhanglao.niubi.widget.ProgressChartView) TextView(android.widget.TextView) CompoundButton(android.widget.CompoundButton) SwitchCompat(android.support.v7.widget.SwitchCompat) Nullable(android.support.annotation.Nullable)

Aggregations

SwitchCompat (android.support.v7.widget.SwitchCompat)29 TextView (android.widget.TextView)20 View (android.view.View)19 CompoundButton (android.widget.CompoundButton)19 Intent (android.content.Intent)7 ImageView (android.widget.ImageView)7 AlertDialog (android.support.v7.app.AlertDialog)6 ScrollView (android.widget.ScrollView)6 DialogInterface (android.content.DialogInterface)5 SearchView (android.support.v7.widget.SearchView)4 MenuItem (android.view.MenuItem)4 CheckerBoardDrawable (com.facebook.fresco.samples.showcase.misc.CheckerBoardDrawable)4 CardView (android.support.v7.widget.CardView)3 LayoutInflater (android.view.LayoutInflater)3 ViewGroup (android.view.ViewGroup)3 AdapterView (android.widget.AdapterView)3 LinearLayout (android.widget.LinearLayout)3 Spinner (android.widget.Spinner)3 ArrayList (java.util.ArrayList)3 ClipData (android.content.ClipData)2