Skip to content
Snippets Groups Projects
Commit 3db2b891 authored by Alasdair Bruce SD2018's avatar Alasdair Bruce SD2018
Browse files

Updated Search functions and added background to textview

parent f78f0879
No related branches found
No related tags found
No related merge requests found
No preview for this file type
File added
......@@ -3,14 +3,11 @@
<component name="GradleSettings">
<option name="linkedExternalProjectsSettings">
<GradleProjectSettings>
<compositeConfiguration>
<compositeBuild compositeDefinitionSource="SCRIPT" />
</compositeConfiguration>
<option name="distributionType" value="DEFAULT_WRAPPED" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="modules">
<set>
<option value="$PROJECT_DIR$" />
<option value="$PROJECT_DIR$/app" />
</set>
</option>
<option name="resolveModulePerSourceSet" value="false" />
</GradleProjectSettings>
</option>
......
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="NullableNotNullManager">
<option name="myDefaultNullable" value="android.support.annotation.Nullable" />
<option name="myDefaultNotNull" value="android.support.annotation.NonNull" />
<option name="myNullables">
<value>
<list size="5">
<item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.Nullable" />
<item index="1" class="java.lang.String" itemvalue="javax.annotation.Nullable" />
<item index="2" class="java.lang.String" itemvalue="javax.annotation.CheckForNull" />
<item index="3" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.Nullable" />
<item index="4" class="java.lang.String" itemvalue="android.support.annotation.Nullable" />
</list>
</value>
</option>
<option name="myNotNulls">
<value>
<list size="4">
<item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.NotNull" />
<item index="1" class="java.lang.String" itemvalue="javax.annotation.Nonnull" />
<item index="2" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.NonNull" />
<item index="3" class="java.lang.String" itemvalue="android.support.annotation.NonNull" />
</list>
</value>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="JDK" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">
......
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
</component>
</project>
\ No newline at end of file
......@@ -10,7 +10,7 @@ public class Book {
author = "";
}
public Book(String title, String author) {
public Book(String author, String title) {
this.title = title;
this.author = author;
}
......
......@@ -23,12 +23,11 @@ public class BookDatabase {
public Book search(String title) {
for (int i = 0; i < books.size(); i++) {
if (title.equals(books.get(i).getTitle())) {
if (title.trim().toLowerCase().equals(books.get(i).getTitle().trim().toLowerCase())) {
return books.get(i);
}
}
Book b = new Book();
return b;
return null;
}
}
......@@ -21,11 +21,13 @@ public class MainActivity extends AppCompatActivity {
// send btn
public void sendMessage(View view){
EditText editText1 = (EditText) findViewById(R.id.editText1);
EditText editText2 = (EditText) findViewById(R.id.editText2);
EditText editText1 = findViewById(R.id.editText1);
EditText editText2 = findViewById(R.id.editText2);
String message1 = editText1.getText().toString();
String message2 = editText2.getText().toString();
books.addBook(new Book(message1, message2));
editText1.getText().clear();
editText2.getText().clear();
}
......@@ -44,22 +46,17 @@ public class MainActivity extends AppCompatActivity {
//display users
public void searchByTitle(View view){
TextView textView1 = findViewById((R.id.textView2));
textView1.setText("");
EditText editText1 = findViewById(R.id.editText3);
String message1 = editText1.getText().toString();
Book book1 = books.search(message1);
if(book1 != null){
textView1.setText(book1.getAuthor());
String result = "Author: " + book1.getAuthor() + "\n" + "Title: " + book1.getTitle();
textView1.setText(result);
}
else {
textView1.setText(R.string.search_rejection);
}
editText1.getText().clear();
}
}
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<!-- View background color -->
<solid
android:color="@color/backgroundColour" >
</solid>
<!-- View border color and width -->
<stroke
android:width="1dp"
android:color="@color/borderColour" >
</stroke>
<!-- The radius makes the corners rounded -->
<corners
android:radius="2dp" >
</corners>
</shape>
\ No newline at end of file
......@@ -82,13 +82,17 @@
<TextView
android:id="@+id/textView2"
android:layout_width="0dp"
android:layout_height="45dp"
android:layout_marginEnd="8dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="8dp"
android:layout_height="131dp"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:layout_marginTop="8dp"
android:text="TextView"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:background="@drawable/my_border"
android:fadingEdge="horizontal"
android:text="Search Results"
android:textSize="15sp"
android:textStyle="bold"
app:layout_constraintEnd_toStartOf="@+id/button2"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/editText3" />
......
......@@ -3,4 +3,6 @@
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FF4081</color>
<color name="backgroundColour">@android:color/darker_gray</color>
<color name="borderColour">@android:color/black</color>
</resources>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment