Android Open Source - android-mimic-ui U I Switch Item






From Project

Back to project page android-mimic-ui.

License

The source code is released under:

Apache License

If you think the Android project android-mimic-ui 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.mimic.ui.tableview.support;
//from w  w w  . ja v  a2 s  .  c  om
import android.content.Context;
import android.view.View;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.Switch;
import android.widget.TextView;

import com.mimic.ui.R;
import com.mimic.ui.tableview.UITableViewItem;

public class UISwitchItem extends UITableViewItem {
  
  private Switch mSwitchView = null;
  
  public UISwitchItem(Context context, String label) {
    super(context, label); // style : STYLE_DEFAULT
    setupSwitchViews();
    setLabel(label);
    setSubtitle(null);
    setClickable(false);
  }
  
  public UISwitchItem(Context context, String label, String subtitle) {
    super(context, label, subtitle, STYLE_SUBTITLE, ACCESSORY_NONE);
    setupSwitchViews();
    setLabel(label);
    setClickable(false);
  }
  
  void setupSwitchViews() {
    mSwitchView = (Switch) getInflater().inflate(
        R.layout.accessory_switch_button, null);
    getAccessoryView().removeAllViews();
    getAccessoryView().addView(mSwitchView);
  }
  
  public TextView getLabelView() {
    return getTextView();
  }
  
  public void setLabel(String label) {
    if (label != null) {
      setText(label);
      getTextView().setVisibility(View.VISIBLE);
    } else {
      getTextView().setVisibility(View.GONE);
    }
  }

  public void setLabelColor(int color) {
    if (color > -1) {
      getTextView().setTextColor(color);
    }
  }
  
  public void showLabel() {
    getTextView().setVisibility(View.VISIBLE);
  }
  
  public void hideLabel() {
    getTextView().setVisibility(View.GONE);
  }

  public TextView getSubtitleView() {
    return getDetailTextView();
  }
  
  public void setSubtitle(String subtitle) {
    if (getDetailTextView() != null) {
      if (subtitle != null) {
        setDetailText(subtitle);
        getDetailTextView().setVisibility(View.VISIBLE);
      } else {
        getDetailTextView().setVisibility(View.GONE);
      }
    }
  }

  public Switch getSwitchView() {
    return mSwitchView;
  }
  
  public boolean getState() {
    return mSwitchView.isChecked();
  }
  
  public void setState(boolean state) {
    mSwitchView.setChecked(true);
  }
  
  public interface OnSwitchChangeListener {
    public void onCheckedChanged(UISwitchItem switchItem, boolean isChecked);
  }
  
  public void setOnSwitchChangeListener(final OnSwitchChangeListener listener) {
    mSwitchView.setOnCheckedChangeListener(new OnCheckedChangeListener() {      
      @Override
      public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
        listener.onCheckedChanged(UISwitchItem.this, isChecked);
      }
    });
  }
  
  @Override
  public boolean isClickable() {
    return false;
  }
}




Java Source Code List

com.mimic.ui.tableview.IListItem.java
com.mimic.ui.tableview.UITableViewActivity.java
com.mimic.ui.tableview.UITableViewItem.java
com.mimic.ui.tableview.UITableViewSection.java
com.mimic.ui.tableview.UITableView.java
com.mimic.ui.tableview.support.UIButtonItem.java
com.mimic.ui.tableview.support.UIMultiChoiceListSection.java
com.mimic.ui.tableview.support.UIProgressItem.java
com.mimic.ui.tableview.support.UISingleChoiceListSection.java
com.mimic.ui.tableview.support.UISliderItem.java
com.mimic.ui.tableview.support.UISwitchItem.java
com.mimic.ui.tableview.support.UITextInputItem.java
com.mimic.ui.tableview.support.UIVolumeControlItem.java