From 3ca73360493ba71831c86c8c5f9c36187c0355ca Mon Sep 17 00:00:00 2001 From: kkinnunen Date: Mon, 18 Jan 2016 00:47:14 -0800 Subject: [PATCH] SampleApp: remove SkWindow::onPDFSaved, it does not work Remove SkWindow::onPDFSaved, it does not work and it is not used anymore. Also, it is very SampleApp -specific feature implemented in SkWindow class. SkWindow class is probably intended to be more app-agnosting than what this method implies. Presumably the idea of the callback was to inform the user of SampleApp that the PDF was saved to a certain location. For Android SampleApp, show a hardcoded toast that the PDF was saved to /sdcard. BUG=skia:4733 GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1547923002 Review URL: https://codereview.chromium.org/1547923002 --- include/views/SkOSWindow_Android.h | 2 -- include/views/SkWindow.h | 3 -- .../java/com/skia/SkiaSampleActivity.java | 28 ------------------- .../main/java/com/skia/SkiaSampleView.java | 4 +++ .../main/jni/com_skia_SkiaSampleRenderer.cpp | 28 ------------------- .../src/main/res/values/strings.xml | 5 ++-- .../src/main/jni/SkOSWindow_AndroidNative.cpp | 3 -- 7 files changed, 6 insertions(+), 67 deletions(-) diff --git a/include/views/SkOSWindow_Android.h b/include/views/SkOSWindow_Android.h index 09163fc1cb..4fc32ce19d 100644 --- a/include/views/SkOSWindow_Android.h +++ b/include/views/SkOSWindow_Android.h @@ -36,8 +36,6 @@ public: void setVsync(bool); bool destroyRequested() { return fDestroyRequested; } - virtual void onPDFSaved(const char title[], const char desc[], const char path[]); - protected: // overrides from SkWindow virtual void onHandleInval(const SkIRect&); diff --git a/include/views/SkWindow.h b/include/views/SkWindow.h index f56c27c022..0d47875bf7 100644 --- a/include/views/SkWindow.h +++ b/include/views/SkWindow.h @@ -72,9 +72,6 @@ public: virtual SkSurface* createSurface(); - virtual void onPDFSaved(const char title[], const char desc[], - const char path[]) {} - protected: virtual bool onEvent(const SkEvent&); virtual bool onDispatchClick(int x, int y, Click::State, void* owner, unsigned modi); diff --git a/platform_tools/android/apps/sample_app/src/main/java/com/skia/SkiaSampleActivity.java b/platform_tools/android/apps/sample_app/src/main/java/com/skia/SkiaSampleActivity.java index d9cd9f887d..6e306966ed 100644 --- a/platform_tools/android/apps/sample_app/src/main/java/com/skia/SkiaSampleActivity.java +++ b/platform_tools/android/apps/sample_app/src/main/java/com/skia/SkiaSampleActivity.java @@ -23,7 +23,6 @@ import android.view.ViewGroup; import android.widget.ArrayAdapter; import android.widget.LinearLayout; import android.widget.TextView; -import android.widget.Toast; import java.io.File; @@ -209,7 +208,6 @@ public class SkiaSampleActivity extends Activity private static final int SET_TITLE = 1; private static final int SET_SLIDES = 2; - private static final int TOAST_DOWNLOAD = 3; private Handler mHandler = new Handler() { @Override @@ -222,10 +220,6 @@ public class SkiaSampleActivity extends Activity case SET_SLIDES: mSlideList.addAll((String[]) msg.obj); break; - case TOAST_DOWNLOAD: - Toast.makeText(SkiaSampleActivity.this, (String) msg.obj, - Toast.LENGTH_SHORT).show(); - break; default: break; } @@ -243,28 +237,6 @@ public class SkiaSampleActivity extends Activity mHandler.obtainMessage(SET_SLIDES, slideList).sendToTarget(); } - // Called by JNI - public void addToDownloads(final String title, final String desc, final String path) { - File file = new File(path); - final long length = file.exists() ? file.length() : 0; - if (length == 0) { - String failed = getString(R.string.save_failed); - mHandler.obtainMessage(TOAST_DOWNLOAD, failed).sendToTarget(); - return; - } - String toast = getString(R.string.file_saved).replace("%s", title); - mHandler.obtainMessage(TOAST_DOWNLOAD, toast).sendToTarget(); - final DownloadManager manager = - (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE); - new Thread("Add PDF to downloads") { - @Override - public void run() { - final String mimeType = "application/pdf"; - manager.addCompletedDownload(title, desc, true, mimeType, path, length, true); - } - }.start(); - } - private boolean setOpenGLContextSettings(boolean requestedOpenGLAPI, int requestedSampleCount) { if (mSampleView != null && mSampleView.getMSAASampleCount() == requestedSampleCount && diff --git a/platform_tools/android/apps/sample_app/src/main/java/com/skia/SkiaSampleView.java b/platform_tools/android/apps/sample_app/src/main/java/com/skia/SkiaSampleView.java index c33f8ae8ac..6213a6f35b 100644 --- a/platform_tools/android/apps/sample_app/src/main/java/com/skia/SkiaSampleView.java +++ b/platform_tools/android/apps/sample_app/src/main/java/com/skia/SkiaSampleView.java @@ -18,6 +18,7 @@ import android.opengl.GLSurfaceView; import android.os.Build; import android.util.Log; import android.view.MotionEvent; +import android.widget.Toast; public class SkiaSampleView extends GLSurfaceView { @@ -177,6 +178,9 @@ public class SkiaSampleView extends GLSurfaceView { mSampleRenderer.saveToPDF(); } }); + + String msg = getContext().getString(R.string.pdf_save_info); + Toast.makeText(getContext(), msg, Toast.LENGTH_SHORT).show(); } public boolean getUsesOpenGLAPI() { diff --git a/platform_tools/android/apps/sample_app/src/main/jni/com_skia_SkiaSampleRenderer.cpp b/platform_tools/android/apps/sample_app/src/main/jni/com_skia_SkiaSampleRenderer.cpp index 15f01a94bf..7da4fa81ca 100644 --- a/platform_tools/android/apps/sample_app/src/main/jni/com_skia_SkiaSampleRenderer.cpp +++ b/platform_tools/android/apps/sample_app/src/main/jni/com_skia_SkiaSampleRenderer.cpp @@ -27,13 +27,11 @@ struct ActivityGlue { jweak m_obj; jmethodID m_setTitle; jmethodID m_setSlideList; - jmethodID m_addToDownloads; ActivityGlue() { m_env = nullptr; m_obj = nullptr; m_setTitle = nullptr; m_setSlideList = nullptr; - m_addToDownloads = nullptr; } } gActivityGlue; @@ -122,30 +120,6 @@ void SkOSWindow::onHandleInval(const SkIRect& rect) env->CallVoidMethod(gWindowGlue.m_obj, gWindowGlue.m_inval); } -void SkOSWindow::onPDFSaved(const char title[], const char desc[], - const char path[]) -{ - JNIEnv* env = gActivityGlue.m_env; - if (!env || !gActivityGlue.m_addToDownloads || !gActivityGlue.m_obj) { - return; - } - if (env->IsSameObject(gActivityGlue.m_obj, nullptr)) { - SkDebugf("ERROR: The JNI WeakRef to the Activity is invalid"); - return; - } - - jstring jtitle = env->NewStringUTF(title); - jstring jdesc = env->NewStringUTF(desc); - jstring jpath = env->NewStringUTF(path); - - env->CallVoidMethod(gActivityGlue.m_obj, gActivityGlue.m_addToDownloads, - jtitle, jdesc, jpath); - - env->DeleteLocalRef(jtitle); - env->DeleteLocalRef(jdesc); - env->DeleteLocalRef(jpath); -} - /////////////////////////////////////////// /////////////// SkEvent impl ////////////// /////////////////////////////////////////// @@ -198,8 +172,6 @@ JNIEXPORT void JNICALL Java_com_skia_SkiaSampleRenderer_init(JNIEnv* env, gActivityGlue.m_obj = env->NewWeakGlobalRef(jsampleActivity); gActivityGlue.m_setTitle = GetJMethod(env, clazz, "setTitle", "(Ljava/lang/CharSequence;)V"); gActivityGlue.m_setSlideList = GetJMethod(env, clazz, "setSlideList", "([Ljava/lang/String;)V"); - gActivityGlue.m_addToDownloads = GetJMethod(env, clazz, "addToDownloads", - "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V"); env->DeleteLocalRef(clazz); // setup jni hooks to the java renderer diff --git a/platform_tools/android/apps/sample_app/src/main/res/values/strings.xml b/platform_tools/android/apps/sample_app/src/main/res/values/strings.xml index b0b4e7b74b..f9ec6a069a 100644 --- a/platform_tools/android/apps/sample_app/src/main/res/values/strings.xml +++ b/platform_tools/android/apps/sample_app/src/main/res/values/strings.xml @@ -8,11 +8,10 @@ Toggle Tiling Toggle SKP BBox Save to PDF - Save Failed - %s saved! + View saved as PDF to directory \"/sdcard\" Set OpenGL Context Type OpenGL ES OpenGL ES, MSAA4 OpenGL OpenGL, MSAA4 - \ No newline at end of file + diff --git a/platform_tools/android/apps/visualbench/src/main/jni/SkOSWindow_AndroidNative.cpp b/platform_tools/android/apps/visualbench/src/main/jni/SkOSWindow_AndroidNative.cpp index df1ca96374..76ace6df46 100644 --- a/platform_tools/android/apps/visualbench/src/main/jni/SkOSWindow_AndroidNative.cpp +++ b/platform_tools/android/apps/visualbench/src/main/jni/SkOSWindow_AndroidNative.cpp @@ -188,9 +188,6 @@ void SkOSWindow::onSetTitle(const char title[]) { void SkOSWindow::onHandleInval(const SkIRect& rect) { } -void SkOSWindow::onPDFSaved(const char title[], const char desc[], const char path[]) { -} - /////////////////////////////////////////// /////////////// SkEvent impl ////////////// ///////////////////////////////////////////