Update sample prebults for 2017-02 release (nyc-mr1-dev)
developers/samples/android commit: 6f3586bc08b96d14d8f1315f4839ac59aa39798c Change-Id: I08c9af2d58f1b3314eba807048dc05175a58e164
This commit is contained in:
@@ -30,7 +30,10 @@ import android.widget.Button;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
/**
|
||||
* This fragment has a big {@ImageView} that shows PDF pages, and 2 {@link android.widget.Button}s to move between
|
||||
@@ -43,6 +46,11 @@ public class PdfRendererBasicFragment extends Fragment implements View.OnClickLi
|
||||
*/
|
||||
private static final String STATE_CURRENT_PAGE_INDEX = "current_page_index";
|
||||
|
||||
/**
|
||||
* The filename of the PDF.
|
||||
*/
|
||||
private static final String FILENAME = "sample.pdf";
|
||||
|
||||
/**
|
||||
* File descriptor of the PDF.
|
||||
*/
|
||||
@@ -136,7 +144,21 @@ public class PdfRendererBasicFragment extends Fragment implements View.OnClickLi
|
||||
*/
|
||||
private void openRenderer(Context context) throws IOException {
|
||||
// In this sample, we read a PDF from the assets directory.
|
||||
mFileDescriptor = context.getAssets().openFd("sample.pdf").getParcelFileDescriptor();
|
||||
File file = new File(context.getCacheDir(), FILENAME);
|
||||
if (!file.exists()) {
|
||||
// Since PdfRenderer cannot handle the compressed asset file directly, we copy it into
|
||||
// the cache directory.
|
||||
InputStream asset = context.getAssets().open(FILENAME);
|
||||
FileOutputStream output = new FileOutputStream(file);
|
||||
final byte[] buffer = new byte[1024];
|
||||
int size;
|
||||
while ((size = asset.read(buffer)) != -1) {
|
||||
output.write(buffer, 0, size);
|
||||
}
|
||||
asset.close();
|
||||
output.close();
|
||||
}
|
||||
mFileDescriptor = ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_ONLY);
|
||||
// This is the PdfRenderer we use to render the PDF.
|
||||
mPdfRenderer = new PdfRenderer(mFileDescriptor);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user