1 /* 2 * Copyright (C) 2009 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.sdkmanager.internal.repository; 18 19 20 import com.android.sdklib.SdkConstants; 21 import com.android.sdklib.repository.PkgProps; 22 import com.android.sdklib.repository.SdkAddonConstants; 23 import com.android.sdklib.repository.SdkRepoConstants; 24 import com.android.sdkmanager.Main; 25 import com.android.sdkuilib.internal.repository.UpdaterPage; 26 27 import org.eclipse.swt.SWT; 28 import org.eclipse.swt.graphics.Image; 29 import org.eclipse.swt.layout.GridData; 30 import org.eclipse.swt.layout.GridLayout; 31 import org.eclipse.swt.widgets.Composite; 32 import org.eclipse.swt.widgets.Label; 33 34 import java.io.File; 35 import java.io.FileInputStream; 36 import java.io.FileNotFoundException; 37 import java.io.IOException; 38 import java.io.InputStream; 39 import java.util.Properties; 40 41 public class AboutPage extends UpdaterPage { 42 43 private Label mLabel; 44 45 /** 46 * Create the composite. 47 * @param parent The parent of the composite. 48 */ 49 public AboutPage(Composite parent, int swtStyle) { 50 super(parent, swtStyle); 51 52 createContents(this); 53 54 postCreate(); //$hide$ 55 } 56 57 @Override 58 public String getPageTitle() { 59 return "About"; 60 } 61 62 private void createContents(Composite parent) { 63 parent.setLayout(new GridLayout(2, false)); 64 65 Label logo = new Label(parent, SWT.NONE); 66 InputStream imageStream = this.getClass().getResourceAsStream("logo.png"); //$NON-NLS-1$ 67 68 if (imageStream != null) { 69 Image img = new Image(parent.getShell().getDisplay(), imageStream); 70 logo.setImage(img); 71 } 72 73 mLabel = new Label(parent, SWT.NONE); 74 mLabel.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1)); 75 mLabel.setText(String.format( 76 "Android SDK Updater.\n" + 77 "Revision %1$s\n" + 78 "Add-on XML Schema #%2$d\n" + 79 "Repository XML Schema #%3$d\n" + 80 "Copyright (C) 2009-2011 The Android Open Source Project.", 81 getRevision(), 82 SdkAddonConstants.NS_LATEST_VERSION, 83 SdkRepoConstants.NS_LATEST_VERSION)); 84 } 85 86 @Override 87 protected void checkSubclass() { 88 // Disable the check that prevents subclassing of SWT components 89 } 90 91 // -- Start of internal part ---------- 92 // Hide everything down-below from SWT designer 93 //$hide>>$ 94 95 /** 96 * Called by the constructor right after {@link #createContents(Composite)}. 97 */ 98 private void postCreate() { 99 } 100 101 // End of hiding from SWT Designer 102 //$hide<<$ 103 104 private String getRevision() { 105 Properties p = new Properties(); 106 try{ 107 String toolsdir = System.getProperty(Main.TOOLSDIR); 108 File sourceProp; 109 if (toolsdir == null || toolsdir.length() == 0) { 110 sourceProp = new File(SdkConstants.FN_SOURCE_PROP); 111 } else { 112 sourceProp = new File(toolsdir, SdkConstants.FN_SOURCE_PROP); 113 } 114 FileInputStream fis = null; 115 try { 116 fis = new FileInputStream(sourceProp); 117 p.load(fis); 118 } finally { 119 if (fis != null) { 120 try { 121 fis.close(); 122 } catch (IOException ignore) { 123 } 124 } 125 } 126 127 String revision = p.getProperty(PkgProps.PKG_REVISION); 128 if (revision != null) { 129 return revision; 130 } 131 } catch (FileNotFoundException e) { 132 // couldn't find the file? don't ping. 133 } catch (IOException e) { 134 // couldn't find the file? don't ping. 135 } 136 137 return "?"; 138 } 139 } 140