Loading res/layout/stopwatch_fragment.xml +15 −0 Original line number Diff line number Diff line Loading @@ -19,6 +19,13 @@ android:orientation="vertical" android:paddingTop="?android:attr/actionBarSize" > <Space android:id="@+id/start_space" android:visibility="gone" android:layout_weight="1" android:layout_width="match_parent" android:layout_height="0dip"/> <com.android.deskclock.CircleButtonsLayout android:id="@+id/stopwatch_circle" android:layout_width="match_parent" Loading Loading @@ -46,6 +53,7 @@ android:layout_height="56dip" android:layout_gravity="bottom|start" android:background="@null" android:contentDescription="@string/sw_lap_button" android:src="@drawable/ic_lap" /> <TextView Loading Loading @@ -78,6 +86,13 @@ android:src="@drawable/ic_share" /> </com.android.deskclock.CircleButtonsLayout> <Space android:id="@+id/end_space" android:visibility="gone" android:layout_weight="1" android:layout_width="match_parent" android:layout_height="0dip"/> <ListView android:id="@+id/laps_list" android:layout_weight="2" Loading src/com/android/deskclock/stopwatch/StopwatchFragment.java +42 −6 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ import android.text.format.DateUtils; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.view.ViewTreeObserver; import android.view.animation.Animation; import android.view.animation.TranslateAnimation; import android.widget.AdapterView; Loading Loading @@ -696,19 +697,19 @@ public class StopwatchFragment extends DeskClockFragment case Stopwatches.STOPWATCH_RESET: setButton(mLeftButton, R.string.sw_lap_button, R.drawable.ic_lap, false, View.INVISIBLE); setStartStopText(mCenterButton, R.string.sw_start_button); setStartStopText(mCircleLayout, mCenterButton, R.string.sw_start_button); showShareButton(false); break; case Stopwatches.STOPWATCH_RUNNING: setButton(mLeftButton, R.string.sw_lap_button, R.drawable.ic_lap, !reachedMaxLaps(), View.VISIBLE); setStartStopText(mCenterButton, R.string.sw_stop_button); setStartStopText(mCircleLayout, mCenterButton, R.string.sw_stop_button); showShareButton(false); break; case Stopwatches.STOPWATCH_STOPPED: setButton(mLeftButton, R.string.sw_reset_button, R.drawable.ic_reset, true, View.VISIBLE); setStartStopText(mCenterButton, R.string.sw_start_button); setStartStopText(mCircleLayout, mCenterButton, R.string.sw_start_button); showShareButton(true); break; default: Loading @@ -734,10 +735,45 @@ public class StopwatchFragment extends DeskClockFragment b.setEnabled(enabled); } private void setStartStopText(TextView v, int text) { /** * Update the Start/Stop text. The button is within a view group with a transition that * is needed to animate the button moving. The transition also animates the the text changing, * but that animation does not provide a good look and feel. Temporarily disable the view group * transition while the text is changing and restore it afterwards. * * @param parent - View Group holding the start/stop button * @param textView - The start/stop button * @param text - Start or Stop id */ private void setStartStopText(final ViewGroup parent, TextView textView, int text) { final LayoutTransition layoutTransition = parent.getLayoutTransition(); // Tap into the parent layout->draw flow just before the draw ViewTreeObserver viewTreeObserver = parent.getViewTreeObserver(); if (viewTreeObserver != null) { viewTreeObserver.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() { /** * Re-establish the transition handler * Remove this listener * * @return true so that onDraw() is called */ @Override public boolean onPreDraw() { parent.setLayoutTransition(layoutTransition); ViewTreeObserver viewTreeObserver = parent.getViewTreeObserver(); if (viewTreeObserver != null) { viewTreeObserver.removeOnPreDrawListener(this); } return true; } }); } // Remove the transition while the text is updated parent.setLayoutTransition(null); String textStr = getActivity().getResources().getString(text); v.setText(textStr); v.setContentDescription(textStr); textView.setText(textStr); textView.setContentDescription(textStr); } /*** Loading Loading
res/layout/stopwatch_fragment.xml +15 −0 Original line number Diff line number Diff line Loading @@ -19,6 +19,13 @@ android:orientation="vertical" android:paddingTop="?android:attr/actionBarSize" > <Space android:id="@+id/start_space" android:visibility="gone" android:layout_weight="1" android:layout_width="match_parent" android:layout_height="0dip"/> <com.android.deskclock.CircleButtonsLayout android:id="@+id/stopwatch_circle" android:layout_width="match_parent" Loading Loading @@ -46,6 +53,7 @@ android:layout_height="56dip" android:layout_gravity="bottom|start" android:background="@null" android:contentDescription="@string/sw_lap_button" android:src="@drawable/ic_lap" /> <TextView Loading Loading @@ -78,6 +86,13 @@ android:src="@drawable/ic_share" /> </com.android.deskclock.CircleButtonsLayout> <Space android:id="@+id/end_space" android:visibility="gone" android:layout_weight="1" android:layout_width="match_parent" android:layout_height="0dip"/> <ListView android:id="@+id/laps_list" android:layout_weight="2" Loading
src/com/android/deskclock/stopwatch/StopwatchFragment.java +42 −6 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ import android.text.format.DateUtils; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.view.ViewTreeObserver; import android.view.animation.Animation; import android.view.animation.TranslateAnimation; import android.widget.AdapterView; Loading Loading @@ -696,19 +697,19 @@ public class StopwatchFragment extends DeskClockFragment case Stopwatches.STOPWATCH_RESET: setButton(mLeftButton, R.string.sw_lap_button, R.drawable.ic_lap, false, View.INVISIBLE); setStartStopText(mCenterButton, R.string.sw_start_button); setStartStopText(mCircleLayout, mCenterButton, R.string.sw_start_button); showShareButton(false); break; case Stopwatches.STOPWATCH_RUNNING: setButton(mLeftButton, R.string.sw_lap_button, R.drawable.ic_lap, !reachedMaxLaps(), View.VISIBLE); setStartStopText(mCenterButton, R.string.sw_stop_button); setStartStopText(mCircleLayout, mCenterButton, R.string.sw_stop_button); showShareButton(false); break; case Stopwatches.STOPWATCH_STOPPED: setButton(mLeftButton, R.string.sw_reset_button, R.drawable.ic_reset, true, View.VISIBLE); setStartStopText(mCenterButton, R.string.sw_start_button); setStartStopText(mCircleLayout, mCenterButton, R.string.sw_start_button); showShareButton(true); break; default: Loading @@ -734,10 +735,45 @@ public class StopwatchFragment extends DeskClockFragment b.setEnabled(enabled); } private void setStartStopText(TextView v, int text) { /** * Update the Start/Stop text. The button is within a view group with a transition that * is needed to animate the button moving. The transition also animates the the text changing, * but that animation does not provide a good look and feel. Temporarily disable the view group * transition while the text is changing and restore it afterwards. * * @param parent - View Group holding the start/stop button * @param textView - The start/stop button * @param text - Start or Stop id */ private void setStartStopText(final ViewGroup parent, TextView textView, int text) { final LayoutTransition layoutTransition = parent.getLayoutTransition(); // Tap into the parent layout->draw flow just before the draw ViewTreeObserver viewTreeObserver = parent.getViewTreeObserver(); if (viewTreeObserver != null) { viewTreeObserver.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() { /** * Re-establish the transition handler * Remove this listener * * @return true so that onDraw() is called */ @Override public boolean onPreDraw() { parent.setLayoutTransition(layoutTransition); ViewTreeObserver viewTreeObserver = parent.getViewTreeObserver(); if (viewTreeObserver != null) { viewTreeObserver.removeOnPreDrawListener(this); } return true; } }); } // Remove the transition while the text is updated parent.setLayoutTransition(null); String textStr = getActivity().getResources().getString(text); v.setText(textStr); v.setContentDescription(textStr); textView.setText(textStr); textView.setContentDescription(textStr); } /*** Loading