Merge "Fix log syntax." into jb-mr1-dev
diff --git a/samples/ApiDemos/res/layout/presentation_content.xml b/samples/ApiDemos/res/layout/presentation_content.xml
index 7e9aaa0..6076aa6 100644
--- a/samples/ApiDemos/res/layout/presentation_content.xml
+++ b/samples/ApiDemos/res/layout/presentation_content.xml
@@ -19,8 +19,7 @@
 
 <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
         android:layout_width="match_parent"
-        android:layout_height="match_parent"
-        android:orientation="vertical">
+        android:layout_height="match_parent">
 
     <!-- A picture for visual interest. -->
     <ImageView android:id="@+id/image"
@@ -32,6 +31,6 @@
         android:layout_width="match_parent"
         android:layout_height="match_parent"
         android:gravity="center_vertical|center_horizontal"
-        android:textAppearance="?android:attr/textAppearanceMedium"/>
+        android:textAppearance="?android:attr/textAppearanceLarge"/>
 
 </FrameLayout>
diff --git a/samples/ApiDemos/res/layout/presentation_list_item.xml b/samples/ApiDemos/res/layout/presentation_list_item.xml
new file mode 100644
index 0000000..d28b5d9
--- /dev/null
+++ b/samples/ApiDemos/res/layout/presentation_list_item.xml
@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2012 The Android Open Source Project
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     You may obtain a copy of the License at
+
+          http://www.apache.org/licenses/LICENSE-2.0
+
+     Unless required by applicable law or agreed to in writing, software
+     distributed under the License is distributed on an "AS IS" BASIS,
+     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     See the License for the specific language governing permissions and
+     limitations under the License.
+-->
+
+<!-- The content that we show on secondary displays.
+     See corresponding Java code PresentationActivity.java. -->
+
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+        android:layout_width="match_parent"
+        android:layout_height="match_parent"
+        android:orientation="horizontal">
+
+    <CheckBox
+        android:id="@+id/checkbox_presentation"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_alignParentLeft="true"
+        android:layout_centerVertical="true"
+        android:layout_marginRight="16dip"/>
+
+    <TextView android:id="@+id/display_id"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_toRightOf="@id/checkbox_presentation"
+        android:layout_centerVertical="true"
+        android:textAppearance="?android:attr/textAppearanceLarge"/>
+
+    <Button android:id="@+id/info"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_alignParentRight="true"
+        android:layout_centerVertical="true"
+        android:textAppearance="?android:attr/textAppearanceMedium"
+        android:text="@string/presentation_info_text"/>
+
+</RelativeLayout>
diff --git a/samples/ApiDemos/res/values/strings.xml b/samples/ApiDemos/res/values/strings.xml
index 64fc5ff..04c7dc3 100644
--- a/samples/ApiDemos/res/values/strings.xml
+++ b/samples/ApiDemos/res/values/strings.xml
@@ -113,8 +113,14 @@
     <string name="apply">Apply</string>
 
     <string name="activity_presentation">App/Activity/Presentation</string>
-    <string name="presentation_activity_text">This activity demonstrates how to use the Presentation activity to show content on other Displays.  Try connecting a secondary display and watch what happens.</string>
+    <string name="presentation_activity_text">This activity demonstrates how to use the Presentation activity to show content on other Displays.\n
+                  Try connecting a secondary display and watch what happens.\n
+                  Selecting a Display will open a Presentation on it.</string>
     <string name="presentation_channel_text">You\'re watching channel %1$d on display %2$d.</string>
+    <string name="presentation_info_text">Info</string>
+    <string name="presentation_display_id_text">Display #%1$d</string>
+    <string name="presentation_alert_info_text">Display %1$d Info</string>
+    <string name="presentation_alert_dismiss_text">OK</string>
 
     <string name="fragment_alert_dialog">App/Fragment/Alert Dialog</string>
 
diff --git a/samples/ApiDemos/src/com/example/android/apis/app/PresentationActivity.java b/samples/ApiDemos/src/com/example/android/apis/app/PresentationActivity.java
index e7e043b..93647bf 100644
--- a/samples/ApiDemos/src/com/example/android/apis/app/PresentationActivity.java
+++ b/samples/ApiDemos/src/com/example/android/apis/app/PresentationActivity.java
@@ -21,19 +21,26 @@
 import com.example.android.apis.R;
 
 import android.app.Activity;
