Example #1
0
 public MultiCardMenu(Context context, AttributeSet attrs, int defStyleAttr) {
   super(context, attrs, defStyleAttr);
   mContext = context;
   ViewConfiguration vc = ViewConfiguration.get(context);
   mMaxVelocity = vc.getScaledMaximumFlingVelocity();
   mMinVelocity = vc.getScaledMinimumFlingVelocity() * 8;
   mTouchSlop = vc.getScaledTouchSlop();
   mDensity = context.getResources().getDisplayMetrics().density;
   TypedArray a =
       context.obtainStyledAttributes(attrs, R.styleable.MultiCardMenu, defStyleAttr, 0);
   MAX_CLICK_DISTANCE =
       mTitleBarHeightNoDisplay =
           a.getDimension(
               R.styleable.MultiCardMenu_title_bar_height_no_display,
               dip2px(DEFAULT_TITLE_BAR_HEIGHT_NO_DISPLAY));
   mTitleBarHeightDisplay =
       a.getDimension(
           R.styleable.MultiCardMenu_title_bar_height_display,
           dip2px(DEFAULT_TITLE_BAR_HEIGHT_DISPLAY));
   mMarginTop =
       a.getDimension(R.styleable.MultiCardMenu_margin_top, dip2px(DEFAULT_CARD_MARGIN_TOP));
   mMoveDistanceToTrigger =
       a.getDimension(
           R.styleable.MultiCardMenu_move_distance_to_trigger,
           dip2px(DEFAULT_MOVE_DISTANCE_TO_TRIGGER));
   mBackgroundRid = a.getResourceId(R.styleable.MultiCardMenu_background_layout, -1);
   mDuration = a.getInt(R.styleable.MultiCardMenu_animator_duration, DEFAULT_DURATION);
   isFade = a.getBoolean(R.styleable.MultiCardMenu_fade, true);
   mBoundary = a.getBoolean(R.styleable.MultiCardMenu_boundary, false);
   a.recycle();
   initBackgroundView();
 }
Example #2
0
 private void init(Context context, AttributeSet attributeset, int i)
 {
     ViewConfiguration viewconfiguration = ViewConfiguration.get(context);
     mScaledDensity = context.getResources().getDisplayMetrics().density / 2.0F;
     attributeset = context.getTheme().obtainStyledAttributes(attributeset, com.aviary.android.feather.sdk.R.styleable.AviaryWheel, i, 0);
     mShadowBottom = attributeset.getDrawable(com.aviary.android.feather.sdk.R.styleable.AviaryWheel_aviaryWheelShadowTop);
     mLinesSingle = attributeset.getDrawable(com.aviary.android.feather.sdk.R.styleable.AviaryWheel_aviaryWheelLine);
     mLinesIndicator = attributeset.getDrawable(com.aviary.android.feather.sdk.R.styleable.AviaryWheel_aviaryWheelIndicator);
     mEdgeStyle = attributeset.getResourceId(com.aviary.android.feather.sdk.R.styleable.AviaryWheel_aviary_edgeStyle, 0);
     attributeset.recycle();
     mEdgeOffset = (float)(20D * (double)mScaledDensity);
     mLineWidth = mLinesSingle.getIntrinsicWidth();
     mLinesPaint = new Paint(7);
     if (!isInEditMode())
     {
         mGestureDetector = new GestureDetector(context, this);
         mGestureDetector.setIsLongpressEnabled(false);
     }
     mScroller = new ScrollerRunnable(this, 200, viewconfiguration.getScaledOverflingDistance(), null);
     mVibrationHelper = new VibrationHelper(context, true);
     mEdgeLeft = new AviaryEdgeEffect(getContext(), mEdgeStyle);
     mEdgeRight = new AviaryEdgeEffect(getContext(), mEdgeStyle);
     mEdgeLeft.setEdgeMaxAlpha(100);
     mEdgeRight.setEdgeMaxAlpha(100);
     mNextValue = -1;
     mCurrentValue = 0.0D;
 }
