diff options
author | linus_lee <llee@cyngn.com> | 2014-11-20 16:39:38 -0800 |
---|---|---|
committer | linus_lee <llee@cyngn.com> | 2014-12-09 12:23:20 -0800 |
commit | 71810ebb2bf8fd792c92487fe87f9dbebefc8541 (patch) | |
tree | 42a4d11ba03a4c7af843edc0b45375b17c64053c /src/com/cyanogenmod/eleven/menu | |
parent | f199f983c9a5e2f4434b85273d1da0d609c33228 (diff) | |
download | android_packages_apps_Eleven-71810ebb2bf8fd792c92487fe87f9dbebefc8541.tar.gz android_packages_apps_Eleven-71810ebb2bf8fd792c92487fe87f9dbebefc8541.tar.bz2 android_packages_apps_Eleven-71810ebb2bf8fd792c92487fe87f9dbebefc8541.zip |
Update Eleven headers and namespace for open source
Change-Id: I82caf2ebf991998e67f546ff2ac7eaf2b30dc6be
Diffstat (limited to 'src/com/cyanogenmod/eleven/menu')
-rw-r--r-- | src/com/cyanogenmod/eleven/menu/BasePlaylistDialog.java | 160 | ||||
-rw-r--r-- | src/com/cyanogenmod/eleven/menu/ConfirmDialog.java | 74 | ||||
-rw-r--r-- | src/com/cyanogenmod/eleven/menu/CreateNewPlaylist.java | 146 | ||||
-rw-r--r-- | src/com/cyanogenmod/eleven/menu/DeleteDialog.java | 114 | ||||
-rw-r--r-- | src/com/cyanogenmod/eleven/menu/FragmentMenuItems.java | 41 | ||||
-rw-r--r-- | src/com/cyanogenmod/eleven/menu/PhotoSelectionDialog.java | 161 | ||||
-rw-r--r-- | src/com/cyanogenmod/eleven/menu/RenamePlaylist.java | 138 |
7 files changed, 834 insertions, 0 deletions
diff --git a/src/com/cyanogenmod/eleven/menu/BasePlaylistDialog.java b/src/com/cyanogenmod/eleven/menu/BasePlaylistDialog.java new file mode 100644 index 0000000..0d9d7fe --- /dev/null +++ b/src/com/cyanogenmod/eleven/menu/BasePlaylistDialog.java @@ -0,0 +1,160 @@ +/* + * Copyright (C) 2012 Andrew Neal + * Copyright (C) 2014 The CyanogenMod Project + * Licensed under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law + * or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the specific language + * governing permissions and limitations under the License. + */ + +package com.cyanogenmod.eleven.menu; + +import android.app.AlertDialog; +import android.app.Dialog; +import android.content.DialogInterface; +import android.content.DialogInterface.OnClickListener; +import android.os.Bundle; +import android.support.v4.app.DialogFragment; +import android.text.Editable; +import android.text.InputType; +import android.text.TextWatcher; +import android.view.WindowManager; +import android.widget.Button; +import android.widget.EditText; + +import com.cyanogenmod.eleven.R; +import com.cyanogenmod.eleven.utils.MusicUtils; + +/** + * A simple base class for the playlist dialogs. + * + * @author Andrew Neal (andrewdneal@gmail.com) + */ +public abstract class BasePlaylistDialog extends DialogFragment { + + /* The actual dialog */ + protected AlertDialog mPlaylistDialog; + + /* Used to make new playlist names */ + protected EditText mPlaylist; + + /* The dialog save button */ + protected Button mSaveButton; + + /* The dialog prompt */ + protected String mPrompt; + + /* The default edit text text */ + protected String mDefaultname; + + /** + * {@inheritDoc} + */ + @Override + public Dialog onCreateDialog(final Bundle savedInstanceState) { + // Initialize the alert dialog + mPlaylistDialog = new AlertDialog.Builder(getActivity()).create(); + // Initialize the edit text + mPlaylist = new EditText(getActivity()); + // To show the "done" button on the soft keyboard + mPlaylist.setSingleLine(true); + // All caps + mPlaylist.setInputType(mPlaylist.getInputType() | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS + | InputType.TYPE_TEXT_FLAG_CAP_WORDS); + // Set the save button action + mPlaylistDialog.setButton(Dialog.BUTTON_POSITIVE, getString(R.string.save), + new OnClickListener() { + + @Override + public void onClick(final DialogInterface dialog, final int which) { + onSaveClick(); + MusicUtils.refresh(); + dialog.dismiss(); + } + }); + // Set the cancel button action + mPlaylistDialog.setButton(Dialog.BUTTON_NEGATIVE, getString(R.string.cancel), + new OnClickListener() { + + @Override + public void onClick(final DialogInterface dialog, final int which) { + MusicUtils.refresh(); + dialog.dismiss(); + } + }); + + mPlaylist.post(new Runnable() { + + @Override + public void run() { + // Request focus to the edit text + mPlaylist.requestFocus(); + // Select the playlist name + mPlaylist.selectAll(); + }; + }); + + initObjects(savedInstanceState); + mPlaylistDialog.setTitle(mPrompt); + mPlaylistDialog.setView(mPlaylist); + mPlaylist.setText(mDefaultname); + mPlaylist.setSelection(mDefaultname.length()); + mPlaylist.addTextChangedListener(mTextWatcher); + mPlaylistDialog.getWindow().setSoftInputMode( + WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE); + mPlaylistDialog.show(); + return mPlaylistDialog; + } + + /** + * Simple {@link TextWatcher} + */ + private final TextWatcher mTextWatcher = new TextWatcher() { + + /** + * {@inheritDoc} + */ + @Override + public void onTextChanged(final CharSequence s, final int start, final int before, + final int count) { + onTextChangedListener(); + } + + /** + * {@inheritDoc} + */ + @Override + public void afterTextChanged(final Editable s) { + /* Nothing to do */ + } + + /** + * {@inheritDoc} + */ + @Override + public void beforeTextChanged(final CharSequence s, final int start, final int count, + final int after) { + /* Nothing to do */ + } + }; + + /** + * Initializes the prompt and default name + */ + public abstract void initObjects(Bundle savedInstanceState); + + /** + * Called when the save button of our {@link AlertDialog} is pressed + */ + public abstract void onSaveClick(); + + /** + * Called in our {@link TextWatcher} during a text change + */ + public abstract void onTextChangedListener(); + +} diff --git a/src/com/cyanogenmod/eleven/menu/ConfirmDialog.java b/src/com/cyanogenmod/eleven/menu/ConfirmDialog.java new file mode 100644 index 0000000..908f3fc --- /dev/null +++ b/src/com/cyanogenmod/eleven/menu/ConfirmDialog.java @@ -0,0 +1,74 @@ +/* +* Copyright (C) 2014 The CyanogenMod Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +package com.cyanogenmod.eleven.menu; + +import android.app.AlertDialog; +import android.app.Dialog; +import android.content.DialogInterface; +import android.content.DialogInterface.OnClickListener; +import android.os.Bundle; +import android.support.v4.app.DialogFragment; +import android.support.v4.app.Fragment; + +import com.cyanogenmod.eleven.R; + +/** Dialog to confirm a non-reversible action */ +public class ConfirmDialog extends DialogFragment { + private static final String TITLE_ID = "titleId"; + private static final String OK_ID = "okId"; + + public interface ConfirmCallback { + public void confirmOk(int requestCode); + } + + public ConfirmDialog() {} + + /** @param title describes action user is confirming + * @param okId text for Ok button */ + public static void show(Fragment target, int requestCode, int titleId, int okId) { + final ConfirmDialog frag = new ConfirmDialog(); + final Bundle args = new Bundle(); + args.putInt(TITLE_ID, titleId); + args.putInt(OK_ID, okId); + frag.setArguments(args); + frag.setTargetFragment(target, requestCode); + frag.show(target.getFragmentManager(), "ConfirmDialog"); + } + + @Override + public Dialog onCreateDialog(final Bundle savedInstanceState) { + Bundle args = getArguments(); + return new AlertDialog.Builder(getActivity()) + .setTitle(args.getInt(TITLE_ID)) + .setMessage(R.string.cannot_be_undone) + .setPositiveButton(args.getInt(OK_ID), new OnClickListener() { + @Override + public void onClick(final DialogInterface dialog, final int which) { + Fragment target = getTargetFragment(); + if (target instanceof ConfirmCallback) { + ((ConfirmCallback)target).confirmOk(getTargetRequestCode()); + } + dialog.dismiss(); + } + }).setNegativeButton(R.string.cancel, new OnClickListener() { + @Override + public void onClick(final DialogInterface dialog, final int which) { + dialog.dismiss(); + } + }).create(); + } +}
\ No newline at end of file diff --git a/src/com/cyanogenmod/eleven/menu/CreateNewPlaylist.java b/src/com/cyanogenmod/eleven/menu/CreateNewPlaylist.java new file mode 100644 index 0000000..84a72c4 --- /dev/null +++ b/src/com/cyanogenmod/eleven/menu/CreateNewPlaylist.java @@ -0,0 +1,146 @@ +/* + * Copyright (C) 2012 Andrew Neal + * Copyright (C) 2014 The CyanogenMod Project + * Licensed under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law + * or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the specific language + * governing permissions and limitations under the License. + */ + +package com.cyanogenmod.eleven.menu; + +import android.app.Dialog; +import android.content.ContentResolver; +import android.database.Cursor; +import android.os.Bundle; +import android.provider.MediaStore; + +import com.cyanogenmod.eleven.R; +import com.cyanogenmod.eleven.format.Capitalize; +import com.cyanogenmod.eleven.utils.MusicUtils; + +/** + * @author Andrew Neal (andrewdneal@gmail.com) TODO - The playlist names are + * automatically capitalized to help when you want to play one via voice + * actions, but it really needs to work either way. As in, capitalized + * or not. + */ +public class CreateNewPlaylist extends BasePlaylistDialog { + + // The playlist list + private long[] mPlaylistList = new long[] {}; + + /** + * @param list The list of tracks to add to the playlist + * @return A new instance of this dialog. + */ + public static CreateNewPlaylist getInstance(final long[] list) { + final CreateNewPlaylist frag = new CreateNewPlaylist(); + final Bundle args = new Bundle(); + args.putLongArray("playlist_list", list); + frag.setArguments(args); + return frag; + } + + /** + * {@inheritDoc} + */ + @Override + public void onSaveInstanceState(final Bundle outcicle) { + outcicle.putString("defaultname", mPlaylist.getText().toString()); + } + + /** + * {@inheritDoc} + */ + @Override + public void initObjects(final Bundle savedInstanceState) { + mPlaylistList = getArguments().getLongArray("playlist_list"); + mDefaultname = savedInstanceState != null ? savedInstanceState.getString("defaultname") + : makePlaylistName(); + if (mDefaultname == null) { + getDialog().dismiss(); + return; + } + final String prromptformat = getString(R.string.create_playlist_prompt); + mPrompt = String.format(prromptformat, mDefaultname); + } + + @Override + public void onSaveClick() { + final String playlistName = mPlaylist.getText().toString(); + if (playlistName != null && playlistName.length() > 0) { + final int playlistId = (int)MusicUtils.getIdForPlaylist(getActivity(), + playlistName); + if (playlistId >= 0) { + MusicUtils.clearPlaylist(getActivity(), playlistId); + MusicUtils.addToPlaylist(getActivity(), mPlaylistList, playlistId); + } else { + final long newId = MusicUtils.createPlaylist(getActivity(), + Capitalize.capitalize(playlistName)); + MusicUtils.addToPlaylist(getActivity(), mPlaylistList, newId); + } + getDialog().dismiss(); + } + } + + /** + * {@inheritDoc} + */ + @Override + public void onTextChangedListener() { + final String playlistName = mPlaylist.getText().toString(); + mSaveButton = mPlaylistDialog.getButton(Dialog.BUTTON_POSITIVE); + if (mSaveButton == null) { + return; + } + if (playlistName.trim().length() == 0) { + mSaveButton.setEnabled(false); + } else { + mSaveButton.setEnabled(true); + if (MusicUtils.getIdForPlaylist(getActivity(), playlistName) >= 0) { + mSaveButton.setText(R.string.overwrite); + } else { + mSaveButton.setText(R.string.save); + } + } + } + + private String makePlaylistName() { + final String template = getString(R.string.new_playlist_name_template); + int num = 1; + final String[] projection = new String[] { + MediaStore.Audio.Playlists.NAME + }; + final ContentResolver resolver = getActivity().getContentResolver(); + final String selection = MediaStore.Audio.Playlists.NAME + " != ''"; + Cursor cursor = resolver.query(MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI, projection, + selection, null, MediaStore.Audio.Playlists.NAME); + if (cursor == null) { + return null; + } + + String suggestedname; + suggestedname = String.format(template, num++); + boolean done = false; + while (!done) { + done = true; + cursor.moveToFirst(); + while (!cursor.isAfterLast()) { + final String playlistname = cursor.getString(0); + if (playlistname.compareToIgnoreCase(suggestedname) == 0) { + suggestedname = String.format(template, num++); + done = false; + } + cursor.moveToNext(); + } + } + cursor.close(); + cursor = null; + return suggestedname; + } +} diff --git a/src/com/cyanogenmod/eleven/menu/DeleteDialog.java b/src/com/cyanogenmod/eleven/menu/DeleteDialog.java new file mode 100644 index 0000000..be22fc7 --- /dev/null +++ b/src/com/cyanogenmod/eleven/menu/DeleteDialog.java @@ -0,0 +1,114 @@ +/* + * Copyright (C) 2012 Andrew Neal + * Copyright (C) 2014 The CyanogenMod Project + * Licensed under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law + * or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the specific language + * governing permissions and limitations under the License. + */ + +package com.cyanogenmod.eleven.menu; + +import android.app.AlertDialog; +import android.app.Dialog; +import android.content.DialogInterface; +import android.content.DialogInterface.OnClickListener; +import android.os.Bundle; +import android.support.v4.app.DialogFragment; + +import com.cyanogenmod.eleven.Config; +import com.cyanogenmod.eleven.R; +import com.cyanogenmod.eleven.cache.ImageFetcher; +import com.cyanogenmod.eleven.utils.ApolloUtils; +import com.cyanogenmod.eleven.utils.MusicUtils; + +/** + * Alert dialog used to delete tracks. + * <p> + * TODO: Remove albums from the recents list upon deletion. + * + * @author Andrew Neal (andrewdneal@gmail.com) + */ +public class DeleteDialog extends DialogFragment { + + public interface DeleteDialogCallback { + public void onDelete(long[] id); + } + + /** + * The item(s) to delete + */ + private long[] mItemList; + + /** + * The image cache + */ + private ImageFetcher mFetcher; + + /** + * Empty constructor as per the {@link Fragment} documentation + */ + public DeleteDialog() { + } + + /** + * @param title The title of the artist, album, or song to delete + * @param items The item(s) to delete + * @param key The key used to remove items from the cache. + * @return A new instance of the dialog + */ + public static DeleteDialog newInstance(final String title, final long[] items, final String key) { + final DeleteDialog frag = new DeleteDialog(); + final Bundle args = new Bundle(); + args.putString(Config.NAME, title); + args.putLongArray("items", items); + args.putString("cachekey", key); + frag.setArguments(args); + return frag; + } + + /** + * {@inheritDoc} + */ + @Override + public Dialog onCreateDialog(final Bundle savedInstanceState) { + final String delete = getString(R.string.context_menu_delete); + final Bundle arguments = getArguments(); + // Get the image cache key + final String key = arguments.getString("cachekey"); + // Get the track(s) to delete + mItemList = arguments.getLongArray("items"); + // Get the dialog title + final String title = arguments.getString(Config.NAME); + final String dialogTitle = getString(R.string.delete_dialog_title, title); + // Initialize the image cache + mFetcher = ApolloUtils.getImageFetcher(getActivity()); + // Build the dialog + return new AlertDialog.Builder(getActivity()).setTitle(dialogTitle) + .setMessage(R.string.cannot_be_undone) + .setPositiveButton(delete, new OnClickListener() { + + @Override + public void onClick(final DialogInterface dialog, final int which) { + // Remove the items from the image cache + mFetcher.removeFromCache(key); + // Delete the selected item(s) + MusicUtils.deleteTracks(getActivity(), mItemList); + if (getActivity() instanceof DeleteDialogCallback) { + ((DeleteDialogCallback)getActivity()).onDelete(mItemList); + } + dialog.dismiss(); + } + }).setNegativeButton(R.string.cancel, new OnClickListener() { + + @Override + public void onClick(final DialogInterface dialog, final int which) { + dialog.dismiss(); + } + }).create(); + } +} diff --git a/src/com/cyanogenmod/eleven/menu/FragmentMenuItems.java b/src/com/cyanogenmod/eleven/menu/FragmentMenuItems.java new file mode 100644 index 0000000..ff9d4c8 --- /dev/null +++ b/src/com/cyanogenmod/eleven/menu/FragmentMenuItems.java @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2012 Andrew Neal + * Copyright (C) 2014 The CyanogenMod Project + * Licensed under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law + * or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the specific language + * governing permissions and limitations under the License. + */ + +package com.cyanogenmod.eleven.menu; + +/** + * Several of the context menu items used in Apollo are reused. This class helps + * keep things tidy. The integer values of the items are used both as the menu IDs + * _and_ to determine the sort order of the items. + */ +public interface FragmentMenuItems { + int PLAY_SELECTION = 10; // play the selected song, album, etc. + int PLAY_NEXT = 20; // queue a track to be played next + // SHUFFLE = 30 // defined in res/menu + int ADD_TO_QUEUE = 40; // add to end of current queue + int ADD_TO_PLAYLIST = 50; // append to a playlist + int REMOVE_FROM_QUEUE = 60; // remove track from play queue + int REMOVE_FROM_PLAYLIST= 70; // remove track from playlist + int REMOVE_FROM_RECENT = 80; // remove track from recently played list + int RENAME_PLAYLIST = 90; // change name of playlist + int MORE_BY_ARTIST = 100; // jump to artist detail page + int USE_AS_RINGTONE = 110; // set track as ringtone + int DELETE = 120; // delete track from device + int NEW_PLAYLIST = 130; // create new playlist - also in res/menu! + int PLAYLIST_SELECTED = 140; // this is used for existing playlists + int CHANGE_IMAGE = 150; // set new art for artist/album + + // not currently in use + int FETCH_ARTIST_IMAGE = 200; + int FETCH_ALBUM_ART = 210; +}
\ No newline at end of file diff --git a/src/com/cyanogenmod/eleven/menu/PhotoSelectionDialog.java b/src/com/cyanogenmod/eleven/menu/PhotoSelectionDialog.java new file mode 100644 index 0000000..e0286fd --- /dev/null +++ b/src/com/cyanogenmod/eleven/menu/PhotoSelectionDialog.java @@ -0,0 +1,161 @@ +/* + * Copyright (C) 2012 Andrew Neal + * Copyright (C) 2014 The CyanogenMod Project + * Licensed under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law + * or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the specific language + * governing permissions and limitations under the License. + */ + +package com.cyanogenmod.eleven.menu; + +import android.app.AlertDialog; +import android.app.Dialog; +import android.content.DialogInterface; +import android.os.Bundle; +import android.support.v4.app.DialogFragment; +import android.widget.ArrayAdapter; +import android.widget.ListAdapter; + +import com.cyanogenmod.eleven.Config; +import com.cyanogenmod.eleven.R; +import com.cyanogenmod.eleven.ui.activities.HomeActivity; +import com.cyanogenmod.eleven.utils.ApolloUtils; +import com.cyanogenmod.eleven.utils.Lists; +import com.cyanogenmod.eleven.utils.MusicUtils; + +import java.util.ArrayList; + +/** + * Used when the user requests to modify Album art or Artist image + * It provides an easy interface for them to choose a new image, use the old + * image, or search Google for one. + * + * @author Andrew Neal (andrewdneal@gmail.com) + */ +public class PhotoSelectionDialog extends DialogFragment { + + private static final int NEW_PHOTO = 0; + + private static final int OLD_PHOTO = 1; + + private final ArrayList<String> mChoices = Lists.newArrayList(); + + private static ProfileType mProfileType; + + private String mKey; + + /** + * Empty constructor as per the {@link Fragment} documentation + */ + public PhotoSelectionDialog() { + } + + /** + * @param title The dialog title. + * @param type Either Artist or Album + * @param key key to query ImageFetcher + * @return A new instance of the dialog. + */ + public static PhotoSelectionDialog newInstance(final String title, final ProfileType type, + String key) { + final PhotoSelectionDialog frag = new PhotoSelectionDialog(); + final Bundle args = new Bundle(); + args.putString(Config.NAME, title); + frag.setArguments(args); + mProfileType = type; + frag.mKey = key; + return frag; + } + + /** + * {@inheritDoc} + */ + @Override + public Dialog onCreateDialog(final Bundle savedInstanceState) { + final String title = getArguments().getString(Config.NAME); + switch (mProfileType) { + case ARTIST: + setArtistChoices(); + break; + case ALBUM: + setAlbumChoices(); + break; + case OTHER: + setOtherChoices(); + break; + default: + break; + } + // Dialog item Adapter + final HomeActivity activity = (HomeActivity) getActivity(); + final ListAdapter adapter = new ArrayAdapter<String>(activity, + android.R.layout.select_dialog_item, mChoices); + return new AlertDialog.Builder(activity).setTitle(title) + .setAdapter(adapter, new DialogInterface.OnClickListener() { + + @Override + public void onClick(final DialogInterface dialog, final int which) { + switch (which) { + case NEW_PHOTO: + activity.selectNewPhoto(mKey); + break; + case OLD_PHOTO: + MusicUtils.selectOldPhoto(activity, mKey); + break; + default: + break; + } + } + }).create(); + } + + /** + * Adds the choices for the artist profile image. + */ + private void setArtistChoices() { + // Select a photo from the gallery + mChoices.add(NEW_PHOTO, getString(R.string.new_photo)); + /* Disable fetching image until we find a last.fm replacement + if (ApolloUtils.isOnline(getActivity())) { + // Option to fetch the old artist image + mChoices.add(OLD_PHOTO, getString(R.string.context_menu_fetch_artist_image)); + }*/ + } + + /** + * Adds the choices for the album profile image. + */ + private void setAlbumChoices() { + // Select a photo from the gallery + mChoices.add(NEW_PHOTO, getString(R.string.new_photo)); + /* Disable fetching image until we find a last.fm replacement + // Option to fetch the old album image + if (ApolloUtils.isOnline(getActivity())) { + // Option to fetch the old artist image + mChoices.add(OLD_PHOTO, getString(R.string.context_menu_fetch_album_art)); + }*/ + } + + /** + * Adds the choices for the genre and playlist images. + */ + private void setOtherChoices() { + // Select a photo from the gallery + mChoices.add(NEW_PHOTO, getString(R.string.new_photo)); + // Disable fetching image until we find a last.fm replacement + // Option to use the default image + // mChoices.add(OLD_PHOTO, getString(R.string.use_default)); + } + + /** + * Easily detect the MIME type + */ + public enum ProfileType { + ARTIST, ALBUM, ProfileType, OTHER + } +} diff --git a/src/com/cyanogenmod/eleven/menu/RenamePlaylist.java b/src/com/cyanogenmod/eleven/menu/RenamePlaylist.java new file mode 100644 index 0000000..a3b8f9e --- /dev/null +++ b/src/com/cyanogenmod/eleven/menu/RenamePlaylist.java @@ -0,0 +1,138 @@ +/* + * Copyright (C) 2012 Andrew Neal + * Copyright (C) 2014 The CyanogenMod Project + * Licensed under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law + * or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the specific language + * governing permissions and limitations under the License. + */ + +package com.cyanogenmod.eleven.menu; + +import android.app.Dialog; +import android.content.ContentResolver; +import android.content.ContentValues; +import android.database.Cursor; +import android.os.Bundle; +import android.provider.MediaStore; +import android.provider.MediaStore.Audio; + +import com.cyanogenmod.eleven.R; +import com.cyanogenmod.eleven.format.Capitalize; +import com.cyanogenmod.eleven.utils.MusicUtils; + +/** + * Alert dialog used to rename playlits. + * + * @author Andrew Neal (andrewdneal@gmail.com) + */ +public class RenamePlaylist extends BasePlaylistDialog { + + private String mOriginalName; + + private long mRenameId; + + /** + * @param id The Id of the playlist to rename + * @return A new instance of this dialog. + */ + public static RenamePlaylist getInstance(final Long id) { + final RenamePlaylist frag = new RenamePlaylist(); + final Bundle args = new Bundle(); + args.putLong("rename", id); + frag.setArguments(args); + return frag; + } + + /** + * {@inheritDoc} + */ + @Override + public void onSaveInstanceState(final Bundle outcicle) { + outcicle.putString("defaultname", mPlaylist.getText().toString()); + outcicle.putLong("rename", mRenameId); + } + + /** + * {@inheritDoc} + */ + @Override + public void initObjects(final Bundle savedInstanceState) { + mRenameId = savedInstanceState != null ? savedInstanceState.getLong("rename") + : getArguments().getLong("rename", -1); + mOriginalName = getPlaylistNameFromId(mRenameId); + mDefaultname = savedInstanceState != null ? savedInstanceState.getString("defaultname") + : mOriginalName; + if (mRenameId < 0 || mOriginalName == null || mDefaultname == null) { + getDialog().dismiss(); + return; + } + final String promptformat = getString(R.string.create_playlist_prompt); + mPrompt = String.format(promptformat, mOriginalName, mDefaultname); + } + + /** + * {@inheritDoc} + */ + @Override + public void onSaveClick() { + final String playlistName = mPlaylist.getText().toString(); + if (playlistName != null && playlistName.length() > 0) { + final ContentResolver resolver = getActivity().getContentResolver(); + final ContentValues values = new ContentValues(1); + values.put(Audio.Playlists.NAME, Capitalize.capitalize(playlistName)); + resolver.update(Audio.Playlists.EXTERNAL_CONTENT_URI, values, + MediaStore.Audio.Playlists._ID + "=?", new String[] { + String.valueOf(mRenameId) + }); + getDialog().dismiss(); + } + } + + @Override + public void onTextChangedListener() { + final String playlistName = mPlaylist.getText().toString(); + mSaveButton = mPlaylistDialog.getButton(Dialog.BUTTON_POSITIVE); + if (mSaveButton == null) { + return; + } + if (playlistName.trim().length() == 0) { + mSaveButton.setEnabled(false); + } else { + mSaveButton.setEnabled(true); + if (MusicUtils.getIdForPlaylist(getActivity(), playlistName) >= 0) { + mSaveButton.setText(R.string.overwrite); + } else { + mSaveButton.setText(R.string.save); + } + } + } + + /** + * @param id The Id of the playlist + * @return The name of the playlist + */ + private String getPlaylistNameFromId(final long id) { + Cursor cursor = getActivity().getContentResolver().query( + MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI, new String[] { + MediaStore.Audio.Playlists.NAME + }, MediaStore.Audio.Playlists._ID + "=?", new String[] { + String.valueOf(id) + }, MediaStore.Audio.Playlists.NAME); + String playlistName = null; + if (cursor != null) { + cursor.moveToFirst(); + if (!cursor.isAfterLast()) { + playlistName = cursor.getString(0); + } + } + cursor.close(); + cursor = null; + return playlistName; + } + +} |