Example #1
0
        /// <summary>
        /// Populate the grid from installed apps
        /// </summary>
        /// <returns></returns>
        private async Task PopulateAsync()
        {
            // Load configuration
            Config config = new Config();

            ConfigPersistence.LoadConfig(config);

            // Process apps in background
            var apps = await Task.Run(() =>
            {
                AndroidJNI.AttachCurrentThread();

                try
                {
                    return(AppProcessor.ProcessApps(config));
                }
                finally
                {
                    AndroidJNI.DetachCurrentThread();
                }
            });

            // Populate the panel content
            await PopulatePanelContentAsync(config, apps);
        }
Example #2
0
        public async void OnSelected(Transform t)
        {
            var appEntry = t.gameObject.GetComponent("AppEntry") as AppEntry;

            if (null != appEntry)
            {
                if (appEntry.isRenameMode)
                {
                    this.renameHandler.Rename(appEntry);
                }
                else
                {
                    await Task.Run(() =>
                    {
                        AndroidJNI.AttachCurrentThread();

                        try
                        {
                            // Launch app
                            Debug.Log("Launching: " + appEntry.appName + " (package id: " + appEntry.packageId + ")");
                            AppProcessor.LaunchApp(appEntry.packageId);
                        }
                        finally
                        {
                            AndroidJNI.DetachCurrentThread();
                        }
                    });
                }
            }
        }
        public void DeleteExcludedApksFile()
        {
            Debug.Log("Delete Excluded App List");

            if (!this.deletedHiddenAppsFile)
            {
                this.deletedHiddenAppsFile = AppProcessor.DeleteExcludedAppsFile();
            }
        }
Example #4
0
        public void DeleteRenameFiles()
        {
            Debug.Log("Delete Rename files");

            if (!this.deletedRenameFiles)
            {
                this.deletedRenameFiles = AppProcessor.DeleteRenameFiles();
            }
        }
Example #5
0
        public async void OnOk()
        {
            // Add package name to excluded file
            Debug.Log("Hiding: " + this.appEntryToHide.appName + " (package id: " + this.appEntryToHide.packageId + ")");
            AppProcessor.AddAppToExcludedFile(this.appEntryToHide.packageId);

            // Reload the scene - this will force all the tabs to update
            await SceneManager.LoadSceneAsync(SceneManager.GetActiveScene().name);
        }
Example #6
0
        private async Task AddCellToGridAsync(ProcessedApp app, Transform transform, bool isRenameMode = false)
        {
            if (app.Index == -1 && string.IsNullOrEmpty(app.IconPath))
            {
                // If we have neither app index or icon path, skip this
                return;
            }

            // Get app icon in background
            var bytesIcon = await Task.Run(() =>
            {
                AndroidJNI.AttachCurrentThread();

                try
                {
                    return(AppProcessor.GetAppIcon(app.IconPath, app.Index));
                }
                finally
                {
                    AndroidJNI.DetachCurrentThread();
                }
            });

            // Create new instances of our app info prefabCell
            var newObj = (GameObject)Instantiate(this.prefabCell, transform);

            // Set app entry info
            var appEntry = newObj.GetComponent <AppEntry>();

            appEntry.packageId         = app.PackageName;
            appEntry.appName           = app.AppName;
            appEntry.isRenameMode      = isRenameMode;
            appEntry.installedApkIndex = app.Index;
            appEntry.externalIconPath  = app.IconPath;

            // Set the icon image
            if (null != bytesIcon)
            {
                var texture = new Texture2D(2, 2, TextureFormat.RGBA32, false);
                texture.filterMode = FilterMode.Trilinear;
                texture.anisoLevel = 16;
                texture.LoadImage(bytesIcon);
                var rect  = new Rect(0, 0, texture.width, texture.height);
                var image = appEntry.sprite.GetComponent <Image>();
                image.sprite = Sprite.Create(texture, rect, new Vector2(0.5f, 0.5f));

                // Preserve icon's aspect ratio
                var aspectRatioFitter = appEntry.sprite.GetComponent <AspectRatioFitter>();
                aspectRatioFitter.aspectRatio = (float)texture.width / (float)texture.height;
            }

            // Set app name in text
            appEntry.text.text = app.AppName;
        }
        public void OnSelected(Transform t)
        {
            var appEntry = t.gameObject.GetComponent("AppEntry") as AppEntry;

            if (null != appEntry)
            {
                // Launch app
                Debug.Log("Launching: " + appEntry.appName + " (package id: " + appEntry.packageId + ")");
                AppProcessor.LaunchApp(appEntry.packageId);
            }
        }
        public void OnSelectedPressedBorY(Transform t)
        {
            var appEntry = t.gameObject.GetComponent("AppEntry") as AppEntry;

            if (null != appEntry)
            {
                // Add package name to excluded file
                Debug.Log("Hiding: " + appEntry.appName + " (package id: " + appEntry.packageId + ")");
                AppProcessor.AddAppToExcludedFile(appEntry.packageId);

                // Remove ourselves from the gridview
                Destroy(t.gameObject);
            }
        }
Example #9
0
        private async Task AddCellToGridAsync(ProcessedApp app, Transform transform)
        {
            // Get app icon in background
            var bytesIcon = await Task.Run(() =>
            {
                AndroidJNI.AttachCurrentThread();

                try
                {
                    return(AppProcessor.GetAppIcon(app.IconPath, app.Index));
                }
                finally
                {
                    AndroidJNI.DetachCurrentThread();
                }
            });

            // Create new instances of our app info prefabCell
            var newObj = (GameObject)Instantiate(this.prefabCell, transform);

            // Set app entry info
            var appEntry = newObj.GetComponent("AppEntry") as AppEntry;

            appEntry.packageId = app.PackageName;
            appEntry.appName   = app.AppName;

            // Set the icon image
            if (null != bytesIcon)
            {
                var image   = newObj.transform.Find("AppIcon").GetComponentInChildren <Image>();
                var texture = new Texture2D(2, 2, TextureFormat.RGB24, false);
                texture.filterMode = FilterMode.Trilinear;
                texture.anisoLevel = 16;
                texture.LoadImage(bytesIcon);
                var rect = new Rect(0, 0, texture.width, texture.height);
                image.sprite = Sprite.Create(texture, rect, new Vector2(0.5f, 0.5f));
            }

            // Set app name in text
            var text = newObj.transform.Find("AppName").GetComponentInChildren <TextMeshProUGUI>();

            text.text = app.AppName;
        }
        /// <summary>
        /// Populate the grid from installed apps
        /// </summary>
        /// <returns></returns>
        private async Task PopulateAsync(bool isRenameMode = false)
        {
            // Load configuration
            var config = ConfigPersistence.LoadConfig();

            // Set skybox
            if (!isRenameMode)
            {
                this.skyboxHandler.SetSkybox(config.background);
            }

            // Process apps in background
            var apps = await Task.Run(() =>
            {
                AndroidJNI.AttachCurrentThread();

                try
                {
                    return(AppProcessor.ProcessApps(config, isRenameMode));
                }
                finally
                {
                    AndroidJNI.DetachCurrentThread();
                }
            });

            // Download updates in the background
            if (!isRenameMode && config.autoUpdate && !GlobalState.Instance.CheckedForUpdate)
            {
                GlobalState.Instance.CheckedForUpdate = true;
                AssetsDownloader.DownloadAssetsAsync(config, this.downloadStatusIndicator);
            }

            // Populate the panel content
            if (!isRenameMode)
            {
                await PopulatePanelContentAsync(config, apps);
            }
            else
            {
                await PopulateRenamePanelContentAsync(config, apps);
            }
        }
