private AlertDialog createEditSubjectDialog(
      final SubjectCard materia, final Runnable success, final Runnable failure) {
    View dialogContent = View.inflate(this, R.layout.edit_dialog, null);
    final TextView etNomeMateria = (TextView) dialogContent.findViewById(R.id.nome_materia);
    final TextView etProfessorName = (TextView) dialogContent.findViewById(R.id.professor_name);
    final TextView etAulasSemanais = (TextView) dialogContent.findViewById(R.id.maximo_atrasos);

    etNomeMateria.setText(materia.getData().getName());
    etProfessorName.setText(materia.getData().getProfessorName());
    etAulasSemanais.setText(Integer.toString(materia.getData().getWeeklyClasses()));

    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder
        .setMessage("Edição de Matéria")
        .setView(dialogContent)
        .setPositiveButton(
            "Salvar",
            new DialogInterface.OnClickListener() {
              @Override
              public void onClick(DialogInterface dialog, int which) {
                materia.setSubjectName(etNomeMateria.getText().toString());
                materia.setProfessorName(etProfessorName.getText().toString());
                materia.setAulasSemanais(Integer.parseInt(etAulasSemanais.getText().toString()));
                materia.update();
                updateTotal();
                if (success != null) success.run();
              }
            })
        .setNegativeButton(
            "Cancelar",
            new DialogInterface.OnClickListener() {
              @Override
              public void onClick(DialogInterface dialog, int which) {
                if (failure != null) failure.run();
              }
            });

    AlertDialog dialog = builder.create();
    dialog.setOnCancelListener(
        new DialogInterface.OnCancelListener() {
          @Override
          public void onCancel(DialogInterface dialog) {
            if (failure != null) failure.run();
          }
        });
    dialog.setOnShowListener(
        new DialogInterface.OnShowListener() {
          @Override
          public void onShow(DialogInterface dialog) {
            etNomeMateria.requestFocus();
            InputMethodManager imm =
                (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.showSoftInput(etNomeMateria, InputMethodManager.SHOW_IMPLICIT);
          }
        });
    return dialog;
  }
  private void showHolderDialog() {
    AlertDialog.Builder builder =
        new AlertDialog.Builder(new UltimateBrowserProjectContextWrapper(this));
    builder.setCancelable(true);

    FrameLayout linearLayout =
        (FrameLayout) getLayoutInflater().inflate(R.layout.dialog_list, null, false);
    builder.setView(linearLayout);

    String[] strings = getResources().getStringArray(R.array.holder_menu);
    List<String> list = new ArrayList<>();
    list.addAll(Arrays.asList(strings));

    ListView listView = (ListView) linearLayout.findViewById(R.id.dialog_list);
    DialogAdapter adapter = new DialogAdapter(this, R.layout.dialog_text_item, list);
    listView.setAdapter(adapter);
    adapter.notifyDataSetChanged();

    final AlertDialog dialog = builder.create();
    dialog.setOnCancelListener(
        new DialogInterface.OnCancelListener() {
          @Override
          public void onCancel(DialogInterface dialog) {
            HolderActivity.this.finish();
          }
        });
    dialog.show();

    listView.setOnItemClickListener(
        new AdapterView.OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            switch (position) {
              case 0:
                Intent toActivity = new Intent(HolderActivity.this, BrowserActivity.class);
                toActivity.putExtra(IntentUnit.OPEN, first.getURL());
                startActivity(toActivity);
                break;
              case 1:
                BrowserUnit.copyURL(HolderActivity.this, first.getURL());
                break;
              case 2:
                IntentUnit.share(HolderActivity.this, first.getTitle(), first.getURL());
                break;
              default:
                break;
            }

            dialog.hide();
            dialog.dismiss();
            finish();
          }
        });
  }
示例#3
0
 @Override
 protected Dialog onCreateDialog(int id) {
   AlertDialog dialog = null;
   switch (id) {
     case DIALOG_DELETE_ITEMS:
       dialog =
           new AlertDialog.Builder(this)
               .setTitle(R.string.delete)
               .setMessage(R.string.delete_selected_items)
               .setIconAttribute(android.R.attr.alertDialogIcon)
               .create();
       dialog.setButton(
           DialogInterface.BUTTON_NEGATIVE,
           getText(R.string.cancel),
           new DialogInterface.OnClickListener() {
             @Override
             public void onClick(DialogInterface dialog, int which) {
               mShowingDialog = false;
             }
           });
       dialog.setButton(
           DialogInterface.BUTTON_POSITIVE,
           getText(R.string.delete),
           new DialogInterface.OnClickListener() {
             @Override
             public void onClick(DialogInterface dialog, int which) {
               mTodosListAdapter.deleteSelectedItems();
               updateToEditNull();
               updateBottomBarWidgetState();
               mShowingDialog = false;
             }
           });
       dialog.setOnCancelListener(
           new DialogInterface.OnCancelListener() {
             public void onCancel(DialogInterface dialog) {
               mShowingDialog = false;
             }
           });
       return dialog;
     default:
       break;
   }
   return super.onCreateDialog(id);
 }
