Skip to content

Commit f2996ca

Browse files
committed
fixes for several very rare bugs dicovered from user feedback
1 parent d19d7f7 commit f2996ca

9 files changed

Lines changed: 52 additions & 18 deletions

File tree

platform/android/AndroidManifest.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
33
package="com.cgogolin.penandpdf"
4-
android:versionCode="62"
5-
android:versionName="1.3.4"
4+
android:versionCode="65"
5+
android:versionName="1.3.5"
66
android:installLocation="auto">
77
<permission android:name="com.cgogolin.penandpdf.LAUNCH_PEN_AND_PDF_FILE_CHOOSER" />
88
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

platform/android/src/com/cgogolin/penandpdf/FileBrowserFragment.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.cgogolin.penandpdf;
22

33
import android.app.AlertDialog;
4+
import android.app.Activity;
45
import android.support.v4.app.Fragment;
56
import android.support.v4.app.ListFragment;
67
import android.support.v7.app.AppCompatActivity;
@@ -332,8 +333,9 @@ void goToDir(File dir) {
332333
}
333334

334335
private void setTitle() {
335-
if(mDirectory != null)
336-
getActivity().setTitle(mDirectory.getPath());
336+
Activity activity = getActivity();
337+
if (mDirectory != null && isAdded() && activity != null)
338+
activity.setTitle(mDirectory.getPath());
337339
}
338340

