Merge pull request #2 from TouchInstinct/bug_fix

fix the bug SECRETCHAT-821
This commit is contained in:
Alex Urzhumtcev 2016-10-18 23:45:22 +03:00 committed by GitHub
commit d59c27eb13
6 changed files with 114 additions and 55 deletions

View File

@ -97,6 +97,7 @@ public class PdfViewerFragment extends Fragment {
mPage = STARTPAGE;
final Toolbar toolbar = (Toolbar) LayoutInflater.from(getActivity()).inflate(R.layout.pfd_toolbar, null);
toolbar.setContentInsetsAbsolute(0, 0);
toolbar.findViewById(R.id.pdf_toolbar_close_image).setOnClickListener(new OnClickListener() {
@Override
public void onClick(final View v) {
@ -363,60 +364,66 @@ public class PdfViewerFragment extends Fragment {
}
// TODO: refactor
private void showPage(int page) {
private void showPage(final int page) {
try {
// free memory from previous page
mGraphView.setPageBitmap(null);
mGraphView.updateImage();
// on some Android getWidth() and getHeight() returns 0, so we need to wait until UI is ready
mGraphView.post(new Runnable() {
@Override
public void run() {
// free memory from previous page
mGraphView.setPageBitmap(null);
mGraphView.updateImage();
// Only load the page if it's a different page (i.e. not just changing the zoom level)
if (mPdfPage == null || mPdfPage.getPageNumber() != page) {
mPdfPage = mPdfFile.getPage(page, true);
}
final int scale = 3;
float width = mPdfPage.getWidth() * scale;
float height = mPdfPage.getHeight() * scale;
int maxWidthToPopulate = mGraphView.getWidth();
int maxHeightToPopulate = mGraphView.getHeight();
int calculatedWidth;
int calculatedHeight;
final float widthRatio = width / maxWidthToPopulate;
final float heightRatio = height / maxHeightToPopulate;
if (width < maxWidthToPopulate && height < maxHeightToPopulate) {
if (widthRatio > heightRatio) {
calculatedWidth = (int) (width / widthRatio);
calculatedHeight = (int) (height / widthRatio);
} else {
calculatedWidth = (int) (width / heightRatio);
calculatedHeight = (int) (height / heightRatio);
}
} else {
if (widthRatio > 1 && heightRatio > 1) {
if (widthRatio > heightRatio) {
calculatedHeight = (int) (height / widthRatio);
calculatedWidth = (int) (width / widthRatio);
} else {
calculatedHeight = (int) (height / heightRatio);
calculatedWidth = (int) (width / heightRatio);
// Only load the page if it's a different page (i.e. not just changing the zoom level)
if (mPdfPage == null || mPdfPage.getPageNumber() != page) {
mPdfPage = mPdfFile.getPage(page, true);
}
} else {
if (widthRatio > heightRatio) {
calculatedHeight = (int) (height / widthRatio);
calculatedWidth = (int) (width / widthRatio);
} else {
calculatedHeight = (int) (height / heightRatio);
calculatedWidth = (int) (width / heightRatio);
}
}
}
final Bitmap bitmap = mPdfPage.getImage(calculatedWidth, calculatedHeight, null, true, true);
mGraphView.setPageBitmap(bitmap);
mGraphView.updateImage();
final int scale = 3;
double width = mPdfPage.getWidth() * scale;
double height = mPdfPage.getHeight() * scale;
int maxWidthToPopulate = mGraphView.getWidth();
int maxHeightToPopulate = mGraphView.getHeight();
int calculatedWidth;
int calculatedHeight;
final double widthRatio = width / maxWidthToPopulate;
final double heightRatio = height / maxHeightToPopulate;
if (width < maxWidthToPopulate && height < maxHeightToPopulate) {
if (widthRatio > heightRatio) {
calculatedWidth = (int) (width / widthRatio);
calculatedHeight = (int) (height / widthRatio);
} else {
calculatedWidth = (int) (width / heightRatio);
calculatedHeight = (int) (height / heightRatio);
}
} else {
if (widthRatio > 1 && heightRatio > 1) {
if (widthRatio > heightRatio) {
calculatedHeight = (int) (height / widthRatio);
calculatedWidth = (int) (width / widthRatio);
} else {
calculatedHeight = (int) (height / heightRatio);
calculatedWidth = (int) (width / heightRatio);
}
} else {
if (widthRatio > heightRatio) {
calculatedHeight = (int) (height / widthRatio);
calculatedWidth = (int) (width / widthRatio);
} else {
calculatedHeight = (int) (height / heightRatio);
calculatedWidth = (int) (width / heightRatio);
}
}
}
final Bitmap bitmap = mPdfPage.getImage(calculatedWidth, calculatedHeight, null, true, true);
mGraphView.setPageBitmap(bitmap);
mGraphView.updateImage();
}
});
} catch (Throwable e) {
Log.e(TAG, e.getMessage(), e);
}

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#3f192d47"/>
</shape>

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/global_close_button_shape" android:state_pressed="true"/>
</selector>

View File

@ -0,0 +1,44 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="56dp"
android:background="#0c0d0e">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:orientation="horizontal">
<ImageView
android:id="@+id/pdf_toolbar_close_image"
android:layout_width="56dp"
android:layout_height="56dp"
android:layout_marginRight="31dp"
android:background="?android:attr/selectableItemBackgroundBorderless"
android:scaleType="centerInside"
android:src="@drawable/global_close_button_normal"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Preview"
android:textColor="@android:color/white"
android:textSize="20sp"/>
<View
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"/>
<TextView
android:id="@+id/pdf_toolbar_page_numbers_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="21dp"
android:textColor="@android:color/white"
android:textSize="20sp"/>
</LinearLayout>
</android.support.v7.widget.Toolbar>

View File

@ -12,10 +12,12 @@
<ImageView
android:id="@+id/pdf_toolbar_close_image"
android:layout_width="wrap_content"
android:layout_width="56dp"
android:layout_height="56dp"
android:layout_marginRight="38dp"
android:background="?android:attr/selectableItemBackgroundBorderless"
android:layout_marginRight="31dp"
android:background="@drawable/global_light_selector"
android:paddingLeft="7dp"
android:paddingRight="7dp"
android:scaleType="centerInside"
android:src="@drawable/global_close_button_normal"/>

View File

@ -1,7 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<drawable name="white">#FFFFFFFF</drawable>
<drawable name="black">#000000</drawable>
<drawable name="blue">#000000FF</drawable>
<drawable name="violet">#9370DB</drawable>