Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,7 @@ dependencies {
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
compile 'de.hdodenhof:circleimageview:1.1.0'
implementation 'com.google.android.material:material:1.2.0'

}
8 changes: 8 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".ProfileActivity">

</activity>
<activity android:name=".GalleryActivity">

</activity>


</application>

</manifest>
Binary file added app/src/main/ic_cancel-playstore.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/ic_save-playstore.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions app/src/main/java/com/example/androidpractice2020/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,11 +1,26 @@
package com.example.androidpractice2020

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.Menu
import android.widget.Toolbar
import kotlinx.android.synthetic.main.activity_main.*
import kotlinx.android.synthetic.main.activity_profile.*

class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
setTitle(R.string.app_registration)
btn_registr.setOnClickListener {
val intent = Intent(this, ProfileActivity::class.java)
intent.putExtra("fName", et_Name.text.toString())
intent.putExtra("fSurname", et_Surname.text.toString())
intent.putExtra("fEmail", et_Email.text.toString())
intent.putExtra("fGender", et_Gender.text.toString())
startActivity(intent)
finish()
}
}
}
146 changes: 146 additions & 0 deletions app/src/main/java/com/example/androidpractice2020/ProfileActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
package com.example.androidpractice2020

import android.app.Activity
import android.content.Intent
import android.graphics.BitmapFactory
import android.graphics.Color
import android.opengl.Visibility
import android.os.Bundle
import android.view.Menu
import android.view.MenuItem
import android.view.View
import android.widget.*
import androidx.appcompat.app.AppCompatActivity
import com.google.android.material.imageview.ShapeableImageView
import kotlinx.android.synthetic.main.activity_profile.*
import java.io.FileNotFoundException

//TODO:
//1) сохранение текущей записи на элементе(View/Edit)
//2) работа с default toolbar (поменять цвет, изменить расположение кнопок) supportactionbar
//3) запрет на нажатие кнопки редактирования isEnabled = false
//4) показывание кнопок на toolbar только при нажатии на редактирование, после нажатие на одну
// из кнопок, убирает просмотр этих кнопок invalidateOptionsMenu()
//5) спросить про предыдущую домашку на примере репозитория
//6) доступ к галереи телефона при нажатии на кнопку профиля
class ProfileActivity : AppCompatActivity() {
//библиотека glide
private var imageView: ImageView? = null
private val pickImage = 1
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_profile)
setTitle(R.string.app_profile)
profile_image.setImageResource(R.drawable.first_picture)
etNameView.setTextColor(Color.BLACK)
etSurnameView.setTextColor(Color.BLACK)
etEmailView.setTextColor(Color.BLACK)
etGenderView.setTextColor(Color.BLACK)
etNameView.text = intent.getStringExtra("fName")
etSurnameView.text = intent.getStringExtra("fSurname")
etEmailView.text = intent.getStringExtra("fEmail")
etGenderView.text = intent.getStringExtra("fGender")
invisible(false)
btn_edit.setOnClickListener {
btn_edit.visibility = View.INVISIBLE
setTitle(R.string.app_edit)
editFirst(etNameView, etName)
editFirst(etSurnameView, etSurname)
editFirst(etEmailView, etEmail)
editFirst(etGenderView, etGender)
}
btn_exit.setOnClickListener {
val intent = Intent(this, MainActivity::class.java)
startActivity(intent)
finish()
}

//Связываемся с нашим ImageView:
imageView = findViewById<View>(R.id.profile_image) as ImageView
//Связываемся с нашей кнопкой Button:
val PickImage =
findViewById<View>(R.id.btn_photo) as Button
//Настраиваем для нее обработчик нажатий OnClickListener:
PickImage.setOnClickListener { //Вызываем стандартную галерею для выбора изображения с помощью Intent.ACTION_PICK:
val photoPickerIntent = Intent(Intent.ACTION_PICK)
//Тип получаемых объектов - image:
photoPickerIntent.type = "image/*"
//Запускаем переход с ожиданием обратного результата в виде информации об изображении:
startActivityForResult(photoPickerIntent, pickImage)
}
}