339341
public void inForground() {

platform/android/src/com/cgogolin/penandpdf/MuPDFCore.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ public String getFileName() {
485485
}
486486

487487

488-
public synchronized void onSharedPreferenceChanged(SharedPreferences sharedPref, String key){
488+
public void onSharedPreferenceChanged(SharedPreferences sharedPref, String key){
489489
//Set ink thickness
490490
float inkThickness = Float.parseFloat(sharedPref.getString(SettingsActivity.PREF_INK_THICKNESS, Float.toString(INK_THICKNESS)));
491491
setInkThickness(inkThickness*0.5f);

platform/android/src/com/cgogolin/penandpdf/MuPDFPageAdapter.java

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,28 @@ public class MuPDFPageAdapter extends BaseAdapter {
1616
private final FilePicker.FilePickerSupport mFilePickerSupport;
1717
private final MuPDFCore mCore;
1818
private final SparseArray<PointF> mPageSizes = new SparseArray<PointF>();
19+
private AsyncTask<MuPDFCore,Void,Void> getPageSizesTask;
1920

2021
public MuPDFPageAdapter(Context c, FilePicker.FilePickerSupport filePickerSupport, MuPDFCore core) {
2122
mContext = c;
2223
mFilePickerSupport = filePickerSupport;
2324
mCore = core;
25+
26+
if(mCore!=null)
27+
{
28+
getPageSizesTask = new AsyncTask<MuPDFCore,Void,Void>(){
29+
@Override
30+
protected Void doInBackground(MuPDFCore... core) {
31+
int numPages = getCount();
32+
for(int position = 0; position < numPages; position++) {
33+
PointF size = core[0].getPageSize(position);
34+
mPageSizes.put(position, size);
35+
}
36+
return null;
37+
}
38+
};
39+
getPageSizesTask.execute(mCore);
40+
}
2441
}
2542

2643
@Override
@@ -57,9 +74,10 @@ public View getView(final int position, View convertView, ViewGroup parent) {
5774
// Page size as yet unknown so find it out
5875
PointF size = mCore.getPageSize(position);
5976
mPageSizes.put(position, size);
60-
pageView.setPage(position, size);
77+
pageView.setPage(position, size);
6178
// Warning: Page size must be known for measuring so
62-
// we can't do this in background!!!
79+
// we can't do this in background, but we try to fetch
80+
// all page sizes in the background when the adapter is created
6381
}
6482
return pageView;
6583
}

platform/android/src/com/cgogolin/penandpdf/NoteBrowserFragment.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.cgogolin.penandpdf;
22

33
import android.app.AlertDialog;
4+
import android.app.Activity;
45
import android.support.v4.app.Fragment;
56
import android.support.v4.app.ListFragment;
67
import android.support.v7.app.AppCompatActivity;
@@ -312,9 +313,12 @@ void goToDir(File dir) {
312313
}
313314

314315
private void setTitle() {
315-
Resources res = getResources();
316-
String appName = res.getString(R.string.app_name);
317-
getActivity().setTitle(appName);
316+
Activity activity = getActivity();
317+
if (isAdded() && activity != null) {
318+
Resources res = getResources();
319+
String appName = res.getString(R.string.app_name);
320+
activity.setTitle(appName);
321+
}
318322
}
319323

320324
public void inForground() {

platform/android/src/com/cgogolin/penandpdf/PageView.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -937,12 +937,14 @@ public void startErase(final float x, final float y) {
937937
}
938938

939939
public void continueErase(final float x, final float y) {
940+
if(eraser==null)
941+
return;//I don't understand under which conditions this is possible but very rarely this function gets called while eraser==null
942+
940943
final float scale = mSourceScale*(float)getWidth()/(float)mSize.x;
941944
final float docRelX = (x - getLeft())/scale;
942945
final float docRelY = (y - getTop())/scale;
943-
944-
if(eraser!=null)
945-
eraser.set(docRelX,docRelY);
946+
947+
eraser.set(docRelX,docRelY);
946948

947949
ArrayList<ArrayList<PointF>> newArcs = new ArrayList<ArrayList<PointF>>();
948950
if (mDrawing != null && mDrawing.size() > 0) {
@@ -954,7 +956,8 @@ public void continueErase(final float x, final float y) {
954956
boolean newArcHasBeenCreated = false;
955957
if(iter.hasNext()) lastPoint = iter.next();
956958
//Remove the first point if under eraser
957-
if(lastPoint!=null && eraser!=null && PointFMath.distance(lastPoint,eraser) <= eraserThickness) iter.remove();
959+
if(lastPoint!=null && PointFMath.distance(lastPoint,eraser) <= eraserThickness)
960+
iter.remove();
958961
while (iter.hasNext())
959962
{
960963
PointF point = iter.next();

platform/android/src/com/cgogolin/penandpdf/PenAndPDFActivity.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2387,6 +2387,8 @@ private void hideKeyboard()
23872387

23882388

23892389
private void enterFullscreen() {
2390+
if(mDocView==null)
2391+
return;
23902392
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
23912393
getSupportActionBar().hide();
23922394
mActionBarMode = ActionBarMode.Hidden;
@@ -2397,6 +2399,8 @@ private void enterFullscreen() {
23972399
}
23982400

23992401
private void exitFullScreen() {
2402+
if(mDocView==null)
2403+
return;
24002404
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
24012405
getSupportActionBar().show();
24022406
if(mActionBarMode == ActionBarMode.Hidden)

platform/android/src/com/cgogolin/penandpdf/PenAndPDFCore.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ public synchronized <T extends Context & TemporaryUriPermission.TemporaryUriPerm
325325
catch(Exception e)
326326
{
327327
// Log.i(context.getString(R.string.app_name), "exception while opening pfd or os via pfd: "+e);
328-
if(e.getMessage().contains("Unsupported mode: wa"))
328+
if(e.getMessage()!=null && e.getMessage().contains("Unsupported mode: wa"))
329329
{
330330
// Log.i(context.getString(R.string.app_name), "assuming that the only problem was the mode 'wa' and setting canWrite = true");
331331
canWrite = true; //We assume that writing with "w" would work to make google dirve work!

platform/android/src/com/cgogolin/penandpdf/RecentFilesFragment.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,9 +215,12 @@ private void loadRecentFilesList() {
215215
}
216216

217217
private void setTitle() {
218-
Resources res = getResources();
219-
String appName = res.getString(R.string.app_name);
220-
getActivity().setTitle(appName);
218+
Activity activity = getActivity();
219+
if (isAdded() && activity != null) {
220+
Resources res = getResources();
221+
String appName = res.getString(R.string.app_name);
222+
activity.setTitle(appName);
223+
}
221224
}
222225

223226
public void inForground() {

0 commit comments

Comments
 (0)