Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

samples of Presentation

  • Loading branch information...
commit ed2865fbceb4920f5dddbdc790a8ddf1f3d8f4ee 1 parent 13d9d08
@commonsguy authored
Showing with 892 additions and 0 deletions.
  1. +8 −0 Presentation/Fragment/.classpath
  2. +33 −0 Presentation/Fragment/.project
  3. +28 −0 Presentation/Fragment/AndroidManifest.xml
  4. BIN  Presentation/Fragment/libs/android-support-v4.jar
  5. +20 −0 Presentation/Fragment/proguard-project.txt
  6. +14 −0 Presentation/Fragment/project.properties
  7. BIN  Presentation/Fragment/res/drawable-hdpi/ic_launcher.png
  8. BIN  Presentation/Fragment/res/drawable-ldpi/ic_launcher.png
  9. BIN  Presentation/Fragment/res/drawable-mdpi/ic_launcher.png
  10. BIN  Presentation/Fragment/res/drawable-xhdpi/ic_launcher.png
  11. +25 −0 Presentation/Fragment/res/layout/activity_main.xml
  12. +8 −0 Presentation/Fragment/res/values-sw600dp/dimens.xml
  13. +9 −0 Presentation/Fragment/res/values-sw720dp-land/dimens.xml
  14. +11 −0 Presentation/Fragment/res/values-v11/styles.xml
  15. +12 −0 Presentation/Fragment/res/values-v14/styles.xml
  16. +7 −0 Presentation/Fragment/res/values/dimens.xml
  17. +8 −0 Presentation/Fragment/res/values/strings.xml
  18. +20 −0 Presentation/Fragment/res/values/styles.xml
  19. +137 −0 Presentation/Fragment/src/com/commonsware/android/preso/fragment/MainActivity.java
  20. +59 −0 Presentation/Fragment/src/com/commonsware/android/preso/fragment/PresentationFragment.java
  21. +53 −0 Presentation/Fragment/src/com/commonsware/android/preso/fragment/SamplePresentationFragment.java
  22. +107 −0 Presentation/Fragment/src/com/commonsware/android/preso/fragment/WebPresentationFragment.java
  23. +8 −0 Presentation/Simple/.classpath
  24. +33 −0 Presentation/Simple/.project
  25. +28 −0 Presentation/Simple/AndroidManifest.xml
  26. BIN  Presentation/Simple/libs/android-support-v4.jar
  27. +20 −0 Presentation/Simple/proguard-project.txt
  28. +14 −0 Presentation/Simple/project.properties
  29. BIN  Presentation/Simple/res/drawable-hdpi/ic_launcher.png
  30. BIN  Presentation/Simple/res/drawable-ldpi/ic_launcher.png
  31. BIN  Presentation/Simple/res/drawable-mdpi/ic_launcher.png
  32. BIN  Presentation/Simple/res/drawable-xhdpi/ic_launcher.png
  33. +15 −0 Presentation/Simple/res/layout/activity_main.xml
  34. +8 −0 Presentation/Simple/res/values-sw600dp/dimens.xml
  35. +9 −0 Presentation/Simple/res/values-sw720dp-land/dimens.xml
  36. +11 −0 Presentation/Simple/res/values-v11/styles.xml
  37. +12 −0 Presentation/Simple/res/values-v14/styles.xml
  38. +7 −0 Presentation/Simple/res/values/dimens.xml
  39. +7 −0 Presentation/Simple/res/values/strings.xml
  40. +20 −0 Presentation/Simple/res/values/styles.xml
  41. +141 −0 Presentation/Simple/src/com/commonsware/android/preso/simple/MainActivity.java
