@Override
  public boolean onTouchEvent(MotionEvent ev) {
    if ((mDragListener != null || mDropListener != null) && mDragView != null) {
      int action = ev.getAction();
      switch (action) {
        case MotionEvent.ACTION_UP:
        case MotionEvent.ACTION_CANCEL:
          Rect r = mTempRect;
          mDragView.getDrawingRect(r);
          stopDragging();
          if (mDropListener != null && mDragPos >= 0 && mDragPos < getCount()) {
            mDropListener.drop(mFirstDragPos, mDragPos);
          }
          unExpandViews(false);
          break;

        case MotionEvent.ACTION_DOWN:
        case MotionEvent.ACTION_MOVE:
          int x = (int) ev.getX();
          int y = (int) ev.getY();
          dragView(x, y);
          int itemnum = getItemForPosition(y);
          if (itemnum >= 0) {
            if (action == MotionEvent.ACTION_DOWN || itemnum != mDragPos) {
              if (mDragListener != null) {
                mDragListener.drag(mDragPos, itemnum);
              }
              mDragPos = itemnum;
              doExpansion();
            }
            int speed = 0;
            adjustScrollBounds(y);
            if (y > mLowerBound) {
              // scroll the list up a bit
              speed = y > (mHeight + mLowerBound) / 2 ? 16 : 4;
            } else if (y < mUpperBound) {
              // scroll the list down a bit
              speed = y < mUpperBound / 2 ? -16 : -4;
            }
            if (speed != 0) {
              int ref = pointToPosition(0, mHeight / 2);
              if (ref == AdapterView.INVALID_POSITION) {
                // we hit a divider or an invisible view, check
                // somewhere else
                ref = pointToPosition(0, mHeight / 2 + getDividerHeight() + 64);
              }
              View v = getChildAt(ref - getFirstVisiblePosition());
              if (v != null) {
                int pos = v.getTop();
                setSelectionFromTop(ref, pos - speed);
              }
            }
          }
          break;
      }
      return true;
    }
    return super.onTouchEvent(ev);
  }
