Mercurial > cgi-bin > hgweb.cgi > SimpleResizer
view app/src/main/java/com/bartsent/simpleresizer/MainActivity.kt @ 10:5626557ac542 memo
Add progress bar and a worker thread. Still way slow.
author | David Barts <n5jrn@me.com> |
---|---|
date | Wed, 17 Feb 2021 13:39:50 -0800 |
parents | 247e03baf77c |
children | 20da616dcda0 |
line wrap: on
line source
package com.bartsent.simpleresizer import android.app.Activity import android.content.Intent import android.os.Bundle import android.widget.Toast import androidx.appcompat.app.AppCompatActivity import com.bartsent.simpleresizer.databinding.ActivityMainBinding class MainActivity : AppCompatActivity() { val GET_IMAGE = 1 private lateinit var binding: ActivityMainBinding private var showChooser = true override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) binding = ActivityMainBinding.inflate(layoutInflater) setContentView(binding.root) } override fun onResume() { super.onResume() if (showChooser) { Intent(Intent.ACTION_GET_CONTENT).run { type = "image/*" addCategory(Intent.CATEGORY_OPENABLE) startActivityForResult(this, GET_IMAGE) } } else { showChooser = true } } override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { showChooser = false super.onActivityResult(requestCode, resultCode, data) if (requestCode == GET_IMAGE) { val imageUri = data?.data if (resultCode == Activity.RESULT_OK && imageUri != null) { Intent(Intent.ACTION_SEND, imageUri, this, EditImage::class.java).run { startActivity(this) } } else { Toast.makeText(applicationContext, "Unable to get image!", Toast.LENGTH_LONG).show() } } } }