List of usage examples for android.graphics Rect Rect
public Rect()
From source file:android.support.v7.internal.view.menu.ActionMenuItemView.java
@Override public boolean onLongClick(View v) { if (hasText()) { // Don't show the cheat sheet for items that already show text. return false; }//from w w w . j av a2s . c o m final int[] screenPos = new int[2]; final Rect displayFrame = new Rect(); getLocationOnScreen(screenPos); getWindowVisibleDisplayFrame(displayFrame); final Context context = getContext(); final int width = getWidth(); final int height = getHeight(); final int midy = screenPos[1] + height / 2; int referenceX = screenPos[0] + width / 2; if (ViewCompat.getLayoutDirection(v) == ViewCompat.LAYOUT_DIRECTION_LTR) { final int screenWidth = context.getResources().getDisplayMetrics().widthPixels; referenceX = screenWidth - referenceX; // mirror } Toast cheatSheet = Toast.makeText(context, mItemData.getTitle(), Toast.LENGTH_SHORT); if (midy < displayFrame.height()) { // Show along the top; follow action buttons cheatSheet.setGravity(Gravity.TOP | GravityCompat.END, referenceX, height); } else { // Show along the bottom center cheatSheet.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, height); } cheatSheet.show(); return true; }
From source file:am.hour.beebird.Activity.MainActivity.java
public void onWindowFocusChanged(boolean hasFocus) { // TODO Auto-generated method stub super.onWindowFocusChanged(hasFocus); Rect frame = new Rect(); getWindow().getDecorView().getWindowVisibleDisplayFrame(frame); MainApplication.setActionbarHeight(getActionBar().getHeight()); spu.saveIntInSP("ACTIONBAR_HEIGHT", getActionBar().getHeight()); }
From source file:com.hxsn.witwork.ui.ViewfinderView.java
@Override public void onDraw(Canvas canvas) { // ??????CameraManager? if (CameraManager.get() == null) { return;//from w w w .j a v a 2s . c o m } Rect frame = CameraManager.get().getFramingRect(); if (frame == null) { return; } // ? if (!isFirst) { isFirst = true; slideTop = frame.top; slideBottom = frame.bottom; } // ?? int width = canvas.getWidth(); int height = canvas.getHeight(); paint.setColor(resultBitmap != null ? resultColor : maskColor); // ????????????? // ????????? canvas.drawRect(0, 0, width, frame.top + 15, paint); canvas.drawRect(0, frame.top + 15, frame.left + 15, frame.bottom - 14, paint); canvas.drawRect(frame.right - 14, frame.top + 15, width, frame.bottom - 14, paint); canvas.drawRect(0, frame.bottom - 14, width, height, paint); if (resultBitmap != null) { // Draw the opaque result bitmap over the scanning rectangle paint.setAlpha(OPAQUE); canvas.drawBitmap(resultBitmap, frame.left, frame.top, paint); } else { // ??8 paint.setColor(Color.rgb(139, 193, 17)); canvas.drawRect(frame.left, frame.top, frame.left + ScreenRate, frame.top + CORNER_WIDTH, paint); canvas.drawRect(frame.left, frame.top, frame.left + CORNER_WIDTH, frame.top + ScreenRate, paint); canvas.drawRect(frame.right - ScreenRate, frame.top, frame.right, frame.top + CORNER_WIDTH, paint); canvas.drawRect(frame.right - CORNER_WIDTH, frame.top, frame.right, frame.top + ScreenRate, paint); canvas.drawRect(frame.left, frame.bottom - CORNER_WIDTH, frame.left + ScreenRate, frame.bottom, paint); canvas.drawRect(frame.left, frame.bottom - ScreenRate, frame.left + CORNER_WIDTH, frame.bottom, paint); canvas.drawRect(frame.right - ScreenRate, frame.bottom - CORNER_WIDTH, frame.right, frame.bottom, paint); canvas.drawRect(frame.right - CORNER_WIDTH, frame.bottom - ScreenRate, frame.right, frame.bottom, paint); // ,??SPEEN_DISTANCE slideTop += SPEEN_DISTANCE; if (slideTop >= frame.bottom) { slideTop = frame.top; } // canvas.drawRect(frame.left + MIDDLE_LINE_PADDING, slideTop - // MIDDLE_LINE_WIDTH/2, frame.right - MIDDLE_LINE_PADDING,slideTop + // MIDDLE_LINE_WIDTH/2, paint); Rect lineRect = new Rect(); lineRect.left = frame.left; lineRect.right = frame.right; lineRect.top = slideTop; lineRect.bottom = slideTop + 18; canvas.drawBitmap(((BitmapDrawable) (getResources().getDrawable(R.drawable.fgx))).getBitmap(), null, lineRect, paint); // ??? paint.setColor(Color.WHITE); paint.setTextSize(TEXT_SIZE * density); // paint.setAlpha(0x40); // paint.setTypeface(Typeface.create("System", Typeface.BOLD)); canvas.drawText("?/??????", frame.left, (float) (frame.bottom + (float) TEXT_PADDING_TOP * density), paint); canvas.drawText("??" + num + "", frame.left, (float) (frame.bottom + (float) TEXT_PADDING_TOP * density + 50), paint); int max = 7; if (name.size() < max) { max = name.size(); for (int i = 0; i < max; i++) { canvas.drawText(name.get(i), frame.left, (float) (frame.bottom + (float) TEXT_PADDING_TOP * density + 100 + 50 * i), paint); } } else { for (int i = 6; i >= 0; i--) { canvas.drawText(name.get((name.size() - 1) - (6 - i)), frame.left, (float) (frame.bottom + (float) TEXT_PADDING_TOP * density + 100 + 50 * i), paint); } } paint.setStyle(Style.STROKE); canvas.drawRect(frame.left + 15, frame.top + 15, frame.right - 15, frame.bottom - 15, paint); setViewY(frame.bottom); paint.setStyle(Style.FILL); Collection<ResultPoint> currentPossible = possibleResultPoints; Collection<ResultPoint> currentLast = lastPossibleResultPoints; if (currentPossible.isEmpty()) { lastPossibleResultPoints = null; } else { possibleResultPoints = new HashSet<ResultPoint>(5); lastPossibleResultPoints = currentPossible; paint.setAlpha(OPAQUE); paint.setColor(resultPointColor); for (ResultPoint point : currentPossible) { canvas.drawCircle(frame.left + point.getX(), frame.top + point.getY(), 6.0f, paint); } } if (currentLast != null) { paint.setAlpha(OPAQUE / 2); paint.setColor(resultPointColor); for (ResultPoint point : currentLast) { canvas.drawCircle(frame.left + point.getX(), frame.top + point.getY(), 3.0f, paint); } } // ???? postInvalidate(); // postInvalidateDelayed(ANIMATION_DELAY, frame.left, frame.top, // frame.right, frame.bottom); } }
From source file:android.support.design.widget.CoordinatorLayout.java
@NonNull private static Rect acquireTempRect() { Rect rect = sRectPool.acquire();//from w ww . ja va 2 s. com if (rect == null) { rect = new Rect(); } return rect; }
From source file:com.firesoft.member.Activity.C0_ServiceListActivity.java
@Override public void OnMessageResponse(String url, JSONObject jo, AjaxStatus status) throws JSONException { mListView.stopRefresh();/*from www .j a v a 2 s.co m*/ mListView.stopLoadMore(); if (url.endsWith(ApiInterface.MEMBER_LIST)) { if (null != jo) { memberlistResponse response = new memberlistResponse(); response.fromJson(jo); if (null == mListWithServiceAdapter) { mListWithServiceAdapter = new C0_ServiceListAdapter(this, mDataModel.dataList); mListView.setAdapter(mListWithServiceAdapter); footView = new View(this); footView.setEnabled(true); footView.setLayoutParams(new AbsListView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ImageUtil.Dp2Px(this, 60))); mListView.addFooterView(footView); } else { mListWithServiceAdapter.notifyDataSetChanged(); } mListView.stopLoadMore(); if (0 == response.more) { mListView.setPullLoadEnable(false); } Rect frame = new Rect(); getWindow().getDecorView().getWindowVisibleDisplayFrame(frame); int statusBarHeight = frame.top; int listHeight = mListView.getHeight(); int screenHeight = getResources().getDisplayMetrics().heightPixels - ImageUtil.Dp2Px(this, 50) - statusBarHeight; if (listHeight >= screenHeight) { footView.setVisibility(View.VISIBLE); } else { footView.setVisibility(View.GONE); mListView.removeFooterView(footView); } } } }
From source file:android.support.design.testutils.TestUtilsMatchers.java
/** * Returns a matcher that matches FloatingActionButtons with the specified background * fill color.//from w ww . ja v a 2 s . c o m */ public static Matcher withFabBackgroundFill(final @ColorInt int fillColor) { return new BoundedMatcher<View, View>(View.class) { private String failedCheckDescription; @Override public void describeTo(final Description description) { description.appendText(failedCheckDescription); } @Override public boolean matchesSafely(final View view) { if (!(view instanceof FloatingActionButton)) { return false; } final FloatingActionButton fab = (FloatingActionButton) view; // Since the FAB background is round, and may contain the shadow, we'll look at // just the center half rect of the content area final Rect area = new Rect(); fab.getContentRect(area); final int rectHeightQuarter = area.height() / 4; final int rectWidthQuarter = area.width() / 4; area.left += rectWidthQuarter; area.top += rectHeightQuarter; area.right -= rectWidthQuarter; area.bottom -= rectHeightQuarter; try { TestUtils.assertAllPixelsOfColor("", fab.getBackground(), view.getWidth(), view.getHeight(), false, fillColor, area, 0, true); } catch (Throwable t) { failedCheckDescription = t.getMessage(); return false; } return true; } }; }
From source file:com.actionbarsherlock.internal.view.menu.ActionMenuItemView.java
@Override public boolean onLongClick(View v) { if (hasText()) { // Don't show the cheat sheet for items that already show text. return false; }//w ww. j a v a 2 s . c om final int[] screenPos = new int[2]; final Rect displayFrame = new Rect(); getLocationOnScreen(screenPos); getWindowVisibleDisplayFrame(displayFrame); final Context context = getContext(); final int width = getWidth(); final int height = getHeight(); final int midy = screenPos[1] + height / 2; final int screenWidth = context.getResources().getDisplayMetrics().widthPixels; Toast cheatSheet = Toast.makeText(context, mItemData.getTitle(), Toast.LENGTH_SHORT); if (midy < displayFrame.height()) { // Show along the top; follow action buttons cheatSheet.setGravity(Gravity.TOP | Gravity.RIGHT, screenWidth - screenPos[0] - width / 2, height); } else { // Show along the bottom center cheatSheet.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, height); } cheatSheet.show(); return true; }
From source file:com.sim2dial.dialer.ChatFragment.java
private void addVirtualKeyboardVisiblityListener() { keyboardListener = new OnGlobalLayoutListener() { @Override/*from www . j av a 2 s .c o m*/ public void onGlobalLayout() { Rect visibleArea = new Rect(); view.getWindowVisibleDisplayFrame(visibleArea); int heightDiff = view.getRootView().getHeight() - (visibleArea.bottom - visibleArea.top); if (heightDiff > 200) { showKeyboardVisibleMode(); } else { hideKeyboardVisibleMode(); } } }; view.getViewTreeObserver().addOnGlobalLayoutListener(keyboardListener); }
From source file:com.oasis.sdk.activity.OasisSdkPayEpinActivity.java
private void initImage(List<String> imgUrls) { if (imgUrls == null || imgUrls.size() <= 0) return;/*from www.j a v a 2 s .c om*/ int size = imgUrls.size(); if (size > 4)// 4 size = 4; Rect r = new Rect(); et_code.getGlobalVisibleRect(r); int width = r.right - r.left; int singWidth = width / size; int imgWidth = DisplayUtil.dip2px(70, BaseUtils.getDensity()); int imgHeight = DisplayUtil.dip2px(30, BaseUtils.getDensity()); double l = singWidth / (double) imgWidth; if (l <= 1) { imgWidth = singWidth; } else { l = Math.round(l * 100) * 0.01d;// ?2?? imgWidth *= l; imgHeight *= l; } for (int i = 0; i < size; i++) { // ? 105*45 final ImageView img = new ImageView(this.getApplicationContext()); img.setLayoutParams(new LayoutParams(imgWidth, imgHeight)); img.setImageResource(BaseUtils.getResourceValue("drawable", "oasisgames_sdk_payway_mob_epin")); ImageRequest iq = new ImageRequest(imgUrls.get(i), new Response.Listener<Bitmap>() { @Override public void onResponse(final Bitmap arg0) { if (arg0 == null) return; img.setImageBitmap(arg0); img.postInvalidate(); } }, imgWidth, // ??? imgHeight, Config.ARGB_8888, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError arg0) { setWaitScreen(false); } }); iq.setRetryPolicy(new DefaultRetryPolicy(60000, 2, 1)); ApplicationContextManager.getInstance().getVolleyRequestQueue().add(iq); ll_images.addView(img); } if (ll_images.getChildCount() > 0) { ll_images.setVisibility(View.VISIBLE); } }