Add option to use Google Assistant on the searchbar instead of voice search

This commit is contained in:
Till Kottmann
2018-08-09 13:43:39 +02:00
parent 1d04cb14ef
commit f1ccb02ebe
7 changed files with 53 additions and 3 deletions

View File

@@ -0,0 +1,7 @@
<vector android:height="24dp" android:viewportHeight="512.0"
android:viewportWidth="512.0" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#2196F3" android:pathData="M156.3,167.7m-156.3,0a156.3,156.3 0,1 1,312.5 0a156.3,156.3 0,1 1,-312.5 0"/>
<path android:fillColor="#00C853" android:pathData="M512,182.9c0,17.5 -14.2,31.8 -31.8,31.8s-31.8,-14.2 -31.8,-31.8c0,-17.5 14.2,-31.8 31.8,-31.8S512,165.4 512,182.9z"/>
<path android:fillColor="#F44336" android:pathData="M454.8,260.4c0,35.1 -28.4,63.5 -63.5,63.5c-35.1,0 -63.5,-28.4 -63.5,-63.5c0,-35.1 28.4,-63.5 63.5,-63.5C426.4,196.9 454.8,225.4 454.8,260.4z"/>
<path android:fillColor="#FFEB3B" android:pathData="M467.5,424.3c0,42.1 -34.1,76.2 -76.2,76.2c-42.1,0 -76.2,-34.1 -76.2,-76.2c0,-42.1 34.1,-76.2 76.2,-76.2C433.4,348.1 467.5,382.2 467.5,424.3z"/>
</vector>

View File

@@ -0,0 +1,7 @@
<vector android:height="24dp" android:viewportHeight="512.0"
android:viewportWidth="512.0" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FFF" android:pathData="M156.3,167.7m-156.3,0a156.3,156.3 0,1 1,312.5 0a156.3,156.3 0,1 1,-312.5 0"/>
<path android:fillColor="#FFF" android:pathData="M512,182.9c0,17.5 -14.2,31.8 -31.8,31.8s-31.8,-14.2 -31.8,-31.8c0,-17.5 14.2,-31.8 31.8,-31.8S512,165.4 512,182.9z"/>
<path android:fillColor="#FFF" android:pathData="M454.8,260.4c0,35.1 -28.4,63.5 -63.5,63.5c-35.1,0 -63.5,-28.4 -63.5,-63.5c0,-35.1 28.4,-63.5 63.5,-63.5C426.4,196.9 454.8,225.4 454.8,260.4z"/>
<path android:fillColor="#FFF" android:pathData="M467.5,424.3c0,42.1 -34.1,76.2 -76.2,76.2c-42.1,0 -76.2,-34.1 -76.2,-76.2c0,-42.1 34.1,-76.2 76.2,-76.2C433.4,348.1 467.5,382.2 467.5,424.3z"/>
</vector>

View File

@@ -541,6 +541,8 @@
<string name="action_do_nothing_class" translatable="false">ch.deletescape.lawnchair.gestures.BlankGestureHandler</string>
<string name="pref_show_assistant_title">Show voice search button</string>
<string name="pref_show_assistant_summary">Display a voice search button in the Google search bar</string>
<string name="pref_show_as_assistant_title">Show as Assistant</string>
<string name="pref_show_as_assistant_summary">Display a Google Assistant button instead of voice search</string>
<string name="current_weather_provider">Current weather provider</string>
<string name="smartspace_time_24_h">Show time in 24 hours</string>
<string name="weather_provider_disabled">Disabled</string>

View File

@@ -65,6 +65,14 @@
android:summary="@string/pref_show_assistant_summary"
android:title="@string/pref_show_assistant_title" />
<ch.deletescape.lawnchair.preferences.StyledSwitchPreferenceCompat
android:defaultValue="true"
android:key="opa_assistant"
android:persistent="true"
android:dependency="opa_enabled"
android:summary="@string/pref_show_as_assistant_summary"
android:title="@string/pref_show_as_assistant_title" />
<ch.deletescape.lawnchair.preferences.StyledSwitchPreferenceCompat
android:defaultValue="false"
android:key="pref_enableBlur"

View File

@@ -7,6 +7,7 @@ import android.content.SharedPreferences;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.graphics.*;
import android.graphics.PorterDuff.Mode;
import android.support.annotation.DrawableRes;
import android.util.AttributeSet;
import android.view.View;
import android.view.View.OnClickListener;
@@ -27,6 +28,8 @@ public abstract class AbstractQsbLayout extends FrameLayout implements LauncherL
protected Bitmap mShadowBitmap;
protected final Paint mShadowPaint;
private boolean mShowAssistant;
protected abstract int getWidth(int i);
protected abstract void loadBottomMargin();
@@ -160,7 +163,7 @@ public abstract class AbstractQsbLayout extends FrameLayout implements LauncherL
public void onClick(View view) {
if (view == mMicIconView) {
fallbackSearch("android.intent.action.VOICE_ASSIST");
fallbackSearch(mShowAssistant ? Intent.ACTION_VOICE_COMMAND : "android.intent.action.VOICE_ASSIST");
}
}
@@ -174,17 +177,31 @@ public abstract class AbstractQsbLayout extends FrameLayout implements LauncherL
}
}
protected @DrawableRes int getMicResource() {
return getMicResource(true);
}
protected @DrawableRes int getMicResource(boolean colored){
if(colored){
return mShowAssistant ? R.drawable.opa_assistant_logo : R.drawable.ic_mic_color;
} else {
return mShowAssistant ? R.drawable.opa_assistant_logo_shadow : R.drawable.ic_mic_shadow;
}
}
protected void noGoogleAppSearch() {
}
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String str) {
if ("opa_enabled".equals(str)) {
if ("opa_enabled".equals(str) || "opa_assistant".equals(str)) {
loadPreferences(sharedPreferences);
}
}
private void loadPreferences(SharedPreferences sharedPreferences) {
mShowAssistant = sharedPreferences.getBoolean("opa_assistant", true);
mMicIconView.setVisibility(!sharedPreferences.getBoolean("opa_enabled", false) ? View.GONE : View.VISIBLE);
mMicIconView.setImageResource(getMicResource());
requestLayout();
}
}

View File

@@ -264,7 +264,6 @@ public class AllAppsQsbLayout extends AbstractQsbLayout implements SearchUiManag
mAllAppsGoogleSearch = allAppsGoogleSearch;
mSearchIcon.setImageResource(mAllAppsGoogleSearch ?
R.drawable.ic_super_g_color : R.drawable.ic_allapps_search);
mMicIconView.setImageResource(mAllAppsGoogleSearch ? R.drawable.ic_mic_color : 0);
if (mAllAppsGoogleSearch) {
removeFallbackView();
mSearchIcon.clearColorFilter();
@@ -280,6 +279,11 @@ public class AllAppsQsbLayout extends AbstractQsbLayout implements SearchUiManag
}
}
@Override
protected int getMicResource(boolean colored) {
return mAllAppsGoogleSearch ? super.getMicResource(colored) : 0;
}
@Override
public void onAccentChange(int color, int foregroundColor) {
if (mSearchIcon != null) {

View File

@@ -77,6 +77,11 @@ public class HotseatQsbWidget extends AbstractQsbLayout implements LawnchairPref
bz(getResources().getColor(mIsGoogleColored ? R.color.qsb_background_hotseat_white : R.color.qsb_background_hotseat_default));
}
@Override
protected int getMicResource() {
return super.getMicResource(mIsGoogleColored);
}
private void openQSB() {
mSearchRequested = false;
playAnimation(mGoogleHasFocus = true, true);