Example usage for android.view Display getHeight

List of usage examples for android.view Display getHeight

Introduction

In this page you can find the example usage for android.view Display getHeight.

Prototype

@Deprecated
public int getHeight() 

Source Link

Usage

From source file:hr.foicore.varazdinlandmarksdemo.POIMapActivity.java

@SuppressWarnings("deprecation")
@SuppressLint("NewApi")
private void lockOrientation() {
    Display display = POIMapActivity.this.getWindowManager().getDefaultDisplay();
    int rotation = display.getRotation();
    int height;//from ww w .  ja  v  a2  s.c om
    int width;
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB_MR2) {
        height = display.getHeight();
        width = display.getWidth();
    } else {
        Point size = new Point();
        display.getSize(size);
        height = size.y;
        width = size.x;
    }
    switch (rotation) {
    case Surface.ROTATION_90:
        if (width > height)
            POIMapActivity.this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
        else
            POIMapActivity.this.setRequestedOrientation(9/* reversePortait */);
        break;
    case Surface.ROTATION_180:
        if (height > width)
            POIMapActivity.this.setRequestedOrientation(9/* reversePortait */);
        else
            POIMapActivity.this.setRequestedOrientation(8/* reverseLandscape */);
        break;
    case Surface.ROTATION_270:
        if (width > height)
            POIMapActivity.this.setRequestedOrientation(8/* reverseLandscape */);
        else
            POIMapActivity.this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        break;
    default:
        if (height > width)
            POIMapActivity.this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        else
            POIMapActivity.this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    }
}

From source file:org.navitproject.navit.Navit.java

public void fullscreen(int fullscreen) {
    int w, h;/*from   w  ww . j  a va 2  s  .  c o m*/

    isFullscreen = (fullscreen != 0);
    if (isFullscreen) {
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
        getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
    } else {
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
        getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
    }

    Display display_ = getWindowManager().getDefaultDisplay();
    if (Build.VERSION.SDK_INT < 17) {
        w = display_.getWidth();
        h = display_.getHeight();
    } else {
        Point size = new Point();
        display_.getRealSize(size);
        w = size.x;
        h = size.y;
    }
    Log.d(TAG, String.format("Toggle fullscreen, w=%d, h=%d", w, h));
    N_NavitGraphics.handleResize(w, h);
}

From source file:org.smilec.smile.ui.GeneralActivity.java