示例#4
0
 @Override
 public boolean onContextMenuClick(
     final ArrayAdapter<?> adapter, int itemId, final int pos, boolean isChecked) {
   final OsmandSettings settings = ma.getMyApplication().getSettings();
   if (itemId == R.string.layer_poi) {
     settings.SELECTED_POI_FILTER_FOR_MAP.set(null);
     if (isChecked) {
       selectPOILayer(settings);
     }
   } else if (itemId == R.string.layer_amenity_label) {
     settings.SHOW_POI_LABEL.set(isChecked);
   } else if (itemId == R.string.shared_string_favorites) {
     settings.SHOW_FAVORITES.set(isChecked);
   } else if (itemId == R.string.layer_gpx_layer) {
     if (ma.getMyApplication().getSelectedGpxHelper().isShowingAnyGpxFiles()) {
       ma.getMyApplication().getSelectedGpxHelper().clearAllGpxFileToShow();
     } else {
       AlertDialog dialog =
           ma.getMapLayers().showGPXFileLayer(getAlreadySelectedGpx(), ma.getMapView());
       dialog.setOnCancelListener(
           new DialogInterface.OnCancelListener() {
             @Override
             public void onCancel(DialogInterface dialogInterface) {
               cm.setSelection(pos, 0);
               adapter.notifyDataSetChanged();
             }
           });
     }
   } else if (itemId == R.string.layer_map) {
     if (OsmandPlugin.getEnabledPlugin(OsmandRasterMapsPlugin.class) == null) {
       Intent intent = new Intent(ma, PluginActivity.class);
       intent.putExtra(PluginActivity.EXTRA_PLUGIN_ID, OsmandRasterMapsPlugin.ID);
       ma.startActivity(intent);
     } else {
       ma.getMapLayers().selectMapLayer(ma.getMapView());
     }
   } else if (itemId == R.string.layer_transport_route) {
     ma.getMapLayers().getTransportInfoLayer().setVisible(isChecked);
   }
   ma.getMapLayers().updateLayers(ma.getMapView());
   ma.getMapView().refreshMap();
   return false;
 }
示例#5
0
 void dialogInit(String title) {
   ScrollView sv = new ScrollView(SGTPuzzles.this);
   dialog = new AlertDialog.Builder(SGTPuzzles.this).setTitle(title).setView(sv).create();
   sv.addView(dialogLayout = new TableLayout(SGTPuzzles.this));
   dialog.setOnCancelListener(
       new OnCancelListener() {
         public void onCancel(DialogInterface dialog) {
           configCancel();
         }
       });
   dialog.setButton(
       DialogInterface.BUTTON_POSITIVE,
       getString(android.R.string.ok),
       new DialogInterface.OnClickListener() {
         public void onClick(DialogInterface d, int which) {
           for (Integer i : dialogIds) {
             View v = dialogLayout.findViewById(i);
             if (v instanceof EditText) {
               configSetString(i, ((EditText) v).getText().toString());
             } else if (v instanceof CheckBox) {
               configSetBool(i, ((CheckBox) v).isChecked() ? 1 : 0);
             } else if (v instanceof Spinner) {
               configSetChoice(i, ((Spinner) v).getSelectedItemPosition());
             }
           }
           dialog.dismiss();
           showProgress(R.string.starting_custom);
           gameView.clear();
           (worker =
                   new Thread("startCustomGame") {
                     public void run() {
                       configOK();
                       handler.sendEmptyMessage(MsgType.DONE.ordinal());
                     }
                   })
               .start();
         }
       });
   dialogIds = new ArrayList<Integer>();
 }
