Skip to content

Commit

Permalink
corrected google url and added search assistant feature
Browse files Browse the repository at this point in the history
  • Loading branch information
TobiasBielefeld committed Mar 31, 2018
1 parent 81c5d84 commit 573d19c
Show file tree
Hide file tree
Showing 10 changed files with 83 additions and 8 deletions.
9 changes: 9 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@

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

<intent-filter>
<action android:name="android.intent.action.ASSIST" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>

<meta-data
android:name="com.android.systemui.action_assist_icon"
android:resource="@mipmap/ic_launcher" />
</activity>

<activity
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright (C) 2016 Tobias Bielefeld
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* If you want to contact me, send me an e-mail at [email protected]
*/

package de.tobiasbielefeld.searchbar.classes;

import android.content.Context;
import android.preference.ListPreference;
import android.util.AttributeSet;

/**
* Custom list preference, because "%s" as summary doesn't update the summary on Android 4. So override
* setValue to get around this issue. Thanks to https://stackoverflow.com/a/16661022/7016229 !
*/

public class ListPreferenceWithSummary extends ListPreference {

public ListPreferenceWithSummary(Context context, AttributeSet attrs) {
super(context, attrs);
}

public ListPreferenceWithSummary(Context context) {
super(context);
}

@Override
public void setValue(String value) {
super.setValue(value);
setSummary(value);
}

@Override
public void setSummary(CharSequence summary) {
super.setSummary(getEntry());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@


import de.tobiasbielefeld.searchbar.R;
import de.tobiasbielefeld.searchbar.classes.ListPreferenceWithSummary;

import static de.tobiasbielefeld.searchbar.SharedData.*;

/**
Expand Down Expand Up @@ -139,6 +141,7 @@ protected void onDialogClosed(boolean positiveResult) {

if (callChangeListener(value)) {
setValue(value);
updateSummary();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,16 @@ public void showToast(String text) {
* @param text The text to search
*/
public void startSearch(String text) {
String baseUrl = getSavedString(PREF_SEARCH_URL, DEFAULT_SEARCH_URL); //get the base url of the search engine
String baseUrl = getSavedString(PREF_SEARCH_URL, DEFAULT_SEARCH_URL); //get the base url of the search engine

logText(baseUrl);

//workaround for the wrong google url
if (baseUrl.equals("https://www.google.de/#q=%s")){
baseUrl = "https://www.google.de/search?q=%s";
} else if (baseUrl.equals("https://www.google.com/#q=%s")){
baseUrl = "https://www.google.com/search?q=%s";
}

Uri searchUrl = null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ protected void onCreate(Bundle savedInstanceState) {
}

reinitializeData(getApplicationContext());

putSavedString(PREF_LANGUAGE,getSavedString(PREF_LANGUAGE,"default"));
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-de/array.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

<string-array formatted="false" name="search_engine_uris">
<item>empty</item> <!-- custom search engine will be set up promatically, so this entry can be empty-->
<item>https://www.google.de/#q=%s</item>
<item>https://www.google.de/search?q=%s</item>
<item>https://de.search.yahoo.com/search?p=%s</item>
<item>https://www.bing.com/search?q=%s&amp;cc=de</item>
<item>https://www.yandex.com/?q=%s</item>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-fr/array.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

<string-array formatted="false" name="search_engine_uris">
<item>empty</item> <!-- custom search engine will be set up programmatically, so this entry can be empty-->
<item>https://www.google.com/#q=%s</item>
<item>https://www.google.com/search?q=%s</item>
<item>https://search.yahoo.com/search?p=%s</item>
<item>https://www.bing.com/search?q=%s</item>
<item>https://www.yandex.com/?q=%s</item>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values/array.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

<string-array formatted="false" name="search_engine_uris">
<item>empty</item> <!-- custom search engine will be set up programmatically, so this entry can be empty-->
<item>https://www.google.com/#q=%s</item>
<item>https://www.google.com/search?q=%s</item>
<item>https://search.yahoo.com/search?p=%s</item>
<item>https://www.bing.com/search?q=%s</item>
<item>https://www.yandex.com/?q=%s</item>
Expand Down
6 changes: 4 additions & 2 deletions app/src/main/res/values/strings-changelog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
<resources>

<string name="changelog_5_1" translatable="false">Improved the about screen\n</string>
<string name="changelog_5_2" translatable="false">Search is cleared upon opening the browser\n</string>
<string name="changelog_5_3" translatable="false">Bug fixes, thanks to julfers!</string>
<string name="changelog_5_2" translatable="false">Fixed the Google search URL\n</string>
<string name="changelog_5_3" translatable="false">App can now be set up as a search assistant\n</string>
<string name="changelog_5_4" translatable="false">Search is cleared upon opening the browser\n</string>
<string name="changelog_5_5" translatable="false">Bug fixes, thanks to julfers!</string>

<string name="changelog_4_1" translatable="false">Added a second transparent widget\n</string>
<string name="changelog_4_2" translatable="false">Added French translations, thanks to Benjamin Tourrel!</string>
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/xml/pref_general.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">

<ListPreference
<de.tobiasbielefeld.searchbar.classes.ListPreferenceWithSummary
android:defaultValue="1"
android:entries="@array/pref_orientation_titles"
android:entryValues="@array/pref_orientation_values"
Expand All @@ -10,7 +10,7 @@
android:summary="%s"
android:title="@string/settings_orientation" />

<ListPreference
<de.tobiasbielefeld.searchbar.classes.ListPreferenceWithSummary
android:defaultValue="default"
android:entries="@array/pref_language_titles"
android:entryValues="@array/pref_language_values"
Expand Down

0 comments on commit 573d19c

Please sign in to comment.