Revision 9881dc03
Added by Leszek Koltunski over 1 year ago
| src/main/java/org/distorted/bandaged/BandagedActivity.java | ||
|---|---|---|
| 21 | 21 |
import android.view.ViewGroup; |
| 22 | 22 |
import android.widget.LinearLayout; |
| 23 | 23 |
|
| 24 |
import androidx.preference.PreferenceManager; |
|
| 25 |
|
|
| 26 | 24 |
import org.distorted.dialogs.RubikDialogError; |
| 27 | 25 |
import org.distorted.dialogs.RubikDialogMessage; |
| 28 | 26 |
import org.distorted.external.RubikFiles; |
| ... | ... | |
| 166 | 164 |
|
| 167 | 165 |
private void savePreferences() |
| 168 | 166 |
{
|
| 169 |
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); |
|
| 170 |
SharedPreferences.Editor editor = preferences.edit(); |
|
| 167 |
SharedPreferences.Editor editor = mPreferences.edit(); |
|
| 171 | 168 |
mScreen.savePreferences(editor); |
| 172 | 169 |
|
| 173 | 170 |
editor.putBoolean("bandageDisplayDialog", mDisplayMessageDialog );
|
| ... | ... | |
| 179 | 176 |
|
| 180 | 177 |
private void restorePreferences() |
| 181 | 178 |
{
|
| 182 |
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); |
|
| 183 |
mScreen.restorePreferences(this,preferences); |
|
| 179 |
mScreen.restorePreferences(this,mPreferences); |
|
| 184 | 180 |
|
| 185 |
mDisplayMessageDialog = preferences.getBoolean("bandageDisplayDialog",true);
|
|
| 181 |
mDisplayMessageDialog = mPreferences.getBoolean("bandageDisplayDialog",true);
|
|
| 186 | 182 |
|
| 187 | 183 |
if( mDisplayMessageDialog ) |
| 188 | 184 |
{
|
| ... | ... | |
| 254 | 250 |
|
| 255 | 251 |
if( !object.getError() ) |
| 256 | 252 |
{
|
| 257 |
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); |
|
| 258 |
SharedPreferences.Editor editor = preferences.edit(); |
|
| 253 |
SharedPreferences.Editor editor = mPreferences.edit(); |
|
| 259 | 254 |
OSInterface os = new OSInterface(this,null); |
| 260 | 255 |
os.setEditor(editor); |
| 261 | 256 |
object.removePreferences(os); |
| src/main/java/org/distorted/config/ConfigActivity.java | ||
|---|---|---|
| 9 | 9 |
|
| 10 | 10 |
package org.distorted.config; |
| 11 | 11 |
|
| 12 |
import android.content.SharedPreferences; |
|
| 13 | 12 |
import android.os.Bundle; |
| 14 |
|
|
| 15 |
import androidx.preference.PreferenceManager; |
|
| 13 |
import android.content.SharedPreferences; |
|
| 16 | 14 |
|
| 17 | 15 |
import org.distorted.dialogs.RubikDialogError; |
| 18 | 16 |
import org.distorted.dialogs.RubikDialogMessage; |
| ... | ... | |
| 95 | 93 |
} |
| 96 | 94 |
} |
| 97 | 95 |
|
| 98 |
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); |
|
| 99 | 96 |
OSInterface os = view.getInterface(); |
| 100 |
os.setPreferences(preferences); |
|
| 101 |
|
|
| 102 |
restorePreferences(preferences); |
|
| 97 |
os.setPreferences(mPreferences); |
|
| 98 |
restorePreferences(); |
|
| 103 | 99 |
|
| 104 | 100 |
if( mScreen==null ) mScreen = new ConfigScreen(); |
| 105 | 101 |
mScreen.onAttachedToWindow(this,mObjectOrdinal); |
| ... | ... | |
| 157 | 153 |
|
| 158 | 154 |
private void savePreferences() |
| 159 | 155 |
{
|
| 160 |
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); |
|
| 161 |
SharedPreferences.Editor editor = preferences.edit(); |
|
| 156 |
SharedPreferences.Editor editor = mPreferences.edit(); |
|
| 162 | 157 |
|
| 163 | 158 |
ConfigSurfaceView view = findViewById(R.id.configSurfaceView); |
| 164 | 159 |
OSInterface os = view.getInterface(); |
| ... | ... | |
| 172 | 167 |
|
| 173 | 168 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 174 | 169 |
|
| 175 |
private void restorePreferences(SharedPreferences preferences)
|
|
| 170 |
private void restorePreferences() |
|
| 176 | 171 |
{
|
| 177 | 172 |
ConfigSurfaceView view = findViewById(R.id.configSurfaceView); |
| 178 | 173 |
view.getObjectControl().restoreStickers(); |
| 179 | 174 |
|
| 180 |
mDisplayMessageDialog = preferences.getBoolean("configDisplayDialog",true);
|
|
| 175 |
mDisplayMessageDialog = mPreferences.getBoolean("configDisplayDialog",true);
|
|
| 181 | 176 |
|
| 182 | 177 |
if( mDisplayMessageDialog ) |
| 183 | 178 |
{
|
| src/main/java/org/distorted/helpers/BaseActivity.java | ||
|---|---|---|
| 9 | 9 |
|
| 10 | 10 |
package org.distorted.helpers; |
| 11 | 11 |
|
| 12 |
import android.content.SharedPreferences; |
|
| 12 | 13 |
import android.content.res.Configuration; |
| 13 | 14 |
import android.os.Build; |
| 14 | 15 |
import android.os.Bundle; |
| ... | ... | |
| 19 | 20 |
import android.widget.LinearLayout; |
| 20 | 21 |
|
| 21 | 22 |
import androidx.appcompat.app.AppCompatActivity; |
| 23 |
import androidx.preference.PreferenceManager; |
|
| 22 | 24 |
|
| 23 | 25 |
import org.distorted.main.R; |
| 24 | 26 |
|
| ... | ... | |
| 26 | 28 |
|
| 27 | 29 |
public class BaseActivity extends AppCompatActivity |
| 28 | 30 |
{
|
| 31 |
protected static final int THEME_GREY = 0; |
|
| 32 |
protected static final int THEME_WHITE = 1; |
|
| 33 |
protected static final int THEME_GREEN = 2; |
|
| 34 |
|
|
| 35 |
public static final float RATIO_HID = 0.050f; |
|
| 29 | 36 |
public static final float RATIO_BAR = 0.080f; |
| 30 | 37 |
public static final int FLAGS = View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |
| 31 | 38 |
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
| ... | ... | |
| 34 | 41 |
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY; |
| 35 | 42 |
|
| 36 | 43 |
private int mCurrentApiVersion; |
| 44 |
protected int mCurrentTheme; |
|
| 37 | 45 |
protected int mScreenWidth, mScreenHeight; |
| 38 | 46 |
protected int mHeightLowerBar, mHeightUpperBar; |
| 47 |
protected SharedPreferences mPreferences; |
|
| 39 | 48 |
|
| 40 | 49 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 41 | 50 |
|
| 42 | 51 |
@Override |
| 43 | 52 |
protected void onCreate(Bundle savedState) |
| 44 | 53 |
{
|
| 45 |
setTheme(R.style.MaterialThemeNoActionBar); |
|
| 54 |
mPreferences = PreferenceManager.getDefaultSharedPreferences(this); |
|
| 55 |
mCurrentTheme = mPreferences.getInt("theme",THEME_GREY);
|
|
| 56 |
|
|
| 57 |
switch(mCurrentTheme) |
|
| 58 |
{
|
|
| 59 |
case THEME_WHITE : setTheme(R.style.WhiteTheme); break; |
|
| 60 |
case THEME_GREEN : setTheme(R.style.GreenTheme); break; |
|
| 61 |
default : setTheme(R.style.GreyTheme); break; |
|
| 62 |
} |
|
| 63 |
|
|
| 64 |
android.util.Log.e("D", "current theme: "+mCurrentTheme);
|
|
| 65 |
|
|
| 46 | 66 |
super.onCreate(savedState); |
| 47 | 67 |
} |
| 48 | 68 |
|
| 69 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 70 |
|
|
| 71 |
public void changeThemeTo(int theme) |
|
| 72 |
{
|
|
| 73 |
mCurrentTheme = theme; |
|
| 74 |
|
|
| 75 |
SharedPreferences.Editor editor = mPreferences.edit(); |
|
| 76 |
editor.putInt("theme", mCurrentTheme );
|
|
| 77 |
editor.apply(); |
|
| 78 |
|
|
| 79 |
recreate(); |
|
| 80 |
} |
|
| 81 |
|
|
| 49 | 82 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 50 | 83 |
|
| 51 | 84 |
protected void getWindowWidth(Configuration conf) |
| src/main/java/org/distorted/main/MainActivity.java | ||
|---|---|---|
| 25 | 25 |
import android.widget.TextView; |
| 26 | 26 |
|
| 27 | 27 |
import androidx.annotation.NonNull; |
| 28 |
import androidx.preference.PreferenceManager; |
|
| 29 | 28 |
|
| 30 | 29 |
import com.google.firebase.analytics.FirebaseAnalytics; |
| 31 | 30 |
import com.google.firebase.inappmessaging.FirebaseInAppMessaging; |
| ... | ... | |
| 79 | 78 |
cutoutHack(); |
| 80 | 79 |
computeHeights(); |
| 81 | 80 |
|
| 81 |
getWindowWidth(getResources().getConfiguration()); |
|
| 82 |
android.util.Log.e("D", "onCreate: "+mScreenWidth+" "+mScreenHeight);
|
|
| 83 |
|
|
| 82 | 84 |
mCurrVersion = getAppVers(); |
| 83 | 85 |
|
| 84 | 86 |
mBubbleUpdates = findViewById(R.id.bubbleUpdates); |
| 85 | 87 |
mBubbleUpdates.setVisibility(View.INVISIBLE); |
| 86 | 88 |
mNumUpdates = 0; |
| 87 | 89 |
|
| 90 |
mGrid = new MainScrollGrid(); |
|
| 91 |
mGrid.createGrid(this,mScreenWidth,mSortMode); |
|
| 92 |
|
|
| 88 | 93 |
Thread thread = new Thread() |
| 89 | 94 |
{
|
| 90 | 95 |
public void run() |
| ... | ... | |
| 116 | 121 |
} |
| 117 | 122 |
|
| 118 | 123 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 119 |
|
|
| 124 |
/* |
|
| 120 | 125 |
@Override |
| 121 | 126 |
public void onAttachedToWindow() |
| 122 | 127 |
{
|
| 123 | 128 |
super.onAttachedToWindow(); |
| 124 | 129 |
|
| 125 | 130 |
getWindowWidth(getResources().getConfiguration()); |
| 131 |
|
|
| 132 |
|
|
| 133 |
android.util.Log.e("D", "onAttachedToWindow: "+mScreenWidth+" "+mScreenHeight);
|
|
| 134 |
|
|
| 135 |
|
|
| 126 | 136 |
mGrid = new MainScrollGrid(); |
| 127 | 137 |
mGrid.createGrid(this,mScreenWidth,mSortMode); |
| 128 | 138 |
|
| ... | ... | |
| 133 | 143 |
|
| 134 | 144 |
if( insetHeight>0 ) |
| 135 | 145 |
{
|
| 136 |
LinearLayout.LayoutParams pH = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 0, RATIO_BAR);
|
|
| 146 |
LinearLayout.LayoutParams pH = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 0, RATIO_HID);
|
|
| 137 | 147 |
LinearLayout layoutHid = findViewById(R.id.hiddenBar); |
| 138 | 148 |
layoutHid.setLayoutParams(pH); |
| 139 | 149 |
|
| 140 |
LinearLayout.LayoutParams pS = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 0, 1-3*RATIO_BAR);
|
|
| 150 |
LinearLayout.LayoutParams pS = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 0, 1-2*RATIO_BAR-RATIO_HID);
|
|
| 141 | 151 |
ScrollView scroll = findViewById(R.id.objectScroll); |
| 142 | 152 |
scroll.setLayoutParams(pS); |
| 143 | 153 |
} |
| 144 | 154 |
} |
| 145 | 155 |
} |
| 146 |
|
|
| 156 |
*/ |
|
| 147 | 157 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 148 | 158 |
|
| 149 | 159 |
@Override |
| ... | ... | |
| 151 | 161 |
{
|
| 152 | 162 |
super.onConfigurationChanged(conf); |
| 153 | 163 |
|
| 164 |
android.util.Log.e("D", "onConfigurationChanged");
|
|
| 165 |
|
|
| 154 | 166 |
getWindowWidth(conf); |
| 155 | 167 |
if( mGrid!=null ) mGrid.updateGrid(this,mScreenWidth); |
| 156 | 168 |
} |
| ... | ... | |
| 163 | 175 |
super.onPause(); |
| 164 | 176 |
RubikNetwork.onPause(); |
| 165 | 177 |
savePreferences(); |
| 178 |
|
|
| 179 |
|
|
| 180 |
android.util.Log.e("D", "onPause");
|
|
| 181 |
|
|
| 166 | 182 |
} |
| 167 | 183 |
|
| 168 | 184 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 172 | 188 |
{
|
| 173 | 189 |
super.onResume(); |
| 174 | 190 |
|
| 175 |
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); |
|
| 176 |
restorePreferences(preferences,mJustStarted); |
|
| 191 |
android.util.Log.e("D", "onResume");
|
|
| 192 |
|
|
| 193 |
restorePreferences(mJustStarted); |
|
| 177 | 194 |
|
| 178 | 195 |
RubikNetwork network = RubikNetwork.getInstance(); |
| 179 | 196 |
network.signUpForUpdates(this); |
| ... | ... | |
| 208 | 225 |
protected void onDestroy() |
| 209 | 226 |
{
|
| 210 | 227 |
super.onDestroy(); |
| 228 |
|
|
| 229 |
android.util.Log.e("D", "onDestroy");
|
|
| 211 | 230 |
} |
| 212 | 231 |
|
| 213 | 232 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 229 | 248 |
|
| 230 | 249 |
private void savePreferences() |
| 231 | 250 |
{
|
| 232 |
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); |
|
| 233 |
SharedPreferences.Editor editor = preferences.edit(); |
|
| 251 |
SharedPreferences.Editor editor = mPreferences.edit(); |
|
| 234 | 252 |
|
| 235 | 253 |
editor.putString("appVersion", mCurrVersion );
|
| 236 | 254 |
editor.putInt("sortMode", mSortMode);
|
| ... | ... | |
| 243 | 261 |
|
| 244 | 262 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 245 | 263 |
|
| 246 |
private void restorePreferences(SharedPreferences preferences, boolean justStarted)
|
|
| 264 |
private void restorePreferences(boolean justStarted) |
|
| 247 | 265 |
{
|
| 248 |
mOldVersion = preferences.getString("appVersion","");
|
|
| 249 |
mSortMode = preferences.getInt("sortMode", MainSettingsPopup.SORT_DEFAULT);
|
|
| 266 |
mOldVersion = mPreferences.getString("appVersion","");
|
|
| 267 |
mSortMode = mPreferences.getInt("sortMode", MainSettingsPopup.SORT_DEFAULT);
|
|
| 250 | 268 |
|
| 251 |
RubikObjectList.restorePreferences(this,preferences,justStarted);
|
|
| 269 |
RubikObjectList.restorePreferences(this,mPreferences,justStarted);
|
|
| 252 | 270 |
RubikScores scores = RubikScores.getInstance(); |
| 253 |
scores.restorePreferences(preferences);
|
|
| 271 |
scores.restorePreferences(mPreferences);
|
|
| 254 | 272 |
|
| 255 | 273 |
if( scores.isVerified() ) |
| 256 | 274 |
{
|
| ... | ... | |
| 399 | 417 |
|
| 400 | 418 |
int vw = v.getWidth(); |
| 401 | 419 |
|
| 402 |
MainSettingsPopup popup = new MainSettingsPopup(this,mSortMode,mScreenWidth,mScreenHeight); |
|
| 420 |
MainSettingsPopup popup = new MainSettingsPopup(this,mSortMode,mCurrentTheme,mScreenWidth,mScreenHeight);
|
|
| 403 | 421 |
popup.displayPopup(this,v,sw,sh,((vw-sw)/2),0); |
| 404 | 422 |
} |
| 405 | 423 |
|
| src/main/java/org/distorted/main/MainSettingsPopup.java | ||
|---|---|---|
| 42 | 42 |
private static final float MENU_TEXT_SIZE = 0.060f; |
| 43 | 43 |
private static final int[] mLocation = new int[2]; |
| 44 | 44 |
|
| 45 |
private final PopupWindow mPopup;
|
|
| 46 |
private final WeakReference<MainActivity> mAct;
|
|
| 45 |
private PopupWindow mPopup; |
|
| 46 |
private WeakReference<MainActivity> mAct; |
|
| 47 | 47 |
private int mCurrMethod; |
| 48 | 48 |
private String[] mSortNames; |
| 49 |
private int mCurrTheme; |
|
| 50 |
private String[] mThemeNames; |
|
| 49 | 51 |
|
| 50 | 52 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 51 | 53 |
// this is supposed to prevent showing the navigational bar when we show the drop down list, |
| ... | ... | |
| 83 | 85 |
|
| 84 | 86 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 85 | 87 |
|
| 86 |
MainSettingsPopup(MainActivity act, int sortMethod, int width, int height) |
|
| 88 |
MainSettingsPopup(MainActivity act, int sortMethod, int themeValue, int width, int height)
|
|
| 87 | 89 |
{
|
| 88 | 90 |
mAct = new WeakReference<>(act); |
| 89 | 91 |
|
| ... | ... | |
| 101 | 103 |
int titleSize = (int)(MENU_TITLE_SIZE*width); |
| 102 | 104 |
int textSize = (int)(MENU_TEXT_SIZE*width); |
| 103 | 105 |
|
| 104 |
TextView title = layout.findViewById(R.id.sortTitle);
|
|
| 106 |
TextView title = layout.findViewById(R.id.settingsTitle);
|
|
| 105 | 107 |
title.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleSize); |
| 106 |
TextView text = layout.findViewById(R.id.sortText); |
|
| 107 |
text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize); |
|
| 108 |
TextView sortText = layout.findViewById(R.id.sortText); |
|
| 109 |
sortText.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize); |
|
| 110 |
TextView themeTitle = layout.findViewById(R.id.themeText); |
|
| 111 |
themeTitle.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize); |
|
| 108 | 112 |
|
| 109 |
Spinner actSpinner = layout.findViewById(R.id.sortMethod);
|
|
| 110 |
actSpinner.setOnItemSelectedListener(this);
|
|
| 113 |
Spinner sortSpinner = layout.findViewById(R.id.sortMethod);
|
|
| 114 |
sortSpinner.setOnItemSelectedListener(this);
|
|
| 111 | 115 |
|
| 112 | 116 |
mCurrMethod = sortMethod; |
| 113 | 117 |
buildSortOptions(act); |
| 114 | 118 |
|
| 115 |
ArrayAdapter<String> actAdapter = new ArrayAdapter<>(act, android.R.layout.simple_spinner_item, mSortNames);
|
|
| 116 |
actAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
|
| 117 |
actSpinner.setAdapter(actAdapter);
|
|
| 119 |
ArrayAdapter<String> sortAdapter = new ArrayAdapter<>(act, android.R.layout.simple_spinner_item, mSortNames);
|
|
| 120 |
sortAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
|
| 121 |
sortSpinner.setAdapter(sortAdapter);
|
|
| 118 | 122 |
|
| 119 |
if( sortMethod>=0 && sortMethod<mSortNames.length ) actSpinner.setSelection(sortMethod); |
|
| 123 |
if( sortMethod>=0 && sortMethod<mSortNames.length ) sortSpinner.setSelection(sortMethod); |
|
| 124 |
|
|
| 125 |
Spinner themeSpinner = layout.findViewById(R.id.themeValue); |
|
| 126 |
themeSpinner.setOnItemSelectedListener(this); |
|
| 127 |
|
|
| 128 |
mCurrTheme = themeValue; |
|
| 129 |
buildThemeOptions(act); |
|
| 130 |
|
|
| 131 |
ArrayAdapter<String> themeAdapter = new ArrayAdapter<>(act, android.R.layout.simple_spinner_item, mThemeNames); |
|
| 132 |
themeAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); |
|
| 133 |
themeSpinner.setAdapter(themeAdapter); |
|
| 134 |
|
|
| 135 |
if( themeValue>=0 && themeValue<mThemeNames.length ) themeSpinner.setSelection(themeValue); |
|
| 120 | 136 |
} |
| 121 | 137 |
|
| 122 | 138 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 133 | 149 |
mSortNames[4] = res.getString(R.string.sort_year); |
| 134 | 150 |
} |
| 135 | 151 |
|
| 152 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 153 |
|
|
| 154 |
private void buildThemeOptions(MainActivity act) |
|
| 155 |
{
|
|
| 156 |
Resources res = act.getResources(); |
|
| 157 |
mThemeNames = new String[3]; |
|
| 158 |
|
|
| 159 |
mThemeNames[0] = res.getString(R.string.theme_grey); |
|
| 160 |
mThemeNames[1] = res.getString(R.string.theme_white); |
|
| 161 |
mThemeNames[2] = res.getString(R.string.theme_green); |
|
| 162 |
} |
|
| 163 |
|
|
| 136 | 164 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 137 | 165 |
// work around lame bugs in Android's version <= 10 pop-up and split-screen modes |
| 138 | 166 |
|
| ... | ... | |
| 187 | 215 |
{
|
| 188 | 216 |
if( parent.getId()==R.id.sortMethod && mCurrMethod!=pos ) |
| 189 | 217 |
{
|
| 218 |
mPopup.dismiss(); |
|
| 190 | 219 |
mCurrMethod = pos; |
| 191 | 220 |
MainActivity act = mAct.get(); |
| 192 | 221 |
act.sortObjectsBy(pos); |
| 222 |
} |
|
| 223 |
if( parent.getId()==R.id.themeValue && mCurrTheme!=pos ) |
|
| 224 |
{
|
|
| 193 | 225 |
mPopup.dismiss(); |
| 226 |
mPopup = null; |
|
| 227 |
mCurrTheme = pos; |
|
| 228 |
MainActivity act = mAct.get(); |
|
| 229 |
mAct = null; |
|
| 230 |
act.changeThemeTo(pos); |
|
| 194 | 231 |
} |
| 195 | 232 |
} |
| 196 | 233 |
|
| src/main/java/org/distorted/patternui/PatternActivity.java | ||
|---|---|---|
| 16 | 16 |
import android.view.ViewGroup; |
| 17 | 17 |
import android.widget.LinearLayout; |
| 18 | 18 |
|
| 19 |
import androidx.preference.PreferenceManager; |
|
| 20 |
|
|
| 21 | 19 |
import org.distorted.dialogs.RubikDialogError; |
| 22 | 20 |
import org.distorted.helpers.BaseActivity; |
| 23 | 21 |
import org.distorted.library.main.DistortedLibrary; |
| ... | ... | |
| 108 | 106 |
view.onResume(); |
| 109 | 107 |
|
| 110 | 108 |
createObject(); |
| 111 |
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); |
|
| 112 |
restorePreferences(preferences); |
|
| 109 |
restorePreferences(); |
|
| 113 | 110 |
ScreenList.setScreen(this); |
| 114 | 111 |
} |
| 115 | 112 |
|
| ... | ... | |
| 126 | 123 |
|
| 127 | 124 |
private void savePreferences() |
| 128 | 125 |
{
|
| 129 |
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); |
|
| 130 |
SharedPreferences.Editor editor = preferences.edit(); |
|
| 126 |
SharedPreferences.Editor editor = mPreferences.edit(); |
|
| 131 | 127 |
|
| 132 | 128 |
for(int i=0; i< ScreenList.LENGTH; i++ ) |
| 133 | 129 |
ScreenList.getScreen(i).getScreenClass().savePreferences(editor); |
| ... | ... | |
| 140 | 136 |
|
| 141 | 137 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 142 | 138 |
|
| 143 |
private void restorePreferences(SharedPreferences preferences)
|
|
| 139 |
private void restorePreferences() |
|
| 144 | 140 |
{
|
| 145 | 141 |
for (int i=0; i<ScreenList.LENGTH; i++) |
| 146 |
ScreenList.getScreen(i).getScreenClass().restorePreferences(preferences);
|
|
| 142 |
ScreenList.getScreen(i).getScreenClass().restorePreferences(mPreferences);
|
|
| 147 | 143 |
|
| 148 |
ScreenList.restorePreferences(preferences);
|
|
| 144 |
ScreenList.restorePreferences(mPreferences);
|
|
| 149 | 145 |
} |
| 150 | 146 |
|
| 151 | 147 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| src/main/java/org/distorted/playui/PlayActivity.java | ||
|---|---|---|
| 18 | 18 |
import android.view.ViewGroup; |
| 19 | 19 |
import android.widget.LinearLayout; |
| 20 | 20 |
|
| 21 |
import androidx.preference.PreferenceManager; |
|
| 22 |
|
|
| 23 | 21 |
import com.google.firebase.analytics.FirebaseAnalytics; |
| 24 | 22 |
|
| 25 | 23 |
import org.distorted.dialogs.RubikDialogScores; |
| ... | ... | |
| 138 | 136 |
ObjectControl control = view.getObjectControl(); |
| 139 | 137 |
view.onResume(); |
| 140 | 138 |
|
| 141 |
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); |
|
| 142 |
restorePreferences(preferences); |
|
| 139 |
restorePreferences(); |
|
| 143 | 140 |
|
| 144 | 141 |
ScreenList sl = mJustStarted ? |
| 145 | 142 |
(mModeFree ? ScreenList.FREE : ScreenList.SCRA) : |
| ... | ... | |
| 147 | 144 |
|
| 148 | 145 |
ScreenList.switchScreen(this,sl); |
| 149 | 146 |
|
| 150 |
if( !mJustStarted ) restoreMoves(preferences);
|
|
| 147 |
if( !mJustStarted ) restoreMoves(); |
|
| 151 | 148 |
|
| 152 | 149 |
if( mObjectName.length()>0 ) |
| 153 | 150 |
{
|
| ... | ... | |
| 175 | 172 |
|
| 176 | 173 |
private void savePreferences() |
| 177 | 174 |
{
|
| 178 |
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); |
|
| 179 |
SharedPreferences.Editor editor = preferences.edit(); |
|
| 175 |
SharedPreferences.Editor editor = mPreferences.edit(); |
|
| 180 | 176 |
|
| 181 | 177 |
for( int i=0; i<ScreenList.LENGTH; i++ ) |
| 182 | 178 |
{
|
| ... | ... | |
| 211 | 207 |
|
| 212 | 208 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 213 | 209 |
|
| 214 |
private void restorePreferences(SharedPreferences preferences)
|
|
| 210 |
private void restorePreferences() |
|
| 215 | 211 |
{
|
| 216 | 212 |
for( int i=0; i<ScreenList.LENGTH; i++) |
| 217 | 213 |
{
|
| 218 |
ScreenList.getScreen(i).getScreenClass().restorePreferences(preferences);
|
|
| 214 |
ScreenList.getScreen(i).getScreenClass().restorePreferences(mPreferences);
|
|
| 219 | 215 |
} |
| 220 | 216 |
|
| 221 |
if( !mJustStarted ) ScreenList.restorePreferences(preferences);
|
|
| 217 |
if( !mJustStarted ) ScreenList.restorePreferences(mPreferences);
|
|
| 222 | 218 |
|
| 223 | 219 |
PlayView view = findViewById(R.id.playView); |
| 224 | 220 |
OSInterface os = view.getInterface(); |
| 225 |
os.setPreferences(preferences);
|
|
| 221 |
os.setPreferences(mPreferences);
|
|
| 226 | 222 |
view.getObjectControl().restorePreferences(); |
| 227 | 223 |
} |
| 228 | 224 |
|
| 229 | 225 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 230 | 226 |
|
| 231 |
private void restoreMoves(SharedPreferences preferences)
|
|
| 227 |
private void restoreMoves() |
|
| 232 | 228 |
{
|
| 233 | 229 |
ScreenList curr = ScreenList.getCurrentScreen(); |
| 234 | 230 |
|
| 235 | 231 |
if( curr==ScreenList.FREE ) |
| 236 | 232 |
{
|
| 237 | 233 |
ScreenFree free = (ScreenFree) ScreenList.FREE.getScreenClass(); |
| 238 |
free.restoreMovePreferences(this,KEY_FREE,preferences);
|
|
| 234 |
free.restoreMovePreferences(this,KEY_FREE,mPreferences);
|
|
| 239 | 235 |
} |
| 240 | 236 |
if( curr==ScreenList.SOLV ) |
| 241 | 237 |
{
|
| 242 | 238 |
ScreenSolving solv = (ScreenSolving) ScreenList.SOLV.getScreenClass(); |
| 243 |
solv.restoreMovePreferences(this,KEY_SOLV,preferences);
|
|
| 239 |
solv.restoreMovePreferences(this,KEY_SOLV,mPreferences);
|
|
| 244 | 240 |
} |
| 245 | 241 |
} |
| 246 | 242 |
|
| src/main/java/org/distorted/purchase/PurchaseActivity.java | ||
|---|---|---|
| 1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 2 |
// Copyright 2019 Leszek Koltunski // |
|
| 3 |
// // |
|
| 4 |
// This file is part of Magic Cube. // |
|
| 5 |
// // |
|
| 6 |
// Magic Cube is proprietary software licensed under an EULA which you should have received // |
|
| 7 |
// along with the code. If not, check https://distorted.org/magic/License-Magic-Cube.html // |
|
| 8 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 9 |
|
|
| 10 |
package org.distorted.purchase; |
|
| 11 |
|
|
| 12 |
import android.content.SharedPreferences; |
|
| 13 |
import android.os.Bundle; |
|
| 14 |
import android.view.View; |
|
| 15 |
import android.view.ViewGroup; |
|
| 16 |
|
|
| 17 |
import androidx.preference.PreferenceManager; |
|
| 18 |
|
|
| 19 |
import org.distorted.dialogs.RubikDialogError; |
|
| 20 |
import org.distorted.external.RubikScores; |
|
| 21 |
import org.distorted.helpers.BaseActivity; |
|
| 22 |
import org.distorted.library.main.DistortedLibrary; |
|
| 23 |
import org.distorted.main.R; |
|
| 24 |
import org.distorted.objectlib.main.InitAssets; |
|
| 25 |
import org.distorted.objectlib.main.ObjectControl; |
|
| 26 |
import org.distorted.objectlib.main.TwistyObject; |
|
| 27 |
import org.distorted.objects.RubikObject; |
|
| 28 |
import org.distorted.objects.RubikObjectList; |
|
| 29 |
|
|
| 30 |
import java.io.InputStream; |
|
| 31 |
|
|
| 32 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 33 |
|
|
| 34 |
public class PurchaseActivity extends BaseActivity |
|
| 35 |
{
|
|
| 36 |
private static final int ACTIVITY_NUMBER = 3; |
|
| 37 |
private static final float RATIO_UBAR = 0.14f; |
|
| 38 |
private static final float RATIO_LBAR = 0.10f; |
|
| 39 |
private static final float RATIO_VIEW = 0.50f; |
|
| 40 |
|
|
| 41 |
private PurchaseScreen mScreen; |
|
| 42 |
private int mObjectOrdinal; |
|
| 43 |
|
|
| 44 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 45 |
|
|
| 46 |
@Override |
|
| 47 |
protected void onCreate(Bundle savedState) |
|
| 48 |
{
|
|
| 49 |
super.onCreate(savedState); |
|
| 50 |
DistortedLibrary.onCreate(ACTIVITY_NUMBER); |
|
| 51 |
setContentView(R.layout.purchase); |
|
| 52 |
|
|
| 53 |
Bundle b = getIntent().getExtras(); |
|
| 54 |
if(b != null) mObjectOrdinal = b.getInt("obj");
|
|
| 55 |
|
|
| 56 |
computeScreenDimensions(); |
|
| 57 |
hideNavigationBar(); |
|
| 58 |
cutoutHack(); |
|
| 59 |
setHeights(); |
|
| 60 |
} |
|
| 61 |
|
|
| 62 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 63 |
|
|
| 64 |
private void setViewHeight(int id, int height) |
|
| 65 |
{
|
|
| 66 |
View view = findViewById(id); |
|
| 67 |
|
|
| 68 |
if( view!=null ) |
|
| 69 |
{
|
|
| 70 |
ViewGroup.LayoutParams params = view.getLayoutParams(); |
|
| 71 |
params.height = height; |
|
| 72 |
view.setLayoutParams(params); |
|
| 73 |
} |
|
| 74 |
} |
|
| 75 |
|
|
| 76 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 77 |
// this does not include possible insets |
|
| 78 |
|
|
| 79 |
private void setHeights() |
|
| 80 |
{
|
|
| 81 |
int ubarHeight= (int)(mScreenHeight*RATIO_UBAR); |
|
| 82 |
int lbarHeight= (int)(mScreenHeight*RATIO_LBAR); |
|
| 83 |
int viewHeight= (int)(mScreenHeight*RATIO_VIEW); |
|
| 84 |
int layHeight = (int)(mScreenHeight*(1-RATIO_UBAR-RATIO_LBAR-RATIO_VIEW)*0.5f); |
|
| 85 |
|
|
| 86 |
setViewHeight(R.id.upperBar , ubarHeight); |
|
| 87 |
setViewHeight(R.id.lowerBar , lbarHeight); |
|
| 88 |
setViewHeight(R.id.purchaseSurfaceView, viewHeight); |
|
| 89 |
setViewHeight(R.id.purchaseLayoutOne , layHeight); |
|
| 90 |
setViewHeight(R.id.purchaseLayoutAll , layHeight); |
|
| 91 |
} |
|
| 92 |
|
|
| 93 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 94 |
|
|
| 95 |
@Override |
|
| 96 |
protected void onPause() |
|
| 97 |
{
|
|
| 98 |
super.onPause(); |
|
| 99 |
PurchaseSurfaceView view = findViewById(R.id.purchaseSurfaceView); |
|
| 100 |
view.onPause(); |
|
| 101 |
DistortedLibrary.onPause(ACTIVITY_NUMBER); |
|
| 102 |
savePreferences(); |
|
| 103 |
} |
|
| 104 |
|
|
| 105 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 106 |
|
|
| 107 |
@Override |
|
| 108 |
protected void onResume() |
|
| 109 |
{
|
|
| 110 |
super.onResume(); |
|
| 111 |
DistortedLibrary.onResume(ACTIVITY_NUMBER); |
|
| 112 |
PurchaseSurfaceView view = findViewById(R.id.purchaseSurfaceView); |
|
| 113 |
view.onResume(); |
|
| 114 |
|
|
| 115 |
if( mScreen==null ) mScreen = new PurchaseScreen(); |
|
| 116 |
mScreen.onAttachedToWindow(this,mObjectOrdinal); |
|
| 117 |
|
|
| 118 |
if( mObjectOrdinal>=0 && mObjectOrdinal< RubikObjectList.getNumObjects() ) |
|
| 119 |
{
|
|
| 120 |
RubikObject object = RubikObjectList.getObject(mObjectOrdinal); |
|
| 121 |
changeIfDifferent(object,mObjectOrdinal,view.getObjectControl()); |
|
| 122 |
} |
|
| 123 |
} |
|
| 124 |
|
|
| 125 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 126 |
|
|
| 127 |
@Override |
|
| 128 |
protected void onDestroy() |
|
| 129 |
{
|
|
| 130 |
super.onDestroy(); |
|
| 131 |
DistortedLibrary.onDestroy(ACTIVITY_NUMBER); |
|
| 132 |
} |
|
| 133 |
|
|
| 134 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 135 |
|
|
| 136 |
private void savePreferences() |
|
| 137 |
{
|
|
| 138 |
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); |
|
| 139 |
SharedPreferences.Editor editor = preferences.edit(); |
|
| 140 |
RubikScores scores = RubikScores.getInstance(); |
|
| 141 |
scores.savePreferencesMinimal(editor); |
|
| 142 |
|
|
| 143 |
boolean success = editor.commit(); |
|
| 144 |
if( !success ) android.util.Log.e("D", "Failed to save preferences");
|
|
| 145 |
} |
|
| 146 |
|
|
| 147 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 148 |
|
|
| 149 |
void OpenGLError() |
|
| 150 |
{
|
|
| 151 |
RubikDialogError errDiag = new RubikDialogError(); |
|
| 152 |
errDiag.show(getSupportFragmentManager(), null); |
|
| 153 |
} |
|
| 154 |
|
|
| 155 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 156 |
|
|
| 157 |
private void changeIfDifferent(RubikObject object,int ordinal,ObjectControl control) |
|
| 158 |
{
|
|
| 159 |
if( object!=null ) |
|
| 160 |
{
|
|
| 161 |
int iconMode = TwistyObject.MODE_NORM; |
|
| 162 |
InputStream jsonStream = object.getObjectStream(this); |
|
| 163 |
InputStream meshStream = object.getMeshStream(this); |
|
| 164 |
String name = object.getUpperName(); |
|
| 165 |
InitAssets asset = new InitAssets(jsonStream,meshStream,null); |
|
| 166 |
control.changeIfDifferent(ordinal,name,iconMode,asset); |
|
| 167 |
} |
|
| 168 |
} |
|
| 169 |
|
|
| 170 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 171 |
// PUBLIC API |
|
| 172 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 173 |
|
|
| 174 |
public ObjectControl getControl() |
|
| 175 |
{
|
|
| 176 |
PurchaseSurfaceView view = findViewById(R.id.purchaseSurfaceView); |
|
| 177 |
return view.getObjectControl(); |
|
| 178 |
} |
|
| 179 |
|
|
| 180 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 181 |
|
|
| 182 |
PurchaseRenderer getRenderer() |
|
| 183 |
{
|
|
| 184 |
PurchaseSurfaceView view = findViewById(R.id.purchaseSurfaceView); |
|
| 185 |
return view.getRenderer(); |
|
| 186 |
} |
|
| 187 |
|
|
| 188 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 189 |
|
|
| 190 |
void blockUI() |
|
| 191 |
{
|
|
| 192 |
mScreen.blockUI(); |
|
| 193 |
} |
|
| 194 |
|
|
| 195 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 196 |
|
|
| 197 |
int getObjectPrice() |
|
| 198 |
{
|
|
| 199 |
if( mObjectOrdinal>=0 && mObjectOrdinal< RubikObjectList.getNumObjects() ) |
|
| 200 |
{
|
|
| 201 |
RubikObject object = RubikObjectList.getObject(mObjectOrdinal); |
|
| 202 |
return object==null ? 0 : object.getPrice(); |
|
| 203 |
} |
|
| 204 |
|
|
| 205 |
return 0; |
|
| 206 |
} |
|
| 207 |
} |
|
| src/main/java/org/distorted/purchase/PurchaseObjectLibInterface.java | ||
|---|---|---|
| 1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 2 |
// Copyright 2021 Leszek Koltunski // |
|
| 3 |
// // |
|
| 4 |
// This file is part of Magic Cube. // |
|
| 5 |
// // |
|
| 6 |
// Magic Cube is proprietary software licensed under an EULA which you should have received // |
|
| 7 |
// along with the code. If not, check https://distorted.org/magic/License-Magic-Cube.html // |
|
| 8 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 9 |
|
|
| 10 |
package org.distorted.purchase; |
|
| 11 |
|
|
| 12 |
import com.google.firebase.crashlytics.FirebaseCrashlytics; |
|
| 13 |
|
|
| 14 |
import org.distorted.main.BuildConfig; |
|
| 15 |
import org.distorted.objectlib.helpers.ObjectLibInterface; |
|
| 16 |
|
|
| 17 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 18 |
|
|
| 19 |
public class PurchaseObjectLibInterface implements ObjectLibInterface |
|
| 20 |
{
|
|
| 21 |
public void onWinEffectFinished(long startTime, long endTime, String debug, int scrambleNum) { }
|
|
| 22 |
public void onScrambleEffectFinished() { }
|
|
| 23 |
public void onBeginRotation() { }
|
|
| 24 |
public void onSolved() { }
|
|
| 25 |
public void onObjectCreated(long time) { }
|
|
| 26 |
public void onReplaceModeDown(int cubit, int face) { }
|
|
| 27 |
public void onReplaceModeUp() { }
|
|
| 28 |
public void onRemoveRotation(int axis, int row, int angle) { }
|
|
| 29 |
public void failedToDrag() { }
|
|
| 30 |
public void reportJSONError(String error, int ordinal) { }
|
|
| 31 |
public void reportBlockProblem(int type, int place, long pause, long resume, long time) { }
|
|
| 32 |
|
|
| 33 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 34 |
|
|
| 35 |
public void reportProblem(String problem, boolean reportException) |
|
| 36 |
{
|
|
| 37 |
if( BuildConfig.DEBUG ) |
|
| 38 |
{
|
|
| 39 |
android.util.Log.e("interface", problem);
|
|
| 40 |
} |
|
| 41 |
else |
|
| 42 |
{
|
|
| 43 |
if( reportException ) |
|
| 44 |
{
|
|
| 45 |
Exception ex = new Exception(problem); |
|
| 46 |
FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance(); |
|
| 47 |
crashlytics.setCustomKey("problem" , problem);
|
|
| 48 |
crashlytics.recordException(ex); |
|
| 49 |
} |
|
| 50 |
else |
|
| 51 |
{
|
|
| 52 |
FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance(); |
|
| 53 |
crashlytics.log(problem); |
|
| 54 |
} |
|
| 55 |
} |
|
| 56 |
} |
|
| 57 |
} |
|
| src/main/java/org/distorted/purchase/PurchaseRenderer.java | ||
|---|---|---|
| 1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 2 |
// Copyright 2019 Leszek Koltunski // |
|
| 3 |
// // |
|
| 4 |
// This file is part of Magic Cube. // |
|
| 5 |
// // |
|
| 6 |
// Magic Cube is proprietary software licensed under an EULA which you should have received // |
|
| 7 |
// along with the code. If not, check https://distorted.org/magic/License-Magic-Cube.html // |
|
| 8 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 9 |
|
|
| 10 |
package org.distorted.purchase; |
|
| 11 |
|
|
| 12 |
import android.app.ActivityManager; |
|
| 13 |
import android.content.Context; |
|
| 14 |
import android.content.pm.ConfigurationInfo; |
|
| 15 |
import android.content.res.Resources; |
|
| 16 |
import android.opengl.GLSurfaceView; |
|
| 17 |
|
|
| 18 |
import org.distorted.library.effect.EffectType; |
|
| 19 |
import org.distorted.library.effect.VertexEffectQuaternion; |
|
| 20 |
import org.distorted.library.effect.VertexEffectRotate; |
|
| 21 |
import org.distorted.library.main.DistortedLibrary; |
|
| 22 |
import org.distorted.library.main.DistortedScreen; |
|
| 23 |
import org.distorted.library.mesh.MeshBase; |
|
| 24 |
import org.distorted.objectlib.effects.BaseEffect; |
|
| 25 |
import org.distorted.objectlib.main.ObjectControl; |
|
| 26 |
import org.distorted.overlays.OverlayGeneric; |
|
| 27 |
|
|
| 28 |
import java.io.InputStream; |
|
| 29 |
|
|
| 30 |
import javax.microedition.khronos.egl.EGLConfig; |
|
| 31 |
import javax.microedition.khronos.opengles.GL10; |
|
| 32 |
|
|
| 33 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 34 |
|
|
| 35 |
public class PurchaseRenderer implements GLSurfaceView.Renderer, DistortedLibrary.LibraryUser |
|
| 36 |
{
|
|
| 37 |
private static final int NUM_SCRAMBLES = 5; |
|
| 38 |
private static final int DURATION = NUM_SCRAMBLES*2*1000; |
|
| 39 |
|
|
| 40 |
private final PurchaseSurfaceView mView; |
|
| 41 |
private final Resources mResources; |
|
| 42 |
private final DistortedScreen mScreen; |
|
| 43 |
|
|
| 44 |
private boolean mFirstRender; |
|
| 45 |
|
|
| 46 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 47 |
|
|
| 48 |
PurchaseRenderer(PurchaseSurfaceView v) |
|
| 49 |
{
|
|
| 50 |
final float BRIGHTNESS = 0.333f; |
|
| 51 |
|
|
| 52 |
mView = v; |
|
| 53 |
mResources = v.getResources(); |
|
| 54 |
|
|
| 55 |
mFirstRender = true; |
|
| 56 |
mScreen = new DistortedScreen(); |
|
| 57 |
mScreen.glClearColor(BRIGHTNESS, BRIGHTNESS, BRIGHTNESS, 1.0f); |
|
| 58 |
} |
|
| 59 |
|
|
| 60 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 61 |
|
|
| 62 |
@Override |
|
| 63 |
public void onDrawFrame(GL10 glUnused) |
|
| 64 |
{
|
|
| 65 |
long time = System.currentTimeMillis(); |
|
| 66 |
mView.getObjectControl().preRender(); |
|
| 67 |
mScreen.render(time); |
|
| 68 |
|
|
| 69 |
if( mFirstRender ) |
|
| 70 |
{
|
|
| 71 |
mFirstRender=false; |
|
| 72 |
mView.getObjectControl().presentObject(NUM_SCRAMBLES, DURATION); |
|
| 73 |
} |
|
| 74 |
} |
|
| 75 |
|
|
| 76 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 77 |
|
|
| 78 |
@Override |
|
| 79 |
public void onSurfaceChanged(GL10 glUnused, int width, int height) |
|
| 80 |
{
|
|
| 81 |
mScreen.resize(width,height); |
|
| 82 |
mView.setScreenSize(width,height); |
|
| 83 |
} |
|
| 84 |
|
|
| 85 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 86 |
|
|
| 87 |
DistortedScreen getScreen() |
|
| 88 |
{
|
|
| 89 |
return mScreen; |
|
| 90 |
} |
|
| 91 |
|
|
| 92 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 93 |
|
|
| 94 |
@Override |
|
| 95 |
public void onSurfaceCreated(GL10 glUnused, EGLConfig config) |
|
| 96 |
{
|
|
| 97 |
DistortedLibrary.setMax(EffectType.VERTEX,ObjectControl.MAX_QUATS+1); |
|
| 98 |
MeshBase.setMaxEffComponents(ObjectControl.MAX_MOVING_PARTS); |
|
| 99 |
|
|
| 100 |
VertexEffectRotate.enable(); |
|
| 101 |
VertexEffectQuaternion.enable(); |
|
| 102 |
BaseEffect.Type.enableEffects(); |
|
| 103 |
OverlayGeneric.enableEffects(); |
|
| 104 |
|
|
| 105 |
DistortedLibrary.onSurfaceCreated(this,1); |
|
| 106 |
DistortedLibrary.setCull(true); |
|
| 107 |
} |
|
| 108 |
|
|
| 109 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 110 |
|
|
| 111 |
public void distortedException(Exception ex) |
|
| 112 |
{
|
|
| 113 |
android.util.Log.e("Purchase", "unexpected exception: "+ex.getMessage() );
|
|
| 114 |
} |
|
| 115 |
|
|
| 116 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 117 |
|
|
| 118 |
public InputStream localFile(int fileID) |
|
| 119 |
{
|
|
| 120 |
return mResources.openRawResource(fileID); |
|
| 121 |
} |
|
| 122 |
|
|
| 123 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 124 |
|
|
| 125 |
public void logMessage(String message) |
|
| 126 |
{
|
|
| 127 |
android.util.Log.e("Purchase", message );
|
|
| 128 |
} |
|
| 129 |
} |
|
| src/main/java/org/distorted/purchase/PurchaseScreen.java | ||
|---|---|---|
| 1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 2 |
// Copyright 2020 Leszek Koltunski // |
|
| 3 |
// // |
|
| 4 |
// This file is part of Magic Cube. // |
|
| 5 |
// // |
|
| 6 |
// Magic Cube is proprietary software licensed under an EULA which you should have received // |
|
| 7 |
// along with the code. If not, check https://distorted.org/magic/License-Magic-Cube.html // |
|
| 8 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 9 |
|
|
| 10 |
package org.distorted.purchase; |
|
| 11 |
|
|
| 12 |
import android.view.View; |
|
| 13 |
import android.widget.LinearLayout; |
|
| 14 |
|
|
| 15 |
import org.distorted.helpers.TransparentImageButton; |
|
| 16 |
import org.distorted.main.R; |
|
| 17 |
|
|
| 18 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 19 |
|
|
| 20 |
public class PurchaseScreen |
|
| 21 |
{
|
|
| 22 |
private TransparentImageButton mBackButton; |
|
| 23 |
private boolean mBlocked; |
|
| 24 |
|
|
| 25 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 26 |
|
|
| 27 |
void blockUI() |
|
| 28 |
{
|
|
| 29 |
mBlocked = true; |
|
| 30 |
} |
|
| 31 |
|
|
| 32 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 33 |
|
|
| 34 |
private void setupBackButton(final PurchaseActivity act) |
|
| 35 |
{
|
|
| 36 |
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT); |
|
| 37 |
mBackButton = new TransparentImageButton(act,R.drawable.ui_smallback,params); |
|
| 38 |
|
|
| 39 |
mBackButton.setOnClickListener( new View.OnClickListener() |
|
| 40 |
{
|
|
| 41 |
@Override |
|
| 42 |
public void onClick(View v) |
|
| 43 |
{
|
|
| 44 |
if( !mBlocked ) act.finish(); |
|
| 45 |
} |
|
| 46 |
}); |
|
| 47 |
} |
|
| 48 |
|
|
| 49 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 50 |
|
|
| 51 |
void onAttachedToWindow(final PurchaseActivity act, final int ordinal) |
|
| 52 |
{
|
|
| 53 |
mBlocked = false; |
|
| 54 |
int width = act.getScreenWidthInPixels(); |
|
| 55 |
|
|
| 56 |
LinearLayout.LayoutParams paramsL = new LinearLayout.LayoutParams(width/4, LinearLayout.LayoutParams.MATCH_PARENT); |
|
| 57 |
LinearLayout.LayoutParams paramsM = new LinearLayout.LayoutParams(width/2, LinearLayout.LayoutParams.MATCH_PARENT); |
|
| 58 |
LinearLayout.LayoutParams paramsR = new LinearLayout.LayoutParams(width/4, LinearLayout.LayoutParams.MATCH_PARENT); |
|
| 59 |
|
|
| 60 |
LinearLayout layoutLeft = new LinearLayout(act); |
|
| 61 |
layoutLeft.setLayoutParams(paramsL); |
|
| 62 |
LinearLayout layoutMid = new LinearLayout(act); |
|
| 63 |
layoutMid.setLayoutParams(paramsM); |
|
| 64 |
LinearLayout layoutRight= new LinearLayout(act); |
|
| 65 |
layoutRight.setLayoutParams(paramsR); |
|
| 66 |
|
|
| 67 |
setupBackButton(act); |
|
| 68 |
|
|
| 69 |
layoutRight.addView(mBackButton); |
|
| 70 |
|
|
| 71 |
LinearLayout layout = act.findViewById(R.id.lowerBar); |
|
| 72 |
layout.removeAllViews(); |
|
| 73 |
layout.addView(layoutLeft); |
|
| 74 |
layout.addView(layoutMid); |
|
| 75 |
layout.addView(layoutRight); |
|
| 76 |
|
|
| 77 |
PurchaseScreenPane pane = new PurchaseScreenPane(act); |
|
| 78 |
pane.updatePane(act,ordinal); |
|
| 79 |
} |
|
| 80 |
} |
|
| src/main/java/org/distorted/purchase/PurchaseScreenPane.java | ||
|---|---|---|
| 1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 2 |
// Copyright 2020 Leszek Koltunski // |
|
| 3 |
// // |
|
| 4 |
// This file is part of Magic Cube. // |
|
| 5 |
// // |
|
| 6 |
// Magic Cube is proprietary software licensed under an EULA which you should have received // |
|
| 7 |
// along with the code. If not, check https://distorted.org/magic/License-Magic-Cube.html // |
|
| 8 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 9 |
|
|
| 10 |
package org.distorted.purchase; |
|
| 11 |
|
|
| 12 |
import android.graphics.drawable.Drawable; |
|
| 13 |
import android.util.TypedValue; |
|
| 14 |
import android.view.View; |
|
| 15 |
import android.widget.ImageButton; |
|
| 16 |
import android.widget.ImageView; |
|
| 17 |
import android.widget.LinearLayout; |
|
| 18 |
import android.widget.TextView; |
|
| 19 |
|
|
| 20 |
import androidx.core.content.res.ResourcesCompat; |
|
| 21 |
|
|
| 22 |
import org.distorted.dialogs.RubikDialogStarsStatus; |
|
| 23 |
import org.distorted.external.RubikScores; |
|
| 24 |
import org.distorted.library.main.DistortedScreen; |
|
| 25 |
import org.distorted.main.R; |
|
| 26 |
import org.distorted.objectlib.json.JsonReader; |
|
| 27 |
import org.distorted.objects.RubikObject; |
|
| 28 |
import org.distorted.objects.RubikObjectList; |
|
| 29 |
import org.distorted.overlays.DataStars; |
|
| 30 |
import org.distorted.overlays.ListenerOverlay; |
|
| 31 |
import org.distorted.overlays.OverlayStars; |
|
| 32 |
|
|
| 33 |
import java.io.InputStream; |
|
| 34 |
import java.lang.ref.WeakReference; |
|
| 35 |
|
|
| 36 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 37 |
|
|
| 38 |
public class PurchaseScreenPane implements ListenerOverlay |
|
| 39 |
{
|
|
| 40 |
public static final int UNLOCK_ALL_PRICE = 600; |
|
| 41 |
|
|
| 42 |
private static final int[] IMAGES = |
|
| 43 |
{
|
|
| 44 |
R.drawable.difficulty1, |
|
| 45 |
R.drawable.difficulty2, |
|
| 46 |
R.drawable.difficulty3, |
|
| 47 |
R.drawable.difficulty4, |
|
| 48 |
R.drawable.difficulty5, |
|
| 49 |
}; |
|
| 50 |
|
|
| 51 |
private static final int NUM_IMAGES = IMAGES.length; |
|
| 52 |
public static final float PADDING_RATIO = 0.017f; |
|
| 53 |
private static final float TEXT_RATIO_1 = 0.032f; |
|
| 54 |
private static final float TEXT_RATIO_2 = 0.020f; |
|
| 55 |
|
|
| 56 |
private final WeakReference<PurchaseActivity> mAct; |
|
| 57 |
private RubikObject mObject; |
|
| 58 |
|
|
| 59 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 60 |
|
|
| 61 |
private boolean chargeUser(int amount) |
|
| 62 |
{
|
|
| 63 |
RubikScores scores = RubikScores.getInstance(); |
|
| 64 |
int numStars = scores.getNumStars(); |
|
| 65 |
|
|
| 66 |
if( numStars>=amount ) |
|
| 67 |
{
|
|
| 68 |
scores.changeNumStars(-amount); |
|
| 69 |
return true; |
|
| 70 |
} |
|
| 71 |
|
|
| 72 |
return false; |
|
| 73 |
} |
|
| 74 |
|
|
| 75 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 76 |
|
|
| 77 |
private void showStatus(PurchaseActivity act) |
|
| 78 |
{
|
|
| 79 |
RubikDialogStarsStatus d = new RubikDialogStarsStatus(); |
|
| 80 |
d.show(act.getSupportFragmentManager(), null); |
|
| 81 |
} |
|
| 82 |
|
|
| 83 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 84 |
|
|
| 85 |
private void showSuccess(PurchaseActivity act, RubikObject object) |
|
| 86 |
{
|
|
| 87 |
act.blockUI(); |
|
| 88 |
RubikScores scores = RubikScores.getInstance(); |
|
| 89 |
int totStars = scores.getNumStars(); |
|
| 90 |
int price = object==null ? UNLOCK_ALL_PRICE:object.getPrice(); |
|
| 91 |
PurchaseRenderer renderer = act.getRenderer(); |
|
| 92 |
DistortedScreen screen = renderer.getScreen(); |
|
| 93 |
OverlayStars stars = new OverlayStars(); |
|
| 94 |
DataStars data = new DataStars(totStars+price,-price,act.getResources()); |
|
| 95 |
stars.startOverlay(screen,this,data); |
|
| 96 |
} |
|
| 97 |
|
|
| 98 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 99 |
|
|
| 100 |
private void oneButtonClicked(PurchaseActivity act) |
|
| 101 |
{
|
|
| 102 |
if( mObject!=null ) |
|
| 103 |
{
|
|
| 104 |
int price = mObject.getPrice(); |
|
| 105 |
|
|
| 106 |
if( chargeUser(price) ) |
|
| 107 |
{
|
|
| 108 |
RubikObjectList.buyObject(mObject); |
|
| 109 |
showSuccess(act,mObject); |
|
| 110 |
} |
|
| 111 |
else |
|
| 112 |
{
|
|
| 113 |
showStatus(act); |
|
| 114 |
} |
|
| 115 |
} |
|
| 116 |
} |
|
| 117 |
|
|
| 118 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 119 |
|
|
| 120 |
private void allButtonClicked(PurchaseActivity act) |
|
| 121 |
{
|
|
| 122 |
if( chargeUser(UNLOCK_ALL_PRICE) ) |
|
| 123 |
{
|
|
| 124 |
RubikObjectList.buyAll(); |
|
| 125 |
showSuccess(act,null); |
|
| 126 |
} |
|
| 127 |
else |
|
| 128 |
{
|
|
| 129 |
showStatus(act); |
|
| 130 |
} |
|
| 131 |
} |
|
| 132 |
|
|
| 133 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 134 |
|
|
| 135 |
private void setUpButtons(PurchaseActivity act, LinearLayout one, LinearLayout all) |
|
| 136 |
{
|
|
| 137 |
ImageButton butO = one.findViewById(R.id.purchaseButtonOne); |
|
| 138 |
ImageButton butA = all.findViewById(R.id.purchaseButtonAll); |
|
| 139 |
|
|
| 140 |
int id,price = act.getObjectPrice(); |
|
| 141 |
|
|
| 142 |
if( price<=10 ) id = R.drawable.price_10; |
|
| 143 |
else if( price<=20 ) id = R.drawable.price_20; |
|
| 144 |
else if( price<=30 ) id = R.drawable.price_30; |
|
| 145 |
else if( price<=40 ) id = R.drawable.price_40; |
|
| 146 |
else if( price<=50 ) id = R.drawable.price_50; |
|
| 147 |
else if( price<=60 ) id = R.drawable.price_60; |
|
| 148 |
else if( price<=70 ) id = R.drawable.price_70; |
|
| 149 |
else if( price<=80 ) id = R.drawable.price_80; |
|
| 150 |
else if( price<=90 ) id = R.drawable.price_90; |
|
| 151 |
else id = R.drawable.price_100; |
|
| 152 |
|
|
| 153 |
Drawable drawable = ResourcesCompat.getDrawable(act.getResources(), id, null); |
|
| 154 |
butO.setImageDrawable(drawable); |
|
| 155 |
|
|
| 156 |
butO.setOnClickListener( new View.OnClickListener() |
|
| 157 |
{
|
|
| 158 |
@Override |
|
| 159 |
public void onClick(View v) |
|
| 160 |
{
|
|
| 161 |
oneButtonClicked(act); |
|
| 162 |
} |
|
| 163 |
}); |
|
| 164 |
|
|
| 165 |
butA.setOnClickListener( new View.OnClickListener() |
|
| 166 |
{
|
|
| 167 |
@Override |
|
| 168 |
public void onClick(View v) |
|
| 169 |
{
|
|
| 170 |
allButtonClicked(act); |
|
| 171 |
} |
|
| 172 |
}); |
|
| 173 |
} |
|
| 174 |
|
|
| 175 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 176 |
|
|
| 177 |
void updatePane(PurchaseActivity act, int objectOrdinal) |
|
| 178 |
{
|
|
| 179 |
mObject = RubikObjectList.getObject(objectOrdinal); |
|
| 180 |
|
|
| 181 |
if( mObject!=null ) |
|
| 182 |
{
|
|
| 183 |
InputStream stream = mObject.getObjectStream(act); |
|
| 184 |
JsonReader reader = new JsonReader(); |
|
| 185 |
String author, name; |
|
| 186 |
int year, difficulty; |
|
| 187 |
|
|
| 188 |
try |
|
| 189 |
{
|
|
| 190 |
reader.parseJsonFileMetadata(stream); |
|
| 191 |
name = reader.getObjectName(); |
|
| 192 |
author = reader.getAuthor(); |
|
| 193 |
year = reader.getYearOfInvention(); |
|
| 194 |
difficulty = (int)reader.getDifficulty(); |
|
| 195 |
} |
|
| 196 |
catch(Exception ex) |
|
| 197 |
{
|
|
| 198 |
name = "?"; |
|
| 199 |
author = "?"; |
|
| 200 |
year = 0; |
|
| 201 |
difficulty = 0; |
|
| 202 |
} |
|
| 203 |
|
|
| 204 |
if( difficulty<0 ) difficulty=0; |
|
| 205 |
if( difficulty>=NUM_IMAGES ) difficulty=NUM_IMAGES-1; |
|
| 206 |
|
|
| 207 |
String both = year>0 ? author+" "+year : author; |
|
| 208 |
|
|
| 209 |
TextView v1 = act.findViewById(R.id.purchaseUpperName); |
|
| 210 |
v1.setText(name); |
|
| 211 |
TextView v2 = act.findViewById(R.id.purchaseUpperAuthor); |
|
| 212 |
v2.setText(both); |
|
| 213 |
ImageView image = act.findViewById(R.id.purchaseDifficulty); |
|
| 214 |
image.setImageResource(IMAGES[difficulty]); |
|
| 215 |
} |
|
| 216 |
} |
|
| 217 |
|
|
| 218 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 219 |
|
|
| 220 |
PurchaseScreenPane(final PurchaseActivity act) |
|
| 221 |
{
|
|
| 222 |
mAct = new WeakReference<>(act); |
|
| 223 |
int height = act.getScreenHeightInPixels(); |
|
| 224 |
float textSize1 = height*TEXT_RATIO_1; |
|
| 225 |
float textSize2 = height*TEXT_RATIO_2; |
|
| 226 |
int margin = (int)(height*PADDING_RATIO); |
|
| 227 |
int padding = margin/3; |
|
| 228 |
|
|
| 229 |
LinearLayout upperBar = act.findViewById(R.id.upperBar); |
|
| 230 |
LinearLayout oneLayout = act.findViewById(R.id.purchaseLayoutOne); |
|
| 231 |
LinearLayout allLayout = act.findViewById(R.id.purchaseLayoutAll); |
|
| 232 |
|
|
| 233 |
upperBar.setPadding( margin, margin, margin, margin); |
|
| 234 |
oneLayout.setPadding( padding, padding, padding, padding); |
|
| 235 |
allLayout.setPadding( padding, padding, padding, padding); |
|
| 236 |
|
|
| 237 |
LinearLayout.LayoutParams params1 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 0, 1.00f); |
|
| 238 |
params1.bottomMargin = 0; |
|
| 239 |
params1.topMargin = margin; |
|
| 240 |
params1.leftMargin = margin; |
|
| 241 |
params1.rightMargin = margin; |
|
| 242 |
|
|
| 243 |
LinearLayout.LayoutParams params2 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 0, 1.00f); |
|
| 244 |
params2.bottomMargin = margin; |
|
| 245 |
params2.topMargin = margin; |
|
| 246 |
params2.leftMargin = margin; |
|
| 247 |
params2.rightMargin = margin; |
|
| 248 |
|
|
| 249 |
LinearLayout.LayoutParams params3 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 0, 1.00f); |
|
| 250 |
params3.bottomMargin = 0; |
|
| 251 |
params3.topMargin = 0; |
|
| 252 |
params3.leftMargin = margin; |
|
| 253 |
params3.rightMargin = margin; |
|
| 254 |
|
|
| 255 |
upperBar.setLayoutParams(params1); |
|
| 256 |
oneLayout.setLayoutParams(params3); |
|
| 257 |
allLayout.setLayoutParams(params2); |
|
| 258 |
|
|
| 259 |
TextView text; |
|
| 260 |
text = upperBar.findViewById(R.id.purchaseUpperName); |
|
| 261 |
text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize1); |
|
| 262 |
text = upperBar.findViewById(R.id.purchaseUpperAuthor); |
|
| 263 |
text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize2); |
|
| 264 |
text = oneLayout.findViewById(R.id.purchaseTextOne); |
|
| 265 |
text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize1); |
|
| 266 |
text = allLayout.findViewById(R.id.purchaseTextAll); |
|
| 267 |
text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize1); |
|
| 268 |
|
|
| 269 |
setUpButtons(act,oneLayout,allLayout); |
|
| 270 |
} |
|
| 271 |
|
|
| 272 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 273 |
|
|
| 274 |
public void overlayFinished(long id) |
|
| 275 |
{
|
|
| 276 |
PurchaseActivity act = mAct.get(); |
|
| 277 |
if( act!=null ) act.finish(); |
|
| 278 |
} |
|
| 279 |
} |
|
| src/main/java/org/distorted/purchase/PurchaseSurfaceView.java | ||
|---|---|---|
| 1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 2 |
// Copyright 2020 Leszek Koltunski // |
|
| 3 |
// // |
|
| 4 |
// This file is part of Magic Cube. // |
|
| 5 |
// // |
|
| 6 |
// Magic Cube is proprietary software licensed under an EULA which you should have received // |
|
| 7 |
// along with the code. If not, check https://distorted.org/magic/License-Magic-Cube.html // |
|
| 8 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 9 |
|
|
| 10 |
package org.distorted.purchase; |
|
| 11 |
|
|
| 12 |
import android.app.ActivityManager; |
|
| 13 |
import android.content.Context; |
|
| 14 |
import android.content.pm.ConfigurationInfo; |
|
| 15 |
import android.opengl.GLES30; |
|
| 16 |
import android.opengl.GLSurfaceView; |
|
| 17 |
import android.util.AttributeSet; |
|
| 18 |
|
|
| 19 |
import com.google.firebase.crashlytics.FirebaseCrashlytics; |
|
| 20 |
|
|
| 21 |
import org.distorted.objectlib.main.ObjectControl; |
|
| 22 |
import org.distorted.objectlib.main.TwistyObjectNode; |
|
| 23 |
import org.distorted.os.OSInterface; |
|
| 24 |
|
|
| 25 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 26 |
|
|
| 27 |
public class PurchaseSurfaceView extends GLSurfaceView |
|
| 28 |
{
|
|
| 29 |
private ObjectControl mObjectController; |
|
| 30 |
private OSInterface mInterface; |
|
| 31 |
private PurchaseRenderer mRenderer; |
|
| 32 |
private boolean mCreated; |
|
| 33 |
|
|
| 34 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 35 |
|
|
| 36 |
void setScreenSize(int width, int height) |
|
| 37 |
{
|
|
| 38 |
mObjectController.setScreenSizeAndScaling(width,height, Math.min(width,height)); |
|
| 39 |
mObjectController.setObjectScale(1.00f); |
|
| 40 |
|
|
| 41 |
if( !mCreated ) |
|
| 42 |
{
|
|
| 43 |
mCreated = true; |
|
| 44 |
mObjectController.createNode(width,height); |
|
| 45 |
TwistyObjectNode objectNode = mObjectController.getNode(); |
|
| 46 |
mRenderer.getScreen().attach(objectNode); |
|
| 47 |
} |
|
| 48 |
} |
|
| 49 |
|
|
| 50 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 51 |
|
|
| 52 |
ObjectControl getObjectControl() |
|
| 53 |
{
|
|
| 54 |
return mObjectController; |
|
| 55 |
} |
|
| 56 |
|
|
| 57 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 58 |
|
|
| 59 |
PurchaseRenderer getRenderer() |
|
| 60 |
{
|
|
| 61 |
return mRenderer; |
|
| 62 |
} |
|
| 63 |
|
|
| 64 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 65 |
// PUBLIC API |
|
| 66 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 67 |
|
|
| 68 |
public PurchaseSurfaceView(Context context, AttributeSet attrs) |
|
| 69 |
{
|
|
| 70 |
super(context,attrs); |
|
| 71 |
|
|
| 72 |
mCreated = false; |
|
| 73 |
|
|
| 74 |
if(!isInEditMode()) |
|
| 75 |
{
|
|
| 76 |
PurchaseActivity act = (PurchaseActivity)context; |
|
| 77 |
PurchaseObjectLibInterface ref = new PurchaseObjectLibInterface(); |
|
| 78 |
mInterface = new OSInterface(act,ref); |
|
| 79 |
mObjectController = new ObjectControl(mInterface); |
|
| 80 |
mObjectController.setRotateOnCreation(true); |
|
| 81 |
mRenderer = new PurchaseRenderer(this); |
|
| 82 |
|
|
| 83 |
final ActivityManager activityManager= (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); |
|
| 84 |
|
|
| 85 |
try |
|
| 86 |
{
|
|
| 87 |
final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo(); |
|
| 88 |
int esVersion = configurationInfo.reqGlEsVersion>>16; |
|
| 89 |
setEGLContextClientVersion(esVersion); |
|
| 90 |
setRenderer(mRenderer); |
|
| 91 |
} |
|
| 92 |
catch(Exception ex) |
|
| 93 |
{
|
|
| 94 |
act.OpenGLError(); |
|
| 95 |
|
|
| 96 |
String shading = GLES30.glGetString(GLES30.GL_SHADING_LANGUAGE_VERSION); |
|
| 97 |
String version = GLES30.glGetString(GLES30.GL_VERSION); |
|
| 98 |
String vendor = GLES30.glGetString(GLES30.GL_VENDOR); |
|
| 99 |
String renderer= GLES30.glGetString(GLES30.GL_RENDERER); |
|
| 100 |
|
|
| 101 |
FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance(); |
|
| 102 |
crashlytics.setCustomKey("GLSL Version" , shading );
|
|
| 103 |
crashlytics.setCustomKey("GL version" , version );
|
|
| 104 |
crashlytics.setCustomKey("GL Vendor " , vendor );
|
|
| 105 |
crashlytics.setCustomKey("GLSL renderer" , renderer);
|
|
| 106 |
crashlytics.recordException(ex); |
|
| 107 |
} |
|
| 108 |
} |
|
| 109 |
} |
|
| 110 |
|
|
| 111 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 112 |
|
|
| 113 |
@Override |
|
| 114 |
public void onPause() |
|
| 115 |
{
|
|
| 116 |
super.onPause(); |
|
| 117 |
mObjectController.onPause(); |
|
| 118 |
} |
|
| 119 |
|
|
| 120 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 121 |
|
|
| 122 |
@Override |
|
| 123 |
public void onResume() |
|
| 124 |
{
|
|
| 125 |
super.onResume(); |
|
| 126 |
mObjectController.onResume(); |
|
| 127 |
} |
|
| 128 |
} |
|
Also available in: Unified diff
common code from all activities to one BaseActivity