// Opens an android date picker dialog and grabs the result using a callback.// Dummy class to hold date - makes it easier to modify it in the callback
class SelectedDate {
static var date : Date = System.DateTime.Now;
}// The callback class
class DateCallback extends AndroidJavaProxy {
function DateCallback() {
super("android.app.DatePickerDialog$OnDateSetListener");
}
function onDateSet(view: AndroidJavaObject, year: int, monthOfYear: int, dayOfMonth: int){
SelectedDate.date = new Date(year, monthOfYear + 1, dayOfMonth);
}
}function OnGUI () {
if (GUI.Button (Rect (10,10,450,100), String.Format("{0:yyyy-MM-dd}", SelectedDate.date))) {
var activity = new AndroidJavaClass("com.unity3d.player.UnityPlayer").GetStatic.<AndroidJavaObject>("currentActivity");
activity.Call("runOnUiThread", new AndroidJavaRunnable(function(){
new AndroidJavaObject("android.app.DatePickerDialog", activity, new DateCallback(),
SelectedDate.date.Year, SelectedDate.date.Month - 1, SelectedDate.date.Day).Call("show");
}));
}
}
using UnityEngine;
using System.Collections;
public class SelectedDate : MonoBehaviour {
public static Date date = System.DateTime.Now;
}
public class DateCallback : MonoBehaviour {
new ("android.app.DatePickerDialog$OnDateSetListener");
void onDateSet(AndroidJavaObject view, int year, int monthOfYear, int dayOfMonth) {
SelectedDate.date = new Date(year, monthOfYear + 1, dayOfMonth);
}
}
public class ExampleClass : MonoBehaviour {
void OnGUI() {
if (GUI.Button(new Rect(10, 10, 450, 100), String.Format("{0:yyyy-MM-dd}", SelectedDate.date))) {
AndroidJavaObject activity = new AndroidJavaClass("com.unity3d.player.UnityPlayer").GetStatic<AndroidJavaObject>("currentActivity");
activity.Call("runOnUiThread", AndroidJavaRunnable( new AndroidJavaObject("android.app.DatePickerDialog", activity, new DateCallback(), SelectedDate.date.Year, SelectedDate.date.Month - 1, SelectedDate.date.Day).Call("show");
));
}
}
}
import UnityEngine
import System.Collections
public class SelectedDate:
public static date as Date = System.DateTime.Now
public class DateCallback(AndroidJavaProxy):
public def constructor():
super('android.app.DatePickerDialog$OnDateSetListener')
def onDateSet(view as AndroidJavaObject, year as int, monthOfYear as int, dayOfMonth as int) as void:
SelectedDate.date = Date(year, (monthOfYear + 1), dayOfMonth)
public class ExampleClass(MonoBehaviour):
def OnGUI() as void:
if GUI.Button(Rect(10, 10, 450, 100), String.Format('{0:yyyy-MM-dd}', SelectedDate.date)):
activity as AndroidJavaObject = AndroidJavaClass('com.unity3d.player.UnityPlayer').GetStatic[of AndroidJavaObject]('currentActivity')
activity.Call('runOnUiThread', AndroidJavaRunnable({ AndroidJavaObject('android.app.DatePickerDialog', activity, DateCallback(), SelectedDate.date.Year, (SelectedDate.date.Month - 1), SelectedDate.date.Day).Call('show') }))