Android Open Source - simpleplayer Dialog Utils






From Project

Back to project page simpleplayer.

License

The source code is released under:

GNU General Public License

If you think the Android project simpleplayer listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package org.sergez.splayer.util;
/*  w  w w. j a  v  a 2 s  .c om*/
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.text.TextUtils;
import com.actionbarsherlock.view.MenuItem;
import org.sergez.splayer.R;
import org.sergez.splayer.enums.RepeatState;
import org.sergez.splayer.enums.ShuffleState;
import org.sergez.splayer.service.SimplePlayerService;

import java.io.File;

import static org.sergez.splayer.util.Utils.makeToast;

/**
 * @author Sergii Zhuk
 *         Date: 16.03.14
 *         Time: 9:46
 */
public class DialogUtils {

  private static int dialogRepeatSelectedItem = -1;

  private static int dialogShuffleSelectedItem = -1;

  // TODO : do not pass service here
  public static void showDialogRepeatChoice(final Context context, final SimplePlayerService playerService,
                                            final MenuItem menuItemRepeat) {

    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    CharSequence[] array = {RepeatState.NO_REPEAT.getLabel(), RepeatState.REPEAT_CURRENT_TRACK.getLabel(),
        RepeatState.REPEAT_ALL_FILES.getLabel()};

    builder.setTitle("Select repeat mode") // TODO const
        .setSingleChoiceItems(array, playerService.getRepeatState().ordinal(), new DialogInterface.OnClickListener() {

          @Override
          public void onClick(DialogInterface dialog, int which) {
            dialogRepeatSelectedItem = which;
          }
        })
        .setPositiveButton("OK", new DialogInterface.OnClickListener() { // TODO const
          @Override
          public void onClick(DialogInterface dialog, int id) {
            if (dialogRepeatSelectedItem > -1) {
              RepeatState selectedState = RepeatState.values()[dialogRepeatSelectedItem];
              playerService.setRepeatState(selectedState);
              menuItemRepeat.setTitle(context.getString(R.string.button_and_toast_repeat_first_part) + " " + selectedState.getLabel());
              makeToast(context, context.getString(R.string.button_and_toast_repeat_first_part) + " " + selectedState.getLabel());
              dialogRepeatSelectedItem = -1;
            }

          }
        })
        .setNegativeButton("Cancel", new DialogInterface.OnClickListener() {  // TODO const
          @Override
          public void onClick(DialogInterface dialog, int id) {
            // empty
          }
        });

    builder.create().show();
  }


  public static void showDialogShuffleChoice(final Context context, final SimplePlayerService playerService,
                                             final MenuItem menuItemShuffle) {

    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    CharSequence[] array = {ShuffleState.SHUFFLE_OFF.getLabel(), ShuffleState.SHUFFLE_ON.getLabel()};

    builder.setTitle("Select shuffle mode") // TODO const

        .setSingleChoiceItems(array, playerService.getShuffleState().ordinal(), new DialogInterface.OnClickListener() {

          @Override
          public void onClick(DialogInterface dialog, int which) {
            dialogShuffleSelectedItem = which;
          }
        })
        .setPositiveButton("OK", new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface dialog, int id) {
            if (dialogShuffleSelectedItem > -1) {
              ShuffleState selectedState = ShuffleState.values()[dialogShuffleSelectedItem];
              playerService.setShuffleState(selectedState);
              menuItemShuffle.setTitle(context.getString(R.string.button_and_toast_shuffle_first_part) + " " + selectedState.getLabel());
              makeToast(context, context.getString(R.string.button_and_toast_shuffle_first_part) + " " + selectedState.getLabel());
              dialogShuffleSelectedItem = -1;
            }
          }
        })
        .setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface dialog, int id) {
            // empty
          }
        });

    builder.create().show();
  }

  public static void showFileCantBePlayed(Context context, String filePath) {
    if (TextUtils.isEmpty(filePath)) {
      new AlertDialog.Builder(context)
          .setTitle(R.string.app_name)
          .setMessage(R.string.file_cant_be_played_refresh)
          .setPositiveButton(R.string.ok, null).show();
    } else {
      new AlertDialog.Builder(context)
          .setTitle(R.string.app_name)
          .setMessage(context.getString(R.string.file_cant_be_played_refresh_part1) + filePath
              + context.getString(R.string.file_cant_be_played_refresh_part2))
          .setPositiveButton(R.string.ok, null).show();
    }
  }

  public static void showFileCantBePlayed(Context context, File file) {
    showFileCantBePlayed(context, file.getAbsolutePath());
  }

  public static void showFolderCantBeRead(Context context, String folderName) {
    new AlertDialog.Builder(context)
        .setTitle(R.string.app_name)
        .setMessage(context.getString(R.string.folder_cant_read_part1) + folderName
            + context.getString(R.string.folder_cant_read_part2))
        .setPositiveButton(R.string.ok, null).show();
  }

  public static void showFolderCantBeRead(Context context, File file) {
    showFolderCantBeRead(context, file.getName());
  }

}




Java Source Code List

org.sergez.splayer.activity.AnimationMakeGoneListener.java
org.sergez.splayer.activity.AudioFxDemo.java
org.sergez.splayer.activity.DonationActivity.java
org.sergez.splayer.activity.ListData.java
org.sergez.splayer.activity.PlayFileAdapter.java
org.sergez.splayer.activity.PreferencesActivity.java
org.sergez.splayer.activity.SimplePlayerActivity.java
org.sergez.splayer.enums.RepeatState.java
org.sergez.splayer.enums.ShuffleState.java
org.sergez.splayer.inappbilling.Base64DecoderException.java
org.sergez.splayer.inappbilling.Base64.java
org.sergez.splayer.inappbilling.IabException.java
org.sergez.splayer.inappbilling.IabHelper.java
org.sergez.splayer.inappbilling.IabResult.java
org.sergez.splayer.inappbilling.Inventory.java
org.sergez.splayer.inappbilling.Purchase.java
org.sergez.splayer.inappbilling.Security.java
org.sergez.splayer.inappbilling.SkuDetails.java
org.sergez.splayer.service.SimplePlayerService.java
org.sergez.splayer.util.Constants.java
org.sergez.splayer.util.DialogUtils.java
org.sergez.splayer.util.DurationAlbumID.java
org.sergez.splayer.util.FileFormat.java
org.sergez.splayer.util.MediaFileData.java
org.sergez.splayer.util.MediaFileUtil.java
org.sergez.splayer.util.PlayerState.java
org.sergez.splayer.util.PrefsConstants.java
org.sergez.splayer.util.PrefsController.java
org.sergez.splayer.util.SortIgnoreCase.java
org.sergez.splayer.util.UIStateController.java
org.sergez.splayer.util.Utils.java
org.sergez.splayer.view.ScrollingTextView.java