Beispiel #1
0
 @Override
 protected void onDraw(Canvas canvas) {
   mPointCloud.draw(canvas);
   mOuterRing.draw(canvas);
   final int ntargets = mTargetDrawables.size();
   for (int i = 0; i < ntargets; i++) {
     TargetDrawable target = mTargetDrawables.get(i);
     if (target != null) {
       target.draw(canvas);
     }
   }
   mHandleDrawable.draw(canvas);
 }
  public static void testLoadingImage(String[] args) {
    System.out.println("Loading image data: ex 0");
    if (args.length < 1) {
      System.out.println("Usage: java ImageManipulation image");
      System.exit(0);
    }
    // load input image
    BufferedImage bimg = ImageManipulation.loadImage(args[0]);
    int dimx = bimg.getWidth();
    int dimy = bimg.getHeight();
    // get array of pixels from image, in L*u*v* space
    WritableRaster raster = bimg.getRaster();
    System.out.println("Pixels array created from image");

    // build point cloud from raster
    int dim = 3;
    PointCloud N = ImageManipulation.rasterToPointCloud(raster, dimx, dimy, dim);

    // draw input image and corresponding point cloud
    System.out.println("dim = " + dim + ", size = " + PointCloud.size(N));
    Draw.draw3D(N);
    Fenetre fInput = new Fenetre(bimg, "input image");
  }
Beispiel #3
0
  @Override
  protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
    super.onLayout(changed, left, top, right, bottom);
    final int width = right - left;
    final int height = bottom - top;

    // Target placement width/height. This puts the targets on the greater of the ring
    // width or the specified outer radius.
    final float placementWidth = getRingWidth();
    final float placementHeight = getRingHeight();
    float newWaveCenterX = mHorizontalInset + (mMaxTargetWidth + placementWidth) / 2;
    float newWaveCenterY = mVerticalInset + (mMaxTargetHeight + placementHeight) / 2;

    if (mInitialLayout) {
      stopAndHideWaveAnimation();
      hideTargets(false, false);
      mInitialLayout = false;
    }

    mOuterRing.setPositionX(newWaveCenterX);
    mOuterRing.setPositionY(newWaveCenterY);

    mPointCloud.setScale(mRingScaleFactor);

    mHandleDrawable.setPositionX(newWaveCenterX);
    mHandleDrawable.setPositionY(newWaveCenterY);

    updateTargetPositions(newWaveCenterX, newWaveCenterY);
    updatePointCloudPosition(newWaveCenterX, newWaveCenterY);
    updateGlowPosition(newWaveCenterX, newWaveCenterY);

    mWaveCenterX = newWaveCenterX;
    mWaveCenterY = newWaveCenterY;

    if (DEBUG) dump();
  }
Beispiel #4
0
  public GlowPadView(Context context, AttributeSet attrs) {
    super(context, attrs);
    Resources res = context.getResources();

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.GlowPadView);
    mInnerRadius = a.getDimension(R.styleable.GlowPadView_innerRadius, mInnerRadius);
    mOuterRadius = a.getDimension(R.styleable.GlowPadView_outerRadius, mOuterRadius);
    mSnapMargin = a.getDimension(R.styleable.GlowPadView_snapMargin, mSnapMargin);
    mVibrationDuration = a.getInt(R.styleable.GlowPadView_vibrationDuration, mVibrationDuration);
    mFeedbackCount = a.getInt(R.styleable.GlowPadView_feedbackCount, mFeedbackCount);
    mAllowScaling = a.getBoolean(R.styleable.GlowPadView_allowScaling, false);
    TypedValue handle = a.peekValue(R.styleable.GlowPadView_handleDrawable);
    mHandleDrawable = new TargetDrawable(res, handle != null ? handle.resourceId : 0, 2);
    mHandleDrawable.setState(TargetDrawable.STATE_INACTIVE);
    mOuterRing =
        new TargetDrawable(res, getResourceId(a, R.styleable.GlowPadView_outerRingDrawable), 1);

    mAlwaysTrackFinger = a.getBoolean(R.styleable.GlowPadView_alwaysTrackFinger, false);

    int pointId = getResourceId(a, R.styleable.GlowPadView_pointDrawable);
    Drawable pointDrawable = pointId != 0 ? res.getDrawable(pointId) : null;
    mGlowRadius = a.getDimension(R.styleable.GlowPadView_glowRadius, 0.0f);

    TypedValue outValue = new TypedValue();

    // Read array of target drawables
    if (a.getValue(R.styleable.GlowPadView_targetDrawables, outValue)) {
      internalSetTargetResources(outValue.resourceId);
    }
    if (mTargetDrawables == null || mTargetDrawables.size() == 0) {
      throw new IllegalStateException("Must specify at least one target drawable");
    }

    // Read array of target descriptions
    if (a.getValue(R.styleable.GlowPadView_targetDescriptions, outValue)) {
      final int resourceId = outValue.resourceId;
      if (resourceId == 0) {
        throw new IllegalStateException("Must specify target descriptions");
      }
      setTargetDescriptionsResourceId(resourceId);
    }

    // Read array of direction descriptions
    if (a.getValue(R.styleable.GlowPadView_directionDescriptions, outValue)) {
      final int resourceId = outValue.resourceId;
      if (resourceId == 0) {
        throw new IllegalStateException("Must specify direction descriptions");
      }
      setDirectionDescriptionsResourceId(resourceId);
    }

    a.recycle();

    // Use gravity attribute from LinearLayout
    // a = context.obtainStyledAttributes(attrs, R.styleable.LinearLayout);
    mGravity = a.getInt(R.styleable.GlowPadView_android_gravity, Gravity.TOP);
    a.recycle();

    setVibrateEnabled(mVibrationDuration > 0);

    assignDefaultsIfNeeded();

    mPointCloud = new PointCloud(pointDrawable);
    mPointCloud.makePointCloud(mInnerRadius, mOuterRadius);
    mPointCloud.glowManager.setRadius(mGlowRadius);
  }
Beispiel #5
0
 private void updatePointCloudPosition(float centerX, float centerY) {
   mPointCloud.setCenter(centerX, centerY);
 }