Esempio n. 1
0
 private void addScrollListener(
     final ViewGroup vg, final boolean setForTop, final boolean setForBottom) {
   if ((!setForBottom && mTopOnScrollChangedListener == null
       || (setForBottom && mBottomOnScrollChangedListener == null))) {
     ViewTreeObserver.OnScrollChangedListener onScrollChangedListener =
         new ViewTreeObserver.OnScrollChangedListener() {
           @Override
           public void onScrollChanged() {
             boolean hasButtons = false;
             for (MDButton button : mButtons) {
               if (button != null && button.getVisibility() != View.GONE) {
                 hasButtons = true;
                 break;
               }
             }
             if (vg instanceof WebView) {
               invalidateDividersForWebView((WebView) vg, setForTop, setForBottom, hasButtons);
             } else {
               invalidateDividersForScrollingView(vg, setForTop, setForBottom, hasButtons);
             }
             invalidate();
           }
         };
     if (!setForBottom) {
       mTopOnScrollChangedListener = onScrollChangedListener;
       vg.getViewTreeObserver().addOnScrollChangedListener(mTopOnScrollChangedListener);
     } else {
       mBottomOnScrollChangedListener = onScrollChangedListener;
       vg.getViewTreeObserver().addOnScrollChangedListener(mBottomOnScrollChangedListener);
     }
     onScrollChangedListener.onScrollChanged();
   }
 }
 private static void sceneChangeRunTransition(ViewGroup sceneRoot, Transition transition) {
   if (transition != null && sceneRoot != null) {
     MultiListener listener = new MultiListener(transition, sceneRoot);
     sceneRoot.addOnAttachStateChangeListener(listener);
     sceneRoot.getViewTreeObserver().addOnPreDrawListener(listener);
   }
 }
Esempio n. 3
0
  public LoadToast(Context context) {
    mView = new LoadToastView(context);
    mParentView =
        (ViewGroup)
            ((Activity) context).getWindow().getDecorView().findViewById(android.R.id.content);
    mParentView.addView(
        mView,
        new ViewGroup.LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
    ViewHelper.setAlpha(mView, 0);
    mParentView.postDelayed(
        new Runnable() {
          @Override
          public void run() {
            ViewHelper.setTranslationX(mView, (mParentView.getWidth() - mView.getWidth()) / 2);
            ViewHelper.setTranslationY(mView, -mView.getHeight() + mTranslationY);
            mInflated = true;
            if (!mToastCanceled && mShowCalled) show();
          }
        },
        1);

    mParentView
        .getViewTreeObserver()
        .addOnGlobalLayoutListener(
            new ViewTreeObserver.OnGlobalLayoutListener() {
              @Override
              public void onGlobalLayout() {
                checkZPosition();
              }
            });
  }
Esempio n. 4
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);
  }
 private void fixLayout() {
   if (avatarContainer != null) {
     avatarContainer
         .getViewTreeObserver()
         .addOnPreDrawListener(
             new ViewTreeObserver.OnPreDrawListener() {
               @Override
               public boolean onPreDraw() {
                 if (avatarContainer != null) {
                   avatarContainer.getViewTreeObserver().removeOnPreDrawListener(this);
                 }
                 int padding =
                     (AndroidUtilities.getCurrentActionBarHeight() - AndroidUtilities.dp(48)) / 2;
                 avatarContainer.setPadding(
                     avatarContainer.getPaddingLeft(),
                     padding,
                     avatarContainer.getPaddingRight(),
                     padding);
                 return true;
               }
             });
   }
   if (messageContainer != null) {
     messageContainer
         .getViewTreeObserver()
         .addOnPreDrawListener(
             new ViewTreeObserver.OnPreDrawListener() {
               @Override
               public boolean onPreDraw() {
                 messageContainer.getViewTreeObserver().removeOnPreDrawListener(this);
                 if (!checkTransitionAnimation() && !startedMoving) {
                   ViewGroup.MarginLayoutParams layoutParams =
                       (ViewGroup.MarginLayoutParams) messageContainer.getLayoutParams();
                   layoutParams.topMargin = AndroidUtilities.getCurrentActionBarHeight();
                   layoutParams.bottomMargin = AndroidUtilities.dp(48);
                   layoutParams.width = ViewGroup.MarginLayoutParams.MATCH_PARENT;
                   layoutParams.height = ViewGroup.MarginLayoutParams.MATCH_PARENT;
                   messageContainer.setLayoutParams(layoutParams);
                   applyViewsLayoutParams(0);
                 }
                 return true;
               }
             });
   }
 }
  private static void sceneChangeRunTransition(
      final ViewGroup sceneRoot, final Transition transition) {
    if (transition != null) {
      final ViewTreeObserver observer = sceneRoot.getViewTreeObserver();
      final ViewTreeObserver.OnPreDrawListener listener =
          new ViewTreeObserver.OnPreDrawListener() {
            public boolean onPreDraw() {
              sceneRoot.getViewTreeObserver().removeOnPreDrawListener(this);
              sPendingTransitions.remove(sceneRoot);
              // Add to running list, handle end to remove it
              final ArrayMap<ViewGroup, ArrayList<Transition>> runningTransitions =
                  getRunningTransitions();
              ArrayList<Transition> currentTransitions = runningTransitions.get(sceneRoot);
              ArrayList<Transition> previousRunningTransitions = null;
              if (currentTransitions == null) {
                currentTransitions = new ArrayList<Transition>();
                runningTransitions.put(sceneRoot, currentTransitions);
              } else if (currentTransitions.size() > 0) {
                previousRunningTransitions = new ArrayList<Transition>(currentTransitions);
              }
              currentTransitions.add(transition);
              transition.addListener(
                  new Transition.TransitionListenerAdapter() {
                    @Override
                    public void onTransitionEnd(Transition transition) {
                      ArrayList<Transition> currentTransitions = runningTransitions.get(sceneRoot);
                      currentTransitions.remove(transition);
                    }
                  });
              transition.captureValues(sceneRoot, false);
              if (previousRunningTransitions != null) {
                for (Transition runningTransition : previousRunningTransitions) {
                  runningTransition.resume();
                }
              }
              transition.playTransition(sceneRoot);

              return true;
            }
          };
      observer.addOnPreDrawListener(listener);
    }
  }