示例#6
0
  public void showProgressDialog(boolean canclelable) {
    if ((getActivity() == null) || (getActivity().isFinishing())) return;

    if (mProgressDialog == null) {
      mProgressDialog =
          new AlertDialog.Builder(mContext, R.style.dialog_progress_transparent).create();
      mProgressDialog.setCancelable(canclelable);
      mProgressDialog.setCanceledOnTouchOutside(false);
      mProgressDialog.setOnCancelListener(
          new DialogInterface.OnCancelListener() {
            @Override
            public void onCancel(DialogInterface dialog) {
              if (ivLoading != null) ivLoading.clearAnimation();
              //                    getAnimationDrawable(mProgressImageView).stop();
            }
          });
      mProgressDialog.setOnDismissListener(
          new DialogInterface.OnDismissListener() {
            @Override
            public void onDismiss(DialogInterface dialog) {
              if (ivLoading != null) ivLoading.clearAnimation();
              //                    getAnimationDrawable(mProgressImageView).stop();
            }
          });
      //            mProgressImageView = (ImageView)
      // mInflater.inflate(R.layout.layout_load_progress, null);
      llProgress = (LinearLayout) mInflater.inflate(R.layout.layout_loading, null);
      ivLoading = (ImageView) llProgress.findViewById(R.id.image_loading);
    }

    mProgressDialog.show();
    Window window = mProgressDialog.getWindow();
    window.setGravity(Gravity.CENTER);
    //        window.setAddView(mProgressImageView);
    window.setContentView(llProgress);
    int width = (int) (ScreenUtils.getScreenW(mContext) * 1 / 3f);
    window.setLayout(width, ViewGroup.LayoutParams.WRAP_CONTENT);
    ivLoading.startAnimation(AnimationUtils.loadAnimation(mContext, R.anim.rotating));
    //        getAnimationDrawable(mProgressImageView).start();
  }
  /**
   * Create menu
   *
   * @return
   */
  public Dialog createMenu(String menuItitle) {
    final AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity);
    builder.setTitle(menuItitle);
    builder.setAdapter(
        menuAdapter,
        new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface dialoginterface, int i) {
            IconContextMenuItem item = (IconContextMenuItem) menuAdapter.getItem(i);

            if (clickHandler != null) {
              clickHandler.onClick(item.actionTag);
            }
          }
        });

    builder.setInverseBackgroundForced(true);

    AlertDialog dialog = builder.create();
    dialog.setOnCancelListener(this);
    dialog.setOnDismissListener(this);
    return dialog;
  }
  @Override
  public void show() {
    LayoutInflater inflater =
        (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View view = inflater.inflate(R.layout.device_dialog_abs, null);

    mProgressContainer = view.findViewById(R.id.progress_container);
    mProgressContainer.setVisibility(View.GONE);

    ViewGroup contentView = (ViewGroup) view.findViewById(R.id.device_dialog_content);
    contentView.addView(getContentView(inflater));

    mDialog =
        new AlertDialog.Builder(mContext)
            .setTitle(mDevice.getName())
            .setView(view)
            .setNegativeButton(R.string.esp_sss_device_dialog_exit, null)
            .show();
    mDialog.setOnDismissListener(this);
    mDialog.setCanceledOnTouchOutside(false);
    mDialog.setOnCancelListener(this);

    new StatusTask().execute();
  }
  private void handleLogin() {
    final String otpCode = otpCodeText.getText().toString();

    final AlertDialog dialog =
        LightProgressDialog.create(this, R.string.login_activity_authenticating);
    dialog.setCancelable(true);
    dialog.setOnCancelListener(
        new OnCancelListener() {

          @Override
          public void onCancel(DialogInterface dialog) {
            if (authenticationTask != null) authenticationTask.cancel(true);
          }
        });
    dialog.show();

    authenticationTask =
        new RoboAsyncTask<User>(this) {

          @Override
          public User call() throws Exception {
            TwoFactorAuthClient client = new TwoFactorAuthClient();
            client.setCredentials(username, password);
            client.setOtpCode(otpCode);

            OAuthService service = new OAuthService(client);
            String authToken = AccountAuthenticator.getAuthorization(service);
            if (authToken == null) authToken = AccountAuthenticator.createAuthorization(service);
            client.setOAuth2Token(authToken);

            User user = new UserService(client).getUser();
            Account account = new Account(user.getLogin(), ACCOUNT_TYPE);
            accountManager.addAccountExplicitly(account, password, null);
            accountManager.setAuthToken(account, ACCOUNT_TYPE, authToken);

            configureSyncFor(account);
            try {
              new LoginActivity.AccountLoader(TwoFactorAuthActivity.this).call();
            } catch (IOException e) {
              Log.d(TAG, "Exception loading organizations", e);
            }

            return user;
          }

          @Override
          protected void onException(Exception e) throws RuntimeException {
            dialog.dismiss();

            Log.d(TAG, "Exception requesting handling two-factor authentication", e);
            setResult(RESULT_CANCELED, new Intent().putExtra(PARAM_EXCEPTION, e));
            finish();
          }

          @Override
          public void onSuccess(User user) {
            dialog.dismiss();
            setResult(RESULT_OK);
            finish();
          }
        };
    authenticationTask.execute();
  }
  @Override
  public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
    if (preference.getKey().equals(KEY_FIRMWARE_VERSION)) {
      System.arraycopy(mHits, 1, mHits, 0, mHits.length - 1);
      mHits[mHits.length - 1] = SystemClock.uptimeMillis();
      if (mHits[0] >= (SystemClock.uptimeMillis() - 500)) {
        Intent intent = new Intent(Intent.ACTION_MAIN);
        intent.setClassName("android", com.android.internal.app.PlatLogoActivity.class.getName());
        try {
          startActivity(intent);
        } catch (Exception e) {
          Log.e(LOG_TAG, "Unable to start activity " + intent.toString());
        }
      }
    } else if (preference.getKey().equals(KEY_BUILD_NUMBER)) {
      // Don't enable developer options for secondary users.
      if (UserHandle.myUserId() != UserHandle.USER_OWNER) return true;

      if (mDevHitCountdown > 0) {
        mDevHitCountdown--;
        if (mDevHitCountdown == 0) {
          getActivity()
              .getSharedPreferences(DevelopmentSettings.PREF_FILE, Context.MODE_PRIVATE)
              .edit()
              .putBoolean(DevelopmentSettings.PREF_SHOW, true)
              .apply();
          if (mDevHitToast != null) {
            mDevHitToast.cancel();
          }
          mDevHitToast = Toast.makeText(getActivity(), R.string.show_dev_on, Toast.LENGTH_LONG);
          mDevHitToast.show();
        } else if (mDevHitCountdown > 0 && mDevHitCountdown < (TAPS_TO_BE_A_DEVELOPER - 2)) {
          if (mDevHitToast != null) {
            mDevHitToast.cancel();
          }
          mDevHitToast =
              Toast.makeText(
                  getActivity(),
                  getResources()
                      .getQuantityString(
                          R.plurals.show_dev_countdown, mDevHitCountdown, mDevHitCountdown),
                  Toast.LENGTH_SHORT);
          mDevHitToast.show();
        }
      } else if (mDevHitCountdown < 0) {
        if (mDevHitToast != null) {
          mDevHitToast.cancel();
        }
        mDevHitToast = Toast.makeText(getActivity(), R.string.show_dev_already, Toast.LENGTH_LONG);
        mDevHitToast.show();
      }
    } else if (preference.getKey().equals(KEY_MOD_VERSION)) {
      System.arraycopy(mHits, 1, mHits, 0, mHits.length - 1);
      mHits[mHits.length - 1] = SystemClock.uptimeMillis();
      if (mHits[0] >= (SystemClock.uptimeMillis() - 500)) {
        Intent intent = new Intent(Intent.ACTION_MAIN);
        intent.putExtra("is_cid", true);
        intent.setClassName("android", com.android.internal.app.PlatLogoActivity.class.getName());
        try {
          startActivity(intent);
        } catch (Exception e) {
          Log.e(LOG_TAG, "Unable to start activity " + intent.toString());
        }
      }
    } else if (preference.getKey().equals(KEY_SELINUX_STATUS)) {
      System.arraycopy(mHits, 1, mHits, 0, mHits.length - 1);
      mHits[mHits.length - 1] = SystemClock.uptimeMillis();
      if (mHits[0] >= (SystemClock.uptimeMillis() - 500)) {
        if (SELinux.isSELinuxEnabled()) {
          if (!SELinux.isSELinuxEnforced()) {
            /* Display the warning dialog */
            AlertDialog alertDialog = new AlertDialog.Builder(getActivity()).create();
            alertDialog.setTitle(R.string.selinux_enable_title);
            alertDialog.setMessage(getResources().getString(R.string.selinux_enable_warning));
            alertDialog.setButton(
                DialogInterface.BUTTON_POSITIVE,
                getResources().getString(com.android.internal.R.string.ok),
                new DialogInterface.OnClickListener() {
                  public void onClick(DialogInterface dialog, int which) {
                    SELinux.setSELinuxEnforce(true);
                    String status = getResources().getString(R.string.selinux_status_enforcing);
                    setStringSummary(KEY_SELINUX_STATUS, status);
                  }
                });
            alertDialog.setButton(
                DialogInterface.BUTTON_NEGATIVE,
                getResources().getString(com.android.internal.R.string.cancel),
                new DialogInterface.OnClickListener() {
                  public void onClick(DialogInterface dialog, int which) {}
                });
            alertDialog.setOnCancelListener(
                new DialogInterface.OnCancelListener() {
                  public void onCancel(DialogInterface dialog) {}
                });
            alertDialog.show();

          } else {
            SELinux.setSELinuxEnforce(false);
          }
        }

        if (!SELinux.isSELinuxEnabled()) {
          String status = getResources().getString(R.string.selinux_status_disabled);
          setStringSummary(KEY_SELINUX_STATUS, status);
        } else if (!SELinux.isSELinuxEnforced()) {
          String status = getResources().getString(R.string.selinux_status_permissive);
          setStringSummary(KEY_SELINUX_STATUS, status);
        } else if (SELinux.isSELinuxEnforced()) {
          String status = getResources().getString(R.string.selinux_status_enforcing);
          setStringSummary(KEY_SELINUX_STATUS, status);
        }
      }
    }
    return super.onPreferenceTreeClick(preferenceScreen, preference);
  }
  @ReactMethod
  public void showImagePicker(final ReadableMap options, final Callback callback) {
    List<String> mTitles = new ArrayList<String>();
    List<String> mActions = new ArrayList<String>();

    String cancelButtonTitle = "Cancel";

    if (options.hasKey("takePhotoButtonTitle")
        && !options.getString("takePhotoButtonTitle").isEmpty()) {
      mTitles.add(options.getString("takePhotoButtonTitle"));
      mActions.add("photo");
    }
    if (options.hasKey("chooseFromLibraryButtonTitle")
        && !options.getString("chooseFromLibraryButtonTitle").isEmpty()) {
      mTitles.add(options.getString("chooseFromLibraryButtonTitle"));
      mActions.add("library");
    }
    if (options.hasKey("cancelButtonTitle") && !options.getString("cancelButtonTitle").isEmpty()) {
      cancelButtonTitle = options.getString("cancelButtonTitle");
    }
    mTitles.add(cancelButtonTitle);
    mActions.add("cancel");

    String[] option = new String[mTitles.size()];
    option = mTitles.toArray(option);

    String[] action = new String[mActions.size()];
    action = mActions.toArray(action);
    final String[] act = action;

    ArrayAdapter<String> adapter =
        new ArrayAdapter<String>(mMainActivity, android.R.layout.select_dialog_item, option);
    AlertDialog.Builder builder = new AlertDialog.Builder(mMainActivity);
    if (options.hasKey("title") && !options.getString("title").isEmpty()) {
      builder.setTitle(options.getString("title"));
    }

    builder.setAdapter(
        adapter,
        new DialogInterface.OnClickListener() {
          public void onClick(DialogInterface dialog, int index) {
            if (act[index].equals("photo")) {
              launchCamera(options, callback);
            } else if (act[index].equals("library")) {
              launchImageLibrary(options, callback);
            } else {
              callback.invoke(true, Arguments.createMap());
            }
          }
        });

    final AlertDialog dialog = builder.create();
    /**
     * override onCancel method to callback cancel in case of a touch outside of the dialog or the
     * BACK key pressed
     */
    dialog.setOnCancelListener(
        new DialogInterface.OnCancelListener() {
          @Override
          public void onCancel(DialogInterface dialog) {
            dialog.dismiss();
            callback.invoke(true, Arguments.createMap());
          }
        });
    dialog.show();
  }
  /**
   * Gets the result of all actions on a button. If a victory or defeat the players statistics are
   * updated
   *
   * @param result an integer sent from the Box specifying hit result
   */
  public void getResult(int result) {
    boolean good = true;
    switch (result) {
      case 0:
        for (int i = 0; i < this.x; ++i) {
          for (int j = 0; j < this.y; ++j) {
            this.board[i][j].setClickable(false);
          }
        }
        good = false;

        if (this.x == Constants.begRowDefault
            && this.y == Constants.begColDefault
            && this.mines == Constants.begMineDefault) {
          int score = this.prefs.getInt("begLosses", 0);
          Editor editor = this.prefs.edit();
          editor.putInt("begLosses", ++score);
          editor.commit();
        } else if (this.x == Constants.medRowDefault
            && this.y == Constants.medColDefault
            && this.mines == Constants.medMineDefault) {
          int score = this.prefs.getInt("medLosses", 0);
          Editor editor = this.prefs.edit();
          editor.putInt("medLosses", ++score);
          editor.commit();
        } else if (this.x == Constants.hardRowDefault
            && this.y == Constants.hardColDefault
            && this.mines == Constants.hardMineDefault) {
          int score = this.prefs.getInt("hardLosses", 0);
          Editor editor = this.prefs.edit();
          editor.putInt("hardLosses", ++score);
          editor.commit();
        }

        AlertDialog.Builder builder = new AlertDialog.Builder(this.context);
        builder.setMessage("You have Died!");
        builder.setPositiveButton(
            R.string.newgame,
            new DialogInterface.OnClickListener() {
              public void onClick(DialogInterface dialog, int id) {
                context.newGameMenu(false);
              }
            });
        final ImageButton flagB = (ImageButton) this.context.findViewById(R.id.flagButton);
        builder.setNegativeButton(
            R.string.cancel,
            new DialogInterface.OnClickListener() {
              public void onClick(DialogInterface dialog, int id) {
                flagB.setImageDrawable(context.getResources().getDrawable(R.drawable.smile));
                context.flagMode = 2;
              }
            });
        AlertDialog dialog = builder.create();
        dialog.setCanceledOnTouchOutside(false);
        dialog.setOnCancelListener(
            new OnCancelListener() {

              @Override
              public void onCancel(DialogInterface dialog) {
                flagB.setImageDrawable(context.getResources().getDrawable(R.drawable.smile));
                context.flagMode = 2;
              }
            });
        dialog.show();

        this.showResults();

        this.isGoing = false;
        this.context.timer.stop();

        break;
      case 2:
        System.out.println("You have already flagged that!");
        break;
      case 3:
        System.out.println("You already hit that!");
        break;
      case 4:
        System.out.println("Invalid Input!");
        break;
      default:
        break;
    }

    if ((this.getX() * this.getY()) - this.getBoxesFilled() - this.getMines() <= 0
        && good != false) {
      for (int i = 0; i < this.x; ++i) {
        for (int j = 0; j < this.y; ++j) {
          this.board[i][j].setClickable(false);
        }
      }

      // long time = SystemClock.elapsedRealtime() - this.context.timer.getBase();
      // time /= 1000;
      int time = this.context.seconds;

      if (this.x == Constants.begRowDefault
          && this.y == Constants.begColDefault
          && this.mines == Constants.begMineDefault) {
        int score = this.prefs.getInt("begWins", 0);
        int prevTime = this.prefs.getInt("begTime", 0);
        time = time < prevTime || prevTime == 0 ? time : prevTime;
        Editor editor = this.prefs.edit();
        editor.putInt("begWins", ++score);
        editor.putInt("begTime", time);
        editor.commit();
      } else if (this.x == Constants.medRowDefault
          && this.y == Constants.medColDefault
          && this.mines == Constants.medMineDefault) {
        int score = this.prefs.getInt("medWins", 0);
        int prevTime = this.prefs.getInt("medTime", 0);
        time = time < prevTime || prevTime == 0 ? time : prevTime;
        Editor editor = this.prefs.edit();
        editor.putInt("medWins", ++score);
        editor.putInt("medTime", time);
        editor.commit();
      } else if (this.x == Constants.hardRowDefault
          && this.y == Constants.hardColDefault
          && this.mines == Constants.hardMineDefault) {
        int score = this.prefs.getInt("hardWins", 0);
        int prevTime = this.prefs.getInt("hardTime", 0);
        time = time < prevTime || prevTime == 0 ? time : prevTime;
        Editor editor = this.prefs.edit();
        editor.putInt("hardWins", ++score);
        editor.putInt("hardTime", time);
        editor.commit();
      }

      AlertDialog.Builder builder = new AlertDialog.Builder(this.context);
      builder.setMessage("You have WON!");
      builder.setPositiveButton(
          R.string.newgame,
          new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
              context.newGameMenu(false);
            }
          });
      final ImageButton flagB = (ImageButton) this.context.findViewById(R.id.flagButton);
      builder.setNegativeButton(
          R.string.cancel,
          new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
              flagB.setImageDrawable(context.getResources().getDrawable(R.drawable.smile));
              context.flagMode = 2;
            }
          });
      AlertDialog dialog = builder.create();
      dialog.setCanceledOnTouchOutside(false);
      dialog.setOnCancelListener(
          new OnCancelListener() {

            @Override
            public void onCancel(DialogInterface dialog) {
              flagB.setImageDrawable(context.getResources().getDrawable(R.drawable.smile));
              context.flagMode = 2;
            }
          });
      dialog.show();

      this.isGoing = false;
      this.context.timer.stop();
    }
  }
