Skip to content

Commit

Permalink
Use "empty presentation" slide as default slide.
Browse files Browse the repository at this point in the history
Since Presentation initializes slides via setSlides(), it's possible for the
presentation to have no slides (e.g. if the presentation.xml is empty).
To avoid the odd crash, we use a default slide that explains the situation
to the user / developer.

Issue #14.
  • Loading branch information
ZoogieZork committed Jun 13, 2011
1 parent 89c52e9 commit 784ac8c
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 2 deletions.
30 changes: 30 additions & 0 deletions framework/res/layout-xlarge/slide_internal_empty_presentation.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2011 Michael Imamura
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.
-->

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="@dimen/title_frag_diff_height">

<TextView
style="@style/SlideText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/slide_internal_empty_content"/>

</LinearLayout>
3 changes: 3 additions & 0 deletions framework/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@

<string name="title_slide_title">Title</string>

<string name="slide_internal_empty_content"
>The presentation is empty or there there was a problem loading the slides.</string>

<string name="menu_title">Title Slide</string>
<string name="menu_toc">Table of Contents</string>
<string name="menu_about">About</string>
Expand Down
55 changes: 53 additions & 2 deletions framework/src/org/lugatgt/zoogie/present/Presentation.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package org.lugatgt.zoogie.present;

import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
Expand All @@ -26,6 +27,9 @@
import android.text.SpannableStringBuilder;
import android.util.AttributeSet;

import org.lugatgt.zoogie.present.slide.EmptyPresentationSlide;
import org.lugatgt.zoogie.present.ui.SlideFragment;


/**
* Base class for presentations.
Expand All @@ -36,7 +40,14 @@ public class Presentation {
private static final String PROP_PFX = "presentation.";
private static final String PROP_INDEX = PROP_PFX + "index";

private List<Slide> slides;
private static final List<Slide> DEFAULT_SLIDES;
static {
List<Slide> slides = new ArrayList<Slide>(1);
slides.add(new EmptyPresentationSlideInfo());
DEFAULT_SLIDES = slides;
}

private List<Slide> slides = DEFAULT_SLIDES;
private Map<String, Integer> nameToIndex;

private OnIndexChangedListener indexChangedListener;
Expand All @@ -58,6 +69,7 @@ public Presentation() {
*/
public Presentation(AttributeSet attrs) {
idx = 0;
nameToIndex = new HashMap<String, Integer>();
}

// FIELD ACCESS ////////////////////////////////////////////////////////////
Expand All @@ -70,13 +82,18 @@ public Presentation(AttributeSet attrs) {
* @param slides The list of slides (may not be null, may not be empty).
*/
public void setSlides(List<? extends Slide> slides) {
//TODO: Properly support changing the slide list multiple times.
if (this.slides != DEFAULT_SLIDES) {
throw new IllegalArgumentException("setSlides() can only be called once.");
}

if (slides == null || slides.isEmpty()) {
throw new IllegalArgumentException("Slide list must not be empty.");
}

this.slides = new ArrayList<Slide>(slides);

nameToIndex = new HashMap<String, Integer>();
nameToIndex.clear();
int i = 0;
for (Slide slide : slides) {
nameToIndex.put(slide.getName(), i);
Expand Down Expand Up @@ -233,4 +250,38 @@ public interface OnIndexChangedListener {

}

////////////////////////////////////////////////////////////////////////////
// EmptyPresentationSlide

private static class EmptyPresentationSlideInfo implements Slide {

@Override
public String getName() {
return "_empty";
}

@Override
public CharSequence getTitle(Context ctx) {
return "";
}

@Override
public CharSequence getSubtitle(Context ctx) {
return null;
}

@Override
public SlideFragment createFragment()
throws InstantiationException, IllegalAccessException, InvocationTargetException
{
return new EmptyPresentationSlide();
}

@Override
public SlideTransition getTransition() {
return null;
}

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.lugatgt.zoogie.present.slide;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import org.lugatgt.zoogie.present.R;
import org.lugatgt.zoogie.present.ui.SlideFragment;


/**
* "Dummy" slide used when the presentation has no slides.
* @author Michael Imamura
*/
public class EmptyPresentationSlide extends SlideFragment {

@Override
protected View onCreateContentView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.slide_internal_empty_presentation, null);
}

}

0 comments on commit 784ac8c

Please sign in to comment.