@SuppressWarnings("deprecation")
@Override// www.j a v  a 2 s .  c  om
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.bt_restart:
        AlertDialog.Builder builderRestart = new AlertDialog.Builder(this);
        builderRestart.setMessage(R.string.restart_game).setCancelable(false)
                .setPositiveButton("Yes", new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int id) {

                        try {
                            //new SmilePlugServerManager().connect(ip, GeneralActivity.this);
                            new SmilePlugServerManager().resetGame(ip, GeneralActivity.this);
                            // QuestionsManager.resetListOfDeletedQuestions(GeneralActivity.this);
                            GeneralActivity.this.finish();
                        } catch (NetworkErrorException e) {
                            ActivityUtil.showLongToast(GeneralActivity.this,
                                    R.string.toast_down_or_unavailable);
                            Log.e(Constants.LOG_CATEGORY, "Error: ", e);
                        }
                    }

                }).setNegativeButton("No", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int id) {
                        dialog.cancel();
                    }
                });
        AlertDialog alertRestart = builderRestart.create();
        alertRestart.show();
        break;
    case R.id.bt_retake:
        AlertDialog.Builder builderRetake = new AlertDialog.Builder(this);
        builderRetake.setMessage(R.string.retake_game).setCancelable(false)
                .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int id) {
                        try {
                            new SmilePlugServerManager().startRetakeQuestions(ip, GeneralActivity.this, board);
                            ActivityUtil.showLongToast(GeneralActivity.this, R.string.toast_retaking);

                            Intent intent = new Intent(GeneralActivity.this,
                                    org.smilec.smile.ui.UsePreparedQuestionsActivity.class);
                            intent.putExtra(GeneralActivity.PARAM_IP, ip);
                            status = CurrentMessageStatus.RE_TAKE.name();
                            intent.putExtra(GeneralActivity.PARAM_STATUS, status);
                            startActivity(intent);

                        } catch (NetworkErrorException e) {
                            Log.e(Constants.LOG_CATEGORY, "Error: ", e);
                        }
                    }
                }).setNegativeButton("No", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int id) {
                        dialog.cancel();
                    }
                });
        AlertDialog alertRetake = builderRetake.create();
        alertRetake.show();
        break;
    case R.id.bt_about:
        Dialog aboutDialog = new Dialog(this, R.style.Dialog);
        aboutDialog.setContentView(R.layout.about);
        Display displaySize = ActivityUtil.getDisplaySize(getApplicationContext());
        aboutDialog.getWindow().setLayout(displaySize.getWidth(), displaySize.getHeight());
        aboutDialog.show();
        break;
    case R.id.bt_exit:
        AlertDialog.Builder builderExit = new AlertDialog.Builder(this);
        builderExit.setMessage(R.string.exit).setCancelable(false)
                .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int id) {
                        Intent intent = new Intent(Intent.ACTION_MAIN);
                        intent.addCategory(Intent.CATEGORY_HOME);
                        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                        startActivity(intent);

                        try {
                            new SmilePlugServerManager().resetGame(ip, GeneralActivity.this);
                        } catch (NetworkErrorException e) {
                            Log.e(Constants.LOG_CATEGORY, "Error: ", e);
                        }

                        // QuestionsManager.resetListOfDeletedQuestions(GeneralActivity.this);
                        GeneralActivity.this.finish();
                    }
                }).setNegativeButton("No", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int id) {
                        dialog.cancel();
                    }
                });
        AlertDialog alertExit = builderExit.create();
        alertExit.show();
        break;
    }
    return true;
}

From source file:com.farmerbb.taskbar.service.StartMenuService.java

@SuppressWarnings("deprecation")
private void openContextMenu(final int[] location) {
    LocalBroadcastManager.getInstance(this).sendBroadcast(new Intent("com.farmerbb.taskbar.HIDE_START_MENU"));

    new Handler().postDelayed(() -> {
        SharedPreferences pref = U.getSharedPreferences(StartMenuService.this);
        Intent intent = null;/* w w w  . jav  a 2 s . co m*/

        switch (pref.getString("theme", "light")) {
        case "light":
            intent = new Intent(StartMenuService.this, ContextMenuActivity.class);
            break;
        case "dark":
            intent = new Intent(StartMenuService.this, ContextMenuActivityDark.class);
            break;
        }

        if (intent != null) {
            intent.putExtra("launched_from_start_menu", true);
            intent.putExtra("is_overflow_menu", true);
            intent.putExtra("x", location[0]);
            intent.putExtra("y", location[1]);
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        }

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N
                && FreeformHackHelper.getInstance().isInFreeformWorkspace()) {
            DisplayManager dm = (DisplayManager) getSystemService(DISPLAY_SERVICE);
            Display display = dm.getDisplay(Display.DEFAULT_DISPLAY);

            if (intent != null && U.isOPreview())
                intent.putExtra("context_menu_fix", true);

            startActivity(intent, U.getActivityOptions(ApplicationType.CONTEXT_MENU)
                    .setLaunchBounds(new Rect(0, 0, display.getWidth(), display.getHeight())).toBundle());
        } else
            startActivity(intent);
    }, shouldDelay() ? 100 : 0);
}

From source file:com.bitants.wally.activities.ImageDetailsActivity.java

