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
3 changes: 2 additions & 1 deletion receiver/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {
}

android {
compileSdk 34
compileSdk 36

defaultConfig {
applicationId "otus.gpb.homework.activities.receiver"
Expand Down Expand Up @@ -57,4 +57,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 'com.google.android.gms:play-services-nearby:19.3.0'
}
19 changes: 18 additions & 1 deletion receiver/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,23 @@
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.receiver.ReceiverActivity"
android:exported="true">

<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>

<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
Expand Up @@ -2,11 +2,36 @@ package otus.gpb.homework.activities.receiver

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import android.widget.ImageView
import android.widget.TextView
import android.widget.Toast

class ReceiverActivity : AppCompatActivity() {

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

val titleView = intent.getStringExtra("title").orEmpty()

findViewById<TextView>(R.id.titleTextView).run {
text = titleView
}
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 (titleView) {
"Славные парни" -> setImageResource(R.drawable.niceguys)
"Интерстеллар" -> setImageResource(R.drawable.interstellar)
}
}
if (!titleView.isEmpty()) {
Toast.makeText(this, titleView, Toast.LENGTH_SHORT).show()
}
}

}
4 changes: 3 additions & 1 deletion sender/build.gradle
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id "kotlin-parcelize"
}

android {
compileSdk 34
compileSdk 36

defaultConfig {
applicationId "otus.gpb.homework.activities.sender"
Expand Down Expand Up @@ -40,4 +41,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.10.1'
}
13 changes: 12 additions & 1 deletion sender/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,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="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,108 @@
package otus.gpb.homework.activities.sender

import android.content.ActivityNotFoundException
import android.content.Context
import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.util.Log
import android.widget.Button
import android.widget.Toast
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.net.toUri
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import otus.gpb.homework.activities.receiver.R

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
}

/* To Google Maps button */
findViewById<Button>(R.id.buttonGoogleMaps).setOnClickListener {
openGoogleMapsWithCategory(this, 55.7558, 37.6173, "Рестораны")
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Тут можно задать нули, и тогда он будет искать вокруг вашей текущей точки

}

/* Send Email button */
findViewById<Button>(R.id.buttonSendEmail).setOnClickListener {
try {
startActivity(
Intent(
Intent.ACTION_SENDTO,
"mailto:android@otus.ru".toUri()
)
)
} catch (e: ActivityNotFoundException) {
Toast.makeText(
this,
"Ни одного почтового клиента не найдено",
Toast.LENGTH_SHORT
).show()
}
}

/* Open Receiver button */
findViewById<Button>(R.id.buttonOpenReciever).setOnClickListener {
val payLoad1 = Payload(
"Славные парни",
"2016",
"Что бывает, когда напарником брутального костолома становится субтильный лопух? Наемный охранник Джексон Хили и частный детектив Холланд Марч вынуждены работать в паре, чтобы распутать плевое дело о пропавшей девушке, которое оборачивается преступлением века. Смогут ли парни разгадать сложный ребус, если у каждого из них – свои, весьма индивидуальные методы."
)
val payLoad2 = Payload(
"Интерстеллар",
"2014",
"Когда засуха, пыльные бури и вымирание растений приводят человечество к продовольственному кризису, коллектив исследователей и учёных отправляется сквозь червоточину (которая предположительно соединяет области пространства-времени через большое расстояние) в путешествие, чтобы превзойти прежние ограничения для космических путешествий человека и найти планету с подходящими для человечества условиями."
)

openReceiver(payLoad1)
}
}

private fun openGoogleMapsWithCategory(
context: Context,
latitude: Double,
longitude: Double,
query: String
) {
try {
context.startActivity(
Intent(
Intent.ACTION_VIEW,
"geo:$latitude,$longitude?q=${Uri.encode(query)}".toUri()
).setPackage("com.google.android.apps.maps")
)
} catch (e: ActivityNotFoundException) {
Toast.makeText(
context,
"Google Maps не установлен",
Toast.LENGTH_SHORT
).show()
}
}

private fun openReceiver(payLoad: Payload) {
try {
startActivity(
Intent().apply {
action = Intent.ACTION_SEND
type = "text/plain"
putExtra(Intent.EXTRA_TEXT, "Hello from Sender!")
putExtra("title", payLoad.title)
putExtra("year", payLoad.year)
putExtra("desc", payLoad.description)
}
)
} catch (e: ActivityNotFoundException) {
Toast.makeText(this, "Activity not found", Toast.LENGTH_SHORT).show()
Log.e("TAG", "Activity not found: ${e.message}")
}
}
}
52 changes: 52 additions & 0 deletions sender/src/main/res/layout/activity_sender.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?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">

<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="150dp"
android:text="SenderActivity"
android:textSize="35sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<Button
android:id="@+id/buttonGoogleMaps"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:text="To Google Maps"
app:layout_constraintEnd_toEndOf="@+id/textView"
app:layout_constraintStart_toStartOf="@+id/textView"
app:layout_constraintTop_toBottomOf="@+id/textView" />

<Button
android:id="@+id/buttonSendEmail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="Send Email"
app:layout_constraintEnd_toEndOf="@+id/buttonGoogleMaps"
app:layout_constraintStart_toStartOf="@+id/buttonGoogleMaps"
app:layout_constraintTop_toBottomOf="@+id/buttonGoogleMaps" />

<Button
android:id="@+id/buttonOpenReciever"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="Open Reciever"
app:layout_constraintEnd_toEndOf="@+id/buttonSendEmail"
app:layout_constraintStart_toStartOf="@+id/buttonSendEmail"
app:layout_constraintTop_toBottomOf="@+id/buttonSendEmail" />

</androidx.constraintlayout.widget.ConstraintLayout>