CommonActivity.java 1.74 KB
package com.lijinji.scan.util;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.lijinji.scan.R;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by youjie on 2018/6/14.
 */

public class CommonActivity extends Activity {

    @BindView(R.id.backImage)
    ImageView backImage;
    @BindView(R.id.commonTitle)
    TextView commonTitle;
    private ViewGroup viewGroup;
    private Context mContext;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        super.setContentView(R.layout.activity_common);
        mContext = this;
        viewGroup = (ViewGroup) this.findViewById(R.id.basePageContainer);
        initActivityOnCreate(savedInstanceState);
    }

    /**
     * 页面初始化
     */
    protected void initActivityOnCreate(Bundle savedInstanceState) {

    }

    @Override
    public void setContentView(int layoutResID) {
        LayoutInflater.from(this).inflate(layoutResID, viewGroup, true);
    }

    public void setBackImageVisible(int visible) {
        if (backImage != null) {
            backImage.setVisibility(visible);
        }
    }

    public void setTitle(String message) {
        if (commonTitle != null) {
            commonTitle.setText(message);
        }
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        return super.onKeyDown(keyCode, event);
    }

    @OnClick(R.id.backImage)
    public void onClick() {
        onBackPressed();
    }
}