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: 3 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package="com.magdamiu.androidfundamentalsmai2021">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CALL_PHONE" />

<application
android:allowBackup="true"
Expand All @@ -11,7 +12,8 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.AndroidFundamentalsMai2021">
<activity android:name=".activities.SecondActivity"></activity>
<activity android:name=".code_challenge_4.ImplicitActivity" />
<activity android:name=".activities.SecondActivity" />
<activity android:name=".activities.FirstActivity" />
<activity android:name=".ConstraintLayoutSampleActivity" />
<activity android:name=".MainActivity" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import android.view.View;

import com.magdamiu.androidfundamentalsmai2021.activities.FirstActivity;
import com.magdamiu.androidfundamentalsmai2021.code_challenge_4.ImplicitActivity;

public class StartActivity extends AppCompatActivity {

Expand Down Expand Up @@ -48,4 +49,9 @@ public void startFirstActivityOnClick(View view) {
Intent intentToStartFirstActivity = new Intent(StartActivity.this, FirstActivity.class);
startActivity(intentToStartFirstActivity);
}

public void startImplicitActivityOnClick(View view) {
Intent intentToStartImplicitActivity = new Intent(StartActivity.this, ImplicitActivity.class);
startActivity(intentToStartImplicitActivity);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package com.magdamiu.androidfundamentalsmai2021.code_challenge_4;

import androidx.appcompat.app.AppCompatActivity;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

import com.magdamiu.androidfundamentalsmai2021.R;
import com.magdamiu.androidfundamentalsmai2021.activities.FirstActivity;

import static com.magdamiu.androidfundamentalsmai2021.R.string.use_device_with_sim;

public class ImplicitActivity extends AppCompatActivity {

private EditText editTextWebsite, editTextLocation, editTextShareText, editTextPhoneNumber;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_implicit);
findViews();
}

private void findViews() {
editTextWebsite = findViewById(R.id.editTextWebsite);
editTextLocation = findViewById(R.id.editTextLocation);
editTextShareText = findViewById(R.id.editTextShareText);
editTextPhoneNumber = findViewById(R.id.editTextPhoneNumber);
}

public void openWebsiteOnClick(View view) {
Intent openWebsite = new Intent(Intent.ACTION_VIEW);
String urlOfWebsite = editTextWebsite.getText().toString();
if (urlOfWebsite.isEmpty()) {
editTextWebsite.setError(getString(R.string.error_insert_url));
} else {
openWebsite.setData(Uri.parse(urlOfWebsite));
startActivity(openWebsite);
}
}

public void openLocationOnClick(View view) {
String location = editTextLocation.getText().toString();
if (location.isEmpty()) {
editTextLocation.setError(getString(R.string.error_insert_location));
} else {
Uri gmmIntentUri = Uri.parse("geo:37.7749,-122.4192?q=" + Uri.encode(location));
Intent openLocation = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
openLocation.setPackage("com.google.android.apps.maps");
startActivity(openLocation);
}
}

@SuppressLint("QueryPermissionsNeeded")
public void shareTextOnClick(View view) {
String textToShare = editTextShareText.getText().toString();
if (textToShare.isEmpty()) {
editTextShareText.setError(getString(R.string.error_insert_text));
} else {
Intent shareText = new Intent(Intent.ACTION_SEND);
shareText.setType("text/plain");
shareText.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.share_subject));
shareText.putExtra(android.content.Intent.EXTRA_TEXT, textToShare);
if (shareText.resolveActivity(ImplicitActivity.this.getPackageManager()) != null) {
startActivity(Intent.createChooser(shareText, getString(R.string.share_using)));
} else {
Toast.makeText(ImplicitActivity.this, "No app found on your phone which can perform this action", Toast.LENGTH_SHORT).show();
Copy link
Owner

Choose a reason for hiding this comment

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

Adauga te rog stringurile in strings.xml

}
}
}

@SuppressLint("QueryPermissionsNeeded")
public void callPhoneNumberOnClick(View view) {
String phoneNumber = editTextPhoneNumber.getText().toString();
if (phoneNumber.length() != 10) {
editTextPhoneNumber.setError(getString(R.string.error_insert_phone_number));
} else {
Intent callPhoneNumber = new Intent(Intent.ACTION_DIAL);
callPhoneNumber.setData(Uri.fromParts("tel", phoneNumber.trim(), null));
if (callPhoneNumber.resolveActivity(ImplicitActivity.this.getPackageManager()) != null) {
startActivity(callPhoneNumber);
} else {
Toast.makeText(ImplicitActivity.this, use_device_with_sim, Toast.LENGTH_LONG).show();
}
}
}
}
105 changes: 105 additions & 0 deletions app/src/main/res/layout/activity_implicit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
<?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=".code_challenge_4.ImplicitActivity">

<EditText
android:id="@+id/editTextWebsite"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:layout_marginTop="@dimen/medium_space"
android:layout_marginEnd="@dimen/medium_space"
android:autofillHints="@string/website"
android:ems="10"
android:hint="@string/website"
android:inputType="textWebEditText"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<Button
android:id="@+id/buttonWebsite"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/space_8"
android:onClick="openWebsiteOnClick"
android:text="@string/open_website"
app:layout_constraintStart_toStartOf="@+id/editTextWebsite"
app:layout_constraintTop_toBottomOf="@+id/editTextWebsite" />

