Example #1
0
  private void loadAndShowCaptcha(String kantonShort, String kantonLong) {
    String capchaUrl = null;
    if (Kantone.isWebFormKantonWithCaptcha(kantonLong)) {
      if (Util.isNetworkAvailable(context)) {
        try {

          WebView myWebView = new WebView(context);
          myWebView.getSettings().setJavaScriptEnabled(true);
          myWebView.getSettings().setUserAgentString(Constants.USER_AGENT_FIREFOX);
          myWebView = (WebView) findViewById(R.id.webViewCaptcha);
          myWebView.setWebViewClient(new MyWebViewClient());
          // myWebView.loadUrl(Constants.BASE_URL_AG_LU_SH_ZG_ZH
          // + kantonShort);

          capchaUrl =
              WebUtil.getCaptchaAndHiddenVars(
                  context, Constants.BASE_URL_AG_LU_SH_ZG_ZH + kantonShort);

          myWebView.setInitialScale(200);
          myWebView.setBackgroundColor(Color.WHITE);
          myWebView.setVisibility(View.VISIBLE);
          myWebView.loadUrl(capchaUrl);

          EditText textCaptcha = (EditText) findViewById(R.id.editTextCaptcha);
          textCaptcha.setVisibility(View.VISIBLE);

        } catch (InterruptedException e) {
          Toast.makeText(context, "Oh no! " + e.getMessage(), Toast.LENGTH_LONG).show();
          Log.e(TAG, "Exception:\n" + e);
        } catch (ExecutionException e) {
          Toast.makeText(context, "Oh no! " + e.getMessage(), Toast.LENGTH_LONG).show();
          Log.e(TAG, "Exception:\n" + e);
        }
      } else {
        Util.showNoNetworkAlert(context);
      }
    }
  }
Example #2
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.search);

    context = this;
    Bundle extras = getIntent().getExtras();
    final String kantonLong = extras.getString("name");
    final String kantonShort = extras.getString("nameShort");

    TextView kantonsKuerzel = (TextView) findViewById(R.id.textKantonKuerzel);
    kantonsKuerzel.setText(kantonShort);

    ImageView iconView = (ImageView) findViewById(R.id.imageKantonWappen);
    iconView.setImageResource(Kantone.getImageResId(kantonShort));

    final EditText nummerText = (EditText) findViewById(R.id.editTextNummer);
    final EditText captchaText = (EditText) findViewById(R.id.editTextCaptcha);

    final Button anfrageButton = (Button) findViewById(R.id.buttonAnfragen);
    anfrageButton.setOnClickListener(
        new View.OnClickListener() {

          public void onClick(View v) {

            if (nummerText.getText() == null
                || "".equals(nummerText.getText().toString().trim())
                || captchaText.getText() == null
                || "".equals(captchaText.getText().toString().trim())) {

              Util.showAlertBox(
                  context, getString(R.string.uuups), getString(R.string.notEmptyText));
              return;
            }

            schild = kantonShort + " " + nummerText.getText();

            // Hide keyboard
            InputMethodManager imm =
                (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(nummerText.getWindowToken(), 0);
            Log.d(TAG, "************ kantonLong=" + kantonLong);
            Log.d(TAG, "************ kantonShort=" + kantonShort);
            Log.d(TAG, "************ isWebFormKanton=" + Kantone.isWebFormKanton(kantonLong));

            if (Kantone.isWebFormKanton(kantonLong)
                || Kantone.isWebFormKantonWithCaptcha(kantonLong)) {
              if (Util.isNetworkAvailable(context)) {
                try {
                  String address =
                      WebUtil.findAddress(
                          context,
                          Constants.BASE_URL_AG_LU_SH_ZG_ZH + kantonShort,
                          schild,
                          "" + captchaText.getText());
                  Log.d(TAG, "************ Adresse=" + address);
                  TextView adresse = (TextView) findViewById(R.id.textViewAdresse);
                  adresse.setVisibility(View.VISIBLE);
                  adresse.setText(address);
                } catch (InterruptedException e) {
                  Toast.makeText(context, "Oh no! " + e.getMessage(), Toast.LENGTH_LONG).show();
                  Log.e(TAG, "Exception:\n" + e);
                } catch (ExecutionException e) {
                  Toast.makeText(context, "Oh no! " + e.getMessage(), Toast.LENGTH_LONG).show();
                  Log.e(TAG, "Exception:\n" + e);
                }

              } else {
                Util.showNoNetworkAlert(context);
              }
            } else if (Kantone.isSmsKanton(kantonLong)) {
              Util.showSmsAlert(context, kantonShort, schild);
            } else if (Kantone.isEmailKanton(kantonLong)) {
              Util.startEmailActivity(context, Kantone.getContact(kantonLong), schild);
            }
          }
        });

    // hides the keyboad when opening sreen
    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);

    loadAndShowCaptcha(kantonShort, kantonLong);
  }