List of usage examples for android.graphics Rect Rect
public Rect()
From source file:android.support.design.testutils.TestUtilsMatchers.java
/** * Returns a matcher that matches FloatingActionButtons with the specified content height *///from w w w . j ava 2s . c o m public static Matcher withFabContentHeight(final int size) { 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; final Rect area = new Rect(); fab.getContentRect(area); return area.height() == size; } }; }
From source file:android.support.v7.app.MediaRouteButton.java
@Override public boolean performLongClick() { if (super.performLongClick()) { return true; }//from w w w .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:android.support.v7.view.menu.CascadingMenuPopup.java
/** * Determines whether the next submenu (of the given width) should display on the right or on * the left of the most recent menu.//from ww w . j ava2s .c om * * @param nextMenuWidth Width of the next submenu to display. * @return The position to display it. */ @HorizPosition private int getNextMenuPosition(int nextMenuWidth) { ListView lastListView = mShowingMenus.get(mShowingMenus.size() - 1).getListView(); final int[] screenLocation = new int[2]; lastListView.getLocationOnScreen(screenLocation); final Rect displayFrame = new Rect(); mShownAnchorView.getWindowVisibleDisplayFrame(displayFrame); if (mLastPosition == HORIZ_POSITION_RIGHT) { final int right = screenLocation[0] + lastListView.getWidth() + nextMenuWidth; if (right > displayFrame.right) { return HORIZ_POSITION_LEFT; } return HORIZ_POSITION_RIGHT; } else { // LEFT final int left = screenLocation[0] - nextMenuWidth; if (left < 0) { return HORIZ_POSITION_RIGHT; } return HORIZ_POSITION_LEFT; } }
From source file:com.sutromedia.android.core.PhotoActivity.java
private void setupTouchOnPlayButton() { View playButton = findViewById(R.image.play_slideshow); Rect expandedSize = new Rect(); playButton.getHitRect(expandedSize); expandedSize.inset(30, 30);// w w w .ja va 2 s .c o m TouchDelegate delegate = new TouchDelegate(expandedSize, playButton); View parent = (View) playButton.getParent(); parent.setTouchDelegate(delegate); }
From source file:com.actionbarsherlock.internal.widget.IcsAbsSpinner.java
/** * Maps a point to a position in the list. * * @param x X in local coordinate/* ww w . j a v a2 s . co m*/ * @param y Y in local coordinate * @return The position of the item which contains the specified point, or * {@link #INVALID_POSITION} if the point does not intersect an item. */ public int pointToPosition(int x, int y) { Rect frame = mTouchFrame; if (frame == null) { mTouchFrame = new Rect(); frame = mTouchFrame; } final int count = getChildCount(); for (int i = count - 1; i >= 0; i--) { View child = getChildAt(i); if (child.getVisibility() == View.VISIBLE) { child.getHitRect(frame); if (frame.contains(x, y)) { return mFirstPosition + i; } } } return INVALID_POSITION; }
From source file:com.tealeaf.TeaLeaf.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); PluginManager.init(this); instance = this; setFullscreenFlag();//from w w w . j a va 2s .co m configureActivity(); String appID = findAppID(); options = new TeaLeafOptions(this); PluginManager.callAll("onCreate", this, savedInstanceState); //check intent for test app info Bundle bundle = getIntent().getExtras(); boolean isTestApp = false; if (bundle != null) { isTestApp = bundle.getBoolean("isTestApp", false); if (isTestApp) { options.setAppID(appID); boolean isPortrait = bundle.getBoolean("isPortrait", false); if (isPortrait) { setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); } else { setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); } options.setCodeHost(bundle.getString("hostValue")); options.setCodePort(bundle.getInt("portValue")); String simulateID = bundle.getString("simulateID"); options.setSimulateID(simulateID); } } getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN); group = new FrameLayout(this); setContentView(group); // TextEditViewHandler setup textEditView = new TextEditViewHandler(this); settings = new Settings(this); remoteLogger = (ILogger) getLoggerInstance(this); checkUpdate(); compareVersions(); setLaunchUri(); // defer building all of these things until we have the absolutely correct options logger.buildLogger(this, remoteLogger); resourceManager = new ResourceManager(this, options); contactList = new ContactList(this, resourceManager); soundQueue = new SoundQueue(this, resourceManager); localStorage = new LocalStorage(this, options); // start push notifications, but defer for 10 seconds to give us time to start up PushBroadcastReceiver.scheduleNext(this, 10); glView = new TeaLeafGLSurfaceView(this); glViewPaused = false; // default screen dimensions Display display = getWindow().getWindowManager().getDefaultDisplay(); int width = display.getWidth(); int height = display.getHeight(); int orientation = getRequestedOrientation(); // gets real screen dimensions without nav bars on recent API versions if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { Point screenSize = new Point(); try { display.getRealSize(screenSize); width = screenSize.x; height = screenSize.y; } catch (NoSuchMethodError e) { } } // flip width and height based on orientation if ((orientation == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE && height > width) || (orientation == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT && width > height)) { int tempWidth = width; width = height; height = tempWidth; } final AbsoluteLayout absLayout = new AbsoluteLayout(this); absLayout.setLayoutParams(new android.view.ViewGroup.LayoutParams(width, height)); absLayout.addView(glView, new android.view.ViewGroup.LayoutParams(width, height)); group.addView(absLayout); editText = EditTextView.Init(this); if (isTestApp) { startGame(); } soundQueue.playSound(SoundQueue.LOADING_SOUND); doFirstRun(); remoteLogger.sendLaunchEvent(this); paused = false; menuButtonHandler = MenuButtonHandlerFactory.getButtonHandler(this); group.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { public void onGlobalLayout() { // get visible area of the view Rect r = new Rect(); group.getWindowVisibleDisplayFrame(r); int visibleHeight = r.bottom; // TODO // maybe this should be renamed if (visibleHeight != lastVisibleHeight) { lastVisibleHeight = visibleHeight; EventQueue.pushEvent(new KeyboardScreenResizeEvent(visibleHeight)); } } }); }
From source file:org.cocos2dx.lib.Cocos2dxBitmap.java
private static int getFontSizeAccordingHeight(int height) { Paint paint = new Paint(); Rect bounds = new Rect(); paint.setTypeface(Typeface.DEFAULT); int incr_text_size = 1; boolean found_desired_size = false; while (!found_desired_size) { paint.setTextSize(incr_text_size); String text = "SghMNy"; paint.getTextBounds(text, 0, text.length(), bounds); incr_text_size++;/*from ww w . j a v a 2s . co m*/ if (height - bounds.height() <= 2) { found_desired_size = true; } Log.d("font size", "incr size:" + incr_text_size); } return incr_text_size; }
From source file:au.org.ala.fielddata.mobile.CollectSurveyData.java
public void scrollTo(final Attribute attribute) { pager.post(new Runnable() { public void run() { Binder binder = (Binder) surveyViewModel.getAttributeListener(attribute); View boundView = binder.getView(); ViewParent parent = boundView.getParent(); while (parent != null && !(parent instanceof ScrollView)) { parent = parent.getParent(); }/*from w w w . j a va 2 s .com*/ if (parent != null) { final ScrollView view = (ScrollView) parent; final Rect r = new Rect(); view.offsetDescendantRectToMyCoords((View) boundView.getParent(), r); view.post(new Runnable() { public void run() { view.scrollTo(0, r.bottom); } }); } } }); }
From source file:com.insthub.O2OMobile.Activity.C0_ServiceListActivity.java
@Override public void OnMessageResponse(String url, JSONObject jo, AjaxStatus status) throws JSONException { mListView.stopRefresh();//from w w w .ja v a 2s . c o m mListView.stopLoadMore(); if (url.endsWith(ApiInterface.USER_LIST)) { if (null != jo) { userlistResponse response = new userlistResponse(); 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); } } } }