Showcase app: Fixed video fragment not showing video. Updated Settings
and deprecated APIs for the app to be installable on L.

Video player was not being prepared for asynchronous playing after the
media source was set. Used the same preparation module for both the
Music and Video players.
Also, updated Settings to include a switch widget. Depredatecd some of
the APIs to level 1 to be able to install app on L.

Change-Id: I3bd8b266be028e80d87367a2c3c8a8174e924b92
diff --git a/samples/SupportLeanbackShowcase/app/src/main/java/android/support/v17/leanback/supportleanbackshowcase/app/media/MediaPlayerGlue.java b/samples/SupportLeanbackShowcase/app/src/main/java/android/support/v17/leanback/supportleanbackshowcase/app/media/MediaPlayerGlue.java
index 7713c1a..f64899e 100644
--- a/samples/SupportLeanbackShowcase/app/src/main/java/android/support/v17/leanback/supportleanbackshowcase/app/media/MediaPlayerGlue.java
+++ b/samples/SupportLeanbackShowcase/app/src/main/java/android/support/v17/leanback/supportleanbackshowcase/app/media/MediaPlayerGlue.java
@@ -133,8 +133,10 @@
      */
     public void setupControlsRowPresenter(PlaybackControlsRowPresenter presenter) {
         // TODO: hahnr@ move into resources
-        presenter.setProgressColor(getContext().getColor(R.color.player_progress_color));
-        presenter.setBackgroundColor(getContext().getColor(R.color.player_background_color));
+        presenter.setProgressColor(getContext().getResources().getColor(
+                R.color.player_progress_color));
+        presenter.setBackgroundColor(getContext().getResources().getColor(
+                R.color.player_background_color));
     }
 
     @Override public PlaybackControlsRowPresenter createControlsRowAndPresenter() {
@@ -284,13 +286,34 @@
     }
 
     /**
-     * @see MediaPlayer#setDataSource(Context, Uri)
+     * Sets the media source of the player witha given URI.
+     * @see MediaPlayer#setDataSource(String)
+     * @return Returns <code>true</code> if uri represents a new media; <code>false</code>
+     * otherwise.
      */
