-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDocumentViewerNativeView.cs
More file actions
115 lines (101 loc) · 3.78 KB
/
Copy pathDocumentViewerNativeView.cs
File metadata and controls
115 lines (101 loc) · 3.78 KB
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
using Android.Content;
using Android.Views;
using Android.Widget;
using AndroidX.CoordinatorLayout.Widget;
using AndroidX.Fragment.App;
using pdftron.PDF.Config;
using DocumentViewer.Controls;
using Color = Android.Graphics.Color;
using Uri = Android.Net.Uri;
using pdftron.PDF.Controls;
namespace DocumentViewer.Platforms.Android
{
public class DocumentViewerNativeView : CoordinatorLayout
{
DocumentView2 _documentView;
Context _context;
DocumentViewerControl _documentViewerControl;
public DocumentViewerNativeView(Context context, DocumentViewerControl documentViewerControl) : base(context)
{
_context = context;
_documentViewerControl = documentViewerControl;
SetBackgroundColor(Color.Black);
// Create a RelativeLayout for sizing the document viewer
RelativeLayout relativeLayout = new RelativeLayout(_context)
{
LayoutParameters = new CoordinatorLayout.LayoutParams(LayoutParams.MatchParent, LayoutParams.MatchParent)
{
Gravity = (int)GravityFlags.Center
}
};
// Create DocumentView and position it in the RelativeLayout
_documentView = new DocumentView2(context)
{
LayoutParameters = new RelativeLayout.LayoutParams(LayoutParams.MatchParent, LayoutParams.MatchParent)
};
// Add to the layouts
relativeLayout.AddView(_documentView);
AddView(relativeLayout);
}
public void UpdateUri()
{
if (!string.IsNullOrEmpty(_documentViewerControl.Uri))
{
_documentView.SetDocumentUri(Uri.Parse(_documentViewerControl.Uri));
}
}
public void UpdatePassword()
{
if (!string.IsNullOrEmpty(_documentViewerControl.Password))
{
_documentView.SetPassword(_documentViewerControl.Password);
}
}
public void OpenDocument()
{
if (string.IsNullOrEmpty(_documentViewerControl.Uri))
{
return;
}
_documentView.SetViewerConfig(GetConfig());
if (Context != null)
_documentView.SetSupportFragmentManager(GetManager(Context));
FragmentManager? GetManager(Context context)
{
FragmentManager? childManager = null;
if (context is FragmentActivity)
{
var activity = context as FragmentActivity;
var manager = activity?.SupportFragmentManager;
var fragments = manager?.Fragments;
if (fragments?.Count > 0)
childManager = fragments[0].ChildFragmentManager;
if (childManager != null)
return childManager;
}
return childManager;
}
ViewerConfig? GetConfig()
{
var toolmanagerBuilder = ToolManagerBuilder.From()?.SetAutoSelect(true);
var builder = new ViewerConfig.Builder();
var config = builder
?.MultiTabEnabled(true)
?.FullscreenModeEnabled(false)
?.UseSupportActionBar(false)
?.ToolManagerBuilder(toolmanagerBuilder)
?.SaveCopyExportPath(this.Context?.FilesDir?.AbsolutePath)
?.Build();
return config;
}
}
protected override void Dispose(bool disposing)
{
if (disposing)
{
_documentView.Dispose();
}
base.Dispose(disposing);
}
}
}