private void enableLayoutTransitions() { LayoutTransition transition = getLayoutTransition(); transition.enableTransitionType(LayoutTransition.APPEARING); transition.enableTransitionType(LayoutTransition.DISAPPEARING); transition.enableTransitionType(LayoutTransition.CHANGE_APPEARING); transition.enableTransitionType(LayoutTransition.CHANGE_DISAPPEARING); }
private void setupPaneLayout(OverlappingPaneLayout paneLayout) { // TODO: Remove the notion of a capturable view. The entire view be slideable, once // the framework better supports nested scrolling. paneLayout.setCapturableView(mViewPagerTabs); paneLayout.openPane(); paneLayout.setPanelSlideCallbacks(mPanelSlideCallbacks); paneLayout.setIntermediatePinnedOffset(((HostInterface) getActivity()).getActionBarHeight()); LayoutTransition transition = paneLayout.getLayoutTransition(); // Turns on animations for all types of layout changes so that they occur for // height changes. transition.enableTransitionType(LayoutTransition.CHANGING); }
private void showSearch() { // set transiontn LayoutTransition l = new LayoutTransition(); l.enableTransitionType(LayoutTransition.APPEARING); RelativeLayout rl = (RelativeLayout) getView().findViewById(R.id.rl_vendorlist); rl.setLayoutTransition(l); // animate mActvSearch.setVisibility(View.VISIBLE); // show keyboard mActvSearch.requestFocus(); InputMethodManager keyboard = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE); keyboard.showSoftInput(mActvSearch, 0); mSearchWasVisible = true; }
private void hideSearch() { // set transiontn LayoutTransition l = new LayoutTransition(); l.enableTransitionType(LayoutTransition.DISAPPEARING); RelativeLayout rl = (RelativeLayout) getView().findViewById(R.id.rl_vendorlist); rl.setLayoutTransition(l); // animate mActvSearch.setVisibility(View.GONE); // set text to "" mActvSearch.setText(""); InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(mActvSearch.getWindowToken(), 0); mSearchWasVisible = false; }
@Override public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment ViewGroup v = (ViewGroup) inflater.inflate(R.layout.stopwatch_fragment, container, false); mLeftButton = (ImageButton) v.findViewById(R.id.stopwatch_left_button); mLeftButton.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { long time = Utils.getTimeNow(); Context context = getActivity().getApplicationContext(); Intent intent = new Intent(context, StopwatchService.class); intent.putExtra(Stopwatches.MESSAGE_TIME, time); intent.putExtra(Stopwatches.SHOW_NOTIF, false); switch (mState) { case Stopwatches.STOPWATCH_RUNNING: // Save lap time addLapTime(time); doLap(); intent.setAction(Stopwatches.LAP_STOPWATCH); context.startService(intent); break; case Stopwatches.STOPWATCH_STOPPED: // do reset doReset(); intent.setAction(Stopwatches.RESET_STOPWATCH); context.startService(intent); releaseWakeLock(); break; default: // Happens in monkey tests Log.i( LOG_TAG, "Illegal state " + mState + " while pressing the left stopwatch button"); break; } } }); mCenterButton = (TextView) v.findViewById(R.id.stopwatch_stop); mShareButton = (ImageButton) v.findViewById(R.id.stopwatch_share_button); mShareButton.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { showSharePopup(); } }); mTime = (CircleTimerView) v.findViewById(R.id.stopwatch_time); mTimeText = (CountingTimerView) v.findViewById(R.id.stopwatch_time_text); mLapsList = (ListView) v.findViewById(R.id.laps_list); mLapsList.setDividerHeight(0); mLapsAdapter = new LapsListAdapter(getActivity()); mLapsList.setAdapter(mLapsAdapter); // Timer text serves as a virtual start/stop button. mTimeText.registerVirtualButtonAction( new Runnable() { @Override public void run() { rightButtonAction(); } }); mTimeText.registerStopTextView(mCenterButton); mTimeText.setVirtualButtonEnabled(true); mCircleLayout = (CircleButtonsLayout) v.findViewById(R.id.stopwatch_circle); mCircleLayout.setCircleTimerViewIds( R.id.stopwatch_time, R.id.stopwatch_left_button, R.id.stopwatch_share_button, R.id.stopwatch_stop, R.dimen.plusone_reset_button_padding, R.dimen.share_button_padding, 0, 0); /** No label for a stopwatch* */ // Animation setup mLayoutTransition = new LayoutTransition(); mCircleLayoutTransition = new LayoutTransition(); // The CircleButtonsLayout only needs to undertake location changes if (Build.VERSION.SDK_INT >= 16) { 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(R.id.start_space); mEndSpace = v.findViewById(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) Log.v(LOG_TAG, "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) Log.v(LOG_TAG, "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; }