blob: 0561f01b094967d88890e25f78f15512b12b6b61 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
|
package com.artifex.mupdf;
import android.app.Activity;
import android.os.Bundle;
import android.os.Environment;
import android.view.*;
import android.view.View.OnClickListener;
import android.widget.*;
import android.widget.LinearLayout.*;
import java.io.File;
import com.artifex.mupdf.PixmapView;
public class MuPDFActivity extends Activity
{
/* The core rendering instance */
private MuPDFCore core;
private MuPDFCore openFile()
{
String storageState = Environment.getExternalStorageState();
File path, file;
MuPDFCore core;
if (Environment.MEDIA_MOUNTED.equals(storageState))
{
System.out.println("Media mounted read/write");
}
else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(storageState))
{
System.out.println("Media mounted read only");
}
else
{
System.out.println("No media at all! Bale!\n");
return null;
}
path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
file = new File(path, "test.pdf");
System.out.println("Trying to open "+file.toString());
try
{
core = new MuPDFCore(file.toString());
}
catch (Exception e)
{
System.out.println(e);
return null;
}
return core;
}
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
PixmapView pixmapView;
core = (MuPDFCore)getLastNonConfigurationInstance();
if (core == null)
core = openFile();
if (core == null)
{
/* FIXME: Error handling here! */
return;
}
pixmapView = new PixmapView(this, core);
super.onCreate(savedInstanceState);
/* Now create the UI */
RelativeLayout layout;
LinearLayout bar;
MyButtonHandler bh = new MyButtonHandler(pixmapView);
bar = new LinearLayout(this);
bar.setOrientation(LinearLayout.HORIZONTAL);
bh.buttonStart = new Button(this);
bh.buttonStart.setText("<<");
bh.buttonStart.setOnClickListener(bh);
bar.addView(bh.buttonStart);
bh.buttonPrev = new Button(this);
bh.buttonPrev.setText("<");
bh.buttonPrev.setOnClickListener(bh);
bar.addView(bh.buttonPrev);
bh.buttonNext = new Button(this);
bh.buttonNext.setText(">");
bh.buttonNext.setOnClickListener(bh);
bar.addView(bh.buttonNext);
bh.buttonEnd = new Button(this);
bh.buttonEnd.setText(">>");
bh.buttonEnd.setOnClickListener(bh);
bar.addView(bh.buttonEnd);
layout = new RelativeLayout(this);
layout.setLayoutParams(new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.FILL_PARENT,
RelativeLayout.LayoutParams.FILL_PARENT));
layout.setGravity(Gravity.FILL);
RelativeLayout.LayoutParams barParams =
new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.FILL_PARENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
barParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
bar.setId(100);
layout.addView(bar, barParams);
RelativeLayout.LayoutParams pixmapParams =
new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.FILL_PARENT,
RelativeLayout.LayoutParams.FILL_PARENT);
pixmapParams.addRule(RelativeLayout.ABOVE,100);
layout.addView(pixmapView, pixmapParams);
setContentView(layout);
}
public Object onRetainNonConfigurationInstance()
{
return core;
}
private class MyButtonHandler implements OnClickListener
{
Button buttonStart;
Button buttonPrev;
Button buttonNext;
Button buttonEnd;
PixmapView pixmapView;
public MyButtonHandler(PixmapView pixmapView)
{
this.pixmapView = pixmapView;
}
public void onClick(View v)
{
if (v == buttonStart)
pixmapView.changePage(Integer.MIN_VALUE);
else if (v == buttonPrev)
pixmapView.changePage(-1);
else if (v == buttonNext)
pixmapView.changePage(+1);
else if (v == buttonEnd)
pixmapView.changePage(Integer.MAX_VALUE);
}
}
}
|