Java Code Examples for android.view.Display

The following are top voted examples for showing how to use android.view.Display. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: PresenterLite   File: DisplayInfoHelper.java   View source code 7 votes vote down vote up
public static void populate(Context context, View view, Display display) {
    View da = view.findViewById(R.id.display_attributes);
    Resources res = context.getResources();
    if (da != null) {
        DisplayMetrics metrics = new DisplayMetrics();
        display.getMetrics(metrics);
        ((TextView) da.findViewById(R.id.density))
                .setText(String.format("%s (%f)",
                        res.getString(R.string.density), metrics.density));
        ((TextView) da.findViewById(R.id.size)).setText(res
                .getString(R.string.size));
        ((TextView) da.findViewById(R.id.dimensions))
                .setText(String
                        .format("%dx%d (%dx%d)",
                                metrics.widthPixels,
                                metrics.heightPixels,
                                (int) ((float) metrics.widthPixels / metrics.density),
                                (int) ((float) metrics.heightPixels / metrics.density)));
    }
}
 
Example 2
Project: QRCodeScanner   File: BarcodeScanView.java   View source code 6 votes vote down vote up
private void init() {
    // init surfaceholder
    SurfaceHolder holder = getHolder();
    holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
    holder.addCallback(this);

    WindowManager manager = (WindowManager) getContext().getSystemService(
            Context.WINDOW_SERVICE);
    Display display = manager.getDefaultDisplay();
    screenWidth = display.getWidth();
    screenHeight = display.getHeight();
    int width = screenWidth >= screenHeight ? screenWidth : screenHeight;
    int height = screenWidth + screenHeight - width;
    int rotation = display.getRotation();
    mScanner = CameraScanner.getInstance();
    mScanner.setRotation(0);  //此处直接设为0,配合竖屏展示
    mScanner.setReqSize(width, height);

}
 
Example 3
Project: Bigbang   File: ViewUtil.java   View source code 6 votes vote down vote up
public static boolean isNavigationBarShow(Activity activity){
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        Display display = activity.getWindowManager().getDefaultDisplay();
        Point size = new Point();
        Point realSize = new Point();
        display.getSize(size);
        display.getRealSize(realSize);
        return realSize.y!=size.y;
    }else {
        boolean menu = ViewConfiguration.get(activity).hasPermanentMenuKey();
        boolean back = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_BACK);
        if(menu || back) {
            return false;
        }else {
            return true;
        }
    }
}
 
Example 4
Project: Bella-Android   File: MainActivity.java   View source code 6 votes vote down vote up
public void checkForUpdate() {
    //Check for update
    new AppUpdater(this)
            .setUpdateFrom(UpdateFrom.XML)
            .setUpdateXML("https://raw.githubusercontent.com/Bella-Assistant/Bella-Android/alpha/update-changelog.xml")
            .setTitleOnUpdateNotAvailable("Update not available")
            .setContentOnUpdateNotAvailable("No update available. Check for updates again later!")
            .setDisplay(com.github.javiersantos.appupdater.enums.Display.DIALOG)
            .showAppUpdated(true)
            .start();
}
 
Example 5
Project: NeoTerm   File: MainActivity.java   View source code 6 votes vote down vote up
public void setUpStatusLabel() {
    MainActivity Parent = this; // Too lazy to rename
    if (Parent._btn != null) {
        Parent._layout2.removeView(Parent._btn);
        Parent._btn = null;
    }
    if (Parent._tv == null) {
        //Get the display so we can know the screen size
        Display display = getWindowManager().getDefaultDisplay();
        int width = display.getWidth();
        int height = display.getHeight();
        Parent._tv = new TextView(Parent);
        Parent._tv.setMaxLines(2); // To show some long texts on smaller devices
        Parent._tv.setMinLines(2); // Otherwise the background picture is getting resized at random, which does not look good
        Parent._tv.setText(R.string.init);
        // Padding is a good idea because if the display device is a TV the edges might be cut off
        Parent._tv.setPadding((int) (width * 0.1), (int) (height * 0.1), (int) (width * 0.1), 0);
        Parent._layout2.addView(Parent._tv);
    }
}
 
