码迷,mamicode.com
首页 > 其他好文 > 详细

人品计算器

时间:2019-01-06 18:12:32      阅读:258      评论:0      收藏:0      [点我收藏+]

标签:over   textutils   alc   src   result   oncreate   cas   toast   hashmap   

人品计算器

  • 功能:计算人品 
  • 代码实现过程: 
    • 实现UI 

技术分享图片

 

 

    • mainActivity代码如下:
public class MainActivity extends AppCompatActivity {
    private static final String TAG = "MainActivity";
    @BindView(R.id.et)
    EditText mEt;
    @BindView(R.id.calculate)
    Button mCalculate;
    @BindView(R.id.clear)
    Button mClear;
    @BindView(R.id.name)
    TextView mName;
    @BindView(R.id.score)
    TextView mScore;
    @BindView(R.id.evaluate)
    TextView mEvaluate;

    private String mPinyin = "";
    private HashMap<String, String> mMap;
    private int mScore1;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);
        init();
    }

    private void init() {
        AdManager.getInstance(this).init("ff8e2077f8854ed7", "9654791c307bf9da", false);
        mMap = new HashMap<>();
        mMap.put("梁铁柱", "100");
        mMap.put("成青青", "100");
        mMap.put("鬼龟", "100");
        mMap.put("cordy", "100");
        mMap.put("jx2cordy", "100");
        mMap.put("2 306205002", "100");
        mMap.put("日本人", "-1");
        mMap.put("小日本", "-1");
        mMap.put("日本", "-1");
        mMap.put("日本鬼子", "-1");
        View bannerView = BannerManager.getInstance(this).getBannerView(this, mBannerViewListener);
        // 获取要嵌入广告条的布局
        LinearLayout bannerLayout = (LinearLayout) findViewById(R.id.ll_banner);
        // 将广告条加入到布局中
        bannerLayout.addView(bannerView);
    }

    private BannerViewListener mBannerViewListener = new BannerViewListener() {
        @Override
        public void onRequestSuccess() {

        }

        @Override
        public void onSwitchBanner() {

        }

        @Override
        public void onRequestFailed() {

        }
    };

    @OnClick({R.id.calculate, R.id.clear})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.calculate:
                calculate();
                break;
            case R.id.clear:
                //点击清空按钮,清空输入的姓名
                mEt.setText("");
                mPinyin = "";
                break;
        }
    }

    private void calculate() {
        //获取用户的姓名
        String name = mEt.getText().toString().trim();
        //判断的输入的姓名是否为空
        if (TextUtils.isEmpty(name)) {
            Toast.makeText(this, "姓名不能为空", Toast.LENGTH_SHORT).show();
        } else {
            String value = Score.checkMap(name, mMap);
            if (value != null) {
                mScore1 = Integer.parseInt(value);
            } else {
                mScore1 = Score.getResult(name);
            }
            String evaluate = Score.getValue(mScore1);
            mName.setText(name);
            mScore.setText(((mScore1 >= 0 && mScore1 <= 100) ? mScore1 + "" : "负溢出"));
            mEvaluate.setText(evaluate);
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        OffersManager.getInstance(this).onAppExit();
    }
}

 

    • 结果页面代码如下:
public class MainActivity extends AppCompatActivity {
    private static final String TAG = "MainActivity";
    @BindView(R.id.et)
    EditText mEt;
    @BindView(R.id.calculate)
    Button mCalculate;
    @BindView(R.id.clear)
    Button mClear;
    @BindView(R.id.name)
    TextView mName;
    @BindView(R.id.score)
    TextView mScore;
    @BindView(R.id.evaluate)
    TextView mEvaluate;

    private String mPinyin = "";
    private HashMap<String, String> mMap;
    private int mScore1;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);
        init();
    }

    private void init() {
        AdManager.getInstance(this).init("ff8e2077f8854ed7", "9654791c307bf9da", false);
        mMap = new HashMap<>();
        mMap.put("梁铁柱", "100");
        mMap.put("成青青", "100");
        mMap.put("鬼龟", "100");
        mMap.put("cordy", "100");
        mMap.put("jx2cordy", "100");
        mMap.put("2 306205002", "100");
        mMap.put("日本人", "-1");
        mMap.put("小日本", "-1");
        mMap.put("日本", "-1");
        mMap.put("日本鬼子", "-1");
        View bannerView = BannerManager.getInstance(this).getBannerView(this, mBannerViewListener);
        // 获取要嵌入广告条的布局
        LinearLayout bannerLayout = (LinearLayout) findViewById(R.id.ll_banner);
        // 将广告条加入到布局中
        bannerLayout.addView(bannerView);
    }

    private BannerViewListener mBannerViewListener = new BannerViewListener() {
        @Override
        public void onRequestSuccess() {

        }

        @Override
        public void onSwitchBanner() {

        }

        @Override
        public void onRequestFailed() {

        }
    };

    @OnClick({R.id.calculate, R.id.clear})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.calculate:
                calculate();
                break;
            case R.id.clear:
                //点击清空按钮,清空输入的姓名
                mEt.setText("");
                mPinyin = "";
                break;
        }
    }

    private void calculate() {
        //获取用户的姓名
        String name = mEt.getText().toString().trim();
        //判断的输入的姓名是否为空
        if (TextUtils.isEmpty(name)) {
            Toast.makeText(this, "姓名不能为空", Toast.LENGTH_SHORT).show();
        } else {
            String value = Score.checkMap(name, mMap);
            if (value != null) {
                mScore1 = Integer.parseInt(value);
            } else {
                mScore1 = Score.getResult(name);
            }
            String evaluate = Score.getValue(mScore1);
            mName.setText(name);
            mScore.setText(((mScore1 >= 0 && mScore1 <= 100) ? mScore1 + "" : "负溢出"));
            mEvaluate.setText(evaluate);
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        OffersManager.getInstance(this).onAppExit();
    }
}

 

人品计算器

标签:over   textutils   alc   src   result   oncreate   cas   toast   hashmap   

原文地址:https://www.cnblogs.com/nangongyibin/p/10229192.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!