Skip to content

Commit

Permalink
Adds a TimePicker component to launch the native Android TimePicker d…
Browse files Browse the repository at this point in the history
…ialog

Change-Id: I1ff85e0c239200fd9b5660f0ba010fd3d79ffe86
  • Loading branch information
vedharaju authored and jisqyv committed Apr 27, 2014
1 parent eccf24e commit 8995234
Show file tree
Hide file tree
Showing 7 changed files with 210 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public interface Images extends Resources {
*/
@Source("com/google/appinventor/images/camera.png")
ImageResource camera();

/**
* Designer palette item: camcorder declaration
*/
Expand Down Expand Up @@ -319,6 +319,12 @@ public interface Images extends Resources {
@Source("com/google/appinventor/images/twitter.png")
ImageResource twitterComponent();

/**
* Designer palette item: TimePicker Component
*/
@Source("com/google/appinventor/images/timePicker.png")
ImageResource timePickerComponent();

/**
* Designer palette item: TinyDB Component
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// -*- mode: java; c-basic-offset: 2; -*-
// Copyright 2009-2011 Google, All Rights reserved
// Copyright 2011-2012 MIT, All rights reserved
// Released under the MIT License https://raw.github.com/mit-cml/app-inventor/master/mitlicense.txt

package com.google.appinventor.client.editor.simple.components;

import com.google.appinventor.client.editor.simple.SimpleEditor;

/**
* Mock TimePicker component.
*
* @author [email protected] Vedha Sayyaparaju
*/
public final class MockTimePicker extends MockButtonBase {

/**
* Component type name.
*/
public static final String TYPE = "TimePicker";

/**
* Creates a new MockImagePicker component.
*
* @param editor editor of source file the component belongs to
*/
public MockTimePicker(SimpleEditor editor) {
super(editor, TYPE, images.timePickerComponent());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.google.appinventor.client.editor.simple.components.MockLabel;
import com.google.appinventor.client.editor.simple.components.MockListView;
import com.google.appinventor.client.editor.simple.components.MockListPicker;
import com.google.appinventor.client.editor.simple.components.MockTimePicker;
import com.google.appinventor.client.editor.simple.components.MockNonVisibleComponent;
import com.google.appinventor.client.editor.simple.components.MockPasswordTextBox;
import com.google.appinventor.client.editor.simple.components.MockPhoneNumberPicker;
Expand Down Expand Up @@ -108,6 +109,7 @@ private static void initBundledImages() {
bundledImages.put("images/textToSpeech.png", images.textToSpeech());
bundledImages.put("images/texting.png", images.texting());
bundledImages.put("images/datePicker.png", images.datePickerComponent());
bundledImages.put("images/timePicker.png", images.timePickerComponent());
bundledImages.put("images/tinyDB.png", images.tinyDB());
bundledImages.put("images/tinyWebDB.png", images.tinyWebDB());
bundledImages.put("images/twitter.png", images.twitterComponent());
Expand Down Expand Up @@ -283,6 +285,8 @@ public static MockComponent createMockComponent(String name, SimpleEditor editor
return new MockListPicker(editor);
} else if (name.equals(MockDatePicker.TYPE)) {
return new MockDatePicker(editor);
} else if (name.equals(MockTimePicker.TYPE)) {
return new MockTimePicker(editor);
} else if (name.equals(MockHorizontalArrangement.TYPE)) {
return new MockHorizontalArrangement(editor);
} else if (name.equals(MockVerticalArrangement.TYPE)) {
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,10 @@ private YaVersion() {
// - TEXTTOSPEECH_COMPONENT_VERSION was incremented to 2
// For YOUNG_ANDROID_VERSION 91:
// - DATEPICKER_COMPONENT_VERSION was incremented to 1.
// For YOUNG_ANDROID_VERSION 92:
// - TIMEPICKER_COMPONENT_VERSION was incremented to 1

public static final int YOUNG_ANDROID_VERSION = 91;
public static final int YOUNG_ANDROID_VERSION = 92;

// ............................... Blocks Language Version Number ...............................

Expand Down Expand Up @@ -619,6 +621,8 @@ private YaVersion() {
// instead of a boolean
public static final int TEXTING_COMPONENT_VERSION = 3;

public static final int TIMEPICKER_COMPONENT_VERSION = 1;

public static final int TINYDB_COMPONENT_VERSION = 1;

// For TINYWEBDB_COMPONENT_VERSION 2:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
// -*- mode: java; c-basic-offset: 2; -*-
// Copyright 2009-2011 Google, All Rights reserved
// Copyright 2011-2014 MIT, All rights reserved
// Released under the MIT License https://raw.github.com/mit-cml/app-inventor/master/mitlicense.txt

package com.google.appinventor.components.runtime;

import com.google.appinventor.components.annotations.DesignerComponent;
import com.google.appinventor.components.annotations.PropertyCategory;
import com.google.appinventor.components.annotations.SimpleEvent;
import com.google.appinventor.components.annotations.SimpleObject;
import com.google.appinventor.components.annotations.SimpleProperty;
import com.google.appinventor.components.common.ComponentCategory;
import com.google.appinventor.components.common.YaVersion;

import android.app.Dialog;
import android.app.TimePickerDialog;
import java.util.Calendar;


/**
* A button allowing a user to launch the TimePickerDialog. This component is
* is based off the ButtonBase class instead of the base Picker class because
* unlike the other pickers, the TimePicker does not need to launch a new
* activity and get a result. The TimePicker is launched as a dialog.
*
* @author [email protected]
*/
@DesignerComponent(version = YaVersion.TIMEPICKER_COMPONENT_VERSION,
category = ComponentCategory.USERINTERFACE,
description = "<p>A button that, when clicked on, launches a popup" +
" dialog to allow the user to select a time.</p>")
@SimpleObject
public class TimePicker extends ButtonBase {

private int hour = 0;
private int minute = 0;
private TimePickerDialog time;

/**
* Create a new TimePicker component.
*
* @param container the parent container.
*/
public TimePicker(ComponentContainer container) {
super(container);
final Calendar c = Calendar.getInstance();
hour = c.get(Calendar.HOUR_OF_DAY);
minute = c.get(Calendar.MINUTE);
time = new TimePickerDialog(this.container.$context(),
timePickerListener, hour, minute, false);
}


/**
* Returns the hour of the time that was last picked using the timepicker.
* The time returned is always in the 24hour format.
*
* @return hour in 24-hour format
*/
@SimpleProperty(
description = "The hour of the last time set using the time picker." +
" The hour is in a 24 hour format. If the last time set was 11:53 pm" +
", this property will return 23.",
category = PropertyCategory.APPEARANCE)
public int Hour() {
return hour;
}

/**
* Returns the hour of the time that was last picked using the timepicker.
* The time returned is always in the 24hour format.
*
* @return hour in 24-hour format
*/
@SimpleProperty(
description = "The minute of the last time set using the time picker",
category = PropertyCategory.APPEARANCE)
public int Minute() {
return minute;
}

@Override
public void click() {
time.show();
}

private TimePickerDialog.OnTimeSetListener timePickerListener =
new TimePickerDialog.OnTimeSetListener() {
public void onTimeSet(android.widget.TimePicker view, int selectedHour,
int selectedMinute) {
hour = selectedHour;
minute = selectedMinute;
time.updateTime(hour, minute);
AfterTimeSet();
}
};

/**
* Indicates the user has set the time.
*/
@SimpleEvent(description="This event is run when a user has set the time in the popup dialog.")
public void AfterTimeSet() {
EventDispatcher.dispatchEvent(this, "AfterTimeSet");
}
}
58 changes: 58 additions & 0 deletions appinventor/docs/reference/components/userinterface.html
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,7 @@ <h2> Table of Contents </h2>
<li> <a href="#Slider"> Slider </a> </li>
<li> <a href="#Spinner"> Spinner </a> </li>
<li> <a href="#TextBox"> TextBox </a> </li>
<li> <a href="#TimePicker"> TimePicker </a> </li>
<li> <a href="#WebViewer"> WebViewer </a> </li>
</ul>
<h2 id="Button"> Button </h2>
Expand Down Expand Up @@ -1219,6 +1220,63 @@ <h3> Methods </h3>
line text boxes close the keyboard when the users presses
the Done key. </dd>
</dl>

<h2 id="TimePicker">TimePicker</h2>
<p><p>A button that, when clicked on, launches a popup dialog to allow the user to select a time.</p></p>

<h3>Properties</h3>
<dl>
<dt><code>BackgroundColor</code></dt>
<dd>Returns the button's background color</dd>
<dt><code>Enabled</code></dt>
<dd></dd>
<dt><code>FontBold</code> (designer only)</dt>
<dd></dd>
<dt><code>FontItalic</code> (designer only)</dt>
<dd></dd>
<dt><code>FontSize</code> (designer only)</dt>
<dd></dd>
<dt><code>FontTypeface</code> (designer only)</dt>
<dd></dd>
<dt><code>Height</code></dt>
<dd></dd>
<dt><code><em>Hour</em></code></dt>
<dd>The hour of the last time set using the time picker. The hour is in a 24 hour format. If the last time set was 11:53 pm, this property will return 23.</dd>
<dt><code>Image</code></dt>
<dd>Specifies the path of the button's image. If there is both an Image and a BackgroundColor, only the Image will be visible.</dd>
<dt><code><em>Minute</em></code></dt>
<dd>The minute of the last time set using the time picker</dd>
<dt><code>Shape</code> (designer only)</dt>
<dd>Specifies the button's shape (default, rounded, rectangular, oval). The shape will not be visible if an Image is being displayed.</dd>
<dt><code>ShowFeedback</code></dt>
<dd>Specifies if a visual feedback should be shown for a button that as an image as background.</dd>
<dt><code>Text</code></dt>
<dd></dd>
<dt><code>TextAlignment</code> (designer only)</dt>
<dd></dd>
<dt><code>TextColor</code></dt>
<dd></dd>
<dt><code>Visible</code></dt>
<dd>Specifies whether the component should be visible on the screen. Value is true if the component is showing and false if hidden.</dd>
<dt><code>Width</code></dt>
<dd></dd>
</dl>

<h3>Events</h3>
<dl>
<dt><code>AfterTimeSet()</code></dt>
<dd>This event is run when a user has set the time in the popup dialog.</dd>
<dt><code>GotFocus()</code></dt>
<dd>Indicates the cursor moved over the button so it is now possible
to click it.</dd>
<dt><code>LostFocus()</code></dt>
<dd>Indicates the cursor moved away from the button so it is now no
longer possible to click it.</dd>
</dl>

<h3>Methods</h3>
none

<h2 id="WebViewer"> WebViewer </h2>
<img src="images/webviewer.png" alt="Picture of WebViewer component" />
<p> Component for viewing Web pages. The Home URL can be
Expand Down

0 comments on commit 8995234

Please sign in to comment.