List of usage examples for android.graphics Rect Rect
public Rect(int left, int top, int right, int bottom)
From source file:com.bizcom.vc.widget.cus.SubsamplingScaleImageView.java
/** * Converts source rectangle from tile, which treats the image file as if it * were in the correct orientation already, to the rectangle of the image * that needs to be loaded.//w ww.j a va 2 s . co m */ private Rect fileSRect(Rect sRect) { if (getRequiredRotation() == 0) { return sRect; } else if (getRequiredRotation() == 90) { return new Rect(sRect.top, sHeight - sRect.right, sRect.bottom, sHeight - sRect.left); } else if (getRequiredRotation() == 180) { return new Rect(sWidth - sRect.right, sHeight - sRect.bottom, sWidth - sRect.left, sHeight - sRect.top); } else { return new Rect(sWidth - sRect.bottom, sRect.left, sWidth - sRect.top, sRect.right); } }
From source file:android.support.v7.widget.RecyclerView.java
/** * Wrapper around layoutChildren() that handles animating changes caused by layout. * Animations work on the assumption that there are five different kinds of items * in play://from w w w . j a v a2 s . c o m * PERSISTENT: items are visible before and after layout * REMOVED: items were visible before layout and were removed by the app * ADDED: items did not exist before layout and were added by the app * DISAPPEARING: items exist in the data set before/after, but changed from * visible to non-visible in the process of layout (they were moved off * screen as a side-effect of other changes) * APPEARING: items exist in the data set before/after, but changed from * non-visible to visible in the process of layout (they were moved on * screen as a side-effect of other changes) * The overall approach figures out what items exist before/after layout and * infers one of the five above states for each of the items. Then the animations * are set up accordingly: * PERSISTENT views are moved ({@link ItemAnimator#animateMove(ViewHolder, int, int, int, int)}) * REMOVED views are removed ({@link ItemAnimator#animateRemove(ViewHolder)}) * ADDED views are added ({@link ItemAnimator#animateAdd(ViewHolder)}) * DISAPPEARING views are moved off screen * APPEARING views are moved on screen */ void dispatchLayout() { if (mAdapter == null) { Log.e(TAG, "No adapter attached; skipping layout"); return; } eatRequestLayout(); // simple animations are a subset of advanced animations (which will cause a // prelayout step) boolean animateChangesSimple = mItemAnimator != null && mItemsAddedOrRemoved && !mItemsChanged; final boolean animateChangesAdvanced = ENABLE_PREDICTIVE_ANIMATIONS && animateChangesSimple && predictiveItemAnimationsEnabled(); mItemsAddedOrRemoved = mItemsChanged = false; ArrayMap<View, Rect> appearingViewInitialBounds = null; mState.mInPreLayout = animateChangesAdvanced; mState.mItemCount = mAdapter.getItemCount(); if (animateChangesSimple) { // Step 0: Find out where all non-removed items are, pre-layout mState.mPreLayoutHolderMap.clear(); mState.mPostLayoutHolderMap.clear(); int count = getChildCount(); for (int i = 0; i < count; ++i) { final ViewHolder holder = getChildViewHolderInt(getChildAt(i)); final View view = holder.itemView; mState.mPreLayoutHolderMap.put(holder, new ItemHolderInfo(holder, view.getLeft(), view.getTop(), view.getRight(), view.getBottom(), holder.mPosition)); } } if (animateChangesAdvanced) { // Step 1: run prelayout: This will use the old positions of items. The layout manager // is expected to layout everything, even removed items (though not to add removed // items back to the container). This gives the pre-layout position of APPEARING views // which come into existence as part of the real layout. mInPreLayout = true; final boolean didStructureChange = mState.mStructureChanged; mState.mStructureChanged = false; // temporarily disable flag because we are asking for previous layout mLayout.onLayoutChildren(mRecycler, mState); mState.mStructureChanged = didStructureChange; mInPreLayout = false; appearingViewInitialBounds = new ArrayMap<View, Rect>(); for (int i = 0; i < getChildCount(); ++i) { boolean found = false; View child = getChildAt(i); for (int j = 0; j < mState.mPreLayoutHolderMap.size(); ++j) { ViewHolder holder = mState.mPreLayoutHolderMap.keyAt(j); if (holder.itemView == child) { found = true; continue; } } if (!found) { appearingViewInitialBounds.put(child, new Rect(child.getLeft(), child.getTop(), child.getRight(), child.getBottom())); } } } clearOldPositions(); dispatchLayoutUpdates(); mState.mItemCount = mAdapter.getItemCount(); // Step 2: Run layout mState.mInPreLayout = false; mLayout.onLayoutChildren(mRecycler, mState); mState.mStructureChanged = false; mPendingSavedState = null; // onLayoutChildren may have caused client code to disable item animations; re-check animateChangesSimple = animateChangesSimple && mItemAnimator != null; if (animateChangesSimple) { // Step 3: Find out where things are now, post-layout int count = getChildCount(); for (int i = 0; i < count; ++i) { ViewHolder holder = getChildViewHolderInt(getChildAt(i)); final View view = holder.itemView; mState.mPostLayoutHolderMap.put(holder, new ItemHolderInfo(holder, view.getLeft(), view.getTop(), view.getRight(), view.getBottom(), holder.mPosition)); } // Step 4: Animate DISAPPEARING and REMOVED items int preLayoutCount = mState.mPreLayoutHolderMap.size(); for (int i = preLayoutCount - 1; i >= 0; i--) { ViewHolder itemHolder = mState.mPreLayoutHolderMap.keyAt(i); if (!mState.mPostLayoutHolderMap.containsKey(itemHolder)) { ItemHolderInfo disappearingItem = mState.mPreLayoutHolderMap.valueAt(i); mState.mPreLayoutHolderMap.removeAt(i); View disappearingItemView = disappearingItem.holder.itemView; removeDetachedView(disappearingItemView, false); mRecycler.unscrapView(disappearingItem.holder); animateDisappearance(disappearingItem); } } // Step 5: Animate APPEARING and ADDED items int postLayoutCount = mState.mPostLayoutHolderMap.size(); if (postLayoutCount > 0) { for (int i = postLayoutCount - 1; i >= 0; i--) { ViewHolder itemHolder = mState.mPostLayoutHolderMap.keyAt(i); ItemHolderInfo info = mState.mPostLayoutHolderMap.valueAt(i); if ((mState.mPreLayoutHolderMap.isEmpty() || !mState.mPreLayoutHolderMap.containsKey(itemHolder))) { mState.mPostLayoutHolderMap.removeAt(i); Rect initialBounds = (appearingViewInitialBounds != null) ? appearingViewInitialBounds.get(itemHolder.itemView) : null; animateAppearance(itemHolder, initialBounds, info.left, info.top); } } } // Step 6: Animate PERSISTENT items count = mState.mPostLayoutHolderMap.size(); for (int i = 0; i < count; ++i) { ViewHolder postHolder = mState.mPostLayoutHolderMap.keyAt(i); ItemHolderInfo postInfo = mState.mPostLayoutHolderMap.valueAt(i); ItemHolderInfo preInfo = mState.mPreLayoutHolderMap.get(postHolder); if (preInfo != null && postInfo != null) { if (preInfo.left != postInfo.left || preInfo.top != postInfo.top) { postHolder.setIsRecyclable(false); if (DEBUG) { Log.d(TAG, "PERSISTENT: " + postHolder + " with view " + postHolder.itemView); } if (mItemAnimator.animateMove(postHolder, preInfo.left, preInfo.top, postInfo.left, postInfo.top)) { postAnimationRunner(); } } } } } resumeRequestLayout(false); mLayout.removeAndRecycleScrapInt(mRecycler, !animateChangesAdvanced); mState.mPreviousLayoutItemCount = mState.mItemCount; mState.mDeletedInvisibleItemCountSincePreviousLayout = 0; }
From source file:com.bizcom.vc.widget.cus.SubsamplingScaleImageView.java
/** * Float to int rect conversion./*from ww w .j a va2s . co m*/ */ private Rect convertRect(RectF rect) { return new Rect((int) rect.left, (int) rect.top, (int) rect.right, (int) rect.bottom); }
From source file:android.webkit.cts.WebViewTest.java
public void testRequestChildRectangleOnScreen() throws Throwable { if (!NullWebViewUtils.isWebViewAvailable()) { return;/*from ww w . j av a2 s. c o m*/ } DisplayMetrics metrics = mOnUiThread.getDisplayMetrics(); final int dimension = 2 * Math.max(metrics.widthPixels, metrics.heightPixels); String p = "<p style=\"height:" + dimension + "px;width:" + dimension + "px\"> </p>"; mOnUiThread.loadDataAndWaitForCompletion("<html><body>" + p + "</body></html>", "text/html", null); new PollingCheck() { @Override protected boolean check() { return mOnUiThread.getContentHeight() >= dimension; } }.run(); int origX = mOnUiThread.getScrollX(); int origY = mOnUiThread.getScrollY(); int half = dimension / 2; Rect rect = new Rect(half, half, half + 1, half + 1); assertTrue(mOnUiThread.requestChildRectangleOnScreen(mWebView, rect, true)); assertTrue(mOnUiThread.getScrollX() > origX); assertTrue(mOnUiThread.getScrollY() > origY); }
From source file:android.support.v7.widget.RecyclerViewEx.java
/** * Wrapper around layoutChildren() that handles animating changes caused by layout. * Animations work on the assumption that there are five different kinds of items * in play:/*w w w . j av a 2 s . c o m*/ * PERSISTENT: items are visible before and after layout * REMOVED: items were visible before layout and were removed by the app * ADDED: items did not exist before layout and were added by the app * DISAPPEARING: items exist in the data set before/after, but changed from * visible to non-visible in the process of layout (they were moved off * screen as a side-effect of other changes) * APPEARING: items exist in the data set before/after, but changed from * non-visible to visible in the process of layout (they were moved on * screen as a side-effect of other changes) * The overall approach figures out what items exist before/after layout and * infers one of the five above states for each of the items. Then the animations * are set up accordingly: * PERSISTENT views are moved ({@link android.support.v7.widget.RecyclerViewEx.ItemAnimator#animateMove(android.support.v7.widget.RecyclerViewEx.ViewHolder, int, int, int, int)}) * REMOVED views are removed ({@link android.support.v7.widget.RecyclerViewEx.ItemAnimator#animateRemove(android.support.v7.widget.RecyclerViewEx.ViewHolder)}) * ADDED views are added ({@link android.support.v7.widget.RecyclerViewEx.ItemAnimator#animateAdd(android.support.v7.widget.RecyclerViewEx.ViewHolder)}) * DISAPPEARING views are moved off screen * APPEARING views are moved on screen */ void dispatchLayout() { if (mAdapter == null) { Log.e(TAG, "No adapter attached; skipping layout"); return; } mDisappearingViewsInLayoutPass.clear(); eatRequestLayout(); mRunningLayoutOrScroll = true; processAdapterUpdatesAndSetAnimationFlags(); mState.mOldChangedHolders = mState.mRunSimpleAnimations && mItemsChanged && supportsChangeAnimations() ? new ArrayMap<Long, ViewHolder>() : null; mItemsAddedOrRemoved = mItemsChanged = false; ArrayMap<View, Rect> appearingViewInitialBounds = null; mState.mInPreLayout = mState.mRunPredictiveAnimations; mState.mItemCount = mAdapter.getItemCount(); if (mState.mRunSimpleAnimations) { // Step 0: Find out where all non-removed items are, pre-layout mState.mPreLayoutHolderMap.clear(); mState.mPostLayoutHolderMap.clear(); int count = mChildHelper.getChildCount(); for (int i = 0; i < count; ++i) { final ViewHolder holder = getChildViewHolderInt(mChildHelper.getChildAt(i)); if (holder.shouldIgnore() || (holder.isInvalid() && !mAdapter.hasStableIds())) { continue; } final View view = holder.itemView; mState.mPreLayoutHolderMap.put(holder, new ItemHolderInfo(holder, view.getLeft(), view.getTop(), view.getRight(), view.getBottom())); } } if (mState.mRunPredictiveAnimations) { // Step 1: run prelayout: This will use the old positions of items. The layout manager // is expected to layout everything, even removed items (though not to add removed // items back to the container). This gives the pre-layout position of APPEARING views // which come into existence as part of the real layout. // Save old positions so that LayoutManager can run its mapping logic. saveOldPositions(); // processAdapterUpdatesAndSetAnimationFlags already run pre-layout animations. if (mState.mOldChangedHolders != null) { int count = mChildHelper.getChildCount(); for (int i = 0; i < count; ++i) { final ViewHolder holder = getChildViewHolderInt(mChildHelper.getChildAt(i)); if (holder.isChanged() && !holder.isRemoved() && !holder.shouldIgnore()) { long key = getChangedHolderKey(holder); mState.mOldChangedHolders.put(key, holder); mState.mPreLayoutHolderMap.remove(holder); } } } final boolean didStructureChange = mState.mStructureChanged; mState.mStructureChanged = false; // temporarily disable flag because we are asking for previous layout mLayout.onLayoutChildren(mRecycler, mState); mState.mStructureChanged = didStructureChange; appearingViewInitialBounds = new ArrayMap<View, Rect>(); for (int i = 0; i < mChildHelper.getChildCount(); ++i) { boolean found = false; View child = mChildHelper.getChildAt(i); if (getChildViewHolderInt(child).shouldIgnore()) { continue; } for (int j = 0; j < mState.mPreLayoutHolderMap.size(); ++j) { ViewHolder holder = mState.mPreLayoutHolderMap.keyAt(j); if (holder.itemView == child) { found = true; break; } } if (!found) { appearingViewInitialBounds.put(child, new Rect(child.getLeft(), child.getTop(), child.getRight(), child.getBottom())); } } // we don't process disappearing list because they may re-appear in post layout pass. clearOldPositions(); mAdapterHelper.consumePostponedUpdates(); } else { clearOldPositions(); // in case pre layout did run but we decided not to run predictive animations. mAdapterHelper.consumeUpdatesInOnePass(); if (mState.mOldChangedHolders != null) { int count = mChildHelper.getChildCount(); for (int i = 0; i < count; ++i) { final ViewHolder holder = getChildViewHolderInt(mChildHelper.getChildAt(i)); if (holder.isChanged() && !holder.isRemoved() && !holder.shouldIgnore()) { long key = getChangedHolderKey(holder); mState.mOldChangedHolders.put(key, holder); mState.mPreLayoutHolderMap.remove(holder); } } } } mState.mItemCount = mAdapter.getItemCount(); mState.mDeletedInvisibleItemCountSincePreviousLayout = 0; // Step 2: Run layout mState.mInPreLayout = false; mLayout.onLayoutChildren(mRecycler, mState); mState.mStructureChanged = false; mPendingSavedState = null; // onLayoutChildren may have caused client code to disable item animations; re-check mState.mRunSimpleAnimations = mState.mRunSimpleAnimations && mItemAnimator != null; if (mState.mRunSimpleAnimations) { // Step 3: Find out where things are now, post-layout ArrayMap<Long, ViewHolder> newChangedHolders = mState.mOldChangedHolders != null ? new ArrayMap<Long, ViewHolder>() : null; int count = mChildHelper.getChildCount(); for (int i = 0; i < count; ++i) { ViewHolder holder = getChildViewHolderInt(mChildHelper.getChildAt(i)); if (holder.shouldIgnore()) { continue; } final View view = holder.itemView; long key = getChangedHolderKey(holder); if (newChangedHolders != null && mState.mOldChangedHolders.get(key) != null) { newChangedHolders.put(key, holder); } else { mState.mPostLayoutHolderMap.put(holder, new ItemHolderInfo(holder, view.getLeft(), view.getTop(), view.getRight(), view.getBottom())); } } processDisappearingList(appearingViewInitialBounds); // Step 4: Animate DISAPPEARING and REMOVED items int preLayoutCount = mState.mPreLayoutHolderMap.size(); for (int i = preLayoutCount - 1; i >= 0; i--) { ViewHolder itemHolder = mState.mPreLayoutHolderMap.keyAt(i); if (!mState.mPostLayoutHolderMap.containsKey(itemHolder)) { ItemHolderInfo disappearingItem = mState.mPreLayoutHolderMap.valueAt(i); mState.mPreLayoutHolderMap.removeAt(i); View disappearingItemView = disappearingItem.holder.itemView; mRecycler.unscrapView(disappearingItem.holder); animateDisappearance(disappearingItem); } } // Step 5: Animate APPEARING and ADDED items int postLayoutCount = mState.mPostLayoutHolderMap.size(); if (postLayoutCount > 0) { for (int i = postLayoutCount - 1; i >= 0; i--) { ViewHolder itemHolder = mState.mPostLayoutHolderMap.keyAt(i); ItemHolderInfo info = mState.mPostLayoutHolderMap.valueAt(i); if ((mState.mPreLayoutHolderMap.isEmpty() || !mState.mPreLayoutHolderMap.containsKey(itemHolder))) { mState.mPostLayoutHolderMap.removeAt(i); Rect initialBounds = (appearingViewInitialBounds != null) ? appearingViewInitialBounds.get(itemHolder.itemView) : null; animateAppearance(itemHolder, initialBounds, info.left, info.top); } } } // Step 6: Animate PERSISTENT items count = mState.mPostLayoutHolderMap.size(); for (int i = 0; i < count; ++i) { ViewHolder postHolder = mState.mPostLayoutHolderMap.keyAt(i); ItemHolderInfo postInfo = mState.mPostLayoutHolderMap.valueAt(i); ItemHolderInfo preInfo = mState.mPreLayoutHolderMap.get(postHolder); if (preInfo != null && postInfo != null) { if (preInfo.left != postInfo.left || preInfo.top != postInfo.top) { postHolder.setIsRecyclable(false); if (DEBUG) { Log.d(TAG, "PERSISTENT: " + postHolder + " with view " + postHolder.itemView); } if (mItemAnimator.animateMove(postHolder, preInfo.left, preInfo.top, postInfo.left, postInfo.top)) { postAnimationRunner(); } } } } // Step 7: Animate CHANGING items count = mState.mOldChangedHolders != null ? mState.mOldChangedHolders.size() : 0; // traverse reverse in case view gets recycled while we are traversing the list. for (int i = count - 1; i >= 0; i--) { long key = mState.mOldChangedHolders.keyAt(i); ViewHolder oldHolder = mState.mOldChangedHolders.get(key); View oldView = oldHolder.itemView; if (oldHolder.shouldIgnore()) { continue; } // We probably don't need this check anymore since these views are removed from // the list if they are recycled. if (mRecycler.mChangedScrap != null && mRecycler.mChangedScrap.contains(oldHolder)) { animateChange(oldHolder, newChangedHolders.get(key)); } else if (DEBUG) { Log.e(TAG, "cannot find old changed holder in changed scrap :/" + oldHolder); } } } resumeRequestLayout(false); mLayout.removeAndRecycleScrapInt(mRecycler); mState.mPreviousLayoutItemCount = mState.mItemCount; mDataSetHasChangedAfterLayout = false; mState.mRunSimpleAnimations = false; mState.mRunPredictiveAnimations = false; mRunningLayoutOrScroll = false; mLayout.mRequestedSimpleAnimations = false; if (mRecycler.mChangedScrap != null) { mRecycler.mChangedScrap.clear(); } mState.mOldChangedHolders = null; }
From source file:cc.flydev.launcher.Workspace.java
/** * Returns a new bitmap to be used as the object outline, e.g. to visualize the drop location. * Responsibility for the bitmap is transferred to the caller. *//*from w w w . j av a 2s.c o m*/ private Bitmap createDragOutline(Bitmap orig, Canvas canvas, int padding, int w, int h, boolean clipAlpha) { final int outlineColor = getResources().getColor(R.color.outline_color); final Bitmap b = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888); canvas.setBitmap(b); Rect src = new Rect(0, 0, orig.getWidth(), orig.getHeight()); float scaleFactor = Math.min((w - padding) / (float) orig.getWidth(), (h - padding) / (float) orig.getHeight()); int scaledWidth = (int) (scaleFactor * orig.getWidth()); int scaledHeight = (int) (scaleFactor * orig.getHeight()); Rect dst = new Rect(0, 0, scaledWidth, scaledHeight); // center the image dst.offset((w - scaledWidth) / 2, (h - scaledHeight) / 2); canvas.drawBitmap(orig, src, dst, null); mOutlineHelper.applyMediumExpensiveOutlineWithBlur(b, canvas, outlineColor, outlineColor, clipAlpha); canvas.setBitmap(null); return b; }
From source file:cc.flydev.launcher.Workspace.java
public void beginDragShared(View child, DragSource source) { // The drag bitmap follows the touch point around on the screen final Bitmap b = createDragBitmap(child, new Canvas(), DRAG_BITMAP_PADDING); final int bmpWidth = b.getWidth(); final int bmpHeight = b.getHeight(); float scale = mLauncher.getDragLayer().getLocationInDragLayer(child, mTempXY); int dragLayerX = Math.round(mTempXY[0] - (bmpWidth - scale * child.getWidth()) / 2); int dragLayerY = Math.round(mTempXY[1] - (bmpHeight - scale * bmpHeight) / 2 - DRAG_BITMAP_PADDING / 2); LauncherAppState app = LauncherAppState.getInstance(); DeviceProfile grid = app.getDynamicGrid().getDeviceProfile(); Point dragVisualizeOffset = null; Rect dragRect = null;// w w w . j a v a2s .c om if (child instanceof BubbleTextView || child instanceof PagedViewIcon) { int iconSize = grid.iconSizePx; int top = child.getPaddingTop(); int left = (bmpWidth - iconSize) / 2; int right = left + iconSize; int bottom = top + iconSize; dragLayerY += top; // Note: The drag region is used to calculate drag layer offsets, but the // dragVisualizeOffset in addition to the dragRect (the size) to position the outline. dragVisualizeOffset = new Point(-DRAG_BITMAP_PADDING / 2, DRAG_BITMAP_PADDING / 2); dragRect = new Rect(left, top, right, bottom); } else if (child instanceof FolderIcon) { int previewSize = grid.folderIconSizePx; dragRect = new Rect(0, child.getPaddingTop(), child.getWidth(), previewSize); } // Clear the pressed state if necessary if (child instanceof BubbleTextView) { BubbleTextView icon = (BubbleTextView) child; icon.clearPressedOrFocusedBackground(); } mDragController.startDrag(b, dragLayerX, dragLayerY, source, child.getTag(), DragController.DRAG_ACTION_MOVE, dragVisualizeOffset, dragRect, scale); if (child.getParent() instanceof ShortcutAndWidgetContainer) { mDragSourceInternal = (ShortcutAndWidgetContainer) child.getParent(); } b.recycle(); }
From source file:app.umitems.greenclock.widget.sgv.StaggeredGridView.java
/** * Before doing an animation, map the item IDs for the currently visible children to the * {@link Rect} that defines their position on the screen so a translation animation * can be applied to their new layout positions. *//*from w w w .j av a 2 s . c o m*/ private void cacheChildRects() { final int childCount = getChildCount(); mChildRectsForAnimation.clear(); long originalDraggedChildId = -1; if (isDragReorderingSupported()) { originalDraggedChildId = mReorderHelper.getDraggedChildId(); if (mCachedDragViewRect != null && originalDraggedChildId != -1) { // This child was dragged in a reordering operation. Use the cached position // of where the drag event was released as the cached location. mChildRectsForAnimation.put(originalDraggedChildId, new ViewRectPair(mDragView, mCachedDragViewRect)); mCachedDragViewRect = null; } } for (int i = 0; i < childCount; i++) { final View child = getChildAt(i); final LayoutParams lp = (LayoutParams) child.getLayoutParams(); Rect rect; if (lp.id != originalDraggedChildId) { final int childTop = (int) child.getY(); final int childBottom = childTop + child.getHeight(); final int childLeft = (int) child.getX(); final int childRight = childLeft + child.getWidth(); rect = new Rect(childLeft, childTop, childRight, childBottom); mChildRectsForAnimation.put(lp.id /* item id */, new ViewRectPair(child, rect)); } } }
From source file:com.skytree.epubtest.BookViewActivity.java
public void recalcFrames() { this.authorLabel.setVisibility(View.VISIBLE); this.secondaryIndexLabel.setVisibility(View.VISIBLE); int seekWidth = (int) (this.getWidth() * 0.75); int seekLeft = (this.getWidth() - seekWidth) / 2; if (!this.isTablet()) { // for phones - tested with Galaxy S2, Galaxy S3, Galaxy S4 if (this.isPortrait()) { this.setLocation(rotationButton, pxl(20), pyt(15 - 2)); this.setLocation(listButton, pxl(20 + (48 + 5) * 1), pyt(15)); this.setLocation(searchButton, pxr(40 + (48 + 5) * 3), pyt(15)); this.setLocation(fontButton, pxr(40 + (48 + 5) * 2), pyt(15)); this.setFrame(seekBar, seekLeft, pyb(125), seekWidth, ps(36)); int brx = 36 + (44) * 1; int bry = 23; bookmarkRect = new Rect(pxr(brx), pyt(bry), pxr(brx - 40), pyt(bry + 40)); bookmarkedRect = new Rect(pxr(brx), pyt(bry), pxr(brx - 38), pyt(bry + 70)); } else {//from w w w. j a v a 2s . co m int sd = ps(40); this.setLocation(rotationButton, pxl(10), pyt(5 - 2)); this.setLocation(listButton, pxl(10 + (48 + 5) * 1), pyt(5)); this.setLocation(searchButton, pxr(60 + (48 + 5) * 3), pyt(5)); this.setLocation(fontButton, pxr(60 + (48 + 5) * 2), pyt(5)); this.setFrame(seekBar, seekLeft, pyb(108), seekWidth, ps(36)); int brx = 40 + (48 + 12) * 1; int bry = 14; bookmarkRect = new Rect(pxr(brx), pyt(bry), pxr(brx - 40), pyt(bry + 40)); bookmarkedRect = new Rect(pxr(brx), pyt(bry), pxr(brx - 38), pyt(bry + 70)); } } else { // for tables - tested with Galaxy Tap 10.1, Galaxy Note 10.1 if (this.isPortrait()) { int ox = 50; int rx = 100; int oy = 30; this.setLocation(rotationButton, pxl(ox), pyt(oy - 2)); this.setLocation(listButton, pxl(ox + (65) * 1), pyt(oy)); this.setLocation(searchButton, pxr(rx + (65) * 3), pyt(oy)); this.setLocation(fontButton, pxr(rx + (65) * 2), pyt(oy)); this.setFrame(seekBar, seekLeft, pyb(140), seekWidth, ps(45)); int brx = rx - 10 + (44) * 1; int bry = oy + 10; bookmarkRect = new Rect(pxr(brx), pyt(bry), pxr(brx - 50), pyt(bry + 50)); bookmarkedRect = new Rect(pxr(brx), pyt(bry), pxr(brx - 50), pyt(bry + 90)); } else { int sd = ps(40); int ox = 40; int rx = 130; int oy = 20; this.setLocation(rotationButton, pxl(ox), pyt(oy - 2)); this.setLocation(listButton, pxl(ox + (65) * 1), pyt(oy)); this.setLocation(searchButton, pxr(rx + (65) * 3), pyt(oy)); this.setLocation(fontButton, pxr(rx + (65) * 2), pyt(oy)); this.setFrame(seekBar, seekLeft, pyb(123), seekWidth, ps(45)); int brx = rx - 20 + (48 + 12) * 1; int bry = oy + 10; bookmarkRect = new Rect(pxr(brx), pyt(bry), pxr(brx - 40), pyt(bry + 40)); bookmarkedRect = new Rect(pxr(brx), pyt(bry), pxr(brx - 38), pyt(bry + 70)); } } RelativeLayout.LayoutParams sl = (RelativeLayout.LayoutParams) seekBar.getLayoutParams(); this.setFrame(pagingView, sl.leftMargin, sl.topMargin, sl.width, sl.height); this.recalcLabelsLayout(); this.enableControlAfterPagination(); }
From source file:self.philbrown.droidQuery.$.java
/** * For `ImageView`s, this will set the image to the given asset or url. Otherwise, it will set the * background image for the selected views. * @param source asset path, file path (starting with "file://") or URL to image * @param width specifies the output bitmap width * @param height specifies the output bitmap height * @param error if the given source is a file or asset, this receives a droidQuery wrapping the * current context and the {@code Throwable} error. Otherwise, this will receive an * Ajax error.//from w ww. j a v a 2s. c o m * @return this * @see AjaxOptions#error(Function) */ public $ image(final String source, int width, int height, final Function error) { if (source.startsWith("file://")) { try { BitmapFactory.Options opt = new BitmapFactory.Options(); opt.inPreferredConfig = Bitmap.Config.ARGB_8888; if (width >= 0) opt.outWidth = width; if (height >= 0) opt.outHeight = height; Bitmap bitmap = BitmapFactory.decodeFile(source.substring(6), opt); for (View v : views) { if (v instanceof ImageView) { try { ((ImageView) v).setImageBitmap(Bitmap.createBitmap(bitmap)); } catch (Throwable t) { if (error != null) error.invoke($.with(context), t); } } else { v.setBackgroundDrawable(new BitmapDrawable(Bitmap.createBitmap(bitmap))); } } } catch (Throwable t) { if (error != null) { error.invoke($.with(context), t); } } } else if (URLUtil.isValidUrl(source)) { AjaxOptions options = new AjaxOptions().url(source).type("GET").dataType("image").context(context) .global(false).redundancy(Redundancy.RESPOND_TO_ALL_LISTENERS).success(new Function() { @Override public void invoke($ droidQuery, Object... params) { Bitmap bitmap = (Bitmap) params[0]; for (View v : views) { if (v instanceof ImageView) { try { ((ImageView) v).setImageBitmap(Bitmap.createBitmap(bitmap)); } catch (Throwable t) { if (error != null) error.invoke($.with(context), t); } } else { v.setBackgroundDrawable(new BitmapDrawable(Bitmap.createBitmap(bitmap))); } } } }); if (error != null) { options.error(error); } if (width >= 0) { options.imageWidth(width); } if (height >= 0) { options.imageHeight(height); } $.ajax(options); } else { try { BitmapFactory.Options opt = new BitmapFactory.Options(); opt.inSampleSize = 1; opt.inPurgeable = true; opt.inInputShareable = false; if (width >= 0) opt.outWidth = width; if (height >= 0) opt.outHeight = height; Bitmap bitmap = BitmapFactory.decodeStream(context.getAssets().open(source), new Rect(0, 0, 0, 0), opt); for (View v : views) { if (v instanceof ImageView) { try { ((ImageView) v).setImageBitmap(Bitmap.createBitmap(bitmap)); } catch (Throwable t) { if (error != null) error.invoke($.with(context), t); } } else { v.setBackgroundDrawable(new BitmapDrawable(Bitmap.createBitmap(bitmap))); } } } catch (Throwable t) { if (error != null) { error.invoke($.with(context), t); } } } return this; }