コード例 #1
0
ファイル: MainActivity.java プロジェクト: katalonec/figures
        @Override
        public void onClick(View v) {
          if (mDrawerToggle != null) mDrawerLayout.closeDrawer(mDrawer);

          AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
          LayoutInflater inflater = getLayoutInflater();
          builder.setTitle(R.string.title_new_surface);
          builder
              .setView(inflater.inflate(R.layout.dialog_new_surface, null))
              .setPositiveButton(
                  R.string.ok,
                  new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int id) {
                      EditText field = (EditText) ((AlertDialog) dialog).findViewById(R.id.name);
                      String name = field.getText().toString();
                      if (!TextUtils.isEmpty(name)) {
                        ContentValues values = new ContentValues();
                        values.put(DbHelper.SURFACE_NAME, name);
                        Uri uri =
                            getContentResolver()
                                .insert(SurfaceProvider.SURFACES_CONTENT_URI, values);
                        if (uri != null) showDetail(0, Long.parseLong(uri.getLastPathSegment()));
                      }
                    }
                  })
              .setNegativeButton(
                  R.string.cancel,
                  new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                      dialog.cancel();
                    }
                  });
          builder.show();
        }
コード例 #2
0
ファイル: MainActivity.java プロジェクト: katalonec/figures
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    if (mDrawerToggle != null && mDrawerToggle.onOptionsItemSelected(item)) {
      return true;
    }
    int id = item.getItemId();
    switch (id) {
      case R.id.action_email:
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        LayoutInflater inflater = getLayoutInflater();
        builder
            .setView(inflater.inflate(R.layout.dialog_email, null))
            .setPositiveButton(
                R.string.send,
                new DialogInterface.OnClickListener() {
                  @Override
                  public void onClick(DialogInterface dialog, int id) {
                    EditText field = (EditText) ((AlertDialog) dialog).findViewById(R.id.mail);
                    String email = field.getText().toString();
                    if (!TextUtils.isEmpty(email)) {
                      mTask = new EmailTask().execute(email);
                    }
                  }
                })
            .setNegativeButton(
                R.string.cancel,
                new DialogInterface.OnClickListener() {
                  public void onClick(DialogInterface dialog, int id) {
                    dialog.cancel();
                  }
                });
        builder.show();
        return true;

      case R.id.action_upload:
        if (isOnline(true)) {
          setProgressBarIndeterminateVisibility(true);

          Intent service = new Intent(this, UploadService.class);
          service.setAction(ACTION_UPLOAD);
          startService(service);
        }
        return true;
    }
    return super.onOptionsItemSelected(item);
  }
コード例 #3
0
  /** Opens the dialog for choosing verifier or signer */
  private void chooseFunction() {
    // Dialog for choosing verifier or signer
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle(R.string.choose_function);
    builder.setSingleChoiceItems(R.array.items, 0, null);
    builder
        .setPositiveButton(
            R.string.select,
            new DialogInterface.OnClickListener() {
              @Override
              public void onClick(DialogInterface dialog, int which) {
                int selectedPos = ((AlertDialog) dialog).getListView().getCheckedItemPosition();
                mNfcAdapter = NfcAdapter.getDefaultAdapter(((AlertDialog) dialog).getContext());
                if (mNfcAdapter == null) {
                  // Stop here, we definitely need NFC
                  Toast.makeText(
                          ((AlertDialog) dialog).getContext(),
                          getString(R.string.not_supporting_NFC),
                          Toast.LENGTH_LONG)
                      .show();
                  finish();
                  return;
                }
                if (selectedPos == 0) {
                  Intent i =
                      new Intent(((AlertDialog) dialog).getContext(), NFCReaderActivity.class);
                  finish();
                  startActivity(i);
                  return;
                } else {
                  setContentView(R.layout.sign_layout);
                  sendButton = (Button) findViewById(R.id.sendButton);
                  messageTextField = (EditText) findViewById(R.id.messageText);
                  if (!mNfcAdapter.isEnabled()) {
                    messageTextField.setText(getString(R.string.nfc_disabled));
                    messageTextField.setEnabled(false);
                    sendButton.setEnabled(false);
                  } else {
                    messageTextField.setText(getString(R.string.nfc_enabled));
                  }

                  // set Elements of spinner
                  spinner = (Spinner) findViewById(R.id.spinner);
                  ArrayAdapter<CharSequence> adapter =
                      ArrayAdapter.createFromResource(
                          ((AlertDialog) dialog).getContext(),
                          R.array.options,
                          android.R.layout.simple_spinner_item);
                  adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
                  spinner.setAdapter(adapter);
                  // define the action if an item is selected
                  spinner.setOnItemSelectedListener(
                      new AdapterView.OnItemSelectedListener() {
                        @Override
                        public void onItemSelected(
                            AdapterView<?> parent, View view, int position, long id) {
                          isWrongMessage = false;
                          if (position < 4) {
                            actualGsk = gsks[position];
                          } else if (position == 4) {
                            actualGsk =
                                new GroupSecretKey(
                                    generateRandomIntArray(8),
                                    generateRandomIntArray(8),
                                    generateRandomIntArray(8));
                          } else {
                            isWrongMessage = true;
                          }
                        }

                        @Override
                        public void onNothingSelected(AdapterView<?> parent) {}
                      });
                  sendButton.setOnClickListener(
                      new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                          String message = messageTextField.getText().toString();
                          if (message.trim().isEmpty()) {
                            Toast.makeText(v.getContext(), R.string.no_message, Toast.LENGTH_LONG)
                                .show();
                          } else {
                            double t = System.nanoTime();
                            SdhSignature sig = sign(message, gpk, actualGsk);
                            t = System.nanoTime() - t;
                            Log.i("TIME in java", "" + t / 1000000000.0);
                            if (isWrongMessage) {
                              message = message + " some text";
                            }
                            // API 10 compatibility
                            mNfcAdapter.enableForegroundNdefPush(
                                MainActivity.this, generateNDefMessage(message, sig));
                          }
                        }
                      });
                }
              }
            })
        .setNegativeButton(
            R.string.cancel,
            new DialogInterface.OnClickListener() {
              @Override
              public void onClick(DialogInterface dialog, int which) {
                System.exit(0);
              }
            });
    AlertDialog dialog = builder.create();
    dialog.show();
  }