Exemplo n.º 1
0
  void initCustomViewAbove() {
    setWillNotDraw(false);
    setDescendantFocusability(FOCUS_AFTER_DESCENDANTS);
    setFocusable(true);
    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);
  }
  /**
   * 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();
  }
Exemplo n.º 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;
              }
            }
          }
        });
  }
Exemplo n.º 4
0
    public void configure(
        final DeploymentPhaseContext context,
        final ComponentConfiguration componentConfiguration,
        final ViewDescription description,
        final ViewConfiguration configuration)
        throws DeploymentUnitProcessingException {
      // Create method indexes
      final DeploymentReflectionIndex reflectionIndex =
          context.getDeploymentUnit().getAttachment(REFLECTION_INDEX);
      final List<Method> methods = configuration.getProxyFactory().getCachedMethods();
      for (final Method method : methods) {
        MethodIdentifier methodIdentifier = MethodIdentifier.getIdentifierForMethod(method);
        Method componentMethod =
            ClassReflectionIndexUtil.findMethod(
                reflectionIndex, componentConfiguration.getComponentClass(), methodIdentifier);

        if (componentMethod == null
            && method.getDeclaringClass().isInterface()
            && (method.getModifiers() & (ABSTRACT | PUBLIC | STATIC)) == PUBLIC) {
          // no component method and the interface method is defaulted, so we really do want to
          // invoke on the interface method
          componentMethod = method;
        }
        if (componentMethod != null) {

          if ((BRIDGE & componentMethod.getModifiers()) != 0) {
            Method other =
                findRealMethodForBridgeMethod(
                    componentMethod, componentConfiguration, reflectionIndex, methodIdentifier);
            // try and find the non-bridge method to delegate to
            if (other != null) {
              componentMethod = other;
            }
          }

          configuration.addViewInterceptor(
              method,
              new ImmediateInterceptorFactory(new ComponentDispatcherInterceptor(componentMethod)),
              InterceptorOrder.View.COMPONENT_DISPATCHER);
          configuration.addClientInterceptor(
              method,
              CLIENT_DISPATCHER_INTERCEPTOR_FACTORY,
              InterceptorOrder.Client.CLIENT_DISPATCHER);
        }
      }

      configuration.addClientPostConstructInterceptor(
          Interceptors.getTerminalInterceptorFactory(),
          InterceptorOrder.ClientPostConstruct.TERMINAL_INTERCEPTOR);
      configuration.addClientPreDestroyInterceptor(
          Interceptors.getTerminalInterceptorFactory(),
          InterceptorOrder.ClientPreDestroy.TERMINAL_INTERCEPTOR);
    }
Exemplo n.º 5
0
    public void configure(
        final DeploymentPhaseContext context,
        final ComponentConfiguration componentConfiguration,
        final ViewDescription description,
        final ViewConfiguration configuration)
        throws DeploymentUnitProcessingException {
      // Create method indexes
      final DeploymentReflectionIndex reflectionIndex =
          context.getDeploymentUnit().getAttachment(REFLECTION_INDEX);
      final List<Method> methods = configuration.getProxyFactory().getCachedMethods();
      for (final Method method : methods) {
        MethodIdentifier methodIdentifier = MethodIdentifier.getIdentifierForMethod(method);
        Method componentMethod =
            ClassReflectionIndexUtil.findMethod(
                reflectionIndex, componentConfiguration.getComponentClass(), methodIdentifier);

        if (componentMethod != null) {

          if ((BRIDGE & componentMethod.getModifiers()) != 0) {
            Collection<Method> otherMethods =
                ClassReflectionIndexUtil.findMethods(
                    reflectionIndex,
                    reflectionIndex.getClassIndex(componentConfiguration.getComponentClass()),
                    methodIdentifier.getName(),
                    methodIdentifier.getParameterTypes());
            // try and find the non-bridge method to delegate to
            for (final Method other : otherMethods) {
              if ((BRIDGE & other.getModifiers()) == 0) {
                componentMethod = other;
                break;
              }
            }
          }

          configuration.addViewInterceptor(
              method,
              new ImmediateInterceptorFactory(new ComponentDispatcherInterceptor(componentMethod)),
              InterceptorOrder.View.COMPONENT_DISPATCHER);
          configuration.addClientInterceptor(
              method,
              CLIENT_DISPATCHER_INTERCEPTOR_FACTORY,
              InterceptorOrder.Client.CLIENT_DISPATCHER);
        }
      }

      configuration.addClientPostConstructInterceptor(
          Interceptors.getTerminalInterceptorFactory(),
          InterceptorOrder.ClientPostConstruct.TERMINAL_INTERCEPTOR);
      configuration.addClientPreDestroyInterceptor(
          Interceptors.getTerminalInterceptorFactory(),
          InterceptorOrder.ClientPreDestroy.TERMINAL_INTERCEPTOR);
    }
 /**
  * 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;
 }
Exemplo n.º 7
0
 private void init(Context context) {
   screenWidth =
       ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE))
           .getDefaultDisplay()
           .getWidth();
   scroller = new Scroller(context);
   mTouchSlop = ViewConfiguration.get(getContext()).getScaledTouchSlop();
 }
Exemplo n.º 8
0
 private void postLongClickRunnable() {
   myLongClickPerformed = false;
   myPendingPress = false;
   if (myPendingLongClickRunnable == null) {
     myPendingLongClickRunnable = new LongClickRunnable();
   }
   postDelayed(myPendingLongClickRunnable, 2 * ViewConfiguration.getLongPressTimeout());
 }
Exemplo n.º 9
0
  public PtrFrameLayout(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    mPtrIndicator = new PtrIndicator();

    TypedArray arr = context.obtainStyledAttributes(attrs, R.styleable.PtrFrameLayout, 0, 0);
    if (arr != null) {

      mHeaderId = arr.getResourceId(R.styleable.PtrFrameLayout_ptr_header, mHeaderId);
      mContainerId = arr.getResourceId(R.styleable.PtrFrameLayout_ptr_content, mContainerId);

      mPtrIndicator.setResistance(
          arr.getFloat(R.styleable.PtrFrameLayout_ptr_resistance, mPtrIndicator.getResistance()));

      mDurationToClose =
          arr.getInt(R.styleable.PtrFrameLayout_ptr_duration_to_close, mDurationToClose);
      mDurationToCloseHeader =
          arr.getInt(
              R.styleable.PtrFrameLayout_ptr_duration_to_close_header, mDurationToCloseHeader);

      float ratio = mPtrIndicator.getRatioOfHeaderToHeightRefresh();
      ratio = arr.getFloat(R.styleable.PtrFrameLayout_ptr_ratio_of_header_height_to_refresh, ratio);
      mPtrIndicator.setRatioOfHeaderHeightToRefresh(ratio);

      mKeepHeaderWhenRefresh =
          arr.getBoolean(
              R.styleable.PtrFrameLayout_ptr_keep_header_when_refresh, mKeepHeaderWhenRefresh);

      mPullToRefresh = arr.getBoolean(R.styleable.PtrFrameLayout_ptr_pull_to_fresh, mPullToRefresh);
      arr.recycle();
    }

    mScrollChecker = new ScrollChecker();

    final ViewConfiguration conf = ViewConfiguration.get(getContext());
    mPagingTouchSlop = conf.getScaledTouchSlop() * 2;
  }
Exemplo n.º 10
0
 @Override
 public boolean onKeyUp(int keyCode, KeyEvent event) {
   if (myKeyUnderTracking != -1) {
     if (myKeyUnderTracking == keyCode) {
       final boolean longPress =
           System.currentTimeMillis()
               > myTrackingStartTime + ViewConfiguration.getLongPressTimeout();
       ZLApplication.Instance().runActionByKey(keyCode, longPress);
     }
     myKeyUnderTracking = -1;
     return true;
   } else {
     final ZLKeyBindings bindings = ZLApplication.Instance().keyBindings();
     return bindings.hasBinding(keyCode, false) || bindings.hasBinding(keyCode, true);
   }
 }
Exemplo n.º 11
0
 private void sendCancelEvent() {
   if (DEBUG) {
     PtrCLog.d(LOG_TAG, "send cancel event");
   }
   MotionEvent last = mDownEvent;
   last = mLastMoveEvent;
   MotionEvent e =
       MotionEvent.obtain(
           last.getDownTime(),
           last.getEventTime() + ViewConfiguration.getLongPressTimeout(),
           MotionEvent.ACTION_CANCEL,
           last.getX(),
           last.getY(),
           last.getMetaState());
   dispatchTouchEventSupper(e);
 }
Exemplo n.º 12
0
 ViewService(final ViewConfiguration viewConfiguration) {
   viewClass = viewConfiguration.getViewClass();
   final ProxyFactory<?> proxyFactory = viewConfiguration.getProxyFactory();
   this.proxyFactory = proxyFactory;
   final Method[] methods = proxyFactory.getCachedMethods();
   final int methodCount = methods.length;
   viewPostConstruct =
       Interceptors.getChainedInterceptorFactory(
           viewConfiguration.getViewPostConstructInterceptors());
   viewPreDestroy =
       Interceptors.getChainedInterceptorFactory(
           viewConfiguration.getViewPreDestroyInterceptors());
   clientPostConstruct =
       Interceptors.getChainedInterceptorFactory(
           viewConfiguration.getClientPostConstructInterceptors());
   clientPreDestroy =
       Interceptors.getChainedInterceptorFactory(
           viewConfiguration.getClientPreDestroyInterceptors());
   final IdentityHashMap<Method, InterceptorFactory> viewInterceptorFactories =
       new IdentityHashMap<Method, InterceptorFactory>(methodCount);
   final IdentityHashMap<Method, InterceptorFactory> clientInterceptorFactories =
       new IdentityHashMap<Method, InterceptorFactory>(methodCount);
   for (Method method : methods) {
     if (method.getName().equals("finalize") && method.getParameterTypes().length == 0) {
       viewInterceptorFactories.put(method, DESTROY_INTERCEPTOR);
     } else {
       viewInterceptorFactories.put(
           method,
           Interceptors.getChainedInterceptorFactory(
               viewConfiguration.getViewInterceptorDeque(method)));
       clientInterceptorFactories.put(
           method,
           Interceptors.getChainedInterceptorFactory(
               viewConfiguration.getClientInterceptorDeque(method)));
     }
   }
   this.viewInterceptorFactories = viewInterceptorFactories;
   this.clientInterceptorFactories = clientInterceptorFactories;
   allowedMethods = Collections.unmodifiableSet(viewInterceptorFactories.keySet());
 }
Exemplo n.º 13
0
    @Override
    public void configure(
        final DeploymentPhaseContext context,
        final ComponentConfiguration componentConfiguration,
        final ViewDescription description,
        final ViewConfiguration configuration)
        throws DeploymentUnitProcessingException {

      // Create view bindings
      final List<BindingConfiguration> bindingConfigurations =
          configuration.getBindingConfigurations();
      for (String bindingName : description.getBindingNames()) {
        bindingConfigurations.add(
            new BindingConfiguration(
                bindingName,
                description.createInjectionSource(
                    description.getServiceName(),
                    Values.immediateValue(componentConfiguration.getModuleClassLoader()))));
      }
    }
Exemplo n.º 14
0
 private void sendCancelEvent() {
   if (DEBUG) {
     PtrCLog.d(LOG_TAG, "send cancel event");
   }
   // The ScrollChecker will update position and lead to send cancel event when mLastMoveEvent is
   // null.
   // fix #104, #80, #92
   if (mLastMoveEvent == null) {
     return;
   }
   MotionEvent last = mLastMoveEvent;
   MotionEvent e =
       MotionEvent.obtain(
           last.getDownTime(),
           last.getEventTime() + ViewConfiguration.getLongPressTimeout(),
           MotionEvent.ACTION_CANCEL,
           last.getX(),
           last.getY(),
           last.getMetaState());
   dispatchTouchEventSupper(e);
 }
Exemplo n.º 15
0
  // 惯性线程
  class FlingThread extends Thread {
    // 初始速度
    private int velocity;
    private static final float INFLEXION = 0.35f;
    // 取得系统摩擦系数
    private float mFlingFriction = ViewConfiguration.getScrollFriction();
    private float mPhysicalCoeff;
    private final float DECELERATION_RATE = (float) (Math.log(0.78) / Math.log(0.9));
    // 计算出惯性总时间
    private double mDuration;
    // 刷新频率
    private int timeInterval = 1000 / 60; // 单位MS
    // 当前惯性耗时
    private int spendTime;

    public FlingThread(float velocityX) {
      velocity = (int) velocityX;
      final float ppi = context.getResources().getDisplayMetrics().density * 160.0f;
      mPhysicalCoeff =
          SensorManager.GRAVITY_EARTH // g (m/s^2)
              * 39.37f // inch/meter
              * ppi
              * 0.84f; // look and feel tuning
    }

    @Override
    public void run() {
      isInertia = true;
      boolean isEnable = false;
      if (velocity != 0) {
        mDuration = getSplineFlingDuration(velocity);
        // 不断循环直到惯性时间到达或者用户点击屏幕中断滑动
        while (mDuration >= spendTime && isInertia) {
          // 每时间间隔内惯性滑动的距离
          int space =
              (int)
                      (velocity
                          + (2 * spendTime / timeInterval + 1)
                              * -velocity
                              / mDuration
                              * timeInterval
                              / 2)
                  * timeInterval
                  / 1000;
          try {
            if (axesData.size() > 1) {
              int max = axesData.get(axesData.size() - 1).X;
              int min = axesData.get(0).X;
              int maxLimit = width - rightPadding - 20;
              int minLimit = leftPadding + yTextWidth + 20;
              if (min + space > minLimit) { // 滑动以后左边界判断
                if (min < minLimit) {
                  isEnable = true;
                } else {
                  space = 0;
                  refreshChart(space);
                  return;
                }
              } else {
                isEnable = true;
              }
              if (max + space < maxLimit) { // 滑动后右边界判断
                if (max > maxLimit) {
                  isEnable = true;
                } else {
                  space = 0;
                  refreshChart(space);
                  return;
                }
              } else {
                isEnable = true;
              }
              if (isEnable) {
                refreshChart(space);
              }
            } else {
              return;
            }
            spendTime += timeInterval;
            sleep(timeInterval);
            isScrollEnd = true;
          } catch (InterruptedException e) {
            e.printStackTrace();
          }
        }
      }
    }

    // 根据速度计算加速度
    private double getSplineDeceleration(int velocity) {
      return Math.log(INFLEXION * Math.abs(velocity) / (mFlingFriction * 2 * mPhysicalCoeff));
    }

    /* Returns the duration, expressed in milliseconds */
    private int getSplineFlingDuration(int velocity) {
      final double l = getSplineDeceleration(velocity);
      final double decelMinusOne = DECELERATION_RATE - 1.0;
      return (int) (1000.0 * Math.exp(l / decelMinusOne));
    }
  }