Esempio n. 7
0
  public void showLongPressCling(boolean showWelcome) {
    ViewGroup root = (ViewGroup) mLauncher.findViewById(R.id.launcher);
    View cling = mInflater.inflate(R.layout.longpress_cling, root, false);

    cling.setOnLongClickListener(
        new OnLongClickListener() {

          @Override
          public boolean onLongClick(View v) {
            mLauncher.getWorkspace().enterOverviewMode();
            dismissLongPressCling();
            return true;
          }
        });

    final ViewGroup content = (ViewGroup) cling.findViewById(R.id.cling_content);
    mInflater.inflate(
        showWelcome ? R.layout.longpress_cling_welcome_content : R.layout.longpress_cling_content,
        content);
    content.findViewById(R.id.cling_dismiss_longpress_info).setOnClickListener(this);

    if (TAG_CROP_TOP_AND_SIDES.equals(content.getTag())) {
      Drawable bg =
          new BorderCropDrawable(
              mLauncher.getResources().getDrawable(R.drawable.cling_bg), true, true, true, false);
      content.setBackground(bg);
    }

    root.addView(cling);

    if (showWelcome) {
      // This is the first cling being shown. No need to animate.
      return;
    }

    // Animate
    content
        .getViewTreeObserver()
        .addOnGlobalLayoutListener(
            new OnGlobalLayoutListener() {

              @Override
              public void onGlobalLayout() {
                content.getViewTreeObserver().removeOnGlobalLayoutListener(this);

                ObjectAnimator anim;
                if (TAG_CROP_TOP_AND_SIDES.equals(content.getTag())) {
                  content.setTranslationY(-content.getMeasuredHeight());
                  anim = LauncherAnimUtils.ofFloat(content, "translationY", 0);
                } else {
                  content.setScaleX(0);
                  content.setScaleY(0);
                  PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1);
                  PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1);
                  anim = LauncherAnimUtils.ofPropertyValuesHolder(content, scaleX, scaleY);
                }

                anim.setDuration(SHOW_CLING_DURATION);
                anim.setInterpolator(new LogDecelerateInterpolator(100, 0));
                anim.start();
              }
            });
  }