Example usage for android.content.pm ActivityInfo SCREEN_ORIENTATION_PORTRAIT

List of usage examples for android.content.pm ActivityInfo SCREEN_ORIENTATION_PORTRAIT

Introduction

In this page you can find the example usage for android.content.pm ActivityInfo SCREEN_ORIENTATION_PORTRAIT.

Prototype

int SCREEN_ORIENTATION_PORTRAIT

To view the source code for android.content.pm ActivityInfo SCREEN_ORIENTATION_PORTRAIT.

Click Source Link

Document

Constant corresponding to portrait in the android.R.attr#screenOrientation attribute.

Usage

From source file:Main.java

public static void fixBitmapRotationExif(String filePath, Activity activityForScreenOrientation) {
    try {/*from   ww  w. j  av a2s  .  c om*/
        ExifInterface exif = new ExifInterface(filePath);

        int exifOrientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION,
                ExifInterface.ORIENTATION_NORMAL);

        if (exifOrientation == ExifInterface.ORIENTATION_UNDEFINED
                && Build.MANUFACTURER.toLowerCase(Locale.ENGLISH).contains("htc"))
            return;

        boolean flippedHorizontally = false, flippedVertically = false;

        int angle = 0;

        if (exifOrientation == ExifInterface.ORIENTATION_ROTATE_90) {
            angle += 90;
        } else if (exifOrientation == ExifInterface.ORIENTATION_ROTATE_180) {
            angle += 180;
        } else if (exifOrientation == ExifInterface.ORIENTATION_ROTATE_270) {
            angle += 270;
        } else if (exifOrientation == ExifInterface.ORIENTATION_FLIP_HORIZONTAL) {
            flippedHorizontally = true;
        } else if (exifOrientation == ExifInterface.ORIENTATION_FLIP_VERTICAL) {
            flippedVertically = true;
        } else if (exifOrientation == ExifInterface.ORIENTATION_TRANSPOSE) {
            angle += 90;
            flippedVertically = true;
        } else if (exifOrientation == ExifInterface.ORIENTATION_TRANSVERSE) {
            angle -= 90;
            flippedVertically = true;
        }

        int orientation;

        if (activityForScreenOrientation != null) {
            orientation = getScreenOrientation(activityForScreenOrientation);
            if (orientation == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) {
                angle += 90;
            } else if (orientation == ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE) {
                angle += 180;
            } else if (orientation == ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT) {
                angle += 270;
            }
        }

        orientation = 0;
        angle = angle % 360;

        if (angle == -90 && flippedVertically && !flippedHorizontally) {
            orientation = ExifInterface.ORIENTATION_TRANSVERSE;
        } else if (angle == -270 && flippedVertically && !flippedHorizontally) {
            orientation = ExifInterface.ORIENTATION_TRANSPOSE;
        } else if (angle == -90 && !flippedVertically && flippedHorizontally) {
            orientation = ExifInterface.ORIENTATION_TRANSPOSE;
        } else if (angle == -270 && !flippedVertically && flippedHorizontally) {
            orientation = ExifInterface.ORIENTATION_TRANSVERSE;
        } else {
            while (angle < 0) {
                angle += 360;
            }
            switch (angle) {
            case 0:
                if (flippedHorizontally) {
                    orientation = ExifInterface.ORIENTATION_FLIP_HORIZONTAL;
                } else if (flippedVertically) {
                    orientation = ExifInterface.ORIENTATION_FLIP_VERTICAL;
                }
                break;
            case 90:
                orientation = ExifInterface.ORIENTATION_ROTATE_90;
                break;
            case 180:
                orientation = ExifInterface.ORIENTATION_ROTATE_180;
                break;
            case 270:
                orientation = ExifInterface.ORIENTATION_ROTATE_270;
                break;
            }
        }

        if (orientation != exifOrientation) {
            exif.setAttribute(ExifInterface.TAG_ORIENTATION, ((Integer) orientation).toString());
            exif.saveAttributes();
        }
    } catch (IOException e) {
        Log.w("TAG", "-- Error in setting image");
    }
}