示例#13
0
  /** Prompts the user to enter a PIN. */
  @CalledByNative
  private static void displayAuthenticationPrompt(boolean pairingSupported) {
    AlertDialog.Builder pinPrompt = new AlertDialog.Builder(sContext);
    pinPrompt.setTitle(sContext.getString(R.string.pin_entry_title));
    pinPrompt.setMessage(sContext.getString(R.string.pin_entry_message));
    pinPrompt.setIcon(android.R.drawable.ic_lock_lock);

    final View pinEntry = sContext.getLayoutInflater().inflate(R.layout.pin_dialog, null);
    pinPrompt.setView(pinEntry);

    final TextView pinTextView = (TextView) pinEntry.findViewById(R.id.pin_dialog_text);
    final CheckBox pinCheckBox = (CheckBox) pinEntry.findViewById(R.id.pin_dialog_check);

    if (!pairingSupported) {
      pinCheckBox.setChecked(false);
      pinCheckBox.setVisibility(View.GONE);
    }

    pinPrompt.setPositiveButton(
        R.string.pin_entry_connect,
        new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface dialog, int which) {
            Log.i("jniiface", "User provided a PIN code");
            nativeAuthenticationResponse(
                String.valueOf(pinTextView.getText()), pinCheckBox.isChecked());
          }
        });

    pinPrompt.setNegativeButton(
        R.string.pin_entry_cancel,
        new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface dialog, int which) {
            Log.i("jniiface", "User canceled pin entry prompt");
            Toast.makeText(
                    sContext, sContext.getString(R.string.msg_pin_canceled), Toast.LENGTH_LONG)
                .show();
            disconnectFromHost();
          }
        });

    final AlertDialog pinDialog = pinPrompt.create();

    pinTextView.setOnEditorActionListener(
        new TextView.OnEditorActionListener() {
          @Override
          public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            // The user pressed enter on the keypad (equivalent to the connect button).
            pinDialog.getButton(AlertDialog.BUTTON_POSITIVE).performClick();
            pinDialog.dismiss();
            return true;
          }
        });

    pinDialog.setOnCancelListener(
        new DialogInterface.OnCancelListener() {
          @Override
          public void onCancel(DialogInterface dialog) {
            // The user backed out of the dialog (equivalent to the cancel button).
            pinDialog.getButton(AlertDialog.BUTTON_NEGATIVE).performClick();
          }
        });

    pinDialog.show();
  }
