/** @return whether the activity was initialized */ private boolean initIfConfigured() { // Do we have a valid server config? Preferences preferences = new Preferences(getApplicationContext()); String host = preferences.getString(R.string.pref_key_host, null); int port = preferences.getInt(R.string.pref_key_port, -1); if (host == null || port == -1){ return false; } initActivity(); return true; }
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Override public void onReceive(Context context, Intent intent) { if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) { Preferences preferences = new Preferences(context); if (preferences.getBoolean(R.string.pref_key_boot)) { final Intent i = new Intent(context, BootActivity.class); i.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION |Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS |Intent.FLAG_ACTIVITY_NO_HISTORY); context.startActivity(i); } } } }
/** Save scan result to Preferences */ private void saveResult() { Preferences prefs = new Preferences(getApplicationContext()); prefs.putString(R.string.pref_key_host, hostName); prefs.putInt(R.string.pref_key_port, port); }
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) private boolean prepared() { Preferences prefs = new Preferences(getBaseContext()); String host = prefs.getString(R.string.pref_key_host, null); int port = prefs.getInt(R.string.pref_key_port, -1); String priority = prefs.getString(R.string.pref_key_priority, "50"); mFrameRate = prefs.getInt(R.string.pref_key_framerate); mHorizontalLEDCount = prefs.getInt(R.string.pref_key_x_led); mVerticalLEDCount = prefs.getInt(R.string.pref_key_y_led); mSendAverageColor = prefs.getBoolean(R.string.pref_key_use_avg_color); RECONNECT = prefs.getBoolean(R.string.pref_key_reconnect); int delay = prefs.getInt(R.string.pref_key_reconnect_delay); if (host == null || Objects.equals(host, "0.0.0.0") || Objects.equals(host, "")) { mStartError = getResources().getString(R.string.error_empty_host); return false; } if (port == -1) { mStartError = getResources().getString(R.string.error_empty_port); return false; } if (mHorizontalLEDCount <= 0 || mVerticalLEDCount <= 0) { mStartError = getResources().getString(R.string.error_invalid_led_counts); return false; } mMediaProjectionManager = (MediaProjectionManager) getSystemService(Context.MEDIA_PROJECTION_SERVICE); mHyperionThread = new HyperionThread(mReceiver, host, port, Integer.parseInt(priority), RECONNECT, delay); mHyperionThread.start(); mStartError = null; return true; }
/** Starts the Settings Activity if connection settings are missing * * @return true if setup was started */ private boolean startSetupIfNeeded(){ Preferences preferences = new Preferences(getApplicationContext()); if (TextUtils.isEmpty(preferences.getString(R.string.pref_key_host, null)) || preferences.getInt(R.string.pref_key_port, -1) == -1){ Intent settingsIntent = new Intent(this, SettingsActivity.class); settingsIntent.putExtra(SettingsActivity.EXTRA_SHOW_TOAST_KEY, SettingsActivity.EXTRA_SHOW_TOAST_SETUP_REQUIRED_FOR_QUICK_TILE); settingsIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // Use TaskStackBuilder to make sure the MainActivity opens when the SettingsActivity is closed TaskStackBuilder.create(this) .addNextIntentWithParentStack(settingsIntent) .startActivities(); Intent closeIntent = new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS); sendBroadcast(closeIntent); return true; } return false; } }