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
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,32 @@
package otus.gpb.homework.activities.receiver

import android.os.Bundle
import android.view.View
import android.widget.ImageView
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat

class ReceiverActivity : AppCompatActivity() {

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

findViewById<TextView>(R.id.titleTextView).run {
text = intent.getStringExtra("title").orEmpty()
}
findViewById<TextView>(R.id.yearTextView).run {
text = intent.getStringExtra("year").orEmpty()
}
findViewById<TextView>(R.id.descriptionTextView).run {
text = intent.getStringExtra("desc").orEmpty()
}
findViewById<ImageView>(R.id.posterImageView).run {
when (intent.getStringExtra("title").orEmpty()) {
"niceguys" -> setImageResource(R.drawable.niceguys)
"interstellar" -> setImageResource(R.drawable.interstellar)
}
}
}
}
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>
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",
"Что бывает, когда напарником брутального костолома становится субтильный лопух? Наемный охранник Джексон Хили и частный детектив Холланд Марч вынуждены работать в паре, чтобы распутать плевое дело о пропавшей девушке, которое оборачивается преступлением века. Смогут ли парни разгадать сложный ребус, если у каждого из них – свои, весьма индивидуальные методы."
)
}
}
34 changes: 34 additions & 0 deletions sender/src/main/res/layout/activity_sender.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?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="16dp"
android:text="Send Email"
app:layout_constraintEnd_toEndOf="@+id/button_ToGoogleMaps"
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="16dp"
android:text="Open Receiver"
app:layout_constraintEnd_toEndOf="@+id/button_SendEmail"
app:layout_constraintStart_toStartOf="@+id/button_SendEmail"
app:layout_constraintTop_toBottomOf="@+id/button_SendEmail"/>
</androidx.constraintlayout.widget.ConstraintLayout>