Use ActionBar for MusicFX, adjust text sizes

b/5447177

Change-Id: If8042879dd0f13d4747a7fbc9247cefa0fa60155
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 361f2d7..ad51ebc 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -32,7 +32,7 @@
         <activity
             android:name=".ActivityMusic"
             android:theme="@android:style/Theme.Holo"
-            android:label="@string/app_name">
+            android:label="@string/eq_dialog_title">
             <intent-filter>
                 <action
                     android:name="android.media.action.DISPLAY_AUDIO_EFFECT_CONTROL_PANEL" />
diff --git a/res/layout-land/music_main.xml b/res/layout-land/music_main.xml
index fc3eacb..11fcf5e 100644
--- a/res/layout-land/music_main.xml
+++ b/res/layout-land/music_main.xml
@@ -33,28 +33,6 @@
         android:layout_weight="1"
         android:visibility="gone" />
 
-    <RelativeLayout
-        android:id="@+id/mainToggleEffectsLayout"
-        android:layout_width="match_parent"
-        android:layout_height="50dip"
-        android:background="#999"
-        android:gravity="center_vertical"
-        android:paddingRight="4dip">
-        <TextView
-            android:id="@+id/mainToggleEffectsTitleTextView"
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            android:layout_marginLeft="15dip"
-            android:layout_alignParentLeft="true"
-            android:textAppearance="?android:attr/textAppearanceLarge"
-            android:text="@string/eq_dialog_title" />
-        <Switch
-            android:id="@+id/mainToggleEffectsCheckBox"
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            android:layout_alignParentRight="true" />
-    </RelativeLayout>
-
     <FrameLayout
         android:id="@+id/contentSoundEffects"
         android:layout_width="match_parent"
diff --git a/res/layout/music_main.xml b/res/layout/music_main.xml
index 90c23ff..367d5a2 100644
--- a/res/layout/music_main.xml
+++ b/res/layout/music_main.xml
@@ -33,28 +33,6 @@
         android:layout_weight="1"
         android:visibility="gone" />
 
-    <RelativeLayout
-        android:id="@+id/mainToggleEffectsLayout"
-        android:layout_width="match_parent"
-        android:layout_height="50dip"
-        android:background="#999"
-        android:gravity="center_vertical"
-        android:paddingRight="4dip">
-        <TextView
-            android:id="@+id/mainToggleEffectsTitleTextView"
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            android:layout_marginLeft="15dip"
-            android:layout_alignParentLeft="true"
-            android:textAppearance="?android:attr/textAppearanceLarge"
-            android:text="@string/eq_dialog_title" />
-        <Switch
-            android:id="@+id/mainToggleEffectsCheckBox"
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            android:layout_alignParentRight="true" />
-    </RelativeLayout>
-
     <ScrollView
         android:id="@+id/contentSoundEffects"
         android:orientation="vertical"
@@ -94,7 +72,7 @@
                     android:layout_width="wrap_content"
                     android:layout_height="wrap_content"
                     android:layout_weight="1"
-                    android:textAppearance="?android:attr/textAppearanceLarge"
+                    android:textAppearance="?android:attr/textAppearanceMedium"
                     android:ellipsize="marquee"
                     android:fadingEdge="horizontal"
                     android:text="@string/bass_boost_strength" />
@@ -125,7 +103,7 @@
                     android:layout_width="wrap_content"
                     android:layout_height="wrap_content"
                     android:layout_weight="1"
-                    android:textAppearance="?android:attr/textAppearanceLarge"
+                    android:textAppearance="?android:attr/textAppearanceMedium"
                     android:ellipsize="marquee"
                     android:fadingEdge="horizontal"
                     android:text="@string/virtualizer_strength" />
diff --git a/res/values/dimens.xml b/res/values/dimens.xml
index 11789cb..4e640ba 100644
--- a/res/values/dimens.xml
+++ b/res/values/dimens.xml
@@ -17,4 +17,5 @@
 <resources>
     <dimen name="eq_slider_margin">5dip</dimen>
     <dimen name="eq_slider_height">180dip</dimen>
+    <dimen name="action_bar_switch_padding">16dip</dimen>
 </resources>
diff --git a/src/com/android/musicfx/ActivityMusic.java b/src/com/android/musicfx/ActivityMusic.java
index 8e9dab2..6a4afa3 100644
--- a/src/com/android/musicfx/ActivityMusic.java
+++ b/src/com/android/musicfx/ActivityMusic.java
@@ -20,6 +20,7 @@
 import com.android.musicfx.seekbar.SeekBar;
 import com.android.musicfx.seekbar.SeekBar.OnSeekBarChangeListener;
 