fun invisible(flag: Boolean) {
setTitle(R.string.app_profile)
etName.visibility = View.INVISIBLE
etSurname.visibility = View.INVISIBLE
etEmail.visibility = View.INVISIBLE
etSyte.visibility = View.INVISIBLE
etGender.visibility = View.INVISIBLE
etNumberPhone.visibility = View.INVISIBLE
}

fun edit(etView: TextView, etEdit: EditText) {
etView.text = etEdit.text.toString()
etView.visibility = View.VISIBLE
etEdit.visibility = View.INVISIBLE
}

fun editFirst(etView: TextView, etEdit: EditText) {
etView.visibility = View.INVISIBLE
etEdit.visibility = View.VISIBLE
}

fun cancel(etView: TextView, etEdit: EditText) {
etView.visibility = View.VISIBLE
etEdit.visibility = View.INVISIBLE
}

override fun onCreateOptionsMenu(menu: Menu?): Boolean {
menuInflater.inflate(R.menu.menu_action, menu)
return true
}

override fun onOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) {
R.id.menu_save -> {
Toast.makeText(this, "Сохранено", Toast.LENGTH_SHORT).show()
edit(etNameView, etName)
edit(etSurnameView, etSurname)
edit(etEmailView, etEmail)
edit(etGenderView, etGender)
btn_edit.visibility = View.VISIBLE
}
R.id.menu_cancel -> {
Toast.makeText(this, "Отмена", Toast.LENGTH_SHORT).show()
cancel(etNameView, etName)
cancel(etSurnameView, etSurname)
cancel(etEmailView, etEmail)
cancel(etGenderView, etGender)
btn_edit.visibility = View.VISIBLE
}
}
return super.onOptionsItemSelected(item)
}

// Обрабатываем результат выбора в галерее:
override fun onActivityResult(requestCode: Int, resultCode: Int, imageReturnedIntent: Intent?) {
super.onActivityResult(requestCode, resultCode, imageReturnedIntent)
when (requestCode) {
pickImage -> if (resultCode == Activity.RESULT_OK) {
try {

//Получаем URI изображения, преобразуем его в Bitmap
//объект и отображаем в элементе ImageView нашего интерфейса:
val imageUri = imageReturnedIntent?.data
val imageStream =
contentResolver.openInputStream(imageUri!!)
val selectedImage = BitmapFactory.decodeStream(imageStream)
imageView!!.setImageBitmap(selectedImage)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

imageView?

} catch (e: FileNotFoundException) {
e.printStackTrace()
}
}
}
}
}
Binary file added app/src/main/res/drawable-v24/unnamed.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-v24/unnamed2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable/first_picture.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions app/src/main/res/drawable/ic_cancel_background.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

</selector>
15 changes: 15 additions & 0 deletions app/src/main/res/drawable/ic_cancel_foreground.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="108dp"
android:height="108dp"
android:viewportWidth="108"
android:viewportHeight="108"
android:tint="#010101">
<group android:scaleX="2.61"
android:scaleY="2.61"
android:translateX="22.68"
android:translateY="22.68">
<path
android:fillColor="@android:color/white"
android:pathData="M19,6.41L17.59,5 12,10.59 6.41,5 5,6.41 10.59,12 5,17.59 6.41,19 12,13.41 17.59,19 19,17.59 13.41,12z"/>
</group>
</vector>
4 changes: 4 additions & 0 deletions app/src/main/res/drawable/ic_save_background.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

</selector>
15 changes: 15 additions & 0 deletions app/src/main/res/drawable/ic_save_foreground.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="108dp"
android:height="108dp"
android:viewportWidth="108"
android:viewportHeight="108"
android:tint="#151287">
<group android:scaleX="2.61"
android:scaleY="2.61"
android:translateX="22.68"
android:translateY="22.68">
<path
android:fillColor="@android:color/white"
android:pathData="M9,16.17L4.83,12l-1.42,1.41L9,19 21,7l-1.41,-1.41z"/>
</group>
</vector>
5 changes: 5 additions & 0 deletions app/src/main/res/drawable/text_color_selector.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="true" android:color="#232B87" />
<item android:color="#232B87" />
</selector>
Loading