@Override protected void onStart() { final GameBoard boardView = (GameBoard) this.findViewById(R.id.gameBoard); SharedPreferences prefs = getPreferences(Context.MODE_PRIVATE); this.level = prefs.getInt("level", 0); String mapJson = prefs.getString("map", null); if (mapJson == null) { waitForNext = true; } else { this.game.initGame(mapJson); String howdyPosition = prefs.getString("howdy", null); if (howdyPosition != null) { this.game.setHowdyPosition(howdyPosition); } Toast.makeText(this, this.level + "", Toast.LENGTH_SHORT).show(); } String allDoneLevelsString = prefs.getString("doneLevels", null); if (allDoneLevelsString != null) { allDoneLevels = new ArrayList<String>(Arrays.asList(allDoneLevelsString.split(","))); } super.onStart(); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // remove title requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow() .setFlags( WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); setContentView(R.layout.activity_main_game); allDoneLevels = new ArrayList<>(); AssetManager am = getResources().getAssets(); final GameBoard boardView = (GameBoard) this.findViewById(R.id.gameBoard); final HowdyShadeView howdyShadeView = (HowdyShadeView) this.findViewById(R.id.howdyShadeView); final GlowingBoard glowingBoard = (GlowingBoard) this.findViewById(R.id.glowingBoard); final HowdyView howdyView = (HowdyView) this.findViewById(R.id.howdyView); this.game = new Game(); boardView.setHowdyShadeView(howdyShadeView); boardView.setGlowingBoard(glowingBoard); boardView.setHowdyView(howdyView); boardView.setOnTouchListener(new BoardGameTouchListener(this)); }
@Override public void onWindowFocusChanged(boolean hasFocus) { // TODO: Implement this method super.onWindowFocusChanged(hasFocus); if (waitForNext) { this.nextLevel(); waitForNext = false; } ((GameBoard) findViewById(R.id.gameBoard)).setGame(this.game); findViewById(R.id.gameBoard).invalidate(); ((GameBoard) findViewById(R.id.gameBoard)).getHowdyShadeView().invalidate(); }
@Override public void onResume() { Log.i(LOG_FILE_NAME, "resume"); if (checkLaunchState(LaunchState.GeckoRunning)) GeckoAppShell.onResume(); // After an onPause, the activity is back in the foreground. // Undo whatever we did in onPause. super.onResume(); // Just in case. Normally we start in onNewIntent if (checkLaunchState(LaunchState.PreLaunch) || checkLaunchState(LaunchState.Launching)) onNewIntent(getIntent()); registerReceiver(mConnectivityReceiver, mConnectivityFilter); GeckoNetworkManager.getInstance().start(); GeckoScreenOrientationListener.getInstance().start(); }
@Override public void onStop() { Log.i(LOG_FILE_NAME, "stop"); // We're about to be stopped, potentially in preparation for // being destroyed. We're killable after this point -- as I // understand it, in extreme cases the process can be terminated // without going through onDestroy. // // We might also get an onRestart after this; not sure what // that would mean for Gecko if we were to kill it here. // Instead, what we should do here is save prefs, session, // etc., and generally mark the profile as 'clean', and then // dirty it again if we get an onResume. GeckoAppShell.sendEventToGecko(new GeckoEvent(GeckoEvent.ACTIVITY_STOPPING)); super.onStop(); GeckoAppShell.putChildInBackground(); }
@Override public void onPause() { Log.i(LOG_FILE_NAME, "pause"); GeckoAppShell.sendEventToGecko(new GeckoEvent(GeckoEvent.ACTIVITY_PAUSING)); // The user is navigating away from this activity, but nothing // has come to the foreground yet; for Gecko, we may want to // stop repainting, for example. // Whatever we do here should be fast, because we're blocking // the next activity from showing up until we finish. // onPause will be followed by either onResume or onStop. super.onPause(); unregisterReceiver(mConnectivityReceiver); GeckoNetworkManager.getInstance().stop(); GeckoScreenOrientationListener.getInstance().stop(); }
@Override public void onDestroy() { Log.i(LOG_FILE_NAME, "destroy"); // Tell Gecko to shutting down; we'll end up calling System.exit() // in onXreExit. if (isFinishing()) GeckoAppShell.sendEventToGecko(new GeckoEvent(GeckoEvent.ACTIVITY_SHUTDOWN)); if (SmsManager.getInstance() != null) { SmsManager.getInstance().stop(); if (isFinishing()) SmsManager.getInstance().shutdown(); } GeckoNetworkManager.getInstance().stop(); GeckoScreenOrientationListener.getInstance().stop(); super.onDestroy(); unregisterReceiver(mBatteryReceiver); }
@Override protected void onStop() { SharedPreferences prefs = getPreferences(Context.MODE_PRIVATE); SharedPreferences.Editor editor = prefs.edit(); editor.putInt("level", this.level); editor.putString("map", game.getLabyrinth().getJsonMap()); editor.putString("howdy", game.getJsonHowdy()); String allDoneLevelsString = ""; for (String s : allDoneLevels) { allDoneLevelsString += s + ","; } if (allDoneLevelsString.length() > 0) { editor.putString( "doneLevels", allDoneLevelsString.substring(0, allDoneLevelsString.length() - 1)); } editor.commit(); super.onStop(); }
@Override public void onLowMemory() { Log.e(LOG_FILE_NAME, "low memory"); if (checkLaunchState(LaunchState.GeckoRunning)) GeckoAppShell.onLowMemory(); super.onLowMemory(); }
@Override public void onConfigurationChanged(android.content.res.Configuration newConfig) { Log.i(LOG_FILE_NAME, "configuration changed"); // nothing, just ignore super.onConfigurationChanged(newConfig); }
@Override public void onStart() { Log.i(LOG_FILE_NAME, "start"); GeckoAppShell.sendEventToGecko(new GeckoEvent(GeckoEvent.ACTIVITY_START)); super.onStart(); }
@Override public void onRestart() { Log.i(LOG_FILE_NAME, "restart"); GeckoAppShell.putChildInForeground(); super.onRestart(); }
/** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { mAppContext = this; mMainHandler = new Handler(); if (!sTryCatchAttached) { sTryCatchAttached = true; mMainHandler.post( new Runnable() { public void run() { try { Looper.loop(); } catch (Exception e) { Log.e(LOG_FILE_NAME, "top level exception", e); StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); e.printStackTrace(pw); pw.flush(); GeckoAppShell.reportJavaCrash(sw.toString()); } // resetting this is kinda pointless, but oh well sTryCatchAttached = false; } }); } SharedPreferences settings = getPreferences(Activity.MODE_PRIVATE); String localeCode = settings.getString(getPackageName() + ".locale", ""); if (localeCode != null && localeCode.length() > 0) GeckoAppShell.setSelectedLocale(localeCode); Log.i(LOG_FILE_NAME, "create"); super.onCreate(savedInstanceState); if (sGREDir == null) sGREDir = new File(this.getApplicationInfo().dataDir); getWindow() .setFlags( mFullscreen ? WindowManager.LayoutParams.FLAG_FULLSCREEN : 0, WindowManager.LayoutParams.FLAG_FULLSCREEN); if (cameraView == null) { cameraView = new SurfaceView(this); cameraView.getHolder().setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); } if (surfaceView == null) surfaceView = new GeckoSurfaceView(this); else mainLayout.removeAllViews(); mainLayout = new AbsoluteLayout(this); mainLayout.addView( surfaceView, new AbsoluteLayout.LayoutParams( AbsoluteLayout.LayoutParams.MATCH_PARENT, // level 8 AbsoluteLayout.LayoutParams.MATCH_PARENT, 0, 0)); setContentView( mainLayout, new ViewGroup.LayoutParams( ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT)); mConnectivityFilter = new IntentFilter(); mConnectivityFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION); mConnectivityReceiver = new GeckoConnectivityReceiver(); IntentFilter batteryFilter = new IntentFilter(); batteryFilter.addAction(Intent.ACTION_BATTERY_CHANGED); mBatteryReceiver = new GeckoBatteryManager(); registerReceiver(mBatteryReceiver, batteryFilter); if (SmsManager.getInstance() != null) { SmsManager.getInstance().start(); } GeckoNetworkManager.getInstance().init(); if (!checkAndSetLaunchState(LaunchState.PreLaunch, LaunchState.Launching)) return; checkAndLaunchUpdate(); mLibLoadThread = new Thread( new Runnable() { public void run() { // At some point while loading the gecko libs our default locale gets set // so just save it to locale here and reset it as default after the join Locale locale = Locale.getDefault(); GeckoAppShell.loadGeckoLibs(getApplication().getPackageResourcePath()); Locale.setDefault(locale); Resources res = getBaseContext().getResources(); Configuration config = res.getConfiguration(); config.locale = locale; res.updateConfiguration(config, res.getDisplayMetrics()); } }); mLibLoadThread.start(); }
// flipscreen not loading again @Override public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.profile); findViews(); /*Select Category work */ final String[] categories = getIntent().getStringArrayExtra("Options"); ArrayAdapter<String> catadapt; catadapt = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, categories); mCatSpin.setAdapter(catadapt); mCatSpin.setOnItemSelectedListener( new OnItemSelectedListener() { public void onItemSelected(AdapterView<?> parent, View v, int pos, long id) { mChosenCategory = categories[pos]; } public void onNothingSelected(AdapterView<?> parent) {} }); /*Availability selection work*/ mAvail = (Button) findViewById(R.id.editavail); mAvail.setOnClickListener(this); /*Submit/Back button work*/ mSub = (Button) findViewById(R.id.submitbutton); mSub.setOnClickListener(this); mBack.setOnClickListener(this); /*Web View & Camera uploader work*/ openCam.setOnClickListener(this); openWeb.setOnClickListener(this); web.getSettings().setJavaScriptEnabled(true); web.loadUrl("http://www.monkbananas.com/uploader/index.php"); // ------Everything below this line was found on StackOverflow-------------------- web.setWebChromeClient( new WebChromeClient() { @Override public boolean shouldOverrideUrlLoading(WebView v, String url) { web.loadUrl(url); return true; } // The undocumented magic method override // Eclipse will swear at you if you try to put @Override here // For Android 3.0+ public void openFileChooser(ValueCallback<Uri> uploadMsg) { mUploadMessage = uploadMsg; Intent i = new Intent(Intent.ACTION_GET_CONTENT); i.addCategory(Intent.CATEGORY_OPENABLE); i.setType("image/*"); startActivityForResult(Intent.createChooser(i, "File Chooser"), FILECHOOSER_RESULTCODE); } // For Android 3.0+ public void openFileChooser(ValueCallback uploadMsg, String acceptType) { mUploadMessage = uploadMsg; Intent i = new Intent(Intent.ACTION_GET_CONTENT); i.addCategory(Intent.CATEGORY_OPENABLE); i.setType("*/*"); startActivityForResult(Intent.createChooser(i, "File Browser"), FILECHOOSER_RESULTCODE); } // For Android 4.1 public void openFileChooser( ValueCallback<Uri> uploadMsg, String acceptType, String capture) { mUploadMessage = uploadMsg; Intent i = new Intent(Intent.ACTION_GET_CONTENT); i.addCategory(Intent.CATEGORY_OPENABLE); i.setType("image/*"); startActivityForResult(Intent.createChooser(i, "File Chooser"), FILECHOOSER_RESULTCODE); } }); }