private void scrollUpToolbarIfNeeded() {
    Display thisDisplay = getWindowManager().getDefaultDisplay();
    int screenHeight = thisDisplay.getHeight();
    int emptySpace = detailsViewGroup.getPaddingTop();
    int targetHeight = emptySpace - ((screenHeight / 3) * 2);
    int navBarHeight = 0;
    if (imageSize.getHeight() > (screenHeight - navBarHeight)) {
        Message msgObj = uiHandler.obtainMessage();
        msgObj.what = MSG_SCROLL_UP_SCROLLVIEW;
        msgObj.arg1 = targetHeight;/*from www.  j av  a2s  . c  om*/
        uiHandler.sendMessageDelayed(msgObj, 500);
    }
}

From source file:com.bitants.wally.activities.ImageDetailsActivity.java

private void enableParallaxEffect(ObservableScrollView scrollView, final View parallaxingView) {
    scrollView.setScrollViewListener(new ScrollViewListener() {
        @Override/* w  w  w .  j a va  2s  .com*/
        public void onScrollChanged(ObservableScrollView scrollView, int x, int y, int oldx, int oldy) {

            WindowManager win = getWindowManager();
            Display d = win.getDefaultDisplay();
            int displayHeight = d.getHeight(); // Height of the actual device

            if (imageSize.getHeight() > displayHeight && photoViewAttacher != null) {
                float[] values = new float[9];
                photoViewAttacher.getDrawMatrix().getValues(values);
                float imageHeight = imageSize.getHeight();

                float diff = imageHeight / displayHeight;

                if (y > oldy) {
                    diff = -diff;
                }

                photoViewAttacher.onDrag(0, diff);

            } else {
                float pY = -(y / 3.0f);
                parallaxingView.setTranslationY(pY);
            }

        }
    });
}

From source file:com.mobilyzer.util.PhoneUtils.java

/**
 * Returns true if the phone is in landscape mode.
 *///www.jav a2 s .c  om
public boolean isLandscape() {
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    return display.getWidth() > display.getHeight();
}

From source file:org.navitproject.navit.Navit.java

