Skip to content

Commit edc773b

Browse files
committed
feat: Drawing function
fix: Camera permission error(temp file) fix: resized ratio of image on PhotoEditor fix: LiveData image bitmap issue version: 1.1.6
1 parent 6223144 commit edc773b

File tree

13 files changed

+98
-13
lines changed

13 files changed

+98
-13
lines changed

.idea/deploymentTargetDropDown.xml

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ android {
3030
applicationId "com.coupleblog"
3131
minSdk 21
3232
targetSdk 30
33-
versionCode 115
34-
versionName "1.1.5"
33+
versionCode 116
34+
versionName "1.1.6"
3535
archivesBaseName = "${rootProject.name}-${versionName}"
3636
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
3737
}

app/src/main/java/com/coupleblog/CB_PhotoEditorActivity.kt

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ package com.coupleblog
22

33
import android.graphics.Bitmap
44
import android.graphics.Color
5+
import android.graphics.Matrix
56
import android.graphics.Typeface
67
import android.os.Bundle
8+
import android.util.Log
79
import android.view.*
810
import android.view.animation.AnticipateOvershootInterpolator
911
import androidx.constraintlayout.widget.ConstraintSet
@@ -111,15 +113,48 @@ class CB_PhotoEditorActivity: CB_BaseActivity(CB_SingleSystemMgr.ACTIVITY_TYPE.P
111113
.build()
112114

113115
mPhotoEditor.setOnPhotoEditorListener(this@CB_PhotoEditorActivity)
116+
}
117+
118+
private fun getResizedBitmap(bm: Bitmap, newWidth: Int): Bitmap? {
119+
val width = bm.width
120+
val height = bm.height
121+
val fWidthRatio = newWidth.toFloat() / width
122+
val matrix = Matrix()
123+
// RESIZE THE BIT MAP
124+
matrix.postScale(fWidthRatio, fWidthRatio - 0.25f)
125+
// RECREATE THE NEW BITMAP
126+
return Bitmap.createBitmap(
127+
bm, 0, 0, width, height,
128+
matrix, false
129+
)
130+
}
131+
132+
override fun onStart() {
133+
super.onStart()
134+
135+
val width = resources.displayMetrics.widthPixels
136+
val height = resources.displayMetrics.heightPixels - CB_AppFunc.convertDpToPixel(250)
114137

115138
// set bitmap to imageView
116139
if(CB_ViewModel.editorBitmap != null)
117140
{
141+
CB_ViewModel.editorBitmap = getResizedBitmap(CB_ViewModel.editorBitmap!!, width)
118142
binding.photoEditorView.source.setImageBitmap(CB_ViewModel.editorBitmap)
119143
}
120144
else
121145
{
122-
binding.photoEditorView.source.setBackgroundResource(R.color.white)
146+
val imageBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888)
147+
imageBitmap.eraseColor(Color.WHITE)
148+
149+
if(imageBitmap == null)
150+
{
151+
Log.e(strTag, "invalid bitmap data")
152+
finish()
153+
return
154+
}
155+
156+
CB_ViewModel.editorBitmap = imageBitmap
157+
binding.photoEditorView.source.setImageBitmap(imageBitmap)
123158
}
124159

125160
mPhotoEditor.setFilterEffect(PhotoFilter.NONE)

app/src/main/java/com/coupleblog/a200photoeditor/shape/ShapeBuilder.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class ShapeBuilder {
5050
}
5151

5252
companion object {
53-
const val DEFAULT_SHAPE_SIZE = 25.0f
53+
const val DEFAULT_SHAPE_SIZE = 5.0f
5454
const val DEFAULT_SHAPE_OPACITY = 255
5555
const val DEFAULT_SHAPE_COLOR = Color.BLACK
5656
}

app/src/main/java/com/coupleblog/base/CB_CameraBaseFragment.kt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,15 @@ abstract class CB_CameraBaseFragment(protected val uploadType: UPLOAD_TYPE,
101101
}
102102
}
103103

