diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 9312351..591c138 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -11,8 +11,8 @@ android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/Theme.AndroidFundamentalsMai2021"> - - + + diff --git a/app/src/main/java/com/magdamiu/androidfundamentalsmai2021/StartActivity.java b/app/src/main/java/com/magdamiu/androidfundamentalsmai2021/StartActivity.java index 3a1a9c0..10e2877 100644 --- a/app/src/main/java/com/magdamiu/androidfundamentalsmai2021/StartActivity.java +++ b/app/src/main/java/com/magdamiu/androidfundamentalsmai2021/StartActivity.java @@ -6,7 +6,7 @@ import android.os.Bundle; import android.view.View; -import com.magdamiu.androidfundamentalsmai2021.activities.FirstActivity; +import com.magdamiu.androidfundamentalsmai2021.course5codechallenge1.FirstActivity; public class StartActivity extends AppCompatActivity { diff --git a/app/src/main/java/com/magdamiu/androidfundamentalsmai2021/activities/FirstActivity.java b/app/src/main/java/com/magdamiu/androidfundamentalsmai2021/activities/FirstActivity.java deleted file mode 100644 index a1546ec..0000000 --- a/app/src/main/java/com/magdamiu/androidfundamentalsmai2021/activities/FirstActivity.java +++ /dev/null @@ -1,115 +0,0 @@ -package com.magdamiu.androidfundamentalsmai2021.activities; - -import androidx.annotation.Nullable; -import androidx.appcompat.app.AppCompatActivity; - -import android.content.Intent; -import android.net.Uri; -import android.os.Bundle; -import android.util.Log; -import android.view.View; -import android.widget.EditText; -import android.widget.Toast; - -import com.magdamiu.androidfundamentalsmai2021.R; - -import java.net.URI; - -import static com.magdamiu.androidfundamentalsmai2021.R.string.use_device_with_sim; - -public class FirstActivity extends AppCompatActivity { - protected static final String MESSAGE = "message"; - protected static final int REQUEST_CODE_FIRST_ACTIVITY = 255; - private static final String FIRST_TAG = "FirstActivity"; - - - private EditText editTextMessage; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_first); - Log.e(FIRST_TAG, "onCreate method was called"); - - editTextMessage = findViewById(R.id.editTextMessage); - } - - @Override - protected void onStart() { - super.onStart(); - Log.e(FIRST_TAG, "onStart method was called"); - } - - @Override - protected void onResume() { - super.onResume(); - Log.e(FIRST_TAG, "onResume method was called"); - } - - @Override - protected void onPause() { - super.onPause(); - Log.e(FIRST_TAG, "onPause method was called"); - } - - @Override - protected void onStop() { - super.onStop(); - Log.e(FIRST_TAG, "onStop method was called"); - } - - @Override - protected void onDestroy() { - super.onDestroy(); - Log.e(FIRST_TAG, "onDestroy method was called"); - } - - @Override - protected void onRestart() { - super.onRestart(); - Log.e(FIRST_TAG, "onRestart method was called"); - } - - public void startSecondActivityOnClick(View view) { - Intent intentToStartSecondActivity = new Intent(FirstActivity.this, SecondActivity.class); - intentToStartSecondActivity.putExtra(MESSAGE, getString(R.string.hello_from_first_activity)); - startActivity(intentToStartSecondActivity); - } - - public void callPhoneNumberOnClick(View view) { - Intent callPhoneNumber = new Intent(Intent.ACTION_DIAL); - callPhoneNumber.setData(Uri.parse("tel:0744444444")); - - if (callPhoneNumber.resolveActivity(getPackageManager()) != null) { - startActivity(callPhoneNumber); - } else { - Toast.makeText(FirstActivity.this, use_device_with_sim, Toast.LENGTH_LONG).show(); - } - } - - public void openURlInBrowserOnClick(View view) { - Intent openURLInBrowser = new Intent(Intent.ACTION_VIEW); - openURLInBrowser.setData(Uri.parse("http://www.twitter.com")); - startActivity(openURLInBrowser); - } - - public void sendMessageOnClick(View view) { - String message = editTextMessage.getText().toString(); - if (message.length() > 0) { - Intent startSecondActivity = new Intent(FirstActivity.this, SecondActivity.class); - startSecondActivity.putExtra(MESSAGE, message); - startActivityForResult(startSecondActivity, REQUEST_CODE_FIRST_ACTIVITY); - } - } - - @Override - protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { - super.onActivityResult(requestCode, resultCode, data); - - if (requestCode == REQUEST_CODE_FIRST_ACTIVITY && resultCode == RESULT_OK) { - String messageReceivedAsResult = data.getStringExtra(MESSAGE); - editTextMessage.setText(messageReceivedAsResult); - } - } - -} \ No newline at end of file diff --git a/app/src/main/java/com/magdamiu/androidfundamentalsmai2021/activities/SecondActivity.java b/app/src/main/java/com/magdamiu/androidfundamentalsmai2021/activities/SecondActivity.java deleted file mode 100644 index 4475293..0000000 --- a/app/src/main/java/com/magdamiu/androidfundamentalsmai2021/activities/SecondActivity.java +++ /dev/null @@ -1,120 +0,0 @@ -package com.magdamiu.androidfundamentalsmai2021.activities; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.appcompat.app.AppCompatActivity; - -import android.annotation.SuppressLint; -import android.content.Intent; -import android.os.Bundle; -import android.util.Log; -import android.widget.CheckBox; -import android.widget.EditText; -import android.widget.TextView; - -import com.magdamiu.androidfundamentalsmai2021.R; - -public class SecondActivity extends AppCompatActivity { - private static final String SECOND_TAG = "SecondActivity"; - private static final String PERSON_NAME = "personName"; - private static final String TERMS_AND_COND = "terms"; - - private TextView textViewMessage; - private EditText editTextPersonName; - private CheckBox checkBoxTermsAndConditions; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_second); - Log.e(SECOND_TAG, "onCreate method was called"); - - textViewMessage = findViewById(R.id.textViewMessage); - editTextPersonName = findViewById(R.id.editTextPersonName); - checkBoxTermsAndConditions = findViewById(R.id.checkBoxTermsAndConditions); - - //processBundle(); - } - - private void processBundle() { - Bundle bundle = getIntent().getExtras(); - if(bundle != null) { - String messageReceived = bundle.getString(FirstActivity.MESSAGE); - textViewMessage.setText(messageReceived); - - // process the message and send the result (dummy processing) - messageReceived = getString(R.string.confirm_message); - - // send back the result to the FirstActivity - Intent intent = new Intent(); - intent.putExtra(FirstActivity.MESSAGE, messageReceived); - setResult(RESULT_OK, intent); - - // close the current activity (remove it from the stack) - finish(); - } - } - - // cache the filled data - // @SuppressLint("MissingSuperCall") - @Override - protected void onSaveInstanceState(@NonNull Bundle outState) { - super.onSaveInstanceState(outState); - Log.e(SECOND_TAG, "onSaveInstanceState method was called"); - - //TODO check for null - String personName = editTextPersonName.getText().toString(); - outState.putString(PERSON_NAME, personName); - - boolean isTermsAndCondChecked = checkBoxTermsAndConditions.isChecked(); - outState.putBoolean(TERMS_AND_COND, isTermsAndCondChecked); - } - - // restore the cached data - @Override - protected void onRestoreInstanceState(@NonNull Bundle savedInstanceState) { - super.onRestoreInstanceState(savedInstanceState); - //TODO check for null - String personName = savedInstanceState.getString(PERSON_NAME); - editTextPersonName.setText(personName); - - boolean isTermsAndCondChecked = savedInstanceState.getBoolean(TERMS_AND_COND); - checkBoxTermsAndConditions.setChecked(isTermsAndCondChecked); - } - - @Override - protected void onStart() { - super.onStart(); - Log.e(SECOND_TAG, "onStart method was called"); - } - - @Override - protected void onResume() { - super.onResume(); - Log.e(SECOND_TAG, "onResume method was called"); - } - - @Override - protected void onPause() { - super.onPause(); - Log.e(SECOND_TAG, "onPause method was called"); - } - - @Override - protected void onStop() { - super.onStop(); - Log.e(SECOND_TAG, "onStop method was called"); - } - - @Override - protected void onDestroy() { - super.onDestroy(); - Log.e(SECOND_TAG, "onDestroy method was called"); - } - - @Override - protected void onRestart() { - super.onRestart(); - Log.e(SECOND_TAG, "onRestart method was called"); - } -} \ No newline at end of file diff --git a/app/src/main/java/com/magdamiu/androidfundamentalsmai2021/course5codechallenge1/FirstActivity.java b/app/src/main/java/com/magdamiu/androidfundamentalsmai2021/course5codechallenge1/FirstActivity.java new file mode 100644 index 0000000..fa92201 --- /dev/null +++ b/app/src/main/java/com/magdamiu/androidfundamentalsmai2021/course5codechallenge1/FirstActivity.java @@ -0,0 +1,63 @@ +package com.magdamiu.androidfundamentalsmai2021.course5codechallenge1; + +import androidx.appcompat.app.AppCompatActivity; + +import android.content.Intent; +import android.os.Bundle; +import android.util.Log; +import android.view.View; + +import com.magdamiu.androidfundamentalsmai2021.R; + +public class FirstActivity extends AppCompatActivity { + + private static final String FIRST_TAG = "FirstActivity"; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_first); + Log.e(FIRST_TAG, "onCreate method was called!"); + } + + @Override + protected void onStart() { + super.onStart(); + Log.e(FIRST_TAG, "onStart method was called!"); + } + + @Override + protected void onResume() { + super.onResume(); + Log.e(FIRST_TAG, "onResume method was called!"); + } + + @Override + protected void onPause() { + super.onPause(); + Log.e(FIRST_TAG, "onPause method was called!"); + } + + @Override + protected void onStop() { + super.onStop(); + Log.e(FIRST_TAG, "onStop method was called!"); + } + + @Override + protected void onDestroy() { + super.onDestroy(); + Log.e(FIRST_TAG, "onDestroy method was called!"); + } + + @Override + protected void onRestart() { + super.onRestart(); + Log.e(FIRST_TAG, "onRestart method was called!"); + } + + public void startSecondActivityOnClick(View view) { + Intent intentToStartSecondActivity = new Intent(FirstActivity.this, SecondActivity.class); + startActivity(intentToStartSecondActivity); + } +} \ No newline at end of file diff --git a/app/src/main/java/com/magdamiu/androidfundamentalsmai2021/course5codechallenge1/SecondActivity.java b/app/src/main/java/com/magdamiu/androidfundamentalsmai2021/course5codechallenge1/SecondActivity.java new file mode 100644 index 0000000..4b99603 --- /dev/null +++ b/app/src/main/java/com/magdamiu/androidfundamentalsmai2021/course5codechallenge1/SecondActivity.java @@ -0,0 +1,56 @@ +package com.magdamiu.androidfundamentalsmai2021.course5codechallenge1; + +import androidx.appcompat.app.AppCompatActivity; + +import android.os.Bundle; +import android.util.Log; + +import com.magdamiu.androidfundamentalsmai2021.R; + +public class SecondActivity extends AppCompatActivity { + + private static final String SECOND_TAG = "SecondActivity"; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_second); + Log.e(SECOND_TAG, "onCreate method was called!"); + } + + @Override + protected void onStart() { + super.onStart(); + Log.e(SECOND_TAG, "onStart method was called!"); + } + + @Override + protected void onResume() { + super.onResume(); + Log.e(SECOND_TAG, "onResume method was called!"); + } + + @Override + protected void onPause() { + super.onPause(); + Log.e(SECOND_TAG, "onPause method was called!"); + } + + @Override + protected void onStop() { + super.onStop(); + Log.e(SECOND_TAG, "onStop method was called!"); + } + + @Override + protected void onDestroy() { + super.onDestroy(); + Log.e(SECOND_TAG, "onDestroy method was called!"); + } + + @Override + protected void onRestart() { + super.onRestart(); + Log.e(SECOND_TAG, "onRestart method was called!"); + } +} \ No newline at end of file diff --git a/app/src/main/res/layout/activity_first.xml b/app/src/main/res/layout/activity_first.xml index 1b82918..6e08424 100644 --- a/app/src/main/res/layout/activity_first.xml +++ b/app/src/main/res/layout/activity_first.xml @@ -4,61 +4,16 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" - tools:context=".activities.FirstActivity"> + tools:context=".course5codechallenge1.FirstActivity">