Android Open Source - misound Mi Switch






From Project

Back to project page misound.

License

The source code is released under:

Apache License

If you think the Android project misound listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.xiaomi.mitv.widget;
//  ww w  . j a v a  2s . c o  m
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import com.xiaomi.mitv.soundbarapp.R;
import com.xiaomi.mitv.utils.Log;

/**
 * Created by chenxuetong on 8/26/14.
 */
public class MiSwitch extends RelativeLayout {
    private static final String TAG = "MiSwitch";
    private ImageView mLeft;
    private ImageView mRight;
    private boolean mChecked= false;
    private OnCheckChangedListener mCheckListener;

    public interface OnCheckChangedListener{
        public void onChanged(boolean checked);
    }

    public MiSwitch(Context context) {
        this(context, null);
    }

    public MiSwitch(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public MiSwitch(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    @Override
    protected void onFinishInflate() {
        super.onFinishInflate();
        View layout = View.inflate(getContext(), R.layout.settings_switcher_view, null);
        mLeft = (ImageView)layout.findViewById(R.id.left);
        mRight = (ImageView)layout.findViewById(R.id.right);
        addView(layout);

        setOnClickListener(mListener);
        updateView();
    }

    public void setOnCheckChangedListener(OnCheckChangedListener l){
        mCheckListener = l;
    }

    public void setChecked(boolean checked){
        mChecked = checked;
        updateView();
    }

    public boolean isChecked(){
        return mChecked;
    }

    private OnClickListener mListener = new OnClickListener() {
        @Override
        public void onClick(View v) {
            Log.logD(TAG, "before onClick() on: " + v);
            boolean checked = mChecked;
            mChecked = !mChecked;
            if(checked != mChecked){
                updateView();
                if(mCheckListener!=null) mCheckListener.onChanged(mChecked);
            }
            Log.logD(TAG, "after onClick() checked: " + mChecked);
        }
    };

    private void updateView(){
        if(mChecked){
            mLeft.setVisibility(GONE);
            mRight.setVisibility(VISIBLE);
        }else{
            mLeft.setVisibility(VISIBLE);
            mRight.setVisibility(GONE);
        }
    }
}




Java Source Code List

com.xiaomi.mitv.soundbar.DefaultMisoundDevice.java
com.xiaomi.mitv.soundbarapp.BarInfoUtils.java
com.xiaomi.mitv.soundbarapp.ConnectingActivity.java
com.xiaomi.mitv.soundbarapp.MainActivity2.java
com.xiaomi.mitv.soundbarapp.SoundBarApplication.java
com.xiaomi.mitv.soundbarapp.TestActivity.java
com.xiaomi.mitv.soundbarapp.TypefaceManager.java
com.xiaomi.mitv.soundbarapp.WrapperActivity.java
com.xiaomi.mitv.soundbarapp.diagnosis.DiagnosisFragment.java
com.xiaomi.mitv.soundbarapp.diagnosis.Engine.java
com.xiaomi.mitv.soundbarapp.diagnosis.ViewWrapper.java
com.xiaomi.mitv.soundbarapp.diagnosis.data.Entry.java
com.xiaomi.mitv.soundbarapp.diagnosis.data.Node.java
com.xiaomi.mitv.soundbarapp.diagnosis.data.OrderedList.java
com.xiaomi.mitv.soundbarapp.diagnosis.data.QAElement.java
com.xiaomi.mitv.soundbarapp.eq.EQManager.java
com.xiaomi.mitv.soundbarapp.eq.EQSettingsFragment.java
com.xiaomi.mitv.soundbarapp.eq.EQStyleResource.java
com.xiaomi.mitv.soundbarapp.eq.EQStyle.java
com.xiaomi.mitv.soundbarapp.eq.UserEQControlFragment.java
com.xiaomi.mitv.soundbarapp.faq.FaqDataStore.java
com.xiaomi.mitv.soundbarapp.faq.FaqFragment.java
com.xiaomi.mitv.soundbarapp.fragment.A2dpDlg.java
com.xiaomi.mitv.soundbarapp.fragment.BaseFragment.java
com.xiaomi.mitv.soundbarapp.fragment.FeedbackFragment.java
com.xiaomi.mitv.soundbarapp.fragment.MainEntryFragment.java
com.xiaomi.mitv.soundbarapp.fragment.PanelFragment.java
com.xiaomi.mitv.soundbarapp.fragment.SettingsFragment.java
com.xiaomi.mitv.soundbarapp.player.MediaButtonIntentReceiver.java
com.xiaomi.mitv.soundbarapp.player.MusicUtils.java
com.xiaomi.mitv.soundbarapp.player.PlayListFragment.java
com.xiaomi.mitv.soundbarapp.player.PlayerFragment.java
com.xiaomi.mitv.soundbarapp.player.PlayerService.java
com.xiaomi.mitv.soundbarapp.player.Player.java
com.xiaomi.mitv.soundbarapp.provider.DataProvider.java
com.xiaomi.mitv.soundbarapp.upgrade.FirmwareManager.java
com.xiaomi.mitv.soundbarapp.upgrade.FirmwareZipFile.java
com.xiaomi.mitv.soundbarapp.upgrade.UpdateActivity.java
com.xiaomi.mitv.soundbarapp.upgrade.UpgradeFragment.java
com.xiaomi.mitv.soundbarapp.upgrade.VersionSelectFragment.java
com.xiaomi.mitv.soundbarapp.util.ConfirmActivityDlg.java
com.xiaomi.mitv.soundbarapp.util.Worker.java
com.xiaomi.mitv.widget.GainView.java
com.xiaomi.mitv.widget.GifView.java
com.xiaomi.mitv.widget.LetterIndexSilderBar.java
com.xiaomi.mitv.widget.MiSwitch.java
com.xiaomi.mitv.widget.RoundAnimationView.java
com.xiaomi.mitv.widget.RoundProgressBar.java
com.xiaomi.mitv.widget.RoundSeekBar.java