<EditText
android:id="@+id/editTextLocation"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/medium_space"
android:layout_marginEnd="@dimen/medium_space"
android:autofillHints="@string/location"
android:ems="10"
android:hint="@string/location"
android:inputType="text"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="@+id/editTextWebsite"
app:layout_constraintTop_toBottomOf="@+id/buttonWebsite" />

<Button
android:id="@+id/buttonLocation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/space_8"
android:onClick="openLocationOnClick"
android:text="@string/open_location"
app:layout_constraintStart_toStartOf="@+id/editTextLocation"
app:layout_constraintTop_toBottomOf="@+id/editTextLocation" />

<EditText
android:id="@+id/editTextShareText"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/medium_space"
android:layout_marginEnd="@dimen/medium_space"
android:autofillHints="@string/text"
android:ems="10"
android:hint="@string/text"
android:inputType="text"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="@+id/editTextWebsite"
app:layout_constraintTop_toBottomOf="@+id/buttonLocation" />

<Button
android:id="@+id/buttonShareText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/space_8"
android:onClick="shareTextOnClick"
android:text="@string/share_text"
app:layout_constraintStart_toStartOf="@+id/editTextShareText"
app:layout_constraintTop_toBottomOf="@+id/editTextShareText" />

<EditText
android:id="@+id/editTextPhoneNumber"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/medium_space"
android:layout_marginEnd="@dimen/medium_space"
android:autofillHints="@string/phone_number"
android:ems="10"
android:hint="@string/phone_number"
android:inputType="phone"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="@+id/editTextWebsite"
app:layout_constraintTop_toBottomOf="@+id/buttonShareText" />

<Button
android:id="@+id/buttonPhone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/space_8"
android:onClick="callPhoneNumberOnClick"
android:text="@string/call"
app:layout_constraintStart_toStartOf="@+id/editTextPhoneNumber"
app:layout_constraintTop_toBottomOf="@+id/editTextPhoneNumber" />
</androidx.constraintlayout.widget.ConstraintLayout>
22 changes: 14 additions & 8 deletions app/src/main/res/layout/activity_start.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,30 @@
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/start_mainactivity"
android:onClick="startMainActivityOnClick"/>
android:onClick="startMainActivityOnClick"
android:text="@string/start_mainactivity" />

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/start_recyclerview_activity"
android:onClick="startRecyclerViewActivityOnClick"/>
android:onClick="startRecyclerViewActivityOnClick"
android:text="@string/start_recyclerview_activity" />

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/start_constraint_activity"
android:onClick="startConstraintActivityOnClick"/>
android:onClick="startConstraintActivityOnClick"
android:text="@string/start_constraint_activity" />

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/start_firstactivity"
android:onClick="startFirstActivityOnClick"/>
android:onClick="startFirstActivityOnClick"
android:text="@string/start_firstactivity" />

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="startImplicitActivityOnClick"
android:text="@string/start_code_challenge_4" />
</LinearLayout>
1 change: 1 addition & 0 deletions app/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<resources>
<dimen name="medium_text">23sp</dimen>
<dimen name="medium_space">16dp</dimen>
<dimen name="space_8">8dp</dimen>
<dimen name="space_128">128dp</dimen>
<dimen name="space_64">64dp</dimen>
</resources>
14 changes: 14 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<string name="please_add_your_name_here">Please add your name here</string>
<string name="greetings">Greetings :)</string>
<string name="error_insert_name">Please insert a name</string>
<string name="error_insert_url">Please insert an url</string>
<string name="textview_3">TextView 3</string>
<string name="textview_2">TextView 2</string>
<string name="textview_1">TextView 1</string>
Expand Down Expand Up @@ -66,4 +67,17 @@ Ut fermentum feugiat lorem sed ultrices. Phasellus et mattis diam. Sed faucibus
<string name="hello_from_first_activity">hello from first activity</string>
<string name="sample_startactivityforresult">Sample startActivityForResult</string>
<string name="confirm_message">Yes, I\'m here! :)</string>
<string name="start_code_challenge_4">Start Code Challenge 4</string>
<string name="website">Website</string>
<string name="location">Location</string>
<string name="open_website">Open Website</string>
<string name="open_location">Open Location</string>
<string name="text">Text</string>
<string name="share_text">Share Text</string>
<string name="phone_number">Phone Number</string>
<string name="error_insert_location">Please insert a location</string>
<string name="error_insert_text">Please insert a text to share</string>
<string name="share_subject">Sharing a text</string>
<string name="share_using">Share using</string>
<string name="error_insert_phone_number">Please insert a valid phone number</string>
</resources>
2 changes: 1 addition & 1 deletion app/src/main/res/values/themes.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Theme.AndroidFundamentalsMai2021" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<style name="Theme.AndroidFundamentalsMai2021" parent="Theme.AppCompat.Light">
<!-- Primary brand color. -->
<item name="colorPrimary">@color/purple_500</item>
<item name="colorPrimaryVariant">@color/purple_700</item>
Expand Down