Prune dead code. Review at http://gwt-code-reviews.appspot.com/1627803 git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@10829 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/samples/mobilewebapp/src/main/java/com/google/gwt/sample/mobilewebapp/client/ProvidesPresenter.java b/samples/mobilewebapp/src/main/java/com/google/gwt/sample/mobilewebapp/client/ProvidesPresenter.java deleted file mode 100644 index 8b7480d..0000000 --- a/samples/mobilewebapp/src/main/java/com/google/gwt/sample/mobilewebapp/client/ProvidesPresenter.java +++ /dev/null
@@ -1,26 +0,0 @@ -/* - * Copyright 2011 Google Inc. - * - * 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.google.gwt.sample.mobilewebapp.client; - -/** - * Provides the presenter to run a given view for a new session. - * - * @param <P> the presenter type - * @param <V> the view type - */ -public interface ProvidesPresenter<P, V> { - P getPresenter(V view); -}
diff --git a/samples/mobilewebapp/src/main/java/com/google/gwt/sample/mobilewebapp/client/desktop/PieChart.java b/samples/mobilewebapp/src/main/java/com/google/gwt/sample/mobilewebapp/client/desktop/PieChart.java deleted file mode 100644 index 679cd75..0000000 --- a/samples/mobilewebapp/src/main/java/com/google/gwt/sample/mobilewebapp/client/desktop/PieChart.java +++ /dev/null
@@ -1,154 +0,0 @@ -/* - * Copyright 2011 Google Inc. - * - * 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.google.gwt.sample.mobilewebapp.client.desktop; - -import com.google.gwt.canvas.client.Canvas; -import com.google.gwt.canvas.dom.client.Context2d; -import com.google.gwt.canvas.dom.client.FillStrokeStyle; -import com.google.gwt.core.client.Scheduler; -import com.google.gwt.core.client.Scheduler.ScheduledCommand; -import com.google.gwt.dom.client.PartialSupport; -import com.google.gwt.user.client.ui.Composite; -import com.google.gwt.user.client.ui.RequiresResize; - -import java.util.ArrayList; -import java.util.List; - -/** - * A pie chart representation of data. - */ -@PartialSupport -public class PieChart extends Composite implements RequiresResize { - - /** - * Information about a slice of pie. - */ - private static class Slice { - private final double weight; - private final FillStrokeStyle fill; - - public Slice(double weight, FillStrokeStyle fill) { - this.weight = weight; - this.fill = fill; - } - } - - /** - * The number of radians in a circle. - */ - private static final double RADIANS_IN_CIRCLE = 2 * Math.PI; - - /** - * Return a new {@link Canvas} if supported, and null otherwise. - * - * @return a new {@link Canvas} if supported, and null otherwise - */ - public static PieChart createIfSupported() { - return isSupported() ? new PieChart() : null; - } - - /** - * Runtime check for whether the canvas element is supported in this browser. - * - * @return whether the canvas element is supported - */ - public static boolean isSupported() { - return Canvas.isSupported(); - } - - private final Canvas canvas; - private final List<Slice> slices = new ArrayList<Slice>(); - - /** - * Create using factory methods. - */ - private PieChart() { - canvas = Canvas.createIfSupported(); - canvas.setCoordinateSpaceHeight(300); - canvas.setCoordinateSpaceWidth(300); - initWidget(canvas); - } - - /** - * Add a slice to the chart. - * - * @param weight the weight of the slice - * @param fill the fill color - */ - public void addSlice(double weight, FillStrokeStyle fill) { - slices.add(new Slice(weight, fill)); - } - - /** - * Clear all slices. - */ - public void clearSlices() { - slices.clear(); - } - - public void onResize() { - redraw(); - } - - /** - * Redraw the pie chart. - */ - public void redraw() { - if (!isAttached()) { - return; - } - - // Get the dimensions of the chart. - int width = canvas.getCoordinateSpaceWidth(); - int height = canvas.getCoordinateSpaceHeight(); - double radius = Math.min(width, height) / 2.0; - double cx = width / 2.0; - double cy = height / 2.0; - - // Clear the context. - Context2d context = canvas.getContext2d(); - context.clearRect(0, 0, width, height); - - // Get the total weight of all slices. - double totalWeight = 0; - for (Slice slice : slices) { - totalWeight += slice.weight; - } - - // Draw the slices. - double startAngle = -0.5 * Math.PI; - for (Slice slice : slices) { - double weight = slice.weight / totalWeight; - double endAngle = startAngle + (weight * RADIANS_IN_CIRCLE); - context.setFillStyle(slice.fill); - context.beginPath(); - context.moveTo(cx, cy); - context.arc(cx, cy, radius, startAngle, endAngle); - context.fill(); - startAngle = endAngle; - } - } - - @Override - protected void onLoad() { - super.onLoad(); - Scheduler.get().scheduleDeferred(new ScheduledCommand() { - public void execute() { - redraw(); - } - }); - } -}
diff --git a/samples/mobilewebapp/src/main/java/com/google/gwt/sample/mobilewebapp/client/event/AddTaskEvent.java b/samples/mobilewebapp/src/main/java/com/google/gwt/sample/mobilewebapp/client/event/AddTaskEvent.java deleted file mode 100644 index cdf3216..0000000 --- a/samples/mobilewebapp/src/main/java/com/google/gwt/sample/mobilewebapp/client/event/AddTaskEvent.java +++ /dev/null
@@ -1,48 +0,0 @@ -/* - * Copyright 2011 Google Inc. - * - * 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.google.gwt.sample.mobilewebapp.client.event; - -import com.google.gwt.event.shared.EventHandler; -import com.google.gwt.event.shared.GwtEvent; - -/** - * Fired when the user wants a new task. - */ -public class AddTaskEvent extends GwtEvent<AddTaskEvent.Handler> { - - /** - * Implemented by objects that handle {@link AddTaskEvent}. - */ - public interface Handler extends EventHandler { - void onAddTask(AddTaskEvent event); - } - - /** - * The event type. - */ - public static final Type<AddTaskEvent.Handler> TYPE = new Type<AddTaskEvent.Handler>(); - - @Override - public final Type<AddTaskEvent.Handler> getAssociatedType() { - return TYPE; - } - - @Override - protected void dispatch(AddTaskEvent.Handler handler) { - handler.onAddTask(this); - } -}
diff --git a/samples/mobilewebapp/src/main/java/com/google/gwt/sample/mobilewebapp/client/event/EditingCanceledEvent.java b/samples/mobilewebapp/src/main/java/com/google/gwt/sample/mobilewebapp/client/event/EditingCanceledEvent.java deleted file mode 100644 index 6eca5d5..0000000 --- a/samples/mobilewebapp/src/main/java/com/google/gwt/sample/mobilewebapp/client/event/EditingCanceledEvent.java +++ /dev/null
@@ -1,48 +0,0 @@ -/* - * Copyright 2011 Google Inc. - * - * 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.google.gwt.sample.mobilewebapp.client.event; - -import com.google.gwt.event.shared.EventHandler; -import com.google.gwt.event.shared.GwtEvent; - -/** - * Fired when the user abandons edits of a task. - */ -public class EditingCanceledEvent extends GwtEvent<EditingCanceledEvent.Handler> { - - /** - * Implemented by objects that handle {@link EditingCanceledEvent}. - */ - public interface Handler extends EventHandler { - void onEditCanceled(EditingCanceledEvent event); - } - - /** - * The event type. - */ - public static final Type<EditingCanceledEvent.Handler> TYPE = new Type<EditingCanceledEvent.Handler>(); - - @Override - public final Type<EditingCanceledEvent.Handler> getAssociatedType() { - return TYPE; - } - - @Override - protected void dispatch(EditingCanceledEvent.Handler handler) { - handler.onEditCanceled(this); - } -}
diff --git a/samples/mobilewebapp/src/main/java/com/google/gwt/sample/mobilewebapp/client/event/GoHomeEvent.java b/samples/mobilewebapp/src/main/java/com/google/gwt/sample/mobilewebapp/client/event/GoHomeEvent.java deleted file mode 100644 index 645899d..0000000 --- a/samples/mobilewebapp/src/main/java/com/google/gwt/sample/mobilewebapp/client/event/GoHomeEvent.java +++ /dev/null
@@ -1,48 +0,0 @@ -/* - * Copyright 2011 Google Inc. - * - * 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.google.gwt.sample.mobilewebapp.client.event; - -import com.google.gwt.event.shared.EventHandler; -import com.google.gwt.event.shared.GwtEvent; - -/** - * Fired when the user wants to return to the main screen of the app. - */ -public class GoHomeEvent extends GwtEvent<GoHomeEvent.Handler> { - - /** - * Implemented by objects that handle {@link GoHomeEvent}. - */ - public interface Handler extends EventHandler { - void onGoHome(GoHomeEvent event); - } - - /** - * The event type. - */ - public static final Type<GoHomeEvent.Handler> TYPE = new Type<GoHomeEvent.Handler>(); - - @Override - public final Type<GoHomeEvent.Handler> getAssociatedType() { - return TYPE; - } - - @Override - protected void dispatch(GoHomeEvent.Handler handler) { - handler.onGoHome(this); - } -}
diff --git a/samples/mobilewebapp/src/main/java/com/google/gwt/sample/mobilewebapp/client/event/TaskSavedEvent.java b/samples/mobilewebapp/src/main/java/com/google/gwt/sample/mobilewebapp/client/event/TaskSavedEvent.java deleted file mode 100644 index 0204352..0000000 --- a/samples/mobilewebapp/src/main/java/com/google/gwt/sample/mobilewebapp/client/event/TaskSavedEvent.java +++ /dev/null
@@ -1,48 +0,0 @@ -/* - * Copyright 2011 Google Inc. - * - * 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.google.gwt.sample.mobilewebapp.client.event; - -import com.google.gwt.event.shared.EventHandler; -import com.google.gwt.event.shared.GwtEvent; - -/** - * Fired when the user has saved a task. - */ -public class TaskSavedEvent extends GwtEvent<TaskSavedEvent.Handler> { - - /** - * Implemented by objects that handle {@link TaskSavedEvent}. - */ - public interface Handler extends EventHandler { - void onTaskSaved(TaskSavedEvent event); - } - - /** - * The event type. - */ - public static final Type<TaskSavedEvent.Handler> TYPE = new Type<TaskSavedEvent.Handler>(); - - @Override - public final Type<TaskSavedEvent.Handler> getAssociatedType() { - return TYPE; - } - - @Override - protected void dispatch(TaskSavedEvent.Handler handler) { - handler.onTaskSaved(this); - } -}
diff --git a/samples/mobilewebapp/src/main/java/com/google/gwt/sample/mobilewebapp/client/place/AppPlaceHistoryMapper.java b/samples/mobilewebapp/src/main/java/com/google/gwt/sample/mobilewebapp/client/place/AppPlaceHistoryMapper.java deleted file mode 100644 index af56cbd..0000000 --- a/samples/mobilewebapp/src/main/java/com/google/gwt/sample/mobilewebapp/client/place/AppPlaceHistoryMapper.java +++ /dev/null
@@ -1,33 +0,0 @@ -/* - * Copyright 2010 Google Inc. - * - * 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.google.gwt.sample.mobilewebapp.client.place; - -import com.google.gwt.place.shared.PlaceHistoryMapper; -import com.google.gwt.place.shared.WithTokenizers; - -/** - * This interface is the hub of your application's navigation system. It links - * the {@link com.google.gwt.place.shared.Place Place}s your user navigates to - * with the browser history system — that is, it makes the browser's back - * and forth buttons work for you, and also makes each spot in your app - * bookmarkable. - * <p> - * Its implementation is code generated based on the @WithTokenizers - * annotation. - */ -@WithTokenizers({TaskListPlace.Tokenizer.class, TaskEditPlace.Tokenizer.class}) -public interface AppPlaceHistoryMapper extends PlaceHistoryMapper { -}
diff --git a/samples/mobilewebapp/src/main/java/com/google/gwt/sample/mobilewebapp/client/place/TaskEditPlace.java b/samples/mobilewebapp/src/main/java/com/google/gwt/sample/mobilewebapp/client/place/TaskEditPlace.java deleted file mode 100644 index bbd3eca..0000000 --- a/samples/mobilewebapp/src/main/java/com/google/gwt/sample/mobilewebapp/client/place/TaskEditPlace.java +++ /dev/null
@@ -1,114 +0,0 @@ -/* - * Copyright 2011 Google Inc. - * - * 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.google.gwt.sample.mobilewebapp.client.place; - -import com.google.gwt.place.shared.Place; -import com.google.gwt.place.shared.PlaceTokenizer; -import com.google.gwt.place.shared.Prefix; -import com.google.gwt.sample.mobilewebapp.shared.TaskProxy; - -/** - * The place in the app that show a task in an editable view. - */ -public class TaskEditPlace extends Place { - - /** - * The tokenizer for this place. - */ - @Prefix("edit") - public static class Tokenizer implements PlaceTokenizer<TaskEditPlace> { - - private static final String NO_ID = "create"; - - public TaskEditPlace getPlace(String token) { - try { - // Parse the task ID from the URL. - Long taskId = Long.parseLong(token); - return new TaskEditPlace(taskId, null); - } catch (NumberFormatException e) { - // If the ID cannot be parsed, assume we are creating a task. - return TaskEditPlace.getTaskCreatePlace(); - } - } - - public String getToken(TaskEditPlace place) { - Long taskId = place.getTaskId(); - return (taskId == null) ? NO_ID : taskId.toString(); - } - } - - /** - * The singleton instance of this place used for creation. - */ - private static TaskEditPlace singleton; - - /** - * Create an instance of {@link TaskEditPlace} associated with the specified - * task ID. - * - * @param taskId the ID of the task to edit - * @param task the task to edit, or null if not available - * @return the place - */ - public static TaskEditPlace createTaskEditPlace(Long taskId, TaskProxy task) { - return new TaskEditPlace(taskId, task); - } - - /** - * Get the singleton instance of the {@link TaskEditPlace} used to create a - * new task. - * - * @return the place - */ - public static TaskEditPlace getTaskCreatePlace() { - if (singleton == null) { - singleton = new TaskEditPlace(null, null); - } - return singleton; - } - - private final TaskProxy task; - private final Long taskId; - - /** - * Construct a new {@link TaskEditPlace} for the specified task id. - * - * @param taskId the ID of the task to edit - * @param task the task to edit, or null if not available - */ - private TaskEditPlace(Long taskId, TaskProxy task) { - this.taskId = taskId; - this.task = task; - } - - /** - * Get the task to edit. - * - * @return the task to edit, or null if not available - */ - public TaskProxy getTask() { - return task; - } - - /** - * Get the ID of the task to edit. - * - * @return the ID of the task, or null if creating a new task - */ - public Long getTaskId() { - return taskId; - } -}
diff --git a/samples/mobilewebapp/src/main/java/com/google/gwt/sample/mobilewebapp/client/place/TaskListPlace.java b/samples/mobilewebapp/src/main/java/com/google/gwt/sample/mobilewebapp/client/place/TaskListPlace.java deleted file mode 100644 index 616a6a8..0000000 --- a/samples/mobilewebapp/src/main/java/com/google/gwt/sample/mobilewebapp/client/place/TaskListPlace.java +++ /dev/null
@@ -1,62 +0,0 @@ -/* - * Copyright 2011 Google Inc. - * - * 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.google.gwt.sample.mobilewebapp.client.place; - -import com.google.gwt.place.shared.Place; -import com.google.gwt.place.shared.PlaceTokenizer; -import com.google.gwt.place.shared.Prefix; - -/** - * The place in the app that shows a list of tasks. - */ -public class TaskListPlace extends Place { - - /** - * The tokenizer for this place. TaskList doesn't have any state, so we don't - * have anything to encode. - */ - @Prefix("tl") - public static class Tokenizer implements PlaceTokenizer<TaskListPlace> { - - public TaskListPlace getPlace(String token) { - return new TaskListPlace(true); - } - - public String getToken(TaskListPlace place) { - return ""; - } - } - - private final boolean taskListStale; - - /** - * Construct a new {@link TaskListPlace}. - * - * @param taskListStale true if the task list is stale and should be cleared - */ - public TaskListPlace(boolean taskListStale) { - this.taskListStale = taskListStale; - } - - /** - * Check if the task list is stale and should be cleared. - * - * @return true if stale, false if not - */ - public boolean isTaskListStale() { - return taskListStale; - } -}
diff --git a/samples/mobilewebapp/src/main/java/com/google/gwt/sample/mobilewebapp/client/ui/OrientationHelper.java b/samples/mobilewebapp/src/main/java/com/google/gwt/sample/mobilewebapp/client/ui/OrientationHelper.java deleted file mode 100644 index a384f5a..0000000 --- a/samples/mobilewebapp/src/main/java/com/google/gwt/sample/mobilewebapp/client/ui/OrientationHelper.java +++ /dev/null
@@ -1,52 +0,0 @@ -/* - * Copyright 2011 Google Inc. - * - * 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.google.gwt.sample.mobilewebapp.client.ui; - -import com.google.gwt.event.logical.shared.HasAttachHandlers; -import com.google.gwt.user.client.Command; -import com.google.web.bindery.event.shared.HandlerRegistration; - -/** - * Accepts {@link Command}s to be run when the browser window or device's - * orientation changes. Commands operate only while the associated widget is - * attached. - */ -public interface OrientationHelper { - /** - * Gives efficient on demand access to the orientation of the window or - * device. - * - * @return true for portrait, false for landscape - */ - boolean isPortrait(); - - /** - * Set commands to run on orientation change, one for portrait and one for - * landscape. The appropriate command is fired immediately if this method is - * called while the widget is attached. - * <p> - * Commands are also fired each time the widget is attached. If that is not - * desired a widget should call {@link HandlerRegistration#removeHandler()} on - * the returned object when it detaches. - * - * @param widget the widget to help - * @param forPortrait command to run when on shift to portrait - * @param forLandscape command to run when on shift to landscape - * @return registration object to be used to stop and dereference the commands - */ - HandlerRegistration setCommands(HasAttachHandlers widget, Command forPortrait, - Command forLandscape); -}
diff --git a/samples/mobilewebapp/src/main/java/com/google/gwt/sample/mobilewebapp/client/ui/WindowBasedOrientationHelper.java b/samples/mobilewebapp/src/main/java/com/google/gwt/sample/mobilewebapp/client/ui/WindowBasedOrientationHelper.java deleted file mode 100644 index 40568cc..0000000 --- a/samples/mobilewebapp/src/main/java/com/google/gwt/sample/mobilewebapp/client/ui/WindowBasedOrientationHelper.java +++ /dev/null
@@ -1,130 +0,0 @@ -/* - * Copyright 2011 Google Inc. - * - * 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.google.gwt.sample.mobilewebapp.client.ui; - -import com.google.gwt.event.logical.shared.AttachEvent; -import com.google.gwt.event.logical.shared.HasAttachHandlers; -import com.google.gwt.event.logical.shared.ResizeEvent; -import com.google.gwt.event.logical.shared.ResizeHandler; -import com.google.gwt.user.client.Command; -import com.google.gwt.user.client.Window; -import com.google.web.bindery.event.shared.HandlerRegistration; - -import java.util.HashSet; - -/** - * OrientationHelper implementation that works by by monitoring window size - * changes, and so works on both mobile devices and desktop browsers. - * <p> - * Expected to be used as an app-wide singleton. - */ -public class WindowBasedOrientationHelper implements OrientationHelper { - private class CommandSet implements AttachEvent.Handler, HandlerRegistration { - final Command portraitCommand; - final Command landscapeCommand; - final HandlerRegistration attachEventReg; - - boolean active; - - CommandSet(HasAttachHandlers widget, Command portrait, Command landscape) { - this.portraitCommand = portrait; - this.landscapeCommand = landscape; - - attachEventReg = widget.addAttachHandler(this); - active = widget.isAttached(); - } - - @Override - public void onAttachOrDetach(AttachEvent event) { - active = event.isAttached(); - fire(); - } - - @Override - public void removeHandler() { - commandSets.remove(this); - attachEventReg.removeHandler(); - } - - void fire() { - if (active) { - if (isPortrait) { - portraitCommand.execute(); - } else { - landscapeCommand.execute(); - } - } - } - } - - private static boolean calculateIsPortrait() { - return Window.getClientHeight() > Window.getClientWidth(); - } - - private boolean isPortrait; - private HandlerRegistration windowResizeReg; - private HashSet<CommandSet> commandSets = new HashSet<CommandSet>(); - - public WindowBasedOrientationHelper() { - isPortrait = calculateIsPortrait(); - windowResizeReg = Window.addResizeHandler(new ResizeHandler() { - public void onResize(ResizeEvent event) { - update(); - } - }); - } - - @Override - public boolean isPortrait() { - assertLive(); - return isPortrait; - } - - @Override - public HandlerRegistration setCommands(HasAttachHandlers widget, Command forPortrait, - Command forLandscape) { - assertLive(); - CommandSet commandSet = new CommandSet(widget, forPortrait, forLandscape); - commandSets.add(commandSet); - commandSet.fire(); - return commandSet; - } - - public void stop() { - assertLive(); - windowResizeReg.removeHandler(); - windowResizeReg = null; - - for (CommandSet commandSet : commandSets) { - commandSet.attachEventReg.removeHandler(); - } - commandSets = null; - } - - private void assertLive() { - assert windowResizeReg != null : "Cannot do this after stop() is called"; - } - - private void update() { - boolean was = isPortrait; - isPortrait = calculateIsPortrait(); - if (was != isPortrait) { - for (CommandSet helper : commandSets) { - helper.fire(); - } - } - } -}
diff --git a/samples/mobilewebapp/src/main/java/com/google/gwt/sample/mobilewebapp/shared/FieldVerifier.java b/samples/mobilewebapp/src/main/java/com/google/gwt/sample/mobilewebapp/shared/FieldVerifier.java deleted file mode 100644 index d6ddb9d..0000000 --- a/samples/mobilewebapp/src/main/java/com/google/gwt/sample/mobilewebapp/shared/FieldVerifier.java +++ /dev/null
@@ -1,57 +0,0 @@ -/* - * Copyright 2011 Google Inc. - * - * 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.google.gwt.sample.mobilewebapp.shared; - -/** - * <p> - * FieldVerifier validates that the name the user enters is valid. - * </p> - * <p> - * This class is in the <code>shared</code> package because we use it in both - * the client code and on the server. On the client, we verify that the name is - * valid before sending an RPC request so the user doesn't have to wait for a - * network round trip to get feedback. On the server, we verify that the name is - * correct to ensure that the input is correct regardless of where the RPC - * originates. - * </p> - * <p> - * When creating a class that is used on both the client and the server, be sure - * that all code is translatable and does not use native JavaScript. Code that - * is note translatable (such as code that interacts with a database or the file - * system) cannot be compiled into client side JavaScript. Code that uses native - * JavaScript (such as Widgets) cannot be run on the server. - * </p> - */ -public class FieldVerifier { - - /** - * Verifies that the specified name is valid for our service. - * - * In this example, we only require that the name is at least four - * characters. In your application, you can use more complex checks to ensure - * that usernames, passwords, email addresses, URLs, and other fields have the - * proper syntax. - * - * @param name the name to validate - * @return true if valid, false if invalid - */ - public static boolean isValidName(String name) { - if (name == null) { - return false; - } - return name.length() > 3; - } -}