Commit ee21d504 authored by linus_lee's avatar linus_lee Committed by Martin Brabham
Browse files

Eleven: Make the Equalizer button a bit smarter

First check if the intent can resolve properly
Secondly start for result to make some MusicFX apps work

Change-Id: Id9b597d0a3881ad7a433a0d39383dddc94b9e3fc
parent 5b9caa21
......@@ -54,6 +54,7 @@ public class HomeActivity extends SlidingPanelActivity {
public static final String EXTRA_BROWSE_PAGE_IDX = "BrowsePageIndex";
private static final int NEW_PHOTO = 1;
public static final int EQUALIZER = 2;
private String mKey;
private boolean mLoadedBaseFragment = false;
......
......@@ -52,6 +52,7 @@ import com.cyanogenmod.eleven.loaders.QueueLoader;
import com.cyanogenmod.eleven.menu.CreateNewPlaylist;
import com.cyanogenmod.eleven.menu.DeleteDialog;
import com.cyanogenmod.eleven.menu.FragmentMenuItems;
import com.cyanogenmod.eleven.ui.activities.HomeActivity;
import com.cyanogenmod.eleven.ui.activities.SlidingPanelActivity;
import com.cyanogenmod.eleven.utils.ApolloUtils;
import com.cyanogenmod.eleven.utils.MusicUtils;
......@@ -624,6 +625,11 @@ public class AudioPlayerFragment extends Fragment implements ServiceConnection,
if (MusicUtils.getQueueSize() > 0) {
// ringtone, and equalizer
inflater.inflate(R.menu.audio_player, menu);
if (!NavUtils.hasEffectsPanel(getActivity())) {
menu.removeItem(R.id.menu_audio_player_equalizer);
}
// save queue/clear queue
inflater.inflate(R.menu.queue, menu);
}
......@@ -646,7 +652,7 @@ public class AudioPlayerFragment extends Fragment implements ServiceConnection,
return true;
case R.id.menu_audio_player_equalizer:
// Sound effects
NavUtils.openEffectsPanel(getActivity());
NavUtils.openEffectsPanel(getActivity(), HomeActivity.EQUALIZER);
return true;
case R.id.menu_settings:
// Settings
......
......@@ -17,9 +17,12 @@ import android.app.Activity;
import android.app.SearchManager;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.media.audiofx.AudioEffect;
import android.os.Bundle;
import android.provider.MediaStore;
import android.util.Log;
import com.cyanogenmod.eleven.Config;
import com.cyanogenmod.eleven.R;
......@@ -27,6 +30,8 @@ import com.cyanogenmod.eleven.ui.activities.HomeActivity;
import com.cyanogenmod.eleven.ui.activities.SearchActivity;
import com.cyanogenmod.eleven.ui.activities.SettingsActivity;
import java.util.List;
/**
* Various navigation helpers.
*
......@@ -110,21 +115,40 @@ public final class NavUtils {
context.startActivity(intent);
}
/**
* @return the intent to launch the effects panel/dsp manager
*/
private static Intent createEffectsIntent() {
final Intent effects = new Intent(AudioEffect.ACTION_DISPLAY_AUDIO_EFFECT_CONTROL_PANEL);
effects.putExtra(AudioEffect.EXTRA_AUDIO_SESSION, MusicUtils.getAudioSessionId());
return effects;
}
/**
* Opens the sound effects panel or DSP manager in CM
*
* @param context The {@link Activity} to use.
* @param requestCode The request code passed into startActivityForResult
*/
public static void openEffectsPanel(final Activity context) {
public static void openEffectsPanel(final Activity context, final int requestCode) {
try {
final Intent effects = new Intent(AudioEffect.ACTION_DISPLAY_AUDIO_EFFECT_CONTROL_PANEL);
effects.putExtra(AudioEffect.EXTRA_AUDIO_SESSION, MusicUtils.getAudioSessionId());
context.startActivity(effects);
// The google MusicFX apps need to be started using startActivityForResult
context.startActivityForResult(createEffectsIntent(), requestCode);
} catch (final ActivityNotFoundException notFound) {
CustomToast.makeText(context, context.getString(R.string.no_effects_for_you), CustomToast.LENGTH_SHORT).show();
CustomToast.makeText(context, context.getString(R.string.no_effects_for_you),
CustomToast.LENGTH_SHORT).show();
}
}
/**
* @return true if there is an effects panel/DSK Manager
*/
public static boolean hasEffectsPanel(final Activity activity) {
final PackageManager packageManager = activity.getPackageManager();
return packageManager.resolveActivity(createEffectsIntent(),
PackageManager.MATCH_DEFAULT_ONLY) != null;
}
/**
* Opens to {@link SettingsActivity}.
*
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment