@Override
  protected void onSizeChanged(int w, int h, int oldw, int oldh) {
    super.onSizeChanged(w, h, oldw, oldh);

    // Skip this work if a transition is running; it sets the scroll values independently
    // and should not have those animated values clobbered by this logic
    LayoutTransition transition = mLinearLayout.getLayoutTransition();
    if (transition != null && transition.isRunning()) {
      return;
    }
    // Keep track of the last visible item in the list so we can restore it
    // to the bottom when the orientation changes.
    mLastScrollPosition = scrollPositionOfMostRecent();

    // This has to happen post-layout, so run it "in the future"
    post(
        new Runnable() {
          public void run() {
            // Make sure we're still not clobbering the transition-set values, since this
            // runnable launches asynchronously
            LayoutTransition transition = mLinearLayout.getLayoutTransition();
            if (transition == null || !transition.isRunning()) {
              scrollTo(mLastScrollPosition, 0);
            }
          }
        });
  }
 private LayoutTransition createLayoutTransitioner() {
   LayoutTransition transitioner = new LayoutTransition();
   transitioner.setDuration(200);
   transitioner.setStartDelay(LayoutTransition.CHANGE_DISAPPEARING, 0);
   transitioner.setAnimator(LayoutTransition.DISAPPEARING, null);
   return transitioner;
 }
 private void disableLayoutTransitions() {
   LayoutTransition transition = getLayoutTransition();
   transition.disableTransitionType(LayoutTransition.APPEARING);
   transition.disableTransitionType(LayoutTransition.DISAPPEARING);
   transition.disableTransitionType(LayoutTransition.CHANGE_APPEARING);
   transition.disableTransitionType(LayoutTransition.CHANGE_DISAPPEARING);
 }
 private void setupTransition(LayoutTransition transition) {
   CheckBox customAnimCB = (CheckBox) findViewById(R.id.customAnimCB);
   CheckBox appearingCB = (CheckBox) findViewById(R.id.appearingCB);
   CheckBox disappearingCB = (CheckBox) findViewById(R.id.disappearingCB);
   CheckBox changingAppearingCB = (CheckBox) findViewById(R.id.changingAppearingCB);
   CheckBox changingDisappearingCB = (CheckBox) findViewById(R.id.changingDisappearingCB);
   transition.setAnimator(
       LayoutTransition.APPEARING,
       appearingCB.isChecked()
           ? (customAnimCB.isChecked() ? customAppearingAnim : defaultAppearingAnim)
           : null);
   transition.setAnimator(
       LayoutTransition.DISAPPEARING,
       disappearingCB.isChecked()
           ? (customAnimCB.isChecked() ? customDisappearingAnim : defaultDisappearingAnim)
           : null);
   transition.setAnimator(
       LayoutTransition.CHANGE_APPEARING,
       changingAppearingCB.isChecked()
           ? (customAnimCB.isChecked()
               ? customChangingAppearingAnim
               : defaultChangingAppearingAnim)
           : null);
   transition.setAnimator(
       LayoutTransition.CHANGE_DISAPPEARING,
       changingDisappearingCB.isChecked()
           ? (customAnimCB.isChecked()
               ? customChangingDisappearingAnim
               : defaultChangingDisappearingAnim)
           : null);
 }
  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);

    if (SLIPPERY_WHEN_DISABLED) {
      setSlippery(disableHome && disableRecent && disableBack && disableSearch);
    }

    if (!mScreenOn && mCurrentView != null) {
      ViewGroup navButtons = (ViewGroup) mCurrentView.findViewById(R.id.nav_buttons);
      LayoutTransition lt = navButtons == null ? null : navButtons.getLayoutTransition();
      if (lt != null) {
        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);

    getSearchLight().setVisibility((disableHome && !disableSearch) ? View.VISIBLE : View.GONE);
  }
  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);
  }
示例#7
0
 @Override
 public void startTransition(
     LayoutTransition transition, ViewGroup container, View view, int transitionType) {
   if (view.getId() == TkR.id.tablet_back) {
     mBackTransitioning = true;
   } else if (view.getId() == TkR.id.tablet_home
       && transitionType == LayoutTransition.APPEARING) {
     mHomeAppearing = true;
     mStartDelay = transition.getStartDelay(transitionType);
     mDuration = transition.getDuration(transitionType);
     mInterpolator = transition.getInterpolator(transitionType);
   }
 }
  public PageIndicator(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.PageIndicator, defStyle, 0);
    mMaxWindowSize = a.getInteger(R.styleable.PageIndicator_windowSize, 15);
    mWindowRange[0] = 0;
    mWindowRange[1] = 0;
    mLayoutInflater = LayoutInflater.from(context);
    a.recycle();

    // Set the layout transition properties
    LayoutTransition transition = getLayoutTransition();
    transition.setDuration(175);
  }
示例#9
0
  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;
  }
示例#10
0
 public void show(boolean showAnimation) {
   if (showAnimation) {
     mLayoutTransition.setDuration(200);
   } else {
     mLayoutTransition.setDuration(0);
   }
   mPickerHeight = EmoticonPickerUtil.getKeyboardHeight(mActivity);
   EmoticonPickerUtil.hideKeyBoard(this.mEditText);
   getLayoutParams().height = mPickerHeight;
   setVisibility(View.VISIBLE);
   // open EmoticonPicker, press home, press app switcher to return to write weibo interface,
   // keyboard will be opened by android system when EmoticonPicker is showing,
   // this method is used to fix this issue
   mActivity
       .getWindow()
       .setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
 }
示例#11
0
  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;
  }
示例#12
0
  private void setupAnimations(LayoutTransition transition) {
    //        ObjectAnimator animIn = ObjectAnimator.ofFloat(null, "translationY",
    //                EmoticonPickerUtil.getScreenHeight(mActivity), mPickerHeight).
    //                setDuration(transition.getDuration(LayoutTransition.APPEARING));
    //        transition.setAnimator(LayoutTransition.APPEARING, animIn);

    // 进入时不显示动画,增加体验
    ObjectAnimator animIn =
        ObjectAnimator.ofFloat(null, "translationY", 0, mPickerHeight)
            .setDuration(transition.getDuration(LayoutTransition.APPEARING));
    transition.setAnimator(LayoutTransition.APPEARING, animIn);

    ObjectAnimator animOut =
        ObjectAnimator.ofFloat(
                null, "translationY", mPickerHeight, EmoticonPickerUtil.getScreenHeight(mActivity))
            .setDuration(transition.getDuration(LayoutTransition.DISAPPEARING));
    transition.setAnimator(LayoutTransition.DISAPPEARING, animOut);
  }
示例#13
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);
    }
  }
示例#14
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*/);
  }
示例#15
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;
 }
