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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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;
}
 
Example 41
Project: RNLearn_Project1   File: DisplayMetricsHolder.java   Source Code and License 5 votes vote down vote up
public static void initDisplayMetrics(Context context) {
  DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
  DisplayMetricsHolder.setWindowDisplayMetrics(displayMetrics);

  DisplayMetrics screenDisplayMetrics = new DisplayMetrics();
  screenDisplayMetrics.setTo(displayMetrics);
  WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
  Assertions.assertNotNull(
      wm,
      "WindowManager is null!");
  Display display = wm.getDefaultDisplay();

  // Get the real display metrics if we are using API level 17 or higher.
  // The real metrics include system decor elements (e.g. soft menu bar).
  //
  // See: http://developer.android.com/reference/android/view/Display.html#getRealMetrics(android.util.DisplayMetrics)
  if (Build.VERSION.SDK_INT >= 17) {
    display.getRealMetrics(screenDisplayMetrics);
  } else {
    // For 14 <= API level <= 16, we need to invoke getRawHeight and getRawWidth to get the real dimensions.
    // Since react-native only supports API level 16+ we don't have to worry about other cases.
    //
    // Reflection exceptions are rethrown at runtime.
    //
    // See: http://stackoverflow.com/questions/14341041/how-to-get-real-screen-height-and-width/23861333#23861333
    try {
      Method mGetRawH = Display.class.getMethod("getRawHeight");
      Method mGetRawW = Display.class.getMethod("getRawWidth");
      screenDisplayMetrics.widthPixels = (Integer) mGetRawW.invoke(display);
      screenDisplayMetrics.heightPixels = (Integer) mGetRawH.invoke(display);
    } catch (InvocationTargetException | IllegalAccessException | NoSuchMethodException e) {
      throw new RuntimeException("Error getting real dimensions for API level < 17", e);
    }
  }
  DisplayMetricsHolder.setScreenDisplayMetrics(screenDisplayMetrics);
}
 
Example 42
Project: AndroidBasicLibs   File: CameraConfigurationManager.java   Source Code and License 5 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");
		Log.d(TAG, "Default preview format: " + previewFormat + '/' + previewFormatString);
		WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
		Display display = manager.getDefaultDisplay();
		screenResolution = new Point(display.getWidth(), display.getHeight());
		Log.d(TAG, "Screen resolution: " + screenResolution);

//		//Lemon add 扫描框修改,解决拉伸但导致成像模糊识别率很低。<<<<<<<<<<<<<<<<<<<<<<<<<<<< 
//		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;
//		}
		//Lemon add 扫描框修改,解决拉伸>>>>>>>>>>>>>>>>>>>>>>>>>>>>

		//Lemon 扫描框修改,解决拉伸但导致成像模糊识别率很低  screenResolution改为screenResolutionForCamera);<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
		cameraResolution = getCameraResolution(parameters, screenResolution);
		Log.d(TAG, "Camera resolution: " + screenResolution);
		//Lemon 扫描框修改,解决拉伸但导致成像模糊识别率很低   screenResolution改为screenResolutionForCamera);>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
	}
 
Example 43
Project: Tesseract-OCR-Scanner   File: ScreenUtils.java   Source Code and License 5 votes vote down vote up
public static Point getScreenResolution(Context context) {

        WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        Display display = manager.getDefaultDisplay();

        int width = display.getWidth();
        int height = display.getHeight();
        return new Point(width, height);
    }
 
Example 44
Project: gmlrva   File: ViewUtils.java   Source Code and License 5 votes vote down vote up
/**
 * Procedure meant to provide the device's screen width in pixels.
 * @param context the application's current {@link Context}.
 * @return an Integer value representing the device's screen width, in pixels.
 */
@IntRange(from = 0) public static int getDeviceScreenWidth(@NonNull final Context context) {
    synchronized (ViewUtils.class) {
        if (sDeviceScreenWidth == 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);
                sDeviceScreenWidth = size.x;
            }
        }
    }
    return sDeviceScreenWidth;
}
 
Example 45
Project: GitHub   File: RecyclerAdapter.java   Source Code and License 5 votes vote down vote up
@SuppressWarnings("deprecation")
private static int getScreenWidth(Context context) {
  WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
  Display display = Preconditions.checkNotNull(wm).getDefaultDisplay();
  Point size = new Point();
  display.getSize(size);
  return size.x;
}
 
Example 46
Project: Quran   File: QuranScreenInfo.java   Source Code and License 5 votes vote down vote up
private static QuranScreenInfo initialize(Context context) {
  final WindowManager w = (WindowManager) context
      .getSystemService(Context.WINDOW_SERVICE);
  final Display display = w.getDefaultDisplay();
  QuranScreenInfo qsi = new QuranScreenInfo(display);
  qsi.setOverrideParam(QuranSettings.getInstance(context).getDefaultImagesDirectory());
  return qsi;
}
 
