forked from SmartToolFactory/Compose-Cropper
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This reverts commit ce1aaa2.
- Loading branch information
Showing
59 changed files
with
3,873 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
plugins { | ||
id 'com.android.application' | ||
id 'org.jetbrains.kotlin.android' | ||
} | ||
|
||
android { | ||
namespace 'com.smarttoolfactory.composecropper' | ||
compileSdk 33 | ||
|
||
defaultConfig { | ||
applicationId "com.smarttoolfactory.composecropper" | ||
minSdk 21 | ||
targetSdk 33 | ||
versionCode 1 | ||
versionName "1.0" | ||
|
||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" | ||
vectorDrawables { | ||
useSupportLibrary true | ||
} | ||
} | ||
|
||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
compileOptions { | ||
sourceCompatibility JavaVersion.VERSION_1_8 | ||
targetCompatibility JavaVersion.VERSION_1_8 | ||
} | ||
kotlinOptions { | ||
jvmTarget = '1.8' | ||
} | ||
buildFeatures { | ||
compose true | ||
} | ||
composeOptions { | ||
kotlinCompilerExtensionVersion = "1.2.0-rc02" | ||
} | ||
packagingOptions { | ||
resources { | ||
excludes += '/META-INF/{AL2.0,LGPL2.1}' | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
|
||
implementation project(':cropper') | ||
|
||
implementation 'androidx.core:core-ktx:1.9.0' | ||
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.5.1' | ||
|
||
// Colorful Customizable Sliders | ||
implementation 'com.github.SmartToolFactory:Compose-Colorful-Sliders:1.1.0' | ||
// Color picker | ||
implementation 'com.github.SmartToolFactory:Compose-Color-Picker-Bundle:1.0.1' | ||
// Gestures | ||
implementation 'com.github.SmartToolFactory:Compose-Extended-Gestures:2.1.0' | ||
// Animated List | ||
implementation 'com.github.SmartToolFactory:Compose-AnimatedList:0.5.1' | ||
|
||
implementation "androidx.compose.ui:ui:$compose_version" | ||
// Tooling support (Previews, etc.) | ||
implementation "androidx.compose.ui:ui-tooling:$compose_version" | ||
// Foundation (Border, Background, Box, Image, Scroll, shapes, animations, etc.) | ||
implementation "androidx.compose.foundation:foundation:$compose_version" | ||
// Material Design | ||
implementation "androidx.compose.material:material:$compose_version" | ||
// Material design icons | ||
implementation "androidx.compose.material:material-icons-core:$compose_version" | ||
implementation "androidx.compose.material:material-icons-extended:$compose_version" | ||
// Integration with activities | ||
implementation 'androidx.activity:activity-compose:1.6.1' | ||
// Integration with ViewModels | ||
implementation 'androidx.lifecycle:lifecycle-viewmodel-compose:2.5.1' | ||
|
||
// Material Design 3 for Compose | ||
implementation "androidx.compose.material3:material3:1.0.0" | ||
|
||
def nav_compose_version = "2.5.3" | ||
implementation "androidx.navigation:navigation-compose:$nav_compose_version" | ||
|
||
def accompanist_version = "0.25.0" | ||
// Accompanist | ||
implementation "com.google.accompanist:accompanist-systemuicontroller:$accompanist_version" | ||
implementation "com.google.accompanist:accompanist-pager:$accompanist_version" | ||
implementation "com.google.accompanist:accompanist-drawablepainter:$accompanist_version" | ||
|
||
// Coil | ||
implementation("io.coil-kt:coil-compose:2.1.0") | ||
|
||
// Photo Picker | ||
implementation("com.google.modernstorage:modernstorage-photopicker:1.0.0-alpha06") | ||
|
||
testImplementation 'junit:junit:4.13.2' | ||
androidTestImplementation 'androidx.test.ext:junit:1.1.3' | ||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' | ||
androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_version" | ||
debugImplementation "androidx.compose.ui:ui-tooling:$compose_version" | ||
debugImplementation "androidx.compose.ui:ui-test-manifest:$compose_version" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Add project specific ProGuard rules here. | ||
# You can control the set of applied configuration files using the | ||
# proguardFiles setting in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} | ||
|
||
# Uncomment this to preserve the line number information for | ||
# debugging stack traces. | ||
#-keepattributes SourceFile,LineNumberTable | ||
|
||
# If you keep the line number information, uncomment this to | ||
# hide the original source file name. | ||
#-renamesourcefileattribute SourceFile |
24 changes: 24 additions & 0 deletions
24
app/src/androidTest/java/com/smarttoolfactory/composecropper/ExampleInstrumentedTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.smarttoolfactory.composecropper | ||
|
||
import androidx.test.platform.app.InstrumentationRegistry | ||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
|
||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
||
import org.junit.Assert.* | ||
|
||
/** | ||
* Instrumented test, which will execute on an Android device. | ||
* | ||
* See [testing documentation](http://d.android.com/tools/testing). | ||
*/ | ||
@RunWith(AndroidJUnit4::class) | ||
class ExampleInstrumentedTest { | ||
@Test | ||
fun useAppContext() { | ||
// Context of the app under test. | ||
val appContext = InstrumentationRegistry.getInstrumentation().targetContext | ||
assertEquals("com.smarttoolfactory.composecropper", appContext.packageName) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools"> | ||
|
||
<application | ||
android:allowBackup="true" | ||
android:dataExtractionRules="@xml/data_extraction_rules" | ||
android:fullBackupContent="@xml/backup_rules" | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="@string/app_name" | ||
android:roundIcon="@mipmap/ic_launcher_round" | ||
android:supportsRtl="true" | ||
android:theme="@style/Theme.ComposeCropper" | ||
tools:targetApi="31"> | ||
<activity | ||
android:name=".MainActivity" | ||
android:exported="true" | ||
android:label="@string/app_name" | ||
android:theme="@style/Theme.ComposeCropper"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
|
||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
|
||
<meta-data | ||
android:name="android.app.lib_name" | ||
android:value="" /> | ||
</activity> | ||
</application> | ||
|
||
</manifest> |
59 changes: 59 additions & 0 deletions
59
app/src/main/java/com/smarttoolfactory/composecropper/ImageSelectionButton.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package com.smarttoolfactory.composecropper | ||
|
||
import android.annotation.SuppressLint | ||
import android.graphics.Bitmap | ||
import android.graphics.ImageDecoder | ||
import android.os.Build | ||
import android.provider.MediaStore | ||
import androidx.activity.compose.rememberLauncherForActivityResult | ||
import androidx.compose.material.Icon | ||
import androidx.compose.material.icons.Icons | ||
import androidx.compose.material.icons.filled.Add | ||
import androidx.compose.material3.FloatingActionButton | ||
import androidx.compose.material3.FloatingActionButtonDefaults | ||
import androidx.compose.material3.FloatingActionButtonElevation | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.graphics.ImageBitmap | ||
import androidx.compose.ui.graphics.asImageBitmap | ||
import androidx.compose.ui.platform.LocalContext | ||
import com.google.modernstorage.photopicker.PhotoPicker | ||
|
||
@SuppressLint("UnsafeOptInUsageError") | ||
@Composable | ||
fun ImageSelectionButton( | ||
elevation: FloatingActionButtonElevation = FloatingActionButtonDefaults.elevation(), | ||
onImageSelected: (ImageBitmap) -> Unit | ||
) { | ||
val context = LocalContext.current | ||
|
||
val photoPicker = | ||
rememberLauncherForActivityResult(PhotoPicker()) { uris -> | ||
val uri = uris.firstOrNull() ?: return@rememberLauncherForActivityResult | ||
|
||
val bitmap: Bitmap = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { | ||
ImageDecoder.decodeBitmap( | ||
ImageDecoder.createSource(context.contentResolver, uri) | ||
) { decoder, info, source -> | ||
decoder.allocator = ImageDecoder.ALLOCATOR_SOFTWARE | ||
decoder.isMutableRequired = true | ||
} | ||
} else { | ||
MediaStore.Images.Media.getBitmap(context.contentResolver, uri) | ||
} | ||
|
||
onImageSelected(bitmap.asImageBitmap()) | ||
|
||
} | ||
|
||
FloatingActionButton( | ||
elevation = elevation, | ||
onClick = { | ||
photoPicker.launch(PhotoPicker.Args(PhotoPicker.Type.IMAGES_ONLY, 1)) | ||
}, | ||
) { | ||
Icon( | ||
imageVector = Icons.Default.Add, | ||
contentDescription = null | ||
) | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
app/src/main/java/com/smarttoolfactory/composecropper/MainActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.smarttoolfactory.composecropper | ||
|
||
import android.os.Bundle | ||
import androidx.activity.ComponentActivity | ||
import androidx.activity.compose.setContent | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.material3.MaterialTheme | ||
import androidx.compose.material3.Surface | ||
import androidx.compose.ui.Modifier | ||
import com.smarttoolfactory.composecropper.demo.ImageCropDemo | ||
import com.smarttoolfactory.composecropper.ui.theme.ComposeCropperTheme | ||
|
||
class MainActivity : ComponentActivity() { | ||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContent { | ||
ComposeCropperTheme { | ||
// A surface container using the 'background' color from the theme | ||
Surface( | ||
modifier = Modifier.fillMaxSize(), | ||
color = MaterialTheme.colorScheme.background | ||
) { | ||
Column { | ||
ImageCropDemo() | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.