Пример #1
0
  @Override
  public boolean onMenuItemSelected(int featureId, MenuItem item) {
    switch (item.getItemId()) {
      case R.id.menu_add_board:
        addBoard();
        return true;

      case R.id.menu_help:
        AlertDialog.Builder helpBuilder = new AlertDialog.Builder(this);
        helpBuilder.setTitle("Help");

        ScrollView scroll = new ScrollView(this);
        helpBuilder.setView(scroll);

        LinearLayout helpLayout = new LinearLayout(this);
        helpLayout.setOrientation(LinearLayout.VERTICAL);
        scroll.addView(helpLayout);

        TextView tv = new TextView(this);
        tv.setText(Html.fromHtml(getResources().getString(R.string.menu_help_text)));
        tv.setMovementMethod(LinkMovementMethod.getInstance());

        Button introductionButton = new Button(this);
        introductionButton.setText("Introduction");
        introductionButton.setOnClickListener(
            new OnClickListener() {
              public void onClick(View v) {
                Intent i = new Intent(SoundboardMenu.this, Introduction.class);
                startActivity(i);
              }
            });

        helpLayout.addView(introductionButton);
        helpLayout.addView(tv);

        AlertDialog helpAlert = helpBuilder.create();
        helpAlert.show();
        return true;

      case R.id.menu_about:
        AlertDialog.Builder aboutBuilder = new AlertDialog.Builder(this);
        aboutBuilder.setTitle("About");
        aboutBuilder.setMessage(
            "Boarder is an opensource project administrated by Mikael Lindlöf.\n\n"
                + "Source code is hosted to Github. You can view and contribute to it there.\n\n"
                + "I'd like to talk with you. You can email us to seek for help or say hello.\n\n"
                + "You should also post on XDA-forums to meet other soundboard loving people :)\n\n"
                + "Find Boarder wiki on Help Center. You are most welcome to explore and improve it.\n\n"
                + "You can find link to these medias in the same menu with About.");
        AlertDialog aboutAlert = aboutBuilder.create();
        aboutAlert.show();
        return true;

      case R.id.menu_play_pause:
        SoundPlayerControl.togglePlayPause(super.mContext);
        return true;

      case R.id.menu_internet:
        Intent i = new Intent(this, InternetMenu.class);
        startActivityForResult(i, 0);
        return true;

      case R.id.menu_dropbox:
        Intent iDrop = new Intent(this, DropboxMenu.class);
        startActivity(iDrop);
        return true;

      case R.id.menu_global_settings:
        LayoutInflater inflater =
            (LayoutInflater) SoundboardMenu.this.getSystemService(LAYOUT_INFLATER_SERVICE);
        View layout =
            inflater.inflate(
                R.layout.soundboard_menu_alert_global_settings,
                (ViewGroup) findViewById(R.id.alert_settings_root));

        final EditText fadeInInput = (EditText) layout.findViewById(R.id.fadeInInput);
        fadeInInput.setText(Integer.toString(GlobalSettings.getFadeInDuration()));

        final EditText fadeOutInput = (EditText) layout.findViewById(R.id.fadeOutInput);
        fadeOutInput.setText(Integer.toString(GlobalSettings.getFadeOutDuration()));

        final CheckBox sensitiveLoggingCheckbox =
            (CheckBox) layout.findViewById(R.id.sensitiveLoggingCheckbox);
        sensitiveLoggingCheckbox.setChecked(GlobalSettings.getSensitiveLogging());

        AlertDialog.Builder builder = new AlertDialog.Builder(SoundboardMenu.this);
        builder.setView(layout);
        builder.setTitle("Sound settings");

        builder.setPositiveButton(
            "Ok",
            new DialogInterface.OnClickListener() {
              public void onClick(DialogInterface dialog, int whichButton) {
                try {
                  int fadeIn = Integer.valueOf(fadeInInput.getText().toString()).intValue();
                  mGlobalVariableDbHelper.updateIntVariable(
                      GlobalVariablesDbAdapter.FADE_IN_DURATION_KEY, fadeIn);

                  int fadeOut = Integer.valueOf(fadeOutInput.getText().toString()).intValue();
                  mGlobalVariableDbHelper.updateIntVariable(
                      GlobalVariablesDbAdapter.FADE_OUT_DURATION_KEY, fadeOut);

                  mGlobalVariableDbHelper.updateBooleanVariable(
                      GlobalVariablesDbAdapter.SENSITIVE_LOGGING,
                      sensitiveLoggingCheckbox.isChecked());

                  loadGlobalSettings();
                } catch (NumberFormatException nfe) {
                  Toast.makeText(
                          SoundboardMenu.super.mContext, "Incorrect value", Toast.LENGTH_SHORT)
                      .show();
                }
              }
            });

        builder.setNegativeButton(
            "Cancel",
            new DialogInterface.OnClickListener() {
              public void onClick(DialogInterface dialog, int whichButton) {}
            });

        builder.show();
        return true;

      case R.id.menu_support_links:
        CharSequence[] pageItems = {"Email us", "Github", "Donate", "Rate"};

        AlertDialog.Builder pageBuilder = new AlertDialog.Builder(SoundboardMenu.this);
        pageBuilder.setTitle("Support & links");
        pageBuilder.setItems(
            pageItems,
            new DialogInterface.OnClickListener() {
              public void onClick(DialogInterface dialog, int item) {
                if (item == 0) { // Email us
                  ExternalIntent.openEmail(SoundboardMenu.super.mContext);

                } else if (item == 1) { // Github
                  ExternalIntent.openGithub(SoundboardMenu.super.mContext);

                } else if (item == 2) { // Donate
                  showDonateNotification();

                } else if (item == 3) { // Rate
                  ExternalIntent.openGooglePlay(SoundboardMenu.super.mContext);
                }
              }
            });
        pageBuilder.show();
        return true;
    }

    return super.onMenuItemSelected(featureId, item);
  }