NetworkSettingActivity.java 1.84 KB
package com.huaheng.mes;

import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.huaheng.mes.activity.model.CommonActivity;
import com.huaheng.mes.bean.Constant;
import com.huaheng.mes.https.HttpConstant;
import com.huaheng.mes.util.MESUtils;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by youjie on 2018/9/19
 */
public class NetworkSettingActivity extends CommonActivity {


    @BindView(R.id.networkEdit)
    EditText networkEdit;
    @BindView(R.id.myNetwork)
    TextView myNetwork;

    @Override
    protected void initActivityOnCreate(Bundle savedInstanceState) {
        super.initActivityOnCreate(savedInstanceState);
        setContentView(R.layout.activity_network_setting);
        ButterKnife.bind(this);
        setTitle(getString(R.string.configure_network));
        freshText();
    }

    @OnClick({R.id.resetDefaultBtn, R.id.setBtn})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.resetDefaultBtn:
                networkEdit.setText(HttpConstant.URL);
                break;
            case R.id.setBtn:
                setNetwork();
                break;
        }
    }

    private void freshText() {
        String network = MESUtils.getData(Constant.NETWORK);
        network = this.getString(R.string.local ) + network;
        myNetwork.setText(network);
    }

    private void setNetwork() {
        String network = networkEdit.getText().toString();
        if (network != null && network.length() > 0) {
            MESUtils.saveData(Constant.NETWORK, network);
            MESUtils.showShort(getString(R.string.setting_success));
            freshText();
        } else {
            MESUtils.showShort(getString(R.string.enter_error_network));
        }
    }

}