コード例 #2
0
ファイル: EditProduct.java プロジェクト: chenmi21/Jerboaa
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_edit_product);
    // initialize Product
    myProduct = new ProductTshirt(SHIRT, "T恤衫");
    garbage = (ImageView) findViewById(R.id.garbagebin);
    recycle = (ImageView) findViewById(R.id.recycle);
    shirtview = (ImageView) findViewById(R.id.tshirt);
    garbage.setVisibility(View.INVISIBLE);
    mRrootLayout = (ViewGroup) findViewById(R.id.imgLayout);
    addBtn = (Button) findViewById(R.id.addbutton);
    minusBtn = (Button) findViewById(R.id.minusbutton);
    productNum = (TextView) findViewById(R.id.quantitytext);
    screenShotImg = (ImageView) findViewById(R.id.screen_shot_output);
    initializeToolbar();
    // garbage bin
    rect = new Rect();
    garbage.getDrawingRect(rect);

    // for image onclick 正反面
    recycle.setOnClickListener(
        new View.OnClickListener() {

          @Override
          public void onClick(View v) {
            if (position_status == FRONT) {
              shirtview.setImageResource(R.drawable.tshirtback);
              for (View element : ViewList) {
                element.setVisibility(View.INVISIBLE);
              }
              for (View element : ViewListBack) {
                element.setVisibility(View.VISIBLE);
              }
              position_status = BACK;

              // test
              addImageViewResources(R.mipmap.ic_launcher);
            } else if (position_status == BACK) {
              shirtview.setImageResource(R.drawable.whiteshirt);
              for (View element : ViewListBack) {
                element.setVisibility(View.INVISIBLE);
              }
              for (View element : ViewList) {
                element.setVisibility(View.VISIBLE);
              }

              position_status = FRONT;
            }
          }
        });

    // for testing
    addImageViewResources(R.drawable.logo);
    addImageViewResources(R.mipmap.ic_launcher);

    ////////////////////////////////////////////////////////////////////////////////////
    //       Sliding Panel initialization
    ////////////////////////////////////////////////////////////////////////////////////

    GridView gv2 = (GridView) findViewById(R.id.grid2);
    gv2.setOnItemClickListener(
        new AdapterView.OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Toast.makeText(EditProduct.this, "onItemClick", Toast.LENGTH_SHORT).show();
          }
        });
    ListView lv3 = (ListView) findViewById(R.id.list3);
    lv3.setOnItemClickListener(
        new AdapterView.OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Toast.makeText(EditProduct.this, "onItemClick", Toast.LENGTH_SHORT).show();
          }
        });

    List<String> your_array_list =
        Arrays.asList(
            "This",
            "Is",
            "An",
            "Example",
            "ListView",
            "That",
            "You",
            "Can",
            "Scroll",
            ".",
            "It",
            "Shows",
            "How",
            "Any",
            "Scrollable",
            "View",
            "Can",
            "Be",
            "Included",
            "As",
            "A",
            "Child",
            "Of",
            "SlidingUpPanelLayout");

    String[] templates =
        new String[] {"grid1", "grid2", "grid3", "grid4", "grid5", "grid6", "grid7"};
    // This is the array adapter, it takes the context of the activity as a
    // first parameter, the type of list view as a second parameter and your
    // array as a third parameter.
    ArrayAdapter<String> arrayAdapter =
        new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, your_array_list);

    gv2.setAdapter(new ImageAdapter(this, templates));

    lv3.setAdapter(arrayAdapter);

    mLayout = (SlidingUpPanelLayout) findViewById(R.id.sliding_layout);
    mLayout.setPanelSlideListener(
        new SlidingUpPanelLayout.PanelSlideListener() {
          @Override
          public void onPanelSlide(View panel, float slideOffset) {}

          @Override
          public void onPanelExpanded(View panel) {}

          @Override
          public void onPanelCollapsed(View panel) {
            mLayout.setPanelState(SlidingUpPanelLayout.PanelState.HIDDEN);
            setAllBtmButtonsVisible();
            setAllPanelsGone();
          }

          @Override
          public void onPanelAnchored(View panel) {}

          @Override
          public void onPanelHidden(View panel) {}
        });
    mLayout2 = (SlidingUpPanelLayout) findViewById(R.id.sliding_layout2);
    mLayout2.setPanelSlideListener(
        new SlidingUpPanelLayout.PanelSlideListener() {
          @Override
          public void onPanelSlide(View panel, float slideOffset) {}

          @Override
          public void onPanelExpanded(View panel) {}

          @Override
          public void onPanelCollapsed(View panel) {
            mLayout2.setPanelState(SlidingUpPanelLayout.PanelState.HIDDEN);
            setAllBtmButtonsVisible();
            setAllPanelsGone();
          }

          @Override
          public void onPanelAnchored(View panel) {}

          @Override
          public void onPanelHidden(View panel) {}
        });
    mLayout3 = (SlidingUpPanelLayout) findViewById(R.id.sliding_layout3);
    mLayout3.setPanelSlideListener(
        new SlidingUpPanelLayout.PanelSlideListener() {
          @Override
          public void onPanelSlide(View panel, float slideOffset) {}

          @Override
          public void onPanelExpanded(View panel) {}

          @Override
          public void onPanelCollapsed(View panel) {
            mLayout3.setPanelState(SlidingUpPanelLayout.PanelState.HIDDEN);
            setAllBtmButtonsVisible();
            setAllPanelsGone();
          }

          @Override
          public void onPanelAnchored(View panel) {}

          @Override
          public void onPanelHidden(View panel) {}
        });
    mLayout4 = (SlidingUpPanelLayout) findViewById(R.id.sliding_layout4);
    mLayout4.setPanelSlideListener(
        new SlidingUpPanelLayout.PanelSlideListener() {
          @Override
          public void onPanelSlide(View panel, float slideOffset) {}

          @Override
          public void onPanelExpanded(View panel) {}

          @Override
          public void onPanelCollapsed(View panel) {
            mLayout4.setPanelState(SlidingUpPanelLayout.PanelState.HIDDEN);
            setAllBtmButtonsVisible();
            setAllPanelsGone();
          }

          @Override
          public void onPanelAnchored(View panel) {}

          @Override
          public void onPanelHidden(View panel) {}
        });

    mAttributeButton = (Button) findViewById(R.id.attributeButton);
    mTemplateButton = (Button) findViewById(R.id.templateButton);
    mTextButton = (Button) findViewById(R.id.textButton);
    mAlignButton = (Button) findViewById(R.id.alignButton);
    mFinishButton = (Button) findViewById(R.id.finishButton);
    mAttributeButton.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View view) {
            setAllBtmButtonsGone();
            if (mLayout != null) {
              if (mLayout.getPanelState() != SlidingUpPanelLayout.PanelState.EXPANDED) {
                mLayout.setVisibility(View.VISIBLE);
                mLayout.setPanelState(SlidingUpPanelLayout.PanelState.EXPANDED);
              }
              mLayout2.setVisibility(View.GONE);
              mLayout3.setVisibility(View.GONE);
              mLayout4.setVisibility(View.GONE);
            }
          }
        });
    mTemplateButton.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View view) {
            setAllBtmButtonsGone();
            if (mLayout2 != null) {
              setAllBtmButtonsGone();
              if (mLayout2.getPanelState() != SlidingUpPanelLayout.PanelState.EXPANDED) {
                mLayout2.setVisibility(View.VISIBLE);
                mLayout2.setPanelState(SlidingUpPanelLayout.PanelState.EXPANDED);
              }
              mLayout.setVisibility(View.GONE);
              mLayout3.setVisibility(View.GONE);
              mLayout4.setVisibility(View.GONE);
            }
          }
        });
    // text 无需上滑菜单
    /* mTextButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            setAllBtmButtonsGone();
            if(mLayout3 != null){
                if(mLayout3.getPanelState() != SlidingUpPanelLayout.PanelState.EXPANDED){
                    mLayout3.setVisibility(View.VISIBLE);
                    mLayout3.setPanelState(SlidingUpPanelLayout.PanelState.EXPANDED);
                }
                mLayout.setVisibility(View.GONE);
                mLayout2.setVisibility(View.GONE);
                mLayout4.setVisibility(View.GONE);
            }
        }
    });*/
    mAlignButton.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View view) {
            setAllBtmButtonsGone();
            if (mLayout4 != null) {
              if (mLayout4.getPanelState() != SlidingUpPanelLayout.PanelState.EXPANDED) {
                mLayout4.setVisibility(View.VISIBLE);
                mLayout4.setPanelState(SlidingUpPanelLayout.PanelState.EXPANDED);
              }
              mLayout.setVisibility(View.GONE);
              mLayout2.setVisibility(View.GONE);
              mLayout3.setVisibility(View.GONE);
            }
          }
        });
    mFinishButton.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            captureScreen();
          }
        });

    setAllPanelsGone();
  }
