|
@@ -13,22 +13,16 @@ import android.content.Context;
|
|
|
import android.graphics.Rect;
|
|
|
import android.net.Uri;
|
|
|
import android.text.TextUtils;
|
|
|
-import android.util.AttributeSet;
|
|
|
-import android.util.Log;
|
|
|
import android.view.View;
|
|
|
import android.view.ViewGroup;
|
|
|
import android.view.ViewTreeObserver;
|
|
|
import android.widget.FrameLayout;
|
|
|
import androidx.annotation.NonNull;
|
|
|
-import androidx.annotation.Nullable;
|
|
|
import androidx.fragment.app.FragmentManager;
|
|
|
-import com.compdfkit.core.document.CPDFDocument;
|
|
|
import com.compdfkit.tools.common.pdf.CPDFDocumentFragment;
|
|
|
import com.compdfkit.tools.common.pdf.config.CPDFConfiguration;
|
|
|
-import com.compdfkit.ui.reader.CPDFReaderView;
|
|
|
import com.compdfkitpdf.reactnative.util.CPDFDocumentUtil;
|
|
|
import com.facebook.react.uimanager.ThemedReactContext;
|
|
|
-import java.util.HashMap;
|
|
|
|
|
|
|
|
|
public class CPDFView extends FrameLayout {
|
|
@@ -71,26 +65,27 @@ public class CPDFView extends FrameLayout {
|
|
|
initDocumentFragment();
|
|
|
}
|
|
|
|
|
|
- public void setPassword(String password){
|
|
|
+ public void setPassword(String password) {
|
|
|
this.password = password;
|
|
|
isPasswordSet = true;
|
|
|
initDocumentFragment();
|
|
|
}
|
|
|
|
|
|
- public void setConfiguration(CPDFConfiguration configuration){
|
|
|
+ public void setConfiguration(CPDFConfiguration configuration) {
|
|
|
this.configuration = configuration;
|
|
|
initDocumentFragment();
|
|
|
}
|
|
|
|
|
|
- private void initDocumentFragment(){
|
|
|
- if (TextUtils.isEmpty(document) || configuration == null || !isPasswordSet){
|
|
|
+ private void initDocumentFragment() {
|
|
|
+ if (TextUtils.isEmpty(document) || configuration == null || !isPasswordSet) {
|
|
|
return;
|
|
|
}
|
|
|
if (documentFragment == null) {
|
|
|
if (document.startsWith(CPDFDocumentUtil.CONTENT_SCHEME) ||
|
|
|
- document.startsWith(CPDFDocumentUtil.FILE_SCHEME)){
|
|
|
- documentFragment = CPDFDocumentFragment.newInstance(Uri.parse(document), password, configuration);
|
|
|
- }else {
|
|
|
+ document.startsWith(CPDFDocumentUtil.FILE_SCHEME)) {
|
|
|
+ documentFragment = CPDFDocumentFragment.newInstance(Uri.parse(document), password,
|
|
|
+ configuration);
|
|
|
+ } else {
|
|
|
documentFragment = CPDFDocumentFragment.newInstance(document, password, configuration);
|
|
|
}
|
|
|
prepareFragment(documentFragment, true);
|
|
@@ -122,26 +117,24 @@ public class CPDFView extends FrameLayout {
|
|
|
|
|
|
private boolean mShouldHandleKeyboard = false;
|
|
|
|
|
|
- private final ViewTreeObserver.OnGlobalLayoutListener mOnGlobalLayoutListener = new ViewTreeObserver.OnGlobalLayoutListener() {
|
|
|
- @Override
|
|
|
- public void onGlobalLayout() {
|
|
|
- Rect r = new Rect();
|
|
|
- getWindowVisibleDisplayFrame(r);
|
|
|
- int screenHeight = getRootView().getHeight();
|
|
|
+ private final ViewTreeObserver.OnGlobalLayoutListener mOnGlobalLayoutListener = () -> {
|
|
|
+ Rect r = new Rect();
|
|
|
+ getWindowVisibleDisplayFrame(r);
|
|
|
+ int screenHeight = getRootView().getHeight();
|
|
|
|
|
|
- // r.bottom is the position above soft keypad or device button.
|
|
|
- // if keypad is shown, the r.bottom is smaller than that before.
|
|
|
- int keypadHeight = screenHeight - r.bottom;
|
|
|
+ // r.bottom is the position above soft keypad or device button.
|
|
|
+ // if keypad is shown, the r.bottom is smaller than that before.
|
|
|
+ int keypadHeight = screenHeight - r.bottom;
|
|
|
|
|
|
- if (keypadHeight > screenHeight * 0.15) { // 0.15 ratio is perhaps enough to determine keypad height.
|
|
|
- // keyboard is opened
|
|
|
- mShouldHandleKeyboard = true;
|
|
|
- } else {
|
|
|
- // keyboard is closed
|
|
|
- if (mShouldHandleKeyboard) {
|
|
|
- mShouldHandleKeyboard = false;
|
|
|
- requestLayout();
|
|
|
- }
|
|
|
+ if (keypadHeight
|
|
|
+ > screenHeight * 0.15) { // 0.15 ratio is perhaps enough to determine keypad height.
|
|
|
+ // keyboard is opened
|
|
|
+ mShouldHandleKeyboard = true;
|
|
|
+ } else {
|
|
|
+ // keyboard is closed
|
|
|
+ if (mShouldHandleKeyboard) {
|
|
|
+ mShouldHandleKeyboard = false;
|
|
|
+ requestLayout();
|
|
|
}
|
|
|
}
|
|
|
};
|
|
@@ -153,6 +146,7 @@ public class CPDFView extends FrameLayout {
|
|
|
layout(getLeft(), getTop(), getRight(), getBottom());
|
|
|
};
|
|
|
|
|
|
+
|
|
|
@Override
|
|
|
public void requestLayout() {
|
|
|
super.requestLayout();
|