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 DatePicker component using Android DatePickerDialog
Change-Id: I389bb5aa343bff69c19209e3fc3d6ce66d9a3a2d
- Loading branch information
Showing
7 changed files
with
229 additions
and
1 deletion.
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
28 changes: 28 additions & 0 deletions
28
.../appengine/src/com/google/appinventor/client/editor/simple/components/MockDatePicker.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,28 @@ | ||
// -*- 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.client.editor.simple.components; | ||
|
||
import com.google.appinventor.client.editor.simple.SimpleEditor; | ||
|
||
/** | ||
* Mock DatePicker component. | ||
*/ | ||
public class MockDatePicker extends MockButtonBase { | ||
|
||
/** | ||
* Component type name. | ||
*/ | ||
public static final String TYPE = "DatePicker"; | ||
|
||
/** | ||
* Creates a new MockDatePicker component. | ||
* | ||
* @param editor editor of source file the component belongs to | ||
*/ | ||
public MockDatePicker(SimpleEditor editor) { | ||
super(editor, TYPE, images.datePickerComponent()); | ||
} | ||
} |
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.15 KB
appinventor/appengine/src/com/google/appinventor/images/datePicker.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
125 changes: 125 additions & 0 deletions
125
appinventor/components/src/com/google/appinventor/components/runtime/DatePicker.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,125 @@ | ||
// -*- 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 android.app.DatePickerDialog; | ||
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 java.text.DateFormatSymbols; | ||
import java.util.Calendar; | ||
|
||
/** | ||
* A button allowing a user to launch a DatePickerDialog. This component is | ||
* is based off the ButtonBase class instead of the base Picker class because | ||
* unlike the other pickers, the DatePicker does not need to launch a new | ||
* activity and get a result. The DatePicker is launched as a dialog. | ||
*/ | ||
@DesignerComponent(version = YaVersion.DATEPICKER_COMPONENT_VERSION, | ||
category = ComponentCategory.USERINTERFACE, | ||
description = "<p>A button that, when clicked on, launches a popup" + | ||
" dialog to allow the user to select a date.</p>") | ||
@SimpleObject | ||
public class DatePicker extends ButtonBase { | ||
|
||
private DatePickerDialog date; | ||
private int year, month, day; | ||
private String [] localizedMonths = new DateFormatSymbols().getMonths(); | ||
|
||
/** | ||
* Creates a new DatePicker component. | ||
* @param container the container in which the component will be placed in. | ||
*/ | ||
public DatePicker(ComponentContainer container) { | ||
super(container); | ||
|
||
//Set the current date on creation | ||
final Calendar c = Calendar.getInstance(); | ||
year = c.get(Calendar.YEAR); | ||
month = c.get(Calendar.MONTH); | ||
day = c.get(Calendar.DAY_OF_MONTH); | ||
date = new DatePickerDialog(this.container.$context(), datePickerListener, year, month, day); | ||
} | ||
|
||
/** | ||
* Returns the Year that was last picked using the DatePicker. | ||
* @return the year in numeric format | ||
*/ | ||
@SimpleProperty(description = "the Year that was last picked using the DatePicker", | ||
category = PropertyCategory.APPEARANCE) | ||
public int Year() { | ||
return year; | ||
} | ||
|
||
/** | ||
* Returns the number of the Month that was last picked using the DatePicker. | ||
* @return the year in numeric format | ||
*/ | ||
@SimpleProperty(description = "the number of the Month that was last picked using the " + | ||
"DatePicker. Note that months start in 0 = January, 11 = December.", | ||
category = PropertyCategory.APPEARANCE) | ||
public int Month() { | ||
return month; | ||
} | ||
|
||
/** | ||
* Returns the name of the Month that was last picked using the DatePicker. | ||
* @return the month in textual format. | ||
*/ | ||
@SimpleProperty(description = "Returns the name of the Month that was last picked using the " + | ||
"DatePicker, in textual format.", | ||
category = PropertyCategory.APPEARANCE) | ||
public String MonthInText() { | ||
return localizedMonths[month]; | ||
} | ||
|
||
/** | ||
* Returns the Day of the month that was last picked using the DatePicker. | ||
* @return the day in numeric format | ||
*/ | ||
@SimpleProperty(description = "the Day of the month that was last picked using the DatePicker.", | ||
category = PropertyCategory.APPEARANCE) | ||
public int Day() { | ||
return day; | ||
} | ||
|
||
/** | ||
* Overriding method from superclass to show the date picker dialog when the button is clicked | ||
*/ | ||
@Override | ||
public void click() { | ||
date.show(); | ||
} | ||
|
||
/** | ||
* Listener for the Dialog. It will update the fields after selection. | ||
*/ | ||
private DatePickerDialog.OnDateSetListener datePickerListener = | ||
new DatePickerDialog.OnDateSetListener() { | ||
@Override | ||
public void onDateSet(android.widget.DatePicker datePicker, int selectedYear, | ||
int selectedMonth, int selectedDay) { | ||
year = selectedYear; | ||
month = selectedMonth; | ||
day = selectedDay; | ||
date.updateDate(year, month, day); | ||
AfterDateSet(); | ||
} | ||
}; | ||
|
||
/** | ||
* Runs when the user sets the date in the Dialog. | ||
*/ | ||
@SimpleEvent(description = "Event that runs after the user chooses a Date in the dialog") | ||
public void AfterDateSet() { | ||
EventDispatcher.dispatchEvent(this, "AfterDateSet"); | ||
} | ||
} |
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