Example #3
0
  public ListViewSwipeGesture(ListView listView, TouchCallbacks Callbacks, Activity context) {
    ViewConfiguration vc = ViewConfiguration.get(listView.getContext());
    mSlop = vc.getScaledTouchSlop();
    mMinFlingVelocity = vc.getScaledMinimumFlingVelocity() * 16;
    mMaxFlingVelocity = vc.getScaledMaximumFlingVelocity();
    mListView = listView;
    activity = context;
    tcallbacks = Callbacks;
    SwipeType = Double;
    GetResourcesValues();

    mListView.setOnItemClickListener(
        new AdapterView.OnItemClickListener() {

          @Override
          public void onItemClick(
              AdapterView<?> arg0,
              View arg1,
              int arg2,
              long arg3) { // Invokes OnClick Functionality

            if (!moptionsDisplay && DeltaX == 0.0) {
              tcallbacks.OnClickListView(temp_position);
            } else {
              if (old_mDownView != null && mDownView != old_mDownView) {
                ResetListItem(old_mDownView);
                old_mDownView = null;
                mDownView = null;
              }
            }
          }
        });
  }
  private void initWorkspace(Context context, AttributeSet attrs, int defStyle) {

    Theme theme = context.getTheme();

    TypedArray a = theme.obtainStyledAttributes(attrs, R.styleable.AviaryWorkspace, defStyle, 0);
    mDefaultScreen = a.getInt(R.styleable.AviaryWorkspace_aviary_defaultScreen, 0);
    int overscrollMode = a.getInt(R.styleable.AviaryWorkspace_aviary_overscroll, 0);
    a.recycle();

    setHapticFeedbackEnabled(false);

    mScrollInterpolator = new DecelerateInterpolator(1.0f);
    mScroller = new Scroller(context, mScrollInterpolator);
    mPreviousScreen = INVALID_SCREEN;

    final ViewConfiguration configuration = ViewConfiguration.get(getContext());
    mTouchSlop = configuration.getScaledTouchSlop();
    mMaximumVelocity = configuration.getScaledMaximumFlingVelocity();

    mPaddingTop = getPaddingTop();
    mPaddingBottom = getPaddingBottom();
    mPaddingLeft = getPaddingLeft();
    mPaddingRight = getPaddingRight();

    setOverScroll(overscrollMode);
  }
  /**
   * Constructs a new swipe touch listener for the given {@link RecyclerView}
   *
   * @param recyclerView The recycler view whose items should be dismissable by swiping.
   * @param listener The listener for the swipe events.
   */
  public SwipeableRecyclerViewTouchListener(RecyclerView recyclerView, SwipeListener listener) {
    ViewConfiguration vc = ViewConfiguration.get(recyclerView.getContext());
    mSlop = vc.getScaledTouchSlop();
    mMinFlingVelocity = vc.getScaledMinimumFlingVelocity() * 16;
    mMaxFlingVelocity = vc.getScaledMaximumFlingVelocity();
    mAnimationTime =
        recyclerView.getContext().getResources().getInteger(android.R.integer.config_shortAnimTime);
    mRecyclerView = recyclerView;
    mSwipeListener = listener;

    /**
     * This will ensure that this SwipeableRecyclerViewTouchListener is paused during list view
     * scrolling. If a scroll listener is already assigned, the caller should still pass scroll
     * changes through to this listener.
     */
    mRecyclerView.setOnScrollListener(
        new RecyclerView.OnScrollListener() {
          @Override
          public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
            setEnabled(newState != RecyclerView.SCROLL_STATE_DRAGGING);
          }

          @Override
          public void onScrolled(RecyclerView recyclerView, int dx, int dy) {}
        });
  }
  /**
   * Constructor that is called when inflating a view from XML. This is called when a view is being
   * constructed from an XML file, supplying attributes that were specified in the XML file. This
   * version uses a default style of 0, so the only attribute values applied are those in the
   * Context's Theme and the given AttributeSet.
   *
   * <p>The method onFinishInflate() will be called after all children have been added.
   *
   * @param context The Context the view is running in, through which it can access the current
   *     theme, resources, etc.
   * @param attrs The attributes of the XML tag that is inflating the view.
   */
  public TableFixHeaders(Context context, AttributeSet attrs) {
    super(context, attrs);

    this.headView = null;
    this.rowViewList = new ArrayList<View>();
    this.columnViewList = new ArrayList<View>();
    this.bodyViewTable = new ArrayList<List<View>>();

    this.needRelayout = true;

    this.shadows = new ImageView[4];
    this.shadows[0] = new ImageView(context);
    this.shadows[0].setImageResource(R.drawable.shadow_left);
    this.shadows[1] = new ImageView(context);
    this.shadows[1].setImageResource(R.drawable.shadow_top);
    this.shadows[2] = new ImageView(context);
    this.shadows[2].setImageResource(R.drawable.shadow_right);
    this.shadows[3] = new ImageView(context);
    this.shadows[3].setImageResource(R.drawable.shadow_bottom);

    //        this.lineView = new View(context);
    //        this.lineView.setTag(R.id.tag_row, -2);

    this.shadowSize = getResources().getDimensionPixelSize(R.dimen.shadow_size);

    this.flinger = new Flinger(context);
    final ViewConfiguration configuration = ViewConfiguration.get(context);
    this.touchSlop = configuration.getScaledTouchSlop();
    this.minimumVelocity = configuration.getScaledMinimumFlingVelocity();
    this.maximumVelocity = configuration.getScaledMaximumFlingVelocity();
  }