Example 47
Project: LoRaWAN-Smart-Parking   File: CordovaActivity.java   Source Code and License 5 votes vote down vote up
@SuppressWarnings("deprecation")
protected void createViews() {
    // This builds the view.  We could probably get away with NOT having a LinearLayout, but I like having a bucket!

    LOG.d(TAG, "CordovaActivity.createViews()");

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

    root = new LinearLayoutSoftKeyboardDetect(this, width, height);
    root.setOrientation(LinearLayout.VERTICAL);
    root.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT, 0.0F));

    appView.setId(100);
    appView.setLayoutParams(new LinearLayout.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT,
            1.0F));

    // need to remove appView from any existing parent before invoking root.addView(appView)
    ViewParent parent = appView.getParent();
    if ((parent != null) && (parent != root)) {
        LOG.d(TAG, "removing appView from existing parent");
        ViewGroup parentGroup = (ViewGroup) parent;
        parentGroup.removeView(appView);
    }
    root.addView((View) appView);
    setContentView(root);

    int backgroundColor = preferences.getInteger("BackgroundColor", Color.BLACK);
    root.setBackgroundColor(backgroundColor);
}
 
Example 48
Project: carousel-picker-android   File: CarouselView.java   Source Code and License 5 votes vote down vote up
protected LinearLayout.LayoutParams calculateLayoutSize(){
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    return new LinearLayout.LayoutParams(size.x/numberOfItensPerPage, getLayoutParams().height);
}
 
Example 49
Project: Pluto-Android   File: PhotoUtil.java   Source Code and License 5 votes vote down vote up
public static Bitmap getBitpMap(Context context, Uri uri, Display display) {
	ParcelFileDescriptor pfd;
	try {
		pfd = context.getContentResolver().openFileDescriptor(uri, "r");
	} catch (IOException ex) {
		return null;
	}
	java.io.FileDescriptor fd = pfd.getFileDescriptor();
	BitmapFactory.Options options = new BitmapFactory.Options();
	// 先指定原始大小
	options.inSampleSize = 1;
	// 只进行大小判断
	options.inJustDecodeBounds = true;
	// 调用此方法得到options得到图片的大小
	BitmapFactory.decodeFileDescriptor(fd, null, options);
	// 我们的目标是在800pixel的画面上显示。
	// 所以需要调用computeSampleSize得到图片缩放的比例
	options.inSampleSize = computeSampleSize(options, display.getWidth(),
			display.getHeight());
	// OK,我们得到了缩放的比例,现在开始正式读入BitMap数据
	options.inJustDecodeBounds = false;
	options.inDither = false;
	options.inPreferredConfig = Bitmap.Config.ARGB_8888;

	// 根据options参数,减少所需要的内存
	Bitmap sourceBitmap = BitmapFactory.decodeFileDescriptor(fd, null,
			options);
	return sourceBitmap;
}
 
Example 50
Project: Tribe   File: OvSlideViewpager.java   Source Code and License 5 votes vote down vote up
/**
 * 计算按照屏幕比例缩放后的尺寸
 * @param sizex
 * @return
 */
public int zoomx(Activity activity, int sizex){
    float widthP=1080.0f;
    if(fzoomx == 0f){
        WindowManager windowManager = activity.getWindowManager();
        Display display = windowManager.getDefaultDisplay();
        DisplayMetrics metrics = new DisplayMetrics();
        display.getMetrics(metrics);
        fzoomx = (metrics.widthPixels/widthP)*sizex+10;
    }
    return (int)(fzoomx);
}
 
Example 51
Project: QuanMinTV   File: ScreenResolution.java   Source Code and License 5 votes vote down vote up
/**
 * Gets real resolution via the new getRealMetrics API.
 * */
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
private static Pair<Integer,Integer> getRealResolution(Context ctx) {
  WindowManager wm = (WindowManager) ctx.getSystemService(Context.WINDOW_SERVICE);
  Display display = wm.getDefaultDisplay();
  DisplayMetrics metrics = new DisplayMetrics();
  display.getRealMetrics(metrics);
  return new Pair<Integer, Integer>(metrics.widthPixels, metrics.heightPixels);
}
 
Example 52
Project: PicKing   File: ScreenUtil.java   Source Code and License 5 votes vote down vote up
/**
 * 获取屏幕的宽度
 * @param context
 * @return
 */
public static int getScreenWidth(Context context) {
    WindowManager manager = (WindowManager) context
            .getSystemService(Context.WINDOW_SERVICE);
    Display display = manager.getDefaultDisplay();
    return display.getWidth();
}
 
Example 53
Project: OpenHomeAnalysis   File: OhaEnergyUseBillFragment.java   Source Code and License 5 votes vote down vote up
@Override
public void onResume() {
    //Definir o tamanho da janela conforme percentual definido no dimens.xml:
    Window window = getDialog().getWindow();
    Point size = new Point();
    Display display = window.getWindowManager().getDefaultDisplay();
    display.getSize(size);
    double percentWidth = getResources().getInteger(R.integer.energy_use_bill_fragment_width_percent) / 100.00;
    double percentHeight = getResources().getInteger(R.integer.energy_use_bill_fragment_height_percent) / 100.00;
    window.setLayout((int) (size.x * percentWidth), (int) (size.y * percentHeight));
    window.setGravity(Gravity.CENTER);
    super.onResume();
}
 
