Chromium Code Reviews| Index: chrome/android/java/src/org/chromium/chrome/browser/infobar/PermissionGroupInfoBarAndroid.java |
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/infobar/PermissionGroupInfoBarAndroid.java b/chrome/android/java/src/org/chromium/chrome/browser/infobar/PermissionGroupInfoBarAndroid.java |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..7e53d9e38d800793853c7cdbf4ca6361a25ada0a |
| --- /dev/null |
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/infobar/PermissionGroupInfoBarAndroid.java |
| @@ -0,0 +1,124 @@ |
| +// Copyright 2015 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.infobar; |
| + |
| +import android.view.LayoutInflater; |
| +import android.view.ViewGroup; |
| +import android.widget.ImageView; |
| +import android.widget.Switch; |
| +import android.widget.TextView; |
| + |
| +import org.chromium.base.ApplicationStatus; |
| +import org.chromium.base.annotations.CalledByNative; |
| +import org.chromium.chrome.R; |
| +import org.chromium.chrome.browser.ContentSettingsType; |
| +import org.chromium.ui.base.WindowAndroid; |
| + |
| +/** |
| + * TODO(lalitm) |
| + */ |
|
gone
2015/09/25 16:43:52
nit: fill out this todo at some point
Lalit Maganti
2015/09/28 09:24:01
Done.
|
| +public class PermissionGroupInfoBarAndroid extends ConfirmInfoBar |
| + implements InfoBarListeners.Confirm { |
| + |
| + private final String[] mPermissionMessages; |
| + private final int[] mContentSettings; |
| + |
| + private long mNativePointer; |
| + private ViewGroup mCustomView; |
| + |
| + private PermissionGroupInfoBarAndroid(long nativePtr, String messageTitle, |
| + String[] permissionMessages, int[] contentSettings) { |
| + super(null, 0, null, messageTitle, null, getAcceptButtonText(), null); |
| + setConfirmListener(this); |
| + |
| + mNativePointer = nativePtr; |
| + mPermissionMessages = permissionMessages; |
| + mContentSettings = contentSettings; |
| + } |
| + |
|
gone
2015/09/25 16:43:52
nit: remove newline
Lalit Maganti
2015/09/28 09:24:02
Done.
|
| + |
| + @CalledByNative |
| + protected void onNativeDestroyed() { |
| + super.onNativeDestroyed(); |
| + mNativePointer = 0; |
| + } |
| + |
| + @Override |
| + public void createContent(InfoBarLayout layout) { |
| + super.createContent(layout); |
| + |
| + mCustomView = (ViewGroup) LayoutInflater.from(getContext()) |
| + .inflate(R.layout.permission_group_infobar, null); |
| + |
| + for (int i = 0; i < mContentSettings.length; i++) { |
| + ViewGroup subView = (ViewGroup) LayoutInflater.from(getContext()) |
| + .inflate(R.layout.permission_group_infobar_item, null); |
| + TextView textView = (TextView) subView.findViewById( |
| + R.id.permission_group_infobar_item_text); |
| + ImageView iconView = (ImageView) subView.findViewById( |
| + R.id.permission_group_infobar_item_icon); |
| + |
| + textView.setText(mPermissionMessages[i]); |
| + iconView.setImageResource(contentSettingToIconResource(mContentSettings[i])); |
| + mCustomView.addView(subView); |
| + } |
| + |
| + layout.setCustomContent(mCustomView); |
| + } |
| + |
| + @Override |
| + public void onConfirmInfoBarButtonClicked(ConfirmInfoBar infoBar, boolean confirm) { |
| + boolean[] checkedState = new boolean[mContentSettings.length]; |
|
gone
2015/09/25 16:43:52
I think you can override this instead, then get ri
Lalit Maganti
2015/09/28 09:24:02
I think I actually need to override the single par
|
| + for (int i = 0; i < mContentSettings.length; i++) { |
| + Switch childSwitch = (Switch) mCustomView.getChildAt(i) |
| + .findViewById(R.id.permission_group_infobar_item_switch); |
| + checkedState[i] = childSwitch.isChecked(); |
| + } |
| + nativeOnCheckedStateUpdate(mNativePointer, checkedState); |
| + } |
| + |
| + @Override |
| + public void onInfoBarDismissed(InfoBar infoBar) { |
| + } |
| + |
| + private static int contentSettingToIconResource(int type) { |
| + switch (type) { |
| + case ContentSettingsType.CONTENT_SETTINGS_TYPE_GEOLOCATION: |
| + return R.drawable.permission_location; |
| + case ContentSettingsType.CONTENT_SETTINGS_TYPE_NOTIFICATIONS: |
| + return R.drawable.permission_push_notification; |
| + case ContentSettingsType.CONTENT_SETTINGS_TYPE_MIDI_SYSEX: |
| + return R.drawable.permission_midi; |
| + case ContentSettingsType.CONTENT_SETTINGS_TYPE_PUSH_MESSAGING: |
| + return R.drawable.permission_push_notification; |
| + case ContentSettingsType.CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER: |
| + return R.drawable.permission_protected_media; |
| + case ContentSettingsType.CONTENT_SETTINGS_TYPE_DURABLE_STORAGE: |
| + return R.drawable.permission_cookie; |
| + case ContentSettingsType.CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC: |
| + return R.drawable.permission_mic; |
| + case ContentSettingsType.CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA: |
| + return R.drawable.permission_camera; |
|
gone
2015/09/25 16:43:52
I think you're supposed to use
default:
asser
Lalit Maganti
2015/09/28 09:24:02
Done.
|
| + } |
| + assert false; |
| + return R.drawable.permission_location; |
| + } |
| + |
| + private static String getAcceptButtonText() { |
| + return ApplicationStatus.getApplicationContext().getString(R.string.ok); |
| + } |
| + |
| + @CalledByNative |
| + private static InfoBar createInfoBar(long nativePtr, WindowAndroid windowAndroid, |
| + String messageTitle, String[] permissionMessages, int[] contentSettings) { |
| + PermissionGroupInfoBarAndroid infobar = new PermissionGroupInfoBarAndroid( |
| + nativePtr, messageTitle, permissionMessages, contentSettings); |
| + infobar.setContentSettings(windowAndroid, contentSettings); |
| + return infobar; |
| + } |
| + |
| + private native void nativeOnCheckedStateUpdate(long nativePermissionGroupInfoBarAndroid, |
| + boolean[] checked); |
| +} |