Mercurial > dwindows
comparison android/DWindows.kt @ 2643:28ca1e59e76f
Android: Catch NotFoundException when loading resource...
This allows HandyFTP to start up on Android now, with missing resources.
APIs should return null on failure not throw an exception.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Fri, 13 Aug 2021 22:19:45 +0000 |
parents | 3edc64443b71 |
children | 7101b5692601 |
comparison
equal
deleted
inserted
replaced
2642:3edc64443b71 | 2643:28ca1e59e76f |
---|---|
7 import android.app.NotificationChannel | 7 import android.app.NotificationChannel |
8 import android.app.NotificationManager | 8 import android.app.NotificationManager |
9 import android.content.* | 9 import android.content.* |
10 import android.content.pm.ActivityInfo | 10 import android.content.pm.ActivityInfo |
11 import android.content.res.Configuration | 11 import android.content.res.Configuration |
12 import android.content.res.Resources | |
12 import android.database.Cursor | 13 import android.database.Cursor |
13 import android.graphics.* | 14 import android.graphics.* |
14 import android.graphics.drawable.BitmapDrawable | 15 import android.graphics.drawable.BitmapDrawable |
15 import android.graphics.drawable.Drawable | 16 import android.graphics.drawable.Drawable |
16 import android.graphics.drawable.GradientDrawable | 17 import android.graphics.drawable.GradientDrawable |
2851 { | 2852 { |
2852 var icon: Drawable? = null | 2853 var icon: Drawable? = null |
2853 | 2854 |
2854 waitOnUiThread { | 2855 waitOnUiThread { |
2855 if(resID != 0) { | 2856 if(resID != 0) { |
2856 icon = ResourcesCompat.getDrawable(resources, resID, null) | 2857 try { |
2858 icon = ResourcesCompat.getDrawable(resources, resID, null) | |
2859 } catch(e: Resources.NotFoundException) { | |
2860 } | |
2857 } else if(filename != null) { | 2861 } else if(filename != null) { |
2858 val exts = arrayOf("", ".png", ".webp", ".jpg", ".jpeg", ".gif") | 2862 val exts = arrayOf("", ".png", ".webp", ".jpg", ".jpeg", ".gif") |
2859 | 2863 |
2860 for (ext in exts) { | 2864 for (ext in exts) { |
2861 // Try to load the image, and protect against exceptions | 2865 // Try to load the image, and protect against exceptions |
2865 } catch (e: IOException) { | 2869 } catch (e: IOException) { |
2866 } | 2870 } |
2867 if(icon != null) { | 2871 if(icon != null) { |
2868 break | 2872 break |
2869 } | 2873 } |
2870 | |
2871 } | 2874 } |
2872 } else if(data != null) { | 2875 } else if(data != null) { |
2873 icon = BitmapDrawable(resources, BitmapFactory.decodeByteArray(data, 0, length)) | 2876 icon = BitmapDrawable(resources, BitmapFactory.decodeByteArray(data, 0, length)) |
2874 } | 2877 } |
2875 } | 2878 } |