From source file:Main.java

public static Bitmap getBitmapByFixingRotationForFile(String filePath, Bitmap sourceBitmap,
        Activity activityForScreenOrientation, boolean freeSourceBitmap) {
    try {/* w w  w  .j  a v a2  s  . c  o  m*/
        ExifInterface exif = new ExifInterface(filePath);
        int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);

        if (orientation == ExifInterface.ORIENTATION_UNDEFINED
                && Build.MANUFACTURER.toLowerCase(Locale.ENGLISH).contains("htc"))
            return null;

        boolean flippedHorizontally = false, flippedVertically = false;

        int angle = 0;

        if (orientation == ExifInterface.ORIENTATION_ROTATE_90) {
            angle += 90;
        } else if (orientation == ExifInterface.ORIENTATION_ROTATE_180) {
            angle += 180;
        } else if (orientation == ExifInterface.ORIENTATION_ROTATE_270) {
            angle += 270;
        } else if (orientation == ExifInterface.ORIENTATION_FLIP_HORIZONTAL) {
            flippedHorizontally = true;
        } else if (orientation == ExifInterface.ORIENTATION_FLIP_VERTICAL) {
            flippedVertically = true;
        } else if (orientation == ExifInterface.ORIENTATION_TRANSPOSE) {
            angle += 90;
            flippedVertically = true;
        } else if (orientation == ExifInterface.ORIENTATION_TRANSVERSE) {
            angle -= 90;
            flippedVertically = true;
        }

        if (activityForScreenOrientation != null) {
            orientation = getScreenOrientation(activityForScreenOrientation);
            if (orientation == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) {
                angle += 90;
            } else if (orientation == ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE) {
                angle += 180;
            } else if (orientation == ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT) {
                angle += 270;
            }
        }

        Bitmap bmp = sourceBitmap;
        if (bmp == null) {
            bmp = BitmapFactory.decodeFile(filePath, null);
        }
        if (angle != 0) {
            Matrix mat = new Matrix();
            mat.postRotate(angle);

            if (flippedHorizontally) {
                mat.postScale(-1.f, 1.f);
            }
            if (flippedVertically) {
                mat.postScale(1.f, -1.f);
            }

            Bitmap rotated = Bitmap.createBitmap(bmp, 0, 0, bmp.getWidth(), bmp.getHeight(), mat, true);
            if (freeSourceBitmap || bmp != sourceBitmap) {
                bmp.recycle();
            }
            bmp = rotated;
        }

        return bmp;

    } catch (IOException e) {
        Log.w("TAG", "-- Error in setting image");
    } catch (OutOfMemoryError oom) {
        Log.w("TAG", "-- OOM Error in setting image");
    }

    return null;
}

From source file:andlabs.lounge.lobby.ui.LoungeActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {

    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.activity);/*from   w  w w .java 2  s  .  c o  m*/

    mSectionLabel = (TextView) findViewById(R.id.lobbySection);
    mAboutIcon = (ImageView) findViewById(R.id.ic_tab_about);
    mLobbyIcon = (ImageView) findViewById(R.id.ic_tab_lobby);
    mStatsIcon = (ImageView) findViewById(R.id.ic_tab_stat);
    mChatIcon = (ImageView) findViewById(R.id.ic_tab_chat);

    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setOnPageChangeListener(this);
    mViewPager.setOffscreenPageLimit(3);
    mViewPager.setAdapter(new FragmentStatePagerAdapter(getSupportFragmentManager()) {

        @Override
        public int getCount() {
            return 4;
        }

        @Override
        public Fragment getItem(int position) {
            Ln.d("ITEM " + position);
            switch (position) {
            case LOBBY:
                return new LobbyFragment();
            case CHAT:
                return new ChatFragment();
            case STATS:
                return new StatsFragment();
            case ABOUT:
                return new AboutFragment();
            }
            return null;
        }
    });
    onPageSelected(LOBBY);
}

