summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Lockwood <alockwood@google.com>2014-10-20 12:08:34 -0400
committerAlex Lockwood <alockwood@google.com>2014-10-22 10:29:25 -0400
commit2176c470cbdf8ce0c95b5d6b5612ca42a33a4593 (patch)
tree9959d5a5d24d5fadb00ba0812c3e2cc49e2161e2
parent264a535d6587bad6f9d80c870459a949f4c97857 (diff)
downloadlogin-2176c470cbdf8ce0c95b5d6b5612ca42a33a4593.tar.gz
Update login code to use theme/resolution aware Google logo
Note that there are still some images/icons that should be migrated to the new GoogleLoginIcons class. I can do that in a new CL once this one goes through. Bug: 17960252 Change-Id: Iaa28d74edf8d97c5ba78da5d068429abf5eb201d
-rw-r--r--resources/icons/GoogleLoginIcons.java53
-rw-r--r--resources/icons/google_logo.pngbin0 -> 2510 bytes
-rw-r--r--resources/icons/google_logo@2x.pngbin0 -> 5150 bytes
-rw-r--r--resources/icons/google_logo@2x_dark.pngbin0 -> 2060 bytes
-rw-r--r--resources/icons/google_logo_dark.pngbin0 -> 984 bytes
-rw-r--r--src/com/google/gct/login/ui/UsersListCellRenderer.java18
6 files changed, 58 insertions, 13 deletions
diff --git a/resources/icons/GoogleLoginIcons.java b/resources/icons/GoogleLoginIcons.java
new file mode 100644
index 0000000..715ef72
--- /dev/null
+++ b/resources/icons/GoogleLoginIcons.java
@@ -0,0 +1,53 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package icons;
+
+import com.intellij.openapi.util.IconLoader;
+
+import javax.swing.*;
+
+/**
+ * A utility class that loads the icons that are used by the Google Login plugin.
+ *
+ * Using this class to load icons is preferred over creating scaled image icons manually in code,
+ * as this utility class will automatically select the appropriate icons based on the current
+ * theme (IntelliJ classic vs. Darcula) and will automatically select high resolution icons
+ * for retina displays.
+ *
+ * To ensure the appropriate icons are selected, they should be named according to the following rules:
+ *
+ * <ul>
+ * <li>icon_name.png - The IntelliJ classic image icon to use.</li>
+ * <li>icon_name@2x.png - The IntelliJ classic image icon to use for retina displays.</li>
+ * <li>icon_name_dark.png - The Darcula image icon to use.</li>
+ * <li>icon_name@2x_dark.png - The Darcula image icon to use for retina displays.</li>
+ * </ul>
+ *
+ * Note that if no alternative image icons are specified, the single provided image icon
+ * will be used in all themes and resolutions.
+ */
+public final class GoogleLoginIcons {
+
+ public static final Icon GOOGLE_LOGO = load("/icons/google_logo.png");
+
+ private static Icon load(String path) {
+ return IconLoader.getIcon(path, GoogleLoginIcons.class);
+ }
+
+ private GoogleLoginIcons() {
+ // This utility class should not be instantiated.
+ }
+}
diff --git a/resources/icons/google_logo.png b/resources/icons/google_logo.png
new file mode 100644
index 0000000..c8ae624
--- /dev/null
+++ b/resources/icons/google_logo.png
Binary files differ
diff --git a/resources/icons/google_logo@2x.png b/resources/icons/google_logo@2x.png
new file mode 100644
index 0000000..65f54b4
--- /dev/null
+++ b/resources/icons/google_logo@2x.png
Binary files differ
diff --git a/resources/icons/google_logo@2x_dark.png b/resources/icons/google_logo@2x_dark.png
new file mode 100644
index 0000000..3263694
--- /dev/null
+++ b/resources/icons/google_logo@2x_dark.png
Binary files differ
diff --git a/resources/icons/google_logo_dark.png b/resources/icons/google_logo_dark.png
new file mode 100644
index 0000000..b37179c
--- /dev/null
+++ b/resources/icons/google_logo_dark.png
Binary files differ
diff --git a/src/com/google/gct/login/ui/UsersListCellRenderer.java b/src/com/google/gct/login/ui/UsersListCellRenderer.java
index 5796029..a0534a7 100644
--- a/src/com/google/gct/login/ui/UsersListCellRenderer.java
+++ b/src/com/google/gct/login/ui/UsersListCellRenderer.java
@@ -15,12 +15,12 @@
*/
package com.google.gct.login.ui;
-import com.intellij.ui.ColorUtil;
import com.google.api.client.util.Maps;
import com.google.gct.login.CredentialedUser;
import com.google.gct.login.GoogleLogin;
import com.intellij.ui.JBColor;
import com.intellij.util.ui.UIUtil;
+import icons.GoogleLoginIcons;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
@@ -36,7 +36,6 @@ import java.awt.GridBagLayout;
import java.awt.Image;
import java.awt.Point;
import java.awt.Toolkit;
-import java.net.URL;
import java.util.Map;
/**
@@ -47,8 +46,6 @@ public class UsersListCellRenderer extends JComponent implements ListCellRendere
private final static String CLOUD_LABEL_TEXT = "Open Google Developers Console";
private final static String PLAY_LABEL_TEXT = "Open Play Developer Console";
private final static String DEFAULT_AVATAR = "/icons/loginAvatar@2x.png";
- private final static String GOOGLE_IMG_COL = "/icons/googleColored.png";
- private final static String GOOGLE_IMG_WHITE = "/icons/googleWhite.png";
private final static String SIGN_IN_TEXT = "<HTML> Sign in with your Google account to start <br> adding "
+ "Cloud functionality to your <br> Android applications from Android Studio. </HTML>";
private final static String LEARN_MORE_TEXT = "Learn more";
@@ -58,8 +55,6 @@ public class UsersListCellRenderer extends JComponent implements ListCellRendere
private static final int PLAIN_USER_IMAGE_HEIGHT = 48;
private static final int ACTIVE_USER_IMAGE_WIDTH = 96;
private static final int ACTIVE_USER_IMAGE_HEIGHT = 96;
- private static final int GOOGLE_IMAGE_WIDTH = 96;
- private static final int GOOGLE_IMAGE_HEIGHT = 35;
private static final int GOOGLE_IMAGE_NORTH = 18;
private static final int GOOGLE_IMAGE_WEST = 18;
private static final int WELCOME_LABEL_NORTH = 15;
@@ -76,6 +71,7 @@ public class UsersListCellRenderer extends JComponent implements ListCellRendere
private final Dimension myCloudLabelDimension;
private final Dimension myPlayLabelDimension;
private final Dimension myLearnMoreLabelDimension;
+ private JLabel myGoogleImageLabel;
/** Maps user emails to large user image icons. */
private final Map<String, Image> myUserLargeImageCache = Maps.newHashMap();
@@ -184,7 +180,7 @@ public class UsersListCellRenderer extends JComponent implements ListCellRendere
public boolean inLearnMoreUrl(Point point) {
// 3 is for the number of labels and row of texts
- double urlYStart = GOOGLE_IMAGE_NORTH + GOOGLE_IMAGE_HEIGHT + WELCOME_LABEL_NORTH
+ double urlYStart = GOOGLE_IMAGE_NORTH + myGoogleImageLabel.getIcon().getIconHeight() + WELCOME_LABEL_NORTH
+ (myGeneralFontHeight * 3) + 3;
double urlYEnd = urlYStart + myLearnMoreLabelDimension.getHeight();
double urlXStart = GOOGLE_IMAGE_WEST;
@@ -273,11 +269,7 @@ public class UsersListCellRenderer extends JComponent implements ListCellRendere
mainPanel.setBackground(JBColor.WHITE);
mainPanel.setBorder(BorderFactory.createEmptyBorder(0, GOOGLE_IMAGE_WEST, 0, 0));
- String googleIcon = UIUtil.isUnderDarcula() ? GOOGLE_IMG_WHITE : GOOGLE_IMG_COL;
- URL url = UsersListCellRenderer.class.getResource(googleIcon);
- Image image = Toolkit.getDefaultToolkit().getImage(url);
- Image scaledImage = image.getScaledInstance(GOOGLE_IMAGE_WIDTH, GOOGLE_IMAGE_HEIGHT, Image.SCALE_SMOOTH);
- JLabel imageLabel = new JLabel(new ImageIcon(scaledImage));
+ myGoogleImageLabel = new JLabel(GoogleLoginIcons.GOOGLE_LOGO);
JLabel signInLabel = new JLabel(SIGN_IN_TEXT);
signInLabel.setFont(myGeneralFont);
@@ -290,7 +282,7 @@ public class UsersListCellRenderer extends JComponent implements ListCellRendere
urlLabel.setPreferredSize(myLearnMoreLabelDimension);
mainPanel.add(Box.createVerticalStrut(GOOGLE_IMAGE_NORTH));
- mainPanel.add(imageLabel);
+ mainPanel.add(myGoogleImageLabel);
mainPanel.add(Box.createVerticalStrut(WELCOME_LABEL_NORTH));
mainPanel.add(signInLabel);
mainPanel.add(urlLabel);