Mercurial > cgi-bin > hgweb.cgi > SimpleResizer
annotate app/src/main/java/com/bartsent/simpleresizer/MainActivity.kt @ 46:8205f3c17500 default tip
Tweak messages a little.
author | David Barts <n5jrn@me.com> |
---|---|
date | Wed, 14 Apr 2021 08:18:23 -0700 |
parents | 0023e6013dd9 |
children |
rev | line source |
---|---|
0
13935000c2d9
Stuff Andriod Studio ignored for some reason.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
1 package com.bartsent.simpleresizer |
13935000c2d9
Stuff Andriod Studio ignored for some reason.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
2 |
15 | 3 import android.annotation.SuppressLint |
0
13935000c2d9
Stuff Andriod Studio ignored for some reason.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
4 import android.app.Activity |
13935000c2d9
Stuff Andriod Studio ignored for some reason.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
5 import android.content.Intent |
2
06825e49f7aa
Got it scaling and rotating, needs settings, etc.
David Barts <n5jrn@me.com>
parents:
0
diff
changeset
|
6 import android.os.Bundle |
15 | 7 import android.util.Log |
2
06825e49f7aa
Got it scaling and rotating, needs settings, etc.
David Barts <n5jrn@me.com>
parents:
0
diff
changeset
|
8 import android.widget.Toast |
0
13935000c2d9
Stuff Andriod Studio ignored for some reason.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
9 import androidx.appcompat.app.AppCompatActivity |
15 | 10 import androidx.preference.PreferenceManager |
0
13935000c2d9
Stuff Andriod Studio ignored for some reason.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
11 import com.bartsent.simpleresizer.databinding.ActivityMainBinding |
13935000c2d9
Stuff Andriod Studio ignored for some reason.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
12 |
13935000c2d9
Stuff Andriod Studio ignored for some reason.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
13 class MainActivity : AppCompatActivity() { |
13935000c2d9
Stuff Andriod Studio ignored for some reason.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
14 val GET_IMAGE = 1 |
13935000c2d9
Stuff Andriod Studio ignored for some reason.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
15 private lateinit var binding: ActivityMainBinding |
3 | 16 private var showChooser = true |
0
13935000c2d9
Stuff Andriod Studio ignored for some reason.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
17 |
13935000c2d9
Stuff Andriod Studio ignored for some reason.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
18 override fun onCreate(savedInstanceState: Bundle?) { |
13935000c2d9
Stuff Andriod Studio ignored for some reason.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
19 super.onCreate(savedInstanceState) |
13935000c2d9
Stuff Andriod Studio ignored for some reason.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
20 binding = ActivityMainBinding.inflate(layoutInflater) |
3 | 21 setContentView(binding.root) |
0
13935000c2d9
Stuff Andriod Studio ignored for some reason.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
22 } |
13935000c2d9
Stuff Andriod Studio ignored for some reason.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
23 |
13935000c2d9
Stuff Andriod Studio ignored for some reason.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
24 override fun onResume() { |
13935000c2d9
Stuff Andriod Studio ignored for some reason.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
25 super.onResume() |
31
0023e6013dd9
Complete the deception that is my dummy main activity (hopefully).
David Barts <n5jrn@me.com>
parents:
30
diff
changeset
|
26 if (showChooser) { |
0023e6013dd9
Complete the deception that is my dummy main activity (hopefully).
David Barts <n5jrn@me.com>
parents:
30
diff
changeset
|
27 Intent(Intent.ACTION_GET_CONTENT).run { |
0023e6013dd9
Complete the deception that is my dummy main activity (hopefully).
David Barts <n5jrn@me.com>
parents:
30
diff
changeset
|
28 type = "image/*" |
0023e6013dd9
Complete the deception that is my dummy main activity (hopefully).
David Barts <n5jrn@me.com>
parents:
30
diff
changeset
|
29 addCategory(Intent.CATEGORY_OPENABLE) |
0023e6013dd9
Complete the deception that is my dummy main activity (hopefully).
David Barts <n5jrn@me.com>
parents:
30
diff
changeset
|
30 startActivityForResult(this, GET_IMAGE) |
0023e6013dd9
Complete the deception that is my dummy main activity (hopefully).
David Barts <n5jrn@me.com>
parents:
30
diff
changeset
|
31 } |
0023e6013dd9
Complete the deception that is my dummy main activity (hopefully).
David Barts <n5jrn@me.com>
parents:
30
diff
changeset
|
32 } else { |
3 | 33 showChooser = true |
0
13935000c2d9
Stuff Andriod Studio ignored for some reason.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
34 } |
13935000c2d9
Stuff Andriod Studio ignored for some reason.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
35 } |
13935000c2d9
Stuff Andriod Studio ignored for some reason.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
36 |
13935000c2d9
Stuff Andriod Studio ignored for some reason.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
37 override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { |
3 | 38 showChooser = false |
0
13935000c2d9
Stuff Andriod Studio ignored for some reason.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
39 super.onActivityResult(requestCode, resultCode, data) |
13935000c2d9
Stuff Andriod Studio ignored for some reason.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
40 if (requestCode == GET_IMAGE) { |
13935000c2d9
Stuff Andriod Studio ignored for some reason.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
41 val imageUri = data?.data |
13935000c2d9
Stuff Andriod Studio ignored for some reason.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
42 if (resultCode == Activity.RESULT_OK && imageUri != null) { |
13935000c2d9
Stuff Andriod Studio ignored for some reason.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
43 Intent(Intent.ACTION_SEND, imageUri, this, EditImage::class.java).run { |
13935000c2d9
Stuff Andriod Studio ignored for some reason.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
44 startActivity(this) |
13935000c2d9
Stuff Andriod Studio ignored for some reason.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
45 } |
31
0023e6013dd9
Complete the deception that is my dummy main activity (hopefully).
David Barts <n5jrn@me.com>
parents:
30
diff
changeset
|
46 return |
0
13935000c2d9
Stuff Andriod Studio ignored for some reason.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
47 } |
13935000c2d9
Stuff Andriod Studio ignored for some reason.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
48 } |
31
0023e6013dd9
Complete the deception that is my dummy main activity (hopefully).
David Barts <n5jrn@me.com>
parents:
30
diff
changeset
|
49 // If we get here, it means that the user backed out of the file chooser. |
0023e6013dd9
Complete the deception that is my dummy main activity (hopefully).
David Barts <n5jrn@me.com>
parents:
30
diff
changeset
|
50 // This should be interpreted as a desire to back out of editing an image |
0023e6013dd9
Complete the deception that is my dummy main activity (hopefully).
David Barts <n5jrn@me.com>
parents:
30
diff
changeset
|
51 // altogether. So… goodbye! |
0023e6013dd9
Complete the deception that is my dummy main activity (hopefully).
David Barts <n5jrn@me.com>
parents:
30
diff
changeset
|
52 showChooser = true // reset flag (paranoid) |
0023e6013dd9
Complete the deception that is my dummy main activity (hopefully).
David Barts <n5jrn@me.com>
parents:
30
diff
changeset
|
53 finish() |
0
13935000c2d9
Stuff Andriod Studio ignored for some reason.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
54 } |
31
0023e6013dd9
Complete the deception that is my dummy main activity (hopefully).
David Barts <n5jrn@me.com>
parents:
30
diff
changeset
|
55 } |