From source file:edu.chl.dat255.sofiase.readyforapet.viewcontroller.SelectGameActivity.java

/**
 * onCreate method/*  w  w  w.  ja v a2 s  .  c o  m*/
 * 
 * @param savedInstanceState - Bundle
 */
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.selectgame);
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

    if (dog == null) {
        try {
            dog = (Dog) Pet.load("pet_file.dat", SelectGameActivity.this);
        } catch (FileNotFoundException e) {
            System.out.print("File not found ");
            e.printStackTrace();
        } catch (IOException e) {
            System.out.print("IO Exception ");
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            System.out.print("Class not found exception ");
            e.printStackTrace();
        }

        //Test to see if the file exist on internal memory when loading
        File file = getBaseContext().getFileStreamPath("pet_file.dat");
        if (file.exists()) {
            Log.i(LOG_TAG1, "is saved on internal memory");
        } else {
            Log.i(LOG_TAG1, "is not saved on internal memory");
        }
    }

    //Continue button starts petActivity if there is an existing pet
    Button continuePreviousGame = (Button) findViewById(R.id.continuegame);
    continuePreviousGame.setOnClickListener(new OnClickListener() {

        /**
         * Method onClick for the continue previous game button
         * 
         * @param v - View
         */
        public void onClick(View v) {

            if (dog != null) {
                startActivity(new Intent(SelectGameActivity.this, PetActivity.class));
            }

            else {
                Toast.makeText(SelectGameActivity.this, "Create a pet first!", Toast.LENGTH_SHORT).show();
            }
        }
    });

    //What happens when button create new pet is pushed
    Button createNewPet = (Button) findViewById(R.id.createnewpet);
    createNewPet.setOnClickListener(new OnClickListener() {
        /**
         * Method onClick for the create new pet button
         * 
         * @param v - View
         */
        public void onClick(View v) {
            //Show a warning alert for creating a new pet if user already has a pet that is still alive.
            if (dog != null && CreatePetActivity.getPet().isAlive()) {
                showWarningAlert();
            } else {
                startActivity(new Intent(SelectGameActivity.this, CreatePetActivity.class));
            }
        }
    });
}

From source file:com.repay.android.adddebt.EditDebtActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_adddebt);
    mDB = new DatabaseHandler(this);
    // If the available screen size is that of an average tablet (as defined
    // in the Android documentation) then allow the screen to rotate
    if (getResources().getBoolean(R.bool.lock_orientation)) {
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    }/*from w w w  . j av  a2  s . co  m*/
    mActionBar = getActionBar();
    mActionBar.setDisplayHomeAsUpEnabled(true);
    mActionBar.setDisplayShowTitleEnabled(true);
    mActionBar.setSubtitle(R.string.fragment_enteramount_subtitle);
    mActionBar.setTitle(R.string.fragment_enteramount_title);

    // Instantiate Fragments
    mEnterAmount = new EnterAmountFragment();
    mSummary = new DebtSummaryFragment();

    if (getIntent().getExtras() != null) {
        Bundle bundle = getIntent().getExtras();
        int debtID = bundle.getInt(DEBT_ID);
        try {
            mDebt = mDB.getDebtByIDs(debtID);
            mFriend = mDB.getFriendByRepayID(mDebt.getRepayID());
        } catch (Exception e) {
            e.printStackTrace();
            Log.e(TAG, "Error occured in retreiving debt from sqlite db. Finishing activity");
            finish();
        }
    }

    mFragMan = getSupportFragmentManager().beginTransaction();
    mFrameLayoutRes = R.id.activity_adddebt_framelayout;
    mFragMan.add(mFrameLayoutRes, mEnterAmount);
    mFragMan.commit();
}

