1
0
mirror of https://github.com/oliexdev/openScale.git synced 2025-08-31 03:59:56 +02:00

lock screen orientation on portrait if screen size is small

This commit is contained in:
OliE
2015-01-05 10:30:40 +01:00
parent e034e52bf5
commit 717342bfc4
3 changed files with 38 additions and 1 deletions

View File

@@ -16,7 +16,9 @@
package com.health.openscale.gui;
import android.app.Activity;
import android.content.SharedPreferences;
import android.content.pm.ActivityInfo;
import android.graphics.Color;
import android.os.Bundle;
import android.preference.PreferenceManager;
@@ -316,4 +318,13 @@ public class GraphFragment extends Fragment implements FragmentUpdateListener {
}
}
@Override
public void setUserVisibleHint(boolean isVisibleToUser) {
super.setUserVisibleHint(isVisibleToUser);
if(isVisibleToUser) {
Activity a = getActivity();
if(a != null) a.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR);
}
}
}

View File

@@ -15,7 +15,9 @@
*/
package com.health.openscale.gui;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
import android.os.Bundle;
import android.support.v4.app.Fragment;
@@ -146,4 +148,17 @@ public class OverviewFragment extends Fragment implements FragmentUpdateListener
{
updateOnView(OpenScale.getInstance(overviewView.getContext()).getScaleDataList());
}
@Override
public void setUserVisibleHint(boolean isVisibleToUser) {
super.setUserVisibleHint(isVisibleToUser);
if (isVisibleToUser) {
if ((getActivity().getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) != Configuration.SCREENLAYOUT_SIZE_XLARGE &&
(getActivity().getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) != Configuration.SCREENLAYOUT_SIZE_LARGE) {
Activity a = getActivity();
if (a != null) a.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
}
}
}

View File

@@ -15,9 +15,11 @@
*/
package com.health.openscale.gui;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
import android.graphics.Color;
import android.os.Bundle;
@@ -144,7 +146,7 @@ public class TableFragment extends Fragment implements FragmentUpdateListener {
deleteButton.setText("X");
deleteButton.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 10);
deleteButton.setTextColor(Color.WHITE);
deleteButton.setBackground(getResources().getDrawable(R.drawable.flat_selector));
deleteButton.setBackgroundResource(R.drawable.flat_selector);
deleteButton.setGravity(Gravity.CENTER);
deleteButton.setPadding(0, 0, 0, 0);
deleteButton.setMinimumHeight(35);
@@ -305,4 +307,13 @@ public class TableFragment extends Fragment implements FragmentUpdateListener {
updateOnView(OpenScale.getInstance(tableView.getContext()).getScaleDataList());
}
}
@Override
public void setUserVisibleHint(boolean isVisibleToUser) {
super.setUserVisibleHint(isVisibleToUser);
if(isVisibleToUser) {
Activity a = getActivity();
if(a != null) a.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR);
}
}
}