-
Notifications
You must be signed in to change notification settings - Fork 99
Решение к домашней работе Activity 2 #197
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
Open
dbulygin
wants to merge
1
commit into
Android-Developer-Basic:homework/activity_02
Choose a base branch
from
dbulygin:homework/activity_02
base: homework/activity_02
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 108 additions & 0 deletions
108
sender/src/main/java/otus/gpb/homework/activities/sender/SenderActivity.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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, "Рестораны") | ||
| } | ||
|
|
||
| /* 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}") | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Тут можно задать нули, и тогда он будет искать вокруг вашей текущей точки