示例#16
0
  /** 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);
          }
        });
  }
  /**
   * Create a searchbox with params and a style
   *
   * @param context Context
   * @param attrs Attributes
   * @param defStyle Style
   */
  public SearchBox(final Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    inflate(context, R.layout.searchbox, this);
    this.searchOpen = false;
    this.isMic = true;
    this.materialMenu = (MaterialMenuView) findViewById(R.id.material_menu_button);
    this.logo = (TextView) findViewById(R.id.logo);
    this.search = (EditText) findViewById(R.id.search);
    this.results = (ListView) findViewById(R.id.results);
    this.context = context;
    this.pb = (ProgressBar) findViewById(R.id.pb);
    this.mic = (ImageView) findViewById(R.id.mic);
    this.overflow = (ImageView) findViewById(R.id.overflow);
    this.drawerLogo = (ImageView) findViewById(R.id.drawer_logo);
    materialMenu.setOnClickListener(
        new OnClickListener() {

          @Override
          public void onClick(View v) {
            if (searchOpen) {

              toggleSearch();
            } else {
              if (menuListener != null) menuListener.onMenuClick();
            }
          }
        });
    resultList = new ArrayList<SearchResult>();
    setAdapter(new SearchAdapter(context, resultList, search));
    animate = true;
    isVoiceRecognitionIntentSupported =
        isIntentAvailable(context, new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH));
    logo.setOnClickListener(
        new OnClickListener() {

          @Override
          public void onClick(View v) {
            toggleSearch();
          }
        });
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
      RelativeLayout searchRoot = (RelativeLayout) findViewById(R.id.search_root);
      LayoutTransition lt = new LayoutTransition();
      lt.setDuration(100);
      searchRoot.setLayoutTransition(lt);
    }
    searchables = new ArrayList<SearchResult>();
    search.setOnEditorActionListener(
        new OnEditorActionListener() {
          public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_SEARCH) {
              search(getSearchText());
              return true;
            }
            return false;
          }
        });
    search.setOnKeyListener(
        new OnKeyListener() {
          public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (keyCode == KeyEvent.KEYCODE_ENTER) {
              if (TextUtils.isEmpty(getSearchText())) {
                toggleSearch();
              } else {
                search(getSearchText());
              }
              return true;
            }
            return false;
          }
        });
    logoText = "";
    micStateChanged();
    mic.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(View v) {
            if (voiceRecognitionListener != null) {
              voiceRecognitionListener.onClick();
            } else {
              micClick();
            }
          }
        });

    overflow.setOnClickListener(
        new OnClickListener() {

          @Override
          public void onClick(View v) {
            popupMenu.show();
          }
        });

    search.addTextChangedListener(
        new TextWatcher() {

          @Override
          public void afterTextChanged(Editable s) {
            if (s.length() > 0) {
              micStateChanged(false);
              mic.setImageDrawable(getContext().getResources().getDrawable(R.drawable.ic_clear));
              updateResults();
            } else {
              micStateChanged(true);
              mic.setImageDrawable(
                  getContext().getResources().getDrawable(R.drawable.ic_action_mic));
              if (initialResults != null) {
                setInitialResults();
              } else {
                updateResults();
              }
            }

            if (listener != null) listener.onSearchTermChanged(s.toString());
          }

          @Override
          public void beforeTextChanged(CharSequence s, int start, int count, int after) {}

          @Override
          public void onTextChanged(CharSequence s, int start, int before, int count) {}
        });
    // Default search Algorithm
    mSearchFilter =
        new SearchFilter() {
          @Override
          public boolean onFilter(SearchResult searchResult, String searchTerm) {
            return searchResult.title.toLowerCase().startsWith(searchTerm.toLowerCase());
          }
        };
  }
