Commit 961b8495 authored by Yu Su's avatar Yu Su Committed by Commit Bot

Lens Code Refactoring Part I

- Add a ChipRenderParams class to wrap the params used when displaying the chip
- add new LensController methods to retrieve chip params, generate Lens intent and launch Lens. Will implement these methods in a follow up clank cl.
- update LensQueryParams to be a temperate wrapper object for Lens init params. Will split out Lens init params into a separate wrapper object once we have the Direct intent SDK.

Change-Id: If90ac5f407889069fe2f58ef210055d2c144df46
Bug: 1145748, b/171252338
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2527724
Commit-Queue: Yu Su <yusuyoutube@google.com>
Reviewed-by: default avatarBen Goldberger <benwgold@google.com>
Reviewed-by: default avatarTheresa  <twellington@chromium.org>
Reviewed-by: default avatarSinan Sahin <sinansahin@google.com>
Cr-Commit-Position: refs/heads/master@{#825685}
parent dec31e17
......@@ -348,6 +348,7 @@ chrome_java_sources = [
"java/src/org/chromium/chrome/browser/contacts_picker/ChromePickerAdapter.java",
"java/src/org/chromium/chrome/browser/content/ContentUtils.java",
"java/src/org/chromium/chrome/browser/content_capture/ContentCaptureHistoryDeletionObserver.java",
"java/src/org/chromium/chrome/browser/contextmenu/ChipRenderParams.java",
"java/src/org/chromium/chrome/browser/contextmenu/ChromeContextMenuItem.java",
"java/src/org/chromium/chrome/browser/contextmenu/ChromeContextMenuPopulator.java",
"java/src/org/chromium/chrome/browser/contextmenu/ChromeContextMenuPopulatorFactory.java",
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.chrome.browser.contextmenu;
import androidx.annotation.DrawableRes;
import androidx.annotation.StringRes;
/**
* An object that contains the required fields to generate the context menu chip.
*/
public class ChipRenderParams {
// The resource id for the chip title.
public @StringRes int titleResourceId;
// The resource id for the chip icon.
public @DrawableRes int iconResourceId;
// The callback to be called when the chip clicked.
public Runnable onClickCallback;
}
......@@ -4,8 +4,18 @@
package org.chromium.chrome.browser.lens;
import android.content.Intent;
import android.net.Uri;
import androidx.annotation.DrawableRes;
import androidx.annotation.Nullable;
import androidx.annotation.StringRes;
import org.chromium.base.Callback;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.AppHooks;
import org.chromium.chrome.browser.contextmenu.ChipRenderParams;
import org.chromium.ui.base.WindowAndroid;
/**
* A class which manages communication with the Lens SDK.
......@@ -24,7 +34,6 @@ public class LensController {
}
/**
* TODO(benwgold): Deprecate this API Call.
* Whether the Lens SDK is available.
* @return Whether the Lens SDK is available.
*/
......@@ -57,4 +66,59 @@ public class LensController {
* the request.
*/
public void terminateClassification() {}
/**
* Get the data to generate a chip as an entry point to Lens.
* Classify an image and return chip data once the classification completes.
* @param lensQueryParams A wrapper object which contains params for the image classification
* query.
* @param chipRenderParamsCallback A callback to trigger once the classification is compelete.
*/
public void getChipRenderParams(
LensQueryParams lensQueryParams, Callback<ChipRenderParams> chipRenderParamsCallback) {}
// TODO(yusuyoutube): deprecate this function and switch to use the Direct Intent API.
/**
* Get a deeplink intent to Google Lens with an optional content provider image
* URI. The intent should be constructed immediately before the intent is fired
* to ensure that the launch timestamp is accurate.
*
* @param imageUri The content provider URI generated by chrome (or empty URI) if only resolving
* the activity.
* @param isIncognito Whether the current tab is in incognito mode.
* @param srcUrl The 'src' attribute of the image.
* @param titleOrAltText The 'title' or, if empty, the 'alt' attribute of the image.
* @param requiresConfirmation Whether the request requires an confirmation dialog.
* @param titleOrAltText The 'title' or, if empty, the 'alt' attribute of the image.
* @param lensIntentType The intent type of the request.
* @return The intent to Google Lens.
*/
public Intent getShareWithGoogleLensIntent(Uri imageUri, boolean isIncognito, String srcUrl,
boolean requiresConfirmation, String titleOrAltText, @Nullable String lensIntentType) {
return null;
}
/**
* Launch Lens with an intent.
* @param window The current window.
* @param intent The intent to Google Lens.
*/
public void startLens(WindowAndroid window, Intent intent) {}
/**
* Retrieve the Text resource id for "Shop with Google Lens".
* @return The resource id for "Shop with Google Lens" string.
*/
protected @StringRes int getShopWithGoogleLensTextResourceId() {
return R.string.contextmenu_shop_image_with_google_lens;
}
/**
* Retrieve the Lens icon resource id.
* Need to put the resource id on the base class to suppress the UnusedResources warning.
* @return The resource id for Lens icon
*/
protected @DrawableRes int getLensIconResourceId() {
return R.drawable.lens_icon;
}
}
\ No newline at end of file
......@@ -7,6 +7,7 @@ package org.chromium.chrome.browser.lens;
import android.net.Uri;
import org.chromium.content_public.browser.WebContents;
import org.chromium.ui.base.WindowAndroid;
/**
* A wrapper class for the Lens image query params (e.g. used in LensController.queryImage)
......@@ -18,6 +19,9 @@ public class LensQueryParams {
private String mImageTitleOrAltText;
private String mPageTitle;
private WebContents mWebContents;
private String mSrcUrl;
private boolean mIsIncognito;
private WindowAndroid mWindow;
/**
* Builder class for LensQueryParams.
......@@ -28,6 +32,8 @@ public class LensQueryParams {
private String mImageTitleOrAltText;
private String mPageTitle;
private WebContents mWebContents;
private String mSrcUrl;
private boolean mIsIncognito;
public Builder() {}
......@@ -56,6 +62,16 @@ public class LensQueryParams {
return this;
}
public Builder withSrcUrl(String srcUrl) {
this.mSrcUrl = srcUrl;
return this;
}
public Builder withIsIncognito(boolean isIncognito) {
this.mIsIncognito = isIncognito;
return this;
}
public LensQueryParams build() {
LensQueryParams lensQueryParams = new LensQueryParams();
lensQueryParams.mImageUri = this.mImageUri;
......@@ -63,10 +79,16 @@ public class LensQueryParams {
lensQueryParams.mImageTitleOrAltText = this.mImageTitleOrAltText;
lensQueryParams.mPageTitle = this.mPageTitle;
lensQueryParams.mWebContents = this.mWebContents;
lensQueryParams.mSrcUrl = this.mSrcUrl;
lensQueryParams.mIsIncognito = this.mIsIncognito;
return lensQueryParams;
}
}
public void setImageUri(Uri imageUri) {
mImageUri = imageUri;
}
public Uri getImageUri() {
return mImageUri;
}
......@@ -86,4 +108,12 @@ public class LensQueryParams {
public WebContents getWebContents() {
return mWebContents;
}
public String getSrcUrl() {
return mSrcUrl;
}
public boolean getIsIncognito() {
return mIsIncognito;
}
}
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment