aboutsummaryrefslogtreecommitdiffstats
path: root/sdkmanager/app/src/com/android/sdkmanager/internal/repository/AboutPage.java
blob: 114aa22d82887221a071f098752000da79e80bf4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/*
 * 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.sdkmanager.internal.repository;


import com.android.sdklib.SdkConstants;
import com.android.sdklib.internal.repository.Package;
import com.android.sdklib.repository.SdkRepoConstants;
import com.android.sdkmanager.*;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class AboutPage extends Composite {

    private Label mLabel;

    /**
     * Create the composite.
     * @param parent The parent of the composite.
     */
    public AboutPage(Composite parent) {
        super(parent, SWT.BORDER);

        createContents(this);

        postCreate();  //$hide$
    }

    private void createContents(Composite parent) {
        parent.setLayout(new GridLayout(2, false));

        Label logo = new Label(parent, SWT.NONE);
        InputStream imageStream = this.getClass().getResourceAsStream("logo.png"); //$NON-NLS-1$

        if (imageStream != null) {
            Image img = new Image(parent.getShell().getDisplay(), imageStream);
            logo.setImage(img);
        }

        mLabel = new Label(parent, SWT.NONE);
        mLabel.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1));
        mLabel.setText(String.format(
                "Android SDK Updater.\n" +
                "Revision %1$s\n" +
                "Repository XML Schema #%2$d\n" +
                "Copyright (C) 2009-2010 The Android Open Source Project.",
                getRevision(),
                SdkRepoConstants.NS_LATEST_VERSION));
    }

    @Override
    protected void checkSubclass() {
        // Disable the check that prevents subclassing of SWT components
    }

    // -- Start of internal part ----------
    // Hide everything down-below from SWT designer
    //$hide>>$

    /**
     * Called by the constructor right after {@link #createContents(Composite)}.
     */
    private void postCreate() {
    }

    // End of hiding from SWT Designer
    //$hide<<$

    private String getRevision() {
        Properties p = new Properties();
        try{
            String toolsdir = System.getProperty(Main.TOOLSDIR);
            File sourceProp;
            if (toolsdir == null || toolsdir.length() == 0) {
                sourceProp = new File(SdkConstants.FN_SOURCE_PROP);
            } else {
                sourceProp = new File(toolsdir, SdkConstants.FN_SOURCE_PROP);
            }
            p.load(new FileInputStream(sourceProp));
            String revision = p.getProperty(Package.PROP_REVISION);
            if (revision != null) {
                return revision;
            }
        } catch (FileNotFoundException e) {
            // couldn't find the file? don't ping.
        } catch (IOException e) {
            // couldn't find the file? don't ping.
        }

        return "?";
    }
}