From source file:vn.com.zinza.zinzamessenger.activity.IntroActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);

    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    mPrefManager = new PrefManager(this);
    if (!mPrefManager.isFirstTimeLaunch()) {
        launchHomeScreen();// w ww . j  a  v a2s .  c om
        finish();
    }
    setContentView(R.layout.intro_layout);

    mIcons = new int[] { R.drawable.zinza_icon, R.drawable.chat, R.drawable.search_friend,
            R.drawable.transfer_files };
    mMessages = new int[] { R.string.app_overview_1st_item_text, R.string.app_overview_2nd_item_text,
            R.string.app_overview_3rd_item_text, R.string.app_overview_4th_item_text };
    mViewPager = (ViewPager) findViewById(R.id.intro_view_pager);
    mStartMessagingButton = (TextView) this.findViewById(R.id.start_messaging_button);
    mStartLogin = (TextView) this.findViewById(R.id.startLogin);
    mStartMessagingButton.setText(getString(R.string.StartMessaging));
    if (Build.VERSION.SDK_INT >= 21) {
        StateListAnimator animator = new StateListAnimator();
        animator.addState(new int[] { android.R.attr.state_pressed },
                ObjectAnimator.ofFloat(mStartMessagingButton, "translationZ", AndroidUtilities.dp(2, this),
                        AndroidUtilities.dp(4, this)).setDuration(200));
        animator.addState(new int[] {}, ObjectAnimator.ofFloat(mStartMessagingButton, "translationZ",
                AndroidUtilities.dp(4, this), AndroidUtilities.dp(2, this)).setDuration(200));
        mStartMessagingButton.setStateListAnimator(animator);
    }
    mTopImage1 = (ImageView) findViewById(R.id.icon_image1);
    mTopImage2 = (ImageView) findViewById(R.id.icon_image2);
    mIndicator = (CirclePageIndicator) findViewById(R.id.indicator);

    mTopImage2.setVisibility(View.GONE);
    mViewPager.setAdapter(new IntroAdapter());
    mViewPager.setPageMargin(0);
    mViewPager.setOffscreenPageLimit(1);
    mIndicator.setViewPager(mViewPager);
    mIndicator.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            if (mViewPager.getCurrentItem() == 3) {
                mStartLogin.setVisibility(View.VISIBLE);
                mStartMessagingButton.setVisibility(View.INVISIBLE);
            } else {
                mStartLogin.setVisibility(View.INVISIBLE);
                mStartMessagingButton.setVisibility(View.VISIBLE);
            }
            if (mLastPage != mViewPager.getCurrentItem()) {
                mLastPage = mViewPager.getCurrentItem();

                final ImageView fadeoutImage;
                final ImageView fadeinImage;
                if (mTopImage1.getVisibility() == View.VISIBLE) {
                    fadeoutImage = mTopImage1;
                    fadeinImage = mTopImage2;

                } else {
                    fadeoutImage = mTopImage2;
                    fadeinImage = mTopImage1;
                }

                fadeinImage.bringToFront();
                fadeinImage.setImageResource(mIcons[mLastPage]);
                fadeinImage.clearAnimation();
                fadeoutImage.clearAnimation();

                Animation outAnimation = AnimationUtils.loadAnimation(IntroActivity.this,
                        R.anim.icon_anim_fade_out);
                outAnimation.setAnimationListener(new Animation.AnimationListener() {
                    @Override
                    public void onAnimationStart(Animation animation) {
                    }

                    @Override
                    public void onAnimationEnd(Animation animation) {
                        fadeoutImage.setVisibility(View.GONE);
                    }

                    @Override
                    public void onAnimationRepeat(Animation animation) {

                    }
                });

                Animation inAnimation = AnimationUtils.loadAnimation(IntroActivity.this,
                        R.anim.icon_anim_fade_in);
                inAnimation.setAnimationListener(new Animation.AnimationListener() {
                    @Override
                    public void onAnimationStart(Animation animation) {
                        fadeinImage.setVisibility(View.VISIBLE);
                    }

                    @Override
                    public void onAnimationEnd(Animation animation) {
                    }

                    @Override
                    public void onAnimationRepeat(Animation animation) {

                    }
                });

                fadeoutImage.startAnimation(outAnimation);
                fadeinImage.startAnimation(inAnimation);
            }
        }

        @Override
        public void onPageSelected(int position) {

        }

        @Override
        public void onPageScrollStateChanged(int state) {

        }
    });

    mStartMessagingButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (mStartPressed) {
                return;
            }
            mStartPressed = true;
            launchHomeScreen();
        }
    });

    mStartLogin.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            launchHomeScreen();
        }
    });

}

