Skip to content

Commit 25420cd

Browse files
committed
QuickPass 2.4.0
- image adding
1 parent 2537fdf commit 25420cd

File tree

5 files changed

+247
-97
lines changed

5 files changed

+247
-97
lines changed

app/src/main/java/com/mikhailgrigorev/quickpass/EditPassActivity.kt

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import android.content.pm.PackageManager
88
import android.content.res.Configuration
99
import android.database.Cursor
1010
import android.database.SQLException
11+
import android.graphics.Point
1112
import android.net.Uri
1213
import android.os.Build
1314
import android.os.Bundle
@@ -53,6 +54,7 @@ class EditPassActivity : AppCompatActivity() {
5354
private var useNumbers = false
5455
private lateinit var login: String
5556
private lateinit var passName: String
57+
private var imageName: String = ""
5658
@SuppressLint("Recycle", "SetTextI18n", "ClickableViewAccessibility")
5759
override fun onCreate(savedInstanceState: Bundle?) {
5860
val pref = getSharedPreferences(_preferenceFile, Context.MODE_PRIVATE)
@@ -587,6 +589,29 @@ class EditPassActivity : AppCompatActivity() {
587589
}
588590
pdbHelper.close()
589591
setResult(1, intent)
592+
593+
val mediaStorageDir = File(
594+
applicationContext.getExternalFilesDir("QuickPassPhotos")!!.absolutePath
595+
)
596+
if (!mediaStorageDir.exists()) {
597+
mediaStorageDir.mkdirs()
598+
Toast.makeText(applicationContext, "Directory Created", Toast.LENGTH_LONG).show()
599+
}
600+
601+
if (!mediaStorageDir.exists()) {
602+
if (!mediaStorageDir.mkdirs()) {
603+
Log.d("App", "failed to create directory")
604+
}
605+
}
606+
607+
if (mediaStorageDir.exists()) {
608+
if(imageName != "") {
609+
val from = File(mediaStorageDir, "$imageName.jpg")
610+
val to = File(mediaStorageDir, "${newNameField.text}.jpg")
611+
if (from.exists()) from.renameTo(to)
612+
}
613+
}
614+
590615
finish()
591616
}
592617
}
@@ -623,12 +648,19 @@ class EditPassActivity : AppCompatActivity() {
623648

624649
val file = File(mediaStorageDir, "$passName.jpg")
625650
if (file.exists()){
651+
imageName = passName
626652
val uri = Uri.fromFile(file)
627653
attachedImage.setImageURI(uri)
628654
clearImage.visibility = View.VISIBLE
629655

630-
val width = attachedImage.drawable.minimumWidth/2
631-
val height = attachedImage.drawable.minimumHeight/2
656+
val display = windowManager.defaultDisplay
657+
val size = Point()
658+
display.getSize(size)
659+
val widthMax: Int = size.x
660+
val width = (widthMax/1.3).toInt()
661+
val height = attachedImage.drawable.minimumHeight * width / attachedImage.drawable.minimumWidth
662+
attachedImage.layoutParams.height = height
663+
attachedImage.layoutParams.width = width
632664
attachedImage.layoutParams.height = height
633665
attachedImage.layoutParams.width = width
634666

@@ -735,8 +767,14 @@ class EditPassActivity : AppCompatActivity() {
735767
if (resultCode == Activity.RESULT_OK && requestCode == IMAGE_PICK_CODE) {
736768
// I'M GETTING THE URI OF THE IMAGE AS DATA AND SETTING IT TO THE IMAGEVIEW
737769
attachedImage.setImageURI(data?.data)
738-
val width = attachedImage.drawable.minimumWidth/2
739-
val height = attachedImage.drawable.minimumHeight/2
770+
val display = windowManager.defaultDisplay
771+
val size = Point()
772+
display.getSize(size)
773+
val widthMax: Int = size.x
774+
val width = (widthMax/1.3).toInt()
775+
val height = attachedImage.drawable.minimumHeight * width / attachedImage.drawable.minimumWidth
776+
attachedImage.layoutParams.height = height
777+
attachedImage.layoutParams.width = width
740778
attachedImage.layoutParams.height = height
741779
attachedImage.layoutParams.width = width
742780
if (ContextCompat.checkSelfPermission(
@@ -768,6 +806,8 @@ class EditPassActivity : AppCompatActivity() {
768806
}
769807
}
770808

809+
imageName = passName
810+
771811
val file = File(mediaStorageDir, "$passName.jpg")
772812

773813
copyFile(File(getRealPathFromURI(selectedImageURI)), file)

app/src/main/java/com/mikhailgrigorev/quickpass/NewPasswordActivity.kt

Lines changed: 41 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import android.content.*
77
import android.content.pm.PackageManager
88
import android.content.res.Configuration
99
import android.database.Cursor
10+
import android.graphics.Point
1011
import android.net.Uri
1112
import android.os.Build
1213
import android.os.Bundle
@@ -26,40 +27,10 @@ import androidx.appcompat.app.AppCompatActivity
2627
import androidx.appcompat.app.AppCompatDelegate
2728
import androidx.core.app.ActivityCompat
2829
import androidx.core.content.ContextCompat
29-
import androidx.core.content.FileProvider
3030
import com.google.android.material.chip.Chip
3131
import com.mikhailgrigorev.quickpass.dbhelpers.DataBaseHelper
3232
import com.mikhailgrigorev.quickpass.dbhelpers.PasswordsDataBaseHelper
33-
import kotlinx.android.synthetic.main.activity_edit_pass.*
3433
import kotlinx.android.synthetic.main.activity_new_password.*
35-
import kotlinx.android.synthetic.main.activity_new_password.accountAvatar
36-
import kotlinx.android.synthetic.main.activity_new_password.accountAvatarText
37-
import kotlinx.android.synthetic.main.activity_new_password.attachedImage
38-
import kotlinx.android.synthetic.main.activity_new_password.authToggle
39-
import kotlinx.android.synthetic.main.activity_new_password.back
40-
import kotlinx.android.synthetic.main.activity_new_password.cardPass
41-
import kotlinx.android.synthetic.main.activity_new_password.cryptToggle
42-
import kotlinx.android.synthetic.main.activity_new_password.email
43-
import kotlinx.android.synthetic.main.activity_new_password.emailField
44-
import kotlinx.android.synthetic.main.activity_new_password.emailSwitch
45-
import kotlinx.android.synthetic.main.activity_new_password.genPasswordId
46-
import kotlinx.android.synthetic.main.activity_new_password.genPasswordIdField
47-
import kotlinx.android.synthetic.main.activity_new_password.generatePassword
48-
import kotlinx.android.synthetic.main.activity_new_password.keyWordsField
49-
import kotlinx.android.synthetic.main.activity_new_password.lengthToggle
50-
import kotlinx.android.synthetic.main.activity_new_password.lettersToggle
51-
import kotlinx.android.synthetic.main.activity_new_password.newName
52-
import kotlinx.android.synthetic.main.activity_new_password.newNameField
53-
import kotlinx.android.synthetic.main.activity_new_password.noteField
54-
import kotlinx.android.synthetic.main.activity_new_password.numbersToggle
55-
import kotlinx.android.synthetic.main.activity_new_password.passQuality
56-
import kotlinx.android.synthetic.main.activity_new_password.passSettings
57-
import kotlinx.android.synthetic.main.activity_new_password.savePass
58-
import kotlinx.android.synthetic.main.activity_new_password.seekBar
59-
import kotlinx.android.synthetic.main.activity_new_password.symToggles
60-
import kotlinx.android.synthetic.main.activity_new_password.timeLimit
61-
import kotlinx.android.synthetic.main.activity_new_password.upload
62-
import kotlinx.android.synthetic.main.activity_new_password.upperCaseToggle
6334
import java.io.File
6435
import java.io.FileInputStream
6536
import java.io.FileOutputStream
@@ -80,6 +51,7 @@ class NewPasswordActivity : AppCompatActivity() {
8051
private var useUC = false
8152
private var useLetters = false
8253
private var useNumbers = false
54+
private var imageName: String = ""
8355

8456
private lateinit var login: String
8557

@@ -498,57 +470,39 @@ class NewPasswordActivity : AppCompatActivity() {
498470

499471
pdbHelper.close()
500472
setResult(1, intent)
501-
finish()
502-
}
503-
}
504-
}
505-
506-
upload.setOnClickListener{
507-
checkPermissionForImage()
508-
}
509473

510474

475+
val mediaStorageDir = File(
476+
applicationContext.getExternalFilesDir("QuickPassPhotos")!!.absolutePath
477+
)
478+
if (!mediaStorageDir.exists()) {
479+
mediaStorageDir.mkdirs()
480+
Toast.makeText(applicationContext, "Directory Created", Toast.LENGTH_LONG).show()
481+
}
511482

512-
val mediaStorageDir = File(
513-
applicationContext.getExternalFilesDir("QuickPassPhotos")!!.absolutePath
514-
)
515-
if (!mediaStorageDir.exists()) {
516-
mediaStorageDir.mkdirs()
517-
Toast.makeText(applicationContext, "Directory Created", Toast.LENGTH_LONG).show()
518-
}
483+
if (!mediaStorageDir.exists()) {
484+
if (!mediaStorageDir.mkdirs()) {
485+
Log.d("App", "failed to create directory")
486+
}
487+
}
519488

520-
if (!mediaStorageDir.exists()) {
521-
if (!mediaStorageDir.mkdirs()) {
522-
Log.d("App", "failed to create directory")
489+
if (mediaStorageDir.exists()) {
490+
if(imageName != "") {
491+
val from = File(mediaStorageDir, "$imageName.jpg")
492+
val to = File(mediaStorageDir, "${newNameField.text}.jpg")
493+
if (from.exists())
494+
from.renameTo(to)
495+
}
496+
}
497+
finish()
498+
}
523499
}
524500
}
525501

526-
val file = File(mediaStorageDir, "${newNameField.text}.jpg")
527-
if (file.exists()){
528-
val uri = Uri.fromFile(file)
529-
attachedImage.setImageURI(uri)
530-
clearImage.visibility = View.VISIBLE
531-
532-
val width = attachedImage.drawable.minimumWidth/2
533-
val height = attachedImage.drawable.minimumHeight/2
534-
attachedImage.layoutParams.height = height
535-
attachedImage.layoutParams.width = width
536-
537-
attachedImage.setOnClickListener {
538-
val uriForOpen = FileProvider.getUriForFile(
539-
this,
540-
this.applicationContext.packageName.toString() + ".provider",
541-
file
542-
)
543-
val intent = Intent()
544-
intent.action = Intent.ACTION_VIEW
545-
intent.setDataAndType(uriForOpen, "image/*")
546-
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
547-
startActivity(intent)
548-
}
502+
upload.setOnClickListener{
503+
checkPermissionForImage()
549504
}
550505

551-
552506
}
553507

554508

@@ -648,19 +602,25 @@ class NewPasswordActivity : AppCompatActivity() {
648602
if (resultCode == Activity.RESULT_OK && requestCode == IMAGE_PICK_CODE) {
649603
// I'M GETTING THE URI OF THE IMAGE AS DATA AND SETTING IT TO THE IMAGEVIEW
650604
attachedImage.setImageURI(data?.data)
651-
val width = attachedImage.drawable.minimumWidth/2
652-
val height = attachedImage.drawable.minimumHeight/2
605+
val display = windowManager.defaultDisplay
606+
val size = Point()
607+
display.getSize(size)
608+
val widthMax: Int = size.x
609+
val width = (widthMax/1.3).toInt()
610+
val height = attachedImage.drawable.minimumHeight * width / attachedImage.drawable.minimumWidth
611+
attachedImage.layoutParams.height = height
612+
attachedImage.layoutParams.width = width
653613
attachedImage.layoutParams.height = height
654614
attachedImage.layoutParams.width = width
655615
if (ContextCompat.checkSelfPermission(
656616
this,
657-
android.Manifest.permission.WRITE_EXTERNAL_STORAGE
617+
Manifest.permission.WRITE_EXTERNAL_STORAGE
658618
)
659619
!= PackageManager.PERMISSION_GRANTED
660620
) {
661621
ActivityCompat.requestPermissions(
662622
this,
663-
arrayOf(android.Manifest.permission.WRITE_EXTERNAL_STORAGE),
623+
arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE),
664624
PackageManager.PERMISSION_GRANTED
665625
)
666626
}
@@ -681,7 +641,11 @@ class NewPasswordActivity : AppCompatActivity() {
681641
}
682642
}
683643

684-
val file = File(mediaStorageDir, "${newNameField.text}.jpg")
644+
imageName = if(newNameField.text.toString() == ""){
645+
"000000001tmp000000001"
646+
} else
647+
newNameField.text.toString()
648+
val file = File(mediaStorageDir, "${imageName}.jpg")
685649

686650
copyFile(File(getRealPathFromURI(selectedImageURI)), file)
687651
isImage = true

app/src/main/java/com/mikhailgrigorev/quickpass/PasswordViewActivity.kt

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import android.content.*
66
import android.content.res.Configuration
77
import android.database.Cursor
88
import android.database.SQLException
9+
import android.graphics.Point
910
import android.net.Uri
1011
import android.os.Bundle
1112
import android.os.Handler
@@ -539,14 +540,28 @@ class PasswordViewActivity : AppCompatActivity() {
539540
layoutTransition.setDuration(5000) // Change duration
540541
layoutTransition.enableTransitionType(LayoutTransition.CHANGING)
541542

542-
543543
val file = File(mediaStorageDir, "$passName.jpg")
544544
if (file.exists()){
545545
val uri = Uri.fromFile(file)
546546
attachedImage.setImageURI(uri)
547547
attachedImageText.visibility = View.VISIBLE
548-
val width = attachedImage.drawable.minimumWidth/3
549-
val height = attachedImage.drawable.minimumHeight/3
548+
//var width = attachedImage.drawable.minimumWidth/3
549+
//var height = attachedImage.drawable.minimumHeight/3
550+
//val display = windowManager.defaultDisplay
551+
//val size = Point()
552+
//display.getSize(size)
553+
//val widthMax: Int = size.x
554+
//val heightMax: Int = size.y
555+
//if (width >= widthMax)
556+
// width = widthMax - 100
557+
//if (height >= heightMax)
558+
// height = heightMax - 100
559+
val display = windowManager.defaultDisplay
560+
val size = Point()
561+
display.getSize(size)
562+
val widthMax: Int = size.x
563+
val width = (widthMax/2.4).toInt()
564+
val height = attachedImage.drawable.minimumHeight * width / attachedImage.drawable.minimumWidth
550565
attachedImage.layoutParams.height = height
551566
attachedImage.layoutParams.width = width
552567

@@ -563,23 +578,11 @@ class PasswordViewActivity : AppCompatActivity() {
563578
startActivity(intent)
564579
}
565580
}
566-
567-
568-
569-
570-
571-
572581
}
573582

574-
575-
576583
override fun onKeyUp(keyCode: Int, msg: KeyEvent?): Boolean {
577584
when (keyCode) {
578585
KeyEvent.KEYCODE_BACK -> {
579-
//logo.visibility = View.VISIBLE
580-
//val rotation = AnimationUtils.loadAnimation(this, R.anim.rotate_splash)
581-
//rotation.fillAfter = true
582-
//logo.startAnimation(rotation)
583586
if (from != "short") {
584587
condition = false
585588
val intent = Intent()

0 commit comments

Comments
 (0)