Esempio n. 1
0
  public void addSegment(String title) {
    DisplayMetrics metrics = new DisplayMetrics();
    ((Activity) getContext()).getWindowManager().getDefaultDisplay().getMetrics(metrics);

    ToggleButton b = new ToggleButton(getContext());
    b.setText(title);
    b.setTextOff(title);
    b.setTextOn(title);
    b.setTextColor(Color.WHITE);
    b.setTypeface(Typeface.DEFAULT_BOLD);
    b.setMinimumWidth((int) (40 * metrics.density));
    if (mSwitches.size() == 0) {
      b.setBackgroundResource(mLeftDrawable);
      b.setEnabled(false);
      b.setChecked(true);
    } else {
      if (mSwitches.size() > 1) {
        ToggleButton temp = mSwitches.get(mSwitches.size() - 1);
        temp.setBackgroundResource(mMidDrawable);
      }

      b.setBackgroundResource(mRightDrawable);
    }

    LinearLayout.LayoutParams params =
        new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    params.weight = 0.1f;
    params.gravity = Gravity.CENTER;
    b.setLayoutParams(params);

    b.setOnCheckedChangeListener(this);

    mSwitches.add(b);
    addView(b);
  }
Esempio n. 2
0
 public void checkButtonAlarm(ToggleButton personale, String log) {
   if (personale.isChecked()) {
     personale.setBackgroundResource(R.layout.rosso);
     personale.setText(log);
   } else {
     personale.setBackgroundResource(R.layout.acceso);
     personale.setText(log);
   }
 }
Esempio n. 3
0
 public void checkButton(ToggleButton personale) {
   if (personale.isChecked()) {
     personale.setBackgroundResource(R.layout.acceso);
     personale.setText("Acceso");
   } else {
     personale.setBackgroundResource(R.layout.spento);
     personale.setText("Spento");
   }
 }
Esempio n. 4
0
  public void setNumberOfSegments(int num) {
    mSwitches.clear();

    DisplayMetrics metrics = new DisplayMetrics();
    ((Activity) getContext()).getWindowManager().getDefaultDisplay().getMetrics(metrics);

    for (int i = 0; i < num; i++) {
      ToggleButton b = new ToggleButton(getContext());
      if (i == 0) {
        b.setBackgroundResource(mLeftDrawable);
        b.setEnabled(false);
        b.setChecked(true);
      } else if (i == num - 1) {
        b.setBackgroundResource(mRightDrawable);
      } else {
        b.setBackgroundResource(mMidDrawable);
      }

      b.setText("");
      b.setTextOff("");
      b.setTextOn("");
      b.setTextColor(Color.WHITE);
      b.setTypeface(Typeface.DEFAULT_BOLD);
      b.setMinimumWidth((int) (40 * metrics.density));

      LinearLayout.LayoutParams params =
          new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
      params.gravity = Gravity.CENTER;
      params.weight = 0.1f;
      b.setLayoutParams(params);

      b.setOnCheckedChangeListener(this);

      mSwitches.add(b);
      addView(b);
    }
  }