コード例 #3
0
  @Override
  public boolean onTouchEvent(MotionEvent ev) {
    if (mGestureDetector != null) {
      mGestureDetector.onTouchEvent(ev);
    }
    if ((mDragListener != null || mDropListener != null) && mFloatView != null) {
      int action = ev.getAction();

      final int x = (int) ev.getX();
      final int y = (int) ev.getY();

      switch (action & MotionEvent.ACTION_MASK) {
        case MotionEvent.ACTION_UP:
        case MotionEvent.ACTION_CANCEL:
          Rect r = mTempRect;
          mFloatView.getDrawingRect(r);
          // mDragScroller.stopScrolling(true);

          if (mRemoveMode == SLIDE && ev.getX() > r.right * 3 / 4) {
            dropFloatView(true);
          } else {
            dropFloatView(false);
          }

          break;

        case MotionEvent.ACTION_DOWN:
          // doExpansion();
          break;
        case MotionEvent.ACTION_MOVE:

          // make src item invisible on first move away from pickup
          // point. Reduces flicker.
          if (mLastY == mDownY) {
            // should we be this careful?
            final View item = getChildAt(mSrcDragPos - getFirstVisiblePosition());
            if (item != null) {
              item.setVisibility(INVISIBLE);
            }
          }

          dragView(x, y);

          if (!mDragScroller.isScrolling()) {
            final int first = getFirstVisiblePosition();
            final View startView = getChildAt(mExpDragPos - first);
            int startPos;
            int startTop;
            if (startView == null) {
              startPos = first + getChildCount() / 2;
              startTop = getChildAt(startPos - first).getTop();
              Log.d("mobeta", "startView was null");
            } else {
              startPos = mExpDragPos;
              startTop = startView.getTop();
            }

            // Log.d("mobeta", "move shuffle");
            boolean shuffled = shuffleItems(getFloatPosition(y, startPos, startTop));

            if (shuffled) {
              super.layoutChildren();
            }
          }

          // get the current scroll direction
          int currentScrollDir = mDragScroller.getScrollDir();

          if (y > mLastY && y > mDownScrollStartY && currentScrollDir != DragScroller.DOWN) {
            // dragged down, it is below the down scroll start and
            // it is not scrolling up

            if (currentScrollDir != DragScroller.STOP) {
              // moved directly from up scroll to down scroll
              mDragScroller.stopScrolling(true);
            }

            // start scrolling down
            mDragScroller.startScrolling(DragScroller.DOWN);
          } else if (y < mLastY && y < mUpScrollStartY && currentScrollDir != DragScroller.UP) {
            // dragged up, it is above the up scroll start and it is
            // not scrolling up

            if (currentScrollDir != DragScroller.STOP) {
              // moved directly from down scroll to up scroll
              mDragScroller.stopScrolling(true);
            }

            // start scrolling up
            mDragScroller.startScrolling(DragScroller.UP);
          } else if (y >= mUpScrollStartY
              && y <= mDownScrollStartY
              && mDragScroller.isScrolling()) {
            // not in the upper nor in the lower drag-scroll regions
            // but it is still scrolling

            mDragScroller.stopScrolling(true);
          }
          break;
      }

      mLastX = x;
      mLastY = y;

      return true;
    }
    return super.onTouchEvent(ev);
  }