Exemplo n.º 16
0
  @Override
  public boolean onTouchEvent(MotionEvent event) {
    int x = (int) event.getX();
    int y = (int) event.getY();

    final ZLView view = ZLApplication.Instance().getCurrentView();
    switch (event.getAction()) {
      case MotionEvent.ACTION_UP:
        if (myPendingDoubleTap) {
          view.onFingerDoubleTap(x, y);
        } else if (myLongClickPerformed) {
          view.onFingerReleaseAfterLongPress(x, y);
        } else {
          if (myPendingLongClickRunnable != null) {
            removeCallbacks(myPendingLongClickRunnable);
            myPendingLongClickRunnable = null;
          }
          if (myPendingPress) {
            if (view.isDoubleTapSupported()) {
              if (myPendingShortClickRunnable == null) {
                myPendingShortClickRunnable = new ShortClickRunnable();
              }
              postDelayed(myPendingShortClickRunnable, ViewConfiguration.getDoubleTapTimeout());
            } else {
              view.onFingerSingleTap(x, y);
            }
          } else {
            view.onFingerRelease(x, y);
          }
        }
        myPendingDoubleTap = false;
        myPendingPress = false;
        myScreenIsTouched = false;
        break;
      case MotionEvent.ACTION_DOWN:
        if (myPendingShortClickRunnable != null) {
          removeCallbacks(myPendingShortClickRunnable);
          myPendingShortClickRunnable = null;
          myPendingDoubleTap = true;
        } else {
          postLongClickRunnable();
          myPendingPress = true;
        }
        myScreenIsTouched = true;
        myPressedX = x;
        myPressedY = y;
        break;
      case MotionEvent.ACTION_MOVE:
        {
          final int slop = ViewConfiguration.get(getContext()).getScaledTouchSlop();
          final boolean isAMove =
              Math.abs(myPressedX - x) > slop || Math.abs(myPressedY - y) > slop;
          if (isAMove) {
            myPendingDoubleTap = false;
          }
          if (myLongClickPerformed) {
            view.onFingerMoveAfterLongPress(x, y);
          } else {
            if (myPendingPress) {
              if (isAMove) {
                if (myPendingShortClickRunnable != null) {
                  removeCallbacks(myPendingShortClickRunnable);
                  myPendingShortClickRunnable = null;
                }
                if (myPendingLongClickRunnable != null) {
                  removeCallbacks(myPendingLongClickRunnable);
                }
                view.onFingerPress(myPressedX, myPressedY);
                myPendingPress = false;
              }
            }
            if (!myPendingPress) {
              view.onFingerMove(x, y);
            }
          }
          break;
        }
    }

    return true;
  }