示例#18
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;
  }
  // called by onCreate; this is subclassed to overwrite WallpaperCropActivity
  protected void init() {
    setContentView(R.layout.wallpaper_picker);

    mCropView = (CropView) findViewById(R.id.cropView);
    mCropView.setVisibility(View.INVISIBLE);

    mWallpaperStrip = findViewById(R.id.wallpaper_strip);
    mCropView.setTouchCallback(
        new CropView.TouchCallback() {
          ViewPropertyAnimator mAnim;

          @Override
          public void onTouchDown() {
            if (mAnim != null) {
              mAnim.cancel();
            }
            if (mWallpaperStrip.getAlpha() == 1f) {
              mIgnoreNextTap = true;
            }
            mAnim = mWallpaperStrip.animate();
            mAnim
                .alpha(0f)
                .setDuration(150)
                .withEndAction(
                    new Runnable() {
                      public void run() {
                        mWallpaperStrip.setVisibility(View.INVISIBLE);
                      }
                    });
            mAnim.setInterpolator(new AccelerateInterpolator(0.75f));
            mAnim.start();
          }

          @Override
          public void onTouchUp() {
            mIgnoreNextTap = false;
          }

          @Override
          public void onTap() {
            boolean ignoreTap = mIgnoreNextTap;
            mIgnoreNextTap = false;
            if (!ignoreTap) {
              if (mAnim != null) {
                mAnim.cancel();
              }
              mWallpaperStrip.setVisibility(View.VISIBLE);
              mAnim = mWallpaperStrip.animate();
              mAnim.alpha(1f).setDuration(150).setInterpolator(new DecelerateInterpolator(0.75f));
              mAnim.start();
            }
          }
        });

    mThumbnailOnClickListener =
        new OnClickListener() {
          public void onClick(View v) {
            if (mActionMode != null) {
              // When CAB is up, clicking toggles the item instead
              if (v.isLongClickable()) {
                mLongClickListener.onLongClick(v);
              }
              return;
            }
            mSetWallpaperButton.setEnabled(true);
            WallpaperTileInfo info = (WallpaperTileInfo) v.getTag();
            if (info.isSelectable() && v.getVisibility() == View.VISIBLE) {
              selectTile(v);
            }
            info.onClick(WallpaperPickerActivity.this);
          }
        };
    mLongClickListener =
        new View.OnLongClickListener() {
          // Called when the user long-clicks on someView
          public boolean onLongClick(View view) {
            CheckableFrameLayout c = (CheckableFrameLayout) view;
            c.toggle();

            if (mActionMode != null) {
              mActionMode.invalidate();
            } else {
              // Start the CAB using the ActionMode.Callback defined below
              mActionMode = startActionMode(mActionModeCallback);
              int childCount = mWallpapersView.getChildCount();
              for (int i = 0; i < childCount; i++) {
                mWallpapersView.getChildAt(i).setSelected(false);
              }
            }
            return true;
          }
        };

    // Populate the built-in wallpapers
    ArrayList<ResourceWallpaperInfo> wallpapers = findBundledWallpapers();
    mWallpapersView = (LinearLayout) findViewById(R.id.wallpaper_list);
    BuiltInWallpapersAdapter ia = new BuiltInWallpapersAdapter(this, wallpapers);
    populateWallpapersFromAdapter(mWallpapersView, ia, false);

    // Populate the saved wallpapers
    mSavedImages = new SavedWallpaperImages(this);
    mSavedImages.loadThumbnailsAndImageIdList();
    populateWallpapersFromAdapter(mWallpapersView, mSavedImages, true);

    // Populate the live wallpapers
    final LinearLayout liveWallpapersView = (LinearLayout) findViewById(R.id.live_wallpaper_list);
    final LiveWallpaperListAdapter a = new LiveWallpaperListAdapter(this);
    a.registerDataSetObserver(
        new DataSetObserver() {
          public void onChanged() {
            liveWallpapersView.removeAllViews();
            populateWallpapersFromAdapter(liveWallpapersView, a, false);
            initializeScrollForRtl();
            updateTileIndices();
          }
        });

    // Populate the third-party wallpaper pickers
    final LinearLayout thirdPartyWallpapersView =
        (LinearLayout) findViewById(R.id.third_party_wallpaper_list);
    final ThirdPartyWallpaperPickerListAdapter ta = new ThirdPartyWallpaperPickerListAdapter(this);
    populateWallpapersFromAdapter(thirdPartyWallpapersView, ta, false);

    // Add a tile for the Gallery
    LinearLayout masterWallpaperList = (LinearLayout) findViewById(R.id.master_wallpaper_list);
    FrameLayout pickImageTile =
        (FrameLayout)
            getLayoutInflater()
                .inflate(R.layout.wallpaper_picker_image_picker_item, masterWallpaperList, false);
    setWallpaperItemPaddingToZero(pickImageTile);
    masterWallpaperList.addView(pickImageTile, 0);

    // Make its background the last photo taken on external storage
    Bitmap lastPhoto = getThumbnailOfLastPhoto();
    if (lastPhoto != null) {
      ImageView galleryThumbnailBg = (ImageView) pickImageTile.findViewById(R.id.wallpaper_image);
      galleryThumbnailBg.setImageBitmap(getThumbnailOfLastPhoto());
      int colorOverlay = getResources().getColor(R.color.wallpaper_picker_translucent_gray);
      galleryThumbnailBg.setColorFilter(colorOverlay, PorterDuff.Mode.SRC_ATOP);
    }

    PickImageInfo pickImageInfo = new PickImageInfo();
    pickImageTile.setTag(pickImageInfo);
    pickImageInfo.setView(pickImageTile);
    pickImageTile.setOnClickListener(mThumbnailOnClickListener);

    // Add a tile for the default wallpaper
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
      DefaultWallpaperInfo defaultWallpaperInfo = getDefaultWallpaper();
      if (defaultWallpaperInfo != null) {
        FrameLayout defaultWallpaperTile =
            (FrameLayout)
                createImageTileView(
                    getLayoutInflater(), 0, null, mWallpapersView, defaultWallpaperInfo.mThumb);
        setWallpaperItemPaddingToZero(defaultWallpaperTile);
        defaultWallpaperTile.setTag(defaultWallpaperInfo);
        mWallpapersView.addView(defaultWallpaperTile, 0);
        defaultWallpaperTile.setOnClickListener(mThumbnailOnClickListener);
        defaultWallpaperInfo.setView(defaultWallpaperTile);
      }
    }

    // Select the first item; wait for a layout pass so that we initialize the dimensions of
    // cropView or the defaultWallpaperView first
    mCropView.addOnLayoutChangeListener(
        new OnLayoutChangeListener() {
          @Override
          public void onLayoutChange(
              View v,
              int left,
              int top,
              int right,
              int bottom,
              int oldLeft,
              int oldTop,
              int oldRight,
              int oldBottom) {
            if ((right - left) > 0 && (bottom - top) > 0) {
              if (mSelectedIndex >= 0 && mSelectedIndex < mWallpapersView.getChildCount()) {
                mThumbnailOnClickListener.onClick(mWallpapersView.getChildAt(mSelectedIndex));
                setSystemWallpaperVisiblity(false);
              }
              v.removeOnLayoutChangeListener(this);
            }
          }
        });

    updateTileIndices();

    // Update the scroll for RTL
    initializeScrollForRtl();

    // Create smooth layout transitions for when items are deleted
    final LayoutTransition transitioner = new LayoutTransition();
    transitioner.setDuration(200);
    transitioner.setStartDelay(LayoutTransition.CHANGE_DISAPPEARING, 0);
    transitioner.setAnimator(LayoutTransition.DISAPPEARING, null);
    mWallpapersView.setLayoutTransition(transitioner);

    // Action bar
    // Show the custom action bar view
    final ActionBar actionBar = getActionBar();
    actionBar.setCustomView(R.layout.actionbar_set_wallpaper);
    actionBar
        .getCustomView()
        .setOnClickListener(
            new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                if (mSelectedTile != null) {
                  WallpaperTileInfo info = (WallpaperTileInfo) mSelectedTile.getTag();
                  info.onSave(WallpaperPickerActivity.this);
                } else {
                  // no tile was selected, so we just finish the activity and go back
                  setResult(Activity.RESULT_OK);
                  finish();
                }
              }
            });
    mSetWallpaperButton = findViewById(R.id.set_wallpaper_button);

    // CAB for deleting items
    mActionModeCallback =
        new ActionMode.Callback() {
          // Called when the action mode is created; startActionMode() was called
          @Override
          public boolean onCreateActionMode(ActionMode mode, Menu menu) {
            // Inflate a menu resource providing context menu items
            MenuInflater inflater = mode.getMenuInflater();
            inflater.inflate(R.menu.cab_delete_wallpapers, menu);
            return true;
          }

          private int numCheckedItems() {
            int childCount = mWallpapersView.getChildCount();
            int numCheckedItems = 0;
            for (int i = 0; i < childCount; i++) {
              CheckableFrameLayout c = (CheckableFrameLayout) mWallpapersView.getChildAt(i);
              if (c.isChecked()) {
                numCheckedItems++;
              }
            }
            return numCheckedItems;
          }

          // Called each time the action mode is shown. Always called after onCreateActionMode,
          // but may be called multiple times if the mode is invalidated.
          @Override
          public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
            int numCheckedItems = numCheckedItems();
            if (numCheckedItems == 0) {
              mode.finish();
              return true;
            } else {
              mode.setTitle(
                  getResources()
                      .getQuantityString(
                          R.plurals.number_of_items_selected, numCheckedItems, numCheckedItems));
              return true;
            }
          }

          // Called when the user selects a contextual menu item
          @Override
          public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
            int itemId = item.getItemId();
            if (itemId == R.id.menu_delete) {
              int childCount = mWallpapersView.getChildCount();
              ArrayList<View> viewsToRemove = new ArrayList<View>();
              boolean selectedTileRemoved = false;
              for (int i = 0; i < childCount; i++) {
                CheckableFrameLayout c = (CheckableFrameLayout) mWallpapersView.getChildAt(i);
                if (c.isChecked()) {
                  WallpaperTileInfo info = (WallpaperTileInfo) c.getTag();
                  info.onDelete(WallpaperPickerActivity.this);
                  viewsToRemove.add(c);
                  if (i == mSelectedIndex) {
                    selectedTileRemoved = true;
                  }
                }
              }
              for (View v : viewsToRemove) {
                mWallpapersView.removeView(v);
              }
              if (selectedTileRemoved) {
                mSelectedIndex = -1;
                mSelectedTile = null;
                setSystemWallpaperVisiblity(true);
              }
              updateTileIndices();
              mode.finish(); // Action picked, so close the CAB
              return true;
            } else {
              return false;
            }
          }

          // Called when the user exits the action mode
          @Override
          public void onDestroyActionMode(ActionMode mode) {
            int childCount = mWallpapersView.getChildCount();
            for (int i = 0; i < childCount; i++) {
              CheckableFrameLayout c = (CheckableFrameLayout) mWallpapersView.getChildAt(i);
              c.setChecked(false);
            }
            if (mSelectedTile != null) {
              mSelectedTile.setSelected(true);
            }
            mActionMode = null;
          }
        };
  }
