OSDN Git Service

Correct some lint warnings
[android-x86/packages-apps-Eleven.git] / src / org / lineageos / eleven / utils / NavUtils.java
1 /*
2  * Copyright (C) 2012 Andrew Neal
3  * Copyright (C) 2014 The CyanogenMod Project
4  * Licensed under the Apache License, Version 2.0
5  * (the "License"); you may not use this file except in compliance with the
6  * License. You may obtain a copy of the License at
7  * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law
8  * or agreed to in writing, software distributed under the License is
9  * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
10  * KIND, either express or implied. See the License for the specific language
11  * governing permissions and limitations under the License.
12  */
13
14 package org.lineageos.eleven.utils;
15
16 import android.app.Activity;
17 import android.app.SearchManager;
18 import android.content.ActivityNotFoundException;
19 import android.content.Intent;
20 import android.content.pm.PackageManager;
21 import android.media.audiofx.AudioEffect;
22 import android.os.Bundle;
23 import android.provider.MediaStore;
24 import android.widget.Toast;
25
26 import org.lineageos.eleven.Config;
27 import org.lineageos.eleven.R;
28 import org.lineageos.eleven.ui.activities.HomeActivity;
29 import org.lineageos.eleven.ui.activities.SearchActivity;
30 import org.lineageos.eleven.ui.activities.SettingsActivity;
31
32 /**
33  * Various navigation helpers.
34  *
35  * @author Andrew Neal (andrewdneal@gmail.com)
36  */
37 public final class NavUtils {
38
39     /**
40      * Opens the profile of an artist.
41      *
42      * @param context The {@link Activity} to use.
43      * @param artistName The name of the artist
44      */
45     public static void openArtistProfile(final Activity context, final String artistName) {
46         // Create a new bundle to transfer the artist info
47         final Bundle bundle = new Bundle();
48         bundle.putLong(Config.ID, MusicUtils.getIdForArtist(context, artistName));
49         bundle.putString(Config.MIME_TYPE, MediaStore.Audio.Artists.CONTENT_TYPE);
50         bundle.putString(Config.ARTIST_NAME, artistName);
51
52         // Create the intent to launch the profile activity
53         final Intent intent = new Intent(context, HomeActivity.class);
54         intent.setAction(HomeActivity.ACTION_VIEW_ARTIST_DETAILS);
55         intent.putExtras(bundle);
56         context.startActivity(intent);
57     }
58
59     /**
60      * Opens the profile of an album.
61      *
62      * @param context The {@link Activity} to use.
63      * @param albumName The name of the album
64      * @param artistName The name of the album artist
65      * @param albumId The id of the album
66      */
67     public static void openAlbumProfile(final Activity context,
68             final String albumName, final String artistName, final long albumId) {
69
70         // Create a new bundle to transfer the album info
71         final Bundle bundle = new Bundle();
72         bundle.putString(Config.ALBUM_YEAR, MusicUtils.getReleaseDateForAlbum(context, albumId));
73         bundle.putInt(Config.SONG_COUNT, MusicUtils.getSongCountForAlbumInt(context, albumId));
74         bundle.putString(Config.ARTIST_NAME, artistName);
75         bundle.putString(Config.MIME_TYPE, MediaStore.Audio.Albums.CONTENT_TYPE);
76         bundle.putLong(Config.ID, albumId);
77         bundle.putString(Config.NAME, albumName);
78
79         // Create the intent to launch the profile activity
80         final Intent intent = new Intent(context, HomeActivity.class);
81         intent.setAction(HomeActivity.ACTION_VIEW_ALBUM_DETAILS);
82         intent.putExtras(bundle);
83         context.startActivity(intent);
84     }
85
86     public static void openSmartPlaylist(final Activity context, final Config.SmartPlaylistType type) {
87         // Create the intent to launch the profile activity
88         final Intent intent = new Intent(context, HomeActivity.class);
89         intent.setAction(HomeActivity.ACTION_VIEW_SMART_PLAYLIST);
90         intent.putExtra(Config.SMART_PLAYLIST_TYPE, type.mId);
91         context.startActivity(intent);
92     }
93
94     /**
95      * Opens the playlist view
96      *
97      * @param context The {@link Activity} to use.
98      * @param playlistId the id of the playlist
99      * @param playlistName the playlist name
100      */
101     public static void openPlaylist(final Activity context, final long playlistId,
102                                     final String playlistName) {
103         final Bundle bundle = new Bundle();
104         bundle.putLong(Config.ID, playlistId);
105         bundle.putString(Config.MIME_TYPE, MediaStore.Audio.Playlists.CONTENT_TYPE);
106         bundle.putString(Config.NAME, playlistName);
107
108         // Create the intent to launch the profile activity
109         final Intent intent = new Intent(context, HomeActivity.class);
110         intent.setAction(HomeActivity.ACTION_VIEW_PLAYLIST_DETAILS);
111         intent.putExtras(bundle);
112         context.startActivity(intent);
113     }
114
115     /**
116      * @return the intent to launch the effects panel/dsp manager
117      */
118     private static Intent createEffectsIntent() {
119         final Intent effects = new Intent(AudioEffect.ACTION_DISPLAY_AUDIO_EFFECT_CONTROL_PANEL);
120         effects.putExtra(AudioEffect.EXTRA_AUDIO_SESSION, MusicUtils.getAudioSessionId());
121         return effects;
122     }
123
124     /**
125      * Opens the sound effects panel AudioFX in LineageOS
126      *
127      * @param context The {@link Activity} to use.
128      * @param requestCode The request code passed into startActivityForResult
129      */
130     public static void openEffectsPanel(final Activity context, final int requestCode) {
131         try {
132             // The google MusicFX apps need to be started using startActivityForResult
133             context.startActivityForResult(createEffectsIntent(), requestCode);
134         } catch (final ActivityNotFoundException notFound) {
135             Toast.makeText(context, context.getString(R.string.no_effects_for_you),
136                     Toast.LENGTH_SHORT).show();
137         }
138     }
139
140     /**
141      * @return true if there is an effects panel/DSK Manager
142      */
143     public static boolean hasEffectsPanel(final Activity activity) {
144         final PackageManager packageManager = activity.getPackageManager();
145         return packageManager.resolveActivity(createEffectsIntent(),
146                 PackageManager.MATCH_DEFAULT_ONLY) != null;
147     }
148
149     /**
150      * Opens to {@link SettingsActivity}.
151      *
152      * @param activity The {@link Activity} to use.
153      */
154     public static void openSettings(final Activity activity) {
155         final Intent intent = new Intent(activity, SettingsActivity.class);
156         activity.startActivity(intent);
157     }
158
159     /**
160      * Opens to {@link org.lineageos.eleven.ui.activities.SearchActivity}.
161      *
162      * @param activity The {@link Activity} to use.
163      * @param query The search query.
164      */
165     public static void openSearch(final Activity activity, final String query) {
166         final Bundle bundle = new Bundle();
167         final Intent intent = new Intent(activity, SearchActivity.class);
168         intent.putExtra(SearchManager.QUERY, query);
169         intent.putExtras(bundle);
170         activity.startActivity(intent);
171     }
172
173     /**
174      * Opens to {@link org.lineageos.eleven.ui.activities.HomeActivity}.
175      *
176      * @param activity The {@link Activity} to use.
177      */
178     public static void goHome(final Activity activity, final int browseIndex) {
179         final Intent intent = new Intent(activity, HomeActivity.class);
180         intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK
181                 | Intent.FLAG_ACTIVITY_NEW_TASK);
182         intent.putExtra(HomeActivity.EXTRA_BROWSE_PAGE_IDX, browseIndex);
183         activity.startActivity(intent);
184     }
185 }