/**
   * 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) {}
        });
  }
Ejemplo n.º 2
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;
              }
            }
          }
        });
  }
Ejemplo n.º 3
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());
  }
  /**
   * 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();
  }
Ejemplo n.º 5
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();
 }
Ejemplo n.º 6
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);
  }
Ejemplo n.º 7
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();
 }
  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();
  }
  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();
  }
 /**
  * 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;
 }
Ejemplo n.º 12
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();
 }
Ejemplo n.º 13
0
    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();
    }
Ejemplo n.º 14
0
 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);
 }
Ejemplo n.º 15
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();
 }
Ejemplo n.º 16
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;
 }
  public PlaylistContainerWrapper(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    mDetector = new GestureDetectorCompat(context, this);
    mNestedScrollingChildHelper = new NestedScrollingChildHelper(this);
    setNestedScrollingEnabled(true);

    final ViewConfiguration vc = ViewConfiguration.get(context);
    mTouchSlop = vc.getScaledTouchSlop();
    mMinFlingVelocity = vc.getScaledMinimumFlingVelocity();
    mMaxFlingVelocity = vc.getScaledMaximumFlingVelocity();
  }
  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;
  }
 /**
  * Constructs a new swipe-to-dismiss touch listener for the given list view.
  *
  * @param listView The list view whose items should be dismissable.
  * @param callbacks The callback to trigger when the user has indicated that she would like to
  *     dismiss one or more list items.
  */
 public SwipeDismissListViewTouchListener(ListView listView, DismissCallbacks callbacks) {
   ViewConfiguration vc = ViewConfiguration.get(listView.getContext());
   mSlop = vc.getScaledTouchSlop();
   mMinFlingVelocity = vc.getScaledMinimumFlingVelocity() * 16;
   mMaxFlingVelocity = vc.getScaledMaximumFlingVelocity();
   mAnimationTime =
       listView.getContext().getResources().getInteger(android.R.integer.config_shortAnimTime);
   mListView = listView;
   mCallbacks = callbacks;
   swipeDistanceDivisor =
       listView.getContext().getResources().getInteger(R.integer.list_card_swipe_distance_divisor);
 }
Ejemplo n.º 21
0
 @SuppressLint("NewApi")
 public ExcelView(Context context) {
   super(context);
   scroller = new Scroller(context);
   final ViewConfiguration configuration = ViewConfiguration.get(getContext());
   minimumVelocity = configuration.getScaledMinimumFlingVelocity();
   maximumVelocity = configuration.getScaledMaximumFlingVelocity();
   touchSlop = configuration.getScaledTouchSlop();
   if (Integer.valueOf(Build.VERSION.SDK) >= 11)
     this.setLayerType(View.LAYER_TYPE_SOFTWARE, painter);
   dp = context.getResources().getDisplayMetrics().density;
 }
 @SuppressLint("NewApi")
 private void initScrollView() {
   mScroller = new OverScroller(getContext());
   setFocusable(true);
   setDescendantFocusability(FOCUS_AFTER_DESCENDANTS);
   setWillNotDraw(false);
   final ViewConfiguration configuration = ViewConfiguration.get(getContext());
   mTouchSlop = configuration.getScaledTouchSlop();
   mMinimumVelocity = configuration.getScaledMinimumFlingVelocity();
   mMaximumVelocity = configuration.getScaledMaximumFlingVelocity();
   mOverscrollDistance = configuration.getScaledOverscrollDistance();
   mOverflingDistance = configuration.getScaledOverflingDistance();
 }
  /** Inits the scroll view. */
  private void initScrollView() {

    mScroller = new OverScroller(getContext(), new DecelerateInterpolator());
    setFocusable(true);
    setDescendantFocusability(FOCUS_AFTER_DESCENDANTS);
    setWillNotDraw(false);
    final ViewConfiguration configuration = ViewConfiguration.get(getContext());
    mTouchSlop = configuration.getScaledTouchSlop();
    mMinimumVelocity = configuration.getScaledMinimumFlingVelocity();
    mMaximumVelocity = configuration.getScaledMaximumFlingVelocity();
    mOverscrollDistance = configuration.getScaledOverscrollDistance();
    mOverflingDistance = configuration.getScaledOverflingDistance();
    mScrollMarginTop = getResources().getDimensionPixelSize(R.dimen.gn_recent_info_zone_height);
  }
