|
| 1 | +--- |
| 2 | +layout: layout |
| 3 | +title: Just a Flashlight |
| 4 | +--- |
| 5 | + |
| 6 | +A simple flashlight app was one of the first things I downloaded when I got a |
| 7 | +smartphone. The thing has an LED, why shouldn't have a simple way to turn it on |
| 8 | +and off? Of course, the app came with ads. |
| 9 | + |
| 10 | +I've made a few false starts at learning Android. I decided that I should be |
| 11 | +able to handle a flashlight app---after all, it can't be that hard to turn a |
| 12 | +light on and off, right? And then I don't have to sell anyone my attention, even |
| 13 | +for the fraction of a second it takes to ignore the ad completely. |
| 14 | + |
| 15 | +Unfortunately, it hasn't proven easy. Even after I gave up on using the new |
| 16 | +`camera2` interface, I was still adrift in a sea of Java. I found several |
| 17 | +examples online, and tried working from them to various degrees. I'm not sure if |
| 18 | +they were out of date, or they were doing things in a way that doesn't work with |
| 19 | +my phone, or if my customizations were to blame. |
| 20 | + |
| 21 | +Finally, I pared my code down to closely mimic one example, and I got it to |
| 22 | +work! |
| 23 | + |
| 24 | +. . . mostly. It doesn't release the camera, and misbehaves when the phone switches |
| 25 | +between landscape and portrait. I hope most of these problems will be fixed by |
| 26 | +moving code off the main thread. I'll also make it release the camera when the |
| 27 | +light is turned off, instead of in `onDestroy()`. But I still feel accomplished |
| 28 | +whenever I click the light on and off. |
| 29 | + |
| 30 | +My code is [on Github][gh]. |
| 31 | + |
| 32 | +[gh]: https://github.com/JStech/just-a-flashlight |
0 commit comments