Example usage for android.app Activity getWindowManager

List of usage examples for android.app Activity getWindowManager

Introduction

In this page you can find the example usage for android.app Activity getWindowManager.

Prototype

public WindowManager getWindowManager() 

Source Link

Document

Retrieve the window manager for showing custom windows.

Usage

From source file:com.uzmap.pkg.uzmodules.uzBMap.utils.JsParamsUtil.java

public int getScreenWidth(Activity act) {
    DisplayMetrics metric = new DisplayMetrics();
    act.getWindowManager().getDefaultDisplay().getMetrics(metric);
    return UZCoreUtil.pixToDip(metric.widthPixels);
}

From source file:com.uzmap.pkg.uzmodules.uzBMap.utils.JsParamsUtil.java

public int getScreenHeight(Activity act) {
    DisplayMetrics metric = new DisplayMetrics();
    act.getWindowManager().getDefaultDisplay().getMetrics(metric);
    return UZCoreUtil.pixToDip(metric.heightPixels);
}

From source file:com.ramsofttech.adpushlibrary.fragment.GridFragment.java

/**
 * onActivityCreated//from w  ww . j ava  2 s  . c  o  m
 * When the activity is created, divide the usable space into columns
 * and put a grid of images in that area.
 */

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    Activity a = getActivity();
    Resources res = a.getResources();

    View rootView = getView();
    GridView gridview = (GridView) rootView.findViewById(R.id.grid);

    DisplayMetrics metrics = new DisplayMetrics();
    a.getWindowManager().getDefaultDisplay().getMetrics(metrics);

    // From the resource files, determine how many rows and columns are to be displayed.
    int numRows = res.getInteger(R.integer.grid_num_rows);
    int numCols = res.getInteger(R.integer.grid_num_cols);
    AppDataHolder dataHolder = ((AppDataHolder) getActivity().getApplicationContext());
    if (dataHolder.getNumCols() != 0)
        numCols = dataHolder.getNumCols();
    if (dataHolder.getNumRows() != 0)
        numRows = dataHolder.getNumRows();
    // Figure out how much space is available for the N rows and M columns to be displayed.
    // We start with the root view for the fragment and adjust for the title, padding, etc.
    int titleHeight = res.getDimensionPixelSize(R.dimen.topic_title_height);
    int titlePadding = res.getDimensionPixelSize(R.dimen.topic_title_padding);
    int buttonAreaHeight = res.getDimensionPixelSize(R.dimen.button_area_height);
    int titleBarHeight = res.getDimensionPixelSize(R.dimen.title_bar_height);
    int gridHspacing = res.getDimensionPixelSize(R.dimen.image_grid_hspacing);
    int gridVSpacing = res.getDimensionPixelSize(R.dimen.image_grid_vspacing);
    int otherGridH = res.getDimensionPixelSize(R.dimen.other_grid_h);
    int otherGridW = res.getDimensionPixelSize(R.dimen.other_grid_w);
    int heightUsed = 2 * titleBarHeight + (numRows + 2) * gridVSpacing + (titleHeight + 2 * titlePadding)
            + otherGridH + buttonAreaHeight;

    int widthUsed = 40; // just a guess for now.
    int availableHeight = metrics.heightPixels - heightUsed;
    int availableWidth = metrics.widthPixels - widthUsed;
    int cellWidth = availableWidth / numCols;
    if (availableWidth > 1000) {
        cellWidth -= 20;
    }

    float cellHeight = numRows * (availableHeight / numRows) / 6;
    if (dataHolder.getCellHeight() != 0) {
        cellHeight = numRows * (availableHeight / numRows) / dataHolder.getCellHeight();
    }

    // Put this back in to check the calculations for cell height and width.
    Log.d("Debug", "--- metrics h: " + metrics.heightPixels + "  w: " + metrics.widthPixels);
    Log.d("Debug", "    available h: " + availableHeight + "  w: " + availableWidth);
    Log.d("Debug", "    already used h: " + heightUsed + "  w: " + widthUsed);
    Log.d("Debug", "    cell h: " + cellHeight + "  w: " + cellWidth);
    Log.d("Debug", "--- num rows: " + numRows + "  cols: " + numCols);
    Log.d("Debug", "--- firstImage: " + mFirstImage + " image count: " + mImageCount);

    if (gridview == null)
        Log.d("DEBUG", "Unable to locate the gridview.");
    else {
        Log.i("Adapter", "--inside call appadapter");
        //  AppDataHolder dataHolder = ((AppDataHolder) getActivity().getApplication());
        gridview.setNumColumns(numCols);
        // Connect the gridview with an adapter that fills up the space.
        //     gridview.setAdapter (new GridImageAdapter (a, mTopicList, mFirstImage, mImageCount, cellWidth, cellHeight));
        gridview.setAdapter(new AppAdapter(a, dataHolder.getApplicationList(), mFirstImage, mImageCount,
                cellWidth, cellHeight));

        // Arrange it so a long click on an item in the grid shows the topic associated with the image.
        gridview.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) {
                // TODO Auto-generated method stub
                //showTopic(mFirstImage + position);
                Toast.makeText(getActivity(), "" + (mFirstImage + position), Toast.LENGTH_LONG).show();

                clickAsyncTask clickAsynctask = new clickAsyncTask(getActivity());
                clickAsynctask.execute("" + (mFirstImage + position));

                AppDataHolder dataHolder = ((AppDataHolder) getActivity().getApplication());
                List<ApplicationData> applicationList = dataHolder.getApplicationList();
                ApplicationData application = applicationList.get(mFirstImage + position);
                startActivity(new Intent(Intent.ACTION_VIEW,
                        Uri.parse("market://details?id=" + application.getPackageName())));
            }
        });

    }
}

