OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 package org.chromium.chrome.browser.dom_distiller; |
| 6 |
| 7 import android.view.LayoutInflater; |
| 8 import android.view.View; |
| 9 import android.view.ViewGroup; |
| 10 |
| 11 import com.google.android.apps.chrome.R; |
| 12 |
| 13 import org.chromium.chrome.browser.ChromeActivity; |
| 14 import org.chromium.chrome.browser.widget.ReaderModeControl; |
| 15 import org.chromium.ui.resources.dynamics.DynamicResourceLoader; |
| 16 |
| 17 |
| 18 /** |
| 19 * Manager for the Reader Mode feature. |
| 20 * This class keeps track of the status of Reader Mode and coordinates the contr
ol |
| 21 * with the layout. |
| 22 */ |
| 23 public class ReaderModeActivityDelegate { |
| 24 private static final String TAG = "ReaderModeActivityDelegate"; |
| 25 |
| 26 private DynamicResourceLoader mResourceLoader; |
| 27 private ReaderModeControl mControl; |
| 28 private final ChromeActivity mActivity; |
| 29 private ViewGroup mParentView; |
| 30 |
| 31 /** |
| 32 * Constructs the manager for the given activity, and will attach views to t
he given parent. |
| 33 * @param activity The {@code ChromeActivity} in use. |
| 34 */ |
| 35 public ReaderModeActivityDelegate(ChromeActivity activity) { |
| 36 mActivity = activity; |
| 37 } |
| 38 |
| 39 /** |
| 40 * Initializes this manager. Must be called before {@link #getReaderModeCon
trol()}. |
| 41 * @param parentView The parent view to attach Reader Mode UX to. |
| 42 */ |
| 43 public void initialize(ViewGroup parentView) { |
| 44 mParentView = parentView; |
| 45 } |
| 46 |
| 47 /** |
| 48 * Destroys the Reader Mode activity delegate. |
| 49 */ |
| 50 public void destroy() { |
| 51 if (mControl != null) { |
| 52 ((ViewGroup) mControl.getParent()).removeView(mControl); |
| 53 mControl = null; |
| 54 if (mResourceLoader != null) { |
| 55 mResourceLoader.unregisterResource(R.id.contextual_search_view); |
| 56 } |
| 57 } |
| 58 mParentView = null; |
| 59 } |
| 60 |
| 61 /** |
| 62 * @param resourceLoader The {@link DynamicResourceLoader} to register and u
nregister the view. |
| 63 */ |
| 64 public void setDynamicResourceLoader(DynamicResourceLoader resourceLoader) { |
| 65 mResourceLoader = resourceLoader; |
| 66 if (mControl != null) { |
| 67 mResourceLoader.registerResource(R.id.reader_mode_view, |
| 68 mControl.getResourceAdapter()); |
| 69 } |
| 70 } |
| 71 |
| 72 /** |
| 73 * Inflates the Reader Mode control, if needed. |
| 74 */ |
| 75 public ReaderModeControl getReaderModeControl() { |
| 76 assert mParentView != null; |
| 77 if (mControl == null) { |
| 78 LayoutInflater.from(mActivity).inflate(R.layout.reader_mode_control,
mParentView); |
| 79 mControl = (ReaderModeControl) |
| 80 mParentView.findViewById(R.id.reader_mode_view); |
| 81 if (mResourceLoader != null) { |
| 82 mResourceLoader.registerResource(R.id.reader_mode_view, |
| 83 mControl.getResourceAdapter()); |
| 84 } |
| 85 } |
| 86 assert mControl != null; |
| 87 mControl.setVisibility(View.INVISIBLE); |
| 88 return mControl; |
| 89 } |
| 90 } |
OLD | NEW |