public void startSildingInAnimation(int position) {
    this.selectItemPosition = position;
    arrowView.setY(leftView.getChildAt(position - leftView.getFirstVisiblePosition()).getTop());
    tempScrollY = (int) getScroll();
    if (Math.abs(leftView.getX()) < leftlist_img_width * 0.2) { // 如果leftview大部分都显示出来,就执行动画

      parentViewSliding(
          viewWidth,
          0,
          parentView,
          500l,
          new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
              super.onAnimationEnd(animation);
            }

            @Override
            public void onAnimationStart(Animator animation) {
              super.onAnimationStart(animation);
              parentView.setVisibility(VISIBLE);
            }
          });

      leftViewSliding(0, -(int) leftlist_img_width, leftView, 500l);
    }
  }
        @Override
        public boolean onTouch(View v, MotionEvent event) {
          switch (event.getAction() & MotionEvent.ACTION_MASK) {
            case MotionEvent.ACTION_DOWN:
              matrix.getValues(imageValues);

              selectedPoint[0] = (event.getX() - imageValues[2]) / imageValues[0];
              selectedPoint[1] = (event.getY() - imageValues[5]) / imageValues[4];

              Log.d("POINT_TOUCH", "IMAGE : " + selectedPoint[0] + " and " + selectedPoint[1]);

              if (selectedPoint[1] < bounds.height()) {
                marker.setX(event.getX() - markerBounds.width() / 2);
                marker.setY(event.getY() - markerBounds.height());
                marker.setAlpha(VISIBLE);
                measureButton.setClickable(true);
                measureButton.setEnabled(true);
              } else {
                marker.setAlpha(TRANSPARENT);
                measureButton.setClickable(false);
                measureButton.setEnabled(false);
              }
              break;
          }
          return true;
        }
 public void setY(float y) {
   if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
     super.setY(y);
   } else {
     RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) getLayoutParams();
     params.topMargin = (int) y;
     setLayoutParams(params);
   }
 }
 private ImageView cloneImageView(ImageView view) {
   ImageView result = new ImageView(this);
   result.setX(view.getX());
   result.setY(view.getY());
   result.setScaleType(view.getScaleType());
   result.setScaleX(view.getScaleX());
   result.setScaleY(view.getScaleY());
   result.setImageDrawable(view.getDrawable());
   return result;
 }
示例#5
0
 /** 根据x,y,重新设置控件的位置 因为setX setY为0的时候,都是在状态栏以下的,所以app不是全屏的话,需要扣掉状态栏的高度 */
 private void relocation(int[] location) {
   ivTriangle.setX(location[0] - ivTriangle.getWidth() / 2);
   ivTriangle.setY(
       location[1]
           - ivTriangle.getHeight() / 2
           - (isFullScreen()
               ? 0.0f
               : getStatusBarHeight())); // 因为三角形是通过XML绘制出来的,可以到activity_tip_overlay.xml中把三角形的那个ImageView背景设置一下,就知道什么情况了。所以需要减掉一半的高度
   switch (gravity) {
     case GRAVITY_BOTTOM:
       llContent.setY(
           location[1]
               - ivTriangle.getHeight() / 2
               - (isFullScreen() ? 0.0f : getStatusBarHeight())
               + ivTriangle.getHeight());
       break;
     case GRAVITY_TOP:
       llContent.setY(
           location[1]
               - llContent.getHeight()
               - (isFullScreen() ? 0.0f : getStatusBarHeight())
               - ivTriangle.getHeight() / 2);
       break;
   }
   // 显示内容的区域往三角形靠拢
   int triangleCenterX = (int) (ivTriangle.getX() + ivTriangle.getWidth() / 2); // 三角形的中心点
   int contentWidth = llContent.getWidth();
   int rightMargin = getScreenWidth() - triangleCenterX; // 三角形中心距离屏幕右边的距离
   int leftMargin = getScreenWidth() - rightMargin; // 三角形中心距离屏幕左边的距离
   RelativeLayout.LayoutParams layoutParams =
       (RelativeLayout.LayoutParams) llContent.getLayoutParams();
   int availableLeftMargin = leftMargin - layoutParams.leftMargin; // 左边可用的距离
   int availableRightMargin = rightMargin - layoutParams.rightMargin; // 右边可用的距离
   int x = 0;
   if (contentWidth / 2 <= availableLeftMargin
       && contentWidth / 2 <= availableRightMargin) // 左右两边有足够的距离
   {
     x = triangleCenterX - contentWidth / 2;
   } else {
     if (availableLeftMargin <= availableRightMargin) // 判断三角形在屏幕中心的左边
     {
       x = layoutParams.leftMargin;
     } else // 三角形在屏幕中心的右边
     {
       x = getScreenWidth() - (contentWidth + layoutParams.rightMargin);
     }
   }
   llContent.setX(x);
 }
 private void setViewY(int y, boolean animated, boolean adjustMapPos) {
   if (!oldAndroid()) {
     mainView.setY(y);
     fabView.setY(getFabY(y));
   } else {
     mainView.setPadding(0, y, 0, 0);
     fabView.setPadding(0, getFabY(y), 0, 0);
   }
   if (!customMapCenter) {
     if (adjustMapPos) {
       adjustMapPosition(y, animated);
     }
   } else {
     customMapCenter = false;
   }
 }