Example 6
Project: KrGallery   File: AndroidUtilities.java   View source code 6 votes vote down vote up
public static void checkDisplaySize() {
    try {
        Configuration configuration = applicationContext.getResources()
                .getConfiguration();
        usingHardwareInput = configuration.keyboard != Configuration.KEYBOARD_NOKEYS
                && configuration.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_NO;
        WindowManager manager = (WindowManager) applicationContext
                .getSystemService(Context.WINDOW_SERVICE);
        if (manager != null) {
            Display display = manager.getDefaultDisplay();
            if (display != null) {
                display.getMetrics(displayMetrics);
                display.getSize(displaySize);
                Log.d("tmessages", "display size = " + displaySize.x + " " + displaySize.y + " "
                        + displayMetrics.xdpi + "x" + displayMetrics.ydpi);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example 7
Project: CalcMate   File: Calculator.java   View source code 6 votes vote down vote up
public void showFirstRunSimpleCling(boolean animate) {
    // Enable the clings only if they have not been dismissed before
    if(isClingsEnabled() && !CalculatorSettings.isDismissed(getContext(), Cling.SIMPLE_CLING_DISMISSED_KEY)) {
        Display display = getWindowManager().getDefaultDisplay();
        Point size = new Point();
        display.getSize(size);
        int[] location = new int[3];
        location[0] = 0;
        location[1] = size.y / 2;
        location[2] = 10;
        initCling(R.id.simple_cling, location, 0, true, animate);
    }
    else {
        removeCling(R.id.simple_cling);
    }
}
 
Example 8
Project: anyRTC-RTCP-Android   File: CameraConfigurationManager.java   View source code 6 votes vote down vote up
public void initFromCameraParameters(Camera camera) {
	Camera.Parameters parameters = camera.getParameters();
	WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
	Display display = manager.getDefaultDisplay();
	Point theScreenResolution = new Point();
	theScreenResolution = getDisplaySize(display);

	screenResolution = theScreenResolution;
	Log.i(TAG, "Screen resolution: " + screenResolution);

	/** 因为换成了竖屏显示,所以不替换屏幕宽高得出的预览图是变形的 */
	Point screenResolutionForCamera = new Point();
	screenResolutionForCamera.x = screenResolution.x;
	screenResolutionForCamera.y = screenResolution.y;

	if (screenResolution.x < screenResolution.y) {
		screenResolutionForCamera.x = screenResolution.y;
		screenResolutionForCamera.y = screenResolution.x;
	}

	cameraResolution = findBestPreviewSizeValue(parameters, screenResolutionForCamera);
	Log.i(TAG, "Camera resolution x: " + cameraResolution.x);
	Log.i(TAG, "Camera resolution y: " + cameraResolution.y);
}
 
Example 9
Project: homebank_android   File: AppStoreInterstitial.java   View source code 6 votes vote down vote up
private static void centerWindow(Window w) {
    DisplayMetrics metrics = new DisplayMetrics();
    Display display = w.getWindowManager().getDefaultDisplay();
    display.getMetrics(metrics);

    int width = Math.min(metrics.widthPixels - (int) (2 * DLG_PADDING_DP * metrics.density),
            (int) (MAX_DIALOG_WIDTH_DP * metrics.density));
    int height = Math.min(metrics.heightPixels - (int) ((2 * DLG_PADDING_DP + APPROX_STATUSBAR_HEIGHT_DP) * metrics.density),
            (int) (MAX_DIALOG_HEIGHT_DP * metrics.density));

    int x = (metrics.widthPixels - width) / 2;
    int y = (metrics.heightPixels - height - ((int) (APPROX_STATUSBAR_HEIGHT_DP * metrics.density))) / 2;

    LayoutParams params = w.getAttributes();
    params.x = x;
    params.y = y;
    params.width = width;
    params.height = height;
    w.setAttributes(params);
    w.setGravity(Gravity.LEFT | Gravity.TOP);
}
 
Example 10
Project: MakiLite   File: QuickTwitter.java   View source code 6 votes vote down vote up
public void setUpWindow() {


        getWindow().setFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND,
                WindowManager.LayoutParams.FLAG_DIM_BEHIND);
        WindowManager.LayoutParams params = getWindow().getAttributes();
        params.alpha = 1.0f;
        params.dimAmount = 0.4f;
        getWindow().setAttributes(params);


        Display display = getWindowManager().getDefaultDisplay();
        Point size = new Point();
        display.getSize(size);
        int width = size.x;
        int height = size.y;


        if (height > width) {
            getWindow().setLayout((int) (width * .9), (int) (height * .7));
        } else {
            getWindow().setLayout((int) (width * .7), (int) (height * .8));
        }
    
    }
 
Example 11
Project: OSchina_resources_android   File: ShareDialogBuilder.java   View source code 6 votes vote down vote up
@SuppressWarnings("deprecation")
@Override
public AlertDialog create() {

    AlertDialog alertDialog = super.create();
    Window window = alertDialog.getWindow();

    if (window != null) {
        window.setGravity(Gravity.BOTTOM);
        WindowManager m = window.getWindowManager();
        Display d = m.getDefaultDisplay();
        WindowManager.LayoutParams p = window.getAttributes();
        p.width = d.getWidth();
        window.setAttributes(p);
    }
    this.mAlertDialog = alertDialog;
    return alertDialog;
}
 
Example 12
Project: ZxingScan   File: CameraConfigurationManager.java   View source code 6 votes vote down vote up
/**
 * Reads, one time, values from the camera that are needed by the app.
 */
void initFromCameraParameters(Camera camera) {
    Camera.Parameters parameters = camera.getParameters();
    previewFormat = parameters.getPreviewFormat();
    previewFormatString = parameters.get("preview-format");

    WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = manager.getDefaultDisplay();
    screenResolution = new Point(display.getWidth(), display.getHeight());

    Point screenResolutionForCamera = new Point();
    screenResolutionForCamera.x = screenResolution.x;
    screenResolutionForCamera.y = screenResolution.y;
    // preview size is always something like 480*320, other 320*480
    if (screenResolution.x < screenResolution.y) {
        screenResolutionForCamera.x = screenResolution.y;
        screenResolutionForCamera.y = screenResolution.x;
    }
    cameraResolution = getCameraResolution(parameters, screenResolutionForCamera);

}
 
Example 13
Project: Cable-Android   File: ConversationPopupActivity.java   View source code 6 votes vote down vote up
@Override
protected void onCreate(Bundle bundle, @NonNull MasterSecret masterSecret) {
  getWindow().setFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND,
                       WindowManager.LayoutParams.FLAG_DIM_BEHIND);

  WindowManager.LayoutParams params = getWindow().getAttributes();
  params.alpha     = 1.0f;
  params.dimAmount = 0.1f;
  params.gravity   = Gravity.TOP;
  getWindow().setAttributes(params);

  Display display = getWindowManager().getDefaultDisplay();
  int     width   = display.getWidth();
  int     height  = display.getHeight();

  if (height > width) getWindow().setLayout((int) (width * .85), (int) (height * .5));
  else                getWindow().setLayout((int) (width * .7), (int) (height * .75));

  super.onCreate(bundle, masterSecret);

  titleView.setOnClickListener(null);
}
 
Example 14
Project: social-login-helper   File: InstagramDialog.java   View source code 6 votes vote down vote up
@Override protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  mSpinner = new ProgressDialog(getContext());
  mSpinner.requestWindowFeature(Window.FEATURE_NO_TITLE);
  mSpinner.setMessage("Loading...");
  mContent = new LinearLayout(getContext());
  mContent.setOrientation(LinearLayout.VERTICAL);
  setUpTitle();
  setUpWebView();
  Display display = getWindow().getWindowManager().getDefaultDisplay();
  final float scale = getContext().getResources().getDisplayMetrics().density;
  float[] dimensions =
      (display.getWidth() < display.getHeight()) ? DIMENSIONS_PORTRAIT : DIMENSIONS_LANDSCAPE;
  addContentView(mContent, new FrameLayout.LayoutParams((int) (dimensions[0] * scale + 0.5f),
      (int) (dimensions[1] * scale + 0.5f)));
  CookieSyncManager.createInstance(getContext());
  CookieManager cookieManager = CookieManager.getInstance();
  cookieManager.removeAllCookie();
}
 
Example 15
Project: pc-android-controller-android   File: MotionClickService.java   View source code 6 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();

    L.d("MotionClickService is create ");

    DisplayMetrics dm = new DisplayMetrics();
    Display mDisplay = ((WindowManager) getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
    mDisplay.getMetrics(dm);
    deviceWidth = dm.widthPixels;
    deviceHeight = dm.heightPixels;

    initSocket();

    EventBus.getDefault().register(this);
}
 
Example 16
Project: emerald   File: Themer.java   View source code 6 votes vote down vote up
public static void setWindowDecorations(Activity activity, SharedPreferences options) {
	if (Build.VERSION.SDK_INT >= 21) {
		activity.getWindow().setStatusBarColor(options.getInt(Keys.STATUS_BAR_BACKGROUND, 0x22000000));
		activity.getWindow().setNavigationBarColor(options.getInt(Keys.NAV_BAR_BACKGROUND, 0x22000000));
	} else {
		activity.findViewById(R.id.dummy_top_view).setBackgroundColor(options.getInt(Keys.BAR_BACKGROUND, 0x22000000));
		Display display = ((WindowManager)activity.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
		Point size = new Point();
		Point realSize = new Point();
		display.getSize(size);
		display.getRealSize(realSize);
		int navBarHeight = size.y-realSize.y;
		View dummyBottomView = activity.findViewById(R.id.dummy_bottom_view);
		ViewGroup.LayoutParams p = dummyBottomView.getLayoutParams();
		p.height = navBarHeight;
		dummyBottomView.setLayoutParams(p);
		if (navBarHeight > 0) {
			dummyBottomView.setVisibility(View.VISIBLE);
			dummyBottomView.setBackgroundColor(options.getInt(Keys.NAV_BAR_BACKGROUND, 0x22000000));
		}
	}
}
 
Example 17
Project: DailyZhiHu   File: SlidingMenu.java   View source code 6 votes vote down vote up
/**
 * Sets the behind width.
 *
 * @param i The width the Sliding Menu will open to, in pixels
 */
@SuppressWarnings("deprecation")
public void setBehindWidth(int i) {
	int width;
	Display display = ((WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE))
			.getDefaultDisplay();
	try {
		Class<?> cls = Display.class;
		Class<?>[] parameterTypes = {Point.class};
		Point parameter = new Point();
		Method method = cls.getMethod("getSize", parameterTypes);
		method.invoke(display, parameter);
		width = parameter.x;
	} catch (Exception e) {
		width = display.getWidth();
	}
	setBehindOffset(width-i);
}
 
Example 18
Project: Coder   File: BaseFragment.java   View source code 6 votes vote down vote up
@DoMain
public void showLoadingDialog(String msg) {
    String content = null;
    if (msg == null) {
        content = "正在与服务器交互,请稍后.....";
    } else {
        content = msg;
    }
    View view = View.inflate(activity, R.layout.view_loading_dialog, null);
    ((TextView) view.findViewById(R.id.view_loading_dialog_desc)).setText(content);
    alertDialog = new AlertDialog.Builder(activity)
            .setView(view)
            .create();
    alertDialog.show();
    WindowManager m = activity.getWindowManager();
    Display d = m.getDefaultDisplay();
    Window dialogWindow = alertDialog.getWindow();
    WindowManager.LayoutParams p = dialogWindow.getAttributes();
    p.width = (int) (d.getWidth() * 0.8);
    dialogWindow.setAttributes(p);
}
 
Example 19
Project: AndroidOCRFforID   File: TransformImageView.java   View source code 6 votes vote down vote up
/**
 * This method calculates maximum size of both width and height of bitmap.
 * It is the device screen diagonal for default implementation.
 *
 * @return - max bitmap size in pixels.
 */
@SuppressWarnings({"SuspiciousNameCombination", "deprecation"})
protected int calculateMaxBitmapSize() {
    WindowManager wm = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();

    Point size = new Point();
    int width, height;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
        display.getSize(size);
        width = size.x*2;
        height = size.y*2;
    } else {
        width = display.getWidth();
        height = display.getHeight();
    }
    return (int) Math.sqrt(Math.pow(width, 2) + Math.pow(height, 2));
}
 
Example 20
Project: ChemistryEasy   File: OrdinaryTable.java   View source code 6 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.ordinary_table_layout, container, false);
    Display display = getActivity().getWindowManager().getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    width = size.x;
    height = size.y;
    x_size = (int) Math.floor((double)width / X_CROP);
    y_size = (int) Math.floor((double)height / Y_CROP);
    //calc of X margin
    int x_margin = (width - x_size*18) /2;
    view.setPadding(x_margin,x_margin,x_margin,x_margin);
    Ui_init(view);
    return view;
}
 