Example #11
0
        public async Task LoadIcon()
        {
            var result = await AppProcessor.GetAppIconAsync(this.externalIconPath, this.installedApkIndex, 1024 * 1024);

            var image       = result.Item1;
            var imageWidth  = result.Item2;
            var imageHeight = result.Item3;

            Texture2D texture = null;

            if (null == image)
            {
                Debug.LogFormat("Error loading icon: Path: {0}, Index: {1}", this.externalIconPath, this.installedApkIndex);
                return;
            }

            // Set the icon image
            if (imageWidth == 0 || imageHeight == 0)
            {
                texture            = new Texture2D(2, 2, TextureFormat.RGBA32, false);
                texture.filterMode = FilterMode.Trilinear;
                texture.anisoLevel = 16;
                texture.LoadImage(image);
            }
            else
            {
                texture            = new Texture2D(imageWidth, imageHeight, TextureFormat.ARGB32, false);
                texture.filterMode = FilterMode.Trilinear;
                texture.anisoLevel = 16;
                texture.LoadRawTextureData(image);
                texture.Apply();
            }

            var rect = new Rect(0, 0, texture.width, texture.height);

            this.image.sprite = Sprite.Create(texture, rect, new Vector2(0.5f, 0.5f));
            this.image.color  = Color.white;

            // Preserve icon's aspect ratio
            this.aspectRatioFitter.aspectRatio = (float)texture.width / (float)texture.height;
        }
        /// <summary>
        /// Sets the skybox. Supports either equirectangular or cubemap, auto chosen based on aspect ratio.
        /// </summary>
        /// <param name="skyboxPath">Path to skybox image</param>
        /// <returns></returns>
        public async Task SetSkybox(string skyboxPath)
        {
            Debug.LogFormat("Setting skybox to '{0}'", skyboxPath);

            if (null == this.defaultSkybox)
            {
                // Save off the default skybox
                this.defaultSkybox = RenderSettings.skybox;
            }

            if (IsDefaultSkybox(skyboxPath))
            {
                if (RenderSettings.skybox == this.defaultSkybox)
                {
                    // Skip if skybox is already the default
                    Debug.LogFormat("Skybox already default, skipping.");
                    return;
                }

                // Set default skybox
                SetDefaultSkybox();
                return;
            }

            // Destroy existing skybox
            if (null != RenderSettings.skybox && RenderSettings.skybox != this.defaultSkybox)
            {
                // Destroy texture
                var oldTexture = RenderSettings.skybox.GetTexture("_Tex");
                if (null != oldTexture)
                {
                    DestroyImmediate(oldTexture);
                }

                // Destroy material
                DestroyImmediate(RenderSettings.skybox);
                RenderSettings.skybox = null;
            }

            // Read the image
            var result = await AppProcessor.LoadRawImageAsync(MakeAbsoluteSkymapPath(skyboxPath), MaxPixels, true);

            var image       = result.Item1;
            var imageWidth  = result.Item2;
            var imageHeight = result.Item3;

            if (null == image)
            {
                // Fall back to default skybox
                SetDefaultSkybox();
                return;
            }

            Texture2D texture        = null;
            Material  material       = null;
            bool      destroyTexture = false;

            try
            {
                // Load the image into a 2D texture. We decode in background thread (above) in Java and load the raw image here
                // because Texture2D.LoadImage on the main thread can cause significant freezes since it is not async.
                texture            = new Texture2D(imageWidth, imageHeight, TextureFormat.ARGB32, false);
                texture.filterMode = FilterMode.Trilinear;
                texture.anisoLevel = 16;
                texture.LoadRawTextureData(image);
                texture.Apply();

                if (4 * texture.height == 3 * texture.width)
                {
                    // Texture is a horizontal cross cube map (4:3 aspect ratio).
                    // Load cubemap shader. Also rotate x-axis by 180 degrees to compensate for platform-specific rendering differences
                    // (see https://docs.unity3d.com/Manual/SL-PlatformDifferences.html).
                    Debug.LogFormat("Setting horizontal-cross cubemap skybox");
                    destroyTexture = true;
                    material       = new Material(Shader.Find("skybox/cube"));
                    material.SetTexture("_Tex", CubemapFromHorizCrossTexture2D(texture));
                }
                else if (6 * texture.height == texture.width)
                {
                    // Texture is a horizontal cube map (6:1 aspect ratio).
                    // Load cubemap shader. Also rotate x-axis by 180 degrees to compensate for platform-specific rendering differences
                    // (see https://docs.unity3d.com/Manual/SL-PlatformDifferences.html).
                    Debug.LogFormat("Setting horizontal cubemap skybox");
                    destroyTexture = true;
                    material       = new Material(Shader.Find("skybox/cube"));
                    material.SetTexture("_Tex", CubemapFromHorizTexture2D(texture));
                }
                else
                {
                    // Texture is equirectangular
                    Debug.LogFormat("Setting equirectangular skybox");
                    material = new Material(Shader.Find("skybox/equirectangular"));
                    material.SetTexture("_Tex", texture);
                }

                RenderSettings.skybox = material;
                DynamicGI.UpdateEnvironment();
            }
            catch (Exception e)
            {
                // Fall back to default skybox
                Debug.LogFormat("Exception: {0}", e.Message);
                SetDefaultSkybox();
            }
            finally
            {
                if (destroyTexture && null != texture)
                {
                    DestroyImmediate(texture);
                }
            }
        }