Added ability to filter 2D apps

This commit is contained in:
tverona1
2019-07-26 01:09:08 -07:00
parent 2b6ebb6e73
commit de5225c19a
9 changed files with 688 additions and 69 deletions
+1
View File
@@ -23,6 +23,7 @@ namespace QuestAppLauncher
}
public GridSize gridSize = new GridSize();
public bool show2D = false;
}
/// <summary>
+42 -32
View File
@@ -28,15 +28,15 @@ namespace QuestAppLauncher
// Grid container game object
public GameObject gridContainer;
// Scroll view game object
public GameObject scrollView;
// Grid content game object
public GameObject gridContent;
// App info GameObject (a cell in the grid content)
public GameObject prefab;
// Reference to executing populate routine
private Coroutine populateCoroutine;
#region MonoBehaviour handler
void Start()
@@ -47,11 +47,8 @@ namespace QuestAppLauncher
// Initialize the core platform
Core.AsyncInitialize();
// Process configuration
StartCoroutine(ProcessConfig());
// Populate the grid
StartCoroutine(Populate());
StartPopulate();
}
void Update()
@@ -126,20 +123,6 @@ namespace QuestAppLauncher
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
}
/// <summary>
/// Loads & processes config
/// </summary>
/// <returns></returns>
IEnumerator ProcessConfig()
{
// Load configuration
Config config = new Config();
ConfigPersistence.LoadConfig(config);
SetGridSize(config.gridSize.rows, config.gridSize.cols);
yield return null;
}
public void SetGridSize(int rows, int cols)
{
// Make sure grid size have sane value
@@ -176,25 +159,41 @@ namespace QuestAppLauncher
(float)((gridTransform.rect.height - 2000) / 2.0),
gridTransform.anchoredPosition3D.z);
gridTransform.anchoredPosition3D = gridPosition;
}
// Adjust scroll view rect transform
var scrollViewRectTransform = this.scrollView.GetComponent<RectTransform>();
scrollViewRectTransform.sizeDelta = new Vector2(width, height);
// Adjust scroll view box collider
var scrollViewBoxCollider = this.scrollView.GetComponent<BoxCollider>();
scrollViewBoxCollider.size = new Vector3(width, height, 0);
public void StartPopulate()
{
// Ensure we only exeucte on populate routine at a time
if (null != this.populateCoroutine)
{
StopCoroutine(this.populateCoroutine);
}
this.populateCoroutine = this.StartCoroutine(Populate());
}
/// <summary>
/// Populate the grid from installed apps
/// </summary>
/// <returns></returns>
IEnumerator Populate()
private IEnumerator Populate()
{
var persistentDataPath = UnityEngine.Application.persistentDataPath;
Debug.Log("Persistent data path: " + persistentDataPath);
// Load configuration
Config config = new Config();
ConfigPersistence.LoadConfig(config);
// Clear any existing elements in grid
for (int i = 0; i < this.gridContent.transform.childCount; i++)
{
Destroy(this.gridContent.transform.GetChild(i).gameObject);
}
// Set grid size
SetGridSize(config.gridSize.rows, config.gridSize.cols);
using (AndroidJavaClass unity = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
using (AndroidJavaObject currentActivity = unity.GetStatic<AndroidJavaObject>("currentActivity"))
{
@@ -232,11 +231,22 @@ namespace QuestAppLauncher
if (excludedPackageNames.Contains(packageName))
{
Debug.Log("Skipping [" + i + "] package: " + packageName + ", name: " + appName);
// Skip exluded package
// Skip excluded package
Debug.LogFormat("Skipping Excluded [{0}] Package: {1}, name: {2}", i, packageName, appName);
continue;
}
if (!config.show2D)
{
var is2D = currentActivity.Call<bool>("is2DApp", i);
if (is2D)
{
// Skip 2D apps
Debug.LogFormat("Skipping 2D [{0}] Package: {1}, name: {2}", i, packageName, appName);
continue;
}
}
packageNameToAppName.Add(packageName, (i, appName));
Debug.Log("[" + i + "] package: " + packageName + ", name: " + appName);
yield return null;
@@ -291,7 +301,7 @@ namespace QuestAppLauncher
foreach (var app in packageNameToAppName.OrderBy(key => key.Value.AppName))
{
// Create new instances of our app info prefab
var newObj = (GameObject)Instantiate(prefab, gridContent.transform);
var newObj = (GameObject)Instantiate(this.prefab, this.gridContent.transform);
// Set app entry info
var appEntry = newObj.GetComponent("AppEntry") as AppEntry;
+43 -14
View File
@@ -18,6 +18,7 @@ namespace QuestAppLauncher
public GameObject gridRows;
public GameObject gridRowsText;
public GameObject gridPopulation;
public GameObject show2DToggle;
private Config config = new Config();
@@ -43,12 +44,15 @@ namespace QuestAppLauncher
var rowsText = this.gridRowsText.GetComponent<TextMeshProUGUI>();
rowsText.text = string.Format("{0} Rows", this.config.gridSize.rows);
// Set 2D toggle
this.show2DToggle.GetComponent<Toggle>().SetIsOnWithoutNotify(this.config.show2D);
}
public void CloseSettings()
{
// Resize grid if necessary
ResizeGrid();
// Persist any config changes
PersistConfig();
Debug.Log("Close Settings");
this.gridContainer.SetActive(true);
@@ -77,27 +81,52 @@ namespace QuestAppLauncher
rowsText.text = string.Format("{0} Rows", rows);
}
private void ResizeGrid()
private void PersistConfig()
{
bool saveConfig = false;
bool resizeGrid = false;
bool rePopulate = false;
// Update grid size
var cols = (int)gridCols.GetComponent<Slider>().value;
var rows = (int)gridRows.GetComponent<Slider>().value;
if (cols == this.config.gridSize.cols &&
rows == this.config.gridSize.rows)
if (cols != this.config.gridSize.cols ||
rows != this.config.gridSize.rows)
{
// Nothing was resized, so no work to do
return;
this.config.gridSize.cols = cols;
this.config.gridSize.rows = rows;
resizeGrid = true;
saveConfig = true;
}
Debug.Log(string.Format("Resizing grid: {0} x {1}", cols, rows));
// Update 2D toggle
var show2D = this.show2DToggle.GetComponent<Toggle>().isOn;
if (show2D != this.config.show2D)
{
this.config.show2D = show2D;
saveConfig = true;
rePopulate = true;
}
// Update configuration
this.config.gridSize.cols = cols;
this.config.gridSize.rows = rows;
ConfigPersistence.SaveConfig(this.config);
if (saveConfig)
{
// Persist configuration
ConfigPersistence.SaveConfig(this.config);
}
// Update grid size
this.gridPopulation.GetComponent<GridPopulation>().SetGridSize(this.config.gridSize.rows, this.config.gridSize.cols);
if (rePopulate)
{
// Re-populate grid
Debug.Log("Re-populating panel");
this.gridPopulation.GetComponent<GridPopulation>().StartPopulate();
}
else if (resizeGrid)
{
// Update grid size
Debug.Log(string.Format("Resizing pael: {0} x {1}", cols, rows));
this.gridPopulation.GetComponent<GridPopulation>().SetGridSize(this.config.gridSize.rows, this.config.gridSize.cols);
}
}
}
}