use of org.omnirom.deskclock.CircleTimerView in project android_packages_apps_OmniClock by omnirom.
the class StopwatchFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// Inflate the layout for this fragment
ViewGroup v = (ViewGroup) inflater.inflate(org.omnirom.deskclock.R.layout.stopwatch_fragment, container, false);
mTime = (CircleTimerView) v.findViewById(org.omnirom.deskclock.R.id.stopwatch_time);
mTime.setBackgroundResource(Utils.getCircleViewBackgroundResourceId(getActivity()));
mTimeText = (CountingTimerView) v.findViewById(org.omnirom.deskclock.R.id.stopwatch_time_text);
mLapsList = (ListView) v.findViewById(org.omnirom.deskclock.R.id.laps_list);
mLapsList.setDividerHeight(0);
mLapsAdapter = new LapsListAdapter(getActivity());
mLapsList.setAdapter(mLapsAdapter);
View footerView = inflater.inflate(org.omnirom.deskclock.R.layout.blank_footer_view, mLapsList, false);
mLapsList.addFooterView(footerView, null, false);
mTimeText.registerVirtualButtonAction(new Runnable() {
@Override
public void run() {
toggleStopwatchState();
}
});
mCircleLayout = (CircleButtonsLayout) v.findViewById(org.omnirom.deskclock.R.id.stopwatch_circle);
mCircleLayout.setCircleTimerViewIds(org.omnirom.deskclock.R.id.stopwatch_time, 0, /* stopwatchId */
0, /* labelId */
0);
// Animation setup
mLayoutTransition = new LayoutTransition();
mCircleLayoutTransition = new LayoutTransition();
// The CircleButtonsLayout only needs to undertake location changes
mCircleLayoutTransition.enableTransitionType(LayoutTransition.CHANGING);
mCircleLayoutTransition.disableTransitionType(LayoutTransition.APPEARING);
mCircleLayoutTransition.disableTransitionType(LayoutTransition.DISAPPEARING);
mCircleLayoutTransition.disableTransitionType(LayoutTransition.CHANGE_APPEARING);
mCircleLayoutTransition.disableTransitionType(LayoutTransition.CHANGE_DISAPPEARING);
mCircleLayoutTransition.setAnimateParentHierarchy(false);
// These spacers assist in keeping the size of CircleButtonsLayout constant
mStartSpace = v.findViewById(org.omnirom.deskclock.R.id.start_space);
mEndSpace = v.findViewById(org.omnirom.deskclock.R.id.end_space);
mSpacersUsed = mStartSpace != null || mEndSpace != null;
// Listener to invoke extra animation within the laps-list
mLayoutTransition.addTransitionListener(new LayoutTransition.TransitionListener() {
@Override
public void startTransition(LayoutTransition transition, ViewGroup container, View view, int transitionType) {
if (view == mLapsList) {
if (transitionType == LayoutTransition.DISAPPEARING) {
if (DEBUG)
LogUtils.v("StopwatchFragment.start laps-list disappearing");
boolean shiftX = view.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE;
int first = mLapsList.getFirstVisiblePosition();
int last = mLapsList.getLastVisiblePosition();
// Ensure index range will not cause a divide by zero
if (last < first) {
last = first;
}
long duration = transition.getDuration(LayoutTransition.DISAPPEARING);
long offset = duration / (last - first + 1) / 5;
for (int visibleIndex = first; visibleIndex <= last; visibleIndex++) {
View lapView = mLapsList.getChildAt(visibleIndex - first);
if (lapView != null) {
float toXValue = shiftX ? 1.0f * (visibleIndex - first + 1) : 0;
float toYValue = shiftX ? 0 : 4.0f * (visibleIndex - first + 1);
TranslateAnimation animation = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, toXValue, Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, toYValue);
animation.setStartOffset((last - visibleIndex) * offset);
animation.setDuration(duration);
lapView.startAnimation(animation);
}
}
}
}
}
@Override
public void endTransition(LayoutTransition transition, ViewGroup container, View view, int transitionType) {
if (transitionType == LayoutTransition.DISAPPEARING) {
if (DEBUG)
LogUtils.v("StopwatchFragment.end laps-list disappearing");
int last = mLapsList.getLastVisiblePosition();
for (int visibleIndex = mLapsList.getFirstVisiblePosition(); visibleIndex <= last; visibleIndex++) {
View lapView = mLapsList.getChildAt(visibleIndex);
if (lapView != null) {
Animation animation = lapView.getAnimation();
if (animation != null) {
animation.cancel();
}
}
}
}
}
});
return v;
}
Aggregations