/** Called when the activity is first created. */
@Override// w ww .  j a v a2 s . c  o m
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB)
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
    else
        this.getActionBar().hide();

    dialogs = new NavitDialogs(this);

    NavitResources = getResources();

    // only take arguments here, onResume gets called all the time (e.g. when screenblanks, etc.)
    Navit.startup_intent = this.getIntent();
    // hack! Remember time stamps, and only allow 4 secs. later in onResume to set target!
    Navit.startup_intent_timestamp = System.currentTimeMillis();
    Log.e("Navit", "**1**A " + startup_intent.getAction());
    Log.e("Navit", "**1**D " + startup_intent.getDataString());

    // init translated text
    NavitTextTranslations.init();

    // NOTIFICATION
    // Setup the status bar notification      
    // This notification is removed in the exit() function
    NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); // Grab a handle to the NotificationManager
    Notification NavitNotification = new Notification(R.drawable.ic_notify,
            getString(R.string.notification_ticker), System.currentTimeMillis()); // Create a new notification, with the text string to show when the notification first appears
    PendingIntent appIntent = PendingIntent.getActivity(getApplicationContext(), 0, getIntent(), 0);
    //      FIXME : needs a fix for sdk 23
    //      NavitNotification.setLatestEventInfo(getApplicationContext(), "Navit", getString(R.string.notification_event_default), appIntent);   // Set the text in the notification
    //      NavitNotification.flags|=Notification.FLAG_ONGOING_EVENT;   // Ensure that the notification appears in Ongoing
    //      nm.notify(R.string.app_name, NavitNotification);   // Set the notification

    // Status and navigation bar sizes
    // These are platform defaults and do not change with rotation, but we have to figure out which ones apply
    // (is the navigation bar visible? on the side or at the bottom?)
    Resources resources = getResources();
    int shid = resources.getIdentifier("status_bar_height", "dimen", "android");
    int adhid = resources.getIdentifier("action_bar_default_height", "dimen", "android");
    int nhid = resources.getIdentifier("navigation_bar_height", "dimen", "android");
    int nhlid = resources.getIdentifier("navigation_bar_height_landscape", "dimen", "android");
    int nwid = resources.getIdentifier("navigation_bar_width", "dimen", "android");
    status_bar_height = (shid > 0) ? resources.getDimensionPixelSize(shid) : 0;
    action_bar_default_height = (adhid > 0) ? resources.getDimensionPixelSize(adhid) : 0;
    navigation_bar_height = (nhid > 0) ? resources.getDimensionPixelSize(nhid) : 0;
    navigation_bar_height_landscape = (nhlid > 0) ? resources.getDimensionPixelSize(nhlid) : 0;
    navigation_bar_width = (nwid > 0) ? resources.getDimensionPixelSize(nwid) : 0;
    Log.d(TAG, String.format(
            "status_bar_height=%d, action_bar_default_height=%d, navigation_bar_height=%d, navigation_bar_height_landscape=%d, navigation_bar_width=%d",
            status_bar_height, action_bar_default_height, navigation_bar_height,
            navigation_bar_height_landscape, navigation_bar_width));
    if ((ContextCompat.checkSelfPermission(this,
            Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED)
            || (ContextCompat.checkSelfPermission(this,
                    Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED)) {
        Log.d(TAG, "ask for permission(s)");
        ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE,
                Manifest.permission.ACCESS_FINE_LOCATION }, MY_PERMISSIONS_REQUEST_ALL);
    }
    // get the local language -------------
    Locale locale = java.util.Locale.getDefault();
    String lang = locale.getLanguage();
    String langu = lang;
    String langc = lang;
    Log.e("Navit", "lang=" + lang);
    int pos = langu.indexOf('_');
    if (pos != -1) {
        langc = langu.substring(0, pos);
        NavitLanguage = langc + langu.substring(pos).toUpperCase(locale);
        Log.e("Navit", "substring lang " + NavitLanguage.substring(pos).toUpperCase(locale));
        // set lang. for translation
        NavitTextTranslations.main_language = langc;
        NavitTextTranslations.sub_language = NavitLanguage.substring(pos).toUpperCase(locale);
    } else {
        String country = locale.getCountry();
        Log.e("Navit", "Country1 " + country);
        Log.e("Navit", "Country2 " + country.toUpperCase(locale));
        NavitLanguage = langc + "_" + country.toUpperCase(locale);
        // set lang. for translation
        NavitTextTranslations.main_language = langc;
        NavitTextTranslations.sub_language = country.toUpperCase(locale);
    }
    Log.e("Navit", "Language " + lang);

    SharedPreferences prefs = getSharedPreferences(NAVIT_PREFS, MODE_PRIVATE);
    map_filename_path = prefs.getString("filenamePath",
            Environment.getExternalStorageDirectory().getPath() + "/navit/");

    // make sure the new path for the navitmap.bin file(s) exist!!
    File navit_maps_dir = new File(map_filename_path);
    navit_maps_dir.mkdirs();

    // make sure the share dir exists
    File navit_data_share_dir = new File(NAVIT_DATA_SHARE_DIR);
    navit_data_share_dir.mkdirs();

    Display display_ = getWindowManager().getDefaultDisplay();
    int width_ = display_.getWidth();
    int height_ = display_.getHeight();
    metrics = new DisplayMetrics();
    display_.getMetrics(Navit.metrics);
    int densityDpi = (int) ((Navit.metrics.density * 160) - .5f);
    Log.e("Navit", "Navit -> pixels x=" + width_ + " pixels y=" + height_);
    Log.e("Navit", "Navit -> dpi=" + densityDpi);
    Log.e("Navit", "Navit -> density=" + Navit.metrics.density);
    Log.e("Navit", "Navit -> scaledDensity=" + Navit.metrics.scaledDensity);

    ActivityResults = new NavitActivityResult[16];
    setVolumeControlStream(AudioManager.STREAM_MUSIC);
    PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
    wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE, "NavitDoNotDimScreen");

    if (!extractRes(langc, NAVIT_DATA_DIR + "/locale/" + langc + "/LC_MESSAGES/navit.mo")) {
        Log.e("Navit", "Failed to extract language resource " + langc);
    }

    if (densityDpi <= 120) {
        my_display_density = "ldpi";
    } else if (densityDpi <= 160) {
        my_display_density = "mdpi";
    } else if (densityDpi < 240) {
        my_display_density = "hdpi";
    } else if (densityDpi < 320) {
        my_display_density = "xhdpi";
    } else if (densityDpi < 480) {
        my_display_density = "xxhdpi";
    } else if (densityDpi < 640) {
        my_display_density = "xxxhdpi";
    } else {
        Log.e("Navit", "found device of very high density (" + densityDpi + ")");
        Log.e("Navit", "using xxxhdpi values");
        my_display_density = "xxxhdpi";
    }

    if (!extractRes("navit" + my_display_density, NAVIT_DATA_DIR + "/share/navit.xml")) {
        Log.e("Navit", "Failed to extract navit.xml for " + my_display_density);
    }

    // --> dont use android.os.Build.VERSION.SDK_INT, needs API >= 4
    Log.e("Navit", "android.os.Build.VERSION.SDK_INT=" + Integer.valueOf(android.os.Build.VERSION.SDK));
    NavitMain(this, NavitLanguage, Integer.valueOf(android.os.Build.VERSION.SDK), my_display_density,
            NAVIT_DATA_DIR + "/bin/navit", map_filename_path);

    showInfos();

    Navit.mgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
}

