Example usage for android.content.res Configuration ORIENTATION_PORTRAIT

List of usage examples for android.content.res Configuration ORIENTATION_PORTRAIT

Introduction

In this page you can find the example usage for android.content.res Configuration ORIENTATION_PORTRAIT.

Prototype

int ORIENTATION_PORTRAIT

To view the source code for android.content.res Configuration ORIENTATION_PORTRAIT.

Click Source Link

Document

Constant for #orientation , value corresponding to the port resource qualifier.

Usage

From source file:com.tweetlanes.android.core.view.DirectMessageFeedFragment.java

private void lockScreenRotation() {
    if (getActivity() != null) {
        switch (getActivity().getResources().getConfiguration().orientation) {
        case Configuration.ORIENTATION_PORTRAIT:
            getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
            break;
        case Configuration.ORIENTATION_LANDSCAPE:
            getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
            break;
        }/*from  ww w.j  a  v a  2 s. c om*/
    }
}

From source file:tr.com.turkcellteknoloji.turkcellupdater.Utilities.java

@SuppressLint("NewApi")
static int getScreenOrientation(Activity activity) {
    if (Build.VERSION.SDK_INT < 8) {
        switch (activity.getResources().getConfiguration().orientation) {
        case Configuration.ORIENTATION_PORTRAIT:
            return ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
        case Configuration.ORIENTATION_LANDSCAPE:
            return ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
        default:/* w ww  .  j  av a  2s  .  c om*/
            return ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
        }
    }

    int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
    DisplayMetrics dm = new DisplayMetrics();
    activity.getWindowManager().getDefaultDisplay().getMetrics(dm);
    int width = dm.widthPixels;
    int height = dm.heightPixels;
    int orientation;
    // if the device's natural orientation is portrait:
    if ((rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_180) && height > width
            || (rotation == Surface.ROTATION_90 || rotation == Surface.ROTATION_270) && width > height) {
        switch (rotation) {
        case Surface.ROTATION_0:
            orientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
            break;
        case Surface.ROTATION_90:
            orientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
            break;
        case Surface.ROTATION_180:
            orientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT;
            break;
        case Surface.ROTATION_270:
            orientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE;
            break;
        default:
            orientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
            break;
        }
    }
    // if the device's natural orientation is landscape or if the device
    // is square:
    else {
        switch (rotation) {
        case Surface.ROTATION_0:
            orientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
            break;
        case Surface.ROTATION_90:
            orientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
            break;
        case Surface.ROTATION_180:
            orientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE;
            break;
        case Surface.ROTATION_270:
            orientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT;
            break;
        default:
            orientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
            break;
        }
    }

    return orientation;
}

From source file:net.archenemy.archenemyapp.presenter.MainActivity.java

/**
 * /*w ww  . j a  va  2s. c om*/
 */
private void assignViews() {
    setContentView(R.layout.main_activity);

    facebookIcon = (ImageView) findViewById(R.id.facebookIcon);
    facebookTab = (FrameLayout) findViewById(R.id.facebookTab);
    facebookTab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View arg0) {
            currentTabTranslationY = calculateTabTranslationY(facebookPageFragment.getScrollY(), false);
            showMenuItem(FACEBOOK);
        }
    });

    twitterIcon = (ImageView) findViewById(R.id.twitterIcon);
    twitterTab = (FrameLayout) findViewById(R.id.twitterTab);
    twitterTab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View arg0) {
            currentTabTranslationY = calculateTabTranslationY(twitterPageFragment.getScrollY(), false);
            showMenuItem(TWITTER);
        }
    });

    toolbar = (Toolbar) findViewById(R.id.toolbar);
    // no title
    toolbar.setTitle("");
    setSupportActionBar(toolbar);

    tabs = (LinearLayout) findViewById(R.id.tabs);
    tabsBackground = (FrameLayout) findViewById(R.id.tabsBackground);
    background = (FrameLayout) findViewById(R.id.background);

    fragmentContainer = (FrameLayout) findViewById(R.id.fragmentContainer);

    headerImage = (ImageView) findViewById(R.id.headerImage);
    int width = 0;
    int height = 0;
    // in portrait orientation, display band picture in 16:9 format
    if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
        width = getResources().getDisplayMetrics().widthPixels;
        height = (width * 9) / 16;
    } else {
        // in landscape orientation, display band picture full screen
        width = getResources().getDisplayMetrics().widthPixels;
        height = getResources().getDisplayMetrics().heightPixels;
    }
    LayoutParams params = new LayoutParams(width, height);
    headerImage.setLayoutParams(params);
    BitmapUtility.loadBitmap(this, R.drawable.band, headerImage, width, height);

}

From source file:cn.com.teamlink.workbench.ExplorerActivity.java

@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
    if (this.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
        // TODO ORIENTATION_LANDSCAPE
    } else if (this.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
        // TODO ORIENTATION_PORTRAIT
    }//from   w w w . j  av  a2  s  .c  o m
}

