List of usage examples for android.graphics Point Point
public Point()
From source file:io.selendroid.server.model.DefaultSelendroidDriver.java
@Override @SuppressWarnings("deprecation") public byte[] takeScreenshot() { ViewHierarchyAnalyzer viewAnalyzer = ViewHierarchyAnalyzer.getDefaultInstance(); // TODO ddary review later, but with getRecentDecorView() it seems to work better // long drawingTime = 0; // View container = null; // for (View view : viewAnalyzer.getTopLevelViews()) { // if (view != null && view.isShown() && view.hasWindowFocus() // && view.getDrawingTime() > drawingTime) { // container = view; // drawingTime = view.getDrawingTime(); // }/*www . ja va 2 s .c o m*/ // } // final View mainView = container; final View mainView = viewAnalyzer.getRecentDecorView(); if (mainView == null) { throw new SelendroidException("No open windows."); } done = false; long end = System.currentTimeMillis() + serverInstrumentation.getAndroidWait().getTimeoutInMillis(); final byte[][] rawPng = new byte[1][1]; ServerInstrumentation.getInstance().getCurrentActivity().runOnUiThread(new Runnable() { public void run() { synchronized (syncObject) { Display display = serverInstrumentation.getCurrentActivity().getWindowManager() .getDefaultDisplay(); Point size = new Point(); try { display.getSize(size); } catch (NoSuchMethodError ignore) { // Older than api level 13 size.x = display.getWidth(); size.y = display.getHeight(); } // Get root view View view = mainView.getRootView(); // Create the bitmap to use to draw the screenshot final Bitmap bitmap = Bitmap.createBitmap(size.x, size.y, Bitmap.Config.ARGB_8888); final Canvas canvas = new Canvas(bitmap); // Get current theme to know which background to use final Activity activity = serverInstrumentation.getCurrentActivity(); final Theme theme = activity.getTheme(); final TypedArray ta = theme .obtainStyledAttributes(new int[] { android.R.attr.windowBackground }); final int res = ta.getResourceId(0, 0); final Drawable background = activity.getResources().getDrawable(res); // Draw background background.draw(canvas); // Draw views view.draw(canvas); ByteArrayOutputStream stream = new ByteArrayOutputStream(); if (!bitmap.compress(Bitmap.CompressFormat.PNG, 70, stream)) { throw new RuntimeException("Error while compressing screenshot image."); } try { stream.flush(); stream.close(); } catch (IOException e) { throw new RuntimeException("I/O Error while capturing screenshot: " + e.getMessage()); } finally { Closeable closeable = (Closeable) stream; try { if (closeable != null) { closeable.close(); } } catch (IOException ioe) { // ignore } } rawPng[0] = stream.toByteArray(); mainView.destroyDrawingCache(); done = true; syncObject.notify(); } } }); waitForDone(end, serverInstrumentation.getAndroidWait().getTimeoutInMillis(), "Failed to take screenshot."); return rawPng[0]; }
From source file:jp.co.ipublishing.esnavi.views.MarqueeView.java
/** * ??X/*from ww w. j a v a 2 s . c o m*/ * * @return */ private int getLastX() { final WindowManager wm = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE); final Display display = wm.getDefaultDisplay(); final Point size = new Point(); display.getSize(size); final int measureText = (int) mTextPaint.measureText(mText); if (measureText >= size.x) { // ???? return -measureText; } else { return -measureText; } }
From source file:com.javielinux.tweettopics2.TweetActivity.java
public void showImage(InfoLink infoLink) { int screenHeight = 0; try {/*w ww . ja va 2 s. co m*/ Point size = new Point(); getWindowManager().getDefaultDisplay().getSize(size); screenHeight = size.y; } catch (NoSuchMethodError e) { screenHeight = getWindowManager().getDefaultDisplay().getHeight(); } Rect rect = new Rect(); getWindow().getDecorView().getWindowVisibleDisplayFrame(rect); int statusBarHeight = rect.top; final float translationOffset = (float) screenHeight - statusBarHeight - tweetActionsContainer.getTop(); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) { Intent showImage = new Intent(this, ShowImageActivity.class); showImage.putExtra(ShowImageActivity.KEY_EXTRA_URL_IMAGE, infoLink.getLinkImageLarge()); startActivity(showImage); } else { AQuery aQuery = new AQuery(this).recycle(ivImageLarger); aQuery.id(ivImageLarger).image(infoLink.getLinkImageLarge(), true, true, 0, R.drawable.icon_tweet_image_large, aQuery.getCachedImage(R.drawable.icon_tweet_image_large), 0); ObjectAnimator tweetInfoLayoutAnimator = ObjectAnimator.ofFloat(tweetInfoLayout, "translationY", 0.0f, translationOffset); tweetInfoLayoutAnimator.setDuration(250); AnimatorSet animatorSet = new AnimatorSet(); animatorSet.addListener(new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animator) { FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) ivImageLarger .getLayoutParams(); layoutParams.setMargins(0, 0, 0, tweetActionsContainer.getTop()); ivImageLarger.setLayoutParams(layoutParams); ivImageLarger.setVisibility(View.VISIBLE); } @Override public void onAnimationEnd(Animator animator) { imageLargerDisplayed = true; } @Override public void onAnimationCancel(Animator animator) { } @Override public void onAnimationRepeat(Animator animator) { } }); animatorSet.playTogether(tweetInfoLayoutAnimator); animatorSet.start(); } }
From source file:com.klinker.android.twitter.activities.tweet_viewer.TweetPager.java
public void setUpWindow(boolean youtube) { requestWindowFeature(Window.FEATURE_ACTION_BAR | Window.FEATURE_PROGRESS); getWindow().setFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND, WindowManager.LayoutParams.FLAG_DIM_BEHIND); // Params for the window. // You can easily set the alpha and the dim behind the window from here WindowManager.LayoutParams params = getWindow().getAttributes(); params.alpha = 1.0f; // lower than one makes it more transparent if (!youtube) { params.dimAmount = .75f; // set it higher if you want to dim behind the window } else {// w w w.j av a2 s . co m params.dimAmount = 0f; } getWindow().setAttributes(params); // Gets the display size so that you can set the window to a percent of that Display display = getWindowManager().getDefaultDisplay(); Point size = new Point(); display.getSize(size); int width = size.x; int height = size.y; // You could also easily used an integer value from the shared preferences to set the percent if (height > width) { getWindow().setLayout((int) (width * .9), (int) (height * .8)); } else { getWindow().setLayout((int) (width * .7), (int) (height * .8)); } }
From source file:gov.sfmta.sfpark.AnnotationsOverlay.java
public void draw(Canvas canvas, MapView mapv, boolean shadow) { if (shadow) { return;//from w w w. j a va 2 s .c o m } Projection projection = mapv.getProjection(); Point from = new Point(); Point to = new Point(); Paint mPaint = new Paint(); mPaint.setStyle(Style.STROKE); mPaint.setAntiAlias(true); mPaint.setStrokeWidth(6); mPaint.setStrokeCap(Paint.Cap.ROUND); // could have NPE: try { for (MyAnnotation a : MainScreenActivity.annotations) { if (a.onStreet) { projection.toPixels(a.nw, from); projection.toPixels(a.se, to); if (MainScreenActivity.showPrice) { mPaint.setColor(a.blockColorPrice); canvas.drawLine(from.x, from.y, to.x, to.y, mPaint); } else { // new: no more availability data on blockfaces. // mPaint.setColor(a.blockColorAvailability); } } } } catch (NullPointerException npe) { // oh sadface! just ignore. } super.draw(canvas, mapv, shadow); }
From source file:com.gm.goldencity.util.Utils.java
/** * Get Display Width//from w ww . j a v a 2 s .c o m * * @param context Application context * @return */ @SuppressLint("NewApi") @SuppressWarnings("deprecation") public static int getDisplayWidth(Context context) { Activity activity = (Activity) context; if (Integer.valueOf(Build.VERSION.SDK_INT) < 13) { Display display = activity.getWindowManager().getDefaultDisplay(); return display.getWidth(); } else { Display display = activity.getWindowManager().getDefaultDisplay(); Point size = new Point(); display.getSize(size); return size.x; } }
From source file:com.nononsenseapps.feeder.ui.ReaderFragment.java
/** * Instantiate and return a new Loader for the given ID. * * @param id The ID whose loader is to be created. * @param args Any arguments supplied by the caller. * @return Return a new Loader instance that is ready to start loading. *//* w ww. j a v a 2 s. c o m*/ @Override public Loader<Spanned> onCreateLoader(final int id, final Bundle args) { Point size = new Point(); getActivity().getWindowManager().getDefaultDisplay().getSize(size); // Using twice window height since we do scroll vertically if (TabletUtils.isTablet(getActivity())) { // Tablet has fixed width return new ImageTextLoader(getActivity(), mRssItem.description, new Point(Math.round(getResources().getDimension(R.dimen.reader_tablet_width)), 2 * size.y)); } else { // Base it on window size return new ImageTextLoader(getActivity(), mRssItem.description, new Point(size.x - 2 * Math.round(getResources().getDimension(R.dimen.keyline_1)), 2 * size.y)); } }
From source file:com.zertinteractive.wallpaper.activities.DetailActivity.java
@SuppressWarnings("ConstantConditions") @Override/*from www . j a v a2 s . c om*/ protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); initActivityTransitions(); setContentView(R.layout.activity_detail); String[] projection = { MediaStore.Images.Media._ID, MediaStore.Images.Media.BUCKET_DISPLAY_NAME, MediaStore.Images.Media.DISPLAY_NAME }; String selection = MediaStore.Images.Media.BUCKET_DISPLAY_NAME + " = ?"; String[] selectionArgs = new String[] { TEMP_WALLPAPER_DIR }; Cursor mImageCursor = getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, projection, selection, selectionArgs, null); mImageCursor.moveToFirst(); if (mImageCursor.getCount() == 1) { imageId = mImageCursor.getInt((mImageCursor.getColumnIndex(MediaStore.Images.Media._ID))); Log.e("CROP", "" + imageId); mImageCursor.close(); } checkDir(); timerTasks = new TimerTasks(context); ViewCompat.setTransitionName(findViewById(R.id.app_bar_layout), EXTRA_IMAGE_SMALL); supportPostponeEnterTransition(); superCategory = getIntent().getExtras().getInt(EXTRA_SUPER_CATEGORY); floatingActionButton = (FloatingActionButton) findViewById(R.id.fab_set_as_wallpaper); floatingActionButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { setAsWallpaper(imageId); } }); toolbar = ((Toolbar) findViewById(R.id.toolbar)); setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); toolbar.setVisibility(View.GONE); String itemTitle = getIntent().getStringExtra(EXTRA_TITLE); progressBar = (ProgressBar) findViewById(R.id.progressBarImage); collapsingToolbarLayout = (CollapsingToolbarLayout) findViewById(R.id.collapsing_toolbar); collapsingToolbarLayout.setTitle(itemTitle); collapsingToolbarLayout.setExpandedTitleColor(getResources().getColor(android.R.color.transparent)); imageView = (ImageView) findViewById(R.id.image); Picasso.with(this).load(getIntent().getStringExtra(EXTRA_IMAGE_SMALL)).into(imageView, new Callback() { @SuppressWarnings("NewApi") @Override public void onSuccess() { Bitmap bitmap = ((BitmapDrawable) imageView.getDrawable()).getBitmap(); float ImageHieghtTemp = bitmap.getHeight(); float ImageWidthTemp = bitmap.getWidth(); Point size = new Point(); WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); wm.getDefaultDisplay().getRealSize(size); float widthMain = size.x; float heightMain = size.y; imageView.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED); int addWidth = imageView.getMeasuredWidth(); // Display display = getWindowManager().getDefaultDisplay(); // float widthMain = display.getWidth(); // float heightMain = display.getHeight(); Log.e(LOG_TAG, "IMAGE_MAIN : " + ImageWidthTemp + " : " + ImageHieghtTemp); float imageHeight = widthMain * ((float) (bitmap.getHeight()) / (float) (bitmap.getWidth())); float scaleXY = heightMain / imageHeight; if (scaleXY > 1.0007f) { Log.e(LOG_TAG, "SCALE FACTORE : " + scaleXY + " : " + 1.10454545f * scaleXY); scaleXY = 1.8f * scaleXY; } PhotoViewAttacher mAttacherTest = new PhotoViewAttacher(imageView, true, false); mAttacherTest.setZoomScale(scaleXY); mAttacherTest.setScale(scaleXY, (widthMain) / 2, heightMain / 2, true); Log.e(LOG_TAG, "DETAILS : " + widthMain + " : " + heightMain + " : " + scaleXY + " : " + bitmap.getWidth() + " : " + bitmap.getHeight()); Palette.from(bitmap).generate(new Palette.PaletteAsyncListener() { public void onGenerated(Palette palette) { applyPalette(palette); } }); } @Override public void onError() { } }); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { Window w = getWindow(); w.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION, WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION); w.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS, WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); } // clearApplicationData(); new ImageLoadTask().execute(""); initDownloadComponents(); mAdView = (AdView) findViewById(R.id.adViewFullImage); mAdView.setVisibility(View.GONE); AdRequest adRequest = new AdRequest.Builder().addTestDevice(AdRequest.DEVICE_ID_EMULATOR).build(); // Start loading the ad in sthe background. mAdView.loadAd(adRequest); mAdView.setAdListener(new AdListener() { @Override public void onAdLoaded() { super.onAdLoaded(); mAdView.setVisibility(View.VISIBLE); } }); }
From source file:Main.java
public static int getDisplayWidth(Activity activity) { int width = 0; if (activity != null && activity.getWindowManager() != null && activity.getWindowManager().getDefaultDisplay() != null) { Point point = new Point(); activity.getWindowManager().getDefaultDisplay().getSize(point); width = point.x;//from w ww .j a v a2s . c o m } return width; }
From source file:Main.java
public static int getDisplayHeight(Activity activity) { int height = 0; if (activity != null && activity.getWindowManager() != null && activity.getWindowManager().getDefaultDisplay() != null) { Point point = new Point(); activity.getWindowManager().getDefaultDisplay().getSize(point); height = point.y;/*w w w. ja va 2s . c o m*/ } Log.e(TAG, "isSupportSmartBar:" + isSupportSmartBar); if (isSupportSmartBar) { int smartBarHeight = getSmartBarHeight(activity); Log.e(TAG, "smartBarHeight:" + smartBarHeight); height -= smartBarHeight; } if (activity != null && activity.getActionBar() != null) { int actionbar = activity.getActionBar().getHeight(); if (actionbar == 0) { TypedArray actionbarSizeTypedArray = activity .obtainStyledAttributes(new int[] { android.R.attr.actionBarSize }); actionbar = (int) actionbarSizeTypedArray.getDimension(0, 0); } Log.d(TAG, "actionbar:" + actionbar); height -= actionbar; } int status = getStatusBarHeight(activity); Log.d(TAG, "status:" + status); height -= status; Log.d(TAG, "height:" + height); return height; }