aboutsummaryrefslogtreecommitdiffhomepage
path: root/platform_tools/android/apps/viewer/src/main/java/org/skia/viewer/ViewerApplication.java
blob: 4b890bd5e1279cb2437a205d581b54aa04dffabc (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
/*
 * Copyright 2015 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

package org.skia.viewer;

import android.app.Application;

public class ViewerApplication extends Application {
    private long mNativeHandle = 0;
    private ViewerActivity mViewerActivity;

    static {
        System.loadLibrary("skia_android");
        System.loadLibrary("viewer");
    }

    private native long createNativeApp();
    private native void destroyNativeApp(long handle);

    @Override
    public void onCreate() {
        super.onCreate();
        mNativeHandle = createNativeApp();
    }

    @Override
    public void onTerminate() {
        if (mNativeHandle != 0) {
            destroyNativeApp(mNativeHandle);
            mNativeHandle = 0;
        }
        super.onTerminate();
    }

    public long getNativeHandle() {
        return mNativeHandle;
    }

    public void setViewerActivity(ViewerActivity viewerActivity) {
        this.mViewerActivity = viewerActivity;
    }

    public void setTitle(String title) {
        final String finalTitle = title;
        if (mViewerActivity != null) {
            mViewerActivity.runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    mViewerActivity.setTitle(finalTitle);
                }
            });
        }
    }
}