From source file:com.facebook.android.friendsmash.GameFragment.java

@SuppressWarnings({ "deprecation" })
@TargetApi(13)// ww w .  ja v a 2s  .co m
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) {

    View v = inflater.inflate(R.layout.fragment_game, parent, false);

    gameFrame = (FrameLayout) v.findViewById(R.id.gameFrame);
    progressContainer = (FrameLayout) v.findViewById(R.id.progressContainer);
    smashPlayerNameTextView = (TextView) v.findViewById(R.id.smashPlayerNameTextView);
    scoreTextView = (TextView) v.findViewById(R.id.scoreTextView);
    livesContainer = (LinearLayout) v.findViewById(R.id.livesContainer);

    // Set the progressContainer as invisible by default
    progressContainer.setVisibility(View.INVISIBLE);

    // Set the icon width (for the images to be smashed)
    setIconWidth(getResources().getDimensionPixelSize(R.dimen.icon_width));

    // Set the screen dimensions
    WindowManager wm = (WindowManager) getActivity().getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    if (Build.VERSION.SDK_INT >= 13) {
        Point size = new Point();
        display.getSize(size);
        setScreenWidth(size.x);
        setScreenHeight(size.y);
    } else {
        setScreenWidth(display.getWidth());
        setScreenHeight(display.getHeight());
    }

    // Always keep the Action Bar hidden
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        getActivity().getActionBar().hide();
    }

    // Instantiate the fireImageTask for future fired images
    fireImageTask = new Runnable() {
        public void run() {
            spawnImage(false);
        }
    };

    // Refresh the score board
    setScore(getScore());

    // Refresh the lives
    setLives(getLives());

    // Note: Images will start firing in the onResume method below

    return v;
}

From source file:org.puder.trs80.EmulatorActivity.java

private void lockOrientation() {
    Display display = getWindowManager().getDefaultDisplay();
    rotation = display.getRotation();/*from   w w  w.j ava2 s.c  om*/
    int height;
    int width;
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB_MR2) {
        height = display.getHeight();
        width = display.getWidth();
    } else {
        Point size = new Point();
        display.getSize(size);
        height = size.y;
        width = size.x;
    }
    switch (rotation) {
    case Surface.ROTATION_90:
        if (width > height) {
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
        } else {
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT);
        }
        break;
    case Surface.ROTATION_180:
        if (height > width) {
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT);
        } else {
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
        }
        break;
    case Surface.ROTATION_270:
        if (width > height) {
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
        } else {
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        }
        break;
    default:
        if (height > width) {
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        } else {
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
        }
    }
}