Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Activity 02 #144

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
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
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# 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` согласно контракту).
В качестве адресата используйте ящик *[email protected]*, тему и содержание письма придумайте сами.

<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">
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.
File renamed without changes.
9 changes: 7 additions & 2 deletions app/build.gradle → receiver/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.receiver"
minSdk 23
targetSdk 34
versionCode 1
Expand All @@ -30,10 +30,14 @@ android {
kotlinOptions {
jvmTarget = '1.8'
}
namespace 'otus.gpb.homework.activities'
namespace 'otus.gpb.homework.activities.receiver'
buildFeatures {
viewBinding true
}
dependenciesInfo {
includeInApk true
includeInBundle true
}
}

detekt {
Expand All @@ -56,4 +60,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'
}
File renamed without changes.
26 changes: 26 additions & 0 deletions receiver/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<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">
<activity
android:name=".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" />
<data android:mimeType="text/plain" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +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
import androidx.core.content.ContextCompat

const val TITLE_KEY = "title key"
const val YEAR_KEY = "year key"
const val DESCR_KEY = "description key"

class ReceiverActivity : AppCompatActivity() {

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

val title: String = intent.extras?.getString(TITLE_KEY)?: ""
val year: String = intent.extras?.getString(YEAR_KEY)?: ""
val description: String = intent.extras?.getString(DESCR_KEY)?: ""

fun getDrawable(): Drawable? {
return when(title) {
"Interstellar" -> ContextCompat.getDrawable(this, R.drawable.interstellar)
"Славные парни" -> ContextCompat.getDrawable(this, R.drawable.niceguys)
else -> null
}
}

findViewById<TextView>(R.id.titleTextView).text = title
findViewById<TextView>(R.id.yearTextView).text = year
findViewById<TextView>(R.id.descriptionTextView).text = description
findViewById<ImageView>(R.id.posterImageView).setImageDrawable(getDrawable())

}
}
Binary file added receiver/src/main/res/drawable/interstellar.webp
Binary file not shown.
Binary file added receiver/src/main/res/drawable/niceguys.webp
Binary file not shown.
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
46 changes: 46 additions & 0 deletions sender/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
}

android {
compileSdk 34

defaultConfig {
applicationId "otus.gpb.homework.activities.sender"
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
}
viewBinding {
enabled true
}
}

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
23 changes: 23 additions & 0 deletions sender/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<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">

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

data class Payload(
val title: String,
val year: String,
val description: String
)
Loading