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
4 changes: 2 additions & 2 deletions .github/workflows/android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ jobs:

steps:
- uses: actions/checkout@v3
- name: set up JDK 11
- name: set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '11'
java-version: '17'
distribution: 'temurin'
cache: gradle

Expand Down
35 changes: 35 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Activity #2 Homework

Создайте в модуле **sender** класс **SenderActivity**. Добавьте в него три кнопки: **“To Google Maps”**, **“Send Email”** и **“Open Receiver”**. Добавьте пустые обработчики нажатий на эти кнопки.

1. По клику на кнопку **“To Google Maps”**, используя явный `Intent` вызовите `Activity` приложения Google Maps. После того как Google Maps поймает ваш Intent, в нем должны отобразиться ближайшие к текущей геолокации места по тэгу “*Рестораны”*

<img src="art/Untitled.png" width="520">

2. По клику на кнопку **“Send Email”** отправьте неявный `Intent` в метод `startActivity()` Этот `Intent` должны уметь обработать любые почтовые клиенты(если они реализовали `intent-filter` согласно контракту).
В качестве адресата используйте ящик *android@otus.ru*, тему и содержание письма придумайте сами.

<img src="art/Untitled%201.png" width="520">

3. По клику на кнопку **“Open Receiver”** отправьте неявный `Intent` со следующими параметрами:

- `action = Action.SEND`
- `type = “text/plain”`
- `category = Category.DEFAULT`

В качестве extras отправьте три объекта String. В качестве значений extras используйте любой набор данных из файла *payload.txt*, который лежит в корне проекта **sender**.

В модуле **receiver** зарегистрируйте `intent-filter`, таким образом, чтобы он поймал отправленный выше `Intent` и открыл **ReceiverActivity**. Полученные из `Intent` extras отобразите в соответсвующих полях:

- title → `titleTextView`
- year → `yearTextView`
- description → `descriptionTextView`
- В зависимости от названия фильма отобразите картинку которая лежит в ресурсах(*res/drawable*) в `posterImageView`

> 💡 Чтобы достать ресурс, используйте метод [Context.getDrawable()](https://developer.android.com/reference/android/content/Context#getDrawable(int)), а чтобы поменять картинку в ImageView используйте метод [setImageDrawable()](https://developer.android.com/reference/android/widget/ImageView#setImageDrawable(android.graphics.drawable.Drawable))

<img src="art/Untitled%202.png" width="720">

4. Оба приложения установлены
./gradlew :sender:installDebug
./gradlew :receiver:installDebug
16 changes: 0 additions & 16 deletions app/src/main/AndroidManifest.xml

This file was deleted.

3 changes: 0 additions & 3 deletions app/src/main/res/values/strings.xml

This file was deleted.

13 changes: 0 additions & 13 deletions app/src/main/res/xml/backup_rules.xml

This file was deleted.

19 changes: 0 additions & 19 deletions app/src/main/res/xml/data_extraction_rules.xml

This file was deleted.

Binary file added art/Untitled 1.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 art/Untitled 2.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 art/Untitled.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id 'com.android.application' version '8.4.0' apply false
id 'com.android.library' version '8.4.0' apply false
id 'com.android.application' version '8.2.2' apply false
id 'com.android.library' version '8.2.2' apply false
id 'org.jetbrains.kotlin.android' version '1.9.23' apply false
id "io.gitlab.arturbosch.detekt" version "1.21.0"
}
Expand Down
File renamed without changes.
60 changes: 60 additions & 0 deletions receiver/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id("io.gitlab.arturbosch.detekt")
}