Example 54
Project: OpenHomeAnalysis   File: OhaEnergyUseLogFilterFragment.java   Source Code and License 5 votes vote down vote up
@Override
public void onResume() {
    //Definir o tamanho da janela conforme percentual definido no dimens.xml:
    Window window = getDialog().getWindow();
    Point size = new Point();
    Display display = window.getWindowManager().getDefaultDisplay();
    display.getSize(size);
    double percentWidth = getResources().getInteger(R.integer.energy_use_log_filter_fragment_width_percent) / 100.00;
    double percentHeight = getResources().getInteger(R.integer.energy_use_log_filter_fragment_height_percent) / 100.00;
    window.setLayout((int) (size.x * percentWidth), (int) (size.y * percentHeight));
    window.setGravity(Gravity.CENTER);
    super.onResume();
}
 
Example 55
Project: CameraFragment   File: Camera2Manager.java   Source Code and License 5 votes vote down vote up
@Override
public void initializeCameraManager(ConfigurationProvider configurationProvider, Context context) {
    super.initializeCameraManager(configurationProvider, context);

    this.manager = (CameraManager) context.getSystemService(Context.CAMERA_SERVICE);

    final WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    final Display display = windowManager.getDefaultDisplay();
    final Point size = new Point();
    display.getSize(size);
    windowSize = new Size(size.x, size.y);

    try {
        final String[] ids = manager.getCameraIdList();
        numberOfCameras = ids.length;
        for (String id : ids) {
            final CameraCharacteristics characteristics = manager.getCameraCharacteristics(id);

            final int orientation = characteristics.get(CameraCharacteristics.LENS_FACING);
            if (orientation == CameraCharacteristics.LENS_FACING_FRONT) {
                faceFrontCameraId = id;
                faceFrontCameraOrientation = characteristics.get(CameraCharacteristics.SENSOR_ORIENTATION);
                frontCameraCharacteristics = characteristics;
            } else {
                faceBackCameraId = id;
                faceBackCameraOrientation = characteristics.get(CameraCharacteristics.SENSOR_ORIENTATION);
                backCameraCharacteristics = characteristics;
            }
        }
    } catch (Exception e) {
        Log.e(TAG, "Error during camera init");
    }
}
 
Example 56
Project: BilibiliClient   File: ScreenResolution.java   Source Code and License 5 votes vote down vote up
/**
 * Gets real resolution via the new getRealMetrics API.
 */
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
private static Pair<Integer, Integer> getRealResolution(Context ctx) {

  WindowManager wm = (WindowManager) ctx.getSystemService(Context.WINDOW_SERVICE);
  Display display = wm.getDefaultDisplay();
  DisplayMetrics metrics = new DisplayMetrics();
  display.getRealMetrics(metrics);
  return new Pair<>(metrics.widthPixels, metrics.heightPixels);
}
 
Example 57
Project: DialogHelper   File: BaseDialog.java   Source Code and License 5 votes vote down vote up
/**
 * 设置宽度全屏,并从下面弹出,添加动画
 */
public void setButtomAndWidth() {

    getWindow().setGravity(Gravity.BOTTOM); //显示在底部
    WindowManager m = getWindow().getWindowManager();
    Display d = m.getDefaultDisplay();
    WindowManager.LayoutParams p = getWindow().getAttributes();
    p.width = d.getWidth(); //设置dialog的宽度为当前手机屏幕的宽度
    getWindow().setAttributes(p);
    getWindow().setWindowAnimations(R.style.popWindow);

}
 
Example 58
Project: TPlayer   File: CameraConfigurationManager.java   Source Code and License 5 votes vote down vote up
@SuppressWarnings("deprecation")
@SuppressLint("NewApi")
private Point getDisplaySize(final Display display) {
    final Point point = new Point();
    try {
        display.getSize(point);
    } catch (NoSuchMethodError ignore) {
        point.x = display.getWidth();
        point.y = display.getHeight();
    }
    return point;
}
 
Example 59
Project: WechatChatroomHelper   File: UIUtil.java   Source Code and License 5 votes vote down vote up
/**
 * 获取屏幕高度,包括底部导航栏
 *
 * @param activity
 * @return
 */
public static int getRealScreenHeight(Activity activity) {
    WindowManager windowManager = activity.getWindowManager();
    Display display = windowManager.getDefaultDisplay();
    DisplayMetrics displayMetrics = new DisplayMetrics();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        display.getRealMetrics(displayMetrics);
    } else {
        display.getMetrics(displayMetrics);
    }
    return displayMetrics.heightPixels;
}
 
Example 60
Project: SmartButler   File: CameraConfigurationManager.java   Source Code and License 5 votes vote down vote up
@SuppressWarnings("deprecation")
@SuppressLint("NewApi")
private Point getDisplaySize(final Display display) {
    final Point point = new Point();
    try {
        display.getSize(point);
    } catch (NoSuchMethodError ignore) {
        point.x = display.getWidth();
        point.y = display.getHeight();
    }
    return point;
}