Skip to content
This repository has been archived by the owner on Apr 3, 2023. It is now read-only.

Commit

Permalink
Changed to new version
Browse files Browse the repository at this point in the history
  • Loading branch information
mstrelex committed Jul 11, 2018
1 parent e6bfd46 commit 9a325ad
Show file tree
Hide file tree
Showing 16 changed files with 408 additions and 123 deletions.
3 changes: 2 additions & 1 deletion app/build.gradle
Expand Up @@ -2,7 +2,7 @@ apply plugin: 'com.android.application'

android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
buildToolsVersion '27.0.3'
defaultConfig {
applicationId "io.testproject.demo"
minSdkVersion 15
Expand All @@ -20,6 +20,7 @@ android {
}

dependencies {
implementation 'com.android.support:design:25.4.0'
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Expand Up @@ -9,13 +9,13 @@
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">

<intent-filter android:label="@string/main_activity_title">
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".ProfileActivity"></activity>
</application>

</manifest>
Binary file modified app/src/main/ic_launcher-web.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
84 changes: 42 additions & 42 deletions app/src/main/java/io/testproject/demo/MainActivity.java
@@ -1,10 +1,16 @@
package io.testproject.demo;

import android.content.BroadcastReceiver;
import android.content.Intent;
import android.content.IntentFilter;
import android.hardware.usb.UsbManager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.KeyEvent;
import android.view.View;
import android.view.inputmethod.EditorInfo;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
Expand All @@ -17,59 +23,53 @@

public class MainActivity extends AppCompatActivity {

private EditText firstName;
private EditText lastName;
private TextView fullName;
private TextView welcome;

private List<String> names;
private ArrayAdapter<String> namesAdapter;
private EditText txtName;
private EditText txtPassword;

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

// Acquire references to UI widgets
this.firstName = (EditText) findViewById(R.id.firstName);
this.lastName = (EditText) findViewById(R.id.lastName);
this.fullName = (TextView) findViewById(R.id.fullName);

// Update Full Name when First/Last names change
this.firstName.addTextChangedListener(getFullNameTextWatcher());
this.lastName.addTextChangedListener(getFullNameTextWatcher());
this.txtName = (EditText) findViewById(R.id.name);
this.txtPassword = (EditText) findViewById(R.id.password);

// Setup Persons ListView
this.names = new ArrayList<>();
namesAdapter =
new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, names);
ListView listView = (ListView) findViewById(R.id.persons);
listView.setAdapter(namesAdapter);
// Submit when password provided
txtPassword.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView view, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_DONE) {
performLogin(null);
return true;
}
return false;
}});
}

public void addPerson(View view) {
names.add(fullName.getText().toString());
namesAdapter.notifyDataSetInvalidated();

public void performLogin(View view) {
boolean hasErrors = false;

if (txtName.getText().length() == 0) {
txtName.setError("Please provide your name");
hasErrors = true;
} else {
txtName.setError(null);
}

if (!txtPassword.getText().toString().equals("12345")) {
txtPassword.setError("This password is incorrect");
hasErrors = true;
} else {
txtPassword.setError(null);
}

if (!hasErrors) {
Intent intent = new Intent(MainActivity.this,ProfileActivity.class);
intent.putExtra("FULL_NAME", txtName.getText().toString());
startActivity(intent);
}
}

private TextWatcher getFullNameTextWatcher() {
return new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {

}

@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {

fullName.setText(firstName.getText() + " " + lastName.getText());
}

@Override
public void afterTextChanged(Editable s) {

}
};
}
}
93 changes: 93 additions & 0 deletions app/src/main/java/io/testproject/demo/ProfileActivity.java
@@ -0,0 +1,93 @@
package io.testproject.demo;

import android.content.Intent;
import android.graphics.Color;
import android.graphics.Typeface;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.SpannableString;
import android.text.style.StyleSpan;
import android.text.style.UnderlineSpan;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Locale;

public class ProfileActivity extends AppCompatActivity {

private TextView lblGreetings;
private EditText txtCountry;
private EditText txtAddress;
private EditText txtEmail;
private EditText txtPhone;
private TextView txtSaved;

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

// Acquire references to UI widgets
this.lblGreetings = (TextView) findViewById(R.id.greetings);
this.txtCountry = (EditText) findViewById(R.id.country);
this.txtAddress = (EditText) findViewById(R.id.address);
this.txtEmail = (EditText) findViewById(R.id.email);
this.txtPhone = (EditText) findViewById(R.id.phone);
this.txtSaved = (TextView) findViewById(R.id.saved);

// Say Hi
String greetings = "Hello " + getIntent().getStringExtra("FULL_NAME");
SpannableString spanString = new SpannableString(greetings);
spanString.setSpan(new StyleSpan(Typeface.BOLD), 0, spanString.length(), 0);
lblGreetings.setText(spanString);

}

public void performLogout(View view) {
startActivity(new Intent(ProfileActivity.this,MainActivity.class));
}

public void performSave(View view) {

txtSaved.setVisibility(View.GONE);
boolean hasErrors = false;

if (txtCountry.getText().length() == 0) {
txtCountry.setError("Please enter your country");
hasErrors = true;
} else {
txtCountry.setError(null);
}

if (txtAddress.getText().length() == 0) {
txtAddress.setError("Please enter your address");
hasErrors = true;
} else {
txtAddress.setError(null);
}

if (txtEmail.getText().length() == 0) {
txtEmail.setError("Please enter your email");
hasErrors = true;
} else {
txtEmail.setError(null);
}

if (txtPhone.getText().length() == 0) {
txtPhone.setError("Please enter your phone number");
hasErrors = true;
} else {
txtPhone.setError(null);
}

if (!hasErrors) {
txtSaved.setVisibility(View.VISIBLE);
}
}
}

0 comments on commit 9a325ad

Please sign in to comment.