From source file:com.stylovid.fastbattery.CurrentInfoFragment.java

private void setSizes(Configuration config) {
    boolean portrait = config.orientation == Configuration.ORIENTATION_PORTRAIT;

    int screenWidth, screenHeight;

    if (android.os.Build.VERSION.SDK_INT < 13) {
        DisplayMetrics metrics = new DisplayMetrics();
        getActivity().getWindowManager().getDefaultDisplay().getMetrics(metrics);

        screenWidth = metrics.widthPixels;
        screenHeight = (int) (metrics.heightPixels * 0.95);
    } else {//w  ww.  ja v a 2s  . co  m
        screenWidth = (int) (config.screenWidthDp * dpScale);
        screenHeight = (int) (config.screenHeightDp * dpScale);
    }

    int minDimen = Math.min(screenWidth, screenHeight);
    float aspectRatio = (float) screenWidth / screenHeight;

    // System.out.println("...................................................." +
    //                    "\n    config.screenWidthDp: " + config.screenWidthDp +
    //                    "\n    config.screenHeightDp: " + config.screenHeightDp +
    //                    "\n    config figured pixel width: " + screenWidth +
    //                    "\n    config figured pixel height: " + screenHeight +
    //                    "\n    aspectRatio: " + aspectRatio +
    //                    "\n    portrait: " + portrait
    //                    );

    int plugged_icon_height;
    int time_remaining_text_height, until_what_text_height;
    int status_text_height;
    int bu_height, bu_text_height;
    int vital_icon_height, vital_text_height;

    if (portrait) {
        plugged_icon_height = (int) (screenHeight * 0.1);

        time_remaining_text_height = (int) (screenHeight * 0.048);
        until_what_text_height = (int) (screenHeight * 0.032);

        status_text_height = (int) (screenHeight * 0.04);

        bu_height = (int) (screenHeight * 0.14);
        bu_text_height = (int) (screenHeight * 0.035);

        vital_icon_height = (int) (screenHeight * 0.05);
        vital_text_height = (int) (screenHeight * 0.03);
    } else {
        plugged_icon_height = (int) (screenHeight * 0.11);

        time_remaining_text_height = (int) (screenHeight * 0.06);
        until_what_text_height = (int) (screenHeight * 0.04);

        status_text_height = (int) (screenHeight * 0.05);

        bu_height = (int) (screenHeight * 0.18);
        bu_text_height = (int) (screenHeight * 0.045);

        vital_icon_height = (int) (screenHeight * 0.08);
        vital_text_height = (int) (screenHeight * 0.05);
    }

    TextView level = (TextView) view.findViewById(R.id.level);
    level.setTextSize(android.util.TypedValue.COMPLEX_UNIT_PX, plugged_icon_height);

    View clock = view.findViewById(R.id.clock);
    clock.setLayoutParams(
            new LinearLayout.LayoutParams(plugged_icon_height, ViewGroup.LayoutParams.MATCH_PARENT));

    TextView time_remaining = (TextView) view.findViewById(R.id.time_remaining);
    time_remaining.setTextSize(android.util.TypedValue.COMPLEX_UNIT_PX, time_remaining_text_height);

    TextView until_what = (TextView) view.findViewById(R.id.until_what);
    until_what.setTextSize(android.util.TypedValue.COMPLEX_UNIT_PX, until_what_text_height);

    TextView status = (TextView) view.findViewById(R.id.status);
    status.setTextSize(android.util.TypedValue.COMPLEX_UNIT_PX, status_text_height);

    TextView status_duration = (TextView) view.findViewById(R.id.status_duration);
    status_duration.setTextSize(android.util.TypedValue.COMPLEX_UNIT_PX, until_what_text_height);

    View plugged_icon = view.findViewById(R.id.plugged_icon);
    plugged_icon.setLayoutParams(
            new LinearLayout.LayoutParams(plugged_icon_height, ViewGroup.LayoutParams.MATCH_PARENT));

    View plugged_spacer = view.findViewById(R.id.plugged_spacer);
    plugged_spacer.setLayoutParams(new LinearLayout.LayoutParams(plugged_icon_height, plugged_icon_height));

    Button bu_button = (Button) view.findViewById(R.id.battery_use_b);
    bu_button.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, bu_height));
    bu_button.setTextSize(android.util.TypedValue.COMPLEX_UNIT_PX, bu_text_height);

    View temp_icon = view.findViewById(R.id.temp_icon);
    temp_icon.setLayoutParams(new LinearLayout.LayoutParams(vital_icon_height, vital_icon_height));
    TextView temp_text = (TextView) view.findViewById(R.id.temp);
    temp_text.setLayoutParams(new LinearLayout.LayoutParams(0, vital_icon_height, 0.5f));
    temp_text.setTextSize(android.util.TypedValue.COMPLEX_UNIT_PX, vital_text_height);

    View health_icon = view.findViewById(R.id.health_icon);
    health_icon.setLayoutParams(new LinearLayout.LayoutParams(vital_icon_height, vital_icon_height));
    TextView health_text = (TextView) view.findViewById(R.id.health);
    health_text.setLayoutParams(new LinearLayout.LayoutParams(0, vital_icon_height, 0.5f));
    health_text.setTextSize(android.util.TypedValue.COMPLEX_UNIT_PX, vital_text_height);

    View voltage_icon = view.findViewById(R.id.voltage_icon);
    voltage_icon.setLayoutParams(new LinearLayout.LayoutParams(vital_icon_height, vital_icon_height));
    TextView voltage_text = (TextView) view.findViewById(R.id.voltage);
    voltage_text.setLayoutParams(new LinearLayout.LayoutParams(0, vital_icon_height, 0.5f));
    voltage_text.setTextSize(android.util.TypedValue.COMPLEX_UNIT_PX, vital_text_height);

    View current_icon = view.findViewById(R.id.current_icon);
    current_icon.setLayoutParams(new LinearLayout.LayoutParams(vital_icon_height, vital_icon_height));
    TextView current_text = (TextView) view.findViewById(R.id.current);
    current_text.setLayoutParams(new LinearLayout.LayoutParams(0, vital_icon_height, 0.5f));
    current_text.setTextSize(android.util.TypedValue.COMPLEX_UNIT_PX, vital_text_height);

    // When in landscape but close to square, plugged icon gets cramped and cut off; make more room:
    if (!portrait && aspectRatio < 1.32)
        plugged_spacer.setVisibility(View.GONE);
    else
        plugged_spacer.setVisibility(View.INVISIBLE);
}

