コード例 #1
0
        protected override void OnElementChanged(ElementChangedEventArgs <Page> e)
        {
            base.OnElementChanged(e);

            if (e.OldElement != null || Element == null)
            {
                return;
            }

            activity = Context as MainActivity;
            view     = activity.LayoutInflater.Inflate(Resource.Layout.ActivityCustomFragment, this, false);

            // Get the Uri provided when launching the activity.
            var documentUri = Utils.ExtractAsset(Context, MainActivity.sampleDoc);

            // Create a new (plain) configuration.
            configuration = new PdfConfiguration.Builder().Build();

            fragment = PdfFragment.NewInstance(documentUri, configuration);
            activity.SupportFragmentManager
            .BeginTransaction()
            .Replace(Resource.Id.fragmentContainer, fragment)
            .Commit();

            InitModularSearchViewAndButton();
            InitOutlineViewAndButton();
            InitThumbnailBar();
            InitThumbnailGridAndButton();

            // Register the activity to be notified when the document is loaded.
            fragment.AddDocumentListener(this);
            fragment.AddDocumentListener(modularSearchView?.JavaCast <IDocumentListener> ());
            fragment.AddDocumentListener(thumbnailBar.DocumentListener);
            fragment.AddDocumentListener(thumbnailGrid);
            fragment.SetOnDocumentLongPressListener(this);

            (this.Element as PdfViewerPage).OnBackPressed = OnBackPressed;

            AddView(view);
        }
コード例 #2
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.ActivityCustomFragment);

            // Get the Uri provided when launching the activity.
            var documentUri = Intent.GetParcelableExtra(ExtraUri)?.JavaCast <Android.Net.Uri> ();

            // Create a new (plain) configuration.
            configuration = new PdfConfiguration.Builder().Build();

            // Extract the existing fragment from the layout. The fragment only exist if it has been created
            // previously (like if the activity is recreated). If no fragment was found, create a new one
            // providing it with the configuration and document Uri.
            fragment = SupportFragmentManager.FindFragmentById(Resource.Id.fragmentContainer)?.JavaCast <PdfFragment> ();
            if (fragment == null)
            {
                fragment = PdfFragment.NewInstance(documentUri, configuration);
                SupportFragmentManager
                .BeginTransaction()
                .Replace(Resource.Id.fragmentContainer, fragment)
                .Commit();
            }

            InitModularSearchViewAndButton();
            InitOutlineViewAndButton();
            InitThumbnailBar();
            InitThumbnailGridAndButton();

            // Register the activity to be notified when the document is loaded.
            fragment.AddDocumentListener(this);
            fragment.AddDocumentListener(modularSearchView?.JavaCast <IDocumentListener> ());
            fragment.AddDocumentListener(thumbnailBar.DocumentListener);
            fragment.AddDocumentListener(thumbnailGrid);
            fragment.SetOnDocumentLongPressListener(this);
        }