Esempio n. 5
0
  @Override
  public void onClick(View v) {
    // TODO Auto-generated method stub
    switch (v.getId()) {
        // home tab view
      case R.id.imageView1:
        if (CONNECTION_SERVER) {
          if (DOOR == Constants.MSG_LOCK) {
            if (tButton2.isChecked()) {
              // Check password
              showDialog(DIALOG_PASSWORD);

            } else if (tButton1.isChecked()) {
              String PASSWORD = "******";
              dataID = String.valueOf(Constants.MSG_UNLOCK);
              data = PASSWORD + "," + mUser.getName() + "," + mUser.getIcon();
              dataLen = mSocket.makeDataLenToByte(data.length());
              mSocket.sendMessage(dataID.getBytes(), dataLen, data.getBytes());
            }

          } else if (DOOR == Constants.MSG_UNLOCK) {
            // Send Lock Message
            dataID = String.valueOf(Constants.MSG_LOCK);
            data = mUser.getName();
            dataLen = mSocket.makeDataLenToByte(data.length());
            mSocket.sendMessage(dataID.getBytes(), dataLen, data.getBytes());
          }
        } else {
          setToast("문을 제어할 수 없습니다. 서버연결 확인 후 다시 시도해주세요.");
        }
        break;

      case R.id.image_lock:
        if (CONNECTION_SERVER && CONNECTION_USER) {
          if (DOOR == Constants.MSG_UNLOCK) {
            // Send Lock Message
            dataID = String.valueOf(Constants.MSG_LOCK);
            data = mUser.getName();
            dataLen = mSocket.makeDataLenToByte(data.length());
            mSocket.sendMessage(dataID.getBytes(), dataLen, data.getBytes());
          }
        } else {
          setToast("문을 제어할 수 없습니다. 서버연결 확인 후 다시 시도해주세요.");
        }
        break;

      case R.id.image_unlock:
        if (CONNECTION_SERVER && CONNECTION_USER) {
          if (DOOR == Constants.MSG_LOCK) {
            if (tButton2.isChecked()) {
              // Check password
              showDialog(DIALOG_PASSWORD);

            } else if (tButton1.isChecked()) {
              String PASSWORD = "******";
              dataID = String.valueOf(Constants.MSG_UNLOCK);
              data = PASSWORD + "," + mUser.getName() + "," + mUser.getIcon();
              dataLen = mSocket.makeDataLenToByte(data.length());
              mSocket.sendMessage(dataID.getBytes(), dataLen, data.getBytes());
            }
          }
        } else {
          setToast("문을 제어할 수 없습니다. 서버연결 확인 후 다시 시도해주세요.");
        }
        break;

        // setting tab view
      case R.id.imageView3:
        imageView3.setVisibility(View.GONE);
        textView10.setVisibility(View.VISIBLE);
        imageView4.setVisibility(View.VISIBLE);
        break;
      case R.id.imageView4:
        imageView3.setVisibility(View.VISIBLE);
        textView10.setVisibility(View.GONE);
        imageView4.setVisibility(View.GONE);
        break;
      case R.id.imageView5:
        imageView5.setVisibility(View.GONE);
        textView11.setVisibility(View.VISIBLE);
        imageView6.setVisibility(View.VISIBLE);
        break;
      case R.id.imageView6:
        imageView5.setVisibility(View.VISIBLE);
        textView11.setVisibility(View.GONE);
        imageView6.setVisibility(View.GONE);
        break;
      case R.id.imageView7:
        imageView7.setVisibility(View.GONE);
        textView12.setVisibility(View.VISIBLE);
        textView13.setVisibility(View.VISIBLE);
        textView14.setVisibility(View.VISIBLE);
        imageView8.setVisibility(View.VISIBLE);
        break;
      case R.id.imageView8:
        imageView7.setVisibility(View.VISIBLE);
        textView12.setVisibility(View.GONE);
        textView13.setVisibility(View.GONE);
        textView14.setVisibility(View.GONE);
        imageView8.setVisibility(View.GONE);
        break;
      case R.id.button1: // request user register
        String name = editText1.getText().toString();
        String key = editText2.getText().toString();
        String icon = String.valueOf(mUser.getIcon());
        String ip = mSocket.getIPAddress().toString();
        if (!name.equals("") && !key.equals("") && !icon.equals("")) {
          if (CONNECTION_SERVER) {
            mUser.setName(editText1.getText().toString());
            dataID = String.valueOf(Constants.MSG_KEY);
            data = key + "," + name + "," + icon + "," + ip;
            dataLen = mSocket.makeDataLenToByte(data.length());
            mSocket.sendMessage(dataID.getBytes(), dataLen, data.getBytes());
          } else {
            setToast("서버와 연결되지 않았습니다.");
          }
        } else {
          setToast("빈칸을 모두 채워주세요.");
        }
        break;
      case R.id.button2: // request connecting server
        SIP = editText3.getText().toString();
        DATA_SPORT = editText4.getText().toString();
        VIDEO_SPORT = editText5.getText().toString();
        if (!SIP.equals("")
            && !(editText4.getText().toString().equals(""))
            && !(editText5.getText().toString().equals(""))) {
          mSocket.setServerAddress(SIP, DATA_SPORT);
          mSocket.Connect();
        } else {
          setToast("빈칸을 모두 채워주세요.");
        }
        break;
      case R.id.button6: // request user delete
        String name1 = editText1.getText().toString();
        String key1 = editText2.getText().toString();
        String icon1 = String.valueOf(mUser.getIcon());
        if (!name1.equals("") && !key1.equals("") && !icon1.equals("")) {
          if (CONNECTION_SERVER) {
            mUser.setName(editText1.getText().toString());
            dataID = String.valueOf(Constants.MSG_KEYDEL);
            data = key1 + "," + name1 + "," + icon1;
            dataLen = mSocket.makeDataLenToByte(data.length());
            mSocket.sendMessage(dataID.getBytes(), dataLen, data.getBytes());
          } else {
            setToast("서버와 연결되지 않았습니다.");
          }
        } else {
          setToast("빈칸을 모두 채워주세요.");
        }
        break;
      case R.id.toggleButton1:
        lockLevel = 1;
        tButton1.setBackgroundResource(R.drawable.selector_red);
        tButton2.setBackgroundResource(R.drawable.selector_gray);
        tButton3.setBackgroundResource(R.drawable.selector_gray);
        tButton1.setChecked(true);
        tButton2.setChecked(false);
        tButton3.setChecked(false);
        tButton1.setText("1단계");
        tButton2.setText("2단계");
        tButton3.setText("3단계");
        break;
      case R.id.toggleButton2:
        lockLevel = 2;
        tButton1.setBackgroundResource(R.drawable.selector_gray);
        tButton2.setBackgroundResource(R.drawable.selector_yellow);
        tButton3.setBackgroundResource(R.drawable.selector_gray);
        tButton1.setChecked(true);
        tButton2.setChecked(true);
        tButton3.setChecked(false);
        tButton1.setText("1단계");
        tButton2.setText("2단계");
        tButton3.setText("3단계");
        break;
      case R.id.toggleButton3:
        lockLevel = 3;
        tButton1.setBackgroundResource(R.drawable.selector_gray);
        tButton2.setBackgroundResource(R.drawable.selector_gray);
        tButton3.setBackgroundResource(R.drawable.selector_green);
        tButton1.setChecked(true);
        tButton2.setChecked(true);
        tButton3.setChecked(true);
        tButton1.setText("1단계");
        tButton2.setText("2단계");
        tButton3.setText("3단계");
        break;
      case R.id.select_icon:
        showDialog(DIALOG_SELECTICON);
        break;
    }
  }