+import android.app.AlertDialog;
 import android.app.Presentation;
 import android.content.Context;
 import android.content.DialogInterface;
 import android.content.res.Resources;
+import android.graphics.Point;
+import android.graphics.drawable.GradientDrawable;
 import android.hardware.display.DisplayManager;
 import android.os.Bundle;
 import android.util.Log;
 import android.util.SparseArray;
 import android.view.Display;
 import android.view.View;
-import android.widget.AdapterView.OnItemClickListener;
-import android.widget.AdapterView;
+import android.view.View.OnClickListener;
+import android.view.ViewGroup;
+import android.widget.CheckBox;
+import android.widget.CompoundButton;
+import android.widget.CompoundButton.OnCheckedChangeListener;
 import android.widget.ArrayAdapter;
+import android.widget.Button;
 import android.widget.ImageView;
 import android.widget.ListView;
 import android.widget.TextView;
@@ -51,21 +58,27 @@
  * a few simulated secondary displays.
  * </p>
  */
-public class PresentationActivity extends Activity {
+public class PresentationActivity extends Activity
+        implements OnCheckedChangeListener, OnClickListener {
     private final String TAG = "PresentationActivity";
 
     // The content that we want to show on the presentation.
     private static final int[] CHANNELS = new int[] {
+        R.drawable.sample_4, R.drawable.frantic, R.drawable.beach,
         R.drawable.photo1, R.drawable.photo2, R.drawable.photo3,
         R.drawable.photo4, R.drawable.photo5, R.drawable.photo6,
     };
 
     private DisplayManager mDisplayManager;
-    private ListView mDisplayList;
     private DisplayListAdapter mDisplayListAdapter;
+    private ListView mListView;
     private int mNextChannelNumber;
 
-    // All active presentations indexed by display id.
+    // Indexed by displayId. Persists across pause/resume.
+    private final SparseArray<PresentationContents> mSavedPresentationContents =
+            new SparseArray<PresentationContents>();
+
+    // Indexed by displayId. Contains all currently displayed Presentations.
     private final SparseArray<DemoPresentation> mActivePresentations =
             new SparseArray<DemoPresentation>();
 
@@ -88,10 +101,8 @@
         setContentView(R.layout.presentation_activity);
 
         mDisplayListAdapter = new DisplayListAdapter(this);
-
-        mDisplayList = (ListView)findViewById(R.id.display_list);
-        mDisplayList.setAdapter(mDisplayListAdapter);
-        mDisplayList.setOnItemClickListener(mOnItemClickListener);
+        mListView = (ListView)findViewById(R.id.display_list);
+        mListView.setAdapter(mDisplayListAdapter);
     }
 
     @Override
@@ -102,6 +113,17 @@
         // Update our list of displays on resume.
         mDisplayListAdapter.updateContents();
 
+        final int numDisplays = mDisplayListAdapter.getCount();
+        for (int i = 0; i < numDisplays; i++) {
+            final Display display = mDisplayListAdapter.getItem(i);
+            final PresentationContents contents =
+                    mSavedPresentationContents.get(display.getDisplayId());
+            if (contents != null) {
+                showPresentation(display, contents);
+            }
+        }
+        mSavedPresentationContents.clear();
+
         // Register to receive events from the display manager.
         mDisplayManager.registerDisplayListener(mDisplayListener, null);
     }
@@ -115,9 +137,11 @@
         mDisplayManager.unregisterDisplayListener(mDisplayListener);
 
         // Dismiss all of our presentations.
-        Log.d(TAG, "Activity is being paused.  Dimissing all active presentation.");
+        Log.d(TAG, "Activity is being paused.  Dismissing all active presentation.");
         for (int i = 0; i < mActivePresentations.size(); i++) {
-            Presentation presentation = mActivePresentations.valueAt(i);
+            DemoPresentation presentation = mActivePresentations.valueAt(i);
+            int displayId = mActivePresentations.keyAt(i);
+            mSavedPresentationContents.put(displayId, presentation.mContents);
             presentation.dismiss();
         }
         mActivePresentations.clear();
@@ -126,38 +150,74 @@
     /**
      * Shows a {@link Presentation} on the specified display.
      */