示例#14
0
  public void show(
      String aTitle, String aText, PromptListItem[] aMenuList, boolean aMultipleSelection) {
    ThreadUtils.assertOnUiThread();

    // treat actions that show a dialog as if preventDefault by content to prevent panning
    GeckoApp.mAppContext.getLayerView().abortPanning();

    AlertDialog.Builder builder = new AlertDialog.Builder(GeckoApp.mAppContext);
    if (!TextUtils.isEmpty(aTitle)) {
      builder.setTitle(aTitle);
    }

    if (!TextUtils.isEmpty(aText)) {
      builder.setMessage(aText);
    }

    int length = mInputs == null ? 0 : mInputs.length;
    if (aMenuList != null && aMenuList.length > 0) {
      int resourceId = android.R.layout.simple_list_item_1;
      if (mSelected != null && mSelected.length > 0) {
        if (aMultipleSelection) {
          resourceId = R.layout.select_dialog_multichoice;
        } else {
          resourceId = R.layout.select_dialog_singlechoice;
        }
      }
      PromptListAdapter adapter =
          new PromptListAdapter(GeckoApp.mAppContext, resourceId, aMenuList);
      if (mSelected != null && mSelected.length > 0) {
        if (aMultipleSelection) {
          adapter.listView = (ListView) mInflater.inflate(R.layout.select_dialog_list, null);
          adapter.listView.setOnItemClickListener(this);
          builder.setInverseBackgroundForced(true);
          adapter.listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
          adapter.listView.setAdapter(adapter);
          builder.setView(adapter.listView);
        } else {
          int selectedIndex = -1;
          for (int i = 0; i < mSelected.length; i++) {
            if (mSelected[i]) {
              selectedIndex = i;
              break;
            }
          }
          mSelected = null;
          builder.setSingleChoiceItems(adapter, selectedIndex, this);
        }
      } else {
        builder.setAdapter(adapter, this);
        mSelected = null;
      }
    } else if (length == 1) {
      try {
        ScrollView view = new ScrollView(GeckoApp.mAppContext);
        view.addView(mInputs[0].getView());
        builder.setView(applyInputStyle(view));
      } catch (UnsupportedOperationException ex) {
        // We cannot display these input widgets with this sdk version,
        // do not display any dialog and finish the prompt now.
        finishDialog("{\"button\": -1}");
        return;
      }
    } else if (length > 1) {
      try {
        LinearLayout linearLayout = new LinearLayout(GeckoApp.mAppContext);
        linearLayout.setOrientation(LinearLayout.VERTICAL);
        for (int i = 0; i < length; i++) {
          View content = mInputs[i].getView();
          linearLayout.addView(content);
        }
        ScrollView view = new ScrollView(GeckoApp.mAppContext);
        view.addView(linearLayout);
        builder.setView(applyInputStyle(view));
      } catch (UnsupportedOperationException ex) {
        // We cannot display these input widgets with this sdk version,
        // do not display any dialog and finish the prompt now.
        finishDialog("{\"button\": -1}");
        return;
      }
    }

    length = mButtons == null ? 0 : mButtons.length;
    if (length > 0) {
      builder.setPositiveButton(mButtons[0], this);
      if (length > 1) {
        builder.setNeutralButton(mButtons[1], this);
        if (length > 2) {
          builder.setNegativeButton(mButtons[2], this);
        }
      }
    }

    mDialog = builder.create();
    mDialog.setOnCancelListener(PromptService.this);
    mDialog.show();
  }