Example #7
0
  private void initView(Context context) {
    mPaint = new Paint();
    mPaint.setColor(Color.WHITE);
    Resources resources = context.getResources();

    // get viewConfiguration
    mClickTimeout = ViewConfiguration.getPressedStateDuration() + ViewConfiguration.getTapTimeout();
    mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();

    // get Bitmap
    mBottom = BitmapFactory.decodeResource(resources, R.drawable.bottom);
    mBtnPressed = BitmapFactory.decodeResource(resources, R.drawable.btn_pressed);
    mBtnNormal = BitmapFactory.decodeResource(resources, R.drawable.btn_unpressed);
    mFrame = BitmapFactory.decodeResource(resources, R.drawable.frame);
    mMask = BitmapFactory.decodeResource(resources, R.drawable.mask);
    mCurBtnPic = mBtnNormal;

    mBtnWidth = mBtnPressed.getWidth();
    mMaskWidth = mMask.getWidth();
    mMaskHeight = mMask.getHeight();

    mBtnOffPos = mBtnWidth / 2;
    mBtnOnPos = mMaskWidth - mBtnWidth / 2;

    mBtnPos = mChecked ? mBtnOnPos : mBtnOffPos;
    mRealPos = getRealPos(mBtnPos);

    final float density = getResources().getDisplayMetrics().density;
    mVelocity = (int) (VELOCITY * density + 0.5f);
    mExtendOffsetY = (int) (EXTENDED_OFFSET_Y * density + 0.5f);

    mSaveLayerRectF =
        new RectF(0, mExtendOffsetY, mMask.getWidth(), mMask.getHeight() + mExtendOffsetY);
    mXfermode = new PorterDuffXfermode(PorterDuff.Mode.SRC_IN);
  }
Example #8
0
  void initCustomViewAbove() {
    //		setDescendantFocusability(FOCUS_AFTER_DESCENDANTS);
    setDescendantFocusability(FOCUS_BEFORE_DESCENDANTS);
    setClickable(true);
    setFocusable(true);
    setWillNotDraw(false);
    final Context context = getContext();
    mScroller = new Scroller(context, sInterpolator);
    final ViewConfiguration configuration = ViewConfiguration.get(context);
    mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration);
    mMinimumVelocity = configuration.getScaledMinimumFlingVelocity();
    mMaximumVelocity = configuration.getScaledMaximumFlingVelocity();
    setInternalPageChangeListener(
        new SimpleOnPageChangeListener() {
          public void onPageSelected(int position) {
            if (mViewBehind != null) {
              switch (position) {
                case 0:
                case 2:
                  mViewBehind.setChildrenEnabled(true);
                  break;
                case 1:
                  mViewBehind.setChildrenEnabled(false);
                  break;
              }
            }
          }
        });

    final float density = context.getResources().getDisplayMetrics().density;
    mFlingDistance = (int) (MIN_DISTANCE_FOR_FLING * density);
  }