-    private void showPresentation(Display display) {
-        // Do nothing if there is already a presentation showing on the display.
-        if (mActivePresentations.get(display.getDisplayId()) != null) {
+    private void showPresentation(Display display, PresentationContents contents) {
+        final int displayId = display.getDisplayId();
+        if (mActivePresentations.get(displayId) != null) {
             return;
         }
 
-        Log.d(TAG, "Showing presentation on display " + display.getDisplayId() + ".");
+        Log.d(TAG, "Showing presentation channel " + contents.channel
+                + " on display " + displayId + ".");
 
-        int channelNumber = mNextChannelNumber;
-        mNextChannelNumber = (mNextChannelNumber + 1) % CHANNELS.length;
-
-        final DemoPresentation presentation = new DemoPresentation(this, display, channelNumber);
-        mActivePresentations.put(display.getDisplayId(), presentation);
+        DemoPresentation presentation = new DemoPresentation(this, display, contents);
         presentation.show();
         presentation.setOnDismissListener(mOnDismissListener);
+        mActivePresentations.put(displayId, presentation);
     }
 
     /**
-     * Shows a {@link Presentation} on the specified display, or dismisses it if one
-     * already showing there.
+     * Hides a {@link Presentation} on the specified display.
      */
-    private void showOrDismissPresentation(Display display) {
-        // Dismiss if already showing.
-        DemoPresentation presentation = mActivePresentations.get(display.getDisplayId());
-        if (presentation != null) {
-            Log.d(TAG, "Dimissing presentation on display " + display.getDisplayId() + ".");
-            presentation.dismiss();
+    private void hidePresentation(Display display) {
+        final int displayId = display.getDisplayId();
+        DemoPresentation presentation = mActivePresentations.get(displayId);
+        if (presentation == null) {
             return;
         }
 
-        // Otherwise show the presentation.
-        showPresentation(display);
+        Log.d(TAG, "Dismissing presentation on display " + displayId + ".");
+
+        presentation.dismiss();
+        mActivePresentations.delete(displayId);
+    }
+
+    private int getNextChannel() {
+        mNextChannelNumber = (mNextChannelNumber + 1) % CHANNELS.length;
+        return mNextChannelNumber;
+    }
+
+    @Override
+    /** Presentation CheckBox */
+    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
+        final Display display = (Display)buttonView.getTag();
+        if (isChecked) {
+            PresentationContents contents = new PresentationContents(getNextChannel());
+            showPresentation(display, contents);
+        } else {
+            hidePresentation(display);
+        }
+    }
+
+    @Override
+    /** Info Button */
+    public void onClick(View v) {
+        Context context = v.getContext();
+        AlertDialog.Builder builder = new AlertDialog.Builder(context);
+        final Display display = (Display)v.getTag();
+        Resources r = context.getResources();
+        AlertDialog alert = builder
+                .setTitle(r.getString(
+                        R.string.presentation_alert_info_text, display.getDisplayId()))
+                .setMessage(display.toString())
+                .setNeutralButton(R.string.presentation_alert_dismiss_text,
+                        new DialogInterface.OnClickListener() {
+                            @Override
+                            public void onClick(DialogInterface dialog, int which) {
+                                dialog.dismiss();
+                            }
+                    })
+                .create();
+        alert.show();
     }
 
     /**
@@ -175,11 +235,6 @@
         public void onDisplayAdded(int displayId) {
             Log.d(TAG, "Display " + displayId + " added.");
             mDisplayListAdapter.updateContents();
-
-            Display display = mDisplayManager.getDisplay(displayId);
-            if (display != null) {
-                showPresentation(display);
-            }
         }
 
         @Override
@@ -203,9 +258,10 @@
         @Override
         public void onDismiss(DialogInterface dialog) {
             DemoPresentation presentation = (DemoPresentation)dialog;
-            Display display = presentation.getDisplay();
-            Log.d(TAG, "Presentation on display " + display.getDisplayId() + " was dismissed.");
-            mActivePresentations.remove(display.getDisplayId());
+            int displayId = presentation.getDisplay().getDisplayId();
+            Log.d(TAG, "Presentation on display " + displayId + " was dismissed.");
+            mActivePresentations.delete(displayId);
+            mDisplayListAdapter.notifyDataSetChanged();
         }
     };
 
@@ -214,8 +270,41 @@
      * Shows information about all displays.
      */
     private final class DisplayListAdapter extends ArrayAdapter<Display> {
+        final Context mContext;
+
         public DisplayListAdapter(Context context) {
-            super(context, android.R.layout.simple_list_item_1);
+            super(context, R.layout.presentation_list_item);
+            mContext = context;
+        }
+
+        @Override
+        public View getView(int position, View convertView, ViewGroup parent) {
+            final View v;
+            if (convertView == null) {
+                v = ((Activity) mContext).getLayoutInflater().inflate(
+                        R.layout.presentation_list_item, null);
+            } else {
+                v = convertView;
+            }
+
+            final Display display = getItem(position);
+            final int displayId = display.getDisplayId();
+
+            CheckBox cb = (CheckBox)v.findViewById(R.id.checkbox_presentation);
+            cb.setTag(display);
+            cb.setOnCheckedChangeListener(PresentationActivity.this);
+            cb.setChecked(mActivePresentations.indexOfKey(displayId) >= 0
+                    || mSavedPresentationContents.indexOfKey(displayId) >= 0);
+
+            TextView tv = (TextView)v.findViewById(R.id.display_id);
+            tv.setText(v.getContext().getResources().getString(
+                    R.string.presentation_display_id_text, displayId));
+
+            Button b = (Button)v.findViewById(R.id.info);
+            b.setTag(display);
+            b.setOnClickListener(PresentationActivity.this);
+
+            return v;
         }
 
         /**
@@ -236,19 +325,6 @@
     }
 
     /**
-     * Called when an item in the display list is clicked.
-     *
-     * Causes a presentation to be shown or dismissed on that display if already showing.
-     */
-    private final OnItemClickListener mOnItemClickListener = new OnItemClickListener() {
-        @Override
-        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
-            Display display = (Display)parent.getItemAtPosition(position);
-            showOrDismissPresentation(display);
-        }
-    };
-
-    /**
      * The presentation to show on the secondary display.
      *
      * Note that this display may have different metrics from the display on which
@@ -256,12 +332,12 @@
      * own {@link Context} whenever we load resources.
      */
     private final class DemoPresentation extends Presentation {
-        // Specifies the content that we want to show in this presentation.
-        private final int mChannelNumber;
 
-        public DemoPresentation(Context context, Display display, int channelNumber) {
+        final PresentationContents mContents;
+
+        public DemoPresentation(Context context, Display display, PresentationContents contents) {
             super(context, display);
-            mChannelNumber = channelNumber;
+            mContents = contents;
         }
 
         @Override
@@ -276,14 +352,40 @@
             // Inflate the layout.
             setContentView(R.layout.presentation_content);
 
+            final Display display = getDisplay();
+            final int displayId = display.getDisplayId();
+            final int channel = mContents.channel;
+
             // Show a text message to describe what's going on.
             TextView text = (TextView)findViewById(R.id.text);
-            text.setText(r.getString(R.string.presentation_channel_text, mChannelNumber + 1,
-                    getDisplay().getDisplayId()));
+            text.setText(r.getString(R.string.presentation_channel_text, channel, displayId));
 
             // Show a n image for visual interest.
             ImageView image = (ImageView)findViewById(R.id.image);
-            image.setImageDrawable(r.getDrawable(CHANNELS[mChannelNumber]));
+            image.setImageDrawable(r.getDrawable(CHANNELS[channel]));
+
+            GradientDrawable drawable = new GradientDrawable();
+            drawable.setShape(GradientDrawable.RECTANGLE);
+            drawable.setGradientType(GradientDrawable.RADIAL_GRADIENT);
+
+            // Set the background to a random gradient.
+            Point p = new Point();
+            getDisplay().getSize(p);
+            drawable.setGradientRadius(Math.max(p.x, p.y) / 2);
+            drawable.setColors(mContents.colors);
+            findViewById(android.R.id.content).setBackground(drawable);
+        }
+    }
+
+    private final static class PresentationContents {
+        final int channel;
+        final int[] colors;
+
+        public PresentationContents(int channel) {
+            this.channel = channel;
+            colors = new int[] {
+                    ((int) (Math.random() * Integer.MAX_VALUE)) | 0xFF000000,
+                    ((int) (Math.random() * Integer.MAX_VALUE)) | 0xFF000000 };
         }
     }
 }
diff --git a/scripts/app_engine_server/redirects.yaml b/scripts/app_engine_server/redirects.yaml
index 23fbeb2..6309d96 100644
--- a/scripts/app_engine_server/redirects.yaml
+++ b/scripts/app_engine_server/redirects.yaml
@@ -440,7 +440,10 @@
   type: permanent
   comment: Redirect to new location
   
-  
+- src: /live/index.html
+  dst: https://developers.google.com/live/
+  type: permanent
+  comment: Redirect to new location