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
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&);
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);
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;
-import android.widget.Toast;
import java.io.File;
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
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;
}
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 &&
import android.os.Build;
import android.util.Log;
import android.view.MotionEvent;
+import android.widget.Toast;
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() {
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;
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 //////////////
///////////////////////////////////////////
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
<string name="tiling">Toggle Tiling</string>
<string name="bbox">Toggle SKP BBox</string>
<string name="save_to_pdf">Save to PDF</string>
- <string name="save_failed">Save Failed</string>
- <string name="file_saved">%s saved!</string>
+ <string name="pdf_save_info">View saved as PDF to directory \"/sdcard\"</string>
<string name="glcontext_menu">Set OpenGL Context Type</string>
<string name="glcontext_opengles">OpenGL ES</string>
<string name="glcontext_msaa4_opengles">OpenGL ES, MSAA4</string>
<string name="glcontext_opengl">OpenGL</string>
<string name="glcontext_msaa4_opengl">OpenGL, MSAA4</string>
-</resources>
\ No newline at end of file
+</resources>
void SkOSWindow::onHandleInval(const SkIRect& rect) {
}
-void SkOSWindow::onPDFSaved(const char title[], const char desc[], const char path[]) {
-}
-
///////////////////////////////////////////
/////////////// SkEvent impl //////////////
///////////////////////////////////////////