Example #9
0
  public Switch(Context context) {
    super(context);

    mThumbDrawable = context.getResources().getDrawable(R.drawable.switch_thumb);
    if (mThumbDrawable != null) {
      mThumbDrawable.setCallback(this);
    }
    mTrackDrawable = context.getResources().getDrawable(R.drawable.switch_track);
    if (mTrackDrawable != null) {
      mTrackDrawable.setCallback(this);
    }

    if (AndroidUtilities.density < 1) {
      mSwitchMinWidth = AndroidUtilities.dp(30);
    } else {
      mSwitchMinWidth = 0;
    }

    mSwitchPadding = 0;
    mSplitTrack = false;

    final ViewConfiguration config = ViewConfiguration.get(context);
    mTouchSlop = config.getScaledTouchSlop();
    mMinFlingVelocity = config.getScaledMinimumFlingVelocity();

    refreshDrawableState();
    setChecked(isChecked());
  }
  public void longPress(Coordinates where) {
    long downTime = SystemClock.uptimeMillis();
    long eventTime = SystemClock.uptimeMillis();
    Point point = where.getLocationOnScreen();
    // List<MotionEvent> motionEvents = new ArrayList<MotionEvent>();
    //
    // motionEvents.add(getMotionEvent(downTime, downTime, MotionEvent.ACTION_DOWN, point));
    // motionEvents.add(getMotionEvent(downTime, (downTime + 3000), MotionEvent.ACTION_UP, point));
    // sendMotionEvents(motionEvents);
    Instrumentation inst = instrumentation;

    MotionEvent event = null;
    boolean successfull = false;
    int retry = 0;
    while (!successfull && retry < 10) {
      try {
        if (event == null) {
          event =
              MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_DOWN, point.x, point.y, 0);
        }
        System.out.println("trying to send pointer");
        inst.sendPointerSync(event);
        successfull = true;
      } catch (SecurityException e) {
        System.out.println("failed: " + retry);
        // activityUtils.hideSoftKeyboard(null, false, true);
        retry++;
      }
    }
    if (!successfull) {
      throw new SelendroidException("Click can not be completed!");
    }
    inst.sendPointerSync(event);
    inst.waitForIdleSync();

    eventTime = SystemClock.uptimeMillis();
    final int touchSlop = ViewConfiguration.get(inst.getTargetContext()).getScaledTouchSlop();
    event =
        MotionEvent.obtain(
            downTime,
            eventTime,
            MotionEvent.ACTION_MOVE,
            point.x + touchSlop / 2,
            point.y + touchSlop / 2,
            0);
    inst.sendPointerSync(event);
    inst.waitForIdleSync();

    try {
      Thread.sleep((long) (ViewConfiguration.getLongPressTimeout() * 1.5f));
    } catch (InterruptedException e) {
      e.printStackTrace();
    }

    eventTime = SystemClock.uptimeMillis();
    event = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_UP, point.x, point.y, 0);
    inst.sendPointerSync(event);
    inst.waitForIdleSync();
  }
 public void init(Context context, int orientation, int spinePosition) {
   setAnimationBitmapFormat(Bitmap.Config.RGB_565);
   ViewConfiguration configuration = ViewConfiguration.get(getContext());
   touchSlop = configuration.getScaledTouchSlop();
   this.flipOrientation = orientation;
   this.spinePosition = spinePosition;
   setupSurfaceView(context);
 }
 public void init(Context context) {
   setOnItemLongClickListener(mOnItemLongClickListener);
   setOnScrollListener(mScrollListener);
   DisplayMetrics metrics = context.getResources().getDisplayMetrics();
   mSmoothScrollAmountAtEdge = (int) (SMOOTH_SCROLL_AMOUNT_AT_EDGE / metrics.density);
   ViewConfiguration vc = ViewConfiguration.get(getContext());
   mSlop = vc.getScaledTouchSlop();
 }
