SettingsActivity.java 35.2 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810
package com.ectrip.cyt.ui;

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

import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.app.Dialog;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.res.Resources;
import android.net.ConnectivityManager;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.os.IBinder;
import android.text.InputType;
import android.text.TextUtils;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.WindowManager;
import android.view.animation.AnticipateOvershootInterpolator;
import android.view.inputmethod.InputMethodManager;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.RelativeLayout;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;

import antistatic.spinnerwheel.AbstractWheel;

import com.ectrip.cyt.bean.ConfigBean;
import com.ectrip.cyt.config.DevicTool;
import com.ectrip.cyt.config.MyApp;
import com.ectrip.cyt.constant.constant;
import com.ectrip.cyt.db.DbManager;
import com.ectrip.cyt.shield_home.LockLayer.MToast;
import com.ectrip.cyt.spinnerwheel.adapters.NumericWheelAdapter;
import com.ectrip.cyt.utils.AESEncryptor;
import com.ectrip.cyt.utils.CommetryUtils;
import com.ectrip.cyt.utils.LogUtil;
import com.ectrip.cyt.utils.SharedPreferences2Obj;
import com.ectrip.cyt.version.UpdateManager;
import com.ectrip.trips.check.R;

/**
 * 设置Activity
 */
public class SettingsActivity extends BaseActivity implements OnClickListener,
        OnCheckedChangeListener {
    //返回相应码
    private final int SETTING_REQUESTCODE = 1;
    // 机器码,服务地址,系统密码,企业标识,企业编码
    private EditText machineCodeEdit, serviceIpEdit, systemPwdEdit,
            identityEdit, encodeEdit;
    // 打印选项组,调试选项组,打印加密选项组
    private RelativeLayout printGroup, reprintEncryptGroup;
    private RadioGroup testGroup;
    // 调试开关选项,是否打印选项,是否加密打印
    private RadioButton testNoRadioBtn, testYesRadioBtn;
    // 确认按钮
    private Button confirmBtn, updateBtn;
    private View testlayout;
    // 是否调试模式,密码弹框
    private Dialog testDialog, pwdDialog;
    // 打印次数,标题,版本,
    private TextView printNumText, titleText, versionText;

    private String mode;
    private int isprint = 0;
    private NetworkConnectChangedReceiver receiver = null;
    // 打印次数
    private Integer pnum = null;
    // 调试模式
    private Boolean testMOdel;
    // 是否加密
    private Boolean isEncrypt;
    //退出应用次数
    private long firstTime = 0;
    private int num = 0;
    private RelativeLayout scanGroup;
    private ImageView isreprint, scanEncrypt, reprntEncrypt;
    private Boolean scanBack;
    private LinearLayout lv_printNum;
    private ArrayList<ConfigBean> beans;
    private Spinner select_dev;
    private List<String> devlist = new ArrayList<String>();
    private ArrayAdapter<String> adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.app_settings);
        init();
        initConfig();
        initView();
        initListen();
        initData();
        initRegist();
    }

    private void init() {
        pnum = SharedPreferences2Obj.getInstance(SettingsActivity.this)
                .setName("MachineType").getObject("printNum", Integer.class);

        if (pnum == null) {
            SharedPreferences2Obj.getInstance(SettingsActivity.this)
                    .setName("MachineType").setObject("printNum", 2);
        } else {
            if (pnum > 3) {
                pnum = 3;
            }
        }

        testMOdel = SharedPreferences2Obj.getInstance(SettingsActivity.this)
                .setName("config").getObject("testMOdel", Boolean.class);
        isEncrypt = SharedPreferences2Obj.getInstance(SettingsActivity.this)
                .setName("config").getObject("isEncrypt", Boolean.class);
    }

    private void initRegist() {
        if (receiver == null) {
            receiver = new NetworkConnectChangedReceiver();
        }
        IntentFilter filter = new IntentFilter();
        filter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION);
        filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
        registerReceiver(receiver, filter);
    }

    private void initView() {
        lv_printNum = (LinearLayout) findViewById(R.id.lv_printNum);
        printNumText = (TextView) findViewById(R.id.printNum);
        machineCodeEdit = (EditText) findViewById(R.id.machineCodeEdit);
        systemPwdEdit = (EditText) findViewById(R.id.systemPwdEdit);
        serviceIpEdit = (EditText) findViewById(R.id.serviceIpEdit);
        identityEdit = (EditText) findViewById(R.id.identityEdit);
        encodeEdit = (EditText) findViewById(R.id.encodeEdit);
        printGroup = (RelativeLayout) this.findViewById(R.id.printGroup);
        testGroup = (RadioGroup) findViewById(R.id.testGroup);
        scanGroup = (RelativeLayout) findViewById(R.id.scanEncryptGroup);
        reprintEncryptGroup = (RelativeLayout) findViewById(R.id.reprintEncryptGroup);
        testlayout = findViewById(R.id.testlayout);// 调节模式
        versionText = (TextView) findViewById(R.id.version);
        confirmBtn = (Button) findViewById(R.id.set_saveBtn);//确认按钮
        updateBtn = (Button) findViewById(R.id.update);
        titleText = (TextView) findViewById(R.id.title);

        isreprint = (ImageView) findViewById(R.id.iv_isreprint);
        reprntEncrypt = (ImageView) findViewById(R.id.iv_reprintEncrypt);
        scanEncrypt = (ImageView) findViewById(R.id.iv_scanEncrypt);

        select_dev = (Spinner) findViewById(R.id.set_select_dev);

        // 显示版本号
        String versionName = MyApp.getInstance().getVersionName();
        versionText.setText(versionName);
        confirmBtn.setVisibility(View.VISIBLE);
        updateBtn.setVisibility(View.VISIBLE);
        //findViewById(R.id.saveBtn).setVisibility(View.VISIBLE);
        if (testMOdel != null && testMOdel) { // 是否隐藏
            testlayout.setVisibility(View.VISIBLE);
        } else if (testMOdel != null && !testMOdel) {
            testlayout.setVisibility(View.GONE);
        }
        titleText.setVisibility(View.VISIBLE);
        titleText.setText(R.string.setting);
        if (pnum != null) {
            printNumText.setText(pnum + "");
        }
        if (isEncrypt != null && isEncrypt) { // 是否隐藏
            reprntEncrypt.setImageDrawable(getResources().getDrawable(R.drawable.set_choice_blue));
        } else if (testMOdel != null && !testMOdel) {
            reprntEncrypt.setImageDrawable(getResources().getDrawable(R.drawable.set_choice_gray));
        }
    }

    private void initListen() {
        versionText.setOnClickListener(this);
        updateBtn.setOnClickListener(this);
        titleText.setOnClickListener(this);
        reprintEncryptGroup.setOnClickListener(this);
        lv_printNum.setOnClickListener(this);
        printGroup.setOnClickListener(this);
        testGroup.setOnClickListener(this);
        scanGroup.setOnClickListener(this);
        confirmBtn.setOnClickListener(this);
        select_dev.setOnItemSelectedListener(new Spinner.OnItemSelectedListener() {
            public void onItemSelected(AdapterView<?> arg0, View view, int position, long id) {
                SharedPreferences2Obj.getInstance(SettingsActivity.this)
                        .setName("MachineType").setObject("type", position);
            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {
                parent.setVisibility(View.VISIBLE);
            }
        });
    }

    /*************************************** 退出应用****************************/
    private void closeApp() {
        if (num < 5) {
            long secondTime = System.currentTimeMillis();
            if (secondTime - firstTime > 4000) { // 如果两次按键时间间隔大于2秒,则不退出
                if (num == 1) {
                    firstTime = secondTime;// 更新firstTime
                }
            }
            num++;
        } else {
            num = 0;
            exitApp();
        }
    }

    /*******************************调试模式*********************************************/
    private void testApp() {
        if (num < 5) {
            long secondTime = System.currentTimeMillis();
            if (secondTime - firstTime > 4000) { // 如果两次按键时间间隔大于2秒,则不退出
                if (num == 1) {
                    firstTime = secondTime;// 更新firstTime
                }
            }
            num++;
        } else {
            num = 0;
            testDialog();
        }
    }

    /******************************* 调试弹框****************************************/
    private void testDialog() {
        if (testDialog == null) {
            final EditText inputpress = new EditText(this);
            inputpress.setInputType(InputType.TYPE_CLASS_TEXT
                    | InputType.TYPE_TEXT_VARIATION_PASSWORD);
            Builder builder = new AlertDialog.Builder(this);
            builder.setTitle(R.string.input_pwd_debug);
            builder.setIcon(android.R.drawable.ic_dialog_info);
            builder.setView(inputpress).setPositiveButton(R.string.btn_ok,
                    new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            String password = inputpress.getText().toString();
                            if (password.equals(constant.exitPwd)) {
                                LogUtil.isDebug = false;
                                testlayout.setVisibility(View.VISIBLE);
                                SharedPreferences2Obj
                                        .getInstance(SettingsActivity.this)
                                        .setName("config")
                                        .setObject("testMOdel", true);
                                testYesRadioBtn.setChecked(true);
                                testNoRadioBtn.setChecked(false);
                            } else {
                                MToast(SettingsActivity.this,
                                        getString(R.string.pwd_error_noexit),
                                        MToast.LENGTH_SHORT);
                            }
                        }
                    });

            builder.setNegativeButton(R.string.btn_cancel, null);
            AlertDialog dialog = builder.create();
            if (MyApp.getInstance().isHandset) {
                dialog.getWindow().setType(
                        WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
            }
            dialog.setCanceledOnTouchOutside(false);
            dialog.show();
        }
    }

    /******************************** 退出手持机的方法******************************/
    private void exitApp() {
        if (pwdDialog == null) {
            final EditText inputpress = new EditText(this);
            inputpress.setInputType(InputType.TYPE_CLASS_TEXT
                    | InputType.TYPE_TEXT_VARIATION_PASSWORD);
            Builder builder = new AlertDialog.Builder(this);
            builder.setTitle(R.string.input_exit_pwd);
            builder.setIcon(android.R.drawable.ic_dialog_info);
            builder.setView(inputpress).setPositiveButton(R.string.btn_ok,
                    new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            String password = inputpress.getText().toString();
                            if (password.equals(constant.exitPwd)) {
                                MyApp.getInstance().exit();
                            } else {
                                MToast(SettingsActivity.this,
                                        getString(R.string.pwd_error_noexit),
                                        MToast.LENGTH_SHORT);
                            }
                        }
                    });

            builder.setNegativeButton(getString(R.string.cancle_label), null);
            AlertDialog dialog = builder.create();
            if (MyApp.getInstance().isHandset) {
                dialog.getWindow().setType(
                        WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
            }
            dialog.setCanceledOnTouchOutside(false);
            dialog.show();
        }
    }

    private void initData() {

        beans = DbManager.GetConfigs();

        if (beans != null && beans.size() > 0) {
            serviceIpEdit.setText(beans.get(0).getEc_ip());
            if (TextUtils.isEmpty(beans.get(0).getEc_mac())) {
                machineCodeEdit.setText(DevicTool.getInstance().getDevId());
            } else {
                machineCodeEdit.setText(beans.get(0).getEc_mac());
            }
            systemPwdEdit.setText(beans.get(0).getEc_passwd());
            encodeEdit.setText(beans.get(0).getEc_identity());
            try {
                String ec_name = AESEncryptor.decrypt(constant.decrypt, beans
                        .get(0).getEc_signkey());
                identityEdit.setText(ec_name);
            } catch (Exception e) {
                e.printStackTrace();
            }
            if (1 == beans.get(0).getEc_isPrint()) {
                isprint = 1;
                isreprint.setImageDrawable(getResources().getDrawable(R.drawable.set_choice_blue));
            } else if (0 == beans.get(0).getEc_isPrint()) {
                isprint = 0;
                isreprint.setImageDrawable(getResources().getDrawable(R.drawable.set_choice_gray));
            }
        } else {

            serviceIpEdit.setText("");
            machineCodeEdit.setText(DevicTool.getInstance().getDevId());
            systemPwdEdit.setText(constant.pwd);
            encodeEdit.setText("");
            identityEdit.setText("");
            MToast(SettingsActivity.this, getString(R.string.init_setting),
                    MToast.LENGTH_SHORT);
        }

        scanBack = SharedPreferences2Obj.getInstance(this).setName("config").getObject("scanBack", Boolean.class);
        if (scanBack != null) {
            if (scanBack) {

                scanEncrypt.setImageDrawable(getResources().getDrawable(R.drawable.set_choice_blue));
            } else {
                scanEncrypt.setImageDrawable(getResources().getDrawable(R.drawable.set_choice_gray));
            }
        } else {
            scanEncrypt.setImageDrawable(getResources().getDrawable(R.drawable.set_choice_gray));
        }

        int type = SharedPreferences2Obj.getInstance(SettingsActivity.this)
                .setName("MachineType").getObject("type", Integer.class);
        select_dev.setSelection(type, true);
        devlist.add("0、鼎游小型手持机");
        devlist.add("1、鼎游指纹手持机");
        devlist.add("2、安卓手机");
        devlist.add("3、鼎游POS机");
        devlist.add("4、鼎游手持POS机");
        devlist.add("5、鼎游身份证手持机");
        devlist.add("6、鼎游大POS机");
        devlist.add("7、鼎游测温手持机");
        devlist.add("8、鼎游身份证手持机");
        devlist.add("9、鼎游NFC手持机");
        devlist.add("10、鼎游新身份证手持机");
        adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, devlist);
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        select_dev.setAdapter(adapter);
        select_dev.setSelection(type, true);
    }


    public class NetworkConnectChangedReceiver extends BroadcastReceiver {
        @Override
        public void onReceive(Context context, Intent intent) {
            if (WifiManager.WIFI_STATE_CHANGED_ACTION
                    .equals(intent.getAction())) {// 这个监听wifi的打开与关闭,与wifi的连接无关
                int wifiState = intent.getIntExtra(
                        WifiManager.EXTRA_WIFI_STATE, 0);
                LogUtil.e("H3c", "wifiState" + wifiState);
                switch (wifiState) {
                    case WifiManager.WIFI_STATE_ENABLED:
                        if (machineCodeEdit != null) {

                            if (beans != null && beans.size() > 0) {
                                if (TextUtils.isEmpty(beans.get(0).getEc_mac())) {
                                    machineCodeEdit.setText(DevicTool.getInstance().getDevId());
                                } else {
                                    machineCodeEdit.setText(beans.get(0).getEc_mac());
                                }
                            }else{
                                machineCodeEdit.setText(DevicTool.getInstance().getDevId());
                            }
                        }
                            break;
                        }
                }
            }
        }

        private void initConfig() {
            mode = getIntent().getStringExtra("mode");
            findViewById(R.id.topBack).setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View arg0) {
                    finish();
                }
            });
        }

        /************************** 下面是打印次数的弹框 ***********************************/
        private LayoutInflater inflater;
        private View layout2;

        private AlertDialog dialog2; // 部分检票弹框
        private AbstractWheel wheel;// 部分检票滚轮
        private Button reduce;// 部分检票减按钮
        private Button plus;// 部分检票加按钮

        @SuppressLint("InflateParams")
        public void dialog(int num) {
            if (dialog2 == null) {
                inflater = LayoutInflater.from(SettingsActivity.this);
                layout2 = inflater.inflate(R.layout.consume_dialog, null);
                Builder builder = new AlertDialog.Builder(SettingsActivity.this);
                builder.setTitle(R.string.print_number);
                builder.setIcon(android.R.drawable.ic_dialog_info);
                builder.setView(layout2).setPositiveButton(R.string.btn_ok,
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                printNumText.setText(wheel.getCurrentItem() + 1
                                        + "");
                                SharedPreferences2Obj
                                        .getInstance(SettingsActivity.this)
                                        .setName("MachineType")
                                        .setObject("printNum",
                                                wheel.getCurrentItem() + 1);
                            }
                        });
                builder.setNegativeButton(R.string.btn_cancel,
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                if (dialog != null) {
                                    try {
                                        dialog.dismiss();
                                    } catch (Exception e) {
                                        e.printStackTrace();
                                    } catch (Throwable e) {
                                        e.printStackTrace();
                                    }
                                }
                            }
                        });
                dialog2 = builder.create();
            }

            initWheel(layout2, R.id.wheelView, num);

            if (MyApp.getInstance().isHandset) {
                dialog2.getWindow().setType(
                        WindowManager.LayoutParams.TYPE_SYSTEM_ERROR);
            }
            dialog2.show();
        }

        private void initWheel(View view, int id, final int num) {
            wheel = (AbstractWheel) view.findViewById(id);
            wheel.setViewAdapter(new NumericWheelAdapter(SettingsActivity.this, 1,
                    num));
            wheel.setCyclic(true);
            wheel.setInterpolator(new AnticipateOvershootInterpolator());
            reduce = (Button) view.findViewById(R.id.reduce);
            reduce.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    int current = wheel.getCurrentItem() - 1;
                    if (current < 0) {
                        return;
                    }
                    wheel.setCurrentItem(current);
                }
            });

            plus = (Button) view.findViewById(R.id.plus);
            plus.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    int current = wheel.getCurrentItem() + 1;
                    if (num == current) {
                        return;
                    }
                    wheel.setCurrentItem(current);
                }
            });
        }

        @Override
        public boolean onKeyDown(int keyCode, KeyEvent event) {
            if (keyCode == KeyEvent.KEYCODE_BACK) {
                try {
                    CommetryUtils.releaseCommery(this);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                finish();
            }
            return false;
        }

        @Override
        protected void onDestroy() {
            if (receiver != null) {
                unregisterReceiver(receiver);
            }
            super.onDestroy();
        }

        /************************* 失去焦点的时候,隐藏键盘 *********************************/
        /**
         * 隐藏软键盘
         */
        @Override
        public boolean dispatchTouchEvent(MotionEvent ev) {
            // TODO Auto-generated method stub
            if (ev.getAction() == MotionEvent.ACTION_DOWN) {

                // 获得当前得到焦点的View,一般情况下就是EditText(特殊情况就是轨迹求或者实体案件会移动焦点)
                View v = getCurrentFocus();

                if (isShouldHideInput(v, ev)) {
                    InputMethodManager im = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                    hideSoftInput(v.getWindowToken(), im);
                }
            }
            return super.dispatchTouchEvent(ev);
        }

        /**
         * 根据EditText所在坐标和用户点击的坐标相对比,来判断是否隐藏键盘,因为当用户点击EditText时没必要隐藏
         *
         * @param v
         * @param event
         * @return
         */
        public boolean isShouldHideInput(View v, MotionEvent event) {
            if (v != null && (v instanceof EditText)) {
                int[] l = {0, 0};
                v.getLocationInWindow(l);
                int left = l[0], top = l[1], bottom = top + v.getHeight(), right = left
                        + v.getWidth();
                if (event.getX() > left && event.getX() < right
                        && event.getY() > top && event.getY() < bottom) {
                    // 点击EditText的事件,忽略它。
                    return false;
                } else {
                    return true;
                }
            }
            // 如果焦点不是EditText则忽略,这个发生在视图刚绘制完,第一个焦点不在EditView上,和用户用轨迹球选择其他的焦点
            return false;
        }

        /**
         * 多种隐藏软件盘方法的其中一种
         *
         * @param token
         */
        public void hideSoftInput(IBinder token, InputMethodManager im) {
            if (token != null) {
                im.hideSoftInputFromWindow(token,
                        InputMethodManager.HIDE_NOT_ALWAYS);
            }
        }

        /********************************监听事件***************************/

        @SuppressLint("DefaultLocale")
        @Override
        public void onClick(View arg0) {

            switch (arg0.getId()) {
                case R.id.lv_printNum:
                    dialog(3);
                    break;
                case R.id.version: // 调试模式
                    testApp();
                    break;
                case R.id.update:
                    if (serviceIpEdit.getText() == null
                            || serviceIpEdit.getText().toString() == null
                            || serviceIpEdit.getText().toString().trim().equals("")) {
                        Toast.makeText(SettingsActivity.this,
                                getString(R.string.fill_in_server_ip),
                                Toast.LENGTH_SHORT).show();
                        return;
                    }
                    if (encodeEdit.getText() == null
                            || encodeEdit.getText().toString() == null
                            || encodeEdit.getText().toString().trim().equals("")) {
                        Toast.makeText(SettingsActivity.this,
                                getString(R.string.fil_in_connkey), Toast.LENGTH_SHORT)
                                .show();
                        return;
                    }
                    if (identityEdit.getText() == null
                            || identityEdit.getText().toString() == null
                            || identityEdit.getText().toString().trim().equals("")) {
                        Toast.makeText(SettingsActivity.this, R.string.fil_in_qiye_key,
                                Toast.LENGTH_SHORT).show();
                        return;
                    }
                    try {
                        UpdateManager.getUpdateManager().checkAppUpdate(
                                SettingsActivity.this,
                                serviceIpEdit.getText().toString().trim(),
                                identityEdit.getText().toString().trim(),
                                encodeEdit.getText().toString().trim());
                        // 并保存信息
                        try {
                            ConfigBean bean = new ConfigBean();
                            String mac = machineCodeEdit.getText().toString().trim();
                            bean.setEc_id(0 + "");
                            bean.setEc_ip(serviceIpEdit.getText().toString().trim());
                            bean.setEc_identity(encodeEdit.getText().toString().trim());
                            bean.setEc_mac(mac.toUpperCase());
                            bean.setEc_passwd(systemPwdEdit.getText().toString().trim());
                            String signkey = AESEncryptor.encrypt(constant.decrypt,
                                    identityEdit.getText().toString().trim());
                            bean.setEc_signkey(signkey);
                            bean.setEc_isPrint(isprint);
                            if ("0".equals(mode)) {
                                DbManager.ClearConfig();
                                DbManager.InsertConfig(bean);
                            } else {
                                DbManager.ModifyConfig(bean);
                            }
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                        // }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    break;
                case R.id.set_saveBtn:
                    String ec_name = identityEdit.getText().toString().trim();
                    if (!ec_name.equals("")) {
                        try {
                            ec_name = AESEncryptor.decrypt(constant.decrypt, ec_name);
                            LogUtil.d(getString(R.string.enterprise_communication_identifier)
                                    + ec_name);
                            ec_name = AESEncryptor.encrypt(constant.decrypt, ec_name);
                        } catch (Exception ex) {
                            try {
                                ec_name = AESEncryptor.encrypt(constant.decrypt,
                                        ec_name);
                                LogUtil.d(getString(R.string.not_successfully_decrypt)
                                        + ec_name);
                            } catch (Exception e) {
                                e.printStackTrace();
                                MToast(SettingsActivity.this,
                                        getString(R.string.communication_id_error),
                                        MToast.LENGTH_SHORT);
                                ec_name = "";
                                identityEdit.setText("");
                                return;
                            }
                        }
                        if ("".equals(serviceIpEdit.getText().toString().trim())) {

                            MToast(SettingsActivity.this,
                                    getString(R.string.server_ip_notnull),
                                    MToast.LENGTH_SHORT);
                            return;
                        } else if ("".equals(systemPwdEdit.getText().toString().trim())) {
                            MToast(SettingsActivity.this,
                                    getString(R.string.pwd_notnull),
                                    MToast.LENGTH_SHORT);
                            return;
                        } else if ("".equals(encodeEdit.getText().toString().trim())) {
                            MToast(SettingsActivity.this,
                                    getString(R.string.connkey_notnull),
                                    MToast.LENGTH_SHORT);
                            return;
                        } else if ("".equals(ec_name)) {
                            MToast(SettingsActivity.this,
                                    getString(R.string.communication_id_notnull),
                                    MToast.LENGTH_SHORT);
                            return;
                        } else {

                            ConfigBean bean = new ConfigBean();
                            String mac = machineCodeEdit.getText().toString().trim();
                            bean.setEc_id(0 + "");
                            bean.setEc_ip(serviceIpEdit.getText().toString().trim());
                            bean.setEc_identity(encodeEdit.getText().toString().trim());
                            bean.setEc_mac(mac.toUpperCase());
                            bean.setEc_passwd(systemPwdEdit.getText().toString().trim());
                            bean.setEc_signkey(ec_name);
                            bean.setEc_isPrint(isprint);
                            if ("0".equals(mode)) {
                                DbManager.ClearConfig();
                                DbManager.InsertConfig(bean);
                            } else {
                                DbManager.ModifyConfig(bean);
                            }

                            Intent intent = new Intent();
                            setResult(SETTING_REQUESTCODE, intent);
                            finish();
                        }
                    } else {
                        MToast(SettingsActivity.this,
                                getString(R.string.communication_id_notnull),
                                MToast.LENGTH_SHORT);
                    }
                    break;
                case R.id.title:
                    closeApp();
                    break;
                case R.id.printGroup:
                    if (isprint == 1) {
                        isprint = 0;
                        isreprint.setImageDrawable(getResources().getDrawable(R.drawable.set_choice_gray));
                    } else if (isprint == 0) {
                        isprint = 1;
                        isreprint.setImageDrawable(getResources().getDrawable(R.drawable.set_choice_blue));
                    }
                    break;
                case R.id.reprintEncryptGroup:
                    if (isEncrypt != null && isEncrypt) { // 是否隐藏
                        isEncrypt = false;
                        SharedPreferences2Obj.getInstance(SettingsActivity.this)
                                .setName("config").setObject("isEncrypt", false);
                        reprntEncrypt.setImageDrawable(getResources().getDrawable(R.drawable.set_choice_gray));
                    } else {
                        isEncrypt = true;
                        SharedPreferences2Obj.getInstance(SettingsActivity.this)
                                .setName("config").setObject("isEncrypt", true);
                        reprntEncrypt.setImageDrawable(getResources().getDrawable(R.drawable.set_choice_blue));
                    }
                    break;
                case R.id.scanEncryptGroup:
                    if (scanBack != null && scanBack) {
                        scanBack = false;
                        SharedPreferences2Obj.getInstance(SettingsActivity.this)
                                .setName("config").setObject("scanBack", false);
                        scanEncrypt.setImageDrawable(getResources().getDrawable(R.drawable.set_choice_gray));
                    } else {
                        scanBack = true;
                        SharedPreferences2Obj.getInstance(SettingsActivity.this)
                                .setName("config").setObject("scanBack", true);
                        scanEncrypt.setImageDrawable(getResources().getDrawable(R.drawable.set_choice_blue));
                    }
                    break;
            }
        }

        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId) {
            switch (group.getId()) {

                case R.id.testGroup:
                    // 获取变更后的选中项的ID
                    if (checkedId == testYesRadioBtn.getId()) {
                        SharedPreferences2Obj.getInstance(SettingsActivity.this)
                                .setName("config").setObject("testMOdel", true);
                        testYesRadioBtn.setChecked(true);
                        testNoRadioBtn.setChecked(false);
                    } else if (checkedId == testNoRadioBtn.getId()) {
                        SharedPreferences2Obj.getInstance(SettingsActivity.this)
                                .setName("config").setObject("testMOdel", false);
                        testlayout.setVisibility(View.GONE);
                        testYesRadioBtn.setChecked(false);
                        testNoRadioBtn.setChecked(true);
                    }
                    break;

                default:
                    break;
            }
        }
    }