コード例 #1
0
 /**
  * 同步联系人
  *
  * @param v
  */
 public void syncContact(View v) {
   Log.d("goc", "syncContact");
   if (BTFileOperater.getAccStatus())
     if (ContactCallLogStatus.contactDeleting()) {
       pdSC = ProgressDialog.show(BTSettings.this, "", "联系人同步中,请稍等。。。", false, true);
     } else if (Config.contactDeleting) {
       pdCC = ProgressDialog.show(BTSettings.this, "", "正在清空联系人,请稍等。。。", false, true);
     } else {
       showDialog("请确认要同步通讯录!", SYNC_CONTACT);
     }
 }
コード例 #2
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.bt_settings);

    syncContact = (LinearLayout) findViewById(R.id.sync_contact);

    // 蓝牙名称
    btName = (EditText) findViewById(R.id.bt_name);
    btName.setText(Config.BT_NAME);
    btName.setOnEditorActionListener(
        new OnEditorActionListener() {

          @Override
          public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            // TODO Auto-generated method stub
            String name = btName.getText().toString();
            if (name == null || name.length() == 0) {
              name = Config.BT_NAME;
              btName.setText(name);
            }
            if (!Config.BT_NAME.equals(name)) {
              Log.d("goc", "input finish " + Config.BT_NAME + " " + name);
              Config.BT_NAME = name;
              if (isBTConnected()) {
                sendBroadcast(new Intent(GocMessage.DISCONNECT_PHONE));
              }
              sendBroadcast(new Intent(GocMessage.SET_BT_NAME));
            }
            return false;
          }
        });
    // 蓝牙密钥
    btPinCode = (EditText) findViewById(R.id.bt_pin_code);
    btPinCode.setText(Config.BT_PIN_CODE);
    btPinCode.setOnEditorActionListener(
        new OnEditorActionListener() {

          @Override
          public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            // TODO Auto-generated method stub
            Log.d("goc", "input finish");
            String pin = btPinCode.getText().toString();
            if (pin == null || pin.length() == 0) {
              pin = Config.BT_PIN_CODE;
              btPinCode.setText(pin);
            }
            Config.BT_PIN_CODE = pin;
            sendBroadcast(new Intent(GocMessage.SET_BT_PIN_CODE));
            return false;
          }
        });
    // 蓝牙连接
    btPair = (RelativeLayout) findViewById(R.id.bt_pair);
    btConnectOperate = (TextView) findViewById(R.id.bt_connect_operate);
    btConnectStatus = (TextView) findViewById(R.id.bt_connect_status);
    btConnectOperate.setText(isBTConnected() ? "断开连接" : "开始配对");
    btConnectStatus.setText(Config.BT_PARI_NAME);

    // 蓝牙开关
    switchButton = (SwitchButton) findViewById(R.id.switchBT);
    String btStatus = Settings.System.getString(getContentResolver(), "bt_enable");
    if (BTFileOperater.getAccStatus()) {
      switchButton.setChecked(btStatus.equals("1"));
      switchButton.setEnabled(true);
    } else {
      switchButton.setEnabled(false);
      btName.setEnabled(false);
      btPinCode.setEnabled(false);
      btPair.setEnabled(false);
      btPair.setClickable(false);
    }
    switchButton.setOnCheckedChangeListener(
        new OnCheckedChangeListener() {

          @Override
          public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            // TODO Auto-generated method stub
            String status = isChecked ? "1" : "0";
            Settings.System.putString(getContentResolver(), "bt_enable", status);
            if (!isChecked) {
              btPair.setClickable(false);
              syncContact.setClickable(false);
              Settings.System.putString(getContentResolver(), "bt_connect", "0");
              startGocsdkService(OperateCommand.BT_UNFOUND_UNCONNECT);
            } else {
              btPair.setClickable(true);
              syncContact.setClickable(true);
              btConnectOperate.setText(isBTConnected() ? "断开连接" : "开始配对");
              startGocsdkService(OperateCommand.BT_FOUND_CONNECT);
            }
            // BTFileOperater.writeBTFile(status);
            // startGocsdkService(isChecked ? OperateCommand.OPEN_BT : OperateCommand.CLOSE_BT);
            switchButton.setEnabled(false);
            new Handler()
                .postDelayed(
                    new Runnable() {

                      @Override
                      public void run() {
                        // TODO Auto-generated method stub
                        switchButton.setEnabled(true);
                      }
                    },
                    2000);
          }
        });

    initGocReceiver();
  }