Permalink
Browse files

samples of Presentation

  • Loading branch information...
1 parent 13d9d08 commit ed2865fbceb4920f5dddbdc790a8ddf1f3d8f4ee @commonsguy committed Mar 19, 2013
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
@@ -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>
@@ -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>
@@ -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>
Binary file not shown.
@@ -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 *;
+#}
@@ -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
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -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>
@@ -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>
@@ -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>
@@ -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>
@@ -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>
@@ -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>
@@ -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>
@@ -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>
@@ -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);
+ }
+ }
+}
Oops, something went wrong.

0 comments on commit ed2865f

Please sign in to comment.