2 * Copyright (C) 2012 Andrew Neal Licensed under the Apache License, Version 2.0
3 * (the "License"); you may not use this file except in compliance with the
4 * License. You may obtain a copy of the License at
5 * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law
6 * or agreed to in writing, software distributed under the License is
7 * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
8 * KIND, either express or implied. See the License for the specific language
9 * governing permissions and limitations under the License.
12 package com.cyngn.eleven.menu;
14 import android.app.AlertDialog;
15 import android.app.Dialog;
16 import android.content.DialogInterface;
17 import android.os.Bundle;
18 import android.support.v4.app.DialogFragment;
19 import android.widget.ArrayAdapter;
20 import android.widget.ListAdapter;
22 import com.cyngn.eleven.Config;
23 import com.cyngn.eleven.R;
24 import com.cyngn.eleven.ui.activities.ProfileActivity;
25 import com.cyngn.eleven.utils.ApolloUtils;
26 import com.cyngn.eleven.utils.Lists;
28 import java.util.ArrayList;
31 * Used when the user touches the image in the header in {@link ProfileActivity}
32 * . It provides an easy interface for them to choose a new image, use the old
33 * image, or search Google for one.
35 * @author Andrew Neal (andrewdneal@gmail.com)
37 public class PhotoSelectionDialog extends DialogFragment {
39 private static final int NEW_PHOTO = 0;
41 private static final int OLD_PHOTO = 1;
43 private static final int GOOGLE_SEARCH = 2;
45 private static final int FETCH_IMAGE = 3;
47 private final ArrayList<String> mChoices = Lists.newArrayList();
49 private static ProfileType mProfileType;
52 * Empty constructor as per the {@link Fragment} documentation
54 public PhotoSelectionDialog() {
58 * @param title The dialog title.
59 * @param value The MIME type
60 * @return A new instance of the dialog.
62 public static PhotoSelectionDialog newInstance(final String title, final ProfileType type) {
63 final PhotoSelectionDialog frag = new PhotoSelectionDialog();
64 final Bundle args = new Bundle();
65 args.putString(Config.NAME, title);
66 frag.setArguments(args);
75 public Dialog onCreateDialog(final Bundle savedInstanceState) {
76 final String title = getArguments().getString(Config.NAME);
77 switch (mProfileType) {
90 // Dialog item Adapter
91 final ProfileActivity activity = (ProfileActivity) getActivity();
92 final ListAdapter adapter = new ArrayAdapter<String>(activity,
93 android.R.layout.select_dialog_item, mChoices);
94 return new AlertDialog.Builder(activity).setTitle(title)
95 .setAdapter(adapter, new DialogInterface.OnClickListener() {
98 public void onClick(final DialogInterface dialog, final int which) {
101 activity.selectNewPhoto();
104 activity.selectOldPhoto();
107 activity.fetchAlbumArt();
110 activity.googleSearch();
120 * Adds the choices for the artist profile image.
122 private void setArtistChoices() {
123 // Select a photo from the gallery
124 mChoices.add(NEW_PHOTO, getString(R.string.new_photo));
125 if (ApolloUtils.isOnline(getActivity())) {
126 // Option to fetch the old artist image
127 mChoices.add(OLD_PHOTO, getString(R.string.context_menu_fetch_artist_image));
128 // Search Google for the artist name
129 mChoices.add(GOOGLE_SEARCH, getString(R.string.google_search));
134 * Adds the choices for the album profile image.
136 private void setAlbumChoices() {
137 // Select a photo from the gallery
138 mChoices.add(NEW_PHOTO, getString(R.string.new_photo));
139 // Option to fetch the old album image
140 mChoices.add(OLD_PHOTO, getString(R.string.old_photo));
141 if (ApolloUtils.isOnline(getActivity())) {
142 // Search Google for the album name
143 mChoices.add(GOOGLE_SEARCH, getString(R.string.google_search));
144 // Option to fetch the album image
145 mChoices.add(FETCH_IMAGE, getString(R.string.context_menu_fetch_album_art));
150 * Adds the choices for the genre and playlist images.
152 private void setOtherChoices() {
153 // Select a photo from the gallery
154 mChoices.add(NEW_PHOTO, getString(R.string.new_photo));
155 // Option to use the default image
156 mChoices.add(OLD_PHOTO, getString(R.string.use_default));
160 * Easily detect the MIME type
162 public enum ProfileType {