Mercurial > cgi-bin > hgweb.cgi > SimpleResizer
comparison app/src/main/java/com/bartsent/simpleresizer/MainActivity.kt @ 31:0023e6013dd9
Complete the deception that is my dummy main activity (hopefully).
author | David Barts <n5jrn@me.com> |
---|---|
date | Fri, 26 Feb 2021 13:24:30 -0800 |
parents | aacf7a856b5f |
children |
comparison
equal
deleted
inserted
replaced
30:aacf7a856b5f | 31:0023e6013dd9 |
---|---|
21 setContentView(binding.root) | 21 setContentView(binding.root) |
22 } | 22 } |
23 | 23 |
24 override fun onResume() { | 24 override fun onResume() { |
25 super.onResume() | 25 super.onResume() |
26 if (showChooser) | 26 if (showChooser) { |
27 doShowChooser() | 27 Intent(Intent.ACTION_GET_CONTENT).run { |
28 else | 28 type = "image/*" |
29 addCategory(Intent.CATEGORY_OPENABLE) | |
30 startActivityForResult(this, GET_IMAGE) | |
31 } | |
32 } else { | |
29 showChooser = true | 33 showChooser = true |
30 } | |
31 | |
32 fun doShowChooser(): Unit { | |
33 Intent(Intent.ACTION_GET_CONTENT).run { | |
34 type = "image/*" | |
35 addCategory(Intent.CATEGORY_OPENABLE) | |
36 startActivityForResult(this, GET_IMAGE) | |
37 } | 34 } |
38 } | 35 } |
39 | 36 |
40 override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { | 37 override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { |
41 showChooser = false | 38 showChooser = false |
44 val imageUri = data?.data | 41 val imageUri = data?.data |
45 if (resultCode == Activity.RESULT_OK && imageUri != null) { | 42 if (resultCode == Activity.RESULT_OK && imageUri != null) { |
46 Intent(Intent.ACTION_SEND, imageUri, this, EditImage::class.java).run { | 43 Intent(Intent.ACTION_SEND, imageUri, this, EditImage::class.java).run { |
47 startActivity(this) | 44 startActivity(this) |
48 } | 45 } |
49 } else { | 46 return |
50 Toast.makeText(applicationContext, "Unable to get image!", Toast.LENGTH_LONG).show() | |
51 doShowChooser() | |
52 } | 47 } |
53 } | 48 } |
49 // If we get here, it means that the user backed out of the file chooser. | |
50 // This should be interpreted as a desire to back out of editing an image | |
51 // altogether. So… goodbye! | |
52 showChooser = true // reset flag (paranoid) | |
53 finish() | |
54 } | 54 } |
55 } | 55 } |