View
8 Presentation/Fragment/.classpath
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="src" path="gen"/>
+ <classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
+ <classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
+ <classpathentry kind="output" path="bin/classes"/>
+</classpath>
View
33 Presentation/Fragment/.project
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>FragmentPresentationDemo</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>com.android.ide.eclipse.adt.ApkBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>com.android.ide.eclipse.adt.AndroidNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
View
28 Presentation/Fragment/AndroidManifest.xml
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="utf-8"?>
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.commonsware.android.preso.fragment"
+ android:versionCode="1"
+ android:versionName="1.0">
+
+ <uses-sdk
+ android:minSdkVersion="17"
+ android:targetSdkVersion="17"/>
+ <uses-permission android:name="android.permission.INTERNET"/>
+
+ <application
+ android:allowBackup="true"
+ android:icon="@drawable/ic_launcher"
+ android:label="@string/app_name"
+ android:theme="@style/AppTheme">
+ <activity
+ android:name="com.commonsware.android.preso.fragment.MainActivity"
+ android:label="@string/app_name">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN"/>
+
+ <category android:name="android.intent.category.LAUNCHER"/>
+ </intent-filter>
+ </activity>
+ </application>
+
+</manifest>
View
BIN  Presentation/Fragment/libs/android-support-v4.jar
Binary file not shown
View
20 Presentation/Fragment/proguard-project.txt
@@ -0,0 +1,20 @@
+# To enable ProGuard in your project, edit project.properties
+# to define the proguard.config property as described in that file.
+#
+# Add project specific ProGuard rules here.
+# By default, the flags in this file are appended to flags specified
+# in ${sdk.dir}/tools/proguard/proguard-android.txt
+# You can edit the include path and order by changing the ProGuard
+# include property in project.properties.
+#
+# For more details, see
+# http://developer.android.com/guide/developing/tools/proguard.html
+
+# Add any project specific keep options here:
+
+# If your project uses WebView with JS, uncomment the following
+# and specify the fully qualified class name to the JavaScript interface
+# class:
+#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
+# public *;
+#}
View
14 Presentation/Fragment/project.properties
@@ -0,0 +1,14 @@
+# This file is automatically generated by Android Tools.
+# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
+#
+# This file must be checked in Version Control Systems.
+#
+# To customize properties used by the Ant build system edit
+# "ant.properties", and override values to adapt the script to your
+# project structure.
+#
+# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
+#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
+
+# Project target.
+target=android-17
View
BIN  Presentation/Fragment/res/drawable-hdpi/ic_launcher.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  Presentation/Fragment/res/drawable-ldpi/ic_launcher.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  Presentation/Fragment/res/drawable-mdpi/ic_launcher.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  Presentation/Fragment/res/drawable-xhdpi/ic_launcher.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
25 Presentation/Fragment/res/layout/activity_main.xml
@@ -0,0 +1,25 @@
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:tools="http://schemas.android.com/tools"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:orientation="horizontal"
+ tools:context=".MainActivity">
+
+ <TextView
+ android:id="@+id/prose"
+ android:layout_width="0px"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center"
+ android:layout_weight="1"
+ android:gravity="center"
+ android:text="@string/secondary"
+ android:textSize="40sp"/>
+
+ <FrameLayout
+ android:id="@+id/preso"
+ android:layout_width="0px"
+ android:layout_height="match_parent"
+ android:layout_weight="1"
+ android:visibility="gone"/>
+
+</LinearLayout>
View
8 Presentation/Fragment/res/values-sw600dp/dimens.xml
@@ -0,0 +1,8 @@
+<resources>
+
+ <!--
+ Customize dimensions originally defined in res/values/dimens.xml (such as
+ screen margins) for sw600dp devices (e.g. 7" tablets) here.
+ -->
+
+</resources>
View
9 Presentation/Fragment/res/values-sw720dp-land/dimens.xml
@@ -0,0 +1,9 @@
+<resources>
+
+ <!--
+ Customize dimensions originally defined in res/values/dimens.xml (such as
+ screen margins) for sw720dp devices (e.g. 10" tablets) in landscape here.
+ -->
+ <dimen name="activity_horizontal_margin">128dp</dimen>
+
+</resources>
View
11 Presentation/Fragment/res/values-v11/styles.xml
@@ -0,0 +1,11 @@
+<resources>
+
+ <!--
+ Base application theme for API 11+. This theme completely replaces
+ AppBaseTheme from res/values/styles.xml on API 11+ devices.
+ -->
+ <style name="AppBaseTheme" parent="android:Theme.Holo.Light">
+ <!-- API 11 theme customizations can go here. -->
+ </style>
+
+</resources>
View
12 Presentation/Fragment/res/values-v14/styles.xml
@@ -0,0 +1,12 @@
+<resources>
+
+ <!--
+ Base application theme for API 14+. This theme completely replaces
+ AppBaseTheme from BOTH res/values/styles.xml and
+ res/values-v11/styles.xml on API 14+ devices.
+ -->
+ <style name="AppBaseTheme" parent="android:Theme.Holo.Light.DarkActionBar">
+ <!-- API 14 theme customizations can go here. -->
+ </style>
+
+</resources>
View
7 Presentation/Fragment/res/values/dimens.xml
@@ -0,0 +1,7 @@
+<resources>
+
+ <!-- Default screen margins, per the Android Design guidelines. -->
+ <dimen name="activity_horizontal_margin">16dp</dimen>
+ <dimen name="activity_vertical_margin">16dp</dimen>
+
+</resources>
View
8 Presentation/Fragment/res/values/strings.xml
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+
+ <string name="app_name">Fragment Presentation Demo</string>
+ <string name="secondary">You should see a Web page on the secondary display!</string>
+ <string name="primary">You should see a Web page to the right!</string>
+
+</resources>
View
20 Presentation/Fragment/res/values/styles.xml
@@ -0,0 +1,20 @@
+<resources>
+
+ <!--
+ Base application theme, dependent on API level. This theme is replaced
+ by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
+ -->
+ <style name="AppBaseTheme" parent="android:Theme.Light">
+ <!--
+ Theme customizations available in newer API levels can go in
+ res/values-vXX/styles.xml, while customizations related to
+ backward-compatibility can go here.
+ -->
+ </style>
+
+ <!-- Application theme. -->
+ <style name="AppTheme" parent="AppBaseTheme">
+ <!-- All customizations that are NOT specific to a particular API-level can go here. -->
+ </style>
+
+</resources>
View
137 Presentation/Fragment/src/com/commonsware/android/preso/fragment/MainActivity.java
@@ -0,0 +1,137 @@
+/***
+ Copyright (c) 2013 CommonsWare, LLC
+ 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.
+
+ From _The Busy Coder's Guide to Android Development_
+ http://commonsware.com/Android
+ */
+
+package com.commonsware.android.preso.fragment;
+
+import android.app.Activity;
+import android.app.Fragment;
+import android.media.MediaRouter;
+import android.media.MediaRouter.RouteInfo;
+import android.media.MediaRouter.SimpleCallback;
+import android.os.Bundle;
+import android.util.Log;
+import android.view.Display;
+import android.view.View;
+import android.widget.TextView;
+
+public class MainActivity extends Activity {
+ MediaRouter router=null;
+ PresentationFragment preso=null;
+ SimpleCallback cb=null;
+ View inline=null;
+ TextView prose=null;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ setContentView(R.layout.activity_main);
+
+ inline=findViewById(R.id.preso);
+ prose=(TextView)findViewById(R.id.prose);
+ }
+
+ @Override
+ protected void onResume() {
+ super.onResume();
+
+ if (cb == null) {
+ cb=new RouteCallback();
+ router=(MediaRouter)getSystemService(MEDIA_ROUTER_SERVICE);
+ }
+
+ handleRoute(router.getSelectedRoute(MediaRouter.ROUTE_TYPE_LIVE_VIDEO));
+ router.addCallback(MediaRouter.ROUTE_TYPE_LIVE_VIDEO, cb);
+ }
+
+ @Override
+ protected void onPause() {
+ clearPreso(false);
+
+ if (router != null) {
+ router.removeCallback(cb);
+ }
+
+ super.onPause();
+ }
+
+ private void handleRoute(RouteInfo route) {
+ if (route == null) {
+ clearPreso(true);
+ }
+ else {
+ Display display=route.getPresentationDisplay();
+
+ if (route.isEnabled() && display != null) {
+ if (preso == null) {
+ showPreso(route);
+ Log.d(getClass().getSimpleName(), "enabled route");
+ }
+ else if (preso.getDisplay().getDisplayId() != display.getDisplayId()) {
+ clearPreso(true);
+ showPreso(route);
+ Log.d(getClass().getSimpleName(), "switched route");
+ }
+ else {
+ // no-op: should already be set
+ }
+ }
+ else {
+ clearPreso(true);
+ Log.d(getClass().getSimpleName(), "disabled route");
+ }
+ }
+ }
+
+ private void clearPreso(boolean switchToInline) {
+ if (switchToInline) {
+ inline.setVisibility(View.VISIBLE);
+ prose.setText(R.string.primary);
+ getFragmentManager().beginTransaction()
+ .add(R.id.preso, buildPreso(null)).commit();
+ }
+
+ if (preso != null) {
+ preso.dismiss();
+ preso=null;
+ }
+ }
+
+ private void showPreso(RouteInfo route) {
+ if (inline.getVisibility() == View.VISIBLE) {
+ inline.setVisibility(View.GONE);
+ prose.setText(R.string.secondary);
+
+ Fragment f=getFragmentManager().findFragmentById(R.id.preso);
+
+ getFragmentManager().beginTransaction().remove(f).commit();
+ }
+
+ preso=buildPreso(route.getPresentationDisplay());
+ preso.show(getFragmentManager(), "preso");
+ }
+
+ private PresentationFragment buildPreso(Display display) {
+ return(SamplePresentationFragment.newInstance(this, display,
+ "http://commonsware.com"));
+ }
+
+ private class RouteCallback extends SimpleCallback {
+ @Override
+ public void onRoutePresentationDisplayChanged(MediaRouter router,
+ RouteInfo route) {
+ handleRoute(route);
+ }
+ }
+}
View
59 Presentation/Fragment/src/com/commonsware/android/preso/fragment/PresentationFragment.java
@@ -0,0 +1,59 @@
+/***
+ Copyright (c) 2013 CommonsWare, LLC
+ 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.
+
+ From _The Busy Coder's Guide to Android Development_
+ http://commonsware.com/Android
+ */
+
+package com.commonsware.android.preso.fragment;
+
+import android.app.Dialog;
+import android.app.DialogFragment;
+import android.app.Presentation;
+import android.content.Context;
+import android.os.Bundle;
+import android.view.Display;
+
+abstract public class PresentationFragment extends DialogFragment {
+ private Display display=null;
+ private Presentation preso=null;
+
+ @Override
+ public Dialog onCreateDialog(Bundle savedInstanceState) {
+ if (preso == null) {
+ return(super.onCreateDialog(savedInstanceState));
+ }
+
+ return(preso);
+ }
+
+ public void setDisplay(Context ctxt, Display display) {
+ if (display == null) {
+ preso=null;
+ }
+ else {
+ preso=new Presentation(ctxt, display, getTheme());
+ }
+
+ this.display=display;
+ }
+
+ public Display getDisplay() {
+ return(display);
+ }
+
+ protected Context getContext() {
+ if (preso != null) {
+ return(preso.getContext());
+ }
+
+ return(getActivity());
+ }
+}
View
53 ...ation/Fragment/src/com/commonsware/android/preso/fragment/SamplePresentationFragment.java
@@ -0,0 +1,53 @@
+/***
+ Copyright (c) 2013 CommonsWare, LLC
+ 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.
+
+ From _The Busy Coder's Guide to Android Development_
+ http://commonsware.com/Android
+ */
+
+package com.commonsware.android.preso.fragment;
+
+import android.content.Context;
+import android.os.Bundle;
+import android.view.Display;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+
+public class SamplePresentationFragment extends WebPresentationFragment {
+ private static final String ARG_URL="url";
+
+ public static SamplePresentationFragment newInstance(Context ctxt,
+ Display display,
+ String url) {
+ SamplePresentationFragment frag=new SamplePresentationFragment();
+
+ frag.setDisplay(ctxt, display);
+
+ Bundle b=new Bundle();
+
+ b.putString(ARG_URL, url);
+ frag.setArguments(b);
+
+ return(frag);
+ }
+
+ @Override
+ public View onCreateView(LayoutInflater inflater,
+ ViewGroup container,
+ Bundle savedInstanceState) {
+ View result=
+ super.onCreateView(inflater, container, savedInstanceState);
+
+ getWebView().loadUrl(getArguments().getString(ARG_URL));
+
+ return(result);
+ }
+}
View
107 ...entation/Fragment/src/com/commonsware/android/preso/fragment/WebPresentationFragment.java
@@ -0,0 +1,107 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ * Portions Copyright (c) 2012 CommonsWare, LLC
+ *
+ * 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.
+ */
+
+package com.commonsware.android.preso.fragment;
+
+import android.annotation.TargetApi;
+import android.os.Build;
+import android.os.Bundle;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.webkit.WebView;
+
+public class WebPresentationFragment extends PresentationFragment {
+ private WebView mWebView;
+ private boolean mIsWebViewAvailable;
+
+ /**
+ * Called to instantiate the view. Creates and returns the
+ * WebView.
+ */
+ @Override
+ public View onCreateView(LayoutInflater inflater,
+ ViewGroup container,
+ Bundle savedInstanceState) {
+ if (mWebView != null) {
+ mWebView.destroy();
+ }
+
+ mWebView=new WebView(getContext());
+ mIsWebViewAvailable=true;
+ return mWebView;
+ }
+
+ /**
+ * Called when the fragment is visible to the user and
+ * actively running. Resumes the WebView.
+ */
+ @TargetApi(11)
+ @Override
+ public void onPause() {
+ super.onPause();
+
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
+ mWebView.onPause();
+ }
+ }
+
+ /**
+ * Called when the fragment is no longer resumed. Pauses
+ * the WebView.
+ */
+ @TargetApi(11)
+ @Override
+ public void onResume() {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
+ mWebView.onResume();
+ }
+
+ super.onResume();
+ }
+
+ /**
+ * Called when the WebView has been detached from the
+ * fragment. The WebView is no longer available after this
+ * time.
+ */
+ @Override
+ public void onDestroyView() {
+ mIsWebViewAvailable=false;
+ super.onDestroyView();
+ }
+
+ /**
+ * Called when the fragment is no longer in use. Destroys
+ * the internal state of the WebView.
+ */
+ @Override
+ public void onDestroy() {
+ if (mWebView != null) {
+ mWebView.destroy();
+ mWebView=null;
+ }
+ super.onDestroy();
+ }
+
+ /**
+ * Gets the WebView.
+ */
+ public WebView getWebView() {
+ return mIsWebViewAvailable ? mWebView : null;
+ }
+}
View
8 Presentation/Simple/.classpath
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="src" path="gen"/>
+ <classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
+ <classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
+ <classpathentry kind="output" path="bin/classes"/>
+</classpath>
View
33 Presentation/Simple/.project
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>SimplePresentationDemo</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>com.android.ide.eclipse.adt.ApkBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>com.android.ide.eclipse.adt.AndroidNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
View
28 Presentation/Simple/AndroidManifest.xml
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="utf-8"?>
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.commonsware.android.preso.simple"
+ android:versionCode="1"
+ android:versionName="1.0">
+
+ <uses-sdk
+ android:minSdkVersion="8"
+ android:targetSdkVersion="17"/>
+ <uses-permission android:name="android.permission.INTERNET"/>
+
+ <application
+ android:allowBackup="true"
+ android:icon="@drawable/ic_launcher"
+ android:label="@string/app_name"
+ android:theme="@style/AppTheme">
+ <activity
+ android:name="com.commonsware.android.preso.simple.MainActivity"
+ android:label="@string/app_name">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN"/>
+
+ <category android:name="android.intent.category.LAUNCHER"/>
+ </intent-filter>
+ </activity>
+ </application>
+
+</manifest>
View
BIN  Presentation/Simple/libs/android-support-v4.jar
Binary file not shown
View
20 Presentation/Simple/proguard-project.txt
@@ -0,0 +1,20 @@
+# To enable ProGuard in your project, edit project.properties
+# to define the proguard.config property as described in that file.
+#
+# Add project specific ProGuard rules here.
+# By default, the flags in this file are appended to flags specified
+# in ${sdk.dir}/tools/proguard/proguard-android.txt
+# You can edit the include path and order by changing the ProGuard
+# include property in project.properties.
+#
+# For more details, see
+# http://developer.android.com/guide/developing/tools/proguard.html
+
+# Add any project specific keep options here:
+
+# If your project uses WebView with JS, uncomment the following
+# and specify the fully qualified class name to the JavaScript interface
+# class:
+#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
+# public *;
+#}
View
14 Presentation/Simple/project.properties
@@ -0,0 +1,14 @@
+# This file is automatically generated by Android Tools.
+# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
+#
+# This file must be checked in Version Control Systems.
+#
+# To customize properties used by the Ant build system edit
+# "ant.properties", and override values to adapt the script to your
+# project structure.
+#
+# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
+#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
+
+# Project target.
+target=android-17
View
BIN  Presentation/Simple/res/drawable-hdpi/ic_launcher.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  Presentation/Simple/res/drawable-ldpi/ic_launcher.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  Presentation/Simple/res/drawable-mdpi/ic_launcher.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  Presentation/Simple/res/drawable-xhdpi/ic_launcher.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
15 Presentation/Simple/res/layout/activity_main.xml
@@ -0,0 +1,15 @@
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:tools="http://schemas.android.com/tools"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ tools:context=".MainActivity">
+
+ <TextView
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_centerInParent="true"
+ android:text="@string/hello_world"
+ android:gravity="center"
+ android:textSize="40sp"/>
+
+</RelativeLayout>
View
8 Presentation/Simple/res/values-sw600dp/dimens.xml
@@ -0,0 +1,8 @@
+<resources>
+
+ <!--
+ Customize dimensions originally defined in res/values/dimens.xml (such as
+ screen margins) for sw600dp devices (e.g. 7" tablets) here.
+ -->
+
+</resources>
View
9 Presentation/Simple/res/values-sw720dp-land/dimens.xml
@@ -0,0 +1,9 @@
+<resources>
+
+ <!--
+ Customize dimensions originally defined in res/values/dimens.xml (such as
+ screen margins) for sw720dp devices (e.g. 10" tablets) in landscape here.
+ -->
+ <dimen name="activity_horizontal_margin">128dp</dimen>
+
+</resources>
View
11 Presentation/Simple/res/values-v11/styles.xml
@@ -0,0 +1,11 @@
+<resources>
+
+ <!--
+ Base application theme for API 11+. This theme completely replaces
+ AppBaseTheme from res/values/styles.xml on API 11+ devices.
+ -->
+ <style name="AppBaseTheme" parent="android:Theme.Holo.Light">
+ <!-- API 11 theme customizations can go here. -->
+ </style>
+
+</resources>
View
12 Presentation/Simple/res/values-v14/styles.xml
@@ -0,0 +1,12 @@
+<resources>
+
+ <!--
+ Base application theme for API 14+. This theme completely replaces
+ AppBaseTheme from BOTH res/values/styles.xml and
+ res/values-v11/styles.xml on API 14+ devices.
+ -->
+ <style name="AppBaseTheme" parent="android:Theme.Holo.Light.DarkActionBar">
+ <!-- API 14 theme customizations can go here. -->
+ </style>
+
+</resources>
View
7 Presentation/Simple/res/values/dimens.xml
@@ -0,0 +1,7 @@
+<resources>
+
+ <!-- Default screen margins, per the Android Design guidelines. -->
+ <dimen name="activity_horizontal_margin">16dp</dimen>
+ <dimen name="activity_vertical_margin">16dp</dimen>
+
+</resources>
View
7 Presentation/Simple/res/values/strings.xml
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+
+ <string name="app_name">Simple Presentation Demo</string>
+ <string name="hello_world">You should see a Web page on the secondary display!</string>
+
+</resources>
View
20 Presentation/Simple/res/values/styles.xml
@@ -0,0 +1,20 @@
+<resources>
+
+ <!--
+ Base application theme, dependent on API level. This theme is replaced
+ by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
+ -->
+ <style name="AppBaseTheme" parent="android:Theme.Light">
+ <!--
+ Theme customizations available in newer API levels can go in
+ res/values-vXX/styles.xml, while customizations related to
+ backward-compatibility can go here.
+ -->
+ </style>
+
+ <!-- Application theme. -->
+ <style name="AppTheme" parent="AppBaseTheme">
+ <!-- All customizations that are NOT specific to a particular API-level can go here. -->
+ </style>
+
+</resources>
View
141 Presentation/Simple/src/com/commonsware/android/preso/simple/MainActivity.java
@@ -0,0 +1,141 @@
+/***
+ Copyright (c) 2013 CommonsWare, LLC
+ 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.
+
+ From _The Busy Coder's Guide to Android Development_
+ http://commonsware.com/Android
+ */
+
+package com.commonsware.android.preso.simple;
+
+import android.annotation.TargetApi;
+import android.app.Activity;
+import android.app.Presentation;
+import android.content.Context;
+import android.media.MediaRouter;
+import android.media.MediaRouter.RouteInfo;
+import android.media.MediaRouter.SimpleCallback;
+import android.os.Build;
+import android.os.Bundle;
+import android.util.Log;
+import android.view.Display;
+import android.webkit.WebView;
+
+public class MainActivity extends Activity {
+ MediaRouter router=null;
+ Presentation preso=null;
+ SimpleCallback cb=null;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ setContentView(R.layout.activity_main);
+ }
+
+ @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
+ @Override
+ protected void onResume() {
+ super.onResume();
+
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
+ if (cb==null) {
+ cb=new RouteCallback();
+ router=(MediaRouter)getSystemService(MEDIA_ROUTER_SERVICE);
+ }
+
+ handleRoute(router.getSelectedRoute(MediaRouter.ROUTE_TYPE_LIVE_VIDEO));
+ router.addCallback(MediaRouter.ROUTE_TYPE_LIVE_VIDEO, cb);
+ }
+ }
+
+ @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
+ @Override
+ protected void onPause() {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
+ clearPreso();
+
+ if (router != null) {
+ router.removeCallback(cb);
+ }
+ }
+
+ super.onPause();
+ }
+
+ @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
+ private void handleRoute(RouteInfo route) {
+ if (route == null) {
+ clearPreso();
+ }
+ else {
+ Display display=route.getPresentationDisplay();
+
+ if (route.isEnabled() && display != null) {
+ if (preso == null) {
+ showPreso(route);
+ Log.d(getClass().getSimpleName(), "enabled route");
+ }
+ else if (preso.getDisplay().getDisplayId() != display.getDisplayId()) {
+ clearPreso();
+ showPreso(route);
+ Log.d(getClass().getSimpleName(), "switched route");
+ }
+ else {
+ // no-op: should already be set
+ }
+ }
+ else {
+ clearPreso();
+ Log.d(getClass().getSimpleName(), "disabled route");
+ }
+ }
+ }
+
+ @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
+ private void clearPreso() {
+ if (preso != null) {
+ preso.dismiss();
+ preso=null;
+ }
+ }
+
+ @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
+ private void showPreso(RouteInfo route) {
+ preso=new SimplePresentation(this, route.getPresentationDisplay());
+ preso.show();
+ }
+
+ @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
+ private class RouteCallback extends SimpleCallback {
+ @Override
+ public void onRoutePresentationDisplayChanged(MediaRouter router,
+ RouteInfo route) {
+ handleRoute(route);
+ }
+ }
+
+ @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
+ private class SimplePresentation extends Presentation {
+ SimplePresentation(Context ctxt, Display display) {
+ super(ctxt, display);
+ }
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ WebView wv=new WebView(getContext());
+
+ wv.loadUrl("http://commonsware.com");
+
+ setContentView(wv);
+ }
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.