From source file:net.gsantner.opoc.util.ContextUtils.java

/**
 * Check if the device is currently in portrait orientation
 */// w w w. j a va 2  s .c  o  m
public boolean isInPortraitMode() {
    return _context.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT;
}

From source file:com.google.appinventor.components.runtime.Form.java

@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);

    final int newOrientation = newConfig.orientation;
    if (newOrientation == Configuration.ORIENTATION_LANDSCAPE
            || newOrientation == Configuration.ORIENTATION_PORTRAIT) {
        // At this point, the screen has not be resized to match the new orientation.
        // We use Handler.post so that we'll dispatch the ScreenOrientationChanged event after the
        // screen has been resized to match the new orientation.

        androidUIHandler.post(new Runnable() {
            public void run() {
                boolean dispatchEventNow = false;
                if (frameLayout != null) {
                    if (newOrientation == Configuration.ORIENTATION_LANDSCAPE) {
                        if (frameLayout.getWidth() >= frameLayout.getHeight()) {
                            dispatchEventNow = true;
                        }//from w  w w.  j  a v a 2 s  . c o  m
                    } else { // Portrait
                        if (frameLayout.getHeight() >= frameLayout.getWidth()) {
                            dispatchEventNow = true;
                        }
                    }
                }
                if (dispatchEventNow) {
                    ScreenOrientationChanged();
                } else {
                    // Try again later.
                    androidUIHandler.post(this);
                }
            }
        });
    }
}

From source file:com.cypress.cysmart.BLEServiceFragments.RGBFragment.java

@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
    if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
        LayoutInflater inflater = (LayoutInflater) getActivity()
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        rootView = inflater.inflate(R.layout.rgb_view_landscape, null);
        ViewGroup rootViewG = (ViewGroup) getView();
        // Remove all the existing views from the root view.
        rootViewG.removeAllViews();//  www  .ja  va 2 s. c  om
        rootViewG.addView(rootView);
        setUpControls();
        setDefaultColorPickerPositionColor();

    } else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) {
        LayoutInflater inflater = (LayoutInflater) getActivity()
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        rootView = inflater.inflate(R.layout.rgb_view_portrait, null);
        ViewGroup rootViewG = (ViewGroup) getView();
        // Remove all the existing views from the root view.
        rootViewG.removeAllViews();
        rootViewG.addView(rootView);
        setUpControls();
        setDefaultColorPickerPositionColor();

    }

}

From source file:com.hplasplas.cam_capture.activitys.CamCapture.java

private Bundle createBundleBitmap(String fileName, int index, int sampleSize) {

    return createBundleBitmap(fileName, index, 0, 0, sampleSize, Configuration.ORIENTATION_PORTRAIT);
}

From source file:tw.idv.palatis.danboorugallery.PostListActivity.java

@Override
public int getPreferredNumColumns() {
    int orientation = getResources().getConfiguration().orientation;
    return orientation == Configuration.ORIENTATION_PORTRAIT ? DanbooruGallerySettings.getColumnsPortrait()
            : DanbooruGallerySettings.getColumnsLandscape();
}