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 @@ -11,7 +11,9 @@
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_3.Activity2" />
<activity android:name=".code_challenge_3.Activity1" />
<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_3.Activity1;

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 startActivity1OnClick(View view) {
Intent intentToStartActivity1 = new Intent(StartActivity.this, Activity1.class);
startActivity(intentToStartActivity1);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.magdamiu.androidfundamentalsmai2021.code_challenge_3;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.magdamiu.androidfundamentalsmai2021.R;

public class Activity1 extends AppCompatActivity {

protected static final String MESSAGE = "Message";
private TextView textViewReplyReceived, textViewReply;
private EditText editTextMessage;
private static final String REPLY_RECEIVED = "Reply received";

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_1);
textViewReplyReceived = findViewById(R.id.textViewReplyReceived);
textViewReply = findViewById(R.id.textViewMessageActivities);
editTextMessage = findViewById(R.id.editTextMessage);

processBundle();
}

private void processBundle() {
Bundle bundle = getIntent().getExtras();
if (bundle != null) {
String reply = bundle.getString(Activity1.MESSAGE);
textViewReplyReceived.setText(REPLY_RECEIVED);
textViewReply.setText(reply);
}
}

public void sendMessageOnClick(View view) {
String message = editTextMessage.getText().toString();
if (!message.isEmpty()) {
Intent intentToStartActivity2 = new Intent(Activity1.this, Activity2.class);
intentToStartActivity2.putExtra(MESSAGE, message);
startActivity(intentToStartActivity2);
} else {
editTextMessage.setError(getString(R.string.error_insert_message));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.magdamiu.androidfundamentalsmai2021.code_challenge_3;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

import com.magdamiu.androidfundamentalsmai2021.R;

public class Activity2 extends AppCompatActivity {

private static final String MESSAGE_RECEIVED = "Message received";
private TextView textViewMessageReceived, textViewMessage;
private EditText editTextReply;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_2);
textViewMessageReceived = findViewById(R.id.textViewMessageReceived);
textViewMessage = findViewById(R.id.textViewMessage);
editTextReply = findViewById(R.id.editTextReply);

processBundle();
}

private void processBundle() {
Bundle bundle = getIntent().getExtras();
if (bundle != null) {
String messageReceived = bundle.getString(Activity1.MESSAGE);
textViewMessageReceived.setText(MESSAGE_RECEIVED);
textViewMessage.setText(messageReceived);
}
}

public void sendReplyOnClick(View view) {
String reply = editTextReply.getText().toString();
if (!reply.isEmpty()) {
Intent intentToStartActivity1 = new Intent(Activity2.this, Activity1.class);
intentToStartActivity1.putExtra(Activity1.MESSAGE, reply);
startActivity(intentToStartActivity1);
} else {
editTextReply.setError(getString(R.string.error_insert_reply));
}
}
}
58 changes: 58 additions & 0 deletions app/src/main/res/layout/activity_1.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?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_3.Activity1">

<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:layout_marginTop="16dp"
android:orientation="vertical"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">

<TextView
android:id="@+id/textViewReplyReceived"
android:layout_width="wrap_content"
android:textColor="@color/black"
android:layout_height="wrap_content"
android:textSize="@dimen/size_18"
android:textStyle="bold" />

<TextView
android:id="@+id/textViewMessageActivities"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="@dimen/size_16" />

</LinearLayout>

<EditText
android:id="@+id/editTextMessage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:layout_marginBottom="16dp"
android:autofillHints="@string/message"
android:ems="10"
android:hint="@string/message"
android:inputType="text"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent" />

<Button
android:id="@+id/buttonSend1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/space_64"
android:layout_marginBottom="16dp"
android:onClick="sendMessageOnClick"
android:text="@string/send"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@+id/editTextMessage" />
</androidx.constraintlayout.widget.ConstraintLayout>
59 changes: 59 additions & 0 deletions app/src/main/res/layout/activity_2.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?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_3.Activity2">

<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:orientation="vertical"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">

<TextView
android:id="@+id/textViewMessageReceived"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/black"
android:textSize="@dimen/size_18"
android:textStyle="bold" />

<TextView
android:id="@+id/textViewMessage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="@dimen/size_16" />

</LinearLayout>

<EditText
android:id="@+id/editTextReply"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:layout_marginBottom="16dp"
android:autofillHints="@string/message"
android:ems="10"
android:hint="@string/message"
android:inputType="text"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent" />

<Button
android:id="@+id/buttonSend2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/space_64"
android:layout_marginBottom="16dp"
android:onClick="sendReplyOnClick"
android:text="@string/send"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@+id/editTextReply" />

</androidx.constraintlayout.widget.ConstraintLayout>
7 changes: 6 additions & 1 deletion app/src/main/res/layout/activity_start.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
Expand Down Expand Up @@ -31,4 +30,10 @@
android:layout_height="wrap_content"
android:text="@string/start_firstactivity"
android:onClick="startFirstActivityOnClick"/>

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/start_code_challenge_3"
android:onClick="startActivity1OnClick"/>
</LinearLayout>
2 changes: 2 additions & 0 deletions app/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@
<dimen name="medium_space">16dp</dimen>
<dimen name="space_128">128dp</dimen>
<dimen name="space_64">64dp</dimen>
<dimen name="size_18">18sp</dimen>
<dimen name="size_16">16sp</dimen>
</resources>
5 changes: 5 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,9 @@ 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="message">Message</string>
<string name="send">Send</string>
<string name="error_insert_message">Please insert a message</string>
<string name="error_insert_reply">Please insert a reply</string>
<string name="start_code_challenge_3">Start Code Challenge 3</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