List of usage examples for java.lang Math atan
public static double atan(double a)
From source file:org.csa.rstb.gpf.decompositions.Touzi.java
/** * Perform decomposition for given tile. * * @param targetTiles The current tiles to be computed for each target band. * @param targetRectangle The area in pixel coordinates to be computed. * @param op the polarimetric decomposition operator * @throws org.esa.beam.framework.gpf.OperatorException If an error occurs during computation of the filtered value. *///w w w . j av a2 s .c o m public void computeTile(final Map<Band, Tile> targetTiles, final Rectangle targetRectangle, final Operator op) { final int x0 = targetRectangle.x; final int y0 = targetRectangle.y; final int w = targetRectangle.width; final int h = targetRectangle.height; final int maxY = y0 + h; final int maxX = x0 + w; //System.out.println("x0 = " + x0 + ", y0 = " + y0 + ", w = " + w + ", h = " + h); final TileIndex trgIndex = new TileIndex(targetTiles.get(op.getTargetProduct().getBandAt(0))); final double[][] Tr = new double[3][3]; final double[][] Ti = new double[3][3]; final double[][] EigenVectRe = new double[3][3]; final double[][] EigenVectIm = new double[3][3]; final double[] EigenVal = new double[3]; final double[] psi = new double[3]; final double[] tau = new double[3]; final double[] alpha = new double[3]; final double[] phi = new double[3]; final double[] vr = new double[3]; final double[] vi = new double[3]; double p1, p2, p3, psiMean, tauMean, alphaMean, phiMean; double phase, c, s, tmp1r, tmp1i, tmp2r, tmp2i; for (final PolBandUtils.PolSourceBand bandList : srcBandList) { final Tile[] sourceTiles = new Tile[bandList.srcBands.length]; final ProductData[] dataBuffers = new ProductData[bandList.srcBands.length]; final Rectangle sourceRectangle = getSourceRectangle(x0, y0, w, h); for (int i = 0; i < bandList.srcBands.length; ++i) { sourceTiles[i] = op.getSourceTile(bandList.srcBands[i], sourceRectangle); dataBuffers[i] = sourceTiles[i].getDataBuffer(); } final TileIndex srcIndex = new TileIndex(sourceTiles[0]); for (int y = y0; y < maxY; ++y) { trgIndex.calculateStride(y); for (int x = x0; x < maxX; ++x) { final int idx = trgIndex.getIndex(x); PolOpUtils.getMeanCoherencyMatrix(x, y, halfWindowSizeX, halfWindowSizeY, sourceImageWidth, sourceImageHeight, sourceProductType, srcIndex, dataBuffers, Tr, Ti); PolOpUtils.eigenDecomposition(3, Tr, Ti, EigenVectRe, EigenVectIm, EigenVal); for (int k = 0; k < 3; ++k) { for (int l = 0; l < 3; ++l) { vr[l] = EigenVectRe[l][k]; vi[l] = EigenVectIm[l][k]; } phase = Math.atan2(vi[0], vr[0] + PolOpUtils.EPS); c = FastMath.cos(phase); s = FastMath.sin(phase); for (int l = 0; l < 3; ++l) { tmp1r = vr[l]; tmp1i = vi[l]; vr[l] = tmp1r * c + tmp1i * s; vi[l] = tmp1i * c - tmp1r * s; } psi[k] = 0.5 * Math.atan2(vr[2], vr[1] + PolOpUtils.EPS); tmp1r = vr[1]; tmp1i = vi[1]; tmp2r = vr[2]; tmp2i = vi[2]; c = FastMath.cos(2.0 * psi[k]); s = FastMath.sin(2.0 * psi[k]); vr[1] = tmp1r * c + tmp2r * s; vi[1] = tmp1i * c + tmp2i * s; vr[2] = -tmp1r * s + tmp2r * c; vi[2] = -tmp1i * s + tmp2i * c; tau[k] = 0.5 * Math.atan2(-vi[2], vr[0] + PolOpUtils.EPS); phi[k] = Math.atan2(vi[1], vr[1] + PolOpUtils.EPS); alpha[k] = Math .atan(Math.sqrt((vr[1] * vr[1] + vi[1] * vi[1]) / (vr[0] * vr[0] + vi[2] * vi[2]))); if ((psi[k] < -Math.PI / 4.0) || (psi[k] > Math.PI / 4.0)) { tau[k] = -tau[k]; phi[k] = -phi[k]; } } final double sum = EigenVal[0] + EigenVal[1] + EigenVal[2]; p1 = EigenVal[0] / sum; p2 = EigenVal[1] / sum; p3 = EigenVal[2] / sum; psiMean = p1 * psi[0] + p2 * psi[1] + p3 * psi[2]; tauMean = p1 * tau[0] + p2 * tau[1] + p3 * tau[2]; alphaMean = p1 * alpha[0] + p2 * alpha[1] + p3 * alpha[2]; phiMean = p1 * phi[0] + p2 * phi[1] + p3 * phi[2]; for (final Band band : bandList.targetBands) { final String targetBandName = band.getName(); final ProductData dataBuffer = targetTiles.get(band).getDataBuffer(); if (outputTouziParamSet0) { if (targetBandName.equals("Psi") || targetBandName.contains("Psi_")) dataBuffer.setElemFloatAt(idx, (float) psiMean); else if (targetBandName.equals("Tau") || targetBandName.contains("Tau_")) dataBuffer.setElemFloatAt(idx, (float) tauMean); else if (targetBandName.equals("Alpha") || targetBandName.contains("Alpha_")) dataBuffer.setElemFloatAt(idx, (float) alphaMean); else if (targetBandName.equals("Phi") || targetBandName.contains("Phi_")) dataBuffer.setElemFloatAt(idx, (float) phiMean); } if (outputTouziParamSet1) { if (targetBandName.contains("Psi1")) dataBuffer.setElemFloatAt(idx, (float) psi[0]); else if (targetBandName.contains("Tau1")) dataBuffer.setElemFloatAt(idx, (float) tau[0]); else if (targetBandName.contains("Alpha1")) dataBuffer.setElemFloatAt(idx, (float) alpha[0]); else if (targetBandName.contains("Phi1")) dataBuffer.setElemFloatAt(idx, (float) phi[0]); } if (outputTouziParamSet2) { if (targetBandName.contains("Psi2")) dataBuffer.setElemFloatAt(idx, (float) psi[1]); else if (targetBandName.contains("Tau2")) dataBuffer.setElemFloatAt(idx, (float) tau[1]); else if (targetBandName.contains("Alpha2")) dataBuffer.setElemFloatAt(idx, (float) alpha[1]); else if (targetBandName.contains("Phi2")) dataBuffer.setElemFloatAt(idx, (float) phi[1]); } if (outputTouziParamSet3) { if (targetBandName.contains("Psi3")) dataBuffer.setElemFloatAt(idx, (float) psi[2]); else if (targetBandName.contains("Tau3")) dataBuffer.setElemFloatAt(idx, (float) tau[2]); else if (targetBandName.contains("Alpha3")) dataBuffer.setElemFloatAt(idx, (float) alpha[2]); else if (targetBandName.contains("Phi3")) dataBuffer.setElemFloatAt(idx, (float) phi[2]); } } } } } }
From source file:org.csa.rstb.polarimetric.gpf.decompositions.Touzi.java
/** * Perform decomposition for given tile. * * @param targetTiles The current tiles to be computed for each target band. * @param targetRectangle The area in pixel coordinates to be computed. * @param op the polarimetric decomposition operator * @throws OperatorException If an error occurs during computation of the filtered value. *//*from w w w . ja va 2 s.com*/ public void computeTile(final Map<Band, Tile> targetTiles, final Rectangle targetRectangle, final Operator op) { final int x0 = targetRectangle.x; final int y0 = targetRectangle.y; final int w = targetRectangle.width; final int h = targetRectangle.height; final int maxY = y0 + h; final int maxX = x0 + w; //System.out.println("x0 = " + x0 + ", y0 = " + y0 + ", w = " + w + ", h = " + h); final TileIndex trgIndex = new TileIndex(targetTiles.get(op.getTargetProduct().getBandAt(0))); final double[][] Tr = new double[3][3]; final double[][] Ti = new double[3][3]; final double[][] EigenVectRe = new double[3][3]; final double[][] EigenVectIm = new double[3][3]; final double[] EigenVal = new double[3]; final double[] psi = new double[3]; final double[] tau = new double[3]; final double[] alpha = new double[3]; final double[] phi = new double[3]; final double[] vr = new double[3]; final double[] vi = new double[3]; double p1, p2, p3, psiMean, tauMean, alphaMean, phiMean; double phase, c, s, tmp1r, tmp1i, tmp2r, tmp2i; for (final PolBandUtils.PolSourceBand bandList : srcBandList) { final Tile[] sourceTiles = new Tile[bandList.srcBands.length]; final ProductData[] dataBuffers = new ProductData[bandList.srcBands.length]; final Rectangle sourceRectangle = getSourceRectangle(x0, y0, w, h); for (int i = 0; i < bandList.srcBands.length; ++i) { sourceTiles[i] = op.getSourceTile(bandList.srcBands[i], sourceRectangle); dataBuffers[i] = sourceTiles[i].getDataBuffer(); } final TileIndex srcIndex = new TileIndex(sourceTiles[0]); for (int y = y0; y < maxY; ++y) { trgIndex.calculateStride(y); for (int x = x0; x < maxX; ++x) { final int idx = trgIndex.getIndex(x); PolOpUtils.getMeanCoherencyMatrix(x, y, halfWindowSizeX, halfWindowSizeY, sourceImageWidth, sourceImageHeight, sourceProductType, srcIndex, dataBuffers, Tr, Ti); PolOpUtils.eigenDecomposition(3, Tr, Ti, EigenVectRe, EigenVectIm, EigenVal); for (int k = 0; k < 3; ++k) { for (int l = 0; l < 3; ++l) { vr[l] = EigenVectRe[l][k]; vi[l] = EigenVectIm[l][k]; } phase = Math.atan2(vi[0], vr[0] + PolOpUtils.EPS); c = FastMath.cos(phase); s = FastMath.sin(phase); for (int l = 0; l < 3; ++l) { tmp1r = vr[l]; tmp1i = vi[l]; vr[l] = tmp1r * c + tmp1i * s; vi[l] = tmp1i * c - tmp1r * s; } psi[k] = 0.5 * Math.atan2(vr[2], vr[1] + PolOpUtils.EPS); tmp1r = vr[1]; tmp1i = vi[1]; tmp2r = vr[2]; tmp2i = vi[2]; c = FastMath.cos(2.0 * psi[k]); s = FastMath.sin(2.0 * psi[k]); vr[1] = tmp1r * c + tmp2r * s; vi[1] = tmp1i * c + tmp2i * s; vr[2] = -tmp1r * s + tmp2r * c; vi[2] = -tmp1i * s + tmp2i * c; tau[k] = 0.5 * Math.atan2(-vi[2], vr[0] + PolOpUtils.EPS); phi[k] = Math.atan2(vi[1], vr[1] + PolOpUtils.EPS); alpha[k] = Math .atan(Math.sqrt((vr[1] * vr[1] + vi[1] * vi[1]) / (vr[0] * vr[0] + vi[2] * vi[2]))); if ((psi[k] < -Constants.PI / 4.0) || (psi[k] > Constants.PI / 4.0)) { tau[k] = -tau[k]; phi[k] = -phi[k]; } } final double sum = EigenVal[0] + EigenVal[1] + EigenVal[2]; p1 = EigenVal[0] / sum; p2 = EigenVal[1] / sum; p3 = EigenVal[2] / sum; psiMean = p1 * psi[0] + p2 * psi[1] + p3 * psi[2]; tauMean = p1 * tau[0] + p2 * tau[1] + p3 * tau[2]; alphaMean = p1 * alpha[0] + p2 * alpha[1] + p3 * alpha[2]; phiMean = p1 * phi[0] + p2 * phi[1] + p3 * phi[2]; for (final Band band : bandList.targetBands) { final String targetBandName = band.getName(); final ProductData dataBuffer = targetTiles.get(band).getDataBuffer(); if (outputTouziParamSet0) { if (targetBandName.equals("Psi") || targetBandName.contains("Psi_")) dataBuffer.setElemFloatAt(idx, (float) psiMean); else if (targetBandName.equals("Tau") || targetBandName.contains("Tau_")) dataBuffer.setElemFloatAt(idx, (float) tauMean); else if (targetBandName.equals("Alpha") || targetBandName.contains("Alpha_")) dataBuffer.setElemFloatAt(idx, (float) alphaMean); else if (targetBandName.equals("Phi") || targetBandName.contains("Phi_")) dataBuffer.setElemFloatAt(idx, (float) phiMean); } if (outputTouziParamSet1) { if (targetBandName.contains("Psi1")) dataBuffer.setElemFloatAt(idx, (float) psi[0]); else if (targetBandName.contains("Tau1")) dataBuffer.setElemFloatAt(idx, (float) tau[0]); else if (targetBandName.contains("Alpha1")) dataBuffer.setElemFloatAt(idx, (float) alpha[0]); else if (targetBandName.contains("Phi1")) dataBuffer.setElemFloatAt(idx, (float) phi[0]); } if (outputTouziParamSet2) { if (targetBandName.contains("Psi2")) dataBuffer.setElemFloatAt(idx, (float) psi[1]); else if (targetBandName.contains("Tau2")) dataBuffer.setElemFloatAt(idx, (float) tau[1]); else if (targetBandName.contains("Alpha2")) dataBuffer.setElemFloatAt(idx, (float) alpha[1]); else if (targetBandName.contains("Phi2")) dataBuffer.setElemFloatAt(idx, (float) phi[1]); } if (outputTouziParamSet3) { if (targetBandName.contains("Psi3")) dataBuffer.setElemFloatAt(idx, (float) psi[2]); else if (targetBandName.contains("Tau3")) dataBuffer.setElemFloatAt(idx, (float) tau[2]); else if (targetBandName.contains("Alpha3")) dataBuffer.setElemFloatAt(idx, (float) alpha[2]); else if (targetBandName.contains("Phi3")) dataBuffer.setElemFloatAt(idx, (float) phi[2]); } } } } } }
From source file:android.view.SpringIndicator.java
private void setUpListener() { viewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { @Override/*w ww .j a va 2s . c o m*/ public void onPageSelected(final int position) { super.onPageSelected(position); setSelectedTextColor(position); if (delegateListener != null) delegateListener.onPageSelected(position); } @Override public void onPageScrolled(final int position, final float positionOffset, final int positionOffsetPixels) { if (position < tabs.size() - 1) { // radius final float radiusOffsetHead = 0.5f; if (positionOffset < radiusOffsetHead) springView.getHeadPoint().setRadius(radiusMin); else springView.getHeadPoint().setRadius( (positionOffset - radiusOffsetHead) / (1 - radiusOffsetHead) * radiusOffset + radiusMin); final float radiusOffsetFoot = 0.5f; if (positionOffset < radiusOffsetFoot) springView.getFootPoint() .setRadius((1 - positionOffset / radiusOffsetFoot) * radiusOffset + radiusMin); else springView.getFootPoint().setRadius(radiusMin); // x float headX = 1f; if (positionOffset < headMoveOffset) { final float positionOffsetTemp = positionOffset / headMoveOffset; headX = (float) ((Math.atan(positionOffsetTemp * acceleration * 2 - acceleration) + Math.atan(acceleration)) / (2 * Math.atan(acceleration))); } springView.getHeadPoint().setX(getTabX(position) - headX * getPositionDistance(position)); float footX = 0f; if (positionOffset > footMoveOffset) { final float positionOffsetTemp = (positionOffset - footMoveOffset) / (1 - footMoveOffset); footX = (float) ((Math.atan(positionOffsetTemp * acceleration * 2 - acceleration) + Math.atan(acceleration)) / (2 * Math.atan(acceleration))); } springView.getFootPoint().setX(getTabX(position) - footX * getPositionDistance(position)); // reset radius if (positionOffset == 0) { springView.getHeadPoint().setRadius(radiusMax); springView.getFootPoint().setRadius(radiusMax); } } else { springView.getHeadPoint().setX(getTabX(position)); springView.getFootPoint().setX(getTabX(position)); springView.getHeadPoint().setRadius(radiusMax); springView.getFootPoint().setRadius(radiusMax); } // set indicator colors // https://github.com/TaurusXi/GuideBackgroundColorAnimation if (indicatorColorsId != 0) { final float length = (position + positionOffset) / viewPager.getAdapter().getCount(); final int progress = (int) (length * INDICATOR_ANIM_DURATION); seek(progress); } springView.postInvalidate(); if (delegateListener != null) delegateListener.onPageScrolled(position, positionOffset, positionOffsetPixels); } @Override public void onPageScrollStateChanged(final int state) { super.onPageScrollStateChanged(state); if (delegateListener != null) delegateListener.onPageScrollStateChanged(state); } }); }
From source file:tools.help.java
/** * POZOR neuprauje sa vyska sfunk?ne suradnice su XYZ * * @param LCcoordinates1 globalne suradnice lokalneho sysemu bod 1 * @param LCcoordinates2 globalne suradnice lokalneho sysemu bod 2 * @param P1 bod v globalnych sur ktory transformujeme do LC pri?om 00je * LCCOORDINATES1/*from w ww . j av a2 s .c o m*/ * @return */ public static DPoint CorToLC(double[] LCcoordinates1, double[] LCcoordinates2, DPoint P1) { //double GCX = constants.getGCcoordinates()[0]; // double GCZ = constants.getGCcoordinates()[2]; double P1XGC = P1.getX(); double P1ZGC = P1.getZ(); double LCX1 = LCcoordinates1[0]; double LCZ1 = LCcoordinates1[2]; double LCX2 = LCcoordinates2[0]; double LCZ2 = LCcoordinates2[2]; double alpha = 0; if (LCX1 == LCX2) { if (LCZ1 - LCZ2 < 0) { alpha = Math.PI / 2; } if (LCZ1 - LCZ2 > 0) { alpha = -Math.PI / 2; } } // n ochrana pred 90 stupnami a delenim nulou else { alpha = Math.atan((LCZ1 - LCZ2) / (LCX1 - LCX2)); // uhol otocenia // else{ alpha = Math.atan2((LCX2 - LCX1),(LCZ2 - LCZ1) ); // else{ alpha = Math.atan((LCZ1 - LCZ2) / (LCX1 - LCX2)); // uhol otocenia System.out.println(alpha); } double P1XLC = (P1XGC - LCX1) * Math.cos(alpha) + (P1ZGC - LCZ1) * Math.sin(alpha); double P1ZLC = (P1ZGC - LCZ1) * Math.cos(alpha) + (P1XGC - LCX1) * Math.sin(alpha); P1.setX(P1XLC); P1.setZ(P1ZLC); return P1; }
From source file:com.darly.dlclent.widget.springindicator.SpringIndicator.java
private void setUpListener() { viewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { @Override/* w ww. j a va 2s .c o m*/ public void onPageSelected(int position) { super.onPageSelected(position); setSelectedTextColor(position); if (delegateListener != null) { delegateListener.onPageSelected(position); } } @Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { if (position < tabs.size() - 1) { // radius float radiusOffsetHead = 0.5f; if (positionOffset < radiusOffsetHead) { springView.getHeadPoint().setRadius(radiusMin); } else { springView.getHeadPoint().setRadius( ((positionOffset - radiusOffsetHead) / (1 - radiusOffsetHead) * radiusOffset + radiusMin)); } float radiusOffsetFoot = 0.5f; if (positionOffset < radiusOffsetFoot) { springView.getFootPoint() .setRadius((1 - positionOffset / radiusOffsetFoot) * radiusOffset + radiusMin); } else { springView.getFootPoint().setRadius(radiusMin); } // x float headX = 1f; if (positionOffset < headMoveOffset) { float positionOffsetTemp = positionOffset / headMoveOffset; headX = (float) ((Math.atan(positionOffsetTemp * acceleration * 2 - acceleration) + (Math.atan(acceleration))) / (2 * (Math.atan(acceleration)))); } springView.getHeadPoint().setX(getTabX(position) - headX * getPositionDistance(position)); float footX = 0f; if (positionOffset > footMoveOffset) { float positionOffsetTemp = (positionOffset - footMoveOffset) / (1 - footMoveOffset); footX = (float) ((Math.atan(positionOffsetTemp * acceleration * 2 - acceleration) + (Math.atan(acceleration))) / (2 * (Math.atan(acceleration)))); } springView.getFootPoint().setX(getTabX(position) - footX * getPositionDistance(position)); // reset radius if (positionOffset == 0) { springView.getHeadPoint().setRadius(radiusMax); springView.getFootPoint().setRadius(radiusMax); } } else { springView.getHeadPoint().setX(getTabX(position)); springView.getFootPoint().setX(getTabX(position)); springView.getHeadPoint().setRadius(radiusMax); springView.getFootPoint().setRadius(radiusMax); } // set indicator colors // https://github.com/TaurusXi/GuideBackgroundColorAnimation if (indicatorColorsId != 0) { float length = (position + positionOffset) / viewPager.getAdapter().getCount(); int progress = (int) (length * INDICATOR_ANIM_DURATION); seek(progress); } springView.postInvalidate(); if (delegateListener != null) { delegateListener.onPageScrolled(position, positionOffset, positionOffsetPixels); } } @Override public void onPageScrollStateChanged(int state) { super.onPageScrollStateChanged(state); if (delegateListener != null) { delegateListener.onPageScrollStateChanged(state); } } }); }
From source file:PaintUtils.java
private static double calcAngle(Point2D p1, Point2D p2) { double x_off = p2.getX() - p1.getX(); double y_off = p2.getY() - p1.getY(); double angle = Math.atan(y_off / x_off); if (x_off < 0) { angle = angle + Math.PI;// w w w . j a v a 2 s . c o m } if (angle < 0) { angle += 2 * Math.PI; } if (angle > 2 * Math.PI) { angle -= 2 * Math.PI; } return angle; }
From source file:com.chalilayang.test.customview.springindicator.SpringIndicator.java
private void setUpListener() { viewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { @Override//from w w w .j a v a 2 s. c o m public void onPageSelected(int position) { super.onPageSelected(position); setSelectedTextColor(position); if (delegateListener != null) { delegateListener.onPageSelected(position); } } @Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { Log.i("yangyong", "positionOffset " + positionOffset + " positionOffsetPixels " + positionOffsetPixels); if (position < tabs.size() - 1) { // radius float radiusOffsetHead = 0.5f; if (positionOffset < radiusOffsetHead) { springView.getHeadPoint().setRadius(radiusMin); } else { springView.getHeadPoint().setRadius( ((positionOffset - radiusOffsetHead) / (1 - radiusOffsetHead) * radiusOffset + radiusMin)); } float radiusOffsetFoot = 0.5f; if (positionOffset < radiusOffsetFoot) { springView.getFootPoint() .setRadius((1 - positionOffset / radiusOffsetFoot) * radiusOffset + radiusMin); } else { springView.getFootPoint().setRadius(radiusMin); } // x float headX = 1f; if (positionOffset < headMoveOffset) { float positionOffsetTemp = positionOffset / headMoveOffset; headX = (float) ((Math.atan(positionOffsetTemp * acceleration * 2 - acceleration) + (Math.atan(acceleration))) / (2 * (Math.atan(acceleration)))); } springView.getHeadPoint().setX(getTabX(position) - headX * getPositionDistance(position)); float footX = 0f; if (positionOffset > footMoveOffset) { float positionOffsetTemp = (positionOffset - footMoveOffset) / (1 - footMoveOffset); footX = (float) ((Math.atan(positionOffsetTemp * acceleration * 2 - acceleration) + (Math.atan(acceleration))) / (2 * (Math.atan(acceleration)))); } springView.getFootPoint().setX(getTabX(position) - footX * getPositionDistance(position)); // reset radius if (positionOffset == 0) { springView.getHeadPoint().setRadius(radiusMax); springView.getFootPoint().setRadius(radiusMax); } } else { springView.getHeadPoint().setX(getTabX(position)); springView.getFootPoint().setX(getTabX(position)); springView.getHeadPoint().setRadius(radiusMax); springView.getFootPoint().setRadius(radiusMax); } // set indicator colors // https://github.com/TaurusXi/GuideBackgroundColorAnimation if (indicatorColorsId != 0) { float length = (position + positionOffset) / viewPager.getAdapter().getCount(); int progress = (int) (length * INDICATOR_ANIM_DURATION); seek(progress); } springView.postInvalidate(); if (delegateListener != null) { delegateListener.onPageScrolled(position, positionOffset, positionOffsetPixels); } } @Override public void onPageScrollStateChanged(int state) { super.onPageScrollStateChanged(state); if (delegateListener != null) { delegateListener.onPageScrollStateChanged(state); } } }); }
From source file:com.grottworkshop.gwsspringindicator.SpringIndicator.java
@SuppressWarnings("deprecation") private void setUpListener() { //TODO: setOnPageChangeListener() is depreciated fix viewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { @Override//from www . ja va 2 s. c o m public void onPageSelected(int position) { super.onPageSelected(position); setSelectedTextColor(position); if (delegateListener != null) { delegateListener.onPageSelected(position); } } @Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { if (position < tabs.size() - 1) { // radius float radiusOffsetHead = 0.5f; if (positionOffset < radiusOffsetHead) { springView.getHeadPoint().setRadius(radiusMin); } else { springView.getHeadPoint().setRadius( ((positionOffset - radiusOffsetHead) / (1 - radiusOffsetHead) * radiusOffset + radiusMin)); } float radiusOffsetFoot = 0.5f; if (positionOffset < radiusOffsetFoot) { springView.getFootPoint() .setRadius((1 - positionOffset / radiusOffsetFoot) * radiusOffset + radiusMin); } else { springView.getFootPoint().setRadius(radiusMin); } // x float headX = 1f; if (positionOffset < headMoveOffset) { float positionOffsetTemp = positionOffset / headMoveOffset; headX = (float) ((Math.atan(positionOffsetTemp * acceleration * 2 - acceleration) + (Math.atan(acceleration))) / (2 * (Math.atan(acceleration)))); } springView.getHeadPoint().setX(getTabX(position) - headX * getPositionDistance(position)); float footX = 0f; if (positionOffset > footMoveOffset) { float positionOffsetTemp = (positionOffset - footMoveOffset) / (1 - footMoveOffset); footX = (float) ((Math.atan(positionOffsetTemp * acceleration * 2 - acceleration) + (Math.atan(acceleration))) / (2 * (Math.atan(acceleration)))); } springView.getFootPoint().setX(getTabX(position) - footX * getPositionDistance(position)); // reset radius if (positionOffset == 0) { springView.getHeadPoint().setRadius(radiusMax); springView.getFootPoint().setRadius(radiusMax); } } else { springView.getHeadPoint().setX(getTabX(position)); springView.getFootPoint().setX(getTabX(position)); springView.getHeadPoint().setRadius(radiusMax); springView.getFootPoint().setRadius(radiusMax); } // set indicator colors // https://github.com/TaurusXi/GuideBackgroundColorAnimation if (indicatorColorsId != 0) { float length = (position + positionOffset) / viewPager.getAdapter().getCount(); int progress = (int) (length * INDICATOR_ANIM_DURATION); seek(progress); } springView.postInvalidate(); if (delegateListener != null) { delegateListener.onPageScrolled(position, positionOffset, positionOffsetPixels); } } @Override public void onPageScrollStateChanged(int state) { super.onPageScrollStateChanged(state); if (delegateListener != null) { delegateListener.onPageScrollStateChanged(state); } } }); }
From source file:springindicator.SpringIndicator.java
private void setUpListener() { viewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { @Override/*from w ww. j a v a 2 s . com*/ public void onPageSelected(int position) { super.onPageSelected(position); if (position == (viewPager.getAdapter().getCount() - 1)) { btn_wel.setVisibility(View.VISIBLE); springIndicator.setVisibility(View.GONE); } else { btn_wel.setVisibility(View.GONE); springIndicator.setVisibility(View.VISIBLE); } setSelectedTextColor(position); } @Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { if (position < tabs.size() - 1) { // radius float radiusOffsetHead = 0.5f; if (positionOffset < radiusOffsetHead) { springView.getHeadPoint().setRadius(radiusMin); } else { springView.getHeadPoint().setRadius( ((positionOffset - radiusOffsetHead) / (1 - radiusOffsetHead) * radiusOffset + radiusMin)); } float radiusOffsetFoot = 0.5f; if (positionOffset < radiusOffsetFoot) { springView.getFootPoint() .setRadius((1 - positionOffset / radiusOffsetFoot) * radiusOffset + radiusMin); } else { springView.getFootPoint().setRadius(radiusMin); } // x float headX = 1f; if (positionOffset < headMoveOffset) { float positionOffsetTemp = positionOffset / headMoveOffset; headX = (float) ((Math.atan(positionOffsetTemp * acceleration * 2 - acceleration) + (Math.atan(acceleration))) / (2 * (Math.atan(acceleration)))); } springView.getHeadPoint().setX(getTabX(position) - headX * getPositionDistance(position)); float footX = 0f; if (positionOffset > footMoveOffset) { float positionOffsetTemp = (positionOffset - footMoveOffset) / (1 - footMoveOffset); footX = (float) ((Math.atan(positionOffsetTemp * acceleration * 2 - acceleration) + (Math.atan(acceleration))) / (2 * (Math.atan(acceleration)))); } springView.getFootPoint().setX(getTabX(position) - footX * getPositionDistance(position)); // reset radius if (positionOffset == 0) { springView.getHeadPoint().setRadius(radiusMax); springView.getFootPoint().setRadius(radiusMax); } } else { springView.getHeadPoint().setX(getTabX(position)); springView.getFootPoint().setX(getTabX(position)); springView.getHeadPoint().setRadius(radiusMax); springView.getFootPoint().setRadius(radiusMax); } // set indicator colors // https://github.com/TaurusXi/GuideBackgroundColorAnimation if (indicatorColorsId != 0) { float length = (position + positionOffset) / viewPager.getAdapter().getCount(); int progress = (int) (length * INDICATOR_ANIM_DURATION); seek(progress); } springView.postInvalidate(); } @Override public void onPageScrollStateChanged(int state) { super.onPageScrollStateChanged(state); } }); }
From source file:com.ltf.mytoolslibrary.viewbase.viewPagerGuidanceActivityMyLib.SpringIndicator.java
@SuppressWarnings("deprecation") private void setUpListener() { viewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { @Override/*from w w w .j a v a2 s .c om*/ public void onPageSelected(int position) { super.onPageSelected(position); setSelectedTextColor(position); if (delegateListener != null) { delegateListener.onPageSelected(position); } } @Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { if (position < tabs.size() - 1) { // radius float radiusOffsetHead = 0.5f; if (positionOffset < radiusOffsetHead) { springView.getHeadPoint().setRadius(radiusMin); } else { springView.getHeadPoint().setRadius( ((positionOffset - radiusOffsetHead) / (1 - radiusOffsetHead) * radiusOffset + radiusMin)); } float radiusOffsetFoot = 0.5f; if (positionOffset < radiusOffsetFoot) { springView.getFootPoint() .setRadius((1 - positionOffset / radiusOffsetFoot) * radiusOffset + radiusMin); } else { springView.getFootPoint().setRadius(radiusMin); } // x float headX = 1f; if (positionOffset < headMoveOffset) { float positionOffsetTemp = positionOffset / headMoveOffset; headX = (float) ((Math.atan(positionOffsetTemp * acceleration * 2 - acceleration) + (Math.atan(acceleration))) / (2 * (Math.atan(acceleration)))); } springView.getHeadPoint().setX(getTabX(position) - headX * getPositionDistance(position)); float footX = 0f; if (positionOffset > footMoveOffset) { float positionOffsetTemp = (positionOffset - footMoveOffset) / (1 - footMoveOffset); footX = (float) ((Math.atan(positionOffsetTemp * acceleration * 2 - acceleration) + (Math.atan(acceleration))) / (2 * (Math.atan(acceleration)))); } springView.getFootPoint().setX(getTabX(position) - footX * getPositionDistance(position)); // reset radius if (positionOffset == 0) { springView.getHeadPoint().setRadius(radiusMax); springView.getFootPoint().setRadius(radiusMax); } } else { springView.getHeadPoint().setX(getTabX(position)); springView.getFootPoint().setX(getTabX(position)); springView.getHeadPoint().setRadius(radiusMax); springView.getFootPoint().setRadius(radiusMax); } // set indicator colors // https://github.com/TaurusXi/GuideBackgroundColorAnimation if (indicatorColorsId != 0) { float length = (position + positionOffset) / viewPager.getAdapter().getCount(); int progress = (int) (length * INDICATOR_ANIM_DURATION); seek(progress); } springView.postInvalidate(); if (delegateListener != null) { delegateListener.onPageScrolled(position, positionOffset, positionOffsetPixels); } } @Override public void onPageScrollStateChanged(int state) { super.onPageScrollStateChanged(state); if (delegateListener != null) { delegateListener.onPageScrollStateChanged(state); } } }); }