Newer
Older
GasOperationApp / app / src / main / java / com / casic / gasoperation / view / ButtomBar.java
[wangxitong] on 24 May 2021 5 KB first commit
package com.casic.gasoperation.view;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.util.AttributeSet;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.casic.gasoperation.CurrentJobActivity;
import com.casic.gasoperation.HistoryJobActivity;
import com.casic.gasoperation.R;
import com.casic.gasoperation.UserInfoActivity;
import com.casic.gasoperation.utils.ApplicationMain;
public class ButtomBar extends LinearLayout {

    private View current_job;
    private View history_job;
    private TextView label1,label2,label3;
    private ImageView pic1,pic2,pic3;
    private View me;
    public static int status = 1;

    private OnClickListener rightBtnListener;

    private OnClickListener linstener = new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            if (arg0 == current_job) {
                if(status !=1)
                {
                    status = 1;
                    Activity activity = (Activity) ButtomBar.this.getContext();
                    Intent intent = new Intent(ButtomBar.this.getContext(), CurrentJobActivity.class);
                    ButtomBar.this.getContext().startActivity(intent);
                    activity.finish();
                }
            } else if (arg0 == history_job) {
                if(status != 2)
                {
                    status = 2;
                    Activity activity = (Activity) ButtomBar.this.getContext();
                    Intent intent = new Intent(ButtomBar.this.getContext(), HistoryJobActivity.class);
                    ButtomBar.this.getContext().startActivity(intent);
                    activity.finish();
                }
            }else if (arg0 == me) {
                if(status != 3)
                {
                    status = 3;
                    Activity activity = (Activity) ButtomBar.this.getContext();
                    Intent intent = new Intent(ButtomBar.this.getContext(), UserInfoActivity.class);
                    ButtomBar.this.getContext().startActivity(intent);
                    activity.finish();
                }
            }
        }
    };
    public void setRightBtnListener(OnClickListener rightBtnListener) {
        this.rightBtnListener = rightBtnListener;
        history_job.setOnClickListener(this.rightBtnListener);
    }

    public OnClickListener getRightBtnListener() {
        return rightBtnListener;
    }

    public ButtomBar(Context context) {
        super(context);
    }

    public ButtomBar(Context context,  AttributeSet attrs) {
        super(context, attrs);
        LayoutInflater.from(context).inflate(R.layout.buttombar, this);
        current_job = findViewById(R.id.current_job);
        history_job = findViewById(R.id.history_job);
        me = findViewById(R.id.me);
        pic1 = (ImageView) findViewById(R.id.pic1);
        pic2 = (ImageView) findViewById(R.id.pic2);
        pic3 = (ImageView) findViewById(R.id.pic3);

        label1 = (TextView) findViewById(R.id.label1);
        label2 = (TextView) findViewById(R.id.label2);
        label3 = (TextView) findViewById(R.id.label3);
        Activity activity = (Activity) ButtomBar.this.getContext();
        if(status == 1)
        {
            label1.setTextColor(Color.parseColor("#0D64AB"));
            label2.setTextColor(getResources().getColor(R.color.gray));
            label3.setTextColor(getResources().getColor(R.color.gray));
            pic1.setImageDrawable(getResources().getDrawable(R.drawable.cur1));
            pic2.setImageDrawable(getResources().getDrawable(R.drawable.his));
            pic3.setImageDrawable(getResources().getDrawable(R.drawable.me));
        }
        else if(status == 2) {
            label2.setTextColor(Color.parseColor("#0D64AB"));
            label1.setTextColor(getResources().getColor(R.color.gray));
            label3.setTextColor(getResources().getColor(R.color.gray));
            pic1.setImageDrawable(getResources().getDrawable(R.drawable.cur));
            pic2.setImageDrawable(getResources().getDrawable(R.drawable.his1));
            pic3.setImageDrawable(getResources().getDrawable(R.drawable.me));
        }
        else if(status == 3) {
            label3.setTextColor(Color.parseColor("#0D64AB"));
            label1.setTextColor(getResources().getColor(R.color.gray));
            label2.setTextColor(getResources().getColor(R.color.gray));
            pic1.setImageDrawable(getResources().getDrawable(R.drawable.cur));
            pic2.setImageDrawable(getResources().getDrawable(R.drawable.his));
            pic3.setImageDrawable(getResources().getDrawable(R.drawable.me1));
        }
        current_job.setOnClickListener(linstener);
        history_job.setOnClickListener(linstener);
        me.setOnClickListener(linstener);
    }
    public ButtomBar(Context context,  AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }
}