示例#20
0
  private void createCustomAnimations(LayoutTransition transition) {
    // Changing while Adding
    PropertyValuesHolder pvhLeft = PropertyValuesHolder.ofInt("left", 0, 1);
    PropertyValuesHolder pvhTop = PropertyValuesHolder.ofInt("top", 0, 1);
    PropertyValuesHolder pvhRight = PropertyValuesHolder.ofInt("right", 0, 1);
    PropertyValuesHolder pvhBottom = PropertyValuesHolder.ofInt("bottom", 0, 1);
    PropertyValuesHolder pvhScaleX = PropertyValuesHolder.ofFloat("scaleX", 1f, 0f, 1f);
    PropertyValuesHolder pvhScaleY = PropertyValuesHolder.ofFloat("scaleY", 1f, 0f, 1f);
    customChangingAppearingAnim =
        ObjectAnimator.ofPropertyValuesHolder(
                this, pvhLeft, pvhTop, pvhRight, pvhBottom, pvhScaleX, pvhScaleY)
            .setDuration(transition.getDuration(LayoutTransition.CHANGE_APPEARING));
    customChangingAppearingAnim.addListener(
        new AnimatorListenerAdapter() {
          public void onAnimationEnd(Animator anim) {
            View view = (View) ((ObjectAnimator) anim).getTarget();
            view.setScaleX(1f);
            view.setScaleY(1f);
          }
        });

    // Changing while Removing
    Keyframe kf0 = Keyframe.ofFloat(0f, 0f);
    Keyframe kf1 = Keyframe.ofFloat(.9999f, 360f);
    Keyframe kf2 = Keyframe.ofFloat(1f, 0f);
    PropertyValuesHolder pvhRotation = PropertyValuesHolder.ofKeyframe("rotation", kf0, kf1, kf2);
    customChangingDisappearingAnim =
        ObjectAnimator.ofPropertyValuesHolder(
                this, pvhLeft, pvhTop, pvhRight, pvhBottom, pvhRotation)
            .setDuration(transition.getDuration(LayoutTransition.CHANGE_DISAPPEARING));
    customChangingDisappearingAnim.addListener(
        new AnimatorListenerAdapter() {
          public void onAnimationEnd(Animator anim) {
            View view = (View) ((ObjectAnimator) anim).getTarget();
            view.setRotation(0f);
          }
        });

    // Adding
    customAppearingAnim =
        ObjectAnimator.ofFloat(null, "rotationY", 90f, 0f)
            .setDuration(transition.getDuration(LayoutTransition.APPEARING));
    customAppearingAnim.addListener(
        new AnimatorListenerAdapter() {
          public void onAnimationEnd(Animator anim) {
            View view = (View) ((ObjectAnimator) anim).getTarget();
            view.setRotationY(0f);
          }
        });

    // Removing
    customDisappearingAnim =
        ObjectAnimator.ofFloat(null, "rotationX", 0f, 90f)
            .setDuration(transition.getDuration(LayoutTransition.DISAPPEARING));
    customDisappearingAnim.addListener(
        new AnimatorListenerAdapter() {
          public void onAnimationEnd(Animator anim) {
            View view = (View) ((ObjectAnimator) anim).getTarget();
            view.setRotationX(0f);
          }
        });
  }
 private void createCustomAnimations(LayoutTransition transitioner) {
   transitioner.setDuration(200);
   transitioner.setStartDelay(LayoutTransition.CHANGE_DISAPPEARING, 0);
   transitioner.setAnimator(LayoutTransition.DISAPPEARING, null);
 }