1
0
Fork 0

For #4516: Use full width for large search widgets (#4659)

master
Yeon Taek Jeong 2019-08-14 16:00:13 -07:00 committed by Jeff Boek
parent f71106cb51
commit 2441592ef2
8 changed files with 126 additions and 186 deletions

View File

@ -58,25 +58,24 @@ class SearchWidgetProvider : AppWidgetProvider() {
} }
private fun getLayoutSize(dp: Int) = when { private fun getLayoutSize(dp: Int) = when {
dp >= DP_EXTRA_LARGE -> SearchWidgetProviderSize.EXTRA_LARGE
dp >= DP_LARGE -> SearchWidgetProviderSize.LARGE dp >= DP_LARGE -> SearchWidgetProviderSize.LARGE
dp >= DP_MEDIUM -> SearchWidgetProviderSize.MEDIUM dp >= DP_MEDIUM -> SearchWidgetProviderSize.MEDIUM
dp >= DP_SMALL -> SearchWidgetProviderSize.SMALL dp >= DP_SMALL -> SearchWidgetProviderSize.SMALL
else -> SearchWidgetProviderSize.EXTRA_SMALL dp >= DP_EXTRA_SMALL -> SearchWidgetProviderSize.EXTRA_SMALL_V2
else -> SearchWidgetProviderSize.EXTRA_SMALL_V1
} }
private fun getLayout(size: SearchWidgetProviderSize) = when (size) { private fun getLayout(size: SearchWidgetProviderSize) = when (size) {
SearchWidgetProviderSize.EXTRA_LARGE -> R.layout.search_widget_extra_large
SearchWidgetProviderSize.LARGE -> R.layout.search_widget_large SearchWidgetProviderSize.LARGE -> R.layout.search_widget_large
SearchWidgetProviderSize.MEDIUM -> R.layout.search_widget_medium SearchWidgetProviderSize.MEDIUM -> R.layout.search_widget_medium
SearchWidgetProviderSize.SMALL -> R.layout.search_widget_small SearchWidgetProviderSize.SMALL -> R.layout.search_widget_small
SearchWidgetProviderSize.EXTRA_SMALL -> R.layout.search_widget_extra_small SearchWidgetProviderSize.EXTRA_SMALL_V2 -> R.layout.search_widget_extra_small_v2
SearchWidgetProviderSize.EXTRA_SMALL_V1 -> R.layout.search_widget_extra_small_v1
} }
private fun getText(layout: SearchWidgetProviderSize, context: Context) = when (layout) { private fun getText(layout: SearchWidgetProviderSize, context: Context) = when (layout) {
SearchWidgetProviderSize.MEDIUM -> context.getString(R.string.search_widget_text_short) SearchWidgetProviderSize.MEDIUM -> context.getString(R.string.search_widget_text_short)
SearchWidgetProviderSize.LARGE, SearchWidgetProviderSize.LARGE -> context.getString(R.string.search_widget_text_long)
SearchWidgetProviderSize.EXTRA_LARGE -> context.getString(R.string.search_widget_text_long)
else -> null else -> null
} }
@ -107,7 +106,8 @@ class SearchWidgetProvider : AppWidgetProvider() {
): RemoteViews { ): RemoteViews {
return RemoteViews(context.packageName, layout).apply { return RemoteViews(context.packageName, layout).apply {
when (layout) { when (layout) {
R.layout.search_widget_extra_small -> { R.layout.search_widget_extra_small_v1,
R.layout.search_widget_extra_small_v2 -> {
setOnClickPendingIntent(R.id.button_search_widget_new_tab, textSearchIntent) setOnClickPendingIntent(R.id.button_search_widget_new_tab, textSearchIntent)
} }
R.layout.search_widget_small -> { R.layout.search_widget_small -> {
@ -115,11 +115,10 @@ class SearchWidgetProvider : AppWidgetProvider() {
setOnClickPendingIntent(R.id.button_search_widget_voice, voiceSearchIntent) setOnClickPendingIntent(R.id.button_search_widget_voice, voiceSearchIntent)
} }
R.layout.search_widget_medium, R.layout.search_widget_medium,
R.layout.search_widget_large, R.layout.search_widget_large -> {
R.layout.search_widget_extra_large -> {
setOnClickPendingIntent(R.id.button_search_widget_new_tab, textSearchIntent) setOnClickPendingIntent(R.id.button_search_widget_new_tab, textSearchIntent)
setOnClickPendingIntent(R.id.button_search_widget_voice, voiceSearchIntent) setOnClickPendingIntent(R.id.button_search_widget_voice, voiceSearchIntent)
setTextViewText(R.id.text_search_widget, text) setTextViewText(R.id.button_search_widget_new_tab, text)
} }
} }
} }
@ -127,19 +126,19 @@ class SearchWidgetProvider : AppWidgetProvider() {
// Cell sizes obtained from the actual dimensions listed in search widget specs // Cell sizes obtained from the actual dimensions listed in search widget specs
companion object { companion object {
private const val DP_EXTRA_SMALL = 64
private const val DP_SMALL = 100 private const val DP_SMALL = 100
private const val DP_MEDIUM = 192 private const val DP_MEDIUM = 192
private const val DP_LARGE = 256 private const val DP_LARGE = 256
private const val DP_EXTRA_LARGE = 360
private const val REQUEST_CODE_NEW_TAB = 0 private const val REQUEST_CODE_NEW_TAB = 0
private const val REQUEST_CODE_VOICE = 1 private const val REQUEST_CODE_VOICE = 1
} }
} }
enum class SearchWidgetProviderSize { enum class SearchWidgetProviderSize {
EXTRA_SMALL, EXTRA_SMALL_V1,
EXTRA_SMALL_V2,
SMALL, SMALL,
MEDIUM, MEDIUM,
LARGE, LARGE,
EXTRA_LARGE
} }

View File

@ -1,45 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- This Source Code Form is subject to the terms of the Mozilla Public
- License, v. 2.0. If a copy of the MPL was not distributed with this
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout android:layout_width="360dp"
android:layout_height="50dp"
android:background="@drawable/rounded_white_corners"
android:layout_gravity="center">
<LinearLayout android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="9dp"
android:id="@+id/button_search_widget_new_tab">
<ImageView
android:layout_width="32dp"
android:layout_height="32dp"
android:background="@drawable/ic_logo_widget"
android:layout_marginLeft="9dp"
android:layout_marginRight="12dp"/>
<TextView
android:id="@+id/text_search_widget"
android:layout_width="wrap_content"
android:layout_height="32dp"
android:gravity="center"
android:textSize="15dp"
android:textColor="@color/search_widget_text"
android:letterSpacing="-0.025"/>
</LinearLayout>
<ImageButton
android:id="@+id/button_search_widget_voice"
android:layout_width="32dp"
android:layout_height="32dp"
android:background="@drawable/ic_microphone_widget"
android:layout_alignParentRight="true"
android:layout_alignTop="@id/button_search_widget_new_tab"
android:layout_marginRight="9dp"/>
</RelativeLayout>
</FrameLayout>

View File

@ -1,25 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- This Source Code Form is subject to the terms of the Mozilla Public
- License, v. 2.0. If a copy of the MPL was not distributed with this
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout android:layout_width="64dp"
android:layout_height="50dp"
android:background="@drawable/rounded_white_corners"
android:layout_gravity="center"
android:orientation="vertical">
<ImageButton
android:id="@id/button_search_widget_new_tab"
android:layout_width="40dp"
android:layout_height="40dp"
android:background="@drawable/ic_logo_widget"
android:layout_gravity="center"
android:layout_marginTop="5dp"/>
</LinearLayout>
</FrameLayout>

View File

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- This Source Code Form is subject to the terms of the Mozilla Public
- License, v. 2.0. If a copy of the MPL was not distributed with this
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@id/button_search_widget_new_tab"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="@drawable/rounded_white_corners"
android:layout_gravity="center">
<ImageButton
android:layout_width="40dp"
android:layout_height="40dp"
android:background="@drawable/ic_logo_widget"
android:layout_gravity="center"/>
</FrameLayout>

View File

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- This Source Code Form is subject to the terms of the Mozilla Public
- License, v. 2.0. If a copy of the MPL was not distributed with this
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@id/button_search_widget_new_tab"
android:layout_width="64dp"
android:layout_height="50dp"
android:background="@drawable/rounded_white_corners"
android:layout_gravity="center">
<ImageButton
android:layout_width="40dp"
android:layout_height="40dp"
android:background="@drawable/ic_logo_widget"
android:layout_gravity="center"/>
</FrameLayout>

View File

@ -3,43 +3,32 @@
- License, v. 2.0. If a copy of the MPL was not distributed with this - License, v. 2.0. If a copy of the MPL was not distributed with this
- file, You can obtain one at http://mozilla.org/MPL/2.0/. --> - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" <RelativeLayout
android:layout_width="match_parent" xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"> android:layout_width="match_parent"
android:layout_height="50dp"
android:background="@drawable/rounded_white_corners"
android:layout_gravity="center">
<RelativeLayout android:layout_width="256dp" <TextView
android:layout_height="50dp" android:id="@+id/button_search_widget_new_tab"
android:background="@drawable/rounded_white_corners" android:layout_width="match_parent"
android:layout_gravity="center"> android:layout_height="32dp"
android:gravity="center_vertical"
android:textSize="15sp"
android:textColor="@color/search_widget_text"
android:letterSpacing="-0.025"
android:drawableStart="@drawable/ic_logo_widget"
android:drawablePadding="12dp"
android:layout_marginStart="9dp"
android:layout_marginTop="9dp"/>
<LinearLayout android:layout_width="match_parent" <ImageButton
android:layout_height="match_parent" android:id="@+id/button_search_widget_voice"
android:layout_marginTop="9dp" android:layout_width="32dp"
android:id="@+id/button_search_widget_new_tab"> android:layout_height="32dp"
<ImageView android:background="@drawable/ic_microphone_widget"
android:layout_width="32dp" android:layout_alignParentEnd="true"
android:layout_height="32dp" android:layout_alignTop="@id/button_search_widget_new_tab"
android:background="@drawable/ic_logo_widget" android:layout_marginEnd="9dp"/>
android:layout_marginLeft="9dp" </RelativeLayout>
android:layout_marginRight="12dp"/>
<TextView
android:id="@+id/text_search_widget"
android:layout_width="wrap_content"
android:layout_height="32dp"
android:gravity="center"
android:textSize="15dp"
android:textColor="@color/search_widget_text"
android:letterSpacing="-0.025"/>
</LinearLayout>
<ImageButton
android:id="@+id/button_search_widget_voice"
android:layout_width="32dp"
android:layout_height="32dp"
android:background="@drawable/ic_microphone_widget"
android:layout_alignParentRight="true"
android:layout_alignTop="@id/button_search_widget_new_tab"
android:layout_marginRight="9dp"/>
</RelativeLayout>
</FrameLayout>

View File

@ -3,43 +3,32 @@
- License, v. 2.0. If a copy of the MPL was not distributed with this - License, v. 2.0. If a copy of the MPL was not distributed with this
- file, You can obtain one at http://mozilla.org/MPL/2.0/. --> - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" <RelativeLayout
android:layout_width="match_parent" xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"> android:layout_width="192dp"
android:layout_height="50dp"
android:background="@drawable/rounded_white_corners"
android:layout_gravity="center">
<RelativeLayout android:layout_width="192dp" <TextView
android:layout_height="50dp" android:id="@+id/button_search_widget_new_tab"
android:background="@drawable/rounded_white_corners" android:layout_width="match_parent"
android:layout_gravity="center"> android:layout_height="32dp"
android:gravity="center_vertical"
android:textSize="15sp"
android:textColor="@color/search_widget_text"
android:letterSpacing="-0.025"
android:drawableStart="@drawable/ic_logo_widget"
android:drawablePadding="12dp"
android:layout_marginStart="9dp"
android:layout_marginTop="9dp"/>
<LinearLayout android:layout_width="match_parent" <ImageButton
android:layout_height="match_parent" android:id="@+id/button_search_widget_voice"
android:layout_marginTop="9dp" android:layout_width="32dp"
android:id="@+id/button_search_widget_new_tab"> android:layout_height="32dp"
<ImageView android:background="@drawable/ic_microphone_widget"
android:layout_width="32dp" android:layout_alignParentEnd="true"
android:layout_height="32dp" android:layout_alignTop="@id/button_search_widget_new_tab"
android:background="@drawable/ic_logo_widget" android:layout_marginEnd="9dp"/>
android:layout_marginLeft="9dp" </RelativeLayout>
android:layout_marginRight="12dp"/>
<TextView
android:id="@+id/text_search_widget"
android:layout_width="wrap_content"
android:layout_height="32dp"
android:gravity="center"
android:textSize="15dp"
android:textColor="@color/search_widget_text"
android:letterSpacing="-0.025"/>
</LinearLayout>
<ImageButton
android:id="@+id/button_search_widget_voice"
android:layout_width="32dp"
android:layout_height="32dp"
android:background="@drawable/ic_microphone_widget"
android:layout_alignParentRight="true"
android:layout_alignTop="@id/button_search_widget_new_tab"
android:layout_marginRight="9dp"/>
</RelativeLayout>
</FrameLayout>

View File

@ -3,35 +3,32 @@
- License, v. 2.0. If a copy of the MPL was not distributed with this - License, v. 2.0. If a copy of the MPL was not distributed with this
- file, You can obtain one at http://mozilla.org/MPL/2.0/. --> - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" <RelativeLayout
android:layout_width="match_parent" xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"> android:layout_width="100dp"
android:layout_height="50dp"
android:background="@drawable/rounded_white_corners"
android:layout_gravity="center">
<RelativeLayout android:layout_width="100dp" <FrameLayout android:id="@+id/button_search_widget_new_tab"
android:layout_height="50dp" android:layout_width="match_parent"
android:background="@drawable/rounded_white_corners" android:layout_height="match_parent"
android:layout_gravity="center"> android:layout_marginTop="9dp">
<LinearLayout android:id="@+id/button_search_widget_new_tab" <ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="9dp">
<ImageView
android:layout_width="32dp"
android:layout_height="32dp"
android:background="@drawable/ic_logo_widget"
android:layout_marginLeft="9dp"
android:layout_marginRight="12dp"/>
</LinearLayout>
<ImageButton
android:id="@+id/button_search_widget_voice"
android:layout_width="32dp" android:layout_width="32dp"
android:layout_height="32dp" android:layout_height="32dp"
android:background="@drawable/ic_microphone_widget" android:background="@drawable/ic_logo_widget"
android:layout_alignParentRight="true" android:layout_marginStart="9dp"/>
android:layout_alignTop="@id/button_search_widget_new_tab" </FrameLayout>
android:layout_marginRight="9dp"/>
</RelativeLayout> <ImageButton
android:id="@+id/button_search_widget_voice"
android:layout_width="32dp"
android:layout_height="32dp"
android:background="@drawable/ic_microphone_widget"
android:layout_alignParentEnd="true"
android:layout_alignTop="@id/button_search_widget_new_tab"
android:layout_marginEnd="9dp"/>
</RelativeLayout>
</FrameLayout>