示例#15
0
  /**
   * Creates the new game menu screen with buttons to increase and decrease the numbers. It starts
   * the new game and it's timer
   *
   * @param onStart specifies if being called when game is going (true) or on boot (false)
   */
  @SuppressWarnings("ConstantConditions")
  public void newGameMenu(boolean onStart) {
    LayoutInflater factory = LayoutInflater.from(this);
    View newGameView = factory.inflate(R.layout.newgamemenu, null);
    AlertDialog.Builder alert = new AlertDialog.Builder(this);
    alert.setTitle("New Game");
    alert.setView(newGameView);

    Button begButton = (Button) newGameView.findViewById(R.id.begButton);
    Button medButton = (Button) newGameView.findViewById(R.id.medButton);
    Button hardButton = (Button) newGameView.findViewById(R.id.hardButton);

    Button rowAdd = (Button) newGameView.findViewById(R.id.rowsAdd);
    final TextView numRows = (TextView) newGameView.findViewById(R.id.numRows);
    Button rowSub = (Button) newGameView.findViewById(R.id.rowsSub);

    Button colAdd = (Button) newGameView.findViewById(R.id.colsAdd);
    final TextView numCols = (TextView) newGameView.findViewById(R.id.numCols);
    Button colSub = (Button) newGameView.findViewById(R.id.colsSub);

    Button mineAdd = (Button) newGameView.findViewById(R.id.minesAdd);
    final TextView numMines = (TextView) newGameView.findViewById(R.id.numMines);
    Button mineSub = (Button) newGameView.findViewById(R.id.minesSub);

    int lastRows = this.prefs.getInt("lastRows", Constants.BEGINNER.getRows());
    int lastCols = this.prefs.getInt("lastCols", Constants.BEGINNER.getCols());
    int lastMines = this.prefs.getInt("lastMines", Constants.BEGINNER.getMines());
    numRows.setText(Integer.toString(lastRows));
    numCols.setText(Integer.toString(lastCols));
    numMines.setText(Integer.toString(lastMines));

    begButton.setOnClickListener(
        new View.OnClickListener() {
          public void onClick(View v) {
            numRows.setText(Integer.toString(Constants.BEGINNER.getRows()));
            numCols.setText(Integer.toString(Constants.BEGINNER.getCols()));
            numMines.setText(Integer.toString(Constants.BEGINNER.getMines()));
          }
        });
    medButton.setOnClickListener(
        new View.OnClickListener() {
          public void onClick(View v) {
            numRows.setText(Integer.toString(Constants.MEDIUM.getRows()));
            numCols.setText(Integer.toString(Constants.MEDIUM.getCols()));
            numMines.setText(Integer.toString(Constants.MEDIUM.getMines()));
          }
        });
    hardButton.setOnClickListener(
        new View.OnClickListener() {
          public void onClick(View v) {
            numRows.setText(Integer.toString(Constants.HARD.getRows()));
            numCols.setText(Integer.toString(Constants.HARD.getCols()));
            numMines.setText(Integer.toString(Constants.HARD.getMines()));
          }
        });

    rowAdd.setOnClickListener(
        new View.OnClickListener() {
          public void onClick(View v) {
            int rows = Integer.parseInt(numRows.getText().toString()) + 1;
            numRows.setText(Integer.toString(rows));
          }
        });
    rowSub.setOnClickListener(
        new View.OnClickListener() {
          public void onClick(View v) {
            int rows = Integer.parseInt(numRows.getText().toString()) - 1;
            if (rows < 1) {
              rows = 1;
            }
            numRows.setText(Integer.toString(rows));
            int cols = Integer.parseInt(numCols.getText().toString());
            int mines = Integer.parseInt(numMines.getText().toString());
            if (mines > ((rows * cols) - 1)) {
              numMines.setText(Integer.toString(((rows * cols) - 1)));
            }
          }
        });

    colAdd.setOnClickListener(
        new View.OnClickListener() {
          public void onClick(View v) {
            int cols = Integer.parseInt(numCols.getText().toString()) + 1;
            numCols.setText(Integer.toString(cols));
          }
        });
    colSub.setOnClickListener(
        new View.OnClickListener() {
          public void onClick(View v) {
            int cols = Integer.parseInt(numCols.getText().toString()) - 1;
            if (cols < 1) {
              cols = 1;
            }
            numCols.setText(Integer.toString(cols));
            int rows = Integer.parseInt(numRows.getText().toString());
            int mines = Integer.parseInt(numMines.getText().toString());
            if (mines > ((rows * cols) - 1)) {
              numMines.setText(Integer.toString(((rows * cols) - 1)));
            }
          }
        });

    mineAdd.setOnClickListener(
        new View.OnClickListener() {
          public void onClick(View v) {
            int mines = Integer.parseInt(numMines.getText().toString()) + 1;
            int rows = Integer.parseInt(numRows.getText().toString());
            int cols = Integer.parseInt(numCols.getText().toString());
            if (mines > ((rows * cols) - 1)) {
              mines = (rows * cols) - 1;
            }
            numMines.setText(Integer.toString(mines));
          }
        });
    mineSub.setOnClickListener(
        new View.OnClickListener() {
          public void onClick(View v) {
            int mines = Integer.parseInt(numMines.getText().toString()) - 1;
            if (mines < 1) {
              mines = 1;
            }
            numMines.setText(Integer.toString(mines));
          }
        });

    final MainActivity myContext = this;
    alert.setPositiveButton(
        R.string.start,
        new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface dialog, int whichButton) {
            if (minesweeperGame != null) {
              if (minesweeperGame.gameMode != Minesweeper.ENDMODE) {
                gameFinished(false);
              }
              minesweeperGame.clearOldGame();
            }
            int mines = Integer.parseInt(numMines.getText().toString());
            int rows = Integer.parseInt(numRows.getText().toString());
            int cols = Integer.parseInt(numCols.getText().toString());
            SharedPreferences.Editor editor = prefs.edit();
            editor.putInt("lastRows", rows);
            editor.putInt("lastCols", cols);
            editor.putInt("lastMines", mines);
            editor.commit();
            minesweeperGame = new Minesweeper(myContext, rows, cols, mines);
          }
        });

    final ImageButton flagButton = (ImageButton) findViewById(R.id.flagButton);

    AlertDialog dialog = null;
    if (!onStart) {
      alert.setNegativeButton(
          R.string.cancel,
          new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
              dialog.cancel();
            }
          });
      dialog = alert.create();
      dialog.setCanceledOnTouchOutside(false);
      dialog.setOnCancelListener(
          new DialogInterface.OnCancelListener() {

            @Override
            public void onCancel(DialogInterface dialog) {
              if (minesweeperGame != null && minesweeperGame.gameMode != Minesweeper.ENDMODE) {
                if (seconds > 0) {
                  timer.start();
                }
              } else {
                minesweeperGame.gameMode = Minesweeper.ENDMODE;
                flagButton.setImageDrawable(getResources().getDrawable(R.drawable.smile));
              }
            }
          });
    }

    if (dialog == null) {
      dialog = alert.create();
      dialog.setCancelable(false);
    }
    dialog.show();
    timer.stop();
  }
  public void show(
      String aTitle,
      String aText,
      PromptButton[] aButtons,
      PromptListItem[] aMenuList,
      boolean aMultipleSelection) {
    final GeckoLayerClient layerClient = GeckoApp.mAppContext.getLayerClient();
    layerClient.post(
        new Runnable() {
          public void run() {
            // treat actions that show a dialog as if preventDefault by content to prevent panning
            layerClient.getPanZoomController().abortPanning();
          }
        });

    AlertDialog.Builder builder = new AlertDialog.Builder(GeckoApp.mAppContext);
    if (!aTitle.equals("")) {
      builder.setTitle(aTitle);
    }

    if (!aText.equals("")) {
      builder.setMessage(aText);
    }

    int length = mInputs == null ? 0 : mInputs.length;
    if (aMenuList != null && aMenuList.length > 0) {
      int resourceId = android.R.layout.select_dialog_item;
      if (mSelected != null && mSelected.length > 0) {
        if (aMultipleSelection) {
          resourceId = android.R.layout.select_dialog_multichoice;
        } else {
          resourceId = android.R.layout.select_dialog_singlechoice;
        }
      }
      PromptListAdapter adapter =
          new PromptListAdapter(GeckoApp.mAppContext, resourceId, aMenuList);
      if (mSelected != null && mSelected.length > 0) {
        if (aMultipleSelection) {
          adapter.listView = (ListView) mInflater.inflate(R.layout.select_dialog_list, null);
          adapter.listView.setOnItemClickListener(this);
          builder.setInverseBackgroundForced(true);
          adapter.listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
          adapter.listView.setAdapter(adapter);
          builder.setView(adapter.listView);
        } else {
          int selectedIndex = -1;
          for (int i = 0; i < mSelected.length; i++) {
            if (mSelected[i]) {
              selectedIndex = i;
              break;
            }
          }
          mSelected = null;
          builder.setSingleChoiceItems(adapter, selectedIndex, this);
        }
      } else {
        builder.setAdapter(adapter, this);
        mSelected = null;
      }
    } else if (length == 1) {
      builder.setView(mInputs[0].getView());
    } else if (length > 1) {
      LinearLayout linearLayout = new LinearLayout(GeckoApp.mAppContext);
      linearLayout.setOrientation(LinearLayout.VERTICAL);
      for (int i = 0; i < length; i++) {
        View content = mInputs[i].getView();
        linearLayout.addView(content);
      }
      builder.setView((View) linearLayout);
    }

    length = aButtons == null ? 0 : aButtons.length;
    if (length > 0) {
      builder.setPositiveButton(aButtons[0].label, this);
    }
    if (length > 1) {
      builder.setNeutralButton(aButtons[1].label, this);
    }
    if (length > 2) {
      builder.setNegativeButton(aButtons[2].label, this);
    }

    mDialog = builder.create();
    mDialog.setOnCancelListener(this);
    mDialog.show();
  }
