代码之家  ›  专栏  ›  技术社区  ›  DarthNoodles

为壁纸选择图像

  •  0
  • DarthNoodles  · 技术社区  · 14 年前

    我正在写一张现场壁纸,需要一些帮助。“我的墙纸”将在用户在“设置…”中选择的其他图像或现有墙纸(而不是其他实时墙纸)上方创建效果。

    任何帮助都将不胜感激。

    1 回复  |  直到 14 年前
        1
  •  0
  •   Kevin Coppock    14 年前

    如果这有帮助的话,我编写了一个文件过滤器,它将返回包含图像的文件夹列表。您只需获取一个表示目录的文件(我将其用于Environment.getExternalStorageDirectory())并使用.listFiles(filterForImageFolders),它将返回一个包含图像的目录的文件[]。然后,您可以使用此列表填充设置中的图像列表:

    FileFilter filterForImageFolders = new FileFilter()
        {           
            public boolean accept(File folder)
            {
                try
                {
                    //Checking only directories, since we are checking for files within
                    //a directory
                    if(folder.isDirectory())
                    {
                        File[] listOfFiles = folder.listFiles();
    
                        if (listOfFiles == null) return false;
    
                        //For each file in the directory...
                        for (File file : listOfFiles)
                        {                           
                            //Check if the extension is one of the supported filetypes                          
                            for (String ext : imageExtensions)
                            {
                                if (file.getName().endsWith("." + ext)) return true;
                            }
                        }                       
                    }
                    return false;
                }
                catch (SecurityException e)
                {
                    Log.v("debug", "Access Denied");
                    return false;
                }
            }
        };