List of usage examples for android.graphics Rect height
public final int height()
From source file:android.support.v7ox.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 w w .ja v a2 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; 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, screenPos[1] + height - displayFrame.top); } else { // Show along the bottom center cheatSheet.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, height); } cheatSheet.show(); return true; }
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 ww .ja v a 2s.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:com.facebook.litho.MountState.java
private static int computeRectArea(Rect rect) { return rect.isEmpty() ? 0 : (rect.width() * rect.height()); }
From source file:android.support.v7.app.MediaRouteButton.java
@Override public boolean performLongClick() { if (super.performLongClick()) { return true; }// w ww . j a va 2s.c om if (!mCheatSheetEnabled) { return false; } final CharSequence contentDesc = getContentDescription(); if (TextUtils.isEmpty(contentDesc)) { // Don't show the cheat sheet if we have no description return false; } 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, contentDesc, Toast.LENGTH_SHORT); if (midy < displayFrame.height()) { // Show along the top; follow action buttons cheatSheet.setGravity(Gravity.TOP | GravityCompat.END, screenWidth - screenPos[0] - width / 2, height); } else { // Show along the bottom center cheatSheet.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, height); } cheatSheet.show(); performHapticFeedback(HapticFeedbackConstants.LONG_PRESS); return true; }
From source file:com.nextgis.metroaccess.ui.activity.SelectStationActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_select_station); resultIntent = new Intent(); // setup action bar for tabs final ActionBar actionBar = getSupportActionBar(); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); //actionBar.setDisplayShowTitleEnabled(false); actionBar.setDisplayHomeAsUpEnabled(true); prefs = PreferenceManager.getDefaultSharedPreferences(this); mIsLimitations = LimitationsActivity.hasLimitations(this); mAdapter = new FragmentRollAdapter(getSupportFragmentManager()); mAdapter.setActionBar(actionBar);// www .j ava2 s . c o m mPager = (ViewPager) findViewById(R.id.pager); mPager.setAdapter(mAdapter); mPager.setOnPageChangeListener(new OnPageChangeListener() { public void onPageScrollStateChanged(int arg0) { } public void onPageScrolled(int arg0, float arg1, int arg2) { } public void onPageSelected(int arg0) { Log.d(TAG, "onPageSelected: " + arg0); actionBar.getTabAt(arg0).select(); filter(mPager.getCurrentItem()); } }); ActionBar.Tab tab = actionBar.newTab().setText(R.string.sSelAlphabeticalTab) .setTabListener(new TabListener(0 + "", mPager)); actionBar.addTab(tab); tab = actionBar.newTab().setText(R.string.sSelLinesTab).setTabListener(new TabListener(1 + "", mPager)); actionBar.addTab(tab); tab = actionBar.newTab().setText(R.string.sSelRecentTab).setTabListener(new TabListener(2 + "", mPager)); actionBar.addTab(tab); //get location from calling class Bundle extras = getIntent().getExtras(); if (extras != null) { int nType = extras.getInt(BUNDLE_EVENTSRC_KEY); m_bIn = extras.getBoolean(BUNDLE_ENTRANCE_KEY); mStationId = extras.getInt(BUNDLE_STATIONID_KEY); mPortalId = extras.getInt(BUNDLE_PORTALID_KEY); int selectedStation = -1; Tracker t = ((MetroApp) getApplication()).getTracker(); t.setScreenName(Constants.SCREEN_SELECT_STATION + " " + getDirection()); t.send(new HitBuilders.AppViewBuilder().build()); switch (nType) { case DEPARTURE_RESULT: setTitle(R.string.sFromStation); selectedStation = prefs.getInt("dep_" + BUNDLE_STATIONID_KEY, -1); break; case ARRIVAL_RESULT: setTitle(R.string.sToStation); selectedStation = prefs.getInt("arr_" + BUNDLE_STATIONID_KEY, -1); break; } if (selectedStation != -1) { final int finalSelectedStation = selectedStation; mPager.post(new Runnable() { @Override public void run() { mAlphaStListFragment.expandStation(finalSelectedStation); } }); } } tvNotes = (TextView) findViewById(R.id.tvNotes); // http://stackoverflow.com/a/9108219 final int softKeyboardHeight = getResources().getDisplayMetrics().heightPixels / 5; final View activityRootView = findViewById(R.id.select_station_layout); activityRootView.getViewTreeObserver() .addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { if (!mIsLimitations) return; Rect r = new Rect(); //r will be populated with the coordinates of your view // that area still visible. activityRootView.getWindowVisibleDisplayFrame(r); // int heightDiff = activityRootView.getRootView().getHeight() - r.height(); mHeightDifference = activityRootView.getRootView().getHeight() - r.height(); // if more than 1/5 of display, its probably a keyboard... mIsKeyboardShown = mHeightDifference > softKeyboardHeight; if (mIsKeyboardShown) tvNotes.setVisibility(View.GONE); else tvNotes.setVisibility(View.VISIBLE); } }); }
From source file:com.astir_trotter.atcustom.ui.iconics.core.IconicsDrawable.java
/** * Update the TextSize/*from w w w . java 2 s . c om*/ * * @param viewBounds */ private void updateTextSize(Rect viewBounds) { float textSize = (float) viewBounds.height() * (mRespectFontBounds ? 1 : 2); mIconPaint.setTextSize(textSize); String textValue = mIcon != null ? String.valueOf(mIcon.getCharacter()) : String.valueOf(mPlainIcon); mIconPaint.getTextPath(textValue, 0, textValue.length(), 0, viewBounds.height(), mPath); mPath.computeBounds(mPathBounds, true); if (!mRespectFontBounds) { float deltaWidth = ((float) mPaddingBounds.width() / mPathBounds.width()); float deltaHeight = ((float) mPaddingBounds.height() / mPathBounds.height()); float delta = (deltaWidth < deltaHeight) ? deltaWidth : deltaHeight; textSize *= delta; mIconPaint.setTextSize(textSize); mIconPaint.getTextPath(textValue, 0, textValue.length(), 0, viewBounds.height(), mPath); mPath.computeBounds(mPathBounds, true); } }
From source file:com.dynamixsoftware.printingsample.IntentApiFragment.java
@Override public void onClick(View v) { switch (v.getId()) { case R.id.check_premium: new AlertDialog.Builder(requireContext()).setTitle(R.string.check_premium) .setMessage("" + intentApi.checkPremium()).setPositiveButton(R.string.ok, null).show(); break;//ww w . j a v a 2s .c om case R.id.activate_online: final Context appContext = requireContext().getApplicationContext(); intentApi.setLicense("YOUR_ACTIVATION_KEY", new ISetLicenseCallback.Stub() { @Override public void start() { toastInMainThread(appContext, "activate start"); } @Override public void serverCheck() { toastInMainThread(appContext, "activate check server"); } @Override public void finish(final Result arg0) { toastInMainThread(appContext, "activate finish " + (arg0 == Result.OK ? "ok" : "error")); } }); break; case R.id.setup_printer: intentApi.setupCurrentPrinter(); break; case R.id.change_options: intentApi.changePrinterOptions(); break; case R.id.get_current_printer: try { IPrinterInfo printer = intentApi.getCurrentPrinter(); Toast.makeText(requireContext().getApplicationContext(), "current printer " + (printer != null ? printer.getName() : "null"), Toast.LENGTH_LONG) .show(); } catch (RemoteException e) { e.printStackTrace(); } break; case R.id.print_image: intentApi.print(Uri.parse("file://" + FilesUtils.getFilePath(requireContext(), FilesUtils.FILE_PNG)), "image/png", "from printing sample"); break; case R.id.print_file: intentApi.print(Uri.parse("file://" + FilesUtils.getFilePath(requireContext(), FilesUtils.FILE_DOC)), "application/msword", "from printing sample"); break; case R.id.show_file_preview: intentApi.showFilePreview( Uri.parse("file://" + FilesUtils.getFilePath(requireContext(), FilesUtils.FILE_DOC)), "application/msword", 0); break; case R.id.print_with_your_rendering: try { IDocument.Stub document = new IDocument.Stub() { private int thumbnailWidth; private int thumbnailHeight; @Override public Bitmap renderPageFragment(int arg0, Rect fragment) throws RemoteException { IPrinterInfo printer = intentApi.getCurrentPrinter(); if (printer != null) { Bitmap bitmap = Bitmap.createBitmap(fragment.width(), fragment.height(), Bitmap.Config.ARGB_8888); for (int i = 0; i < 3; i++) try { BitmapFactory.Options options = new BitmapFactory.Options(); options.inPreferredConfig = Bitmap.Config.ARGB_8888; options.inDither = false; if (i > 0) { options.inSampleSize = 1 << i; } Bitmap imageBMP = BitmapFactory.decodeStream( new FileInputStream( FilesUtils.getFilePath(requireContext(), FilesUtils.FILE_PNG)), null, options); Paint p = new Paint(); int imageWidth = 0; int imageHeight = 0; if (imageBMP != null) { imageWidth = imageBMP.getWidth(); imageHeight = imageBMP.getHeight(); } int xDpi = printer.getPrinterContext().getHResolution(); int yDpi = printer.getPrinterContext().getVResolution(); // in dots int paperWidth = printer.getPrinterContext().getPaperWidth() * xDpi / 72; int paperHeight = printer.getPrinterContext().getPaperHeight() * yDpi / 72; float aspectH = (float) imageHeight / (float) paperHeight; float aspectW = (float) imageWidth / (float) paperWidth; aspectH = aspectH > 1 ? 1 / aspectH : aspectH; aspectW = aspectW > 1 ? 1 / aspectW : aspectW; RectF dst = new RectF(0, 0, fragment.width() * aspectW, fragment.height() * aspectH); float sLeft = 0; float sTop = fragment.top * aspectH; float sRight = imageWidth; float sBottom = fragment.top * aspectH + fragment.bottom * aspectH; RectF source = new RectF(sLeft, sTop, sRight, sBottom); Canvas canvas = new Canvas(bitmap); canvas.drawColor(Color.WHITE); // move image to actual printing area dst.offsetTo(dst.left - fragment.left, dst.top - fragment.top); Matrix matrix = new Matrix(); matrix.setRectToRect(source, dst, Matrix.ScaleToFit.FILL); canvas.drawBitmap(imageBMP, matrix, p); break; } catch (IOException ex) { ex.printStackTrace(); break; } catch (OutOfMemoryError ex) { if (bitmap != null) { bitmap.recycle(); bitmap = null; } continue; } return bitmap; } else { return null; } } @Override public void initDeviceContext(IPrinterContext printerContext, int thumbnailWidth, int thumbnailHeight) { this.thumbnailWidth = thumbnailWidth; this.thumbnailHeight = thumbnailHeight; } @Override public int getTotalPages() { return 1; } @Override public String getDescription() { return "PrintHand test page"; } @Override public Bitmap getPageThumbnail(int arg0) throws RemoteException { Bitmap bitmap = Bitmap.createBitmap(thumbnailWidth, thumbnailHeight, Bitmap.Config.ARGB_8888); for (int i = 0; i < 3; i++) try { BitmapFactory.Options options = new BitmapFactory.Options(); options.inPreferredConfig = Bitmap.Config.ARGB_8888; options.inDither = false; if (i > 0) { options.inSampleSize = 1 << i; } Bitmap imageBMP = BitmapFactory.decodeStream( new FileInputStream( FilesUtils.getFilePath(requireContext(), FilesUtils.FILE_PNG)), null, options); Paint p = new Paint(); int imageWidth = 0; int imageHeight = 0; if (imageBMP != null) { imageWidth = imageBMP.getWidth(); imageHeight = imageBMP.getHeight(); } // default int paperWidth = 2481; int paperHeight = 3507; IPrinterInfo printer = intentApi.getCurrentPrinter(); if (printer != null) { int xDpi = printer.getPrinterContext().getHResolution(); int yDpi = printer.getPrinterContext().getVResolution(); // in dots paperWidth = printer.getPrinterContext().getPaperWidth() * xDpi / 72; paperHeight = printer.getPrinterContext().getPaperHeight() * yDpi / 72; } float aspectW = (float) imageWidth / (float) paperWidth; float aspectH = (float) imageHeight / (float) paperHeight; RectF dst = new RectF(0, 0, thumbnailWidth * aspectW, thumbnailHeight * aspectH); float sLeft = 0; float sTop = 0; float sRight = imageWidth; float sBottom = imageHeight; RectF source = new RectF(sLeft, sTop, sRight, sBottom); Canvas canvas = new Canvas(bitmap); canvas.drawColor(Color.WHITE); Matrix matrix = new Matrix(); matrix.setRectToRect(source, dst, Matrix.ScaleToFit.FILL); canvas.drawBitmap(imageBMP, matrix, p); break; } catch (IOException ex) { ex.printStackTrace(); break; } catch (OutOfMemoryError ex) { if (bitmap != null) { bitmap.recycle(); bitmap = null; } continue; } return bitmap; } }; intentApi.print(document); } catch (RemoteException e) { e.printStackTrace(); } break; case R.id.print_with_your_rendering_without_ui: try { IJob.Stub job = new IJob.Stub() { @Override public Bitmap renderPageFragment(int num, Rect fragment) throws RemoteException { IPrinterInfo printer = intentApi.getCurrentPrinter(); if (printer != null) { Bitmap bitmap = Bitmap.createBitmap(fragment.width(), fragment.height(), Bitmap.Config.ARGB_8888); for (int i = 0; i < 3; i++) try { BitmapFactory.Options options = new BitmapFactory.Options(); options.inPreferredConfig = Bitmap.Config.ARGB_8888; options.inDither = false; if (i > 0) { options.inSampleSize = 1 << i; } Bitmap imageBMP = BitmapFactory.decodeStream( new FileInputStream( FilesUtils.getFilePath(requireContext(), FilesUtils.FILE_PNG)), null, options); Paint p = new Paint(); int imageWidth = 0; int imageHeight = 0; if (imageBMP != null) { imageWidth = imageBMP.getWidth(); imageHeight = imageBMP.getHeight(); } int xDpi = printer.getPrinterContext().getHResolution(); int yDpi = printer.getPrinterContext().getVResolution(); // in dots int paperWidth = printer.getPrinterContext().getPaperWidth() * xDpi / 72; int paperHeight = printer.getPrinterContext().getPaperHeight() * yDpi / 72; float aspectH = (float) imageHeight / (float) paperHeight; float aspectW = (float) imageWidth / (float) paperWidth; RectF dst = new RectF(0, 0, fragment.width() * aspectW, fragment.height() * aspectH); float sLeft = 0; float sTop = fragment.top * aspectH; float sRight = imageWidth; float sBottom = fragment.top * aspectH + fragment.bottom * aspectH; RectF source = new RectF(sLeft, sTop, sRight, sBottom); Canvas canvas = new Canvas(bitmap); canvas.drawColor(Color.WHITE); // move image to actual printing area dst.offsetTo(dst.left - fragment.left, dst.top - fragment.top); Matrix matrix = new Matrix(); matrix.setRectToRect(source, dst, Matrix.ScaleToFit.FILL); canvas.drawBitmap(imageBMP, matrix, p); break; } catch (IOException ex) { ex.printStackTrace(); break; } catch (OutOfMemoryError ex) { if (bitmap != null) { bitmap.recycle(); bitmap = null; } continue; } return bitmap; } else { return null; } } @Override public int getTotalPages() { return 1; } }; intentApi.print(job, 1); } catch (RemoteException e) { e.printStackTrace(); } break; case R.id.print_image_with_print_hand_rendering_without_ui: try { intentApi.print("PrintingSample", "image/png", Uri.parse("file://" + FilesUtils.getFilePath(requireContext(), FilesUtils.FILE_PNG))); } catch (RemoteException e) { e.printStackTrace(); } break; case R.id.change_image_options: try { List<PrintHandOption> imageOptions = intentApi.getImagesOptions(); changeRandomOption(imageOptions); intentApi.setImagesOptions(imageOptions); } catch (RemoteException e) { e.printStackTrace(); } break; case R.id.print_file_with_print_hand_rendering_without_ui: try { intentApi.print("PrintingSample", "application/ms-word", Uri.parse("file://" + FilesUtils.getFilePath(requireContext(), FilesUtils.FILE_DOC))); } catch (RemoteException e) { e.printStackTrace(); } break; case R.id.print_protected_file_with_print_hand_rendering_without_ui: try { intentApi.print("PrintingSample", "application/pdf", Uri.parse("file://" + FilesUtils.getFilePath(requireContext(), FilesUtils.FILE_PDF))); } catch (RemoteException e) { e.printStackTrace(); } break; case R.id.change_files_options: try { List<PrintHandOption> fileOptions = intentApi.getFilesOptions(); changeRandomOption(fileOptions); intentApi.setFilesOptions(fileOptions); } catch (RemoteException e) { e.printStackTrace(); } break; } }
From source file:com.cachirulop.moneybox.fragment.MoneyboxFragment.java
/** * Drop money from the top of the layout to the bottom simulating that a * coin or bill is inserted in the moneybox. * /* w ww .ja v a 2 s . c o m*/ * @param leftMargin * Left side of the coin/bill * @param width * Width of the image to slide down * @param m * Movement with the value of the money to drop */ protected void dropMoney(int leftMargin, int width, Movement m) { ImageView money; AnimationSet moneyDrop; RelativeLayout layout; RelativeLayout.LayoutParams lpParams; Rect r; Activity parent; CurrencyValueDef curr; parent = getActivity(); curr = CurrencyManager.getCurrencyDef(Math.abs(m.getAmount())); r = curr.getDrawable().getBounds(); money = new ImageView(parent); money.setVisibility(View.INVISIBLE); money.setImageDrawable(curr.getDrawable().getConstantState().newDrawable()); money.setTag(curr); money.setId((int) m.getIdMovement()); layout = findLayout(); lpParams = new RelativeLayout.LayoutParams(r.width(), r.height()); lpParams.leftMargin = leftMargin; lpParams.rightMargin = layout.getWidth() - (leftMargin + width); lpParams.topMargin = 0; lpParams.bottomMargin = r.height(); layout.addView(money, lpParams); moneyDrop = createDropAnimation(money, layout, curr); money.setVisibility(View.VISIBLE); SoundsManager.playMoneySound(curr.getType()); VibratorManager.vibrateMoneyDrop(curr.getType()); money.startAnimation(moneyDrop); }
From source file:com.astir_trotter.atcustom.ui.iconics.core.IconicsDrawable.java
/** * Update the Padding Bounds// w w w . j a v a 2 s.co m * * @param viewBounds */ private void updatePaddingBounds(Rect viewBounds) { if (mIconPadding >= 0 && !(mIconPadding * 2 > viewBounds.width()) && !(mIconPadding * 2 > viewBounds.height())) { mPaddingBounds.set(viewBounds.left + mIconPadding, viewBounds.top + mIconPadding, viewBounds.right - mIconPadding, viewBounds.bottom - mIconPadding); } }
From source file:com.android.deskclock.alarms.AlarmActivity.java
private Animator getAlertAnimator(final View source, final int titleResId, final String infoText, final String accessibilityText, final int revealColor, final int backgroundColor) { final ViewGroup containerView = (ViewGroup) findViewById(android.R.id.content); final Rect sourceBounds = new Rect(0, 0, source.getHeight(), source.getWidth()); containerView.offsetDescendantRectToMyCoords(source, sourceBounds); final int centerX = sourceBounds.centerX(); final int centerY = sourceBounds.centerY(); final int xMax = Math.max(centerX, containerView.getWidth() - centerX); final int yMax = Math.max(centerY, containerView.getHeight() - centerY); final float startRadius = Math.max(sourceBounds.width(), sourceBounds.height()) / 2.0f; final float endRadius = (float) Math.sqrt(xMax * xMax + yMax * yMax); final CircleView revealView = new CircleView(this).setCenterX(centerX).setCenterY(centerY) .setFillColor(revealColor);/*from ww w. j a v a2s . c om*/ containerView.addView(revealView); // TODO: Fade out source icon over the reveal (like LOLLIPOP version). final Animator revealAnimator = ObjectAnimator.ofFloat(revealView, CircleView.RADIUS, startRadius, endRadius); revealAnimator.setDuration(ALERT_REVEAL_DURATION_MILLIS); revealAnimator.setInterpolator(REVEAL_INTERPOLATOR); revealAnimator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animator) { mAlertView.setVisibility(View.VISIBLE); mAlertTitleView.setText(titleResId); if (infoText != null) { mAlertInfoView.setText(infoText); mAlertInfoView.setVisibility(View.VISIBLE); } mContentView.setVisibility(View.GONE); getWindow().setBackgroundDrawable(new ColorDrawable(backgroundColor)); } }); final ValueAnimator fadeAnimator = ObjectAnimator.ofFloat(revealView, View.ALPHA, 0.0f); fadeAnimator.setDuration(ALERT_FADE_DURATION_MILLIS); fadeAnimator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { containerView.removeView(revealView); } }); final AnimatorSet alertAnimator = new AnimatorSet(); alertAnimator.play(revealAnimator).before(fadeAnimator); alertAnimator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animator) { mAlertView.announceForAccessibility(accessibilityText); mHandler.postDelayed(new Runnable() { @Override public void run() { finish(); } }, ALERT_DISMISS_DELAY_MILLIS); } }); return alertAnimator; }