From source file:com.limewoodmedia.nsdroid.activities.Preferences.java

@SuppressWarnings("deprecation")
@Override/*from w  ww .j  a v  a  2  s  .com*/
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Portrait orientation only
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
        addPreferencesFromResource(R.xml.preferences);
        PreferenceChangedListener listener = new PreferenceChangedListener(this);
        listener.doSetup(this);
    } else {
        addPreferencesFragment();
    }

    ActionBar actionBar = getSupportActionBar();
    actionBar.setHomeButtonEnabled(true);
    actionBar.setDisplayHomeAsUpEnabled(true);
}

From source file:edu.chl.dat255.sofiase.readyforapet.viewcontroller.WalkActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.walkactivity);
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

    dogPrints = (ImageView) findViewById(R.id.dogprints);

    startWalking = (Button) findViewById(R.id.startwalking);
    stopWalking = (Button) findViewById(R.id.stopwalking);

    stopWalking.setEnabled(false);//w  ww  .j a v  a 2 s  .c o m

    //Start walking button
    startWalking.setOnClickListener(new OnClickListener() {
        /**
         * Enables GPS when start walking. Starts to measure the distance.
         * Checks if the user has GPS turned on, otherwise asks if it wants to turn the GPS on.
         * 
         */
        public void onClick(View v) {

            stopWalking.setEnabled(true);
            startWalking.setEnabled(false);

            location = new LocationHelper(WalkActivity.this);

            //Checking if the GPS is enabled, else let the user start GPS if wanted.
            if (location.gpsEnabled()) {
                Toast.makeText(WalkActivity.this, "GPS is Enabled on your devide", Toast.LENGTH_SHORT).show();
            }

            else {
                showGPSDisabledAlert();
            }

            //Timer to update the textview with the distance walked.
            try {
                timer = new Timer();
                timer.schedule(myTimerTask, delay, period);
            }

            catch (Exception e) {
                e.printStackTrace();
            }

            //Animated dogprints on the screen
            dogPrints.setVisibility(View.VISIBLE);
            dogPrints.setBackgroundResource(R.anim.animation3);
            anim = (AnimationDrawable) dogPrints.getBackground();
            anim.start();
            uiHandler.postDelayed(makeViewStop, 7000);
        }
    });

    stopWalking.setOnClickListener(new OnClickListener() {
        /**
         * Method onClick for the stop walking button.
         * Stops the GPS and sends a result, the distance, to PetActivity.
         * 
         * @param v - View
         */
        public void onClick(View v) {
            distance = (int) Math.round(location.getDistance());

            //Turn off GPS
            location.killLocationServices();

            //If timer is not initiated, the timer should not be stopped
            if (timer != null) {
                timer.cancel();
            }

            //setting a resultCode with the distance walked that is sent to PetActivity
            WalkActivity.this.setResult(distance);
            WalkActivity.this.finish();

        }
    });

}

From source file:io.v.android.apps.reader.BaseReaderActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    initTracker();/*from ww w  . java2s .co m*/

    // TODO(youngseokyoon): allow screen rotation and properly handle orientation changes
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

    // Initialize the DB
    mDB = DB.Singleton.get(this);
    mDB.init(this);
}

From source file:com.lweynant.yearly.action.OrientationChangeAction.java

public static ViewAction orientationPortrait() {
    return new OrientationChangeAction(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}