Skip to content
Open

hm 2 #231

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
13 changes: 12 additions & 1 deletion receiver/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,17 @@
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Activities" />
android:theme="@style/Theme.Activities">

<activity
android:name=".ReceiverActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
</activity>
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -1,12 +1,43 @@
package otus.gpb.homework.activities.receiver

import android.graphics.drawable.Drawable
import android.os.Bundle
import android.widget.ImageView
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity

const val TITLEKEY = "title"
const val YEARKEY = "year"
const val DESCRIPTIONKEY = "description"
class ReceiverActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_receiver)

val titleView: TextView = findViewById(R.id.titleTextView)
val yearView: TextView = findViewById(R.id.yearTextView)
val descriptionView: TextView = findViewById(R.id.descriptionTextView)
val posterView: ImageView = findViewById(R.id.posterImageView)

val title = getFromIntent(TITLEKEY)

titleView.text = title
yearView.text = getFromIntent(YEARKEY)
descriptionView.text = getFromIntent(DESCRIPTIONKEY)
posterView.setImageDrawable(getPoster(title))

}

private fun getFromIntent(key: String): String {
return intent.getStringExtra(key) ?: ""
}

private fun getPoster(title: String): Drawable? {
return when (title) {
"Славные парни" -> getDrawable(R.drawable.niceguys)
"Интерстеллар" -> getDrawable(R.drawable.interstellar)
else -> null
}
}

}
1 change: 1 addition & 0 deletions sender/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,5 @@ dependencies {
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.12.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.activity:activity:1.8.0'
}
11 changes: 10 additions & 1 deletion sender/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Activities" />
android:theme="@style/Theme.Activities">
<activity
android:name="otus.gpb.homework.activities.sender.SenderActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package otus.gpb.homework.activities.sender

import android.content.Intent
import android.icu.util.ULocale
import android.net.Uri
import android.os.Bundle
import android.widget.Button
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import otus.gpb.homework.activities.receiver.R
import kotlin.jvm.java
import androidx.core.net.toUri

class SenderActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enableEdgeToEdge()
setContentView(R.layout.activity_sender)
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
insets
}

findViewById<Button>(R.id.GoogleMapsButton).setOnClickListener {
val intent = Intent(Intent.ACTION_VIEW, "geo:0,0?q=restaurants".toUri())
.setPackage("com.google.android.apps.maps")

startActivity(intent)
}

findViewById<Button>(R.id.SendEmailButton).setOnClickListener {
val intent = Intent(Intent.ACTION_SENDTO, "mailto:android@otus.ru".toUri())
.putExtra(Intent.EXTRA_SUBJECT, "Тут вот тема письма.")
.putExtra(Intent.EXTRA_TEXT, "А тут нужно тело письма написать.")

startActivity(intent)
}

findViewById<Button>(R.id.OpenReceiverButton).setOnClickListener {
val intent = Intent(Intent.ACTION_SEND)
.setType("text/plain")
.addCategory(Intent.CATEGORY_DEFAULT)
.putExtra("title", "Славные парни")
.putExtra("year", "2016")
.putExtra("description",
"Что бывает, когда напарником брутального костолома становится субтильный лопух? Наемный охранник Джексон Хили и частный детектив Холланд Марч вынуждены работать в паре, чтобы распутать плевое дело о пропавшей девушке, которое оборачивается преступлением века. Смогут ли парни разгадать сложный ребус, если у каждого из них – свои, весьма индивидуальные методы."
)

startActivity(intent)
}
}
}
40 changes: 40 additions & 0 deletions sender/src/main/res/layout/activity_sender.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="otus.gpb.homework.activities.sender.SenderActivity">

<Button
android:id="@+id/GoogleMapsButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/to_google_maps"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="@id/SendEmailButton"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent" />

<Button
android:id="@+id/SendEmailButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/send_email"
app:layout_constraintTop_toTopOf="@id/GoogleMapsButton"
app:layout_constraintBottom_toBottomOf="@id/OpenReceiverButton"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent" />


<Button
android:id="@+id/OpenReceiverButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/open_receiver"
app:layout_constraintTop_toTopOf="@id/SendEmailButton"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
3 changes: 3 additions & 0 deletions sender/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
<resources>
<string name="app_name">Sender</string>
<string name="to_google_maps">To Google Maps</string>
<string name="send_email">Send Email</string>
<string name="open_receiver">Open Receiver</string>
</resources>