forked from mit-cml/appinventor-sources
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds a TimePicker component to launch the native Android TimePicker d…
…ialog Change-Id: I1ff85e0c239200fd9b5660f0ba010fd3d79ffe86
- Loading branch information
Showing
7 changed files
with
210 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
.../appengine/src/com/google/appinventor/client/editor/simple/components/MockTimePicker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+4.13 KB
appinventor/appengine/src/com/google/appinventor/images/timePicker.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 106 additions & 0 deletions
106
appinventor/components/src/com/google/appinventor/components/runtime/TimePicker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters