Exemplo n.º 1
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;
        }
Exemplo n.º 2
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;
        }