mirror of
https://github.com/ClaytonWWilson/Listify.git
synced 2025-12-16 02:38:47 +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:supportsRtl="true"
|
||||
android:theme="@style/AppTheme">
|
||||
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
android:label="@string/app_name"
|
||||
@ -18,32 +19,13 @@
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</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
|
||||
android:name=".SearchResults"
|
||||
android:label=""
|
||||
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>
|
||||
</application>
|
||||
|
||||
|
||||
@ -54,13 +54,12 @@ public class MainActivity extends AppCompatActivity {
|
||||
searchButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
// onSearchRequested();
|
||||
Intent intent = new Intent(MainActivity.this, SearchResults.class);
|
||||
// Send them to the search results page
|
||||
|
||||
// Send user to SearchResults activity
|
||||
startActivity(intent);
|
||||
overridePendingTransition(R.anim.enter_from_left, R.anim.exit_from_left);
|
||||
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@ -1,20 +1,14 @@
|
||||
package com.example.listify;
|
||||
|
||||
import android.app.SearchManager;
|
||||
import android.content.Intent;
|
||||
import android.media.Image;
|
||||
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.EditText;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.ListView;
|
||||
import android.widget.SearchView;
|
||||
import android.widget.Toast;
|
||||
|
||||
public class SearchResults extends AppCompatActivity {
|
||||
|
||||
@ -25,6 +19,7 @@ public class SearchResults extends AppCompatActivity {
|
||||
Toolbar toolbar = findViewById(R.id.toolbar);
|
||||
setSupportActionBar(toolbar);
|
||||
|
||||
// Back button closes this activity and returns to previous activity (MainActivity)
|
||||
ImageButton backButton = (ImageButton) findViewById(R.id.backToHomeButton);
|
||||
backButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
@ -34,23 +29,32 @@ public class SearchResults extends AppCompatActivity {
|
||||
}
|
||||
});
|
||||
|
||||
// Intent intent = getIntent();
|
||||
// if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
|
||||
// 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();
|
||||
// Set the search bar to be active and focused
|
||||
final SearchView searchView = (SearchView) findViewById(R.id.searchBar);
|
||||
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() {
|
||||
@Override
|
||||
public boolean onQueryTextSubmit(String query) {
|
||||
doSearch(query);
|
||||
// TODO: Display the search results listview
|
||||
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
|
||||
public void onBackPressed() {
|
||||
super.onBackPressed();
|
||||
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) {
|
||||
System.out.println(query);
|
||||
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>
|
||||
|
||||
<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" />-->
|
||||
|
||||
<include layout="@layout/content_search_results" />\
|
||||
</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>
|
||||
@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:label="@string/app_label"
|
||||
android:hint="@string/search_hint" >
|
||||
android:label="@string/app_label"
|
||||
android:hint="@string/search_hint" >
|
||||
</searchable>
|
||||
Loading…
Reference in New Issue
Block a user