mirror of
https://github.com/ClaytonWWilson/Listify.git
synced 2025-12-16 18:48:48 +00:00
Cleaning up code and comments
This commit is contained in:
parent
af2bc752a5
commit
9449b9a350
@ -9,6 +9,7 @@
|
|||||||
android:roundIcon="@mipmap/ic_launcher_round"
|
android:roundIcon="@mipmap/ic_launcher_round"
|
||||||
android:supportsRtl="true"
|
android:supportsRtl="true"
|
||||||
android:theme="@style/AppTheme">
|
android:theme="@style/AppTheme">
|
||||||
|
|
||||||
<activity
|
<activity
|
||||||
android:name=".MainActivity"
|
android:name=".MainActivity"
|
||||||
android:label="@string/app_name"
|
android:label="@string/app_name"
|
||||||
@ -18,32 +19,13 @@
|
|||||||
|
|
||||||
<category android:name="android.intent.category.LAUNCHER" />
|
<category android:name="android.intent.category.LAUNCHER" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
|
|
||||||
<!-- Enable Searching from main activity -->
|
|
||||||
<!-- <meta-data-->
|
|
||||||
<!-- android:name="android.app.default_searchable"-->
|
|
||||||
<!-- android:value=".SearchResults" />-->
|
|
||||||
</activity> <!-- Searchable activity used to handle searches -->
|
|
||||||
<activity
|
|
||||||
android:name=".SearchableActivity"
|
|
||||||
android:label="@string/title_activity_search"
|
|
||||||
android:theme="@style/AppTheme.NoActionBar">
|
|
||||||
<!-- <intent-filter>-->
|
|
||||||
<!-- <action android:name="android.intent.action.SEARCH" />-->
|
|
||||||
<!-- </intent-filter>-->
|
|
||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
<activity
|
<activity
|
||||||
android:name=".SearchResults"
|
android:name=".SearchResults"
|
||||||
android:label=""
|
android:label=""
|
||||||
android:theme="@style/AppTheme.NoActionBar"
|
android:theme="@style/AppTheme.NoActionBar"
|
||||||
>
|
>
|
||||||
<!-- <intent-filter>-->
|
|
||||||
<!-- <action android:name="android.intent.action.SEARCH" />-->
|
|
||||||
<!-- </intent-filter>-->
|
|
||||||
|
|
||||||
<!-- <meta-data-->
|
|
||||||
<!-- android:name="android.app.searchable"-->
|
|
||||||
<!-- android:resource="@xml/searchable" />-->
|
|
||||||
</activity>
|
</activity>
|
||||||
</application>
|
</application>
|
||||||
|
|
||||||
|
|||||||
@ -54,13 +54,12 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
searchButton.setOnClickListener(new View.OnClickListener() {
|
searchButton.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
// onSearchRequested();
|
|
||||||
Intent intent = new Intent(MainActivity.this, SearchResults.class);
|
Intent intent = new Intent(MainActivity.this, SearchResults.class);
|
||||||
// Send them to the search results page
|
|
||||||
|
// Send user to SearchResults activity
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
overridePendingTransition(R.anim.enter_from_left, R.anim.exit_from_left);
|
overridePendingTransition(R.anim.enter_from_left, R.anim.exit_from_left);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,20 +1,14 @@
|
|||||||
package com.example.listify;
|
package com.example.listify;
|
||||||
|
import android.media.Image;
|
||||||
import android.app.SearchManager;
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
|
||||||
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
|
||||||
import com.google.android.material.snackbar.Snackbar;
|
|
||||||
|
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
import androidx.appcompat.widget.Toolbar;
|
import androidx.appcompat.widget.Toolbar;
|
||||||
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.widget.EditText;
|
||||||
import android.widget.ImageButton;
|
import android.widget.ImageButton;
|
||||||
|
import android.widget.ImageView;
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
import android.widget.SearchView;
|
import android.widget.SearchView;
|
||||||
import android.widget.Toast;
|
|
||||||
|
|
||||||
public class SearchResults extends AppCompatActivity {
|
public class SearchResults extends AppCompatActivity {
|
||||||
|
|
||||||
@ -25,6 +19,7 @@ public class SearchResults extends AppCompatActivity {
|
|||||||
Toolbar toolbar = findViewById(R.id.toolbar);
|
Toolbar toolbar = findViewById(R.id.toolbar);
|
||||||
setSupportActionBar(toolbar);
|
setSupportActionBar(toolbar);
|
||||||
|
|
||||||
|
// Back button closes this activity and returns to previous activity (MainActivity)
|
||||||
ImageButton backButton = (ImageButton) findViewById(R.id.backToHomeButton);
|
ImageButton backButton = (ImageButton) findViewById(R.id.backToHomeButton);
|
||||||
backButton.setOnClickListener(new View.OnClickListener() {
|
backButton.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
@ -34,23 +29,32 @@ public class SearchResults extends AppCompatActivity {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Intent intent = getIntent();
|
// Set the search bar to be active and focused
|
||||||
// if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
|
final SearchView searchView = (SearchView) findViewById(R.id.searchBar);
|
||||||
// String query = intent.getStringExtra(SearchManager.QUERY);
|
|
||||||
// Toast.makeText(this, query, Toast.LENGTH_SHORT).show();
|
|
||||||
// doSearch();
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
SearchManager searchManager = (SearchManager) getSystemService(SEARCH_SERVICE);
|
|
||||||
SearchView searchView = (SearchView) findViewById(R.id.searchBar);
|
|
||||||
// searchView.requestFocus();
|
|
||||||
searchView.setIconified(false);
|
searchView.setIconified(false);
|
||||||
|
|
||||||
|
// There's no easy way to find the close button on the search bar, so this is the way I'm
|
||||||
|
// doing it
|
||||||
|
int searchCloseButtonId = searchView.getContext().getResources().getIdentifier("android:id/search_close_btn", null, null);
|
||||||
|
ImageView closeButton = (ImageView) searchView.findViewById(searchCloseButtonId);
|
||||||
|
closeButton.setOnClickListener(new View.OnClickListener() {
|
||||||
|
// Override default close behavior to only clear the search text and the query
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
// Finding the edit text of the search bar. Same as the method above
|
||||||
|
int searchTextId = searchView.getContext().getResources().getIdentifier("android:id/search_src_text", null, null);
|
||||||
|
EditText searchText = (EditText) searchView.findViewById(searchTextId);
|
||||||
|
searchText.setText("");
|
||||||
|
searchView.setQuery("", false);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Handle searches
|
||||||
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
|
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
|
||||||
@Override
|
@Override
|
||||||
public boolean onQueryTextSubmit(String query) {
|
public boolean onQueryTextSubmit(String query) {
|
||||||
doSearch(query);
|
doSearch(query);
|
||||||
|
// TODO: Display the search results listview
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -60,25 +64,17 @@ public class SearchResults extends AppCompatActivity {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// searchView.setSearchableInfo(searchManager.getSearchableInfo((getComponentName())));
|
|
||||||
// searchView.setSubmitButtonEnabled(true);
|
|
||||||
|
|
||||||
// FloatingActionButton fab = findViewById(R.id.fab);
|
|
||||||
// fab.setOnClickListener(new View.OnClickListener() {
|
|
||||||
// @Override
|
|
||||||
// public void onClick(View view) {
|
|
||||||
// Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
|
|
||||||
// .setAction("Action", null).show();
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Override default phone back button to add animation
|
||||||
@Override
|
@Override
|
||||||
public void onBackPressed() {
|
public void onBackPressed() {
|
||||||
super.onBackPressed();
|
super.onBackPressed();
|
||||||
overridePendingTransition(R.anim.enter_from_right, R.anim.exit_from_right);
|
overridePendingTransition(R.anim.enter_from_right, R.anim.exit_from_right);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: This function will handle the search operation with the database and return
|
||||||
|
// a listview to caller to be displayed
|
||||||
private ListView doSearch(String query) {
|
private ListView doSearch(String query) {
|
||||||
System.out.println(query);
|
System.out.println(query);
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@ -1,49 +0,0 @@
|
|||||||
package com.example.listify;
|
|
||||||
|
|
||||||
//import android.app.ListActivity;
|
|
||||||
import android.app.SearchManager;
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.os.Bundle;
|
|
||||||
|
|
||||||
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
|
||||||
import com.google.android.material.snackbar.Snackbar;
|
|
||||||
|
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
|
||||||
import androidx.appcompat.widget.Toolbar;
|
|
||||||
|
|
||||||
import android.view.View;
|
|
||||||
import android.widget.ImageButton;
|
|
||||||
|
|
||||||
public class SearchableActivity extends AppCompatActivity {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
|
||||||
super.onCreate(savedInstanceState);
|
|
||||||
setContentView(R.layout.activity_searchable);
|
|
||||||
|
|
||||||
// Toolbar toolbar = findViewById(R.id.toolbar);
|
|
||||||
// setSupportActionBar(toolbar);
|
|
||||||
//
|
|
||||||
// FloatingActionButton fab = findViewById(R.id.fab);
|
|
||||||
// fab.setOnClickListener(new View.OnClickListener() {
|
|
||||||
// @Override
|
|
||||||
// public void onClick(View view) {
|
|
||||||
// Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
|
|
||||||
// .setAction("Action", null).show();
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
|
|
||||||
// Get search query and send it to doSearch()
|
|
||||||
Intent intent = getIntent();
|
|
||||||
if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
|
|
||||||
String query = intent.getStringExtra(SearchManager.QUERY);
|
|
||||||
doSearch(query);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: Implement database search and return results
|
|
||||||
// https://developer.android.com/guide/topics/search/search-dialog#SearchingYourData
|
|
||||||
public void doSearch(String query) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -41,14 +41,5 @@
|
|||||||
|
|
||||||
</com.google.android.material.appbar.AppBarLayout>
|
</com.google.android.material.appbar.AppBarLayout>
|
||||||
|
|
||||||
<include layout="@layout/content_search_results" />
|
<include layout="@layout/content_search_results" />\
|
||||||
|
|
||||||
<!-- <com.google.android.material.floatingactionbutton.FloatingActionButton-->
|
|
||||||
<!-- android:id="@+id/fab"-->
|
|
||||||
<!-- android:layout_width="wrap_content"-->
|
|
||||||
<!-- android:layout_height="wrap_content"-->
|
|
||||||
<!-- android:layout_gravity="bottom|end"-->
|
|
||||||
<!-- android:layout_margin="@dimen/fab_margin"-->
|
|
||||||
<!-- app:srcCompat="@android:drawable/ic_dialog_email" />-->
|
|
||||||
|
|
||||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
||||||
@ -1,33 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<androidx.coordinatorlayout.widget.CoordinatorLayout 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=".SearchableActivity">
|
|
||||||
|
|
||||||
<com.google.android.material.appbar.AppBarLayout
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:theme="@style/AppTheme.AppBarOverlay">
|
|
||||||
|
|
||||||
<androidx.appcompat.widget.Toolbar
|
|
||||||
android:id="@+id/toolbar"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="?attr/actionBarSize"
|
|
||||||
android:background="?attr/colorPrimary"
|
|
||||||
app:popupTheme="@style/AppTheme.PopupOverlay" />
|
|
||||||
|
|
||||||
</com.google.android.material.appbar.AppBarLayout>
|
|
||||||
|
|
||||||
<include layout="@layout/content_search" />
|
|
||||||
|
|
||||||
<com.google.android.material.floatingactionbutton.FloatingActionButton
|
|
||||||
android:id="@+id/fab"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_gravity="bottom|end"
|
|
||||||
android:layout_margin="@dimen/fab_margin"
|
|
||||||
app:srcCompat="@android:drawable/ic_dialog_email" />
|
|
||||||
|
|
||||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
|
||||||
@ -1,6 +0,0 @@
|
|||||||
<?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"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
app:layout_behavior="@string/appbar_scrolling_view_behavior"></androidx.constraintlayout.widget.ConstraintLayout>
|
|
||||||
Loading…
Reference in New Issue
Block a user