| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.chrome.browser.widget; | 5 package org.chromium.chrome.browser.widget; |
| 6 | 6 |
| 7 import android.app.Dialog; | 7 import android.app.Dialog; |
| 8 import android.content.Context; | 8 import android.content.Context; |
| 9 import android.content.DialogInterface; | 9 import android.content.DialogInterface; |
| 10 import android.os.Bundle; | 10 import android.os.Bundle; |
| 11 import android.view.LayoutInflater; | 11 import android.view.LayoutInflater; |
| 12 import android.view.View; | 12 import android.view.View; |
| 13 import android.view.ViewGroup.LayoutParams; | 13 import android.view.ViewGroup.LayoutParams; |
| 14 import android.widget.FrameLayout; | 14 import android.widget.FrameLayout; |
| 15 | 15 |
| 16 import org.chromium.base.ApiCompatibilityUtils; | 16 import org.chromium.base.ApiCompatibilityUtils; |
| 17 import org.chromium.chrome.R; | 17 import org.chromium.chrome.R; |
| 18 import org.chromium.chrome.browser.infobar.InfoBarControlLayout; | |
| 19 | 18 |
| 20 /** | 19 /** |
| 21 * Generic builder for promo dialogs. | 20 * Generic builder for promo dialogs. |
| 22 */ | 21 */ |
| 23 public abstract class PromoDialog | 22 public abstract class PromoDialog |
| 24 extends Dialog implements View.OnClickListener, DialogInterface.OnDismis
sListener { | 23 extends Dialog implements View.OnClickListener, DialogInterface.OnDismis
sListener { |
| 25 /** Parameters that can be used to create a new PromoDialog. */ | 24 /** Parameters that can be used to create a new PromoDialog. */ |
| 26 public static class DialogParams { | 25 public static class DialogParams { |
| 27 /** Optional: Resource ID of the Drawable to use for the promo illustrat
ion. */ | 26 /** Optional: Resource ID of the Drawable to use for the promo illustrat
ion. */ |
| 28 public int drawableResource; | 27 public int drawableResource; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 53 | 52 |
| 54 mScrimView = new FrameLayout(context); | 53 mScrimView = new FrameLayout(context); |
| 55 mScrimView.setBackgroundColor(ApiCompatibilityUtils.getColor( | 54 mScrimView.setBackgroundColor(ApiCompatibilityUtils.getColor( |
| 56 context.getResources(), R.color.modal_dialog_scrim_color)); | 55 context.getResources(), R.color.modal_dialog_scrim_color)); |
| 57 LayoutInflater.from(context).inflate(R.layout.promo_dialog_layout, mScri
mView, true); | 56 LayoutInflater.from(context).inflate(R.layout.promo_dialog_layout, mScri
mView, true); |
| 58 | 57 |
| 59 mDialogLayout = (PromoDialogLayout) mScrimView.findViewById(R.id.promo_d
ialog_layout); | 58 mDialogLayout = (PromoDialogLayout) mScrimView.findViewById(R.id.promo_d
ialog_layout); |
| 60 mDialogLayout.initialize(getDialogParams()); | 59 mDialogLayout.initialize(getDialogParams()); |
| 61 } | 60 } |
| 62 | 61 |
| 63 /** Add a standardized set of dialog controls. */ | 62 /** |
| 64 protected InfoBarControlLayout addControlLayout() { | 63 * Adds a View to the layout within the scrollable area. |
| 65 return mDialogLayout.addControlLayout(); | 64 * See {@link PromoDialogLayout#addControl}. |
| 65 */ |
| 66 protected void addControl(View control) { |
| 67 mDialogLayout.addControl(control); |
| 66 } | 68 } |
| 67 | 69 |
| 68 @Override | 70 @Override |
| 69 protected void onCreate(Bundle savedInstanceState) { | 71 protected void onCreate(Bundle savedInstanceState) { |
| 70 super.onCreate(savedInstanceState); | 72 super.onCreate(savedInstanceState); |
| 71 setContentView(mScrimView); | 73 setContentView(mScrimView); |
| 72 | 74 |
| 73 // Force the window to allow the dialog contents be as wide as necessary
. | 75 // Force the window to allow the dialog contents be as wide as necessary
. |
| 74 getWindow().setLayout(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARE
NT); | 76 getWindow().setLayout(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARE
NT); |
| 75 | 77 |
| 76 // Connect all the buttons to this class. | 78 // Connect all the buttons to this class. |
| 77 for (int interactiveViewId : CLICKABLE_BUTTON_IDS) { | 79 for (int interactiveViewId : CLICKABLE_BUTTON_IDS) { |
| 78 View view = findViewById(interactiveViewId); | 80 View view = findViewById(interactiveViewId); |
| 79 if (view != null) view.setOnClickListener(this); | 81 if (view != null) view.setOnClickListener(this); |
| 80 } | 82 } |
| 81 } | 83 } |
| 82 | 84 |
| 83 @Override | 85 @Override |
| 84 public void onClick(View view) {} | 86 public void onClick(View view) {} |
| 85 | 87 |
| 86 /** Returns a set of {@link DialogParams} that define what is shown in the p
romo dialog. */ | 88 /** Returns a set of {@link DialogParams} that define what is shown in the p
romo dialog. */ |
| 87 protected abstract DialogParams getDialogParams(); | 89 protected abstract DialogParams getDialogParams(); |
| 88 } | 90 } |
| OLD | NEW |