| 1 |
1237d25d
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 2 |
|
|
// Copyright 2019 Leszek Koltunski //
|
| 3 |
|
|
// //
|
| 4 |
|
|
// This file is part of Magic Cube. //
|
| 5 |
|
|
// //
|
| 6 |
|
|
// Magic Cube is free software: you can redistribute it and/or modify //
|
| 7 |
|
|
// it under the terms of the GNU General Public License as published by //
|
| 8 |
|
|
// the Free Software Foundation, either version 2 of the License, or //
|
| 9 |
|
|
// (at your option) any later version. //
|
| 10 |
|
|
// //
|
| 11 |
|
|
// Magic Cube is distributed in the hope that it will be useful, //
|
| 12 |
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
| 13 |
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
| 14 |
|
|
// GNU General Public License for more details. //
|
| 15 |
|
|
// //
|
| 16 |
|
|
// You should have received a copy of the GNU General Public License //
|
| 17 |
|
|
// along with Magic Cube. If not, see <http://www.gnu.org/licenses/>. //
|
| 18 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 19 |
|
|
|
| 20 |
|
|
package org.distorted.config;
|
| 21 |
|
|
|
| 22 |
314e9ff0
|
Leszek Koltunski
|
import java.io.InputStream;
|
| 23 |
|
|
|
| 24 |
1237d25d
|
Leszek Koltunski
|
import android.os.Build;
|
| 25 |
|
|
import android.os.Bundle;
|
| 26 |
|
|
import android.util.DisplayMetrics;
|
| 27 |
|
|
import android.view.View;
|
| 28 |
|
|
import android.view.ViewGroup;
|
| 29 |
|
|
import android.view.WindowManager;
|
| 30 |
|
|
import android.widget.LinearLayout;
|
| 31 |
|
|
import androidx.appcompat.app.AppCompatActivity;
|
| 32 |
|
|
import com.google.firebase.analytics.FirebaseAnalytics;
|
| 33 |
|
|
|
| 34 |
|
|
import org.distorted.library.main.DistortedLibrary;
|
| 35 |
|
|
import org.distorted.objectlib.main.ObjectControl;
|
| 36 |
314e9ff0
|
Leszek Koltunski
|
import org.distorted.main.R;
|
| 37 |
|
|
import org.distorted.dialogs.RubikDialogError;
|
| 38 |
d433b50e
|
Leszek Koltunski
|
import org.distorted.objects.RubikObject;
|
| 39 |
|
|
import org.distorted.objects.RubikObjectList;
|
| 40 |
1237d25d
|
Leszek Koltunski
|
|
| 41 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 42 |
|
|
|
| 43 |
|
|
public class ConfigActivity extends AppCompatActivity
|
| 44 |
|
|
{
|
| 45 |
|
|
private static final int ACTIVITY_NUMBER = 2;
|
| 46 |
97a4ae23
|
Leszek Koltunski
|
private static final float RATIO_BAR = 0.10f;
|
| 47 |
1237d25d
|
Leszek Koltunski
|
|
| 48 |
|
|
public static final float DIALOG_BUTTON_SIZE = 0.06f;
|
| 49 |
|
|
public static final float MENU_BIG_TEXT_SIZE = 0.05f;
|
| 50 |
|
|
|
| 51 |
|
|
public static final int FLAGS = View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
|
| 52 |
|
|
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
|
| 53 |
|
|
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
|
| 54 |
|
|
| View.SYSTEM_UI_FLAG_FULLSCREEN
|
| 55 |
|
|
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
|
| 56 |
|
|
|
| 57 |
|
|
private FirebaseAnalytics mFirebaseAnalytics;
|
| 58 |
|
|
private static int mScreenWidth, mScreenHeight;
|
| 59 |
|
|
private int mCurrentApiVersion;
|
| 60 |
|
|
private ConfigScreen mScreen;
|
| 61 |
|
|
private int mObjectOrdinal;
|
| 62 |
97a4ae23
|
Leszek Koltunski
|
private int mHeightBar;
|
| 63 |
1237d25d
|
Leszek Koltunski
|
|
| 64 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 65 |
|
|
|
| 66 |
|
|
@Override
|
| 67 |
|
|
protected void onCreate(Bundle savedState)
|
| 68 |
|
|
{
|
| 69 |
|
|
super.onCreate(savedState);
|
| 70 |
|
|
DistortedLibrary.onCreate(ACTIVITY_NUMBER);
|
| 71 |
|
|
setTheme(R.style.MaterialThemeNoActionBar);
|
| 72 |
|
|
setContentView(R.layout.config);
|
| 73 |
|
|
|
| 74 |
|
|
Bundle b = getIntent().getExtras();
|
| 75 |
|
|
|
| 76 |
|
|
if(b != null) mObjectOrdinal = b.getInt("obj");
|
| 77 |
|
|
|
| 78 |
|
|
mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);
|
| 79 |
|
|
|
| 80 |
|
|
DisplayMetrics displaymetrics = new DisplayMetrics();
|
| 81 |
|
|
getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
|
| 82 |
|
|
mScreenWidth =displaymetrics.widthPixels;
|
| 83 |
|
|
mScreenHeight=displaymetrics.heightPixels;
|
| 84 |
97a4ae23
|
Leszek Koltunski
|
mScreenHeight = (int)(1.07f*mScreenHeight); // add 7% for the upper bar
|
| 85 |
|
|
// which is not yet hidden.
|
| 86 |
|
|
// TODO: figure this out exactly.
|
| 87 |
1237d25d
|
Leszek Koltunski
|
hideNavigationBar();
|
| 88 |
|
|
cutoutHack();
|
| 89 |
97a4ae23
|
Leszek Koltunski
|
computeBarHeights();
|
| 90 |
|
|
}
|
| 91 |
|
|
|
| 92 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 93 |
|
|
// this does not include possible insets
|
| 94 |
|
|
|
| 95 |
|
|
private void computeBarHeights()
|
| 96 |
|
|
{
|
| 97 |
|
|
int barHeight = (int)(mScreenHeight*RATIO_BAR);
|
| 98 |
|
|
mHeightBar = barHeight;
|
| 99 |
|
|
|
| 100 |
|
|
LinearLayout layout = findViewById(R.id.lowerBar);
|
| 101 |
|
|
ViewGroup.LayoutParams params = layout.getLayoutParams();
|
| 102 |
|
|
params.height = barHeight;
|
| 103 |
|
|
layout.setLayoutParams(params);
|
| 104 |
1237d25d
|
Leszek Koltunski
|
}
|
| 105 |
|
|
|
| 106 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 107 |
|
|
|
| 108 |
|
|
private void hideNavigationBar()
|
| 109 |
|
|
{
|
| 110 |
|
|
mCurrentApiVersion = Build.VERSION.SDK_INT;
|
| 111 |
|
|
|
| 112 |
|
|
if(mCurrentApiVersion >= Build.VERSION_CODES.KITKAT)
|
| 113 |
|
|
{
|
| 114 |
|
|
final View decorView = getWindow().getDecorView();
|
| 115 |
|
|
|
| 116 |
|
|
decorView.setSystemUiVisibility(FLAGS);
|
| 117 |
|
|
|
| 118 |
|
|
decorView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener()
|
| 119 |
|
|
{
|
| 120 |
|
|
@Override
|
| 121 |
|
|
public void onSystemUiVisibilityChange(int visibility)
|
| 122 |
|
|
{
|
| 123 |
|
|
if((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0)
|
| 124 |
|
|
{
|
| 125 |
|
|
decorView.setSystemUiVisibility(FLAGS);
|
| 126 |
|
|
}
|
| 127 |
|
|
}
|
| 128 |
|
|
});
|
| 129 |
|
|
}
|
| 130 |
|
|
}
|
| 131 |
|
|
|
| 132 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 133 |
|
|
// do not avoid cutouts
|
| 134 |
|
|
|
| 135 |
|
|
private void cutoutHack()
|
| 136 |
|
|
{
|
| 137 |
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P)
|
| 138 |
|
|
{
|
| 139 |
|
|
getWindow().getAttributes().layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
|
| 140 |
|
|
}
|
| 141 |
|
|
}
|
| 142 |
|
|
|
| 143 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 144 |
|
|
|
| 145 |
|
|
@Override
|
| 146 |
|
|
public void onWindowFocusChanged(boolean hasFocus)
|
| 147 |
|
|
{
|
| 148 |
|
|
super.onWindowFocusChanged(hasFocus);
|
| 149 |
|
|
|
| 150 |
|
|
if(mCurrentApiVersion >= Build.VERSION_CODES.KITKAT && hasFocus)
|
| 151 |
|
|
{
|
| 152 |
|
|
getWindow().getDecorView().setSystemUiVisibility(FLAGS);
|
| 153 |
|
|
}
|
| 154 |
|
|
}
|
| 155 |
|
|
|
| 156 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 157 |
|
|
|
| 158 |
|
|
@Override
|
| 159 |
|
|
protected void onPause()
|
| 160 |
|
|
{
|
| 161 |
|
|
super.onPause();
|
| 162 |
|
|
ConfigSurfaceView view = findViewById(R.id.configSurfaceView);
|
| 163 |
|
|
view.onPause();
|
| 164 |
|
|
DistortedLibrary.onPause(ACTIVITY_NUMBER);
|
| 165 |
|
|
}
|
| 166 |
|
|
|
| 167 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 168 |
|
|
|
| 169 |
|
|
@Override
|
| 170 |
|
|
protected void onResume()
|
| 171 |
|
|
{
|
| 172 |
|
|
super.onResume();
|
| 173 |
|
|
DistortedLibrary.onResume(ACTIVITY_NUMBER);
|
| 174 |
|
|
ConfigSurfaceView view = findViewById(R.id.configSurfaceView);
|
| 175 |
|
|
view.onResume();
|
| 176 |
|
|
|
| 177 |
280dc794
|
Leszek Koltunski
|
if( mScreen==null ) mScreen = new ConfigScreen();
|
| 178 |
|
|
mScreen.onAttachedToWindow(this,mObjectOrdinal);
|
| 179 |
|
|
|
| 180 |
d433b50e
|
Leszek Koltunski
|
if( mObjectOrdinal>=0 && mObjectOrdinal< RubikObjectList.getNumObjects() )
|
| 181 |
1237d25d
|
Leszek Koltunski
|
{
|
| 182 |
d433b50e
|
Leszek Koltunski
|
RubikObject object = RubikObjectList.getObject(mObjectOrdinal);
|
| 183 |
d36d8517
|
Leszek Koltunski
|
changeIfDifferent(object,mObjectOrdinal,view.getObjectControl());
|
| 184 |
1237d25d
|
Leszek Koltunski
|
}
|
| 185 |
|
|
}
|
| 186 |
|
|
|
| 187 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 188 |
|
|
|
| 189 |
|
|
@Override
|
| 190 |
|
|
protected void onDestroy()
|
| 191 |
|
|
{
|
| 192 |
|
|
super.onDestroy();
|
| 193 |
|
|
DistortedLibrary.onDestroy(ACTIVITY_NUMBER);
|
| 194 |
|
|
}
|
| 195 |
|
|
|
| 196 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 197 |
|
|
|
| 198 |
|
|
void OpenGLError()
|
| 199 |
|
|
{
|
| 200 |
|
|
RubikDialogError errDiag = new RubikDialogError();
|
| 201 |
|
|
errDiag.show(getSupportFragmentManager(), null);
|
| 202 |
|
|
}
|
| 203 |
|
|
|
| 204 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 205 |
|
|
|
| 206 |
d36d8517
|
Leszek Koltunski
|
private void changeIfDifferent(RubikObject object,int ordinal,ObjectControl control)
|
| 207 |
1237d25d
|
Leszek Koltunski
|
{
|
| 208 |
d433b50e
|
Leszek Koltunski
|
if( object!=null )
|
| 209 |
|
|
{
|
| 210 |
314e9ff0
|
Leszek Koltunski
|
int meshState = object.getMeshState();
|
| 211 |
|
|
InputStream jsonStream = object.getObjectStream(this);
|
| 212 |
|
|
InputStream meshStream = object.getMeshStream(this);
|
| 213 |
aec421fd
|
Leszek Koltunski
|
String name = object.getUpperName();
|
| 214 |
09cf2a36
|
Leszek Koltunski
|
|
| 215 |
aec421fd
|
Leszek Koltunski
|
control.changeIfDifferent(ordinal,name,meshState,jsonStream,meshStream);
|
| 216 |
d433b50e
|
Leszek Koltunski
|
}
|
| 217 |
1237d25d
|
Leszek Koltunski
|
}
|
| 218 |
|
|
|
| 219 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 220 |
|
|
// PUBLIC API
|
| 221 |
09cf2a36
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 222 |
|
|
|
| 223 |
280dc794
|
Leszek Koltunski
|
public void changeObject(int ordinal)
|
| 224 |
09cf2a36
|
Leszek Koltunski
|
{
|
| 225 |
280dc794
|
Leszek Koltunski
|
mObjectOrdinal = ordinal;
|
| 226 |
|
|
RubikObject object = RubikObjectList.getObject(ordinal);
|
| 227 |
09cf2a36
|
Leszek Koltunski
|
ConfigSurfaceView view = findViewById(R.id.configSurfaceView);
|
| 228 |
|
|
ObjectControl control = view.getObjectControl();
|
| 229 |
d36d8517
|
Leszek Koltunski
|
changeIfDifferent(object,ordinal,control);
|
| 230 |
09cf2a36
|
Leszek Koltunski
|
}
|
| 231 |
|
|
|
| 232 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 233 |
|
|
|
| 234 |
d36d8517
|
Leszek Koltunski
|
public void changeMeshState(RubikObject object, int ordinal)
|
| 235 |
09cf2a36
|
Leszek Koltunski
|
{
|
| 236 |
|
|
if( object!=null )
|
| 237 |
|
|
{
|
| 238 |
|
|
ConfigSurfaceView view = findViewById(R.id.configSurfaceView);
|
| 239 |
|
|
ObjectControl control = view.getObjectControl();
|
| 240 |
|
|
|
| 241 |
314e9ff0
|
Leszek Koltunski
|
int meshState = object.getMeshState();
|
| 242 |
|
|
InputStream jsonStream = object.getObjectStream(this);
|
| 243 |
|
|
InputStream meshStream = object.getMeshStream(this);
|
| 244 |
09cf2a36
|
Leszek Koltunski
|
|
| 245 |
314e9ff0
|
Leszek Koltunski
|
control.changeObject(ordinal,meshState,jsonStream,meshStream);
|
| 246 |
09cf2a36
|
Leszek Koltunski
|
}
|
| 247 |
|
|
}
|
| 248 |
|
|
|
| 249 |
1237d25d
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 250 |
|
|
|
| 251 |
|
|
public FirebaseAnalytics getAnalytics()
|
| 252 |
|
|
{
|
| 253 |
|
|
return mFirebaseAnalytics;
|
| 254 |
|
|
}
|
| 255 |
|
|
|
| 256 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 257 |
|
|
|
| 258 |
97a4ae23
|
Leszek Koltunski
|
public int getHeightBar()
|
| 259 |
1237d25d
|
Leszek Koltunski
|
{
|
| 260 |
97a4ae23
|
Leszek Koltunski
|
return mHeightBar;
|
| 261 |
1237d25d
|
Leszek Koltunski
|
}
|
| 262 |
|
|
|
| 263 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 264 |
|
|
|
| 265 |
|
|
public int getScreenWidthInPixels()
|
| 266 |
|
|
{
|
| 267 |
|
|
return mScreenWidth;
|
| 268 |
|
|
}
|
| 269 |
|
|
|
| 270 |
97a4ae23
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 271 |
|
|
|
| 272 |
|
|
public int getScreenHeightInPixels()
|
| 273 |
|
|
{
|
| 274 |
|
|
return mScreenHeight;
|
| 275 |
|
|
}
|
| 276 |
|
|
|
| 277 |
1237d25d
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 278 |
|
|
|
| 279 |
|
|
public ObjectControl getControl()
|
| 280 |
|
|
{
|
| 281 |
|
|
ConfigSurfaceView view = findViewById(R.id.configSurfaceView);
|
| 282 |
|
|
return view.getObjectControl();
|
| 283 |
|
|
}
|
| 284 |
|
|
|
| 285 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 286 |
|
|
|
| 287 |
|
|
public static int getDrawableSize()
|
| 288 |
|
|
{
|
| 289 |
|
|
if( mScreenHeight<1000 )
|
| 290 |
|
|
{
|
| 291 |
|
|
return 0;
|
| 292 |
|
|
}
|
| 293 |
|
|
if( mScreenHeight<1600 )
|
| 294 |
|
|
{
|
| 295 |
|
|
return 1;
|
| 296 |
|
|
}
|
| 297 |
|
|
if( mScreenHeight<1900 )
|
| 298 |
|
|
{
|
| 299 |
|
|
return 2;
|
| 300 |
|
|
}
|
| 301 |
|
|
|
| 302 |
|
|
return 3;
|
| 303 |
|
|
}
|
| 304 |
|
|
|
| 305 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 306 |
|
|
|
| 307 |
|
|
public static int getDrawable(int small, int medium, int big, int huge)
|
| 308 |
|
|
{
|
| 309 |
|
|
int size = getDrawableSize();
|
| 310 |
|
|
|
| 311 |
|
|
switch(size)
|
| 312 |
|
|
{
|
| 313 |
|
|
case 0 : return small;
|
| 314 |
|
|
case 1 : return medium;
|
| 315 |
|
|
case 2 : return big;
|
| 316 |
|
|
default: return huge;
|
| 317 |
|
|
}
|
| 318 |
|
|
}
|
| 319 |
|
|
|
| 320 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 321 |
|
|
|
| 322 |
|
|
public boolean isVertical()
|
| 323 |
|
|
{
|
| 324 |
|
|
ConfigSurfaceView view = findViewById(R.id.configSurfaceView);
|
| 325 |
|
|
return view.isVertical();
|
| 326 |
|
|
}
|
| 327 |
|
|
}
|