Exemplo n.º 17
0
    @Override
    public boolean onTouch(View v, MotionEvent event) {
      // detector.onTouchEvent(event);
      switch (event.getAction()) {
        case MotionEvent.ACTION_DOWN:
          startX = event.getX();
          downX = event.getX();
          break;
        case MotionEvent.ACTION_UP:
          v.performClick();
          break;
        case MotionEvent.ACTION_MOVE:
          // 是否已滚动到无法继续滑动
          boolean isEnable = false;
          // 手指move的像素值超过系统判定判定滚动的最小临界值,避免手指抖动造成chart图抖动
          if (Math.abs(event.getX() - downX)
              > ViewConfiguration.get(context).getScaledTouchSlop()) {
            int transValue = (int) (event.getX() - startX);
            if (axesData.size() > 1) {
              int max = axesData.get(axesData.size() - 1).X;
              int min = axesData.get(0).X;
              int maxLimit = width - rightPadding - POINT_PADDING;
              int minLimit = leftPadding + yTextWidth + POINT_PADDING;
              if (min + transValue > minLimit) { // 滑动以后左边界判断
                if (min < minLimit) {
                  transValue = minLimit - min;
                  isEnable = true;
                } else {
                  transValue = 0;
                  if (loadMore != null) {
                    loadMore.onLoad();
                  }
                }
              } else {
                isEnable = true;
              }
              if (max + transValue < maxLimit) { // 滑动后右边界判断
                if (max > maxLimit) {
                  transValue = maxLimit - max;
                  isEnable = true;
                } else {
                  transValue = 0;
                }
              } else {
                isEnable = true;
              }
              Log.d("min", min + "");
              Log.d("minLimit", minLimit + "");
              Log.d("transValue", transValue + "");
              if (isEnable) {
                startX = event.getX();
                refreshChart(transValue);
              }
            }
          }
          break;

        default:
          break;
      }
      return true;
    }
  public boolean hasNavigationBar(Context context) {
    boolean hasMenuKey = ViewConfiguration.get(context).hasPermanentMenuKey();
    boolean hasBackKey = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_BACK);

    return (!hasMenuKey && !hasBackKey);
  }