@Override
  public void addView(View child, int left, int top) {
    if (child.getParent() instanceof ViewGroup) {
      ViewGroup parent = (ViewGroup) child.getParent();
      LayoutTransition layoutTransition = null;
      if (parent.getLayoutTransition() != null) {
        layoutTransition = parent.getLayoutTransition();
        parent.setLayoutTransition(null);
      }
      parent.removeView(child);
      if (layoutTransition != null) {
        parent.setLayoutTransition(layoutTransition);
      }

      if (child.getParent() != null) {
        // LayoutTransition will cause the child to delay removal - cancel it
        ViewGroupUtils.cancelLayoutTransition(parent);
        // fail-safe if view is still attached for any reason
        if (child.getParent() != null && FIELD_VIEW_PARENT != null) {
          ReflectionUtils.setFieldValue(child, FIELD_VIEW_PARENT, null);
        }
      }
      if (child.getParent() != null) {
        return;
      }
    }
    child.setTag(R.id.overlay_layout_params_backup, child.getLayoutParams());
    addView(child, initParams(child, left, top));
    invalidate();
  }
 public void onAnimationEnd(Animator animation) {
   if (mShowing) {
     final LayoutTransition transitioner = new LayoutTransition();
     ((ViewGroup) mRecentsContainer).setLayoutTransition(transitioner);
     createCustomAnimations(transitioner);
   } else {
     ((ViewGroup) mRecentsContainer).setLayoutTransition(null);
   }
 }
示例#3
0
  /**
   * 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);
    textView.setText(textStr);
    textView.setContentDescription(textStr);
  }
示例#4
0
 public void setEditText(Activity activity, ViewGroup rootLayout, EditText editText) {
   mActivity = activity;
   mEditText = editText;
   mEditText.setFilters(new InputFilter[] {getEmoticonInputFilter()});
   rootLayout.setLayoutTransition(mLayoutTransition);
   setupAnimations(mLayoutTransition);
 }
示例#5
0
  /** Show or hide the laps-list */
  private void showLaps() {
    if (DEBUG)
      Log.v(
          LOG_TAG, String.format("StopwatchFragment.showLaps: count=%d", mLapsAdapter.getCount()));

    boolean lapsVisible = mLapsAdapter.getCount() > 0;

    // Layout change animations will start upon the first add/hide view. Temporarily disable
    // the layout transition animation for the spacers, make the changes, then re-enable
    // the animation for the add/hide laps-list
    if (mSpacersUsed) {
      int spacersVisibility = lapsVisible ? View.GONE : View.VISIBLE;
      ViewGroup rootView = (ViewGroup) getView();
      if (rootView != null) {
        rootView.setLayoutTransition(null);
        if (mStartSpace != null) {
          mStartSpace.setVisibility(spacersVisibility);
        }
        if (mEndSpace != null) {
          mEndSpace.setVisibility(spacersVisibility);
        }
        rootView.setLayoutTransition(mLayoutTransition);
      }
    }

    if (lapsVisible) {
      // There are laps - show the laps-list
      // No delay for the CircleButtonsLayout changes - start immediately so that the
      // circle has shifted before the laps-list starts appearing.
      mCircleLayoutTransition.setStartDelay(LayoutTransition.CHANGING, 0);

      mLapsList.setVisibility(View.VISIBLE);
    } else {
      // There are no laps - hide the laps list

      // Delay the CircleButtonsLayout animation until after the laps-list disappears
      long startDelay =
          mLayoutTransition.getStartDelay(LayoutTransition.DISAPPEARING)
              + mLayoutTransition.getDuration(LayoutTransition.DISAPPEARING);
      mCircleLayoutTransition.setStartDelay(LayoutTransition.CHANGING, startDelay);
      mLapsList.setVisibility(View.GONE);
    }
  }
