User cannot miss that notification, but it's not iritating. And or developer - it's easy to show the kind of notification - just one line of code
Toast.makeText(getApplicationContext(), "message from Android", Toast.LENGTH_LONG).show();
However some components would benefit from some polishing - especially TimePicker, which allows user to pick a Time - Hour and Minute.
But it has a drawback - imagine You have 22:59 choosen:

and You click '+' to add one minute.
What do You expect? I expect to see 23:00 - I hope it's not too extravagant.
But Android gives You

yes, just 22:00, and if You want 23:00 You have to manually increase hour.
I would like my Users to be in better situation, so I decided to enhance TimePicker to support that. It wasn't that hard - it only needed one specific time change listener, which is handling approprate hour change and also delegating the event to another listener when done. It's strange that TimePicker is able to handle only one Listener each type, but You can always get around it.
import android.widget.TimePicker;
import android.widget.TimePicker.OnTimeChangedListener;
public class HourChangingListener implements OnTimeChangedListener {
int lastMinute = Integer.MIN_VALUE;
private final OnTimeChangedListener delegate;
public HourChangingListener(OnTimeChangedListener delegate) {
this.delegate = delegate;
}
@Override
public void onTimeChanged(TimePicker timePicker, int hour, int minute) {
if (minute == 0 && lastMinute == 59) {
lastMinute = minute;
incrementAndSetHour(timePicker, hour);
} else if (minute == 59 && lastMinute == 0) {
lastMinute = minute;
decrementAndSetHour(timePicker, hour);
} else {
delegate.onTimeChanged(timePicker, hour, minute);
}
lastMinute = minute;
}
private void decrementAndSetHour(TimePicker timePicker, int hour) {
setSafeHour(timePicker, hour - 1);
}
private void incrementAndSetHour(TimePicker timePicker, int hour) {
setSafeHour(timePicker, hour + 1);
}
private void setSafeHour(TimePicker timePicker, int hour) {
int base = 24;
hour = (base + hour) % base;
timePicker.setCurrentHour(hour);
}
}
And You use it by
TimePicker timePicker;
OnTimeChangedListener originalTimePickerChangeListener;
timePicker.setOnTimeChangedListener(new HourChangingListener(originalTimePickerChangeListener));
Keep in mind that HourChangingListener is not thread-safe and cannot be reusable to handle multiple TimePickers!
This works and when You add minute to 22:59 you get:

This solution needs enhancement to support client that doesn't need a delegate listener. I also consider this solution as a workaround as TimePicker should be supporting this internally.
Off-topic: Right now I think my app would gain more value if I would have done sth more 'core' than this small enhancement:)


I've filled issue for that http://code.google.com/p/android/issues/detail?id=5955, we will see what will happen..
OdpowiedzUsuń na zawszeHi, great blog. I like it. Keep doing.
OdpowiedzUsuń na zawszeIf you want, you can visit my blog.
Happy new year!! :)
Ten komentarz został usunięty przez administratora bloga.
OdpowiedzUsuń na zawsze