Revision a5972f92
Added by Leszek Koltunski over 1 year ago
| src/main/java/org/distorted/solverui/SolverActivity.java | ||
|---|---|---|
| 12 | 12 |
import android.content.SharedPreferences; |
| 13 | 13 |
import android.os.Build; |
| 14 | 14 |
import android.os.Bundle; |
| 15 |
import android.util.DisplayMetrics; |
|
| 16 | 15 |
import android.view.DisplayCutout; |
| 17 |
import android.view.View; |
|
| 18 | 16 |
import android.view.ViewGroup; |
| 19 |
import android.view.WindowManager; |
|
| 20 | 17 |
import android.widget.LinearLayout; |
| 21 | 18 |
|
| 22 |
import androidx.appcompat.app.AppCompatActivity; |
|
| 23 | 19 |
import androidx.preference.PreferenceManager; |
| 24 | 20 |
|
| 25 | 21 |
import org.distorted.dialogs.RubikDialogError; |
| 26 | 22 |
import org.distorted.dialogs.RubikDialogMessage; |
| 23 |
import org.distorted.helpers.BaseActivity; |
|
| 27 | 24 |
import org.distorted.library.main.DistortedLibrary; |
| 28 | 25 |
import org.distorted.library.main.DistortedScreen; |
| 29 |
import org.distorted.main.MainActivity; |
|
| 30 | 26 |
import org.distorted.main.R; |
| 31 | 27 |
import org.distorted.objectlib.helpers.OperatingSystemInterface; |
| 32 | 28 |
import org.distorted.objectlib.main.InitAssets; |
| ... | ... | |
| 41 | 37 |
|
| 42 | 38 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 43 | 39 |
|
| 44 |
public class SolverActivity extends AppCompatActivity
|
|
| 40 |
public class SolverActivity extends BaseActivity
|
|
| 45 | 41 |
{
|
| 46 |
public static final float RATIO_BAR = 0.100f;
|
|
| 42 |
public static final float RATIO_UPP = 0.100f;
|
|
| 47 | 43 |
public static final float PADDING = 0.010f; |
| 48 | 44 |
public static final float SMALL_MARGIN = 0.004f; |
| 49 | 45 |
public static final float BUTTON_TEXT_SIZE= 0.050f; |
| ... | ... | |
| 52 | 48 |
private static final int ACTIVITY_NUMBER = 4; |
| 53 | 49 |
private static final float RATIO_INSET= 0.09f; |
| 54 | 50 |
|
| 55 |
private static int mScreenWidth, mScreenHeight; |
|
| 56 |
private int mCurrentApiVersion; |
|
| 57 |
private int mHeightUpperBar; |
|
| 58 | 51 |
private int mSolverOrdinal; |
| 59 | 52 |
private int mObjectOrdinal; |
| 60 | 53 |
private boolean mDisplayMessageDialog; |
| ... | ... | |
| 64 | 57 |
@Override |
| 65 | 58 |
protected void onCreate(Bundle savedState) |
| 66 | 59 |
{
|
| 67 |
setTheme(R.style.MaterialThemeNoActionBar); |
|
| 68 | 60 |
super.onCreate(savedState); |
| 69 | 61 |
DistortedLibrary.onCreate(ACTIVITY_NUMBER); |
| 70 | 62 |
setContentView(R.layout.solver); |
| 71 |
hideNavigationBar(); |
|
| 72 | 63 |
|
| 73 | 64 |
Bundle b = getIntent().getExtras(); |
| 74 | 65 |
mObjectOrdinal = b!=null ? b.getInt("obj") : 0;
|
| 75 | 66 |
mSolverOrdinal = ImplementedSolversList.getSolverOrdinal(mObjectOrdinal); |
| 76 |
|
|
| 77 |
DisplayMetrics displaymetrics = new DisplayMetrics(); |
|
| 78 |
getWindowManager().getDefaultDisplay().getRealMetrics(displaymetrics); |
|
| 79 |
mScreenWidth =displaymetrics.widthPixels; |
|
| 80 |
mScreenHeight=displaymetrics.heightPixels; |
|
| 81 |
|
|
| 82 | 67 |
mDisplayMessageDialog = true; |
| 83 | 68 |
|
| 69 |
computeScreenDimensions(); |
|
| 70 |
hideNavigationBar(); |
|
| 84 | 71 |
cutoutHack(); |
| 85 |
computeBarHeights(); |
|
| 86 |
} |
|
| 87 |
|
|
| 88 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 89 |
// this does not include possible insets |
|
| 90 |
|
|
| 91 |
private void computeBarHeights() |
|
| 92 |
{
|
|
| 93 |
int barHeight = (int)(mScreenHeight*RATIO_BAR); |
|
| 94 |
mHeightUpperBar = barHeight; |
|
| 95 |
|
|
| 96 |
LinearLayout layoutTop = findViewById(R.id.upperBar); |
|
| 97 |
LinearLayout layoutBot = findViewById(R.id.lowerBar); |
|
| 98 |
|
|
| 99 |
ViewGroup.LayoutParams paramsTop = layoutTop.getLayoutParams(); |
|
| 100 |
paramsTop.height = mHeightUpperBar; |
|
| 101 |
layoutTop.setLayoutParams(paramsTop); |
|
| 102 |
ViewGroup.LayoutParams paramsBot = layoutBot.getLayoutParams(); |
|
| 103 |
paramsBot.height = barHeight; |
|
| 104 |
layoutBot.setLayoutParams(paramsBot); |
|
| 105 |
} |
|
| 106 |
|
|
| 107 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 108 |
|
|
| 109 |
private void hideNavigationBar() |
|
| 110 |
{
|
|
| 111 |
mCurrentApiVersion = Build.VERSION.SDK_INT; |
|
| 112 |
|
|
| 113 |
if(mCurrentApiVersion >= Build.VERSION_CODES.KITKAT) |
|
| 114 |
{
|
|
| 115 |
final View decorView = getWindow().getDecorView(); |
|
| 116 |
|
|
| 117 |
decorView.setSystemUiVisibility(MainActivity.FLAGS); |
|
| 118 |
|
|
| 119 |
decorView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() |
|
| 120 |
{
|
|
| 121 |
@Override |
|
| 122 |
public void onSystemUiVisibilityChange(int visibility) |
|
| 123 |
{
|
|
| 124 |
if((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) |
|
| 125 |
{
|
|
| 126 |
decorView.setSystemUiVisibility(MainActivity.FLAGS); |
|
| 127 |
} |
|
| 128 |
} |
|
| 129 |
}); |
|
| 130 |
} |
|
| 72 |
computeUpperBarHeight(RATIO_UPP); |
|
| 73 |
computeLowerBarHeight(RATIO_BAR); |
|
| 131 | 74 |
} |
| 132 | 75 |
|
| 133 | 76 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 146 | 89 |
ViewGroup.LayoutParams paramsHid = layoutHid.getLayoutParams(); |
| 147 | 90 |
paramsHid.height = (int)(insetHeight*RATIO_INSET); |
| 148 | 91 |
layoutHid.setLayoutParams(paramsHid); |
| 149 |
mHeightUpperBar += paramsHid.height; |
|
| 150 |
} |
|
| 151 |
} |
|
| 152 |
|
|
| 153 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 154 |
// do not avoid cutouts |
|
| 155 |
|
|
| 156 |
private void cutoutHack() |
|
| 157 |
{
|
|
| 158 |
if( Build.VERSION.SDK_INT >= Build.VERSION_CODES.P ) |
|
| 159 |
{
|
|
| 160 |
getWindow().getAttributes().layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES; |
|
| 161 |
} |
|
| 162 |
} |
|
| 163 |
|
|
| 164 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 165 |
|
|
| 166 |
@Override |
|
| 167 |
public void onWindowFocusChanged(boolean hasFocus) |
|
| 168 |
{
|
|
| 169 |
super.onWindowFocusChanged(hasFocus); |
|
| 170 |
|
|
| 171 |
if( mCurrentApiVersion >= Build.VERSION_CODES.KITKAT && hasFocus ) |
|
| 172 |
{
|
|
| 173 |
getWindow().getDecorView().setSystemUiVisibility(MainActivity.FLAGS); |
|
| 174 | 92 |
} |
| 175 | 93 |
} |
| 176 | 94 |
|
| ... | ... | |
| 296 | 214 |
return view.getObjectControl(); |
| 297 | 215 |
} |
| 298 | 216 |
|
| 299 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 300 |
|
|
| 301 |
public int getScreenWidthInPixels() |
|
| 302 |
{
|
|
| 303 |
return mScreenWidth; |
|
| 304 |
} |
|
| 305 |
|
|
| 306 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 307 |
|
|
| 308 |
public int getScreenHeightInPixels() |
|
| 309 |
{
|
|
| 310 |
return mScreenHeight; |
|
| 311 |
} |
|
| 312 |
|
|
| 313 | 217 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 314 | 218 |
|
| 315 | 219 |
public int getSolverOrdinal() |
Also available in: Unified diff
common code from all activities to one BaseActivity