示例#6
0
  @Override
  protected void onFinishInflate() {
    super.onFinishInflate();

    mZenButtons = (SegmentedButtons) findViewById(R.id.zen_buttons);
    mZenButtons.addButton(
        R.string.interruption_level_none, R.drawable.ic_zen_none, Global.ZEN_MODE_NO_INTERRUPTIONS);
    mZenButtons.addButton(
        R.string.interruption_level_priority,
        R.drawable.ic_zen_important,
        Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS);
    mZenButtons.addButton(
        R.string.interruption_level_all, R.drawable.ic_zen_all, Global.ZEN_MODE_OFF);
    mZenButtons.setCallback(mZenButtonsCallback);

    final ViewGroup zenButtonsContainer = (ViewGroup) findViewById(R.id.zen_buttons_container);
    zenButtonsContainer.setLayoutTransition(newLayoutTransition(null));

    mZenSubhead = findViewById(R.id.zen_subhead);

    mZenSubheadCollapsed = (TextView) findViewById(R.id.zen_subhead_collapsed);
    mZenSubheadCollapsed.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            setExpanded(true);
          }
        });
    Interaction.register(mZenSubheadCollapsed, mInteractionCallback);

    mZenSubheadExpanded = (TextView) findViewById(R.id.zen_subhead_expanded);
    Interaction.register(mZenSubheadExpanded, mInteractionCallback);

    mMoreSettings = findViewById(R.id.zen_more_settings);
    mMoreSettings.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            fireMoreSettings();
          }
        });
    Interaction.register(mMoreSettings, mInteractionCallback);

    mZenConditions = (LinearLayout) findViewById(R.id.zen_conditions);
    for (int i = 0; i < mMaxConditions; i++) {
      mZenConditions.addView(mInflater.inflate(R.layout.zen_mode_condition, this, false));
    }

    setLayoutTransition(newLayoutTransition(mTransitionHelper));
  }
 public void show(final boolean show, boolean animate) {
   if (!show) {
     final LayoutTransition transitioner = animate ? createLayoutTransitioner() : null;
     ((ViewGroup) mSearchTargetsContainer).setLayoutTransition(transitioner);
   }
   mShowing = show;
   if (show) {
     maybeSwapSearchIcon();
     if (getVisibility() != View.VISIBLE) {
       setVisibility(View.VISIBLE);
       // Don't start the animation until we've created the layer, which is done
       // right before we are drawn
       mGlowPadView.suspendAnimations();
       mGlowPadView.ping();
       getViewTreeObserver().addOnPreDrawListener(mPreDrawListener);
       vibrate();
     }
     setFocusable(true);
     setFocusableInTouchMode(true);
     requestFocus();
   } else {
     setVisibility(View.INVISIBLE);
   }
 }
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.layout_animations);

    container = new FixedGridLayout(this);
    container.setClipChildren(false);
    ((FixedGridLayout) container).setCellHeight(90);
    ((FixedGridLayout) container).setCellWidth(100);
    final LayoutTransition transitioner = new LayoutTransition();
    container.setLayoutTransition(transitioner);
    defaultAppearingAnim = transitioner.getAnimator(LayoutTransition.APPEARING);
    defaultDisappearingAnim = transitioner.getAnimator(LayoutTransition.DISAPPEARING);
    defaultChangingAppearingAnim = transitioner.getAnimator(LayoutTransition.CHANGE_APPEARING);
    defaultChangingDisappearingAnim =
        transitioner.getAnimator(LayoutTransition.CHANGE_DISAPPEARING);
    createCustomAnimations(transitioner);
    currentAppearingAnim = defaultAppearingAnim;
    currentDisappearingAnim = defaultDisappearingAnim;
    currentChangingAppearingAnim = defaultChangingAppearingAnim;
    currentChangingDisappearingAnim = defaultChangingDisappearingAnim;

    ViewGroup parent = (ViewGroup) findViewById(R.id.parent);
    parent.addView(container);
    parent.setClipChildren(false);
    Button addButton = (Button) findViewById(R.id.addNewButton);
    addButton.setOnClickListener(
        new View.OnClickListener() {
          public void onClick(View v) {
            Button newButton = new Button(LayoutAnimation.this);
            newButton.setText(String.valueOf(numButtons++));
            newButton.setOnClickListener(
                new View.OnClickListener() {
                  public void onClick(View v) {
                    container.removeView(v);
                  }
                });
            container.addView(newButton, Math.min(1, container.getChildCount()));
          }
        });

    CheckBox customAnimCB = (CheckBox) findViewById(R.id.customAnimCB);
    customAnimCB.setOnCheckedChangeListener(
        new CompoundButton.OnCheckedChangeListener() {
          public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            setupTransition(transitioner);
          }
        });

    // Check for disabled animations
    CheckBox appearingCB = (CheckBox) findViewById(R.id.appearingCB);
    appearingCB.setOnCheckedChangeListener(
        new CompoundButton.OnCheckedChangeListener() {
          public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            setupTransition(transitioner);
          }
        });
    CheckBox disappearingCB = (CheckBox) findViewById(R.id.disappearingCB);
    disappearingCB.setOnCheckedChangeListener(
        new CompoundButton.OnCheckedChangeListener() {
          public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            setupTransition(transitioner);
          }
        });
    CheckBox changingAppearingCB = (CheckBox) findViewById(R.id.changingAppearingCB);
    changingAppearingCB.setOnCheckedChangeListener(
        new CompoundButton.OnCheckedChangeListener() {
          public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            setupTransition(transitioner);
          }
        });
    CheckBox changingDisappearingCB = (CheckBox) findViewById(R.id.changingDisappearingCB);
    changingDisappearingCB.setOnCheckedChangeListener(
        new CompoundButton.OnCheckedChangeListener() {
          public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            setupTransition(transitioner);
          }
        });
  }