+import android.app.ActionBar;
 import android.app.Activity;
 import android.app.AlertDialog;
 import android.app.Dialog;
@@ -52,6 +53,7 @@
 import android.widget.ListView;
 import android.widget.RelativeLayout;
 import android.widget.Spinner;
+import android.widget.Switch;
 import android.widget.TextView;
 import android.widget.Toast;
 
@@ -100,6 +102,7 @@
     private int mPRPresetPrevious;
 
     private boolean mIsHeadsetOn = false;
+    private CompoundButton mToggleSwitch;
 
     private StringBuilder mFormatBuilder = new StringBuilder();
     private Formatter mFormatter = new Formatter(mFormatBuilder, Locale.getDefault());
@@ -256,7 +259,6 @@
 
         setContentView(R.layout.music_main);
         final ViewGroup viewGroup = (ViewGroup) findViewById(R.id.contentSoundEffects);
-        final View mainToggleView = findViewById(R.id.mainToggleEffectsLayout);
 
         // Fill array with presets from AudioEffects call.
         // allocate a space for 2 extra strings (CI Extreme & User)
@@ -277,8 +279,8 @@
             // Set the listener for the main enhancements toggle button.
             // Depending on the state enable the supported effects if they were
             // checked in the setup tab.
-            final CompoundButton toggleEffects = (CompoundButton) findViewById(R.id.mainToggleEffectsCheckBox);
-            toggleEffects.setOnCheckedChangeListener(new OnCheckedChangeListener() {
+            mToggleSwitch = new Switch(this);
+            mToggleSwitch.setOnCheckedChangeListener(new OnCheckedChangeListener() {
                 @Override
                 public void onCheckedChanged(final CompoundButton buttonView,
                         final boolean isChecked) {
@@ -294,8 +296,6 @@
                 }
             });
 
-            mainToggleView.setVisibility(View.VISIBLE);
-
             // Initialize the Virtualizer elements.
             // Set the SeekBar listener.
             if (mVirtualizerSupported) {
@@ -424,12 +424,18 @@
 
         } else {
             viewGroup.setVisibility(View.GONE);
-            mainToggleView.setVisibility(View.GONE);
             ((TextView) findViewById(R.id.noEffectsTextView)).setVisibility(View.VISIBLE);
         }
 
-        // TODO, actually use the action bar
-        getActionBar().hide();
+        ActionBar ab = getActionBar();
+        final int padding = getResources().getDimensionPixelSize(
+                R.dimen.action_bar_switch_padding);
+        mToggleSwitch.setPadding(0,0, padding, 0);
+        ab.setCustomView(mToggleSwitch, new ActionBar.LayoutParams(
+                ActionBar.LayoutParams.WRAP_CONTENT,
+                ActionBar.LayoutParams.WRAP_CONTENT,
+                Gravity.CENTER_VERTICAL | Gravity.RIGHT));
+        ab.setDisplayOptions(ActionBar.DISPLAY_SHOW_TITLE | ActionBar.DISPLAY_SHOW_CUSTOM);
     }
 
     /*
@@ -543,7 +549,7 @@
     private void updateUI() {
         final boolean isEnabled = ControlPanelEffect.getParameterBoolean(mContext,
                 mCallingPackageName, mAudioSession, ControlPanelEffect.Key.global_enabled);
-        ((CompoundButton) findViewById(R.id.mainToggleEffectsCheckBox)).setChecked(isEnabled);
+        mToggleSwitch.setChecked(isEnabled);
         setEnabledAllChildren((ViewGroup) findViewById(R.id.contentSoundEffects), isEnabled);
         updateUIHeadset();
 
@@ -574,7 +580,7 @@
      * control/events.
      */
     private void updateUIHeadset() {
-        if (((CompoundButton) findViewById(R.id.mainToggleEffectsCheckBox)).isChecked()) {
+        if (mToggleSwitch.isChecked()) {
             ((TextView) findViewById(R.id.vIStrengthText)).setEnabled(mIsHeadsetOn);
             ((SeekBar) findViewById(R.id.vIStrengthSeekBar)).setEnabled(mIsHeadsetOn);
             findViewById(R.id.vILayout).setEnabled(!mIsHeadsetOn);