예제 #1
0
 @Override
 public void onClick(View view) {
   switch (view.getId()) {
     case R.id.send:
       String question = showQuestion ? questionView.getText().toString() : null;
       String answer = ((TextView) findViewById(R.id.answer)).getText().toString();
       try {
         if (answerRequest) OTRManager.getInstance().respondSmp(account, user, question, answer);
         else OTRManager.getInstance().initSmp(account, user, question, answer);
       } catch (NetworkException e) {
         Application.getInstance().onError(e);
       }
       finish();
       break;
     case R.id.cancel:
       try {
         OTRManager.getInstance().abortSmp(account, user);
       } catch (NetworkException e) {
         Application.getInstance().onError(e);
       }
       finish();
     default:
       break;
   }
 }
예제 #2
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (isFinishing()) return;

    Intent intent = getIntent();
    account = QuestionViewer.getAccount(intent);
    user = QuestionViewer.getUser(intent);
    if (AccountManager.getInstance().getAccount(account) == null || user == null) {
      Application.getInstance().onError(R.string.ENTRY_IS_NOT_FOUND);
      finish();
      return;
    }
    if (intent.getBooleanExtra(EXTRA_FIELD_CANCEL, false)) {
      try {
        OTRManager.getInstance().abortSmp(account, user);
      } catch (NetworkException e) {
        Application.getInstance().onError(e);
      }
      finish();
      return;
    }
    showQuestion = intent.getBooleanExtra(EXTRA_FIELD_SHOW_QUESTION, true);
    answerRequest = intent.getBooleanExtra(EXTRA_FIELD_ANSWER_REQUEST, false);
    if (showQuestion) {
      setContentView(R.layout.question_viewer);
      questionView = (EditText) findViewById(R.id.question);
      questionView.setEnabled(!answerRequest);
      if (answerRequest) questionView.setText(intent.getStringExtra(Intent.EXTRA_TEXT));
      else findViewById(R.id.cancel).setVisibility(View.GONE);
    } else setContentView(R.layout.secret_viewer);
    findViewById(R.id.cancel).setOnClickListener(this);
    findViewById(R.id.send).setOnClickListener(this);
  }