コード例 #4
0
  @Override
  public boolean onTouchEvent(MotionEvent ev) {
    if (mGestureDetector != null) {
      mGestureDetector.onTouchEvent(ev);
    }
    if ((mDragListener != null || mDropListener != null) && mDragView != null) {
      int action = ev.getAction();
      switch (action) {
        case MotionEvent.ACTION_UP:
        case MotionEvent.ACTION_CANCEL:
          Rect r = mTempRect;
          mDragView.getDrawingRect(r);
          stopDragging();
          if (mRemoveMode == SLIDE && ev.getX() > r.right * 3 / 4) {
            if (mRemoveListener != null) {
              mRemoveListener.remove(mSrcDragPos);
            }
            unExpandViews(true);
          } else {
            if (mDropListener != null && mDragPos >= 0 && mDragPos < getCount()) {
              mDropListener.drop(mSrcDragPos, mDragPos);
            }
            unExpandViews(false);
          }
          break;

        case MotionEvent.ACTION_DOWN:
        case MotionEvent.ACTION_MOVE:
          int x = (int) ev.getX();
          int y = (int) ev.getY();
          dragView(x, y);
          int itemnum = getItemForPosition(y);
          if (itemnum >= 0) {
            if (action == MotionEvent.ACTION_DOWN || itemnum != mDragPos) {
              if (mDragListener != null) {
                mDragListener.drag(mDragPos, itemnum);
              }
              mDragPos = itemnum;
              doExpansion();
            }
            int speed = 0;
            adjustScrollBounds(y);
            if (y > mLowerBound) {
              // scroll the list up a bit
              if (getLastVisiblePosition() < getCount() - 1) {
                speed = y > (mHeight + mLowerBound) / 2 ? 16 : 4;
              } else {
                speed = 1;
              }
            } else if (y < mUpperBound) {
              // scroll the list down a bit
              speed = y < mUpperBound / 2 ? -16 : -4;
              if (getFirstVisiblePosition() == 0 && getChildAt(0).getTop() >= getPaddingTop()) {
                // if we're already at the top, don't try to scroll, because
                // it causes the framework to do some extra drawing that messes
                // up our animation
                speed = 0;
              }
            }
            if (speed != 0) {
              smoothScrollBy(speed, 30);
            }
          }
          break;
      }
      return true;
    }
    return super.onTouchEvent(ev);
  }