@Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.upload_key_activity);

    mUploadButton = findViewById(R.id.upload_key_action_upload);
    mKeyServerSpinner = (Spinner) findViewById(R.id.upload_key_keyserver);

    ArrayAdapter<String> adapter =
        new ArrayAdapter<String>(
            this,
            android.R.layout.simple_spinner_item,
            Preferences.getPreferences(this).getKeyServers());
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    mKeyServerSpinner.setAdapter(adapter);
    if (adapter.getCount() > 0) {
      mKeyServerSpinner.setSelection(0);
    } else {
      mUploadButton.setEnabled(false);
    }

    mUploadButton.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(View v) {
            uploadKey();
          }
        });

    mDataUri = getIntent().getData();
    if (mDataUri == null) {
      Log.e(Constants.TAG, "Intent data missing. Should be Uri of key!");
      finish();
      return;
    }
  }
  /** Inflate the layout for this fragment */
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.import_keys_server_fragment, container, false);

    mSearchButton = view.findViewById(R.id.import_server_search);
    mQueryEditText = (AutoCompleteTextView) view.findViewById(R.id.import_server_query);
    mConfigButton = view.findViewById(R.id.import_server_config_button);
    mConfigLayout = view.findViewById(R.id.import_server_config);
    mServerSpinner = (Spinner) view.findViewById(R.id.import_server_spinner);

    // add keyservers to spinner
    mServerAdapter =
        new ArrayAdapter<String>(
            getActivity(),
            android.R.layout.simple_spinner_item,
            Preferences.getPreferences(getActivity()).getKeyServers());
    mServerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    mServerSpinner.setAdapter(mServerAdapter);
    if (mServerAdapter.getCount() > 0) {
      mServerSpinner.setSelection(0);
    } else {
      mSearchButton.setEnabled(false);
    }

    List<String> namesAndEmails = ContactHelper.getContactNames(getActivity());
    namesAndEmails.addAll(ContactHelper.getContactMails(getActivity()));
    mQueryEditText.setThreshold(3);
    mQueryEditText.setAdapter(
        new ArrayAdapter<String>(
            getActivity(), android.R.layout.simple_spinner_dropdown_item, namesAndEmails));

    mSearchButton.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(View v) {
            String query = mQueryEditText.getText().toString();
            String keyServer = (String) mServerSpinner.getSelectedItem();
            search(query, keyServer);

            // close keyboard after pressing search
            InputMethodManager imm =
                (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(mQueryEditText.getWindowToken(), 0);
          }
        });

    mQueryEditText.setOnEditorActionListener(
        new TextView.OnEditorActionListener() {
          @Override
          public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_SEARCH) {
              String query = mQueryEditText.getText().toString();
              String keyServer = (String) mServerSpinner.getSelectedItem();
              search(query, keyServer);

              // Don't return true to let the keyboard close itself after pressing search
              return false;
            }
            return false;
          }
        });

    mConfigButton.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(View v) {
            if (mImportActivity.getViewPagerHeight() > ImportKeysActivity.VIEW_PAGER_HEIGHT) {
              mImportActivity.resizeViewPager(ImportKeysActivity.VIEW_PAGER_HEIGHT);
            } else {
              mImportActivity.resizeViewPager(ImportKeysActivity.VIEW_PAGER_HEIGHT + 41);
            }
          }
        });

    return view;
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.certify_key_activity);

    final ActionBar actionBar = getSupportActionBar();
    actionBar.setDisplayShowTitleEnabled(true);
    actionBar.setDisplayHomeAsUpEnabled(false);
    actionBar.setHomeButtonEnabled(false);

    mSelectKeyFragment =
        (SelectSecretKeyLayoutFragment)
            getSupportFragmentManager().findFragmentById(R.id.sign_key_select_key_fragment);
    mSelectKeyFragment.setCallback(this);
    mSelectKeyFragment.setFilterCertify(true);

    mSelectKeyserverSpinner = (Spinner) findViewById(R.id.sign_key_keyserver);
    ArrayAdapter<String> adapter =
        new ArrayAdapter<String>(
            this,
            android.R.layout.simple_spinner_item,
            Preferences.getPreferences(this).getKeyServers());
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    mSelectKeyserverSpinner.setAdapter(adapter);

    mUploadKeyCheckbox = (CheckBox) findViewById(R.id.sign_key_upload_checkbox);
    if (!mUploadKeyCheckbox.isChecked()) {
      mSelectKeyserverSpinner.setEnabled(false);
    } else {
      mSelectKeyserverSpinner.setEnabled(true);
    }

    mUploadKeyCheckbox.setOnCheckedChangeListener(
        new OnCheckedChangeListener() {

          @Override
          public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (!isChecked) {
              mSelectKeyserverSpinner.setEnabled(false);
            } else {
              mSelectKeyserverSpinner.setEnabled(true);
            }
          }
        });

    mSignButton = (BootstrapButton) findViewById(R.id.sign_key_sign_button);
    mSignButton.setOnClickListener(
        new OnClickListener() {

          @Override
          public void onClick(View v) {
            if (mPubKeyId != 0) {
              if (mMasterKeyId == 0) {
                mSelectKeyFragment.setError(getString(R.string.select_key_to_sign));
              } else {
                initiateSigning();
              }
            }
          }
        });

    mDataUri = getIntent().getData();
    if (mDataUri == null) {
      Log.e(Constants.TAG, "Intent data missing. Should be Uri of key!");
      finish();
      return;
    }

    PGPPublicKeyRing signKey = (PGPPublicKeyRing) ProviderHelper.getPGPKeyRing(this, mDataUri);

    if (signKey != null) {
      mPubKeyId = PgpKeyHelper.getMasterKey(signKey).getKeyID();
      drawPublicKey();
    }
    if (mPubKeyId == 0) {
      Log.e(Constants.TAG, "this shouldn't happen. KeyId == 0!");
      finish();
      return;
    }
  }