Notes
Notes - notes.io |
import android.R
import android.app.Activity
import android.content.Intent
import android.graphics.Bitmap
import android.net.Uri
import android.os.Bundle
import android.os.Environment
import android.provider.MediaStore
import android.util.Log
import android.view.View
import android.widget.ImageView
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import com.example.myapplication.ui.theme.MyApplicationTheme
import java.io.File
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enableEdgeToEdge()
setContent {
MyApplicationTheme {
Scaffold(modifier = Modifier.fillMaxSize()) { innerPadding ->
Greeting(
name = "Android",
modifier = Modifier.padding(innerPadding)
)
}
}
}
}
}
@Composable
fun Greeting(name: String, modifier: Modifier = Modifier) {
Text(
text = "Hello $name!",
modifier = modifier
)
}
@Preview(showBackground = true)
@Composable
fun GreetingPreview() {
MyApplicationTheme {
Greeting("Android")
}
}
class MainActivity() : Activity() {
var directory: File? = null
val TYPE_PHOTO: Int = 1
val TYPE_VIDEO: Int = 2
val REQUEST_CODE_PHOTO: Int = 1
val REQUEST_CODE_VIDEO: Int = 2
val TAG: String = "myLogs"
var ivPhoto: ImageView? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.main)
createDirectory()
ivPhoto = findViewById<View>(R.id.ivPhoto) as ImageView
}
fun onClickPhoto(view: View?) {
val intent = Intent(MediaStore.ACTION_IMAGE_CAPTURE)
intent.putExtra(MediaStore.EXTRA_OUTPUT, generateFileUri(TYPE_PHOTO))
startActivityForResult(intent, REQUEST_CODE_PHOTO)
}
fun onClickVideo(view: View?) {
val intent = Intent(MediaStore.ACTION_VIDEO_CAPTURE)
intent.putExtra(MediaStore.EXTRA_OUTPUT, generateFileUri(TYPE_VIDEO))
startActivityForResult(intent, REQUEST_CODE_VIDEO)
}
override fun onActivityResult(
requestCode: Int, resultCode: Int,
intent: Intent
) {
if (requestCode == REQUEST_CODE_PHOTO) {
if (resultCode == RESULT_OK) {
if (intent == null) {
Log.d(TAG, "Intent is null")
} else {
Log.d(TAG, "Photo uri: " + intent.data)
val bndl = intent.extras
if (bndl != null) {
val obj = intent.extras!!["data"]
if (obj is Bitmap) {
val bitmap = obj
Log.d(
TAG, "bitmap " + bitmap.width + " x "
+ bitmap.height
)
ivPhoto!!.setImageBitmap(bitmap)
}
}
}
} else if (resultCode == RESULT_CANCELED) {
Log.d(TAG, "Canceled")
}
}
if (requestCode == REQUEST_CODE_VIDEO) {
if (resultCode == RESULT_OK) {
if (intent == null) {
Log.d(TAG, "Intent is null")
} else {
Log.d(TAG, "Video uri: " + intent.data)
}
} else if (resultCode == RESULT_CANCELED) {
Log.d(TAG, "Canceled")
}
}
}
private fun generateFileUri(type: Int): Uri {
var file: File? = null
when (type) {
TYPE_PHOTO -> file = File(
directory!!.path + "/" + "photo_"
+ System.currentTimeMillis() + ".jpg"
)
TYPE_VIDEO -> file = File(
(directory!!.path + "/" + "video_"
+ System.currentTimeMillis() + ".mp4")
)
}
Log.d(TAG, "fileName = $file")
return Uri.fromFile(file)
}
private fun createDirectory() {
directory = File(
Environment
.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES),
"MyFolder"
)
if (!directory!!.exists()) directory!!.mkdirs()
}
![]() |
Notes is a web-based application for online taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000+ notes created and continuing...
With notes.io;
- * You can take a note from anywhere and any device with internet connection.
- * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
- * You can quickly share your contents without website, blog and e-mail.
- * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
- * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.
Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.
Easy: Notes.io doesn’t require installation. Just write and share note!
Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )
Free: Notes.io works for 14 years and has been free since the day it was started.
You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;
Email: [email protected]
Twitter: http://twitter.com/notesio
Instagram: http://instagram.com/notes.io
Facebook: http://facebook.com/notesio
Regards;
Notes.io Team
