List of usage examples for java.lang Math hypot
public static double hypot(double x, double y)
From source file:com.rks.musicx.misc.utils.Helper.java
@NonNull public static Animator getCircularHideAnimtion(@NonNull View view) { int cx = view.getWidth() / 2; int cy = view.getHeight() / 2; int finalRadius = (int) Math.hypot(view.getWidth(), view.getHeight()); Animator animation = ViewAnimationUtils.createCircularReveal(view, cx, cy, 0, finalRadius); animation.setDuration(500);//from w w w .j a va2s .co m return animation; }
From source file:com.android.launcher3.CellLayout.java
/** * Find a vacant area that will fit the given bounds nearest the requested * cell location. Uses Euclidean distance to score multiple vacant areas. * * @param pixelX The X location at which you want to search for a vacant area. * @param pixelY The Y location at which you want to search for a vacant area. * @param minSpanX The minimum horizontal span required * @param minSpanY The minimum vertical span required * @param spanX Horizontal span of the object. * @param spanY Vertical span of the object. * @param ignoreOccupied If true, the result can be an occupied cell * @param result Array in which to place the result, or null (in which case a new array will * be allocated)//from www . j a v a 2 s . c om * @return The X, Y cell of a vacant area that can contain this object, * nearest the requested location. */ private int[] findNearestArea(int pixelX, int pixelY, int minSpanX, int minSpanY, int spanX, int spanY, boolean ignoreOccupied, int[] result, int[] resultSpan) { lazyInitTempRectStack(); // For items with a spanX / spanY > 1, the passed in point (pixelX, pixelY) corresponds // to the center of the item, but we are searching based on the top-left cell, so // we translate the point over to correspond to the top-left. pixelX -= (mCellWidth + mWidthGap) * (spanX - 1) / 2f; pixelY -= (mCellHeight + mHeightGap) * (spanY - 1) / 2f; // Keep track of best-scoring drop area final int[] bestXY = result != null ? result : new int[2]; double bestDistance = Double.MAX_VALUE; final Rect bestRect = new Rect(-1, -1, -1, -1); final Stack<Rect> validRegions = new Stack<Rect>(); final int countX = mCountX; final int countY = mCountY; if (minSpanX <= 0 || minSpanY <= 0 || spanX <= 0 || spanY <= 0 || spanX < minSpanX || spanY < minSpanY) { return bestXY; } for (int y = 0; y < countY - (minSpanY - 1); y++) { inner: for (int x = 0; x < countX - (minSpanX - 1); x++) { int ySize = -1; int xSize = -1; if (ignoreOccupied) { // First, let's see if this thing fits anywhere for (int i = 0; i < minSpanX; i++) { for (int j = 0; j < minSpanY; j++) { if (mOccupied[x + i][y + j]) { continue inner; } } } xSize = minSpanX; ySize = minSpanY; // We know that the item will fit at _some_ acceptable size, now let's see // how big we can make it. We'll alternate between incrementing x and y spans // until we hit a limit. boolean incX = true; boolean hitMaxX = xSize >= spanX; boolean hitMaxY = ySize >= spanY; while (!(hitMaxX && hitMaxY)) { if (incX && !hitMaxX) { for (int j = 0; j < ySize; j++) { if (x + xSize > countX - 1 || mOccupied[x + xSize][y + j]) { // We can't move out horizontally hitMaxX = true; } } if (!hitMaxX) { xSize++; } } else if (!hitMaxY) { for (int i = 0; i < xSize; i++) { if (y + ySize > countY - 1 || mOccupied[x + i][y + ySize]) { // We can't move out vertically hitMaxY = true; } } if (!hitMaxY) { ySize++; } } hitMaxX |= xSize >= spanX; hitMaxY |= ySize >= spanY; incX = !incX; } incX = true; hitMaxX = xSize >= spanX; hitMaxY = ySize >= spanY; } final int[] cellXY = mTmpPoint; cellToCenterPoint(x, y, cellXY); // We verify that the current rect is not a sub-rect of any of our previous // candidates. In this case, the current rect is disqualified in favour of the // containing rect. Rect currentRect = mTempRectStack.pop(); currentRect.set(x, y, x + xSize, y + ySize); boolean contained = false; for (Rect r : validRegions) { if (r.contains(currentRect)) { contained = true; break; } } validRegions.push(currentRect); double distance = Math.hypot(cellXY[0] - pixelX, cellXY[1] - pixelY); if ((distance <= bestDistance && !contained) || currentRect.contains(bestRect)) { bestDistance = distance; bestXY[0] = x; bestXY[1] = y; if (resultSpan != null) { resultSpan[0] = xSize; resultSpan[1] = ySize; } bestRect.set(currentRect); } } } // Return -1, -1 if no suitable location found if (bestDistance == Double.MAX_VALUE) { bestXY[0] = -1; bestXY[1] = -1; } recycleTempRects(validRegions); return bestXY; }
From source file:com.marlonjones.voidlauncher.CellLayout.java
/** * Find a vacant area that will fit the given bounds nearest the requested * cell location, and will also weigh in a suggested direction vector of the * desired location. This method computers distance based on unit grid distances, * not pixel distances./*from ww w .j a va 2s. c om*/ * * @param cellX The X cell nearest to which you want to search for a vacant area. * @param cellY The Y cell nearest which you want to search for a vacant area. * @param spanX Horizontal span of the object. * @param spanY Vertical span of the object. * @param direction The favored direction in which the views should move from x, y * @param occupied The array which represents which cells in the CellLayout are occupied * @param blockOccupied The array which represents which cells in the specified block (cellX, * cellY, spanX, spanY) are occupied. This is used when try to move a group of views. * @param result Array in which to place the result, or null (in which case a new array will * be allocated) * @return The X, Y cell of a vacant area that can contain this object, * nearest the requested location. */ private int[] findNearestArea(int cellX, int cellY, int spanX, int spanY, int[] direction, boolean[][] occupied, boolean blockOccupied[][], int[] result) { // Keep track of best-scoring drop area final int[] bestXY = result != null ? result : new int[2]; float bestDistance = Float.MAX_VALUE; int bestDirectionScore = Integer.MIN_VALUE; final int countX = mCountX; final int countY = mCountY; for (int y = 0; y < countY - (spanY - 1); y++) { inner: for (int x = 0; x < countX - (spanX - 1); x++) { // First, let's see if this thing fits anywhere for (int i = 0; i < spanX; i++) { for (int j = 0; j < spanY; j++) { if (occupied[x + i][y + j] && (blockOccupied == null || blockOccupied[i][j])) { continue inner; } } } float distance = (float) Math.hypot(x - cellX, y - cellY); int[] curDirection = mTmpPoint; computeDirectionVector(x - cellX, y - cellY, curDirection); // The direction score is just the dot product of the two candidate direction // and that passed in. int curDirectionScore = direction[0] * curDirection[0] + direction[1] * curDirection[1]; if (Float.compare(distance, bestDistance) < 0 || (Float.compare(distance, bestDistance) == 0 && curDirectionScore > bestDirectionScore)) { bestDistance = distance; bestDirectionScore = curDirectionScore; bestXY[0] = x; bestXY[1] = y; } } } // Return -1, -1 if no suitable location found if (bestDistance == Float.MAX_VALUE) { bestXY[0] = -1; bestXY[1] = -1; } return bestXY; }
From source file:com.android.launcher3.CellLayout.java
/** * Find a vacant area that will fit the given bounds nearest the requested * cell location, and will also weigh in a suggested direction vector of the * desired location. This method computers distance based on unit grid distances, * not pixel distances.// w ww .jav a 2 s . c o m * * @param cellX The X cell nearest to which you want to search for a vacant area. * @param cellY The Y cell nearest which you want to search for a vacant area. * @param spanX Horizontal span of the object. * @param spanY Vertical span of the object. * @param direction The favored direction in which the views should move from x, y * @param exactDirectionOnly If this parameter is true, then only solutions where the direction * matches exactly. Otherwise we find the best matching direction. * @param occoupied The array which represents which cells in the CellLayout are occupied * @param blockOccupied The array which represents which cells in the specified block (cellX, * cellY, spanX, spanY) are occupied. This is used when try to move a group of views. * @param result Array in which to place the result, or null (in which case a new array will * be allocated) * @return The X, Y cell of a vacant area that can contain this object, * nearest the requested location. */ private int[] findNearestArea(int cellX, int cellY, int spanX, int spanY, int[] direction, boolean[][] occupied, boolean blockOccupied[][], int[] result) { // Keep track of best-scoring drop area final int[] bestXY = result != null ? result : new int[2]; float bestDistance = Float.MAX_VALUE; int bestDirectionScore = Integer.MIN_VALUE; final int countX = mCountX; final int countY = mCountY; for (int y = 0; y < countY - (spanY - 1); y++) { inner: for (int x = 0; x < countX - (spanX - 1); x++) { // First, let's see if this thing fits anywhere for (int i = 0; i < spanX; i++) { for (int j = 0; j < spanY; j++) { if (occupied[x + i][y + j] && (blockOccupied == null || blockOccupied[i][j])) { continue inner; } } } float distance = (float) Math.hypot(x - cellX, y - cellY); int[] curDirection = mTmpPoint; computeDirectionVector(x - cellX, y - cellY, curDirection); // The direction score is just the dot product of the two candidate direction // and that passed in. int curDirectionScore = direction[0] * curDirection[0] + direction[1] * curDirection[1]; boolean exactDirectionOnly = false; boolean directionMatches = direction[0] == curDirection[0] && direction[0] == curDirection[0]; if ((directionMatches || !exactDirectionOnly) && Float.compare(distance, bestDistance) < 0 || (Float.compare(distance, bestDistance) == 0 && curDirectionScore > bestDirectionScore)) { bestDistance = distance; bestDirectionScore = curDirectionScore; bestXY[0] = x; bestXY[1] = y; } } } // Return -1, -1 if no suitable location found if (bestDistance == Float.MAX_VALUE) { bestXY[0] = -1; bestXY[1] = -1; } return bestXY; }
From source file:org.eclipse.january.dataset.Maths.java
/** * abs - absolute value of each element//w w w.j av a2 s . com * @param a * @param o output can be null - in which case, a new dataset is created * @return dataset */ public static Dataset abs(final Object a, final Dataset o) { final Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a); final SingleInputBroadcastIterator it = new SingleInputBroadcastIterator(da, o, true, true, false); final Dataset result = it.getOutput(); final int is = result.getElementsPerItem(); final int dt = result.getDType(); final int as = da.getElementsPerItem(); switch (dt) { case Dataset.INT8: final byte[] oi8data = ((ByteDataset) result).data; it.setOutputDouble(false); while (it.hasNext()) { oi8data[it.oIndex] = (byte) Math.abs(it.aLong); } break; case Dataset.INT16: final short[] oi16data = ((ShortDataset) result).data; it.setOutputDouble(false); while (it.hasNext()) { oi16data[it.oIndex] = (short) Math.abs(it.aLong); } break; case Dataset.INT32: final int[] oi32data = ((IntegerDataset) result).data; it.setOutputDouble(false); while (it.hasNext()) { oi32data[it.oIndex] = (int) Math.abs(it.aLong); } break; case Dataset.INT64: final long[] oi64data = ((LongDataset) result).data; it.setOutputDouble(false); while (it.hasNext()) { oi64data[it.oIndex] = Math.abs(it.aLong); } break; case Dataset.ARRAYINT8: final byte[] oai8data = ((CompoundByteDataset) result).data; it.setOutputDouble(false); if (is == 1) { while (it.hasNext()) { oai8data[it.oIndex] = (byte) Math.abs(it.aLong); } } else if (as == 1) { while (it.hasNext()) { byte ox = (byte) Math.abs(it.aLong); for (int j = 0; j < is; j++) { oai8data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { oai8data[it.oIndex] = (byte) Math.abs(it.aLong); for (int j = 1; j < is; j++) { oai8data[it.oIndex + j] = (byte) Math.abs(da.getElementLongAbs(it.aIndex + j)); } } } break; case Dataset.ARRAYINT16: final short[] oai16data = ((CompoundShortDataset) result).data; it.setOutputDouble(false); if (is == 1) { while (it.hasNext()) { oai16data[it.oIndex] = (short) Math.abs(it.aLong); } } else if (as == 1) { while (it.hasNext()) { short ox = (short) Math.abs(it.aLong); for (int j = 0; j < is; j++) { oai16data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { oai16data[it.oIndex] = (short) Math.abs(it.aLong); for (int j = 1; j < is; j++) { oai16data[it.oIndex + j] = (short) Math.abs(da.getElementLongAbs(it.aIndex + j)); } } } break; case Dataset.ARRAYINT32: final int[] oai32data = ((CompoundIntegerDataset) result).data; it.setOutputDouble(false); if (is == 1) { while (it.hasNext()) { oai32data[it.oIndex] = (int) Math.abs(it.aLong); } } else if (as == 1) { while (it.hasNext()) { int ox = (int) Math.abs(it.aLong); for (int j = 0; j < is; j++) { oai32data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { oai32data[it.oIndex] = (int) Math.abs(it.aLong); for (int j = 1; j < is; j++) { oai32data[it.oIndex + j] = (int) Math.abs(da.getElementLongAbs(it.aIndex + j)); } } } break; case Dataset.ARRAYINT64: final long[] oai64data = ((CompoundLongDataset) result).data; it.setOutputDouble(false); if (is == 1) { while (it.hasNext()) { oai64data[it.oIndex] = Math.abs(it.aLong); } } else if (as == 1) { while (it.hasNext()) { long ox = Math.abs(it.aLong); for (int j = 0; j < is; j++) { oai64data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { oai64data[it.oIndex] = Math.abs(it.aLong); for (int j = 1; j < is; j++) { oai64data[it.oIndex + j] = Math.abs(da.getElementLongAbs(it.aIndex + j)); } } } break; case Dataset.FLOAT32: final float[] of32data = ((FloatDataset) result).data; if (as == 1) { while (it.hasNext()) { of32data[it.oIndex] = (float) (Math.abs(it.aDouble)); } } else { while (it.hasNext()) { of32data[it.oIndex] = (float) (Math.hypot(it.aDouble, da.getElementDoubleAbs(it.aIndex + 1))); } } break; case Dataset.FLOAT64: final double[] of64data = ((DoubleDataset) result).data; if (as == 1) { while (it.hasNext()) { of64data[it.oIndex] = Math.abs(it.aDouble); } } else { while (it.hasNext()) { of64data[it.oIndex] = Math.hypot(it.aDouble, da.getElementDoubleAbs(it.aIndex + 1)); } } break; case Dataset.ARRAYFLOAT32: final float[] oaf32data = ((CompoundFloatDataset) result).data; if (is == 1) { while (it.hasNext()) { oaf32data[it.oIndex] = (float) (Math.abs(it.aDouble)); } } else if (as == 1) { while (it.hasNext()) { float ox = (float) (Math.abs(it.aDouble)); for (int j = 0; j < is; j++) { oaf32data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { oaf32data[it.oIndex] = (float) Math.abs(it.aDouble); for (int j = 1; j < is; j++) { oaf32data[it.oIndex + j] = (float) Math.abs(da.getElementDoubleAbs(it.aIndex + j)); } } } break; case Dataset.ARRAYFLOAT64: final double[] oaf64data = ((CompoundDoubleDataset) result).data; if (is == 1) { while (it.hasNext()) { oaf64data[it.oIndex] = Math.abs(it.aDouble); } } else if (as == 1) { while (it.hasNext()) { final double ix = it.aDouble; double ox = Math.abs(ix); for (int j = 0; j < is; j++) { oaf64data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { oaf64data[it.oIndex] = Math.abs(it.aDouble); for (int j = 1; j < is; j++) { oaf64data[it.oIndex + j] = Math.abs(da.getElementDoubleAbs(it.aIndex + j)); } } } break; case Dataset.COMPLEX64: final float[] oc64data = ((ComplexFloatDataset) result).data; if (as == 1) { while (it.hasNext()) { oc64data[it.oIndex] = (float) Math.abs(it.aDouble); } } else { while (it.hasNext()) { oc64data[it.oIndex] = (float) Math.hypot(it.aDouble, da.getElementDoubleAbs(it.aIndex + 1)); } } break; case Dataset.COMPLEX128: final double[] oc128data = ((ComplexDoubleDataset) result).data; if (as == 1) { while (it.hasNext()) { oc128data[it.oIndex] = Math.abs(it.aDouble); } } else { while (it.hasNext()) { oc128data[it.oIndex] = Math.hypot(it.aDouble, da.getElementDoubleAbs(it.aIndex + 1)); } } break; default: throw new IllegalArgumentException( "abs supports integer, compound integer, real, compound real, complex datasets only"); } addFunctionName(result, "abs"); return result; }
From source file:org.eclipse.dataset.Maths.java
/** * abs - absolute value of each element//from ww w. ja v a 2 s.co m * @param a * @param o output can be null - in which case, a new dataset is created * @return dataset */ public static Dataset abs(final Object a, final Dataset o) { final Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a); final SingleInputBroadcastIterator it = new SingleInputBroadcastIterator(da, o, true, true, false); final Dataset result = it.getOutput(); final int is = result.getElementsPerItem(); final int dt = result.getDtype(); final int as = da.getElementsPerItem(); switch (dt) { case Dataset.INT8: final byte[] oi8data = ((ByteDataset) result).data; it.setOutputDouble(false); while (it.hasNext()) { oi8data[it.oIndex] = (byte) Math.abs(it.aLong); } break; case Dataset.INT16: final short[] oi16data = ((ShortDataset) result).data; it.setOutputDouble(false); while (it.hasNext()) { oi16data[it.oIndex] = (short) Math.abs(it.aLong); } break; case Dataset.INT32: final int[] oi32data = ((IntegerDataset) result).data; it.setOutputDouble(false); while (it.hasNext()) { oi32data[it.oIndex] = (int) Math.abs(it.aLong); } break; case Dataset.INT64: final long[] oi64data = ((LongDataset) result).data; it.setOutputDouble(false); while (it.hasNext()) { oi64data[it.oIndex] = Math.abs(it.aLong); } break; case Dataset.ARRAYINT8: final byte[] oai8data = ((CompoundByteDataset) result).data; it.setOutputDouble(false); if (is == 1) { while (it.hasNext()) { oai8data[it.oIndex] = (byte) Math.abs(it.aLong); } } else if (as == 1) { while (it.hasNext()) { byte ox = (byte) Math.abs(it.aLong); for (int j = 0; j < is; j++) { oai8data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { oai8data[it.oIndex] = (byte) Math.abs(it.aLong); for (int j = 1; j < is; j++) { oai8data[it.oIndex + j] = (byte) Math.abs(da.getElementLongAbs(it.aIndex + j)); } } } break; case Dataset.ARRAYINT16: final short[] oai16data = ((CompoundShortDataset) result).data; it.setOutputDouble(false); if (is == 1) { while (it.hasNext()) { oai16data[it.oIndex] = (short) Math.abs(it.aLong); } } else if (as == 1) { while (it.hasNext()) { short ox = (short) Math.abs(it.aLong); for (int j = 0; j < is; j++) { oai16data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { oai16data[it.oIndex] = (short) Math.abs(it.aLong); for (int j = 1; j < is; j++) { oai16data[it.oIndex + j] = (short) Math.abs(da.getElementLongAbs(it.aIndex + j)); } } } break; case Dataset.ARRAYINT32: final int[] oai32data = ((CompoundIntegerDataset) result).data; it.setOutputDouble(false); if (is == 1) { while (it.hasNext()) { oai32data[it.oIndex] = (int) Math.abs(it.aLong); } } else if (as == 1) { while (it.hasNext()) { int ox = (int) Math.abs(it.aLong); for (int j = 0; j < is; j++) { oai32data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { oai32data[it.oIndex] = (int) Math.abs(it.aLong); for (int j = 1; j < is; j++) { oai32data[it.oIndex + j] = (int) Math.abs(da.getElementLongAbs(it.aIndex + j)); } } } break; case Dataset.ARRAYINT64: final long[] oai64data = ((CompoundLongDataset) result).data; it.setOutputDouble(false); if (is == 1) { while (it.hasNext()) { oai64data[it.oIndex] = Math.abs(it.aLong); } } else if (as == 1) { while (it.hasNext()) { long ox = Math.abs(it.aLong); for (int j = 0; j < is; j++) { oai64data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { oai64data[it.oIndex] = Math.abs(it.aLong); for (int j = 1; j < is; j++) { oai64data[it.oIndex + j] = Math.abs(da.getElementLongAbs(it.aIndex + j)); } } } break; case Dataset.FLOAT32: final float[] of32data = ((FloatDataset) result).data; if (as == 1) { while (it.hasNext()) { of32data[it.oIndex] = (float) (Math.abs(it.aDouble)); } } else { while (it.hasNext()) { of32data[it.oIndex] = (float) (Math.hypot(it.aDouble, da.getElementDoubleAbs(it.aIndex + 1))); } } break; case Dataset.FLOAT64: final double[] of64data = ((DoubleDataset) result).data; if (as == 1) { while (it.hasNext()) { of64data[it.oIndex] = Math.abs(it.aDouble); } } else { while (it.hasNext()) { of64data[it.oIndex] = Math.hypot(it.aDouble, da.getElementDoubleAbs(it.aIndex + 1)); } } break; case Dataset.ARRAYFLOAT32: final float[] oaf32data = ((CompoundFloatDataset) result).data; if (is == 1) { while (it.hasNext()) { oaf32data[it.oIndex] = (float) (Math.abs(it.aDouble)); } } else if (as == 1) { while (it.hasNext()) { float ox = (float) (Math.abs(it.aDouble)); for (int j = 0; j < is; j++) { oaf32data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { oaf32data[it.oIndex] = (float) Math.abs(it.aDouble); for (int j = 1; j < is; j++) { oaf32data[it.oIndex + j] = (float) Math.abs(da.getElementDoubleAbs(it.aIndex + j)); } } } break; case Dataset.ARRAYFLOAT64: final double[] oaf64data = ((CompoundDoubleDataset) result).data; if (is == 1) { while (it.hasNext()) { oaf64data[it.oIndex] = Math.abs(it.aDouble); } } else if (as == 1) { while (it.hasNext()) { final double ix = it.aDouble; double ox = Math.abs(ix); for (int j = 0; j < is; j++) { oaf64data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { oaf64data[it.oIndex] = Math.abs(it.aDouble); for (int j = 1; j < is; j++) { oaf64data[it.oIndex + j] = Math.abs(da.getElementDoubleAbs(it.aIndex + j)); } } } break; case Dataset.COMPLEX64: final float[] oc64data = ((ComplexFloatDataset) result).data; if (as == 1) { while (it.hasNext()) { oc64data[it.oIndex] = (float) Math.abs(it.aDouble); } } else { while (it.hasNext()) { oc64data[it.oIndex] = (float) Math.hypot(it.aDouble, da.getElementDoubleAbs(it.aIndex + 1)); } } break; case Dataset.COMPLEX128: final double[] oc128data = ((ComplexDoubleDataset) result).data; if (as == 1) { while (it.hasNext()) { oc128data[it.oIndex] = Math.abs(it.aDouble); } } else { while (it.hasNext()) { oc128data[it.oIndex] = Math.hypot(it.aDouble, da.getElementDoubleAbs(it.aIndex + 1)); } } break; default: throw new IllegalArgumentException( "abs supports integer, compound integer, real, compound real, complex datasets only"); } addFunctionName(result, "abs"); return result; }
From source file:org.telepatch.ui.ChatActivity.java
public View createView(LayoutInflater inflater, ViewGroup container) { if (fragmentView == null) { actionBarLayer.setDisplayHomeAsUpEnabled(true, R.drawable.ic_ab_back); if (AndroidUtilities.isTablet()) { actionBarLayer.setExtraLeftMargin(4); }/*from w ww . j a v a2s.co m*/ actionBarLayer.setBackOverlay(R.layout.updating_state_layout); actionBarLayer.setActionBarMenuOnItemClick(new ActionBarLayer.ActionBarMenuOnItemClick() { @Override public void onItemClick(int id) { if (id == -1) { finishFragment(); } else if (id == -2) { selectedMessagesIds.clear(); selectedMessagesCanCopyIds.clear(); actionBarLayer.hideActionMode(); updateVisibleRows(); } else if (id == attach_photo) { try { Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); File image = Utilities.generatePicturePath(); if (image != null) { takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(image)); currentPicturePath = image.getAbsolutePath(); } startActivityForResult(takePictureIntent, 0); } catch (Exception e) { FileLog.e("tmessages", e); } } else if (id == attach_gallery) { PhotoPickerActivity fragment = new PhotoPickerActivity(); fragment.setDelegate(new PhotoPickerActivity.PhotoPickerActivityDelegate() { @Override public void didSelectPhotos(ArrayList<String> photos) { SendMessagesHelper.prepareSendingPhotos(photos, null, dialog_id); } @Override public void startPhotoSelectActivity() { try { Intent photoPickerIntent = new Intent(Intent.ACTION_PICK); photoPickerIntent.setType("image/*"); startActivityForResult(photoPickerIntent, 1); } catch (Exception e) { FileLog.e("tmessages", e); } } }); presentFragment(fragment); } else if (id == attach_video) { try { Intent pickIntent = new Intent(); pickIntent.setType("video/*"); pickIntent.setAction(Intent.ACTION_GET_CONTENT); pickIntent.putExtra(MediaStore.EXTRA_SIZE_LIMIT, (long) (1024 * 1024 * 1000)); Intent takeVideoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE); File video = Utilities.generateVideoPath(); if (video != null) { if (Build.VERSION.SDK_INT >= 18) { takeVideoIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(video)); } takeVideoIntent.putExtra(MediaStore.EXTRA_SIZE_LIMIT, (long) (1024 * 1024 * 1000)); currentPicturePath = video.getAbsolutePath(); } Intent chooserIntent = Intent.createChooser(pickIntent, ""); chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { takeVideoIntent }); startActivityForResult(chooserIntent, 2); } catch (Exception e) { FileLog.e("tmessages", e); } } else if (id == attach_location) { if (!isGoogleMapsInstalled()) { return; } LocationActivity fragment = new LocationActivity(); fragment.setDelegate(new LocationActivity.LocationActivityDelegate() { @Override public void didSelectLocation(double latitude, double longitude) { SendMessagesHelper.getInstance().sendMessage(latitude, longitude, dialog_id); if (chatListView != null) { chatListView.setSelectionFromTop(messages.size() - 1, -100000 - chatListView.getPaddingTop()); } if (paused) { scrollToTopOnResume = true; } } }); presentFragment(fragment); } else if (id == attach_document) { DocumentSelectActivity fragment = new DocumentSelectActivity(); fragment.setDelegate(new DocumentSelectActivity.DocumentSelectActivityDelegate() { @Override public void didSelectFile(DocumentSelectActivity activity, String path) { activity.finishFragment(); SendMessagesHelper.prepareSendingDocument(path, path, dialog_id); } @Override public void startDocumentSelectActivity() { try { Intent photoPickerIntent = new Intent(Intent.ACTION_PICK); photoPickerIntent.setType("*/*"); startActivityForResult(photoPickerIntent, 21); } catch (Exception e) { FileLog.e("tmessages", e); } } }); presentFragment(fragment); } else if (id == chat_menu_avatar) { if (currentUser != null) { Bundle args = new Bundle(); args.putInt("user_id", currentUser.id); if (currentEncryptedChat != null) { args.putLong("dialog_id", dialog_id); } presentFragment(new UserProfileActivity(args)); } else if (currentChat != null) { if (info != null && info instanceof TLRPC.TL_chatParticipantsForbidden) { return; } int count = currentChat.participants_count; if (info != null) { count = info.participants.size(); } if (count == 0 || currentChat.left || currentChat instanceof TLRPC.TL_chatForbidden) { return; } Bundle args = new Bundle(); args.putInt("chat_id", currentChat.id); ChatProfileActivity fragment = new ChatProfileActivity(args); fragment.setChatInfo(info); presentFragment(fragment); } } else if (id == copy) { String str = ""; ArrayList<Integer> ids = new ArrayList<Integer>(selectedMessagesCanCopyIds.keySet()); if (currentEncryptedChat == null) { Collections.sort(ids); } else { Collections.sort(ids, Collections.reverseOrder()); } for (Integer messageId : ids) { MessageObject messageObject = selectedMessagesCanCopyIds.get(messageId); if (str.length() != 0) { str += "\n"; } if (messageObject.messageOwner.message != null) { str += messageObject.messageOwner.message; } else { str += messageObject.messageText; } } if (str.length() != 0) { if (Build.VERSION.SDK_INT < 11) { android.text.ClipboardManager clipboard = (android.text.ClipboardManager) ApplicationLoader.applicationContext .getSystemService(Context.CLIPBOARD_SERVICE); clipboard.setText(str); } else { android.content.ClipboardManager clipboard = (android.content.ClipboardManager) ApplicationLoader.applicationContext .getSystemService(Context.CLIPBOARD_SERVICE); android.content.ClipData clip = android.content.ClipData.newPlainText("label", str); clipboard.setPrimaryClip(clip); } } selectedMessagesIds.clear(); selectedMessagesCanCopyIds.clear(); actionBarLayer.hideActionMode(); updateVisibleRows(); } else if (id == delete) { ArrayList<Integer> ids = new ArrayList<Integer>(selectedMessagesIds.keySet()); ArrayList<Long> random_ids = null; if (currentEncryptedChat != null) { random_ids = new ArrayList<Long>(); for (HashMap.Entry<Integer, MessageObject> entry : selectedMessagesIds.entrySet()) { MessageObject msg = entry.getValue(); if (msg.messageOwner.random_id != 0 && msg.type != 10) { random_ids.add(msg.messageOwner.random_id); } } } //MessagesController.getInstance().deleteMessages(ids, random_ids, currentEncryptedChat); //TODO qui utilizzo un mio metodo per cancellare i messaggi, cosi' prima mostro un alert deleteMessages(ids, random_ids, currentEncryptedChat); actionBarLayer.hideActionMode(); } else if (id == forward) { Bundle args = new Bundle(); args.putBoolean("onlySelect", true); args.putBoolean("serverOnly", true); args.putString("selectAlertString", LocaleController.getString("ForwardMessagesTo", R.string.ForwardMessagesTo)); args.putString("selectAlertStringGroup", LocaleController .getString("ForwardMessagesToGroup", R.string.ForwardMessagesToGroup)); MessagesActivity fragment = new MessagesActivity(args); fragment.setDelegate(ChatActivity.this); presentFragment(fragment); } } }); updateSubtitle(); if (currentEncryptedChat != null) { actionBarLayer.setTitleIcon(R.drawable.ic_lock_white, AndroidUtilities.dp(4)); } else if (currentChat != null && currentChat.id < 0) { actionBarLayer.setTitleIcon(R.drawable.broadcast2, AndroidUtilities.dp(4)); } ActionBarMenu menu = actionBarLayer.createMenu(); if (currentEncryptedChat != null) { timeItem = menu.addItemResource(chat_enc_timer, R.layout.chat_header_enc_layout); } //TODO aggiungo il pulsante di ricerca item_search = menu.addItem(chat_menu_search, R.drawable.ic_ab_search); item_search.setIsSearchField(true) .setActionBarMenuItemSearchListener(new ActionBarMenuItem.ActionBarMenuItemSearchListener() { @Override public void onSearchExpand() { searching = true; } @Override public void onSearchCollapse() { searching = false; //MessagesController.getInstance().loadMessages(dialog_id, 0, 20, maxMessageId, !cacheEndReaced, minDate, classGuid, false, false); //NotificationCenter.getInstance().postNotificationName(dialogsNeedReload); } @Override public void onTextChanged(final EditText editText) { editText.requestFocus(); editText.setOnKeyListener(new View.OnKeyListener() { public boolean onKey(View v, int keyCode, KeyEvent event) { boolean result = false; // se l'evento e' un "tasto premuto" sul tasto enter if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) { //fai azione if (!editText.getText().toString().equals("")) { searchMessages(dialog_id, editText.getText().toString(), new FutureSearch()); try { presentFragment(new SearchResultsActivity( doSearchAndBlock(dialog_id, editText.getText().toString()), getArguments())); } catch (ExecutionException e) { e.printStackTrace(); } catch (InterruptedException e) { e.printStackTrace(); } catch (NullPointerException e) { Log.e("xela92", "NullPointerException. Forse la connessione di rete e' assente? La ricerca stata annullata. "); e.printStackTrace(); } } result = true; } return result; } }); } }); ActionBarMenuItem item = menu.addItem(chat_menu_attach, R.drawable.ic_ab_attach); item.addSubItem(attach_photo, LocaleController.getString("ChatTakePhoto", R.string.ChatTakePhoto), R.drawable.ic_attach_photo); item.addSubItem(attach_gallery, LocaleController.getString("ChatGallery", R.string.ChatGallery), R.drawable.ic_attach_gallery); item.addSubItem(attach_video, LocaleController.getString("ChatVideo", R.string.ChatVideo), R.drawable.ic_attach_video); item.addSubItem(attach_document, LocaleController.getString("ChatDocument", R.string.ChatDocument), R.drawable.ic_ab_doc); item.addSubItem(attach_location, LocaleController.getString("ChatLocation", R.string.ChatLocation), R.drawable.ic_attach_location); menuItem = item; actionModeViews.clear(); final ActionBarMenu actionMode = actionBarLayer.createActionMode(); actionModeViews.add(actionMode.addItem(-2, R.drawable.ic_ab_done_gray, R.drawable.bar_selector_mode)); FrameLayout layout = new FrameLayout(actionMode.getContext()); layout.setBackgroundColor(0xffe5e5e5); actionMode.addView(layout); LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) layout.getLayoutParams(); layoutParams.width = AndroidUtilities.dp(1); layoutParams.height = LinearLayout.LayoutParams.MATCH_PARENT; layoutParams.topMargin = AndroidUtilities.dp(12); layoutParams.bottomMargin = AndroidUtilities.dp(12); layoutParams.gravity = Gravity.CENTER_VERTICAL; layout.setLayoutParams(layoutParams); actionModeViews.add(layout); selectedMessagesCountTextView = new TextView(actionMode.getContext()); selectedMessagesCountTextView.setTextSize(18); selectedMessagesCountTextView.setTextColor(0xff000000); selectedMessagesCountTextView.setSingleLine(true); selectedMessagesCountTextView.setLines(1); selectedMessagesCountTextView.setEllipsize(TextUtils.TruncateAt.END); selectedMessagesCountTextView.setPadding(AndroidUtilities.dp(11), 0, 0, 0); selectedMessagesCountTextView.setGravity(Gravity.CENTER_VERTICAL); selectedMessagesCountTextView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { return true; } }); actionMode.addView(selectedMessagesCountTextView); layoutParams = (LinearLayout.LayoutParams) selectedMessagesCountTextView.getLayoutParams(); layoutParams.weight = 1; layoutParams.width = 0; layoutParams.height = LinearLayout.LayoutParams.MATCH_PARENT; selectedMessagesCountTextView.setLayoutParams(layoutParams); if (currentEncryptedChat == null) { actionModeViews .add(actionMode.addItem(copy, R.drawable.ic_ab_fwd_copy, R.drawable.bar_selector_mode)); actionModeViews.add( actionMode.addItem(forward, R.drawable.ic_ab_fwd_forward, R.drawable.bar_selector_mode)); actionModeViews .add(actionMode.addItem(delete, R.drawable.ic_ab_fwd_delete, R.drawable.bar_selector_mode)); } else { actionModeViews .add(actionMode.addItem(copy, R.drawable.ic_ab_fwd_copy, R.drawable.bar_selector_mode)); actionModeViews .add(actionMode.addItem(delete, R.drawable.ic_ab_fwd_delete, R.drawable.bar_selector_mode)); } actionMode.getItem(copy) .setVisibility(selectedMessagesCanCopyIds.size() != 0 ? View.VISIBLE : View.GONE); View avatarLayout = menu.addItemResource(chat_menu_avatar, R.layout.chat_header_layout); avatarImageView = (BackupImageView) avatarLayout.findViewById(R.id.chat_avatar_image); avatarImageView.processDetach = false; checkActionBarMenu(); fragmentView = inflater.inflate(R.layout.chat_layout, container, false); View contentView = fragmentView.findViewById(R.id.chat_layout); TextView emptyView = (TextView) fragmentView.findViewById(R.id.searchEmptyView); emptyViewContainer = fragmentView.findViewById(R.id.empty_view); emptyViewContainer.setVisibility(View.GONE); emptyViewContainer.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { return true; } }); emptyView.setText(LocaleController.getString("NoMessages", R.string.NoMessages)); chatListView = (LayoutListView) fragmentView.findViewById(R.id.chat_list_view); chatListView.setAdapter(chatAdapter = new ChatAdapter(getParentActivity())); topPanel = fragmentView.findViewById(R.id.top_panel); topPlaneClose = (ImageView) fragmentView.findViewById(R.id.top_plane_close); topPanelText = (TextView) fragmentView.findViewById(R.id.top_panel_text); bottomOverlay = fragmentView.findViewById(R.id.bottom_overlay); bottomOverlayText = (TextView) fragmentView.findViewById(R.id.bottom_overlay_text); bottomOverlayChat = fragmentView.findViewById(R.id.bottom_overlay_chat); progressView = fragmentView.findViewById(R.id.progressLayout); pagedownButton = fragmentView.findViewById(R.id.pagedown_button); pagedownButton.setVisibility(View.GONE); View progressViewInner = progressView.findViewById(R.id.progressLayoutInner); updateContactStatus(); SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE); int selectedBackground = preferences.getInt("selectedBackground", 1000001); int selectedColor = preferences.getInt("selectedColor", 0); if (selectedColor != 0) { contentView.setBackgroundColor(selectedColor); chatListView.setCacheColorHint(selectedColor); } else { chatListView.setCacheColorHint(0); try { if (selectedBackground == 1000001) { ((SizeNotifierRelativeLayout) contentView).setBackgroundImage(R.drawable.background_hd); } else { File toFile = new File(ApplicationLoader.applicationContext.getFilesDir(), "wallpaper.jpg"); if (toFile.exists()) { if (ApplicationLoader.cachedWallpaper != null) { ((SizeNotifierRelativeLayout) contentView) .setBackgroundImage(ApplicationLoader.cachedWallpaper); } else { Drawable drawable = Drawable.createFromPath(toFile.getAbsolutePath()); if (drawable != null) { ((SizeNotifierRelativeLayout) contentView).setBackgroundImage(drawable); ApplicationLoader.cachedWallpaper = drawable; } else { contentView.setBackgroundColor(-2693905); chatListView.setCacheColorHint(-2693905); } } isCustomTheme = true; } else { ((SizeNotifierRelativeLayout) contentView).setBackgroundImage(R.drawable.background_hd); } } } catch (Exception e) { contentView.setBackgroundColor(-2693905); chatListView.setCacheColorHint(-2693905); FileLog.e("tmessages", e); } } if (currentEncryptedChat != null) { emptyView.setVisibility(View.GONE); View secretChatPlaceholder = contentView.findViewById(R.id.secret_placeholder); secretChatPlaceholder.setVisibility(View.VISIBLE); if (isCustomTheme) { secretChatPlaceholder.setBackgroundResource(R.drawable.system_black); } else { secretChatPlaceholder.setBackgroundResource(R.drawable.system_blue); } secretViewStatusTextView = (TextView) contentView.findViewById(R.id.invite_text); secretChatPlaceholder.setPadding(AndroidUtilities.dp(16), AndroidUtilities.dp(12), AndroidUtilities.dp(16), AndroidUtilities.dp(12)); View v = contentView.findViewById(R.id.secret_placeholder); v.setVisibility(View.VISIBLE); if (currentEncryptedChat.admin_id == UserConfig.getClientUserId()) { if (currentUser.first_name.length() > 0) { secretViewStatusTextView .setText(LocaleController.formatString("EncryptedPlaceholderTitleOutgoing", R.string.EncryptedPlaceholderTitleOutgoing, currentUser.first_name)); } else { secretViewStatusTextView .setText(LocaleController.formatString("EncryptedPlaceholderTitleOutgoing", R.string.EncryptedPlaceholderTitleOutgoing, currentUser.last_name)); } } else { if (currentUser.first_name.length() > 0) { secretViewStatusTextView .setText(LocaleController.formatString("EncryptedPlaceholderTitleIncoming", R.string.EncryptedPlaceholderTitleIncoming, currentUser.first_name)); } else { secretViewStatusTextView .setText(LocaleController.formatString("EncryptedPlaceholderTitleIncoming", R.string.EncryptedPlaceholderTitleIncoming, currentUser.last_name)); } } updateSecretStatus(); } if (isCustomTheme) { progressViewInner.setBackgroundResource(R.drawable.system_loader2); emptyView.setBackgroundResource(R.drawable.system_black); } else { progressViewInner.setBackgroundResource(R.drawable.system_loader1); emptyView.setBackgroundResource(R.drawable.system_blue); } emptyView.setPadding(AndroidUtilities.dp(7), AndroidUtilities.dp(1), AndroidUtilities.dp(7), AndroidUtilities.dp(1)); if (currentUser != null && (currentUser.id / 1000 == 333 || currentUser.id % 1000 == 0)) { emptyView.setText(LocaleController.getString("GotAQuestion", R.string.GotAQuestion)); } chatListView.setOnItemLongClickListener(onItemLongClickListener); chatListView.setOnItemClickListener(onItemClickListener); final Rect scrollRect = new Rect(); chatListView.setOnInterceptTouchEventListener(new LayoutListView.OnInterceptTouchEventListener() { @Override public boolean onInterceptTouchEvent(MotionEvent event) { if (actionBarLayer.isActionModeShowed()) { return false; } if (event.getAction() == MotionEvent.ACTION_DOWN) { int x = (int) event.getX(); int y = (int) event.getY(); int count = chatListView.getChildCount(); Rect rect = new Rect(); for (int a = 0; a < count; a++) { View view = chatListView.getChildAt(a); int top = view.getTop(); int bottom = view.getBottom(); view.getLocalVisibleRect(rect); if (top > y || bottom < y) { continue; } if (!(view instanceof ChatMediaCell)) { break; } final ChatMediaCell cell = (ChatMediaCell) view; final MessageObject messageObject = cell.getMessageObject(); if (messageObject == null || !messageObject.isSecretPhoto() || !cell.getPhotoImage().isInsideImage(x, y - top)) { break; } File file = FileLoader.getPathToMessage(messageObject.messageOwner); if (!file.exists()) { break; } startX = x; startY = y; chatListView.setOnItemClickListener(null); openSecretPhotoRunnable = new Runnable() { @Override public void run() { if (openSecretPhotoRunnable == null) { return; } chatListView.requestDisallowInterceptTouchEvent(true); chatListView.setOnItemLongClickListener(null); chatListView.setLongClickable(false); openSecretPhotoRunnable = null; if (sendSecretMessageRead(messageObject)) { cell.invalidate(); } SecretPhotoViewer.getInstance().setParentActivity(getParentActivity()); SecretPhotoViewer.getInstance().openPhoto(messageObject); } }; AndroidUtilities.RunOnUIThread(openSecretPhotoRunnable, 100); return true; } } return false; } }); chatListView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { if (openSecretPhotoRunnable != null || SecretPhotoViewer.getInstance().isVisible()) { if (event.getAction() == MotionEvent.ACTION_UP || event.getAction() == MotionEvent.ACTION_CANCEL || event.getAction() == MotionEvent.ACTION_POINTER_UP) { AndroidUtilities.RunOnUIThread(new Runnable() { @Override public void run() { chatListView.setOnItemClickListener(onItemClickListener); } }, 150); if (openSecretPhotoRunnable != null) { AndroidUtilities.CancelRunOnUIThread(openSecretPhotoRunnable); openSecretPhotoRunnable = null; try { Toast.makeText(v.getContext(), LocaleController.getString("PhotoTip", R.string.PhotoTip), Toast.LENGTH_SHORT).show(); } catch (Exception e) { FileLog.e("tmessages", e); } } else { if (SecretPhotoViewer.getInstance().isVisible()) { AndroidUtilities.RunOnUIThread(new Runnable() { @Override public void run() { chatListView.setOnItemLongClickListener(onItemLongClickListener); chatListView.setLongClickable(true); } }); SecretPhotoViewer.getInstance().closePhoto(); } } } else if (event.getAction() != MotionEvent.ACTION_DOWN) { if (SecretPhotoViewer.getInstance().isVisible()) { return true; } else if (openSecretPhotoRunnable != null) { if (event.getAction() == MotionEvent.ACTION_MOVE) { if (Math.hypot(startX - event.getX(), startY - event.getY()) > AndroidUtilities .dp(5)) { AndroidUtilities.CancelRunOnUIThread(openSecretPhotoRunnable); openSecretPhotoRunnable = null; } } else { AndroidUtilities.CancelRunOnUIThread(openSecretPhotoRunnable); openSecretPhotoRunnable = null; } } } } return false; } }); chatListView.setOnScrollListener(new AbsListView.OnScrollListener() { @Override public void onScrollStateChanged(AbsListView absListView, int i) { } @Override public void onScroll(AbsListView absListView, int firstVisibleItem, int visibleItemCount, int totalItemCount) { if (visibleItemCount > 0) { if (firstVisibleItem <= 10) { if (!endReached && !loading) { if (messagesByDays.size() != 0) { MessagesController.getInstance().loadMessages(dialog_id, 20, maxMessageId, !cacheEndReaced, minDate, classGuid, false, false, null); } else { MessagesController.getInstance().loadMessages(dialog_id, 20, 0, !cacheEndReaced, minDate, classGuid, false, false, null); } loading = true; } } if (firstVisibleItem + visibleItemCount >= totalItemCount - 6) { if (!unread_end_reached && !loadingForward) { MessagesController.getInstance().loadMessages(dialog_id, 20, minMessageId, true, maxDate, classGuid, false, true, null); loadingForward = true; } } if (firstVisibleItem + visibleItemCount == totalItemCount && unread_end_reached) { showPagedownButton(false, true); } } for (int a = 0; a < visibleItemCount; a++) { View view = absListView.getChildAt(a); if (view instanceof ChatMessageCell) { ChatMessageCell messageCell = (ChatMessageCell) view; messageCell.getLocalVisibleRect(scrollRect); messageCell.setVisiblePart(scrollRect.top, scrollRect.bottom - scrollRect.top); } } } }); bottomOverlayChatText = (TextView) fragmentView.findViewById(R.id.bottom_overlay_chat_text); TextView textView = (TextView) fragmentView.findViewById(R.id.secret_title); textView.setText( LocaleController.getString("EncryptedDescriptionTitle", R.string.EncryptedDescriptionTitle)); textView = (TextView) fragmentView.findViewById(R.id.secret_description1); textView.setText(LocaleController.getString("EncryptedDescription1", R.string.EncryptedDescription1)); textView = (TextView) fragmentView.findViewById(R.id.secret_description2); textView.setText(LocaleController.getString("EncryptedDescription2", R.string.EncryptedDescription2)); textView = (TextView) fragmentView.findViewById(R.id.secret_description3); textView.setText(LocaleController.getString("EncryptedDescription3", R.string.EncryptedDescription3)); textView = (TextView) fragmentView.findViewById(R.id.secret_description4); textView.setText(LocaleController.getString("EncryptedDescription4", R.string.EncryptedDescription4)); if (loading && messages.isEmpty()) { progressView.setVisibility(View.VISIBLE); chatListView.setEmptyView(null); } else { progressView.setVisibility(View.GONE); chatListView.setEmptyView(emptyViewContainer); } pagedownButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { scrollToLastMessage(); } }); bottomOverlayChat.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (getParentActivity() == null) { return; } AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setTitle(LocaleController.getString("AppName", R.string.AppName)); if (currentUser != null && userBlocked) { builder.setMessage(LocaleController.getString("AreYouSureUnblockContact", R.string.AreYouSureUnblockContact)); builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { MessagesController.getInstance().unblockUser(currentUser.id); } }); } else { builder.setMessage(LocaleController.getString("AreYouSureDeleteThisChat", R.string.AreYouSureDeleteThisChat)); builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { MessagesController.getInstance().deleteDialog(dialog_id, 0, false); finishFragment(); } }); } builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); showAlertDialog(builder); } }); updateBottomOverlay(); chatActivityEnterView.setContainerView(getParentActivity(), fragmentView); } else { ViewGroup parent = (ViewGroup) fragmentView.getParent(); if (parent != null) { parent.removeView(fragmentView); } } return fragmentView; }
From source file:com.zertinteractive.wallpaper.MainActivity.java
@SuppressWarnings("NewApi") private android.animation.Animator animateRevealColorFromCoordinates(ViewGroup viewRoot, @ColorRes int color, int x, int y) { float finalRadius = (float) Math.hypot(viewRoot.getWidth(), viewRoot.getHeight()); android.animation.Animator anim = ViewAnimationUtils.createCircularReveal(viewRoot, x, y, 0, finalRadius); viewRoot.setBackgroundColor(ContextCompat.getColor(this, color)); anim.setDuration(getResources().getInteger(R.integer.anim_duration_long)); anim.setInterpolator(new AccelerateDecelerateInterpolator()); anim.start();/*from w w w . j a va 2 s . c om*/ return anim; }
From source file:org.nd4j.linalg.util.BigDecimalMath.java
/** * The inverse hyperbolic sine./* ww w .j a v a 2 s . co m*/ * * @param x The argument. * @return The arcsinh(x) . */ static public BigDecimal asinh(final BigDecimal x) { if (x.compareTo(BigDecimal.ZERO) == 0) { return BigDecimal.ZERO; } else { BigDecimal xhighpr = scalePrec(x, 2); /* arcsinh(x) = log(x+hypot(1,x)) */ BigDecimal logx = log(hypot(1, xhighpr).add(xhighpr)); /* The absolute error in arcsinh x is err(x)/sqrt(1+x^2) */ double xDbl = x.doubleValue(); double eps = 0.5 * x.ulp().doubleValue() / Math.hypot(1., xDbl); MathContext mc = new MathContext(err2prec(logx.doubleValue(), eps)); return logx.round(mc); } }
From source file:org.eclipse.january.dataset.Maths.java
/** * @param a side of right-angled triangle * @param b side of right-angled triangle * @param o output can be null - in which case, a new dataset is created * @return hypotenuse of right-angled triangle: sqrt(a^2 + a^2) *///from ww w. j a v a 2s . c om public static Dataset hypot(final Object a, final Object b, final Dataset o) { final Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a); final Dataset db = b instanceof Dataset ? (Dataset) b : DatasetFactory.createFromObject(b); final BroadcastIterator it = BroadcastIterator.createIterator(da, db, o, true); final Dataset result = it.getOutput(); final int is = result.getElementsPerItem(); final int dt = result.getDType(); switch (dt) { case Dataset.BOOL: boolean[] bdata = ((BooleanDataset) result).getData(); while (it.hasNext()) { bdata[it.oIndex] = Math.hypot(it.aDouble, it.bDouble) != 0; } break; case Dataset.INT8: byte[] i8data = ((ByteDataset) result).getData(); while (it.hasNext()) { i8data[it.oIndex] = (byte) toLong(Math.hypot(it.aDouble, it.bDouble)); } break; case Dataset.INT16: short[] i16data = ((ShortDataset) result).getData(); while (it.hasNext()) { i16data[it.oIndex] = (short) toLong(Math.hypot(it.aDouble, it.bDouble)); } break; case Dataset.INT32: int[] i32data = ((IntegerDataset) result).getData(); while (it.hasNext()) { i32data[it.oIndex] = (int) toLong(Math.hypot(it.aDouble, it.bDouble)); } break; case Dataset.INT64: long[] i64data = ((LongDataset) result).getData(); while (it.hasNext()) { i64data[it.oIndex] = toLong(Math.hypot(it.aDouble, it.bDouble)); } break; case Dataset.FLOAT32: float[] f32data = ((FloatDataset) result).getData(); while (it.hasNext()) { f32data[it.oIndex] = (float) Math.hypot(it.aDouble, it.bDouble); } break; case Dataset.FLOAT64: double[] f64data = ((DoubleDataset) result).getData(); while (it.hasNext()) { f64data[it.oIndex] = Math.hypot(it.aDouble, it.bDouble); } break; case Dataset.ARRAYINT8: byte[] ai8data = ((CompoundByteDataset) result).getData(); if (is == 1) { while (it.hasNext()) { ai8data[it.oIndex] = (byte) toLong(Math.hypot(it.aDouble, it.bDouble)); } } else if (da.getElementsPerItem() == 1) { while (it.hasNext()) { ai8data[it.oIndex] = (byte) toLong(Math.hypot(it.aDouble, it.bDouble)); for (int j = 1; j < is; j++) { ai8data[it.oIndex + j] = (byte) toLong(Math.hypot(it.aDouble, db.getElementDoubleAbs(it.bIndex + j))); } } } else if (db.getElementsPerItem() == 1) { while (it.hasNext()) { ai8data[it.oIndex] = (byte) toLong(Math.hypot(it.aDouble, it.bDouble)); for (int j = 1; j < is; j++) { ai8data[it.oIndex + j] = (byte) toLong(Math.hypot(da.getElementDoubleAbs(it.aIndex + j), it.bDouble)); } } } else { while (it.hasNext()) { ai8data[it.oIndex] = (byte) toLong(Math.hypot(it.aDouble, it.bDouble)); for (int j = 1; j < is; j++) { ai8data[it.oIndex + j] = (byte) toLong(Math.hypot(da.getElementDoubleAbs(it.aIndex + j), db.getElementDoubleAbs(it.bIndex + j))); } } } break; case Dataset.ARRAYINT16: short[] ai16data = ((CompoundShortDataset) result).getData(); if (is == 1) { while (it.hasNext()) { ai16data[it.oIndex] = (short) toLong(Math.hypot(it.aDouble, it.bDouble)); } } else if (da.getElementsPerItem() == 1) { while (it.hasNext()) { ai16data[it.oIndex] = (short) toLong(Math.hypot(it.aDouble, it.bDouble)); for (int j = 1; j < is; j++) { ai16data[it.oIndex + j] = (short) toLong( Math.hypot(it.aDouble, db.getElementDoubleAbs(it.bIndex + j))); } } } else if (db.getElementsPerItem() == 1) { while (it.hasNext()) { ai16data[it.oIndex] = (short) toLong(Math.hypot(it.aDouble, it.bDouble)); for (int j = 1; j < is; j++) { ai16data[it.oIndex + j] = (short) toLong( Math.hypot(da.getElementDoubleAbs(it.aIndex + j), it.bDouble)); } } } else { while (it.hasNext()) { ai16data[it.oIndex] = (short) toLong(Math.hypot(it.aDouble, it.bDouble)); for (int j = 1; j < is; j++) { ai16data[it.oIndex + j] = (short) toLong(Math.hypot(da.getElementDoubleAbs(it.aIndex + j), db.getElementDoubleAbs(it.bIndex + j))); } } } break; case Dataset.ARRAYINT32: int[] ai32data = ((CompoundIntegerDataset) result).getData(); if (is == 1) { while (it.hasNext()) { ai32data[it.oIndex] = (int) toLong(Math.hypot(it.aDouble, it.bDouble)); } } else if (da.getElementsPerItem() == 1) { while (it.hasNext()) { ai32data[it.oIndex] = (int) toLong(Math.hypot(it.aDouble, it.bDouble)); for (int j = 1; j < is; j++) { ai32data[it.oIndex + j] = (int) toLong(Math.hypot(it.aDouble, db.getElementDoubleAbs(it.bIndex + j))); } } } else if (db.getElementsPerItem() == 1) { while (it.hasNext()) { ai32data[it.oIndex] = (int) toLong(Math.hypot(it.aDouble, it.bDouble)); for (int j = 1; j < is; j++) { ai32data[it.oIndex + j] = (int) toLong(Math.hypot(da.getElementDoubleAbs(it.aIndex + j), it.bDouble)); } } } else { while (it.hasNext()) { ai32data[it.oIndex] = (int) toLong(Math.hypot(it.aDouble, it.bDouble)); for (int j = 1; j < is; j++) { ai32data[it.oIndex + j] = (int) toLong(Math.hypot(da.getElementDoubleAbs(it.aIndex + j), db.getElementDoubleAbs(it.bIndex + j))); } } } break; case Dataset.ARRAYINT64: long[] ai64data = ((CompoundLongDataset) result).getData(); if (is == 1) { while (it.hasNext()) { ai64data[it.oIndex] = toLong(Math.hypot(it.aDouble, it.bDouble)); } } else if (da.getElementsPerItem() == 1) { while (it.hasNext()) { ai64data[it.oIndex] = toLong(Math.hypot(it.aDouble, it.bDouble)); for (int j = 1; j < is; j++) { ai64data[it.oIndex + j] = toLong( Math.hypot(it.aDouble, db.getElementDoubleAbs(it.bIndex + j))); } } } else if (db.getElementsPerItem() == 1) { while (it.hasNext()) { ai64data[it.oIndex] = toLong(Math.hypot(it.aDouble, it.bDouble)); for (int j = 1; j < is; j++) { ai64data[it.oIndex + j] = toLong( Math.hypot(da.getElementDoubleAbs(it.aIndex + j), it.bDouble)); } } } else { while (it.hasNext()) { ai64data[it.oIndex] = toLong(Math.hypot(it.aDouble, it.bDouble)); for (int j = 1; j < is; j++) { ai64data[it.oIndex + j] = toLong(Math.hypot(da.getElementDoubleAbs(it.aIndex + j), db.getElementDoubleAbs(it.bIndex + j))); } } } break; case Dataset.ARRAYFLOAT32: float[] a32data = ((CompoundFloatDataset) result).getData(); if (is == 1) { while (it.hasNext()) { a32data[it.oIndex] = (float) Math.hypot(it.aDouble, it.bDouble); } } else if (da.getElementsPerItem() == 1) { while (it.hasNext()) { a32data[it.oIndex] = (float) Math.hypot(it.aDouble, it.bDouble); for (int j = 1; j < is; j++) { a32data[it.oIndex + j] = (float) Math.hypot(it.aDouble, db.getElementDoubleAbs(it.bIndex + j)); } } } else if (db.getElementsPerItem() == 1) { while (it.hasNext()) { a32data[it.oIndex] = (float) Math.hypot(it.aDouble, it.bDouble); for (int j = 1; j < is; j++) { a32data[it.oIndex + j] = (float) Math.hypot(da.getElementDoubleAbs(it.aIndex + j), it.bDouble); } } } else { while (it.hasNext()) { a32data[it.oIndex] = (float) Math.hypot(it.aDouble, it.bDouble); for (int j = 1; j < is; j++) { a32data[it.oIndex + j] = (float) Math.hypot(da.getElementDoubleAbs(it.aIndex + j), db.getElementDoubleAbs(it.bIndex + j)); } } } break; case Dataset.ARRAYFLOAT64: double[] a64data = ((CompoundDoubleDataset) result).getData(); if (is == 1) { while (it.hasNext()) { a64data[it.oIndex] = Math.hypot(it.aDouble, it.bDouble); } } else if (da.getElementsPerItem() == 1) { while (it.hasNext()) { a64data[it.oIndex] = Math.hypot(it.aDouble, it.bDouble); for (int j = 1; j < is; j++) { a64data[it.oIndex + j] = Math.hypot(it.aDouble, db.getElementDoubleAbs(it.bIndex + j)); } } } else if (db.getElementsPerItem() == 1) { while (it.hasNext()) { a64data[it.oIndex] = Math.hypot(it.aDouble, it.bDouble); for (int j = 1; j < is; j++) { a64data[it.oIndex + j] = Math.hypot(da.getElementDoubleAbs(it.aIndex + j), it.bDouble); } } } else { while (it.hasNext()) { a64data[it.oIndex] = Math.hypot(it.aDouble, it.bDouble); for (int j = 1; j < is; j++) { a64data[it.oIndex + j] = Math.hypot(da.getElementDoubleAbs(it.aIndex + j), db.getElementDoubleAbs(it.bIndex + j)); } } } break; default: throw new UnsupportedOperationException("hypot does not support this dataset type"); } addFunctionName(da, db, result, "hypot"); return result; }