104+
fun drawProcess()
105+
{
106+
CB_AppFunc.mainScope.launch {
107+
CB_ViewModel.editorBitmap = null
108+
CB_PhotoEditorActivity.cameraListener = this@CB_CameraBaseFragment
109+
startActivity(Intent(requireActivity(), CB_PhotoEditorActivity::class.java))
110+
}
111+
}
112+
104113
protected fun imageProcess()
105114
{
106115
CB_AppFunc.networkScope.launch {
@@ -169,7 +178,7 @@ abstract class CB_CameraBaseFragment(protected val uploadType: UPLOAD_TYPE,
169178
requireActivity().startService(intent)
170179
}
171180

172-
private fun createTempFile()
181+
fun createTempFile()
173182
{
174183
val strTime = CB_AppFunc.getDateStringForSave()
175184
val storageDir = requireActivity().getExternalFilesDir(Environment.DIRECTORY_PICTURES)

app/src/main/java/com/coupleblog/fragment/mail/CB_NewMailFragment.kt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,13 @@ class CB_NewMailFragment: CB_CameraBaseFragment(UPLOAD_TYPE.EMAIL_IMAGE, bDeferr
9999
callback =
100100
{
101101
Log.i(strTag, "no image")
102-
CB_ViewModel.mailImage.postValue(null)
102+
CB_ViewModel.postImage.postValue(null)
103+
binding.postImageView.setImageBitmap(null)
103104
}),
104105
DialogItem(getString(R.string.str_camera), R.drawable.camera,
105106
callback =
106107
{
108+
super.createTempFile()
107109
Log.i(strTag, "camera")
108110
cameraLauncher.launch(imageUri)
109111
}),
@@ -112,7 +114,13 @@ class CB_NewMailFragment: CB_CameraBaseFragment(UPLOAD_TYPE.EMAIL_IMAGE, bDeferr
112114
{
113115
Log.i(strTag, "gallery")
114116
galleryLauncher.launch("image/*")
115-
})
117+
}),
118+
DialogItem(getString(R.string.str_drawing), R.drawable.pencil,
119+
callback =
120+
{
121+
Log.i(strTag, "draw")
122+
drawProcess()
123+
}),
116124
)
117125

118126
CB_ItemListDialog(requireActivity(), getString(R.string.str_add_image), listItem, true)

app/src/main/java/com/coupleblog/fragment/post/CB_NewPostFragment.kt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,11 +191,13 @@ class CB_NewPostFragment: CB_CameraBaseFragment(UPLOAD_TYPE.POST_IMAGE, bDeferre
191191
{
192192
Log.i(strTag, "no image")
193193
CB_ViewModel.postImage.postValue(null)
194+
binding.postImageView.setImageBitmap(null)
194195
bImageChanged = true
195196
}),
196197
DialogItem(getString(R.string.str_camera), R.drawable.camera,
197198
callback =
198199
{
200+
super.createTempFile()
199201
Log.i(strTag, "camera")
200202
cameraLauncher.launch(imageUri)
201203
}),
@@ -204,7 +206,13 @@ class CB_NewPostFragment: CB_CameraBaseFragment(UPLOAD_TYPE.POST_IMAGE, bDeferre
204206
{
205207
Log.i(strTag, "gallery")
206208
galleryLauncher.launch("image/*")
207-
})
209+
}),
210+
DialogItem(getString(R.string.str_drawing), R.drawable.pencil,
211+
callback =
212+
{
213+
Log.i(strTag, "draw")
214+
drawProcess()
215+
}),
208216
)
209217

210218
CB_ItemListDialog(requireActivity(), getString(R.string.str_add_image), listItem, true)

app/src/main/java/com/coupleblog/fragment/profile/CB_EditProfileFragment.kt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ class CB_EditProfileFragment : CB_CameraBaseFragment(UPLOAD_TYPE.PROFILE_IMAGE)
9090
DialogItem(getString(R.string.str_camera), R.drawable.camera,
9191
callback =
9292
{
93+
super.createTempFile()
9394
Log.i(strTag, "camera")
9495
cameraLauncher.launch(imageUri)
9596
}),
@@ -98,7 +99,13 @@ class CB_EditProfileFragment : CB_CameraBaseFragment(UPLOAD_TYPE.PROFILE_IMAGE)
9899
{
99100
Log.i(strTag, "gallery")
100101
galleryLauncher.launch("image/*")
101-
})
102+
}),
103+
DialogItem(getString(R.string.str_drawing), R.drawable.pencil,
104+
callback =
105+
{
106+
Log.i(strTag, "draw")
107+
drawProcess()
108+
}),
102109
)
103110

104111
CB_ItemListDialog(requireActivity(), getString(R.string.str_change_profile_image), listItem, true)

app/src/main/res/layout/activity_photo_editor.xml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,11 @@
110110
<androidx.recyclerview.widget.RecyclerView
111111
android:id="@+id/rvConstraintTools"
112112
android:layout_width="0dp"
113-
android:layout_height="wrap_content"
113+
android:layout_height="90dp"
114114
bind:layout_manager="@{llmTools}"
115115
bind:adapter="@{toolsAdapter}"
116116
android:background="@color/tool_bg"
117117
android:orientation="horizontal"
118-
android:paddingTop="4dp"
119-
android:paddingBottom="4dp"
120118
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
121119
app:layout_constraintBottom_toTopOf="@+id/guideline"
122120
app:layout_constraintEnd_toEndOf="parent"

0 commit comments

Comments
 (0)