From source file:org.videolan.vlc2.gui.video.VideoGridFragment.java

private boolean hasSpaceForGrid(View v) {
    final Activity activity = getActivity();
    if (activity == null)
        return true;

    DisplayMetrics outMetrics = new DisplayMetrics();
    activity.getWindowManager().getDefaultDisplay().getMetrics(outMetrics);

    final int itemWidth = Util.convertDpToPx(GRID_ITEM_WIDTH_DP);
    final int horizontalspacing = Util.convertDpToPx(GRID_HORIZONTAL_SPACING_DP);
    final int width = mGridView.getPaddingLeft() + mGridView.getPaddingRight() + horizontalspacing
            + (itemWidth * 2);//from   w  ww  .j  ava  2s .  c  o m
    if (width < outMetrics.widthPixels)
        return true;
    return false;
}

From source file:com.digitalvotingpass.camera.CameraFragment.java

/**
 * Configures the necessary {@link android.graphics.Matrix} transformation to `mTextureView`.
 * This method should be called after the camera preview size is determined in
 * setUpCameraOutputs and also the size of `mTextureView` is fixed.
 *
 * @param viewWidth  The width of `mTextureView`
 * @param viewHeight The height of `mTextureView`
 *//*from  w  ww  . ja  v a 2s  .  c o m*/
public void configureTransform(int viewWidth, int viewHeight) {
    Activity activity = getActivity();
    if (null == mTextureView || null == mPreviewSize || null == activity) {
        return;
    }
    int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
    Matrix matrix = new Matrix();
    RectF viewRect = new RectF(0, 0, viewWidth, viewHeight);
    RectF bufferRect = new RectF(0, 0, mPreviewSize.getHeight(), mPreviewSize.getWidth());
    float centerX = viewRect.centerX();
    float centerY = viewRect.centerY();
    if (Surface.ROTATION_90 == rotation || Surface.ROTATION_270 == rotation) {
        bufferRect.offset(centerX - bufferRect.centerX(), centerY - bufferRect.centerY());
        matrix.setRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.FILL);
        float scale = Math.max((float) viewHeight / mPreviewSize.getHeight(),
                (float) viewWidth / mPreviewSize.getWidth());
        matrix.postScale(scale, scale, centerX, centerY);
        matrix.postRotate(90 * (rotation - 2), centerX, centerY);
    } else if (Surface.ROTATION_180 == rotation) {
        matrix.postRotate(180, centerX, centerY);
    }
    mTextureView.setTransform(matrix);
    overlay.setRect(CameraFragmentUtil.getScanRect(scanSegment));
}