示例#17
0
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

    mAlertBuilder = new AlertDialog.Builder(this);
    gAlertBuilder = mAlertBuilder; //  keep a static copy of this that other classes can use

    if (core == null) {
      core = (MuPDFCore) getLastNonConfigurationInstance();

      if (savedInstanceState != null && savedInstanceState.containsKey("FileName")) {
        mFileName = savedInstanceState.getString("FileName");
      }
    }
    if (core == null) {
      Intent intent = getIntent();
      byte buffer[] = null;

      if (Intent.ACTION_VIEW.equals(intent.getAction())) {
        Uri uri = intent.getData();
        System.out.println("URI to open is: " + uri);
        if (uri.toString().startsWith("content://")) {
          String reason = null;
          try {
            InputStream is = getContentResolver().openInputStream(uri);
            int len = is.available();
            buffer = new byte[len];
            is.read(buffer, 0, len);
            is.close();
          } catch (java.lang.OutOfMemoryError e) {
            System.out.println("Out of memory during buffer reading");
            reason = e.toString();
          } catch (Exception e) {
            System.out.println("Exception reading from stream: " + e);

            // Handle view requests from the Transformer Prime's file manager
            // Hopefully other file managers will use this same scheme, if not
            // using explicit paths.
            // I'm hoping that this case below is no longer needed...but it's
            // hard to test as the file manager seems to have changed in 4.x.
            try {
              Cursor cursor =
                  getContentResolver().query(uri, new String[] {"_data"}, null, null, null);
              if (cursor.moveToFirst()) {
                String str = cursor.getString(0);
                if (str == null) {
                  reason = "Couldn't parse data in intent";
                } else {
                  uri = Uri.parse(str);
                }
              }
            } catch (Exception e2) {
              System.out.println("Exception in Transformer Prime file manager code: " + e2);
              reason = e2.toString();
            }
          }
          if (reason != null) {
            buffer = null;
            Resources res = getResources();
            AlertDialog alert = mAlertBuilder.create();
            setTitle(String.format(res.getString(R.string.cannot_open_document_Reason), reason));
            alert.setButton(
                AlertDialog.BUTTON_POSITIVE,
                getString(R.string.dismiss),
                new DialogInterface.OnClickListener() {
                  public void onClick(DialogInterface dialog, int which) {
                    finish();
                  }
                });
            alert.show();
            return;
          }
        }
        if (buffer != null) {
          core = openBuffer(buffer, intent.getType());
        } else {
          String path = Uri.decode(uri.getEncodedPath());
          if (path == null) {
            path = uri.toString();
          }
          core = openFile(path);
        }
        SearchTaskResult.set(null);
      }
      if (core != null && core.needsPassword()) {
        requestPassword(savedInstanceState);
        return;
      }
      if (core != null && core.countPages() == 0) {
        core = null;
      }
    }
    if (core == null) {
      AlertDialog alert = mAlertBuilder.create();
      alert.setTitle(R.string.cannot_open_document);
      alert.setButton(
          AlertDialog.BUTTON_POSITIVE,
          getString(R.string.dismiss),
          new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
              finish();
            }
          });
      alert.setOnCancelListener(
          new OnCancelListener() {

            @Override
            public void onCancel(DialogInterface dialog) {
              finish();
            }
          });
      alert.show();
      return;
    }

    createUI(savedInstanceState);

    //  hide the proof button if this file can't be proofed
    if (!core.canProof()) {
      mProofButton.setVisibility(View.INVISIBLE);
    }

    if (isProofing()) {

      //  start the activity with a new array
      mSepEnabled = null;

      //  show the separations button
      mSepsButton.setVisibility(View.VISIBLE);

      //  hide some other buttons
      mLinkButton.setVisibility(View.INVISIBLE);
      mReflowButton.setVisibility(View.INVISIBLE);
      mOutlineButton.setVisibility(View.INVISIBLE);
      mSearchButton.setVisibility(View.INVISIBLE);
      mMoreButton.setVisibility(View.INVISIBLE);
    } else {
      //  hide the separations button
      mSepsButton.setVisibility(View.INVISIBLE);
    }
  }
 public DialogHelper setOnCancelListener(DialogInterface.OnCancelListener l) {
   if (mDialog != null) {
     mDialog.setOnCancelListener(l);
   }
   return this;
 }