Open nubuntu opened 7 years ago
When I had these issues I changed the constants, have a play with these.
@1stmetro how to change the constants??
Constant.blah
Think there listed on main page
@nubuntu Is this issue resolved?
not yet
You may try using pdfView.loadPages()
after .moveTo()
application has stopped after adding pdfView.loadPages() , here my full source ` public class MainActivity extends AppCompatActivity{
private ConstraintLayout content;
private PdfViewer PdfViewer;
private com.example.nubuntu.pdfviewer.tools.PdfViewer pdfView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
content = (ConstraintLayout) findViewById(R.id.content);
pdfView = new PdfViewer(this,R.id.pdfView,R.raw.pdf);
}
}
public class PdfViewer implements OnPageChangeListener, OnLoadCompleteListener, OnPageScrollListener, SensorEventListener {
private final Activity activity;
private SensorManager mSensorManager;
private Sensor mSensor;
private PDFView pdfView;
private float smoothedX;
private float smoothedY;
public PdfViewer(Activity activity, int resource_layout, int resource_raw) {
this.activity = activity;
pdfView = (PDFView)activity.findViewById(resource_layout);
pdfView.setLayerType(View.LAYER_TYPE_HARDWARE,null);
pdfView.setDrawingCacheEnabled(true);
pdfView.enableRenderDuringScale(false);
pdfView.useBestQuality(true);
pdfView.doRenderDuringScale();
InputStream inStream = activity.getResources().openRawResource(resource_raw);
pdfView.fromStream(inStream)
.defaultPage(0)
.onPageChange(this)
.enableDoubletap(false)
.enableAnnotationRendering(true)
.onLoad(this)
.onPageScroll(this)
.scrollHandle(new DefaultScrollHandle(activity))
.load();
this.init_sensor();
}
private void init_sensor() {
mSensorManager = (SensorManager) this.activity.getSystemService(SENSOR_SERVICE);
mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE);
mSensorManager.registerListener(this, mSensor, SensorManager.SENSOR_DELAY_GAME);
}
@Override
public void onPageChanged(int page, int pageCount) {
}
@Override
public void loadComplete(int nbPages) {
pdfView.zoomTo(3);
}
@Override
public void onPageScrolled(int page, float positionOffset) {
pdfView.invalidate();
Log.d("onPageScroll", String.valueOf(page));
Log.d("onPageScrollOffset", String.valueOf(positionOffset));
}
@Override
public void onSensorChanged(SensorEvent event) {
float valuey = event.values[0];
float valuex = event.values[1];
valuey = valuey * 50;
valuex = valuex * 50;
smoothedX = smooth(valuex, smoothedX);
valuex = smoothedX;
smoothedY = smooth(valuey, smoothedY);
valuey = smoothedY;
float baseX = pdfView.getCurrentXOffset();
float baseY = pdfView.getCurrentYOffset();
if(abs(valuex)>3 || abs(valuey)>3){
baseY += valuey;
baseX -= valuex;
pdfView.moveTo(baseX, baseY);
pdfView.loadPages();
}
}
@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
}
static float smooth(float input, float output) {
float ALPHA = 0.2f;
return (int) (output + ALPHA * (input - output));
}
int getDeviceHeight() {
WindowManager wm = (WindowManager) activity.getSystemService(WINDOW_SERVICE);
Display display = wm.getDefaultDisplay();
Point size = new Point();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
display.getSize(size);
} else {
display.getHeight();
}
return size.y;
}
} `
Application has stopped because of some reason, show logs
here's log cat error message
06-06 20:12:28.050 19220-19311/com.example.nubuntu.pdfviewer E/AndroidRuntime: FATAL EXCEPTION: PDF renderer Process: com.example.nubuntu.pdfviewer, PID: 19220 java.lang.OutOfMemoryError: Failed to allocate a 262156 byte allocation with 16208 free bytes and 15KB until OOM at dalvik.system.VMRuntime.newNonMovableArray(Native Method) at android.graphics.Bitmap.nativeCreate(Native Method) at android.graphics.Bitmap.createBitmap(Bitmap.java:831) at android.graphics.Bitmap.createBitmap(Bitmap.java:808) at android.graphics.Bitmap.createBitmap(Bitmap.java:775) at com.github.barteksc.pdfviewer.RenderingHandler.proceed(RenderingHandler.java:96) at com.github.barteksc.pdfviewer.RenderingHandler.handleMessage(RenderingHandler.java:71) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:148) at android.os.HandlerThread.run(HandlerThread.java:61)
when I run moveTo in loadComplete, it rendered correctly
public void loadComplete(int nbPages) { pdfView.zoomTo(3); pdfView.moveTo(-2000,-50); }
but when I do onSensorChanged, it won't rendered ` public void onSensorChanged(SensorEvent event) { float valuey = event.values[0]; float valuex = event.values[1]; valuey = valuey 50; valuex = valuex 50;
smoothedX = smooth(valuex, smoothedX);
valuex = smoothedX;
smoothedY = smooth(valuey, smoothedY);
valuey = smoothedY;
float baseX = pdfView.getCurrentXOffset();
float baseY = pdfView.getCurrentYOffset();
if(abs(valuex)>3 || abs(valuey)>3){
baseY += valuey;
baseX -= valuex;
pdfView.moveTo(baseX, baseY);
}
}
`
I have this problem too. Have you found any solution for this? Library version: 3.0.0-beta.5 Please, give me an answer.
Run in debug mode and check your grids. You'll probably find that you don't have grids covering everything. When this happens the places without a grid will display the "thumbnail" low res version of the page that lives behind the grids.
If you zoom in and then back out you'll see a lot of tiny grids are created but not release. You have a maximum amount of these grids to use so when you run out you just get a blur. I worked around this issue by clearing the cache after it hit its max limit so that it could regenerate the larger grids again.
I just using .loadPages()
method after moveTo
or zoomTo
. And after that all this small grids releases.
I use GYROSCOPE sensor to swipe & scroll pdfview,
bellow my pdfview init ` pdfView = (PDFView)activity.findViewById(resource_layout); pdfView.setLayerType(View.LAYER_TYPE_HARDWARE,null); pdfView.setDrawingCacheEnabled(true); pdfView.enableRenderDuringScale(false); pdfView.useBestQuality(true);
`
on loadcomplete I set zoom to 3
@Override public void loadComplete(int nbPages) { pdfView.zoomTo(3); }
when pdfview zoom to 3, it works well,
but when I scroll with sensor ` @Override public void onSensorChanged(SensorEvent event) { float valuey = event.values[0]; float valuex = event.values[1]; valuey = valuey 50; valuex = valuex 50;
pdf move to point x & y correctly , but display is blur
please help...