| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| /* | ||
| * Copyright 2020 The Android Open Source Project | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * https://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package com.example.compose.jetsurvey.survey | ||
|
|
||
| import android.content.ContentValues | ||
| import android.content.Context | ||
| import android.provider.MediaStore | ||
|
|
||
| /** | ||
| * Manages the creation of photo Uris. The Uri is used to store the photos taken with camera. | ||
| */ | ||
| class PhotoUriManager(private val appContext: Context) { | ||
|
|
||
| private val photoCollection by lazy { | ||
| MediaStore.Images.Media.getContentUri(MediaStore.VOLUME_EXTERNAL_PRIMARY) | ||
| } | ||
|
|
||
| private val resolver by lazy { appContext.contentResolver } | ||
|
|
||
| fun buildNewUri() = resolver.insert(photoCollection, buildPhotoDetails()) | ||
|
|
||
| private fun buildPhotoDetails() = ContentValues().apply { | ||
| put(MediaStore.Images.Media.DISPLAY_NAME, generateFilename()) | ||
| put(MediaStore.Images.Media.MIME_TYPE, "image/jpeg") | ||
| } | ||
|
|
||
| /** | ||
| * Create a unique file name based on the time the photo is taken | ||
| */ | ||
| private fun generateFilename() = "selfie-${System.currentTimeMillis()}.jpg" | ||
| } |
| Back | FazBrowse Home | New Git URL |
Uh oh!
There was an error while loading. Please reload this page.