Esempio n. 1
0
 @Override
 public void onBackPressed() {
   if (lock != null) {
     lock.stop();
   }
   super.onBackPressed();
 }
Esempio n. 2
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
    super.onCreate(savedInstanceState);

    // requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
    setContentView(R.layout.activity_lock);
    getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.custom_title);

    SharedPreferences settings = getSharedPreferences("my", 0);
    String address = settings.getString("LockAddress", "");
    String nameLock = settings.getString("LockName", "");
    boolean useLock = settings.getBoolean("LockEnable", false);
    pass = settings.getString("LockPass", "");

    BluetoothAdapter btAdapter = BluetoothAdapter.getDefaultAdapter();
    if (!btAdapter.isEnabled()) btAdapter.enable();

    device = btAdapter.getRemoteDevice(address);

    use = (CheckBox) findViewById(R.id.useLock);
    use.setOnClickListener(
        new View.OnClickListener() {
          public void onClick(View v) {
            SharedPreferences settings = getSharedPreferences("my", 0);
            SharedPreferences.Editor editor = settings.edit();
            editor.putBoolean("LockEnable", use.isChecked());
            editor.commit();
          }
        });
    use.setChecked(useLock);

    name = (TextView) findViewById(R.id.textview_lock_name);
    name.setText(nameLock);

    oldPass = (EditText) findViewById(R.id.edittext_old_pass);
    newPass = (EditText) findViewById(R.id.edittext_new_pass);
    setPass = (EditText) findViewById(R.id.edittext_set_pass);
    setPass.setText(pass);

    lock = new LockEngine(this, mHandler, device, pass, true);
    lock.start();

    open = (Button) findViewById(R.id.button_open);
    open.setOnClickListener(
        new View.OnClickListener() {
          public void onClick(View v) {
            lock.open();
          }
        });
    close = (Button) findViewById(R.id.button_close);
    close.setOnClickListener(
        new View.OnClickListener() {
          public void onClick(View v) {
            lock.close();
          }
        });

    set = (Button) findViewById(R.id.button_set);
    set.setOnClickListener(
        new View.OnClickListener() {
          public void onClick(View v) {
            SharedPreferences settings = getSharedPreferences("my", 0);
            SharedPreferences.Editor editor = settings.edit();
            pass = setPass.getText().toString();
            Toast.makeText(getApplicationContext(), "Lock password: "******"LockPass", pass);
            editor.commit();
            setPass.setText(pass);
          }
        });

    reset = (Button) findViewById(R.id.button_reset);
    reset.setOnClickListener(
        new View.OnClickListener() {
          public void onClick(View v) {
            Log.d(tag, "resetActivity");
            String olde = oldPass.getText().toString();
            String newe = newPass.getText().toString();
            if (olde.equals("") || newe.equals("")) {
              Toast.makeText(getApplicationContext(), "Set both fields", Toast.LENGTH_SHORT).show();
              return;
            }
            lock.reset(olde, newe);
            SharedPreferences settings = getSharedPreferences("my", 0);
            SharedPreferences.Editor editor = settings.edit();
            pass = newPass.getText().toString();
            editor.putString("LockPass", pass);
            editor.commit();
            oldPass.setText("");
            newPass.setText("");
            setPass.setText(pass);
          }
        });
    test = (Button) findViewById(R.id.button_test);
    test.setOnClickListener(
        new View.OnClickListener() {
          public void onClick(View v) {
            lock.test(pass);
          }
        });
  }