Example #13
0
 public ResizeManager(@NonNull CollapseCalendarView calendarView) {
   mCalendarView = calendarView;
   mScroller = new Scroller(calendarView.getContext());
   ViewConfiguration viewConfig = ViewConfiguration.get(mCalendarView.getContext());
   mTouchSlop = viewConfig.getScaledTouchSlop();
   mMinFlingVelocity = viewConfig.getScaledMinimumFlingVelocity();
   mMaxFlingVelocity = viewConfig.getScaledMaximumFlingVelocity();
 }
 @TargetApi(Build.VERSION_CODES.LOLLIPOP)
 public AbstractMultiShrinkScroller(
     Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
   // super(context, attrs, defStyleAttr, defStyleRes);
   super(context, attrs, defStyleAttr);
   final ViewConfiguration configuration = ViewConfiguration.get(context);
   mTouchSlop = configuration.getScaledTouchSlop();
 }
  /** Initializes various states for this workspace. */
  private void init(Context context) {
    mScroller = new Scroller(getContext(), new DecelerateInterpolator());
    mCurrentPage = 0;

    final ViewConfiguration configuration = ViewConfiguration.get(getContext());
    mTouchSlop = configuration.getScaledTouchSlop();
    mMaximumVelocity = configuration.getScaledMaximumFlingVelocity();
  }
  private void init(Context context) {
    setOrientation(VERTICAL);

    mOverScroller = new OverScroller(context);
    final ViewConfiguration configuration = ViewConfiguration.get(context);
    mTouchSlop = configuration.getScaledTouchSlop();
    mMaximumVelocity = configuration.getScaledMaximumFlingVelocity();
    mMinimumVelocity = configuration.getScaledMinimumFlingVelocity();
  }
Example #17
0
 public SwipeBackUtil(Activity activity) {
   mActivity = activity;
   mTouchSlop = ViewConfiguration.get(mActivity).getScaledTouchSlop();
   mScaledEdgeSlop = ViewConfiguration.get(mActivity).getScaledEdgeSlop();
   mScreenWidth = mActivity.getWindowManager().getDefaultDisplay().getWidth();
   mDecorView = mActivity.getWindow().getDecorView();
   mIsTrackingSwipeBackGesture = false;
   mLastX = 0.0f;
 }
    public MultiGestureDetector(Context context) {
      scaleGestureDetector = new ScaleGestureDetector(context, this);

      gestureDetector = new GestureDetector(context, this);
      gestureDetector.setOnDoubleTapListener(this);

      final ViewConfiguration configuration = ViewConfiguration.get(context);
      scaledMinimumFlingVelocity = configuration.getScaledMinimumFlingVelocity();
      scaledTouchSlop = configuration.getScaledTouchSlop();
    }
Example #19
0
 private void initTwoDScrollView() {
   mScroller = new Scroller(getContext());
   setFocusable(true);
   setDescendantFocusability(FOCUS_AFTER_DESCENDANTS);
   setWillNotDraw(false);
   final ViewConfiguration configuration = ViewConfiguration.get(getContext());
   mTouchSlop = configuration.getScaledTouchSlop();
   mMinimumVelocity = configuration.getScaledMinimumFlingVelocity();
   mMaximumVelocity = configuration.getScaledMaximumFlingVelocity();
 }
 /**
  * Constructs a new swipe-to-dismiss touch listener for the given list view.
  *
  * @param listView The list view whose items should be dismissable.
  * @param callback The callback to trigger when the user has indicated that she would like to
  *     dismiss one or more list items.
  */
 public SwipeDismissListViewTouchListener(ListView listView, OnDismissCallback callback) {
   ViewConfiguration vc = ViewConfiguration.get(listView.getContext());
   mSlop = vc.getScaledTouchSlop();
   mMinFlingVelocity = vc.getScaledMinimumFlingVelocity();
   mMaxFlingVelocity = vc.getScaledMaximumFlingVelocity();
   mAnimationTime =
       listView.getContext().getResources().getInteger(android.R.integer.config_shortAnimTime);
   mListView = listView;
   mCallback = callback;
 }
 /**
  * Constructs a new swipe-to-dismiss OnItemTouchListener for RecyclerView
  *
  * @param recyclerView RecyclerView
  * @param callbacks The callback to trigger when the user has indicated that she would like to
  *     dismiss this view.
  */
 public SwipeToDismissTouchListener(RecyclerView recyclerView, DismissCallbacks callbacks) {
   ViewConfiguration vc = ViewConfiguration.get(recyclerView.getContext());
   mSlop = vc.getScaledTouchSlop();
   mMinFlingVelocity = vc.getScaledMinimumFlingVelocity() * 4;
   mMaxFlingVelocity = vc.getScaledMaximumFlingVelocity();
   mAnimationTime =
       recyclerView.getContext().getResources().getInteger(android.R.integer.config_shortAnimTime);
   mRecyclerView = recyclerView;
   mCallbacks = callbacks;
 }
Example #22
0
  /**
   * initialize method, called inside the Chart.init() method. backwards compatibility - to not
   * break existing code
   *
   * @param res
   */
  @Deprecated
  public static void init(Resources res) {

    mMetrics = res.getDisplayMetrics();

    // noinspection deprecation
    mMinimumFlingVelocity = ViewConfiguration.getMinimumFlingVelocity();
    // noinspection deprecation
    mMaximumFlingVelocity = ViewConfiguration.getMaximumFlingVelocity();
  }
  public OnSwipeGestureTouchListener(Context context, boolean isLongPressEnabled) {
    super(context, isLongPressEnabled);

    ViewConfiguration configuration = ViewConfiguration.get(context);
    // We think a swipe flings a full page.
    // mMinSwipeDelta = configuration.getScaledTouchSlop();
    mMinSwipeDelta = configuration.getScaledPagingTouchSlop();
    mMinSwipeVelocity = configuration.getScaledMinimumFlingVelocity();
    mMaxSwipeVelocity = configuration.getScaledMaximumFlingVelocity();
  }
Example #24
0
 private void initScrollView() {
   this.mScroller = new ScrollerCompat(this.getContext(), (Interpolator) null);
   this.setFocusable(true);
   this.setDescendantFocusability(262144);
   this.setWillNotDraw(false);
   ViewConfiguration var1 = ViewConfiguration.get(this.getContext());
   this.mTouchSlop = var1.getScaledTouchSlop();
   this.mMinimumVelocity = var1.getScaledMinimumFlingVelocity();
   this.mMaximumVelocity = var1.getScaledMaximumFlingVelocity();
 }
 public ScrollLayout(Context context, AttributeSet attrs) {
   super(context, attrs);
   mScroller = new Scroller(getContext());
   setGravity(Gravity.CENTER_VERTICAL);
   final ViewConfiguration configuration = ViewConfiguration.get(getContext());
   mMinimumVelocity = configuration.getScaledMinimumFlingVelocity();
   // as mMaximumVelocity does not exist in API<4
   float density = getContext().getResources().getDisplayMetrics().density;
   mMaximumVelocity = (int) (4000 * 0.5f * density);
 }