-    public void setMediaSource(Uri uri) {
+    public boolean setMediaSource(Uri uri) {
         if (mMediaSourceUri != null && mMediaSourceUri.equals(uri)) {
-            return;
+            return false;
         }
         mMediaSourceUri = uri;
+        return true;
+    }
+
+    /**
+     * Sets the media source of the player with a String path URL.
+     * @see MediaPlayer#setDataSource(String)
+     * @return Returns <code>true</code> if path represents a new media; <code>false</code>
+     * otherwise.
+     */
+    public boolean setMediaSource(String path) {
+        if (mMediaSourcePath != null && mMediaSourcePath.equals(mMediaSourcePath)) {
+            return false;
+        }
+        mMediaSourcePath = path;
+        return true;
+    }
+
+    public void prepareMediaForPlaying() {
         reset();
         try {
             if (mMediaSourceUri != null) mPlayer.setDataSource(getContext(), mMediaSourceUri);
@@ -324,13 +347,6 @@
     }
 
     /**
-     * @see MediaPlayer#setDataSource(String)
-     */
-    public void setMediaSource(String path) {
-        mMediaSourcePath = path;
-    }
-
-    /**
      * Call to <code>startPlayback(1)</code>.
      *
      * @throws IllegalStateException See {@link MediaPlayer} for further information about it's
diff --git a/samples/SupportLeanbackShowcase/app/src/main/java/android/support/v17/leanback/supportleanbackshowcase/app/media/MusicConsumptionExampleFragment.java b/samples/SupportLeanbackShowcase/app/src/main/java/android/support/v17/leanback/supportleanbackshowcase/app/media/MusicConsumptionExampleFragment.java
index 885ebd7..0650cfc 100644
--- a/samples/SupportLeanbackShowcase/app/src/main/java/android/support/v17/leanback/supportleanbackshowcase/app/media/MusicConsumptionExampleFragment.java
+++ b/samples/SupportLeanbackShowcase/app/src/main/java/android/support/v17/leanback/supportleanbackshowcase/app/media/MusicConsumptionExampleFragment.java
@@ -105,6 +105,7 @@
         Uri uri = Utils.getResourceUri(getActivity(), song.getFileResource(getActivity()));
         mGlue.setMetaData(metaData);
         mGlue.setMediaSource(uri);
+        mGlue.prepareMediaForPlaying();
 
         addPlaybackControlsRow();
     }
@@ -149,11 +150,12 @@
                 vh.getMediaItemNameView().setTextColor(favoriteTextColor);
                 vh.getMediaItemDurationView().setTextColor(favoriteTextColor);
             } else {
-                vh.getMediaItemNumberView().setTextAppearance(
+                Context context = vh.getMediaItemNumberView().getContext();
+                vh.getMediaItemNumberView().setTextAppearance(context,
                         R.style.TextAppearance_Leanback_PlaybackMediaItemNumber);
-                vh.getMediaItemNameView().setTextAppearance(
+                vh.getMediaItemNameView().setTextAppearance(context,
                         R.style.TextAppearance_Leanback_PlaybackMediaItemName);
-                vh.getMediaItemDurationView().setTextAppearance(
+                vh.getMediaItemDurationView().setTextAppearance(context,
                         R.style.TextAppearance_Leanback_PlaybackMediaItemDuration);
             }
         }
@@ -302,7 +304,10 @@
 
         Uri uri = Utils.getResourceUri(getActivity(), song.getFileResource(getActivity()));
         mGlue.setMetaData(metaData);
-        mGlue.setMediaSource(uri);
+
+        if (mGlue.setMediaSource(uri)) {
+            mGlue.prepareMediaForPlaying();
+        }
         mGlue.startPlayback();
     }
 }
diff --git a/samples/SupportLeanbackShowcase/app/src/main/java/android/support/v17/leanback/supportleanbackshowcase/app/media/VideoConsumptionExampleFragment.java b/samples/SupportLeanbackShowcase/app/src/main/java/android/support/v17/leanback/supportleanbackshowcase/app/media/VideoConsumptionExampleFragment.java
index dec3913..ca33b42 100644
--- a/samples/SupportLeanbackShowcase/app/src/main/java/android/support/v17/leanback/supportleanbackshowcase/app/media/VideoConsumptionExampleFragment.java
+++ b/samples/SupportLeanbackShowcase/app/src/main/java/android/support/v17/leanback/supportleanbackshowcase/app/media/VideoConsumptionExampleFragment.java
@@ -55,6 +55,7 @@
         metaData.setTitle("Diving with Sharks");
         mGlue.setMetaData(metaData);
         mGlue.setMediaSource(URL);
+        mGlue.prepareMediaForPlaying();
 
 
         Fragment videoSurfaceFragment = getFragmentManager()
diff --git a/samples/SupportLeanbackShowcase/app/src/main/res/xml/prefs.xml b/samples/SupportLeanbackShowcase/app/src/main/res/xml/prefs.xml
index e69c4e2..f0edd0e 100644
--- a/samples/SupportLeanbackShowcase/app/src/main/res/xml/prefs.xml
+++ b/samples/SupportLeanbackShowcase/app/src/main/res/xml/prefs.xml
@@ -87,9 +87,9 @@
                 <Preference
                     android:selectable="false"
                     android:summary="Hier steht ein voelligst sinnfreier Text den ja sowieso niemandhier lesen kann. Deshalb macht es auch keinen Unterschied ob hier sinnvolles und nicht so sinnvolles Zeug steht. Hm... Sasha, du kannst das vielleicht lesen und denkst dir jetzt auch, dass ich voll haengen geblieben bin, oder?... ^_^"></Preference>
-                <Preference
-                    android:title="Force Stop"
-                    android:key="pref_force_stop"><!-- Start an Intent --></Preference>
+                <SwitchPreference
+                    android:title="Notifications"
+                    android:key="pref_force_stop"><!-- Start an Intent --></SwitchPreference>
                 <Preference
                     android:title="Uninstall"
                     android:key="pref_uninstall"><!-- Start an Intent --></Preference>