Skip to content
Open

dz#2 #228

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
3 changes: 2 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ kotlin.code.style=official
# thereby reducing the size of the R class for that library
android.nonTransitiveRClass=true
android.defaults.buildfeatures.buildconfig=true
android.nonFinalResIds=false
android.nonFinalResIds=false
android.overridePathCheck=true
17 changes: 12 additions & 5 deletions receiver/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
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,38 @@
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

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 movieTitle = intent.getStringExtra("title") ?: ""
val movieYear = intent.getStringExtra("year") ?: ""
val movieDescription = intent.getStringExtra("description") ?: ""

titleView.text = movieTitle
yearView.text = movieYear
descriptionView.text = movieDescription

val posterDrawable: Drawable? = when (movieTitle) {
"niceguys" -> getDrawable(R.drawable.niceguys)
"interstellar" -> getDrawable(R.drawable.interstellar)
else -> null
}

posterDrawable?.let {
posterView.setImageDrawable(it)
}
}
}
12 changes: 10 additions & 2 deletions sender/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@
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=".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>

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package otus.gpb.homework.activities.receiver

import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.widget.Button
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity

class SenderActivity : AppCompatActivity() {

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

findViewById<Button>(R.id.button_ToGoogleMaps).setOnClickListener {
try {
startActivity(openGoogleMaps())
} catch (e: Exception) {
Toast.makeText(
this,
"Ошибка открытия карты",
Toast.LENGTH_SHORT
).show()
}
}

findViewById<Button>(R.id.button_SendEmail).setOnClickListener {
try {
startActivity(sendMail())
} catch (e: Exception) {
Toast.makeText(
this,
"Ошибка открытия почтового агента",
Toast.LENGTH_SHORT
).show()
}
}

findViewById<Button>(R.id.button_OpenReceiver).setOnClickListener {
try {
startActivity(sendMessage())
} catch (e: Exception) {
Toast.makeText(
this,
"Ошибка открытия Receiver'a",
Toast.LENGTH_SHORT
).show()
}
}
}

fun openGoogleMaps() : Intent {
return Intent(Intent.ACTION_VIEW, Uri.parse("geo:0,0?q=restaurant"))
.setPackage("com.google.android.apps.maps")
}

fun sendMail() : Intent {
val uriText = "mailto:android@otus.ru" +
"?subject=" + Uri.encode("otus") +
"&body=" + Uri.encode("Hello world")
return Intent(Intent.ACTION_SENDTO, Uri.parse(uriText))
}

fun sendMessage() : Intent {
return Intent(Intent.ACTION_SEND)
.addCategory(Intent.CATEGORY_DEFAULT)
.setType("text/plain")
.putExtra("title", "niceguys")
.putExtra("year", "2016")
.putExtra("description",
"Что бывает, когда напарником брутального костолома становится субтильный лопух? Наемный охранник Джексон Хили и частный детектив Холланд Марч вынуждены работать в паре, чтобы распутать плевое дело о пропавшей девушке, которое оборачивается преступлением века. Смогут ли парни разгадать сложный ребус, если у каждого из них – свои, весьма индивидуальные методы."
)
}
}
38 changes: 38 additions & 0 deletions sender/src/main/res/layout/activity_sender.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?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"
android:id="@+id/activity_sender"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/button_ToGoogleMaps"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="To Google Maps"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<Button
android:id="@+id/button_SendEmail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="168dp"
android:text="Send Email"
app:layout_constraintEnd_toEndOf="@+id/button_ToGoogleMaps"
app:layout_constraintHorizontal_bias="0.476"
app:layout_constraintStart_toStartOf="@+id/button_ToGoogleMaps"
app:layout_constraintTop_toBottomOf="@+id/button_ToGoogleMaps" />

<Button
android:id="@+id/button_OpenReceiver"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="228dp"
android:text="Open Receiver"
app:layout_constraintEnd_toEndOf="@+id/button_SendEmail"
app:layout_constraintHorizontal_bias="0.518"
app:layout_constraintStart_toStartOf="@+id/button_SendEmail"
app:layout_constraintTop_toBottomOf="@+id/button_SendEmail" />
</androidx.constraintlayout.widget.ConstraintLayout>