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
1 change: 1 addition & 0 deletions .idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.AndroidFundamentalsMai2021">
<activity android:name=".MainActivity">
<activity android:name=".ConstraintLayoutSampleActivity"></activity>
<activity android:name=".MainActivity" />
<activity android:name=".EmailsActivity" />
<activity android:name=".StartActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.magdamiu.androidfundamentalsmai2021;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

public class ConstraintLayoutSampleActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_constraint_layout_sample);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.magdamiu.androidfundamentalsmai2021;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import java.util.List;

public class EmailAdapter extends RecyclerView.Adapter<EmailViewHolder> {
private List<Mail> emails;

public EmailAdapter(List<Mail> emails) {
this.emails = emails;
}

// creates the item view, only the UI elements (it's like a template)
@NonNull
@Override
public EmailViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.email_item, parent, false);
return new EmailViewHolder(itemView);
}

// fills the item with the corresponding element from the list (data source)
@Override
public void onBindViewHolder(@NonNull EmailViewHolder holder, int position) {
Mail currentMail = emails.get(position);
holder.getTextViewSender().setText(currentMail.getSenderName());
holder.getTextViewSubject().setText(currentMail.getSubject());
}

// decides how many items to create in our recycler view
@Override
public int getItemCount() {
return emails.size();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.magdamiu.androidfundamentalsmai2021;

import android.view.View;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

// the class associated to the item of the recycler view
// each UI element from the item should have a dedicated field in this class
public class EmailViewHolder extends RecyclerView.ViewHolder {
final private TextView textViewSender;
final private TextView textViewSubject;

public EmailViewHolder(@NonNull View itemView) {
super(itemView);

textViewSender = itemView.findViewById(R.id.textViewSender);
textViewSubject = itemView.findViewById(R.id.textViewSubject);
}

public TextView getTextViewSender() {
return textViewSender;
}

public TextView getTextViewSubject() {
return textViewSubject;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package com.magdamiu.androidfundamentalsmai2021;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.os.Bundle;

import java.util.ArrayList;
import java.util.List;

public class EmailsActivity extends AppCompatActivity {

private List<Mail> emails;
private RecyclerView recyclerViewEmails;
private RecyclerView.LayoutManager layoutManager;
private EmailAdapter emailAdapter;

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

// data source for our RecyclerView
populateListOfEmails();

// init the ui elements
initView();

// set the linear layout manager to our recycler view
setLayoutManager();

// set the adapter to our recycler view
setAdapter();
}

private void initView() {
recyclerViewEmails = findViewById(R.id.recyclerViewEmails);
}

private void populateListOfEmails() {
emails = new ArrayList<>();
Mail newEmail = new Mail(1, "Magda", "Curs Android");
emails.add(newEmail);
for (int i = 1; i < 20; i++) {
int index = i + 1;
newEmail = new Mail(index, "Sender " + index, "Subject " + index);
emails.add(newEmail);
}
}

private void setLayoutManager() {
layoutManager = new LinearLayoutManager(this);
recyclerViewEmails.setLayoutManager(layoutManager);
}

private void setAdapter() {
emailAdapter = new EmailAdapter(emails);
recyclerViewEmails.setAdapter(emailAdapter);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.magdamiu.androidfundamentalsmai2021;

public class Mail {
private int id;
private String senderName;
private String subject;

public Mail(int id, String senderName, String subject) {
this.id = id;
this.senderName = senderName;
this.subject = subject;
}

public int getId() {
return id;
}

public void setId(int id) {
this.id = id;
}

public String getSenderName() {
return senderName;
}

public void setSenderName(String senderName) {
this.senderName = senderName;
}

public String getSubject() {
return subject;
}

public void setSubject(String subject) {
this.subject = subject;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.util.Patterns;
import android.view.View;
import android.webkit.WebView;
import android.widget.AdapterView;
Expand All @@ -21,6 +23,8 @@ public class MainActivity extends AppCompatActivity {
private static final String ANDROID_URL = "https://developer.android.com/";

private EditText editTextName;
private EditText editTextEmail;
private EditText editTextPhone;
private Button buttonDisplayGreetings;
private TextView textViewGreetings;

Expand All @@ -33,20 +37,22 @@ public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
/*setContentView(R.layout.activity_main);*/
/*setContentView(R.layout.sample);*/
// setContentView(R.layout.scrollview_sample);
// setContentView(R.layout.webview_sample);
/* setContentView(R.layout.activity_main);
setContentView(R.layout.sample);
setContentView(R.layout.code_challenge_c2);
setContentView(R.layout.scrollview_sample);
setContentView(R.layout.webview_sample);
setContentView(R.layout.spinner_sample);
setContentView(R.layout.code_challenge2_c3); */
setContentView(R.layout.code_challenge1_c3);

setAndroidVersions();
/* setAndroidVersions();
initialiseSpinnerAdapter();
setSpinnerAdapter();
handlingSpinnerListener();
handlingSpinnerListener(); */

//loadUrl();

// initViews();
// loadUrl();
initViews();
displayLogs();
}

Expand All @@ -60,6 +66,7 @@ private void setAndroidVersions() {
androidVersions.add("kitkat");
}


// step 2: initialise adapter for our spinner
// ArrayAdapter is a default adapter
private void initialiseSpinnerAdapter() {
Expand Down Expand Up @@ -89,18 +96,22 @@ public void onNothingSelected(AdapterView<?> adapterView) {
});
}


// webview load url
private void loadUrl() {
webView = findViewById(R.id.webViewSample);
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl(ANDROID_URL);
}


// init views for implementing a first simple form
private void initViews() {
editTextName = findViewById(R.id.editTextName);
buttonDisplayGreetings = findViewById(R.id.buttonDisplayGreetings);
textViewGreetings = findViewById(R.id.textViewGreetings);
editTextEmail = findViewById(R.id.editTextEmail);
editTextPhone = findViewById(R.id.editTextPhone);
}

private void displayLogs() {
Expand Down Expand Up @@ -128,4 +139,28 @@ public void displayGreetingsOnClick(View view) {
Toast.makeText(MainActivity.this, getString(R.string.error_insert_name), Toast.LENGTH_LONG).show();
}
}

// Course 3: Code Challenge 1
public static boolean isValidEmail(CharSequence target) {
return (!TextUtils.isEmpty(target) && Patterns.EMAIL_ADDRESS.matcher(target).matches());
}

public static boolean isValidPhone(CharSequence phone) {
return (!TextUtils.isEmpty(phone) && Patterns.PHONE.matcher(phone).matches());
}

public void displaySubmitOnClick(View view) {
String inputName = editTextEmail.getText().toString();
if (!isValidEmail(inputName)) {
editTextEmail.setError(getString(R.string.error_insert_email));
Toast.makeText(MainActivity.this, getString(R.string.error_insert_email),
Toast.LENGTH_LONG).show();
}
inputName = editTextPhone.getText().toString();
if (!isValidPhone(inputName)) {
editTextPhone.setError(getString(R.string.error_insert_phone));
Toast.makeText(MainActivity.this, getString(R.string.error_insert_phone),
Toast.LENGTH_LONG).show();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.magdamiu.androidfundamentalsmai2021;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;

public class StartActivity extends AppCompatActivity {

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

public void startMainActivityOnClick(View view) {
// starts from the current activity, and moves the user to the Main Activity screen
Intent intentToStartMainActivity = new Intent(StartActivity.this, MainActivity.class);
startActivity(intentToStartMainActivity);
}

public void startRecyclerViewActivityOnClick(View view) {
// starts from the current activity, and moves the user to the Emails Activity screen
Intent intentToStartEmailsActivity = new Intent(StartActivity.this, EmailsActivity.class);
startActivity(intentToStartEmailsActivity);
}

public void startConstraintActivity(View view) {
// starts from the current activity, and moves the user to the Constraint Activity screen
Intent intentToStartConstraintActivity = new Intent(StartActivity.this, ConstraintLayoutSampleActivity.class);
startActivity(intentToStartConstraintActivity);
}
}
Binary file added app/src/main/res/drawable/paint.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading