TaskShipItemView.java 2.62 KB
package com.huaheng.mobilewms.view;

import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.widget.LinearLayout;

import com.huaheng.mobilewms.util.WMSUtils;

import java.util.ArrayList;
import java.util.List;

public class TaskShipItemView extends LinearLayout {

    private int index = 0;
    private boolean itemSelected = false;
    private int colorNormal;
    private int colorSelected1 = Color.rgb(163+10,214+10,231+10);
    private int colorSelected2 = Color.rgb(163+10,214+10,231+10);
    private int colorLine = Color.rgb(0, 0, 0);
    public TaskShipItemView(Context context, int index){
        super(context);
        this.setOrientation(VERTICAL);
        this.index = index;
        if(index %2 == 0) {
            colorNormal = Color.rgb(255,255,255);
        }else{
            colorNormal = Color.rgb(255,255,255);
        }
        this.setBackgroundColor(colorNormal);
        LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
//        lp.setMargins(0, 10, 0, 10);
//        this.setPadding(0, 10, 0, 10);
        this.setLayoutParams(lp);
        View line = new View(context);
        LayoutParams llp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 12);
        line.setLayoutParams(llp);
        line.setBackgroundColor(colorLine);
        this.addView(line);
        this.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View v) {
                selectSwitch();
            }
        });
    }


    public void newLine(String label, String info){
        if(WMSUtils.isEmpty(info)){
            return;
        }
        TaskShipItem item = new TaskShipItem(this.getContext(), label, info);
        item.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
        this.addView(item);
    }

    @Override
    public void addView(View view){
        view.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
        super.addView(view);
    }

    public void selectSwitch(){
        select(!this.itemSelected);
    }

    public void select(boolean isSelect){
        this.itemSelected = isSelect;
        if(itemSelected){
            if(index % 2 == 0) {
                this.setBackgroundColor(this.colorSelected1);
            }else{
                this.setBackgroundColor(this.colorSelected2);
            }
        }else{
            this.setBackgroundColor(this.colorNormal);
        }
    }

    public boolean isItemSelected(){
        return this.itemSelected;
    }
}