SDK Updater: icons for packages in remote page.
One of the rationales behind this was to show incompatible archives using some icon. This moves all SDK Updater icons in internal/repository/icons and create an ImageFactory available to the remote page via the UpdaterData.
@@ -229,6 +229,13 @@ public class RemotePackagesPage extends Composite implements ISdkListener {
|
|||||||
mDescriptionLabel.setText(""); //$NON-NLS1-$
|
mDescriptionLabel.setText(""); //$NON-NLS1-$
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle checking and unchecking of the tree items.
|
||||||
|
*
|
||||||
|
* When unchecking, all sub-tree items checkboxes are cleared too.
|
||||||
|
* When checking a source, all of its packages are checked too.
|
||||||
|
* When checking a package, only its compatible archives are checked.
|
||||||
|
*/
|
||||||
private void onTreeCheckStateChanged(CheckStateChangedEvent event) {
|
private void onTreeCheckStateChanged(CheckStateChangedEvent event) {
|
||||||
boolean b = event.getChecked();
|
boolean b = event.getChecked();
|
||||||
Object elem = event.getElement(); // Will be Archive or Package or RepoSource
|
Object elem = event.getElement(); // Will be Archive or Package or RepoSource
|
||||||
|
|||||||
@@ -16,13 +16,18 @@
|
|||||||
|
|
||||||
package com.android.sdkuilib.internal.repository;
|
package com.android.sdkuilib.internal.repository;
|
||||||
|
|
||||||
|
import com.android.sdklib.internal.repository.AddonPackage;
|
||||||
import com.android.sdklib.internal.repository.Archive;
|
import com.android.sdklib.internal.repository.Archive;
|
||||||
|
import com.android.sdklib.internal.repository.DocPackage;
|
||||||
import com.android.sdklib.internal.repository.IDescription;
|
import com.android.sdklib.internal.repository.IDescription;
|
||||||
import com.android.sdklib.internal.repository.ITask;
|
import com.android.sdklib.internal.repository.ITask;
|
||||||
import com.android.sdklib.internal.repository.ITaskMonitor;
|
import com.android.sdklib.internal.repository.ITaskMonitor;
|
||||||
import com.android.sdklib.internal.repository.Package;
|
import com.android.sdklib.internal.repository.Package;
|
||||||
|
import com.android.sdklib.internal.repository.PlatformPackage;
|
||||||
import com.android.sdklib.internal.repository.RepoSource;
|
import com.android.sdklib.internal.repository.RepoSource;
|
||||||
import com.android.sdklib.internal.repository.RepoSources;
|
import com.android.sdklib.internal.repository.RepoSources;
|
||||||
|
import com.android.sdklib.internal.repository.ToolPackage;
|
||||||
|
import com.android.sdkuilib.internal.repository.icons.ImageFactory;
|
||||||
|
|
||||||
import org.eclipse.jface.viewers.IContentProvider;
|
import org.eclipse.jface.viewers.IContentProvider;
|
||||||
import org.eclipse.jface.viewers.ILabelProvider;
|
import org.eclipse.jface.viewers.ILabelProvider;
|
||||||
@@ -39,11 +44,19 @@ import org.eclipse.swt.graphics.Image;
|
|||||||
class RepoSourcesAdapter {
|
class RepoSourcesAdapter {
|
||||||
|
|
||||||
private final RepoSources mRepoSources;
|
private final RepoSources mRepoSources;
|
||||||
|
private ImageFactory mImageFactory;
|
||||||
|
|
||||||
public RepoSourcesAdapter(RepoSources repoSources) {
|
public RepoSourcesAdapter(RepoSources repoSources) {
|
||||||
mRepoSources = repoSources;
|
mRepoSources = repoSources;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the image factory used by the label provider.
|
||||||
|
*/
|
||||||
|
public void setImageFactory(ImageFactory imageFactory) {
|
||||||
|
mImageFactory = imageFactory;
|
||||||
|
}
|
||||||
|
|
||||||
public ILabelProvider getLabelProvider() {
|
public ILabelProvider getLabelProvider() {
|
||||||
return new ViewerLabelProvider();
|
return new ViewerLabelProvider();
|
||||||
}
|
}
|
||||||
@@ -55,10 +68,40 @@ class RepoSourcesAdapter {
|
|||||||
|
|
||||||
// ------------
|
// ------------
|
||||||
|
|
||||||
public static class ViewerLabelProvider extends LabelProvider {
|
public class ViewerLabelProvider extends LabelProvider {
|
||||||
|
|
||||||
/** Returns null by default */
|
/** Returns null by default */
|
||||||
@Override
|
@Override
|
||||||
public Image getImage(Object element) {
|
public Image getImage(Object element) {
|
||||||
|
|
||||||
|
if (mImageFactory != null) {
|
||||||
|
if (element instanceof RepoSource) {
|
||||||
|
return mImageFactory.getImage("source_icon16.png");
|
||||||
|
|
||||||
|
} else if (element instanceof PlatformPackage) {
|
||||||
|
return mImageFactory.getImage("red_ball_icon16.png");
|
||||||
|
|
||||||
|
} else if (element instanceof AddonPackage) {
|
||||||
|
return mImageFactory.getImage("green_ball_icon16.png");
|
||||||
|
|
||||||
|
} else if (element instanceof ToolPackage) {
|
||||||
|
return mImageFactory.getImage("blue_ball_icon16.png");
|
||||||
|
|
||||||
|
} else if (element instanceof DocPackage) {
|
||||||
|
return mImageFactory.getImage("purple_ball_icon16.png");
|
||||||
|
|
||||||
|
} else if (element instanceof Package) {
|
||||||
|
return mImageFactory.getImage("gray_ball_icon16.png");
|
||||||
|
|
||||||
|
} else if (element instanceof Archive) {
|
||||||
|
if (((Archive) element).isCompatible()) {
|
||||||
|
return mImageFactory.getImage("archive_icon16.png");
|
||||||
|
} else {
|
||||||
|
return mImageFactory.getImage("incompat_icon16.png");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return super.getImage(element);
|
return super.getImage(element);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ import com.android.sdklib.internal.repository.ITaskMonitor;
|
|||||||
import com.android.sdklib.internal.repository.LocalSdkParser;
|
import com.android.sdklib.internal.repository.LocalSdkParser;
|
||||||
import com.android.sdklib.internal.repository.RepoSource;
|
import com.android.sdklib.internal.repository.RepoSource;
|
||||||
import com.android.sdklib.internal.repository.RepoSources;
|
import com.android.sdklib.internal.repository.RepoSources;
|
||||||
|
import com.android.sdkuilib.internal.repository.icons.ImageFactory;
|
||||||
|
|
||||||
import org.eclipse.swt.widgets.Display;
|
import org.eclipse.swt.widgets.Display;
|
||||||
|
|
||||||
@@ -52,6 +53,8 @@ class UpdaterData {
|
|||||||
private final LocalSdkAdapter mLocalSdkAdapter = new LocalSdkAdapter(this);
|
private final LocalSdkAdapter mLocalSdkAdapter = new LocalSdkAdapter(this);
|
||||||
private final RepoSourcesAdapter mSourcesAdapter = new RepoSourcesAdapter(mSources);
|
private final RepoSourcesAdapter mSourcesAdapter = new RepoSourcesAdapter(mSources);
|
||||||
|
|
||||||
|
private ImageFactory mImageFactory;
|
||||||
|
|
||||||
private final ArrayList<ISdkListener> mListeners = new ArrayList<ISdkListener>();
|
private final ArrayList<ISdkListener> mListeners = new ArrayList<ISdkListener>();
|
||||||
|
|
||||||
public interface ISdkListener {
|
public interface ISdkListener {
|
||||||
@@ -116,6 +119,15 @@ class UpdaterData {
|
|||||||
return mSdkLog;
|
return mSdkLog;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setImageFactory(ImageFactory imageFactory) {
|
||||||
|
mImageFactory = imageFactory;
|
||||||
|
mSourcesAdapter.setImageFactory(imageFactory);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ImageFactory getImageFactory() {
|
||||||
|
return mImageFactory;
|
||||||
|
}
|
||||||
|
|
||||||
public SdkManager getSdkManager() {
|
public SdkManager getSdkManager() {
|
||||||
return mSdkManager;
|
return mSdkManager;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,17 +21,15 @@ import com.android.sdklib.ISdkLog;
|
|||||||
import com.android.sdklib.SdkConstants;
|
import com.android.sdklib.SdkConstants;
|
||||||
import com.android.sdklib.internal.repository.RepoSource;
|
import com.android.sdklib.internal.repository.RepoSource;
|
||||||
import com.android.sdklib.repository.SdkRepository;
|
import com.android.sdklib.repository.SdkRepository;
|
||||||
|
import com.android.sdkuilib.internal.repository.icons.ImageFactory;
|
||||||
|
|
||||||
import org.eclipse.swt.SWT;
|
import org.eclipse.swt.SWT;
|
||||||
import org.eclipse.swt.SWTException;
|
|
||||||
import org.eclipse.swt.custom.SashForm;
|
import org.eclipse.swt.custom.SashForm;
|
||||||
import org.eclipse.swt.custom.StackLayout;
|
import org.eclipse.swt.custom.StackLayout;
|
||||||
import org.eclipse.swt.events.DisposeEvent;
|
import org.eclipse.swt.events.DisposeEvent;
|
||||||
import org.eclipse.swt.events.DisposeListener;
|
import org.eclipse.swt.events.DisposeListener;
|
||||||
import org.eclipse.swt.events.SelectionAdapter;
|
import org.eclipse.swt.events.SelectionAdapter;
|
||||||
import org.eclipse.swt.events.SelectionEvent;
|
import org.eclipse.swt.events.SelectionEvent;
|
||||||
import org.eclipse.swt.graphics.Image;
|
|
||||||
import org.eclipse.swt.graphics.ImageData;
|
|
||||||
import org.eclipse.swt.graphics.Point;
|
import org.eclipse.swt.graphics.Point;
|
||||||
import org.eclipse.swt.layout.FillLayout;
|
import org.eclipse.swt.layout.FillLayout;
|
||||||
import org.eclipse.swt.widgets.Composite;
|
import org.eclipse.swt.widgets.Composite;
|
||||||
@@ -39,7 +37,6 @@ import org.eclipse.swt.widgets.Display;
|
|||||||
import org.eclipse.swt.widgets.List;
|
import org.eclipse.swt.widgets.List;
|
||||||
import org.eclipse.swt.widgets.Shell;
|
import org.eclipse.swt.widgets.Shell;
|
||||||
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.lang.reflect.Constructor;
|
import java.lang.reflect.Constructor;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
@@ -71,7 +68,6 @@ public class UpdaterWindowImpl {
|
|||||||
private RemotePackagesPage mRemotePackagesPage;
|
private RemotePackagesPage mRemotePackagesPage;
|
||||||
private AvdManagerPage mAvdManagerPage;
|
private AvdManagerPage mAvdManagerPage;
|
||||||
private StackLayout mStackLayout;
|
private StackLayout mStackLayout;
|
||||||
private Image mIconImage;
|
|
||||||
|
|
||||||
public UpdaterWindowImpl(ISdkLog sdkLog, String osSdkRoot, boolean userCanChangeSdkRoot) {
|
public UpdaterWindowImpl(ISdkLog sdkLog, String osSdkRoot, boolean userCanChangeSdkRoot) {
|
||||||
mUpdaterData = new UpdaterData(osSdkRoot, sdkLog);
|
mUpdaterData = new UpdaterData(osSdkRoot, sdkLog);
|
||||||
@@ -174,33 +170,27 @@ public class UpdaterWindowImpl {
|
|||||||
* Callback called when the window shell is disposed.
|
* Callback called when the window shell is disposed.
|
||||||
*/
|
*/
|
||||||
private void onAndroidSdkUpdaterDispose() {
|
private void onAndroidSdkUpdaterDispose() {
|
||||||
if (mIconImage != null) {
|
if (mUpdaterData != null) {
|
||||||
mIconImage.dispose();
|
ImageFactory imgFactory = mUpdaterData.getImageFactory();
|
||||||
mIconImage = null;
|
if (imgFactory != null) {
|
||||||
|
imgFactory.dispose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates the icon of the window shell.
|
* Creates the icon of the window shell.
|
||||||
* The icon is disposed by {@link #onAndroidSdkUpdaterDispose()}.
|
|
||||||
*/
|
*/
|
||||||
private void setWindowImage(Shell androidSdkUpdater) {
|
private void setWindowImage(Shell androidSdkUpdater) {
|
||||||
String image = "android_icon_16.png"; //$NON-NLS-1$
|
String imageName = "android_icon_16.png"; //$NON-NLS-1$
|
||||||
if (SdkConstants.currentPlatform() == SdkConstants.PLATFORM_DARWIN) {
|
if (SdkConstants.currentPlatform() == SdkConstants.PLATFORM_DARWIN) {
|
||||||
image = "android_icon_128.png"; //$NON-NLS-1$
|
imageName = "android_icon_128.png"; //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
InputStream stream = getClass().getResourceAsStream(image);
|
|
||||||
if (stream != null) {
|
if (mUpdaterData != null) {
|
||||||
try {
|
ImageFactory imgFactory = mUpdaterData.getImageFactory();
|
||||||
ImageData imgData = new ImageData(stream);
|
if (imgFactory != null) {
|
||||||
mIconImage = new Image(mAndroidSdkUpdater.getDisplay(),
|
mAndroidSdkUpdater.setImage(imgFactory.getImage(imageName));
|
||||||
imgData,
|
|
||||||
imgData.getTransparencyMask());
|
|
||||||
mAndroidSdkUpdater.setImage(mIconImage);
|
|
||||||
} catch (SWTException e) {
|
|
||||||
mUpdaterData.getSdkLog().error(e, "Failed to set window icon"); //$NON-NLS-1$
|
|
||||||
} catch (IllegalArgumentException e) {
|
|
||||||
mUpdaterData.getSdkLog().error(e, "Failed to set window icon"); //$NON-NLS-1$
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -212,6 +202,7 @@ public class UpdaterWindowImpl {
|
|||||||
private void firstInit() {
|
private void firstInit() {
|
||||||
mTaskFactory = new ProgressTaskFactory(getShell());
|
mTaskFactory = new ProgressTaskFactory(getShell());
|
||||||
mUpdaterData.setTaskFactory(mTaskFactory);
|
mUpdaterData.setTaskFactory(mTaskFactory);
|
||||||
|
mUpdaterData.setImageFactory(new ImageFactory(getShell().getDisplay()));
|
||||||
|
|
||||||
addPage(mAvdManagerPage, "Virtual Devices");
|
addPage(mAvdManagerPage, "Virtual Devices");
|
||||||
addPage(mLocalPackagePage, "Installed Packages");
|
addPage(mLocalPackagePage, "Installed Packages");
|
||||||
|
|||||||
@@ -0,0 +1,85 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2009 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 com.android.sdkuilib.internal.repository.icons;
|
||||||
|
|
||||||
|
import org.eclipse.swt.SWTException;
|
||||||
|
import org.eclipse.swt.graphics.Image;
|
||||||
|
import org.eclipse.swt.graphics.ImageData;
|
||||||
|
import org.eclipse.swt.widgets.Display;
|
||||||
|
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Iterator;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An utility class to serve {@link Image} correspond to the various icons
|
||||||
|
* present in this package and dispose of them correctly at the end.
|
||||||
|
*/
|
||||||
|
public class ImageFactory {
|
||||||
|
|
||||||
|
private final Display mDisplay;
|
||||||
|
private final HashMap<String, Image> mImages = new HashMap<String, Image>();
|
||||||
|
|
||||||
|
public ImageFactory(Display display) {
|
||||||
|
mDisplay = display;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loads an image given its filename (with its extension).
|
||||||
|
* Might return null if the image cannot be loaded.
|
||||||
|
*/
|
||||||
|
public Image getImage(String imageName) {
|
||||||
|
|
||||||
|
Image image = mImages.get(imageName);
|
||||||
|
if (image != null) {
|
||||||
|
return image;
|
||||||
|
}
|
||||||
|
|
||||||
|
InputStream stream = getClass().getResourceAsStream(imageName);
|
||||||
|
if (stream != null) {
|
||||||
|
try {
|
||||||
|
ImageData imgData = new ImageData(stream);
|
||||||
|
image = new Image(mDisplay, imgData, imgData.getTransparencyMask());
|
||||||
|
} catch (SWTException e) {
|
||||||
|
// ignore
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Store the image in the hash, even if this failed. If it fails now, it will fail later.
|
||||||
|
mImages.put(imageName, image);
|
||||||
|
|
||||||
|
return image;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Dispose all the images created by this factory so far.
|
||||||
|
*/
|
||||||
|
public void dispose() {
|
||||||
|
Iterator<Image> it = mImages.values().iterator();
|
||||||
|
while(it.hasNext()) {
|
||||||
|
Image img = it.next();
|
||||||
|
if (img != null) {
|
||||||
|
img.dispose();
|
||||||
|
}
|
||||||
|
it.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
Before Width: | Height: | Size: 6.6 KiB After Width: | Height: | Size: 6.6 KiB |
|
Before Width: | Height: | Size: 460 B After Width: | Height: | Size: 460 B |
|
After Width: | Height: | Size: 493 B |
|
After Width: | Height: | Size: 376 B |
|
After Width: | Height: | Size: 396 B |
|
After Width: | Height: | Size: 370 B |
|
After Width: | Height: | Size: 735 B |
|
After Width: | Height: | Size: 392 B |
|
After Width: | Height: | Size: 380 B |
|
After Width: | Height: | Size: 879 B |