示例#7
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    layout = (RelativeLayout) findViewById(R.id.layout_pato);

    this.getSupportActionBar().hide();

    pato = new ImageView(this);
    pato.setY(150);
    posXini = pato.getX();
    posYini = pato.getY();

    pato.setImageResource(R.drawable.little_duck);
    tiempo = (TextView) findViewById(R.id.textViewTiempo);
    btnRestart = (Button) findViewById(R.id.btn_restart);
    txtPuntuacion = (TextView) findViewById(R.id.textViewPuntuacion);
    cuentaAtrasIni = (TextView) findViewById(R.id.textViewCuentaAtrasIni);

    layout.addView(pato);
    AudioAttributes aa =
        new AudioAttributes.Builder()
            .setUsage(AudioAttributes.USAGE_ALARM)
            .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
            .build();

    soundPool = new SoundPool.Builder().setMaxStreams(10).setAudioAttributes(aa).build();

    id = soundPool.load(MainActivity.this, R.raw.powerup, 1);
    iniciarCuentaAtrasInicial();

    btnRestart.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {

            txtPuntuacion.setText("0");
            iniciarCuentaAtrasInicial();
            btnRestart.setVisibility(View.INVISIBLE);
            pato.setX(posXini);
            pato.setY(posYini);
            cuentaAtrasIni.setVisibility(View.VISIBLE);
            puntuacion = 0;
          }
        });
  }
  /**
   * Method that create a new frame to be drawn in the specified location
   *
   * @param r The location relative to the parent layout
   * @return v The new view
   */
  private View createFrame(Rect r, boolean animate) {
    int padding = (int) getResources().getDimension(R.dimen.disposition_frame_padding);
    final ImageView v = new ImageView(getContext());
    v.setImageResource(R.drawable.ic_camera);
    v.setScaleType(ScaleType.CENTER);

    // Is locked? Then change the background color
    v.setBackgroundColor(
        getResources()
            .getColor(
                mResizeFrame == null
                    ? R.color.disposition_locked_frame_bg_color
                    : R.color.disposition_frame_bg_color));

    RelativeLayout.LayoutParams params =
        new RelativeLayout.LayoutParams(r.width() - padding, r.height() - padding);
    v.setX(r.left + padding);
    v.setY(r.top + padding);
    v.setOnLongClickListener(this);
    addView(v, params);

    // Animate the view
    if (animate) {
      List<Animator> animators = new ArrayList<Animator>();
      animators.add(ObjectAnimator.ofFloat(v, "scaleX", 0.0f, 1.0f));
      animators.add(ObjectAnimator.ofFloat(v, "scaleY", 0.0f, 1.0f));
      animators.add(ObjectAnimator.ofFloat(v, "alpha", 0.0f, 1.0f));
      animators.add(ObjectAnimator.ofFloat(v, "alpha", 0.0f, 1.0f));

      AnimatorSet animSet = new AnimatorSet();
      animSet.playTogether(animators);
      animSet.setDuration(getResources().getInteger(R.integer.disposition_show_anim));
      animSet.setInterpolator(new BounceInterpolator());
      animSet.setTarget(v);
      animSet.start();
    }

    return v;
  }
    @Override
    protected void onPostExecute(String result) {
      Log.d("HTTP_REQUEST", result);
      tmpMatrix.getValues(tmpValues);

      try {
        JSONArray jsonList = new JSONArray(result);

        for (int i = 0; i < jsonList.length(); ++i) {
          JSONObject row = jsonList.getJSONObject(i);
          Float x = (float) row.getDouble("x");
          Float y = (float) row.getDouble("y");
          savedLocations.add(new Location(x, y));

          // Display all markers
          ImageView existingPointMarker = new ImageView(getApplicationContext());
          existingPointMarker.setImageResource(R.drawable.marker);
          existingPointMarker.setAlpha(VISIBLE);
          existingPointMarker.setX(tmpValues[0] * x + tmpValues[2] - markerBounds.width() / 2);
          existingPointMarker.setY(tmpValues[4] * y + tmpValues[5] - markerBounds.height());
          relativeLayout.addView(existingPointMarker);
          markers.add(existingPointMarker);
        }
      } catch (JSONException e) {
        try {
          JSONObject jsonResponse = new JSONObject(result);
          if (!jsonResponse.getBoolean("success")) {
            Toast.makeText(
                    CalibrationActivity.this,
                    jsonResponse.getString("exception"),
                    Toast.LENGTH_LONG)
                .show();
          }
        } catch (JSONException ex) {
          ex.printStackTrace();
        }
      }
    }
  // *************************      Initialize Question       *********************************
  private void initQuestion() {
    Log.i("fullCClassName", className);
    if (numberOfQuestionsRemaining < 1) {
      Intent intent = new Intent(NegativeCoordActivity.this, ResultActivity.class);
      intent.putExtra("Score", scoreTotal);
      intent.putExtra("ClassName", className);
      intent.putExtra("Level", 3);
      startActivity(intent);
      finish();
    } else {

      if (firstQuestion == false) {
        numberOfQuestionsRemaining--;

        Random randScore = new Random();
        int low = 0;
        int high = 0;
        if (seconds <= 5) {
          low = 40;
          high = 50;
        }
        if (seconds > 5 && seconds <= 7) {
          low = 30;
          high = 40;
        }
        if (seconds > 7) {
          low = 10;
          high = 30;
        }
        score = randScore.nextInt(high - low + 1) + low;
        scoreTotal = scoreTotal + score;
        scoreText.setText(Integer.toString(score));
        scoreText.startAnimation(scoreTextAnimmation);
        timerHandler.removeCallbacks(timerRunnable);
      }
      firstQuestion = false;
      seconds = 0;
      timerHandler.postDelayed(timerRunnable, 0);

      ProgressBarAnimation anim =
          new ProgressBarAnimation(scoreBar, scoreBar.getProgress(), scoreTotal);
      anim.setDuration(300);
      scoreBar.startAnimation(anim);

      if (STAR_ONE_ENABLED == 0) {
        if (scoreBar.getProgress() >= (scoreBar.getMax() / 2)) {
          StarView star1 =
              new StarView(
                  this,
                  scoreLayout,
                  new RelativeLayout.LayoutParams(starOne.getWidth(), starOne.getHeight()),
                  starOne);
          scoreLayout.addView(star1);
          star1.translateAndShine(new ImageView(this));
          STAR_ONE_ENABLED = 1;
        }
      }
      if (STAR_TWO_ENABLED == 0) {
        if (scoreBar.getProgress() >= ((scoreBar.getMax() * 1.7) - scoreBar.getMax())) {
          StarView star2 =
              new StarView(
                  this,
                  scoreLayout,
                  new RelativeLayout.LayoutParams(starTwo.getWidth(), starTwo.getHeight()),
                  starTwo);
          scoreLayout.addView(star2);
          star2.translateAndShine(new ImageView(this));
          STAR_TWO_ENABLED = 1;
        }
      }
      if (STAR_THREE_ENABLED == 0) {
        if (scoreBar.getProgress() >= ((scoreBar.getMax() * 1.8) - scoreBar.getMax())) {
          StarView star3 =
              new StarView(
                  this,
                  scoreLayout,
                  new RelativeLayout.LayoutParams(starThree.getWidth(), starThree.getHeight()),
                  starThree);
          scoreLayout.addView(star3);
          star3.translateAndShine(new ImageView(this));
          STAR_THREE_ENABLED = 1;
        }
      }
      // *****  Type of Question  *****

      // Init question
      Random random = new Random();
      int randomCoordX = random.nextInt(8) - 4;
      int randomCoordY = random.nextInt(8) - 4;
      question = new QuestionCoord(randomCoordX, randomCoordY);

      // Move Lines
      if (numberOfQuestionsRemaining > (numberOfQuestions / 2)) {
        marker.setVisibility(View.INVISIBLE);

        // Positive
        questionCoordX.setText(question.getxString());
        questionCoordY.setText(question.getyString());

        currentLineXcoord = 0;
        currentLineYcoord = 0;
        setLinePositions(glv);

        coordNumbersX.setText("x");
        coordNumbersY.setText("y");

      }
      // Drag Number Panels Positive
      else {
        if (numberOfQuestionsRemaining == (numberOfQuestions / 2)) {
          gridLayout.removeView(lineX);
          gridLayout.removeView(lineY);

          questionCoordX.setText("x");
          questionCoordY.setText("y");

          initNumberPadAndAnswePanel();
          initSwitches();
        }

        marker.setVisibility(View.INVISIBLE);

        // Match x&y to question x&y
        AxisX x = null;
        AxisY y = null;
        for (int i = 0; i < glv.getAxisXlines().size(); i++) {
          if (glv.getAxisXlines().get(i).xNumber == question.getXNumber()) {
            x = glv.getAxisXlines().get(i);
          }
          if (glv.getAxisYlines().get(i).yNumber == question.getYNumber()) {
            y = glv.getAxisYlines().get(i);
          }
        }
        marker.setX(((int) x.x) - marker.getWidth() / 2);
        marker.setY(((int) y.y) - marker.getHeight() / 2);
        scaleIn = new ScaleAnimation(0.0f, 1.0f, 0.0f, 1.0f);
        scaleIn.setDuration(300);
        scaleIn.setStartOffset(200);
        scaleIn.setInterpolator(new OvershootInterpolator());
        scaleIn.setFillAfter(true);
        scaleIn.setAnimationListener(
            new AnimationListener() {
              @Override
              public void onAnimationEnd(Animation arg0) {}

              @Override
              public void onAnimationRepeat(Animation animation) {}

              @Override
              public void onAnimationStart(Animation animation) {
                marker.setVisibility(View.VISIBLE);
              }
            });
        marker.startAnimation(scaleIn);

        coordNumbersX.setText("x");
        coordNumbersY.setText("y");
      }
    }
  }
  @Override
  public boolean onTouch(View v, MotionEvent event) {
    switch (event.getAction()) {
      case MotionEvent.ACTION_DOWN:
        {
          x = event.getX();
          y = event.getY();
          startX = (int) event.getX() - (int) imageView.getX();
          startY = (int) event.getY() - (int) imageView.getY();
          start = System.currentTimeMillis();
        }
        break;
      case MotionEvent.ACTION_MOVE:
        {
          difx = x - imageView.getX();
          dify = y - imageView.getY();
          int xd = getDistance(startX, (int) difx);
          int yd = getDistance(startY, (int) dify);

          if (allowDrag) {
            if (event.getX() - difx > i_activity.GetPreviewLeftMargine()
                && event.getX() - difx + imageView.getWidth()
                    < i_activity.GetPreviewLeftMargine() + i_activity.GetPreviewWidth())
              imageView.setX(event.getX() - difx);
            if (event.getY() - dify > i_activity.GetPreviewTopMargine()
                && event.getY() - dify + imageView.getHeight()
                    < i_activity.GetPreviewTopMargine() + i_activity.GetPreviewHeight())
              imageView.setY(event.getY() - dify);
            if (xd >= distance || yd >= distance) {

              moving = true;
            }
          }
        }
        break;
      case MotionEvent.ACTION_UP:
        {
          long time = System.currentTimeMillis() - start;
          duration = duration + time;

          if (moving) {
            moving = false;
            x = 0;
            y = 0;
            difx = 0;
            dify = 0;
            recthalf = (int) imageView.getWidth() / 2;
            imageRect =
                new FocusRect(
                    (int) imageView.getX() - recthalf,
                    (int) imageView.getX() + recthalf,
                    (int) imageView.getY() - recthalf,
                    (int) imageView.getY() + recthalf);
            if (touchListnerEvent != null)
              touchListnerEvent.onAreaCHanged(
                  imageRect, i_activity.GetPreviewWidth(), i_activity.GetPreviewHeight());
          } else {
            touchListnerEvent.OnAreaClick(
                ((int) imageView.getX() + (int) event.getX()),
                ((int) imageView.getY() + (int) event.getY()));
          }

          if (duration >= MAX_DURATION) {
            System.out.println("Long Press Time: " + duration);
            // George Was Here On a tuesday lol
            System.out.println("Insert AE Code here: ");
          }
        }
    }
    return true;
  }