From source file:org.videolan.vlc.gui.video.VideoGridFragment.java

private boolean hasSpaceForGrid(View v) {
    final Activity activity = getActivity();
    if (activity == null)
        return true;

    final GridView grid = (GridView) v.findViewById(android.R.id.list);

    DisplayMetrics outMetrics = new DisplayMetrics();
    activity.getWindowManager().getDefaultDisplay().getMetrics(outMetrics);

    final int itemWidth = Util.convertDpToPx(GRID_ITEM_WIDTH_DP);
    final int horizontalspacing = Util.convertDpToPx(GRID_HORIZONTAL_SPACING_DP);
    final int width = grid.getPaddingLeft() + grid.getPaddingRight() + horizontalspacing + (itemWidth * 2);
    if (width < outMetrics.widthPixels)
        return true;
    return false;
}

From source file:org.solovyev.android.calculator.ActivityUi.java

private void addHelpInfo(@Nonnull Activity activity, @Nonnull View root) {
    if (CalculatorApplication.isMonkeyRunner(activity)) {
        if (root instanceof ViewGroup) {
            final TextView helperTextView = new TextView(activity);

            final DisplayMetrics dm = new DisplayMetrics();
            activity.getWindowManager().getDefaultDisplay().getMetrics(dm);

            helperTextView.setTextSize(15);
            helperTextView.setTextColor(Color.WHITE);

            final Configuration c = activity.getResources().getConfiguration();

            final StringBuilder helpText = new StringBuilder();
            helpText.append("Size: ");
            if (Views.isLayoutSizeAtLeast(Configuration.SCREENLAYOUT_SIZE_XLARGE, c)) {
                helpText.append("xlarge");
            } else if (Views.isLayoutSizeAtLeast(Configuration.SCREENLAYOUT_SIZE_LARGE, c)) {
                helpText.append("large");
            } else if (Views.isLayoutSizeAtLeast(Configuration.SCREENLAYOUT_SIZE_NORMAL, c)) {
                helpText.append("normal");
            } else if (Views.isLayoutSizeAtLeast(Configuration.SCREENLAYOUT_SIZE_SMALL, c)) {
                helpText.append("small");
            } else {
                helpText.append("unknown");
            }/*www  .  ja v  a 2s.c  om*/

            helpText.append(" (").append(dm.widthPixels).append("x").append(dm.heightPixels).append(")");

            helpText.append(" Density: ");
            switch (dm.densityDpi) {
            case DisplayMetrics.DENSITY_LOW:
                helpText.append("ldpi");
                break;
            case DisplayMetrics.DENSITY_MEDIUM:
                helpText.append("mdpi");
                break;
            case DisplayMetrics.DENSITY_HIGH:
                helpText.append("hdpi");
                break;
            case DisplayMetrics.DENSITY_XHIGH:
                helpText.append("xhdpi");
                break;
            case DisplayMetrics.DENSITY_TV:
                helpText.append("tv");
                break;
            }

            helpText.append(" (").append(dm.densityDpi).append(")");

            helperTextView.setText(helpText);

            ((ViewGroup) root).addView(helperTextView, new ViewGroup.LayoutParams(
                    ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
        }
    }
}

From source file:com.mappn.gfan.ui.HomeTabActivity.java

private void drawUpdateCount(Activity context, Resources res, ImageView view, boolean flag) {
    DisplayMetrics dm = new DisplayMetrics();
    context.getWindowManager().getDefaultDisplay().getMetrics(dm);
    Bitmap cornerRes = BitmapFactory.decodeResource(res, R.drawable.notify_update);
    Bitmap appBitmapNormal = BitmapFactory.decodeResource(res, R.drawable.main_tab_app_unselect);
    Bitmap appBitmapPressed = BitmapFactory.decodeResource(res, R.drawable.main_tab_app_select);

    StateListDrawable stateDrawable = new StateListDrawable();
    int stateSelected = android.R.attr.state_selected;
    if (flag) {/*from   w  w  w. ja  v  a2s  . co m*/
        Bitmap cornerBitmap = drawText(dm, res, cornerRes, mSession.getUpgradeNumber());
        Bitmap newBitmapNormal = drawBitmap(dm, appBitmapNormal, cornerBitmap);
        Bitmap newBitmapPressed = drawBitmap(dm, appBitmapPressed, cornerBitmap);

        stateDrawable.addState(new int[] { -stateSelected }, new BitmapDrawable(res, newBitmapNormal));
        stateDrawable.addState(new int[] { stateSelected }, new BitmapDrawable(res, newBitmapPressed));

        view.setImageDrawable(stateDrawable);
    } else {

        view.setImageResource(R.drawable.main_tab_app_manager_selector);
    }
}

From source file:com.tzutalin.dlibtest.CameraConnectionFragment.java

/**
 * Configures the necessary {@link android.graphics.Matrix} transformation to `mTextureView`.
 * This method should be called after the camera preview size is determined in
 * setUpCameraOutputs and also the size of `mTextureView` is fixed.
 *
 * @param viewWidth  The width of `mTextureView`
 * @param viewHeight The height of `mTextureView`
 *///from   ww  w  . j a  v  a  2s .  co  m
@DebugLog
private void configureTransform(final int viewWidth, final int viewHeight) {
    final Activity activity = getActivity();
    if (null == textureView || null == previewSize || null == activity) {
        return;
    }
    final int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
    final Matrix matrix = new Matrix();
    final RectF viewRect = new RectF(0, 0, viewWidth, viewHeight);
    final RectF bufferRect = new RectF(0, 0, previewSize.getHeight(), previewSize.getWidth());
    final float centerX = viewRect.centerX();
    final float centerY = viewRect.centerY();
    if (Surface.ROTATION_90 == rotation || Surface.ROTATION_270 == rotation) {
        bufferRect.offset(centerX - bufferRect.centerX(), centerY - bufferRect.centerY());
        matrix.setRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.FILL);
        final float scale = Math.max((float) viewHeight / previewSize.getHeight(),
                (float) viewWidth / previewSize.getWidth());
        matrix.postScale(scale, scale, centerX, centerY);
        matrix.postRotate(90 * (rotation - 2), centerX, centerY);
    } else if (Surface.ROTATION_180 == rotation) {
        matrix.postRotate(180, centerX, centerY);
    }
    textureView.setTransform(matrix);
}

From source file:com.example.android.tflitecamerademo.Camera2BasicFragment.java

/**
 * Configures the necessary {@link android.graphics.Matrix} transformation to `textureView`. This
 * method should be called after the camera preview size is determined in setUpCameraOutputs and
 * also the size of `textureView` is fixed.
 *
 * @param viewWidth The width of `textureView`
 * @param viewHeight The height of `textureView`
 *//*from  w  w w .java2s . c o m*/
private void configureTransform(int viewWidth, int viewHeight) {
    Activity activity = getActivity();
    if (null == textureView || null == previewSize || null == activity) {
        return;
    }
    int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
    Matrix matrix = new Matrix();
    RectF viewRect = new RectF(0, 0, viewWidth, viewHeight);
    RectF bufferRect = new RectF(0, 0, previewSize.getHeight(), previewSize.getWidth());
    float centerX = viewRect.centerX();
    float centerY = viewRect.centerY();
    if (Surface.ROTATION_90 == rotation || Surface.ROTATION_270 == rotation) {
        bufferRect.offset(centerX - bufferRect.centerX(), centerY - bufferRect.centerY());
        matrix.setRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.FILL);
        float scale = Math.max((float) viewHeight / previewSize.getHeight(),
                (float) viewWidth / previewSize.getWidth());
        matrix.postScale(scale, scale, centerX, centerY);
        matrix.postRotate(90 * (rotation - 2), centerX, centerY);
    } else if (Surface.ROTATION_180 == rotation) {
        matrix.postRotate(180, centerX, centerY);
    }
    textureView.setTransform(matrix);
}