示例#9
0
  @Override
  public void setCallState(
      int state,
      Call.DisconnectCause cause,
      boolean bluetoothOn,
      String gatewayLabel,
      String gatewayNumber) {
    String callStateLabel = null;

    // States other than disconnected not yet supported
    callStateLabel = getCallStateLabelFromState(state, cause);

    Log.v(this, "setCallState " + callStateLabel);
    Log.v(this, "DisconnectCause " + cause);
    Log.v(this, "bluetooth on " + bluetoothOn);
    Log.v(this, "gateway " + gatewayLabel + gatewayNumber);

    // There are cases where we totally skip the animation, in which case remove the transition
    // animation here and restore it afterwards.
    final boolean skipAnimation =
        (Call.State.isDialing(state)
            || state == Call.State.DISCONNECTED
            || state == Call.State.DISCONNECTING);
    LayoutTransition transition = null;
    if (skipAnimation) {
      transition = mSupplementaryInfoContainer.getLayoutTransition();
      mSupplementaryInfoContainer.setLayoutTransition(null);
    }

    // Update the call state label.
    if (!TextUtils.isEmpty(callStateLabel)) {
      mCallStateLabel.setVisibility(View.VISIBLE);
      mCallStateLabel.setText(callStateLabel);

      if (Call.State.INCOMING == state) {
        setBluetoothOn(bluetoothOn);
      }
    } else {
      mCallStateLabel.setVisibility(View.GONE);
      // Gravity is aligned left when receiving an incoming call in landscape.
      // In that rare case, the gravity needs to be reset to the right.
      // Also, setText("") is used since there is a delay in making the view GONE,
      // so the user will otherwise see the text jump to the right side before disappearing.
      if (mCallStateLabel.getGravity() != Gravity.END) {
        mCallStateLabel.setText("");
        mCallStateLabel.setGravity(Gravity.END);
      }
    }

    // Provider info: (e.g. "Calling via <gatewayLabel>")
    if (!TextUtils.isEmpty(gatewayLabel) && !TextUtils.isEmpty(gatewayNumber)) {
      mProviderLabel.setText(gatewayLabel);
      mProviderNumber.setText(gatewayNumber);
      mProviderInfo.setVisibility(View.VISIBLE);
    } else {
      mProviderInfo.setVisibility(View.GONE);
    }

    // Restore the animation.
    if (skipAnimation) {
      mSupplementaryInfoContainer.setLayoutTransition(transition);
    }
  }