Loading res/layout/search_saved_query_item.xml 0 → 100644 +45 −0 Original line number Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <!-- Copyright (C) 2017 The Android Open Source Project Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="?android:attr/selectableItemBackground" android:minHeight="?android:attr/listPreferredItemHeight" android:gravity="center_vertical" android:paddingStart="@dimen/preference_no_icon_padding_start" android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"> <TextView android:id="@android:id/title" android:textAppearance="?android:attr/textAppearanceListItem" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_weight="1"/> <ImageView android:id="@android:id/icon" android:layout_width="@dimen/search_suggestion_item_image_size" android:layout_height="@dimen/search_suggestion_item_image_size" android:layout_marginStart="@dimen/search_suggestion_item_image_margin_start" android:layout_marginEnd="@dimen/search_suggestion_item_image_margin_end" android:scaleType="centerInside" android:src="@drawable/ic_search_history"/> </LinearLayout> No newline at end of file src/com/android/settings/search/Index.java +5 −5 Original line number Diff line number Diff line Loading @@ -266,7 +266,7 @@ public class Index { StringBuilder sb = new StringBuilder(); sb.append("SELECT "); sb.append(IndexDatabaseHelper.SavedQueriesColums.QUERY); sb.append(IndexDatabaseHelper.SavedQueriesColumns.QUERY); sb.append(" FROM "); sb.append(Tables.TABLE_SAVED_QUERIES); Loading @@ -274,7 +274,7 @@ public class Index { sb.append(" ORDER BY rowId DESC"); } else { sb.append(" WHERE "); sb.append(IndexDatabaseHelper.SavedQueriesColums.QUERY); sb.append(IndexDatabaseHelper.SavedQueriesColumns.QUERY); sb.append(" LIKE "); sb.append("'"); sb.append(query); Loading Loading @@ -1299,8 +1299,8 @@ public class Index { final long now = new Date().getTime(); final ContentValues values = new ContentValues(); values.put(IndexDatabaseHelper.SavedQueriesColums.QUERY, params[0]); values.put(IndexDatabaseHelper.SavedQueriesColums.TIME_STAMP, now); values.put(IndexDatabaseHelper.SavedQueriesColumns.QUERY, params[0]); values.put(IndexDatabaseHelper.SavedQueriesColumns.TIME_STAMP, now); final SQLiteDatabase database = getWritableDatabase(); if (database == null) { Loading @@ -1312,7 +1312,7 @@ public class Index { try { // First, delete all saved queries that are the same database.delete(Tables.TABLE_SAVED_QUERIES, IndexDatabaseHelper.SavedQueriesColums.QUERY + " = ?", IndexDatabaseHelper.SavedQueriesColumns.QUERY + " = ?", new String[] { params[0] }); // Second, insert the saved query Loading src/com/android/settings/search/IndexDatabaseHelper.java +3 −3 Original line number Diff line number Diff line Loading @@ -67,7 +67,7 @@ public class IndexDatabaseHelper extends SQLiteOpenHelper { String BUILD = "build"; } public interface SavedQueriesColums { public interface SavedQueriesColumns { String QUERY = "query"; String TIME_STAMP = "timestamp"; } Loading Loading @@ -127,9 +127,9 @@ public class IndexDatabaseHelper extends SQLiteOpenHelper { private static final String CREATE_SAVED_QUERIES_TABLE = "CREATE TABLE " + Tables.TABLE_SAVED_QUERIES + "(" + SavedQueriesColums.QUERY + " VARCHAR(64) NOT NULL" + SavedQueriesColumns.QUERY + " VARCHAR(64) NOT NULL" + ", " + SavedQueriesColums.TIME_STAMP + " INTEGER" + SavedQueriesColumns.TIME_STAMP + " INTEGER" + ")"; private static final String INSERT_BUILD_VERSION = Loading src/com/android/settings/search2/ResultPayload.java +8 −2 Original line number Diff line number Diff line Loading @@ -29,7 +29,7 @@ import java.lang.annotation.RetentionPolicy; public abstract class ResultPayload implements Parcelable { @IntDef({PayloadType.INLINE_SLIDER, PayloadType.INLINE_SWITCH, PayloadType.INTENT}) PayloadType.INTENT, PayloadType.SAVED_QUERY}) @Retention(RetentionPolicy.SOURCE) public @interface PayloadType { /** Loading @@ -46,6 +46,11 @@ public abstract class ResultPayload implements Parcelable { * Result is a inline widget, using a toggle widget as UI. */ int INLINE_SWITCH = 2; /** * Result is a recently saved query. */ int SAVED_QUERY = 3; } @IntDef({SettingsSource.UNKNOWN, SettingsSource.SYSTEM, SettingsSource.SECURE, Loading @@ -59,5 +64,6 @@ public abstract class ResultPayload implements Parcelable { } @ResultPayload.PayloadType public abstract int getType(); @ResultPayload.PayloadType public abstract int getType(); } src/com/android/settings/search2/SavedQueryLoader.java 0 → 100644 +77 −0 Original line number Diff line number Diff line /* * Copyright (C) 2017 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.settings.search2; import android.content.Context; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.support.annotation.VisibleForTesting; import com.android.settings.search.IndexDatabaseHelper; import com.android.settings.search.IndexDatabaseHelper.SavedQueriesColumns; import com.android.settings.utils.AsyncLoader; import java.util.ArrayList; import java.util.List; /** * Loader for recently searched queries. */ public class SavedQueryLoader extends AsyncLoader<List<SearchResult>> { // Max number of proposed suggestions @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE) static final int MAX_PROPOSED_SUGGESTIONS = 5; private final SQLiteDatabase mDatabase; public SavedQueryLoader(Context context) { super(context); mDatabase = IndexDatabaseHelper.getInstance(context).getReadableDatabase(); } @Override protected void onDiscardResult(List<SearchResult> result) { } @Override public List<SearchResult> loadInBackground() { Cursor cursor = mDatabase.query(IndexDatabaseHelper.Tables.TABLE_SAVED_QUERIES /* table */, new String[]{SavedQueriesColumns.QUERY} /* columns */, null /* selection */, null /* selectionArgs */, null /* groupBy */, null /* having */, "rowId DESC" /* orderBy */, String.valueOf(MAX_PROPOSED_SUGGESTIONS) /* limit */); return convertCursorToResult(cursor); } private List<SearchResult> convertCursorToResult(Cursor cursor) { final List<SearchResult> results = new ArrayList<>(); while (cursor.moveToNext()) { final SavedQueryPayload payload = new SavedQueryPayload( cursor.getString(cursor.getColumnIndex(SavedQueriesColumns.QUERY))); results.add(new SearchResult.Builder() .addTitle(payload.query) .addPayload(payload) .build()); } return results; } } Loading
res/layout/search_saved_query_item.xml 0 → 100644 +45 −0 Original line number Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <!-- Copyright (C) 2017 The Android Open Source Project Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="?android:attr/selectableItemBackground" android:minHeight="?android:attr/listPreferredItemHeight" android:gravity="center_vertical" android:paddingStart="@dimen/preference_no_icon_padding_start" android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"> <TextView android:id="@android:id/title" android:textAppearance="?android:attr/textAppearanceListItem" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_weight="1"/> <ImageView android:id="@android:id/icon" android:layout_width="@dimen/search_suggestion_item_image_size" android:layout_height="@dimen/search_suggestion_item_image_size" android:layout_marginStart="@dimen/search_suggestion_item_image_margin_start" android:layout_marginEnd="@dimen/search_suggestion_item_image_margin_end" android:scaleType="centerInside" android:src="@drawable/ic_search_history"/> </LinearLayout> No newline at end of file
src/com/android/settings/search/Index.java +5 −5 Original line number Diff line number Diff line Loading @@ -266,7 +266,7 @@ public class Index { StringBuilder sb = new StringBuilder(); sb.append("SELECT "); sb.append(IndexDatabaseHelper.SavedQueriesColums.QUERY); sb.append(IndexDatabaseHelper.SavedQueriesColumns.QUERY); sb.append(" FROM "); sb.append(Tables.TABLE_SAVED_QUERIES); Loading @@ -274,7 +274,7 @@ public class Index { sb.append(" ORDER BY rowId DESC"); } else { sb.append(" WHERE "); sb.append(IndexDatabaseHelper.SavedQueriesColums.QUERY); sb.append(IndexDatabaseHelper.SavedQueriesColumns.QUERY); sb.append(" LIKE "); sb.append("'"); sb.append(query); Loading Loading @@ -1299,8 +1299,8 @@ public class Index { final long now = new Date().getTime(); final ContentValues values = new ContentValues(); values.put(IndexDatabaseHelper.SavedQueriesColums.QUERY, params[0]); values.put(IndexDatabaseHelper.SavedQueriesColums.TIME_STAMP, now); values.put(IndexDatabaseHelper.SavedQueriesColumns.QUERY, params[0]); values.put(IndexDatabaseHelper.SavedQueriesColumns.TIME_STAMP, now); final SQLiteDatabase database = getWritableDatabase(); if (database == null) { Loading @@ -1312,7 +1312,7 @@ public class Index { try { // First, delete all saved queries that are the same database.delete(Tables.TABLE_SAVED_QUERIES, IndexDatabaseHelper.SavedQueriesColums.QUERY + " = ?", IndexDatabaseHelper.SavedQueriesColumns.QUERY + " = ?", new String[] { params[0] }); // Second, insert the saved query Loading
src/com/android/settings/search/IndexDatabaseHelper.java +3 −3 Original line number Diff line number Diff line Loading @@ -67,7 +67,7 @@ public class IndexDatabaseHelper extends SQLiteOpenHelper { String BUILD = "build"; } public interface SavedQueriesColums { public interface SavedQueriesColumns { String QUERY = "query"; String TIME_STAMP = "timestamp"; } Loading Loading @@ -127,9 +127,9 @@ public class IndexDatabaseHelper extends SQLiteOpenHelper { private static final String CREATE_SAVED_QUERIES_TABLE = "CREATE TABLE " + Tables.TABLE_SAVED_QUERIES + "(" + SavedQueriesColums.QUERY + " VARCHAR(64) NOT NULL" + SavedQueriesColumns.QUERY + " VARCHAR(64) NOT NULL" + ", " + SavedQueriesColums.TIME_STAMP + " INTEGER" + SavedQueriesColumns.TIME_STAMP + " INTEGER" + ")"; private static final String INSERT_BUILD_VERSION = Loading
src/com/android/settings/search2/ResultPayload.java +8 −2 Original line number Diff line number Diff line Loading @@ -29,7 +29,7 @@ import java.lang.annotation.RetentionPolicy; public abstract class ResultPayload implements Parcelable { @IntDef({PayloadType.INLINE_SLIDER, PayloadType.INLINE_SWITCH, PayloadType.INTENT}) PayloadType.INTENT, PayloadType.SAVED_QUERY}) @Retention(RetentionPolicy.SOURCE) public @interface PayloadType { /** Loading @@ -46,6 +46,11 @@ public abstract class ResultPayload implements Parcelable { * Result is a inline widget, using a toggle widget as UI. */ int INLINE_SWITCH = 2; /** * Result is a recently saved query. */ int SAVED_QUERY = 3; } @IntDef({SettingsSource.UNKNOWN, SettingsSource.SYSTEM, SettingsSource.SECURE, Loading @@ -59,5 +64,6 @@ public abstract class ResultPayload implements Parcelable { } @ResultPayload.PayloadType public abstract int getType(); @ResultPayload.PayloadType public abstract int getType(); }
src/com/android/settings/search2/SavedQueryLoader.java 0 → 100644 +77 −0 Original line number Diff line number Diff line /* * Copyright (C) 2017 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.settings.search2; import android.content.Context; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.support.annotation.VisibleForTesting; import com.android.settings.search.IndexDatabaseHelper; import com.android.settings.search.IndexDatabaseHelper.SavedQueriesColumns; import com.android.settings.utils.AsyncLoader; import java.util.ArrayList; import java.util.List; /** * Loader for recently searched queries. */ public class SavedQueryLoader extends AsyncLoader<List<SearchResult>> { // Max number of proposed suggestions @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE) static final int MAX_PROPOSED_SUGGESTIONS = 5; private final SQLiteDatabase mDatabase; public SavedQueryLoader(Context context) { super(context); mDatabase = IndexDatabaseHelper.getInstance(context).getReadableDatabase(); } @Override protected void onDiscardResult(List<SearchResult> result) { } @Override public List<SearchResult> loadInBackground() { Cursor cursor = mDatabase.query(IndexDatabaseHelper.Tables.TABLE_SAVED_QUERIES /* table */, new String[]{SavedQueriesColumns.QUERY} /* columns */, null /* selection */, null /* selectionArgs */, null /* groupBy */, null /* having */, "rowId DESC" /* orderBy */, String.valueOf(MAX_PROPOSED_SUGGESTIONS) /* limit */); return convertCursorToResult(cursor); } private List<SearchResult> convertCursorToResult(Cursor cursor) { final List<SearchResult> results = new ArrayList<>(); while (cursor.moveToNext()) { final SavedQueryPayload payload = new SavedQueryPayload( cursor.getString(cursor.getColumnIndex(SavedQueriesColumns.QUERY))); results.add(new SearchResult.Builder() .addTitle(payload.query) .addPayload(payload) .build()); } return results; } }