Example #26
0
  private void init(Context context, AttributeSet attrs) {
    mPaint = new Paint();
    mPaint.setColor(Color.WHITE);
    Resources resources = context.getResources();

    // get attrConfiguration
    TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.SwitchButton);
    int width = (int) array.getDimensionPixelSize(R.styleable.SwitchButton_bmWidth, 0);
    int height = (int) array.getDimensionPixelSize(R.styleable.SwitchButton_bmHeight, 0);
    array.recycle();

    // size width or height
    if (width <= 0 || height <= 0) {
      width = COMMON_WIDTH_IN_PIXEL;
      height = COMMON_HEIGHT_IN_PIXEL;
    } else {
      float scale = (float) COMMON_WIDTH_IN_PIXEL / COMMON_HEIGHT_IN_PIXEL;
      if ((float) width / height > scale) {
        width = (int) (height * scale);
      } else if ((float) width / height < scale) {
        height = (int) (width / scale);
      }
    }

    // get viewConfiguration
    mClickTimeout = ViewConfiguration.getPressedStateDuration() + ViewConfiguration.getTapTimeout();
    mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();

    // get Bitmap
    bmBgGreen = BitmapFactory.decodeResource(resources, R.drawable.switch_btn_bg_green);
    bmBgWhite = BitmapFactory.decodeResource(resources, R.drawable.switch_btn_bg_white);
    bmBtnNormal = BitmapFactory.decodeResource(resources, R.drawable.switch_btn_normal);
    bmBtnPressed = BitmapFactory.decodeResource(resources, R.drawable.switch_btn_pressed);

    // size Bitmap
    bmBgGreen = Bitmap.createScaledBitmap(bmBgGreen, width, height, true);
    bmBgWhite = Bitmap.createScaledBitmap(bmBgWhite, width, height, true);
    bmBtnNormal = Bitmap.createScaledBitmap(bmBtnNormal, height, height, true);
    bmBtnPressed = Bitmap.createScaledBitmap(bmBtnPressed, height, height, true);

    bmCurBtnPic = bmBtnNormal; // 初始按钮图片
    bmCurBgPic = mChecked ? bmBgGreen : bmBgWhite; // 初始背景图片
    bgWidth = bmBgGreen.getWidth(); // 背景宽度
    bgHeight = bmBgGreen.getHeight(); // 背景高度
    btnWidth = bmBtnNormal.getWidth(); // 按钮宽度
    offBtnPos = 0; // 关闭时在最左边
    onBtnPos = bgWidth - btnWidth; // 开始时在右边
    curBtnPos = mChecked ? onBtnPos : offBtnPos; // 按钮当前为初始位置

    // get density
    float density = resources.getDisplayMetrics().density;
    mVelocity = (int) (VELOCITY * density + 0.5f); // 动画距离
    mSaveLayerRectF = new RectF(0, 0, bgWidth, bgHeight);
  }
Example #27
0
  public ItemSlideHelper(Context context, Callback callback) {
    this.mCallback = callback;

    // 手势用于处理fling
    mGestureDetector = new GestureDetectorCompat(context, this);

    ViewConfiguration configuration = ViewConfiguration.get(context);
    mTouchSlop = configuration.getScaledTouchSlop();
    mMaxVelocity = configuration.getScaledMaximumFlingVelocity();
    mMinVelocity = configuration.getScaledMinimumFlingVelocity();
  }
 /**
  * Constructs a new swipe-to-dismiss touch listener for the given view.
  *
  * @param view The view to make dismissable.
  * @param token An optional token/cookie object to be passed through to the callback.
  * @param callbacks The callback to trigger when the user has indicated that she would like to
  *     dismiss this view.
  */
 public SwipeDismissTouchListener(View view, Object token, DismissCallbacks callbacks) {
   ViewConfiguration vc = ViewConfiguration.get(view.getContext());
   mSlop = vc.getScaledTouchSlop();
   mMinFlingVelocity = vc.getScaledMinimumFlingVelocity() * 16;
   mMaxFlingVelocity = vc.getScaledMaximumFlingVelocity();
   mAnimationTime =
       view.getContext().getResources().getInteger(android.R.integer.config_shortAnimTime);
   mView = view;
   mToken = token;
   mCallbacks = callbacks;
 }
  private void init(Context context) {
    ViewConfiguration vc = ViewConfiguration.get(context);
    mSlop = vc.getScaledTouchSlop();
    mMinFlingVelocity = vc.getScaledMinimumFlingVelocity() * 8; // 获取滑动的最小速度
    mMaxFlingVelocity = vc.getScaledMaximumFlingVelocity(); // 获取滑动的最大速度

    // 获取分辨率
    DisplayMetrics dm = context.getApplicationContext().getResources().getDisplayMetrics();
    mWidth = dm.widthPixels;
    mFlaggingWidth = mWidth / 4;
  }
Example #30
0
 /**
  * Returns the display width, or if the device has software buttons, the 'right' of the view (in
  * order to take into account the software buttons.
  *
  * @return the width in pixels.
  */
 public int getWidth() {
   View v = getWindow().getDecorView().findViewById(android.R.id.content);
   Display d = getWindowManager().getDefaultDisplay();
   int right = v.getRight();
   int width = d.getWidth();
   if (android.os.Build.VERSION.SDK_INT >= 14) {
     android.view.ViewConfiguration vc = ViewConfiguration.get(this);
     if (vc.hasPermanentMenuKey()) return right;
   }
   return width;
 }