예제 #1
0
 private LayoutTransition newLayoutTransition(TransitionListener listener) {
   final LayoutTransition transition = new LayoutTransition();
   transition.disableTransitionType(LayoutTransition.DISAPPEARING);
   transition.disableTransitionType(LayoutTransition.CHANGE_DISAPPEARING);
   transition.disableTransitionType(LayoutTransition.APPEARING);
   transition.setInterpolator(LayoutTransition.CHANGE_APPEARING, mInterpolator);
   if (listener != null) {
     transition.addTransitionListener(listener);
   }
   return transition;
 }
예제 #2
0
  public void setDisabledFlags(int disabledFlags, boolean force) {
    if (!force && mDisabledFlags == disabledFlags) return;

    mDisabledFlags = disabledFlags;

    final boolean disableHome = ((disabledFlags & View.STATUS_BAR_DISABLE_HOME) != 0);
    final boolean disableRecent = ((disabledFlags & View.STATUS_BAR_DISABLE_RECENT) != 0);
    final boolean disableBack =
        ((disabledFlags & View.STATUS_BAR_DISABLE_BACK) != 0)
            && ((mNavigationIconHints & StatusBarManager.NAVIGATION_HINT_BACK_ALT) == 0);
    final boolean disableSearch = ((disabledFlags & View.STATUS_BAR_DISABLE_SEARCH) != 0);

    ViewGroup navButtons = (ViewGroup) findViewById(SystemR.id.nav_buttons);
    if (navButtons != null) {
      LayoutTransition lt = navButtons.getLayoutTransition();
      if (lt != null) {
        if (!lt.getTransitionListeners().contains(mTransitionListener)) {
          lt.addTransitionListener(mTransitionListener);
        }
        if (!mScreenOn) {
          lt.disableTransitionType(
              LayoutTransition.CHANGE_APPEARING
                  | LayoutTransition.CHANGE_DISAPPEARING
                  | LayoutTransition.APPEARING
                  | LayoutTransition.DISAPPEARING);
        }
      }
    }
    getBackButton().setVisibility(disableBack ? View.INVISIBLE : View.VISIBLE);
    getHomeButton().setVisibility(disableHome ? View.INVISIBLE : View.VISIBLE);
    getRecentsButton().setVisibility(disableRecent ? View.INVISIBLE : View.VISIBLE);

    final boolean showSearch = disableHome && !disableSearch;
    //        final boolean showCamera = showSearch && !mCameraDisabledByDpm;
    setVisibleOrGone(getSearchLight(), showSearch);
    //        setVisibleOrGone(getCameraButton(), showCamera);

    mBarTransitions.applyBackButtonQuiescentAlpha(mBarTransitions.getMode(), true /*animate*/);
  }
예제 #3
0
  @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;
  }