Skip to content

Commit

Permalink
[TIMOB-8430] Fix TimePicker AM/PM
Browse files Browse the repository at this point in the history
  • Loading branch information
Gary Mathews committed May 18, 2017
1 parent 0d8a8f1 commit 71f8738
Showing 1 changed file with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.appcelerator.kroll.KrollProxy;
import org.appcelerator.kroll.common.Log;
import org.appcelerator.titanium.proxy.TiViewProxy;
import org.appcelerator.titanium.TiApplication;
import org.appcelerator.titanium.util.TiConvert;
import org.appcelerator.titanium.util.TiRHelper;
import org.appcelerator.titanium.util.TiUIHelper;
Expand All @@ -21,6 +22,7 @@

import android.app.Activity;
import android.os.Build;
import android.view.View;
import android.widget.TimePicker;
import android.widget.TimePicker.OnTimeChangedListener;

Expand All @@ -32,6 +34,9 @@ public class TiUITimePicker extends TiUIView

protected Date minDate, maxDate;
protected int minuteInterval;

private static int id_am = 0;
private static int id_pm = 0;

public TiUITimePicker(TiViewProxy proxy)
{
Expand All @@ -55,6 +60,35 @@ protected void onLayout(boolean changed, int left, int top, int right, int botto
TiUIHelper.firePostLayoutEvent(proxy);
}
};

// TIMOB-8430: https://issuetracker.google.com/issues/36931448
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP && Build.VERSION.SDK_INT <= Build.VERSION_CODES.M) {
if (id_am == 0) {
id_am = TiApplication.getInstance().getResources().getIdentifier("android:id/am_label","drawable", "android.widget.TimePicker");
}
if (id_pm == 0) {
id_pm = TiApplication.getInstance().getResources().getIdentifier("android:id/pm_label", "drawable", "android.widget.TimePicker");
}
View am = (View) picker.findViewById(id_am);
View pm = (View) picker.findViewById(id_pm);
View.OnClickListener listener = new View.OnClickListener() {
@Override
public void onClick(View v) {
if (Build.VERSION.SDK_INT >= 23) {
picker.setHour((picker.getHour() + 12) % 24);
} else {
picker.setCurrentHour((picker.getCurrentHour() + 12) % 24);
}
}
};
if (am != null) {
am.setOnClickListener(listener);
}
if (pm != null) {
pm.setOnClickListener(listener);
}
}

} else {
// A bug where PickerCalendarDelegate does not send events to the
// listener on API Level 21 (Android 5.0) for TIMOB-19192
Expand Down

0 comments on commit 71f8738

Please sign in to comment.