Example 21
Project: QuranAndroid   File: MainActivity.java   View source code 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_splashscreen_main);

    Display display = getWindowManager().getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);

    //marshmallow check permission permissions
    boolean hasPermission = (ContextCompat.checkSelfPermission(this,
            Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED);
    if (!hasPermission) {
        ActivityCompat.requestPermissions(this,
                new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
                REQUEST_WRITE_STORAGE);
    } else {
        validateFilesAndDownload();
    }

}
 
Example 22
Project: ChatExchange-old   File: SlidingMenu.java   View source code 6 votes vote down vote up
/**
 * Sets the behind width.
 *
 * @param i The width the Sliding Menu will open to, in pixels
 */
@SuppressWarnings("deprecation")
public void setBehindWidth(int i)
{
    int width;
    Display display = ((WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE))
            .getDefaultDisplay();
    try
    {
        Class<?> cls = Display.class;
        Class<?>[] parameterTypes = {Point.class};
        Point parameter = new Point();
        Method method = cls.getMethod("getSize", parameterTypes);
        method.invoke(display, parameter);
        width = parameter.x;
    }
    catch (Exception e)
    {
        width = display.getWidth();
    }
    setBehindOffset(width - i);
}
 
Example 23
Project: nightmode   File: Utility.java   View source code 6 votes vote down vote up
public static int getTrueScreenHeight(Context context) {
    int dpi = 0;
    Display display = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
    DisplayMetrics dm = new DisplayMetrics();
    if (Build.VERSION.SDK_INT >= 17) {
        display.getRealMetrics(dm);
        dpi = dm.heightPixels;
    } else {
        try {
            Class c = Class.forName("android.view.Display");
            Method method = c.getMethod("getRealMetrics", DisplayMetrics.class);
            method.invoke(display, dm);
            dpi = dm.heightPixels;
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    return dpi;
}
 
Example 24
Project: Selector   File: QuickOptionDialog.java   View source code 6 votes vote down vote up
@Override

  protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    getWindow().setGravity(Gravity.BOTTOM);
    //getWindow().setNavigationBarColor(Color.TRANSPARENT);
    WindowManager windowManager = getWindow().getWindowManager();

    Display display = windowManager.getDefaultDisplay();
    WindowManager.LayoutParams layoutParams = getWindow().getAttributes();
    layoutParams.width = display.getWidth();
    getWindow().setAttributes(layoutParams);

    mShare.setOnClickListener(this);
    saveLocal.setOnClickListener(this);
    collection.setOnClickListener(this);
    // mPresent = new ImageBrowsePresenter(this);
  }
 
Example 25
Project: AirPanel   File: MainActivity.java   View source code 6 votes vote down vote up
public static Point getRealScreenSize(Context context) {
    WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = windowManager.getDefaultDisplay();
    Point size = new Point();

    if (Build.VERSION.SDK_INT >= 17) {
        display.getRealSize(size);
    } else {
        try {
            size.x = (Integer) Display.class.getMethod("getRawWidth").invoke(display);
            size.y = (Integer) Display.class.getMethod("getRawHeight").invoke(display);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    return size;
}
 
Example 26
Project: yyox   File: UserPhoneActivity.java   View source code 6 votes vote down vote up
/**
 * 获得手机屏幕宽高
 * @return
 */
public String getHeightAndWidth(){
    WindowManager windowManager = getWindowManager();
    Display display = windowManager.getDefaultDisplay();
    int screenWidth = display.getWidth();
    int screenHeight = display.getHeight();
    dm = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(dm);

    //获得手机的宽带和高度像素单位为px
    String str = "\n手机屏幕分辨率为1:" + dm.widthPixels
            +" * "+ dm.heightPixels
    +"\n手机屏幕分辨率为2:" + screenWidth
            +" * "+ screenHeight;
    return str;
}
 
Example 27
Project: Hitalk   File: CameraConfigurationManager.java   View source code 6 votes vote down vote up
public void initFromCameraParameters(Camera camera) {
    Camera.Parameters parameters = camera.getParameters();
    WindowManager manager = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
    Display display = manager.getDefaultDisplay();
    mScreenResolution = new Point(display.getWidth(), display.getHeight());
    Point screenResolutionForCamera = new Point();
    screenResolutionForCamera.x = mScreenResolution.x;
    screenResolutionForCamera.y = mScreenResolution.y;

    // preview size is always something like 480*320, other 320*480
    if (mScreenResolution.x < mScreenResolution.y) {
        screenResolutionForCamera.x = mScreenResolution.y;
        screenResolutionForCamera.y = mScreenResolution.x;
    }

    cameraResolution = getCameraResolution(parameters, screenResolutionForCamera);
}
 
Example 28
Project: PeSanKita-android   File: ConversationPopupActivity.java   View source code 6 votes vote down vote up
@Override
protected void onCreate(Bundle bundle, @NonNull MasterSecret masterSecret) {
  getWindow().setFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND,
                       WindowManager.LayoutParams.FLAG_DIM_BEHIND);

  WindowManager.LayoutParams params = getWindow().getAttributes();
  params.alpha     = 1.0f;
  params.dimAmount = 0.1f;
  params.gravity   = Gravity.TOP;
  getWindow().setAttributes(params);

  Display display = getWindowManager().getDefaultDisplay();
  int     width   = display.getWidth();
  int     height  = display.getHeight();

  if (height > width) getWindow().setLayout((int) (width * .85), (int) (height * .5));
  else                getWindow().setLayout((int) (width * .7), (int) (height * .75));

  super.onCreate(bundle, masterSecret);

  titleView.setOnClickListener(null);
}
 
Example 29
Project: redpacketui-open   File: ADPacketFragment.java   View source code 6 votes vote down vote up
private int getRealScreenHeight() {
    int height = 0;
    Display display = getActivity().getWindowManager().getDefaultDisplay();
    DisplayMetrics dm = new DisplayMetrics();
    @SuppressWarnings("rawtypes")
    Class c;
    try {
        c = Class.forName("android.view.Display");
        @SuppressWarnings("unchecked")
        Method method = c.getMethod("getRealMetrics", DisplayMetrics.class);
        method.invoke(display, dm);
        height = dm.heightPixels;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return height;
}
 
Example 30
Project: LuaViewPlayground   File: CameraConfigurationManager.java   View source code 6 votes vote down vote up
public void initFromCameraParameters(Camera camera) {
    Camera.Parameters parameters = camera.getParameters();
    WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = manager.getDefaultDisplay();
    Point theScreenResolution = new Point();
    theScreenResolution = getDisplaySize(display);

    screenResolution = theScreenResolution;
    Log.i(TAG, "Screen resolution: " + screenResolution);

    /** 因为换成了竖屏显示,所以不替换屏幕宽高得出的预览图是变形的 */
    Point screenResolutionForCamera = new Point();
    screenResolutionForCamera.x = screenResolution.x;
    screenResolutionForCamera.y = screenResolution.y;

    if (screenResolution.x < screenResolution.y) {
        screenResolutionForCamera.x = screenResolution.y;
        screenResolutionForCamera.y = screenResolution.x;
    }

    cameraResolution = findBestPreviewSizeValue(parameters, screenResolutionForCamera);
    Log.i(TAG, "Camera resolution x: " + cameraResolution.x);
    Log.i(TAG, "Camera resolution y: " + cameraResolution.y);
}
 
Example 31
Project: YZxing   File: CameraConfigurationManager.java   View source code 5 votes vote down vote up
/**
 * Reads, one time, values from the camera that are needed by the app.
 */
void initFromCameraParameters(OpenCamera camera) {
    Camera.Parameters parameters = camera.getCamera().getParameters();
    WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = manager.getDefaultDisplay();
    Point theScreenResolution = new Point();
    display.getSize(theScreenResolution);
    screenResolution = theScreenResolution;
    Log.i(TAG, "Screen resolution in current orientation: " + screenResolution);
    cameraResolution = CameraConfigurationUtils.findBestPreviewSizeValue(parameters, screenResolution);
    Log.i(TAG, "Camera resolution: " + cameraResolution);
    bestPreviewSize = CameraConfigurationUtils.findBestPreviewSizeValue(parameters, screenResolution);
    Log.i(TAG, "Best available preview size: " + bestPreviewSize);
}
 
Example 32
Project: recyclviewpagger   File: MainActivity.java   View source code 5 votes vote down vote up
private DisplayMetrics getDisplayMetrics() {
    Display display = getWindowManager().getDefaultDisplay();
    DisplayMetrics metrics = new DisplayMetrics();
    display.getMetrics(metrics);

    return metrics;
}
 
Example 33
Project: DailyStudy   File: Measure.java   View source code 5 votes vote down vote up
private static Point getAppUsableScreenSize(Context context) {
    WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = windowManager.getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    return size;
}
 
Example 34
Project: SmART-Form   File: PictureUtils.java   View source code 5 votes vote down vote up
/**
 * Get a BitmapDrawable from a local file that is scaled down
 * to fid the current Window size.
 */
@SuppressWarnings("deprecation")
public static BitmapDrawable getScaledDrawable(Activity a, String path) {
	Log.d(TAG, "Inside getScaledDrawable()");
	
	Display display = a.getWindowManager().getDefaultDisplay();
	float destWidth = display.getWidth();
	float destHeight = display.getHeight();
	
	// Read in the dimensions of the image on disk
	BitmapFactory.Options options = new BitmapFactory.Options();
	options.inJustDecodeBounds = true;
	BitmapFactory.decodeFile(path, options);
	
	float srcWidth = options.outWidth;
	float srcHeight = options.outHeight;
	
	Log.d(TAG, "srcWidth: " + srcWidth);
	Log.d(TAG, "srcHeight: " + srcHeight);
	
	int inSampleSize = 1;
	if( srcHeight > destHeight || srcWidth > destWidth) {
		if(srcWidth > srcHeight){
			inSampleSize = Math.round( srcHeight / destHeight );
		}
		else {
			inSampleSize = Math.round(srcWidth / destWidth);
		}
	}
	
	options = new BitmapFactory.Options();
	options.inSampleSize = inSampleSize;
	
	Log.d(TAG, "inSampleSize: " + inSampleSize);
	
	Bitmap bitmap = BitmapFactory.decodeFile(path, options);
	return new BitmapDrawable(a.getResources(), bitmap);
}
 
Example 35
Project: MeteorView   File: Utils.java   View source code 5 votes vote down vote up
public static int getScreenHeight(Context c) {
    if (screenHeight == 0) {
        WindowManager wm = (WindowManager) c.getSystemService(Context.WINDOW_SERVICE);
        Display display = wm.getDefaultDisplay();
        Point size = new Point();
        display.getSize(size);
        screenHeight = size.y;
    }

    return screenHeight;
}
 
Example 36
Project: FlickLauncher   File: Launcher.java   View source code 5 votes vote down vote up
private int mapConfigurationOriActivityInfoOri(int configOri) {
    final Display d = getWindowManager().getDefaultDisplay();
    int naturalOri = Configuration.ORIENTATION_LANDSCAPE;
    switch (d.getRotation()) {
    case Surface.ROTATION_0:
    case Surface.ROTATION_180:
        // We are currently in the same basic orientation as the natural orientation
        naturalOri = configOri;
        break;
    case Surface.ROTATION_90:
    case Surface.ROTATION_270:
        // We are currently in the other basic orientation to the natural orientation
        naturalOri = (configOri == Configuration.ORIENTATION_LANDSCAPE) ?
                Configuration.ORIENTATION_PORTRAIT : Configuration.ORIENTATION_LANDSCAPE;
        break;
    }

    int[] oriMap = {
            ActivityInfo.SCREEN_ORIENTATION_PORTRAIT,
            ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE,
            ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT,
            ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE
    };
    // Since the map starts at portrait, we need to offset if this device's natural orientation
    // is landscape.
    int indexOffset = 0;
    if (naturalOri == Configuration.ORIENTATION_LANDSCAPE) {
        indexOffset = 1;
    }
    return oriMap[(d.getRotation() + indexOffset) % 4];
}
 
Example 37
Project: GitHub   File: App.java   View source code 5 votes vote down vote up
public void getScreenSize() {
    WindowManager windowManager = (WindowManager) this.getSystemService(Context.WINDOW_SERVICE);
    DisplayMetrics dm = new DisplayMetrics();
    Display display = windowManager.getDefaultDisplay();
    display.getMetrics(dm);
    DIMEN_RATE = dm.density / 1.0F;
    DIMEN_DPI = dm.densityDpi;
    SCREEN_WIDTH = dm.widthPixels;
    SCREEN_HEIGHT = dm.heightPixels;
    if (SCREEN_WIDTH > SCREEN_HEIGHT) {
        int t = SCREEN_HEIGHT;
        SCREEN_HEIGHT = SCREEN_WIDTH;
        SCREEN_WIDTH = t;
    }
}
 
Example 38
Project: gmlrva   File: ViewUtils.java   View source code 5 votes vote down vote up
/**
 * Procedure meant to provide the device's screen height in pixels.
 * @param context the application's current {@link Context}.
 * @return an Integer value representing the device's screen height, in pixels.
 */
@IntRange(from = 0) public static int getDeviceScreenHeight(@NonNull final Context context) {
    synchronized (ViewUtils.class) {
        if (sDeviceScreenHeight == 0) {
            final WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
            if (windowManager != null) {
                final Display display = windowManager.getDefaultDisplay();
                final Point size = new Point();
                display.getSize(size);
                sDeviceScreenHeight = size.y;
            }
        }
    }
    return sDeviceScreenHeight;
}
 
Example 39
Project: GitHub   File: FloatingActionsMenu.java   View source code 5 votes vote down vote up
private void init(Context context, AttributeSet attributeSet) {
    mAddButtonPlusColor = getColor(android.R.color.white);
    mAddButtonColorNormal = getColor(android.R.color.holo_blue_dark);
    mAddButtonColorPressed = getColor(android.R.color.holo_blue_light);

    mButtonSpacing = (int) (getResources().getDimension(R.dimen.fab_actions_spacing) - getResources().getDimension(R.dimen.fab_shadow_radius) - getResources().getDimension(R.dimen.fab_shadow_offset));

    if (attributeSet != null) {
        TypedArray attr = context.obtainStyledAttributes(attributeSet, R.styleable.FloatingActionsMenu, 0, 0);
        if (attr != null) {
            try {
                mAddButtonPlusColor = attr.getColor(R.styleable.FloatingActionsMenu_addButtonPlusIconColor, getColor(android.R.color.white));
                mAddButtonColorNormal = attr.getColor(R.styleable.FloatingActionsMenu_addButtonColorNormal, getColor(android.R.color.holo_blue_dark));
                mAddButtonColorPressed = attr.getColor(R.styleable.FloatingActionsMenu_addButtonColorPressed, getColor(android.R.color.holo_blue_light));
                isHorizontal = attr.getBoolean(R.styleable.FloatingActionsMenu_addButtonIsHorizontal, false);
            } finally {
                attr.recycle();
            }
        }
    }
    WindowManager mWindowManager = (WindowManager)
            context.getSystemService(Context.WINDOW_SERVICE);
    Display display = mWindowManager.getDefaultDisplay();
    Point size = new Point();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
        display.getSize(size);
        mYHidden = size.y;
    } else mYHidden = display.getHeight();

    createAddButton(context);
}
 
Example 40
Project: TimeSkyBackground   File: SkyViewUtils.java   View source code 5 votes vote down vote up
public static int getScreenWidth(Context c) {
    WindowManager mWindowManager = (WindowManager)c.getSystemService(Context.WINDOW_SERVICE);
    Display mDisplay = mWindowManager.getDefaultDisplay();

    DisplayMetrics mMetrics = new DisplayMetrics();
    mDisplay.getMetrics(mMetrics);

    return mMetrics.widthPixels;
}