Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copy calculator search result to clipboard #4798

Open
wants to merge 6 commits into
base: 14-dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions lawnchair/res/layout/search_result_tall_icon_row_calculator.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?xml version="1.0" encoding="utf-8"?>
<app.lawnchair.allapps.views.SearchResultIconRow xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:launcher="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="@dimen/search_result_row_height"
android:gravity="center"
android:orientation="horizontal"
android:paddingStart="@dimen/search_result_margin"
android:paddingTop="@dimen/search_result_padding"
android:paddingBottom="@dimen/search_result_padding">

<app.lawnchair.allapps.views.SearchResultIcon
android:id="@id/icon"
android:layout_width="@dimen/search_row_icon_size"
android:layout_height="wrap_content"
launcher:iconDisplay="search_result_tall"
launcher:layoutHorizontal="true" />

<LinearLayout
android:id="@+id/text_rows"
android:layout_width="0.0dip"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:orientation="vertical"
android:paddingStart="@dimen/search_result_padding">

<TextView
android:id="@+id/title"
style="@style/AllAppsSearchResult"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:gravity="start|center"
android:maxLines="1"
android:singleLine="true"
android:textAlignment="viewStart"
android:textColor="?android:textColorPrimary"
android:textSize="@dimen/search_result_hero_title_size" />

<TextView
android:id="@+id/subtitle"
style="@style/AllAppsSearchResult"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="1"
android:singleLine="true"
android:textColor="?android:textColorSecondary"
android:textSize="@dimen/search_result_hero_subtitle_size" />
</LinearLayout>

<ImageView
android:id="@+id/clipboard"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginStart="@dimen/search_result_padding"
android:layout_marginEnd="@dimen/search_result_padding"
android:src="@drawable/ic_copy" />
</app.lawnchair.allapps.views.SearchResultIconRow>
1 change: 1 addition & 0 deletions lawnchair/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@

<!-- Toast text and tips -->
<string name="copied_toast">Copied to clipboard</string>
<string name="calculator_search_result_copied_toast">Result copied to clipboard</string>
<string name="item_removed">Item removed</string>

<!-- Miscellaneous -->
Expand Down
15 changes: 15 additions & 0 deletions lawnchair/src/app/lawnchair/allapps/views/SearchResultIconRow.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ import androidx.core.view.ViewCompat
import androidx.core.view.isVisible
import app.lawnchair.allapps.views.SearchResultView.Companion.FLAG_HIDE_SUBTITLE
import app.lawnchair.font.FontManager
import app.lawnchair.search.adapter.CALCULATOR
import app.lawnchair.search.adapter.HISTORY
import app.lawnchair.search.adapter.SETTINGS
import app.lawnchair.search.adapter.SearchTargetCompat
import app.lawnchair.search.adapter.WEB_SUGGESTION
import app.lawnchair.search.model.SearchResultActionCallBack
import app.lawnchair.util.copyToClipboard
import com.android.app.search.LayoutType
import com.android.launcher3.R
import com.android.launcher3.touch.ItemClickHandler
Expand Down Expand Up @@ -92,6 +94,10 @@ class SearchResultIconRow(context: Context, attrs: AttributeSet?) :
target.resultType == SearchTargetCompat.RESULT_TYPE_SETTING_TILE &&
target.packageName == SETTINGS

val isCalculator = target.layoutType == LayoutType.CALCULATOR &&
target.resultType == SearchTargetCompat.RESULT_TYPE_CALCULATOR &&
target.packageName == CALCULATOR

bindShortcuts(shortcuts)
var showDelimiter = true
if (isSmall) {
Expand Down Expand Up @@ -120,6 +126,15 @@ class SearchResultIconRow(context: Context, attrs: AttributeSet?) :
target.searchAction?.intent?.let { intent -> handleSearchTargetClick(context, intent) }
}
}
if (isCalculator) {
setOnClickListener {
copyToClipboard(
context = context,
text = target.extras.getString("result"),
toastMessage = context.getString(R.string.calculator_search_result_copied_toast),
)
}
}
}

private fun setSubtitleText(subtitleText: CharSequence?, showDelimiter: Boolean) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class LawnchairSearchAdapterProvider(
append(SEARCH_RESULT_SUGGESTION_TILE, R.layout.search_result_small_icon_row)
append(SEARCH_RESULT_SETTINGS_TILE, R.layout.search_result_small_icon_row)
append(SEARCH_RESULT_RECENT_TILE, R.layout.search_result_small_icon_row)
append(SEARCH_RESULT_CALCULATOR, R.layout.search_result_tall_icon_row)
append(SEARCH_RESULT_CALCULATOR, R.layout.search_result_tall_icon_row_calculator)
}
private var quickLaunchItem: SearchResultView? = null
set(value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,16 @@ class SearchTargetFactory(
.setIntent(Intent())
.build()

val extras = bundleOf()
val extras = bundleOf(
"result" to result,
)

return createSearchTarget(
id,
action,
LayoutType.CALCULATOR,
SearchTargetCompat.RESULT_TYPE_CALCULATOR,
"",
CALCULATOR,
extras,
)
}
Expand Down