android {
compileSdk 34

defaultConfig {
applicationId "otus.gpb.homework.activities.receiver"
minSdk 23
targetSdk 34
versionCode 1
versionName "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
namespace 'otus.gpb.homework.activities.receiver'
buildFeatures {
viewBinding true
}
}

detekt {
source = files("src/main/java", "src/main/kotlin")
config = files("$rootDir/config/detekt/detekt.yml")
}

tasks.named("detekt").configure {
reports {
txt.required.set(true)
html.required.set(false)
md.required.set(false)
xml.required.set(false)
sarif.required.set(false)
html.outputLocation.set(file("build/reports/detekt/detekt.html"))
}
}

dependencies {
implementation 'androidx.core:core-ktx:1.13.1'
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.12.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
}
File renamed without changes.
25 changes: 25 additions & 0 deletions receiver/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<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">

<activity
android:name=".ReceiverActivity"
android:exported="true">
<intent-filter android:priority="999">
<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
@@ -0,0 +1,53 @@
package otus.gpb.homework.activities.receiver

import android.content.Intent
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import otus.gpb.homework.activities.receiver.databinding.ActivityReceiverBinding
import java.util.Locale

class ReceiverActivity : AppCompatActivity() {

private lateinit var binding: ActivityReceiverBinding

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityReceiverBinding.inflate(layoutInflater)
setContentView(binding.root)

android.util.Log.d("RECEIVER_DEBUG", "ReceiverActivity created")
android.util.Log.d("RECEIVER_DEBUG", "Intent action: ${intent.action}")
android.util.Log.d("RECEIVER_DEBUG", "Intent type: ${intent.type}")

handleIntent(intent)
}

override fun onNewIntent(intent: Intent?) {
super.onNewIntent(intent)
intent?.let { handleIntent(it) }
}

private fun handleIntent(intent: Intent) {
val title = intent.getStringExtra("title") ?: "No title"
val year = intent.getStringExtra("year") ?: "No year"
val description = intent.getStringExtra("description") ?: "No description"

binding.titleTextView.text = title
binding.yearTextView.text = year
binding.descriptionTextView.text = description

setPosterImage(title)
}

private fun setPosterImage(movieTitle: String) {
val drawableResId = when (movieTitle.lowercase(Locale.ROOT)) {
"interstellar" -> R.drawable.interstellar
"inception" -> R.drawable.inception
"niceguys" -> R.drawable.niceguys
else -> R.drawable.interstellar
}

val drawable = getDrawable(drawableResId)
binding.posterImageView.setImageDrawable(drawable)
}
}
Binary file added receiver/src/main/res/drawable/inception.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 receiver/src/main/res/drawable/inters_tellar.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 receiver/src/main/res/drawable/interstellar.webp
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 receiver/src/main/res/drawable/nic_guys.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 receiver/src/main/res/drawable/niceguys.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
55 changes: 55 additions & 0 deletions receiver/src/main/res/layout/activity_receiver.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ReceiverActivity">

<ImageView
android:id="@+id/posterImageView"
android:layout_width="120dp"
android:layout_height="180dp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:srcCompat="@drawable/interstellar" />

<TextView
android:id="@+id/titleTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="32dp"
android:textColor="#212121"
android:textSize="24dp"
app:layout_constraintStart_toEndOf="@+id/posterImageView"
app:layout_constraintTop_toTopOf="@+id/posterImageView"
tools:text="Interstellar" />

<TextView
android:id="@+id/descriptionTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="16dp"
android:textColor="#B3212121"
android:textSize="16dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/posterImageView"
tools:text="Когда засуха, пыльные бури и вымирание растений приводят человечество к продовольственному кризису, коллектив исследователей и учёных отправляется сквозь червоточину (которая предположительно соединяет области пространства-времени через большое расстояние) в путешествие, чтобы превзойти прежние ограничения для космических путешествий человека и найти планету с подходящими для человечества условиями." />

<TextView
android:id="@+id/yearTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:textColor="#80212121"
android:textSize="14dp"
app:layout_constraintStart_toStartOf="@+id/titleTextView"
app:layout_constraintTop_toBottomOf="@+id/titleTextView"
tools:text="2014" />

</androidx.constraintlayout.widget.ConstraintLayout>
3 changes: 3 additions & 0 deletions receiver/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<resources>
<string name="app_name">Receiver</string>
</resources>
1 change: 1 addition & 0 deletions sender/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
5 changes: 3 additions & 2 deletions app/build.gradle → sender/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ android {
compileSdk 34

defaultConfig {
applicationId "otus.gpb.homework.activities"
applicationId "otus.gpb.homework.activities.sender"
minSdk 23
targetSdk 34
versionCode 1
Expand All @@ -30,7 +30,7 @@ android {
kotlinOptions {
jvmTarget = '1.8'
}
namespace 'otus.gpb.homework.activities'
namespace 'otus.gpb.homework.activities.sender'
buildFeatures {
viewBinding true
}
Expand All @@ -56,4 +56,5 @@ dependencies {
implementation 'androidx.core:core-ktx:1.13.1'
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.12.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
}
7 changes: 7 additions & 0 deletions sender/payload.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
title: Славные парни
year: 2016
description: Что бывает, когда напарником брутального костолома становится субтильный лопух? Наемный охранник Джексон Хили и частный детектив Холланд Марч вынуждены работать в паре, чтобы распутать плевое дело о пропавшей девушке, которое оборачивается преступлением века. Смогут ли парни разгадать сложный ребус, если у каждого из них – свои, весьма индивидуальные методы.

title: Интерстеллар
year: 2014
description: Когда засуха, пыльные бури и вымирание растений приводят человечество к продовольственному кризису, коллектив исследователей и учёных отправляется сквозь червоточину (которая предположительно соединяет области пространства-времени через большое расстояние) в путешествие, чтобы превзойти прежние ограничения для космических путешествий человека и найти планету с подходящими для человечества условиями.
21 changes: 21 additions & 0 deletions sender/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
Loading