Ejemplo n.º 24
0
  private void init() {
    final Context context = getContext();
    mScroller = new Scroller(context, flipInterpolator);
    final ViewConfiguration configuration = ViewConfiguration.get(context);
    mTouchSlop = configuration.getScaledPagingTouchSlop();
    mMinimumVelocity = configuration.getScaledMinimumFlingVelocity();
    mMaximumVelocity = configuration.getScaledMaximumFlingVelocity();

    mShadowPaint.setColor(Color.BLACK);
    mShadowPaint.setStyle(Style.FILL);
    mShadePaint.setColor(Color.BLACK);
    mShadePaint.setStyle(Style.FILL);
    mShinePaint.setColor(Color.WHITE);
    mShinePaint.setStyle(Style.FILL);
  }
  /**
   * 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.datagrid_shadow_left);
    this.shadows[1] = new ImageView(context);
    this.shadows[1].setImageResource(R.drawable.datagrid_shadow_top);
    this.shadows[2] = new ImageView(context);
    this.shadows[2].setImageResource(R.drawable.datagrid_shadow_right);
    this.shadows[3] = new ImageView(context);
    this.shadows[3].setImageResource(R.drawable.datagrid_shadow_bottom);

    this.shadowSize = getResources().getDimensionPixelSize(R.dimen.datagrid_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();

    this.setWillNotDraw(false);

    final TypedArray a = context.obtainStyledAttributes(R.styleable.View);
    try {
      // TODO fix initializeScrollbars
      // initializeScrollbars(a);
    } finally {
      if (a != null) {
        a.recycle();
      }
    }

    this.setHorizontalScrollBarEnabled(true);
    this.setVerticalScrollBarEnabled(true);

    this.rowSelectable = true;
    if (context instanceof OnDataGridRowSelectedListener) {
      mRowSelectedListener = (OnDataGridRowSelectedListener) context;
    }
  }
  // TODO 需要研究
  private void init() {
    setWillNotDraw(false);
    setDescendantFocusability(FOCUS_AFTER_DESCENDANTS);
    setFocusable(true);
    final Context context = getContext();
    mScroller = new Scroller(context, sMenuInterpolator);
    final ViewConfiguration configuration = ViewConfiguration.get(context);
    mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration);
    mMinimumVelocity = configuration.getScaledMinimumFlingVelocity();
    mMaximumVelocity = configuration.getScaledMaximumFlingVelocity();

    final float density = context.getResources().getDisplayMetrics().density;
    mFlingDistance = (int) (MIN_DISTANCE_FOR_FLING * density);

    mRandom = new Random();
  }
Ejemplo n.º 27
0
  @Test
  public void methodsShouldReturnScaledAndroidConstantsDependingOnPixelDensity() {
    Activity context = new Activity();
    shadowOf(context.getResources()).setDensity(1.5f);
    ViewConfiguration viewConfiguration = ViewConfiguration.get(context);

    assertEquals(15, viewConfiguration.getScaledScrollBarSize());
    assertEquals(18, viewConfiguration.getScaledFadingEdgeLength());
    assertEquals(18, viewConfiguration.getScaledEdgeSlop());
    assertEquals(24, viewConfiguration.getScaledTouchSlop());
    assertEquals(48, viewConfiguration.getScaledPagingTouchSlop());
    assertEquals(150, viewConfiguration.getScaledDoubleTapSlop());
    assertEquals(24, viewConfiguration.getScaledWindowTouchSlop());
    assertEquals(75, viewConfiguration.getScaledMinimumFlingVelocity());
    assertEquals(6000, viewConfiguration.getScaledMaximumFlingVelocity());
  }
 /**
  * Constructor
  *
  * @param swipeListView SwipeListView
  * @param swipeFrontView front view Identifier
  * @param swipeBackView back view Identifier
  */
 public SwipeListViewTouchListener(
     SwipeListView swipeListView, int swipeFrontView, int swipeBackView) {
   this.swipeFrontView = swipeFrontView;
   this.swipeBackView = swipeBackView;
   ViewConfiguration vc = ViewConfiguration.get(swipeListView.getContext());
   slop = vc.getScaledTouchSlop();
   minFlingVelocity = vc.getScaledMinimumFlingVelocity();
   maxFlingVelocity = vc.getScaledMaximumFlingVelocity();
   configShortAnimationTime =
       swipeListView
           .getContext()
           .getResources()
           .getInteger(android.R.integer.config_shortAnimTime);
   animationTime = configShortAnimationTime;
   this.swipeListView = swipeListView;
 }
Ejemplo n.º 29
0
  /**
   * Construct a new Switch with a default style determined by the given theme attribute, overriding
   * specific style attributes as requested.
   *
   * @param context The Context that will determine this widget's theming.
   * @param attrs Specification of attributes that should deviate from the default styling.
   * @param defStyle An attribute ID within the active theme containing a reference to the default
   *     style for this widget. e.g. android.R.attr.switchStyle.
   */
  public Switch(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    mTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
    Resources res = getResources();
    mTextPaint.density = res.getDisplayMetrics().density;

    // TODO resolve error
    // mTextPaint.setCompatibilityScaling(res.getCompatibilityInfo().applicationScale);

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.Switch, defStyle, 0);

    mThumbDrawable = a.getDrawable(R.styleable.Switch_thumb);
    mTrackDrawable = a.getDrawable(R.styleable.Switch_track);
    mTextOn = a.getText(R.styleable.Switch_textOn);
    mTextOff = a.getText(R.styleable.Switch_textOff);
    mThumbTextPadding = a.getDimensionPixelSize(R.styleable.Switch_thumbTextPadding, 0);
    mSwitchMinWidth = a.getDimensionPixelSize(R.styleable.Switch_switchMinWidth, 0);
    mSwitchPadding = a.getDimensionPixelSize(R.styleable.Switch_switchPadding, 0);

    int appearance = a.getResourceId(R.styleable.Switch_switchTextAppearance, 0);
    if (appearance != 0) {
      setSwitchTextAppearance(context, appearance);
    }
    a.recycle();

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

    // Refresh display with current params
    refreshDrawableState();
    setChecked(isChecked());

    // TODO I don't know why, but in order for the OnCheckedChangeListener to work this switch has
    // to have an OnClickListener
    this.setOnClickListener(
        new OnClickListener() {

          @Override
          public void onClick(View v) {
            // do nothing
          }
        });
  }
    private void init(Context context) {
      if (context == null) {
        throw new IllegalArgumentException("Context must not be null");
      }
      if (mListener == null) {
        throw new IllegalArgumentException("OnGestureListener must not be null");
      }
      mIsLongpressEnabled = true;

      final ViewConfiguration configuration = ViewConfiguration.get(context);
      final int touchSlop = configuration.getScaledTouchSlop();
      final int doubleTapSlop = configuration.getScaledDoubleTapSlop();
      mMinimumFlingVelocity = configuration.getScaledMinimumFlingVelocity();
      mMaximumFlingVelocity = configuration.getScaledMaximumFlingVelocity();

      mTouchSlopSquare = touchSlop * touchSlop;
      mDoubleTapSlopSquare = doubleTapSlop * doubleTapSlop;
    }