Ejemplo n.º 1
0
        private async Task AddCellToGridAsync(ProcessedApp app, Transform transform, bool loadIcon, bool isRenameMode = false)
        {
            if (app.Index == -1 && string.IsNullOrEmpty(app.IconPath))
            {
                // If we have neither app index or icon path, skip this
                return;
            }

            // 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.scrollViewTransform = transform.parent.parent.gameObject.GetComponent <RectTransform>();
            appEntry.packageId           = app.PackageName;
            appEntry.appName             = app.AppName;
            appEntry.isRenameMode        = isRenameMode;
            appEntry.installedApkIndex   = app.Index;
            appEntry.externalIconPath    = app.IconPath;

            // Dynamically load icon if we're not loading the icon now
            appEntry.dynamicallyLoadIcon = !loadIcon;

            // Set the icon image
            if (loadIcon)
            {
                await appEntry.LoadIcon();
            }

            // Set app name in text
            appEntry.text.text = app.AppName;
        }
Ejemplo n.º 2
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;
        }
        private static void ProcessIconsInPath(Dictionary <string, ProcessedApp> apps, string path)
        {
            foreach (var iconFilePath in Directory.GetFiles(path, IconOverrideExtSearch))
            {
                // This is a list of jpg images stored as packageName.jpg.
                var entry = Path.GetFileNameWithoutExtension(iconFilePath);
                if (apps.ContainsKey(entry))
                {
                    Debug.Log("Found icon override: " + iconFilePath);

                    ProcessedApp newProcessedApp = apps[entry];
                    newProcessedApp.IconPath = iconFilePath;
                    apps[entry] = newProcessedApp;
                }
            }
        }
Ejemplo n.º 4
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;
        }
        private static void ProcessAppNameOverrideTxtFile(bool isRenameMode, Dictionary <string, ProcessedApp> apps, string appNameOverrideFilePath)
        {
            // Override app names, if any
            // This is just a file with comma-separated packageName,appName[,category1[, category2]]
            // Category1 and category2 are optional categories (tabs).
            Debug.Log("Found file: " + appNameOverrideFilePath);

            string[] lines = File.ReadAllLines(appNameOverrideFilePath, Encoding.UTF8);
            foreach (string line in lines)
            {
                line.Trim();

                if (line.StartsWith("#"))
                {
                    // Skip comments
                    continue;
                }

                // Parse line
                var entry = line.Split(',');
                if (entry.Length < 2)
                {
                    // We expect at least two entries
                    continue;
                }

                var packageName = entry[0];
                var appName     = entry[1];

                if (!apps.ContainsKey(packageName))
                {
                    // App is not installed
                    if (isRenameMode)
                    {
                        // If rename mode, so just add it
                        apps[packageName] = new ProcessedApp
                        {
                            PackageName = packageName,
                            AppName     = appName,
                        };
                    }

                    continue;
                }

                // Get the custom tab names, if any
                string autoTabName = null;
                var    tab1        = entry.Length > 2 ? entry[2] : null;
                var    tab2        = entry.Length > 3 ? entry[3] : null;

                if (tab1 != null && tab1.Length == 0)
                {
                    tab1 = null;
                }

                if (tab2 != null && tab2.Length == 0)
                {
                    tab2 = null;
                }

                if (tab1 != null && tab2 != null && tab1.Equals(tab2, StringComparison.OrdinalIgnoreCase))
                {
                    tab2 = null;
                }

                // Override auto tab name if custom name matches built-in tab name
                if (tab1 != null && Auto_Tabs.Contains(tab1, StringComparer.OrdinalIgnoreCase))
                {
                    autoTabName = tab1;
                    tab1        = null;
                }

                if (tab2 != null && Auto_Tabs.Contains(tab2, StringComparer.OrdinalIgnoreCase))
                {
                    autoTabName = tab2;
                    tab2        = null;
                }

                // Update entry
                apps[packageName] = new ProcessedApp
                {
                    PackageName  = apps[entry[0]].PackageName,
                    Index        = apps[entry[0]].Index,
                    AppName      = appName,
                    AutoTabName  = autoTabName ?? apps[entry[0]].AutoTabName,
                    Tab1Name     = tab1 ?? apps[entry[0]].Tab1Name,
                    Tab2Name     = tab2 ?? apps[entry[0]].Tab2Name,
                    LastTimeUsed = apps[entry[0]].LastTimeUsed
                };
            }
        }
        private static void ProcessAppNameOverrideJsonFile(bool isRenameMode, Dictionary <string, ProcessedApp> apps, string appNameOverrideFilePath)
        {
            if (isRenameMode && appNameOverrideFilePath.Equals(Path.Combine(UnityEngine.Application.persistentDataPath, RenameJsonFileName),
                                                               StringComparison.InvariantCultureIgnoreCase))
            {
                // In rename mode, so skip the rename json file itself
                return;
            }

            // Override app names, if any
            Debug.Log("Found file: " + appNameOverrideFilePath);

            try
            {
                var json         = File.ReadAllText(appNameOverrideFilePath, Encoding.UTF8);
                var jsonAppNames = JsonConvert.DeserializeObject <Dictionary <string, JsonAppNamesEntry> >(json);

                foreach (var entry in jsonAppNames)
                {
                    var packageName = entry.Key;
                    var appName     = entry.Value.Name;

                    if (!apps.ContainsKey(packageName))
                    {
                        // App is not installed
                        if (isRenameMode)
                        {
                            // If rename mode, just add it
                            apps[packageName] = new ProcessedApp
                            {
                                PackageName = packageName,
                                AppName     = appName,
                            };
                        }

                        continue;
                    }

                    // Get the custom tab names, if any
                    string autoTabName = null;
                    var    tab1        = entry.Value.Category;
                    var    tab2        = entry.Value.Category2;

                    if (tab1 != null && tab1.Length == 0)
                    {
                        tab1 = null;
                    }

                    if (tab2 != null && tab2.Length == 0)
                    {
                        tab2 = null;
                    }

                    if (tab1 != null && tab2 != null && tab1.Equals(tab2, StringComparison.OrdinalIgnoreCase))
                    {
                        tab2 = null;
                    }

                    // Override auto tab name if custom name matches built-in tab name
                    if (tab1 != null && Auto_Tabs.Contains(tab1, StringComparer.OrdinalIgnoreCase))
                    {
                        autoTabName = tab1;
                        tab1        = null;
                    }

                    if (tab2 != null && Auto_Tabs.Contains(tab2, StringComparer.OrdinalIgnoreCase))
                    {
                        autoTabName = tab2;
                        tab2        = null;
                    }

                    // Update entry
                    apps[packageName] = new ProcessedApp
                    {
                        PackageName  = apps[entry.Key].PackageName,
                        Index        = apps[entry.Key].Index,
                        AppName      = appName,
                        AutoTabName  = autoTabName ?? apps[entry.Key].AutoTabName,
                        Tab1Name     = tab1 ?? apps[entry.Key].Tab1Name,
                        Tab2Name     = tab2 ?? apps[entry.Key].Tab2Name,
                        LastTimeUsed = apps[entry.Key].LastTimeUsed
                    };
                }
            }
            catch (Exception e)
            {
                Debug.Log(string.Format("Failed to process json app names: {0}", e.Message));
                return;
            }
        }