Bug 6260 - [TimePicker] SetIs24HourView blindly updates the CurrentHour
Summary: [TimePicker] SetIs24HourView blindly updates the CurrentHour
Status: RESOLVED FEATURE
Alias: None
Product: Android
Classification: Xamarin
Component: BCL Class Libraries ()
Version: 4.2.x
Hardware: PC Mac OS
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2012-07-24 14:38 UTC by Stephen Shaw
Modified: 2012-08-07 06:26 UTC (History)
2 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FEATURE

Description Stephen Shaw 2012-07-24 14:38:02 UTC
Looking at this it seems like the bool value for .IS24HourView is current and updated correctly when calling SetIS24HourView and updates the CurrentHour value.  The problem seems to be that it blindly converts the CurrentHour without checking if it should be in 24 hour or not.

Here is the android code (http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/2.1_r2/android/widget/TimePicker.java#TimePicker.updateHourDisplay%28%29)


    public void setIs24HourView(Boolean is24HourView) {
        if (mIs24HourView != is24HourView) {
            mIs24HourView = is24HourView;
            configurePickerRanges();
            updateHourDisplay();
        }
    }



    private void updateHourDisplay() {
        int currentHour = mCurrentHour;
        if (!mIs24HourView) {  <-------------- Is this check not being done?
            // convert [0,23] ordinal to wall clock display
            if (currentHour > 12) currentHour -= 12;
            else if (currentHour == 0) currentHour = 12;
        }
        mHourPicker.setCurrent(currentHour);
        mIsAm = mCurrentHour < 12;
        mAmPmButton.setText(mIsAm ? mAmText : mPmText);
        onTimeChanged();
    }
Comment 1 Atsushi Eno 2012-08-07 06:26:34 UTC
We are only dispatching arguments to Android API method and converting return value to managed code. Hence, as long as the corresponding Android API results in the same, it is expected.

Here is the code I wrote to verify that Java-only Android code results in the same (in Main activity java in a default app + main.xml below):

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Button btn = (Button) this.findViewById(R.id.myButton);
        btn.setOnClickListener(new Button.OnClickListener () {
			@Override
			public void onClick(View v) {
				TimePicker tp = (TimePicker) findViewById (R.id.timePicker);
				tp.setIs24HourView(count++ % 2 == 0 ? true : false);
			}
        });
    }

main.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<Button
    android:id="@+id/myButton"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/hello"
    />

<TimePicker
    android:id="@+id/timePicker"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

</LinearLayout>