Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(757)

Side by Side Diff: platform_tools/android/apps/sample_app/src/main/java/com/skia/SkiaSampleActivity.java

Issue 1547923002: SampleApp: remove SkWindow::onPDFSaved, it does not work (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rebase Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright 2012 Google Inc. 2 * Copyright 2012 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 package com.skia; 8 package com.skia;
9 9
10 import android.app.ActionBar; 10 import android.app.ActionBar;
11 import android.app.Activity; 11 import android.app.Activity;
12 import android.app.DownloadManager; 12 import android.app.DownloadManager;
13 import android.content.Intent; 13 import android.content.Intent;
14 import android.content.Context; 14 import android.content.Context;
15 import android.os.Build; 15 import android.os.Build;
16 import android.os.Bundle; 16 import android.os.Bundle;
17 import android.os.Handler; 17 import android.os.Handler;
18 import android.os.Message; 18 import android.os.Message;
19 import android.view.KeyEvent; 19 import android.view.KeyEvent;
20 import android.view.Menu; 20 import android.view.Menu;
21 import android.view.MenuItem; 21 import android.view.MenuItem;
22 import android.view.ViewGroup; 22 import android.view.ViewGroup;
23 import android.widget.ArrayAdapter; 23 import android.widget.ArrayAdapter;
24 import android.widget.LinearLayout; 24 import android.widget.LinearLayout;
25 import android.widget.TextView; 25 import android.widget.TextView;
26 import android.widget.Toast;
27 26
28 import java.io.File; 27 import java.io.File;
29 28
30 public class SkiaSampleActivity extends Activity 29 public class SkiaSampleActivity extends Activity
31 { 30 {
32 private TextView mTitle; 31 private TextView mTitle;
33 private SkiaSampleView mSampleView; 32 private SkiaSampleView mSampleView;
34 33
35 private ArrayAdapter<String> mSlideList; 34 private ArrayAdapter<String> mSlideList;
36 35
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 if (event.getAction() == KeyEvent.ACTION_UP) { 201 if (event.getAction() == KeyEvent.ACTION_UP) {
203 finish(); 202 finish();
204 } 203 }
205 return true; 204 return true;
206 } 205 }
207 return false; 206 return false;
208 } 207 }
209 208
210 private static final int SET_TITLE = 1; 209 private static final int SET_TITLE = 1;
211 private static final int SET_SLIDES = 2; 210 private static final int SET_SLIDES = 2;
212 private static final int TOAST_DOWNLOAD = 3;
213 211
214 private Handler mHandler = new Handler() { 212 private Handler mHandler = new Handler() {
215 @Override 213 @Override
216 public void handleMessage(Message msg) { 214 public void handleMessage(Message msg) {
217 switch (msg.what) { 215 switch (msg.what) {
218 case SET_TITLE: 216 case SET_TITLE:
219 mTitle.setText((String) msg.obj); 217 mTitle.setText((String) msg.obj);
220 SkiaSampleActivity.this.getActionBar().setSubtitle((String) msg. obj); 218 SkiaSampleActivity.this.getActionBar().setSubtitle((String) msg. obj);
221 break; 219 break;
222 case SET_SLIDES: 220 case SET_SLIDES:
223 mSlideList.addAll((String[]) msg.obj); 221 mSlideList.addAll((String[]) msg.obj);
224 break; 222 break;
225 case TOAST_DOWNLOAD:
226 Toast.makeText(SkiaSampleActivity.this, (String) msg.obj,
227 Toast.LENGTH_SHORT).show();
228 break;
229 default: 223 default:
230 break; 224 break;
231 } 225 }
232 } 226 }
233 }; 227 };
234 228
235 // Called by JNI 229 // Called by JNI
236 @Override 230 @Override
237 public void setTitle(CharSequence title) { 231 public void setTitle(CharSequence title) {
238 mHandler.obtainMessage(SET_TITLE, title).sendToTarget(); 232 mHandler.obtainMessage(SET_TITLE, title).sendToTarget();
239 } 233 }
240 234
241 // Called by JNI 235 // Called by JNI
242 public void setSlideList(String[] slideList) { 236 public void setSlideList(String[] slideList) {
243 mHandler.obtainMessage(SET_SLIDES, slideList).sendToTarget(); 237 mHandler.obtainMessage(SET_SLIDES, slideList).sendToTarget();
244 } 238 }
245 239
246 // Called by JNI
247 public void addToDownloads(final String title, final String desc, final Stri ng path) {
248 File file = new File(path);
249 final long length = file.exists() ? file.length() : 0;
250 if (length == 0) {
251 String failed = getString(R.string.save_failed);
252 mHandler.obtainMessage(TOAST_DOWNLOAD, failed).sendToTarget();
253 return;
254 }
255 String toast = getString(R.string.file_saved).replace("%s", title);
256 mHandler.obtainMessage(TOAST_DOWNLOAD, toast).sendToTarget();
257 final DownloadManager manager =
258 (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
259 new Thread("Add PDF to downloads") {
260 @Override
261 public void run() {
262 final String mimeType = "application/pdf";
263 manager.addCompletedDownload(title, desc, true, mimeType, path, length, true);
264 }
265 }.start();
266 }
267
268 private boolean setOpenGLContextSettings(boolean requestedOpenGLAPI, int req uestedSampleCount) { 240 private boolean setOpenGLContextSettings(boolean requestedOpenGLAPI, int req uestedSampleCount) {
269 if (mSampleView != null && 241 if (mSampleView != null &&
270 mSampleView.getMSAASampleCount() == requestedSampleCount && 242 mSampleView.getMSAASampleCount() == requestedSampleCount &&
271 mSampleView.getUsesOpenGLAPI() == requestedOpenGLAPI) { 243 mSampleView.getUsesOpenGLAPI() == requestedOpenGLAPI) {
272 return true; 244 return true;
273 } 245 }
274 246
275 createSampleView(requestedOpenGLAPI, requestedSampleCount); 247 createSampleView(requestedOpenGLAPI, requestedSampleCount);
276 248
277 return true; 249 return true;
278 } 250 }
279 } 251 }
OLDNEW
« no previous file with comments | « include/views/SkWindow.h ('k') | platform_tools/android/apps/sample_app/src/main/java/com/skia/SkiaSampleView.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698