diff options
author | 2016-05-09 08:49:29 -0700 | |
---|---|---|
committer | 2016-05-09 08:49:29 -0700 | |
commit | 796c5bb4655a511553970e111c96d90963fb9ae4 (patch) | |
tree | c6ac0daf5a9a1756ddc55ec09728b2c0d3b31b29 /platform_tools | |
parent | 5a493cdbeca87f85e2b08914c176c29d914083d9 (diff) |
Initial commit of our new Android app to demo Skia.
Currently, there's only a simple Activity with a title bar and a surface view
that connects with Skia viewer native application.
Before integrating user action events, I want to make sure that the design and
implementation so far are good. Note that the old NativeApplication-based
Activity (ViewerActivity) is still there for reference and test purposes. It
will be removed eventually.
BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1952323004
Review-Url: https://codereview.chromium.org/1952323004
Diffstat (limited to 'platform_tools')
4 files changed, 100 insertions, 19 deletions
diff --git a/platform_tools/android/apps/viewer/src/main/AndroidManifest.xml b/platform_tools/android/apps/viewer/src/main/AndroidManifest.xml index 2ed88e1da6..a1fd9714e3 100644 --- a/platform_tools/android/apps/viewer/src/main/AndroidManifest.xml +++ b/platform_tools/android/apps/viewer/src/main/AndroidManifest.xml @@ -7,14 +7,11 @@ <application android:allowBackup="false" + android:theme="@android:style/Theme.Holo.Light" + android:name=".ViewerApplication" android:label="Viewer"> - <activity android:name=".ViewerActivity" - android:label="Viewer" - android:screenOrientation="portrait" - android:configChanges="orientation|keyboardHidden"> - <meta-data android:name="android.app.lib_name" - android:value="viewer" /> + <activity android:name=".ViewerActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> diff --git a/platform_tools/android/apps/viewer/src/main/java/org/skia/viewer/ViewerActivity.java b/platform_tools/android/apps/viewer/src/main/java/org/skia/viewer/ViewerActivity.java index 950d6b2d5b..48cec39f48 100644 --- a/platform_tools/android/apps/viewer/src/main/java/org/skia/viewer/ViewerActivity.java +++ b/platform_tools/android/apps/viewer/src/main/java/org/skia/viewer/ViewerActivity.java @@ -7,22 +7,48 @@ package org.skia.viewer; -import android.app.ActionBar; +import android.app.Activity; import android.os.Bundle; -import android.provider.Settings; -import android.view.View; -import android.view.WindowManager; +import android.view.Surface; +import android.view.SurfaceHolder; +import android.view.SurfaceView; + +public class ViewerActivity extends Activity implements SurfaceHolder.Callback { + private SurfaceView mView; + private ViewerApplication mApplication; + + private native void onSurfaceCreated(long handle, Surface surface); + private native void onSurfaceChanged(long handle, Surface surface); + private native void onSurfaceDestroyed(long handle); -public class ViewerActivity extends android.app.NativeActivity { - static { - System.loadLibrary("skia_android"); - } - @Override - public void onCreate(Bundle savedInstanceState) - { + protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - ActionBar ab = this.getActionBar(); - ab.hide(); + setContentView(R.layout.activity_main); + + mApplication = (ViewerApplication) getApplication(); + mView = (SurfaceView) findViewById(R.id.surfaceView); + mView.getHolder().addCallback(this); + } + + @Override + public void surfaceCreated(SurfaceHolder holder) { + if (mApplication.getNativeHandle() != 0) { + onSurfaceCreated(mApplication.getNativeHandle(), holder.getSurface()); + } + } + + @Override + public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { + if (mApplication.getNativeHandle() != 0) { + onSurfaceChanged(mApplication.getNativeHandle(), holder.getSurface()); + } + } + + @Override + public void surfaceDestroyed(SurfaceHolder holder) { + if (mApplication.getNativeHandle() != 0) { + onSurfaceDestroyed(mApplication.getNativeHandle()); + } } } diff --git a/platform_tools/android/apps/viewer/src/main/java/org/skia/viewer/ViewerApplication.java b/platform_tools/android/apps/viewer/src/main/java/org/skia/viewer/ViewerApplication.java new file mode 100644 index 0000000000..9389f72208 --- /dev/null +++ b/platform_tools/android/apps/viewer/src/main/java/org/skia/viewer/ViewerApplication.java @@ -0,0 +1,41 @@ +/* + * 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; + + 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; + } +} diff --git a/platform_tools/android/apps/viewer/src/main/res/layout/activity_main.xml b/platform_tools/android/apps/viewer/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000000..6597a48dcc --- /dev/null +++ b/platform_tools/android/apps/viewer/src/main/res/layout/activity_main.xml @@ -0,0 +1,17 @@ +<?xml version="1.0" encoding="utf-8"?> +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:tools="http://schemas.android.com/tools" + android:id="@+id/mainLayout" + android:orientation="vertical" + android:layout_width="match_parent" + android:layout_height="match_parent" + tools:context=".ViewerActivity"> + + <SurfaceView + android:id="@+id/surfaceView" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:layout_centerVertical="true" + android:layout_centerHorizontal="true" /> + +</LinearLayout> |