Commit d7c4fd36 authored by Gayane Petrosyan's avatar Gayane Petrosyan Committed by Commit Bot

[QRcode Android] Boilerplate code for download button

Boilerplate code that adds properties for download button and qrcode
bitmap.
This CL also hooks up the download button to saveBitmap utility function.

Bug: 993920
Change-Id: I1ebc7a6641a7294a1b3d9c63fd8cfdeb83fb7c31
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2071510Reviewed-by: default avatarTravis Skare <skare@google.com>
Reviewed-by: default avatarTanya Gupta <tgupta@chromium.org>
Commit-Queue: Gayane Petrosyan <gayane@chromium.org>
Auto-Submit: Gayane Petrosyan <gayane@chromium.org>
Cr-Commit-Position: refs/heads/master@{#748768}
parent 54b1dc4f
...@@ -8,6 +8,8 @@ import android.content.Context; ...@@ -8,6 +8,8 @@ import android.content.Context;
import android.view.View; import android.view.View;
import org.chromium.chrome.browser.share.qrcode.QrCodeDialogTab; import org.chromium.chrome.browser.share.qrcode.QrCodeDialogTab;
import org.chromium.ui.modelutil.PropertyModel;
import org.chromium.ui.modelutil.PropertyModelChangeProcessor;
/** /**
* Creates and represents the QrCode share panel UI. * Creates and represents the QrCode share panel UI.
...@@ -16,7 +18,12 @@ public class QrCodeShareCoordinator implements QrCodeDialogTab { ...@@ -16,7 +18,12 @@ public class QrCodeShareCoordinator implements QrCodeDialogTab {
private final QrCodeShareView mShareView; private final QrCodeShareView mShareView;
public QrCodeShareCoordinator(Context context) { public QrCodeShareCoordinator(Context context) {
mShareView = new QrCodeShareView(context); PropertyModel shareViewModel = new PropertyModel(QrCodeShareViewProperties.ALL_KEYS);
QrCodeShareMediator shareViewMediator = new QrCodeShareMediator(context, shareViewModel);
mShareView = new QrCodeShareView(context, shareViewMediator::downloadQrCode);
PropertyModelChangeProcessor.create(
shareViewModel, mShareView, new QrCodeShareViewBinder());
} }
/** QrCodeDialogTab implementation. */ /** QrCodeDialogTab implementation. */
......
// 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.share.qrcode.share_tab;
import android.content.Context;
import android.graphics.Bitmap;
import android.view.View;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.share.ShareImageFileUtils;
import org.chromium.ui.modelutil.PropertyModel;
import java.io.File;
/**
* QrCodeShareMediator is in charge of calculating and setting values for QrCodeShareViewProperties.
*/
class QrCodeShareMediator implements ShareImageFileUtils.OnImageSaveListener {
private final Context mContext;
private final PropertyModel mPropertyModel;
/**
* The QrCodeScanMediator constructor.
* @param context The context to use.
* @param propertyModel The property modelto use to communicate with views.
*/
QrCodeShareMediator(Context context, PropertyModel propertyModel) {
mContext = context;
mPropertyModel = propertyModel;
// TODO(gayane): Request generated QR code bitmap with a callback that sets QRCODE_BITMAP
// property.
}
/** Triggers download for the generated QR code bitmap if available. */
protected void downloadQrCode(View view) {
Bitmap qrcodeBitmap = mPropertyModel.get(QrCodeShareViewProperties.QRCODE_BITMAP);
if (qrcodeBitmap != null) {
String fileName = mContext.getString(
R.string.qr_code_filename_prefix, String.valueOf(System.currentTimeMillis()));
ShareImageFileUtils.saveBitmapToExternalStorage(mContext, fileName, qrcodeBitmap, this);
}
}
// ShareImageFileUtils.OnImageSaveListener implementation.
@Override
public void onImageSaved(File imageFile) {
// TODO(gayane): Maybe need to show confirmation message.
mPropertyModel.set(QrCodeShareViewProperties.DOWNLOAD_SUCCESSFUL, true);
}
@Override
public void onImageSaveError() {
// TODO(gayane): Maybe need to show error message.
mPropertyModel.set(QrCodeShareViewProperties.DOWNLOAD_SUCCESSFUL, false);
}
}
\ No newline at end of file
...@@ -5,8 +5,15 @@ ...@@ -5,8 +5,15 @@
package org.chromium.chrome.browser.share.qrcode.share_tab; package org.chromium.chrome.browser.share.qrcode.share_tab;
import android.content.Context; import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import org.chromium.chrome.browser.share.qrcode.R;
/** /**
* Manages the Android View representing the QrCode share panel. * Manages the Android View representing the QrCode share panel.
...@@ -15,14 +22,28 @@ class QrCodeShareView { ...@@ -15,14 +22,28 @@ class QrCodeShareView {
private final Context mContext; private final Context mContext;
private final View mView; private final View mView;
public QrCodeShareView(Context context) { public QrCodeShareView(Context context, View.OnClickListener listener) {
mContext = context; mContext = context;
mView = (View) LayoutInflater.from(context).inflate( mView = (View) LayoutInflater.from(context).inflate(
org.chromium.chrome.browser.share.qrcode.R.layout.qrcode_share_layout, null, false); R.layout.qrcode_share_layout, null, false);
Button downloadButton = (Button) mView.findViewById(R.id.download);
downloadButton.setOnClickListener(listener);
} }
public View getView() { public View getView() {
return mView; return mView;
} }
/**
* Updates QR code image on share panel.
*
* @param bitmap The {@link Bitmap} to display on share panel.
*/
public void updateQrCodeBitmap(Bitmap bitmap) {
TextView qrcodeText = mView.findViewById(R.id.qrcode_text_image);
Drawable drawable = new BitmapDrawable(bitmap);
qrcodeText.setCompoundDrawablesWithIntrinsicBounds(null, null, null, drawable);
}
} }
// 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.share.qrcode.share_tab;
import org.chromium.ui.modelutil.PropertyKey;
import org.chromium.ui.modelutil.PropertyModel;
import org.chromium.ui.modelutil.PropertyModelChangeProcessor.ViewBinder;
class QrCodeShareViewBinder implements ViewBinder<PropertyModel, QrCodeShareView, PropertyKey> {
@Override
public void bind(PropertyModel model, QrCodeShareView view, PropertyKey propertyKey) {
if (QrCodeShareViewProperties.QRCODE_BITMAP == propertyKey) {
view.updateQrCodeBitmap(model.get(QrCodeShareViewProperties.QRCODE_BITMAP));
}
}
}
// 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.share.qrcode.share_tab;
import android.graphics.Bitmap;
import org.chromium.ui.modelutil.PropertyKey;
import org.chromium.ui.modelutil.PropertyModel.WritableBooleanPropertyKey;
import org.chromium.ui.modelutil.PropertyModel.WritableObjectPropertyKey;
class QrCodeShareViewProperties {
/** The action that occurs when the download button is tapped. */
public static final WritableObjectPropertyKey<Bitmap> QRCODE_BITMAP =
new WritableObjectPropertyKey<>();
/** Indicates whether download was successful. */
public static final WritableBooleanPropertyKey DOWNLOAD_SUCCESSFUL =
new WritableBooleanPropertyKey();
public static final PropertyKey[] ALL_KEYS = {QRCODE_BITMAP, DOWNLOAD_SUCCESSFUL};
}
...@@ -20,6 +20,9 @@ share_java_sources = [ ...@@ -20,6 +20,9 @@ share_java_sources = [
"//chrome/browser/share/android/java/src/org/chromium/chrome/browser/share/qrcode/scan_tab/QrCodeScanViewBinder.java", "//chrome/browser/share/android/java/src/org/chromium/chrome/browser/share/qrcode/scan_tab/QrCodeScanViewBinder.java",
"//chrome/browser/share/android/java/src/org/chromium/chrome/browser/share/qrcode/scan_tab/QrCodeScanViewProperties.java", "//chrome/browser/share/android/java/src/org/chromium/chrome/browser/share/qrcode/scan_tab/QrCodeScanViewProperties.java",
"//chrome/browser/share/android/java/src/org/chromium/chrome/browser/share/qrcode/share_tab/QrCodeShareCoordinator.java", "//chrome/browser/share/android/java/src/org/chromium/chrome/browser/share/qrcode/share_tab/QrCodeShareCoordinator.java",
"//chrome/browser/share/android/java/src/org/chromium/chrome/browser/share/qrcode/share_tab/QrCodeShareMediator.java",
"//chrome/browser/share/android/java/src/org/chromium/chrome/browser/share/qrcode/share_tab/QrCodeShareView.java", "//chrome/browser/share/android/java/src/org/chromium/chrome/browser/share/qrcode/share_tab/QrCodeShareView.java",
"//chrome/browser/share/android/java/src/org/chromium/chrome/browser/share/qrcode/share_tab/QrCodeShareViewBinder.java",
"//chrome/browser/share/android/java/src/org/chromium/chrome/browser/share/qrcode/share_tab/QrCodeShareViewProperties.java",
"//chrome/browser/share/android/java/src/org/chromium/chrome/browser/share/screenshot/ScreenshotCoordinator.java", "//chrome/browser/share/android/java/src/org/chromium/chrome/browser/share/screenshot/ScreenshotCoordinator.java",
] ]
...@@ -4074,6 +4074,10 @@ Only you can see what your camera is looking at. The site can't see your camera' ...@@ -4074,6 +4074,10 @@ Only you can see what your camera is looking at. The site can't see your camera'
This QR Code is not a URL: <ph name="QrCodeValue">%1$s<ex>QR Code Text</ex></ph> This QR Code is not a URL: <ph name="QrCodeValue">%1$s<ex>QR Code Text</ex></ph>
</message> </message>
<message name="IDS_QR_CODE_FILENAME_PREFIX" desc="File name prefix for downloaded qrcode that is followed by timestamp.">
chrome_qrcode_<ph name="CURRENT_TIMESTAMP_MS">%1$s<ex>1582667748515</ex></ph>
</message>
<!-- Chime DFM module strings --> <!-- Chime DFM module strings -->
<message name="IDS_CHIME_MODULE_TITLE" desc="Text shown when the chime module is referenced in install start, success, failure UI (e.g. in IDS_MODULE_INSTALL_START_TEXT, which will expand to 'Installing Google Notifications Platform for Chrome…')."> <message name="IDS_CHIME_MODULE_TITLE" desc="Text shown when the chime module is referenced in install start, success, failure UI (e.g. in IDS_MODULE_INSTALL_START_TEXT, which will expand to 'Installing Google Notifications Platform for Chrome…').">
Google Notifications Platform Google Notifications Platform
......
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