Skip to content Skip to sidebar Skip to footer

Mupdf For Android: Option For Fragment Instead Activity

In my existing android app, Im using MuPDF, which i ported with help of this doc. Now when i want to open pdf files inside activity i use : Uri uri = Uri.parse(path); I

Solution 1:

Maybe you shouldn't use the MuPDFActivity in your project - it's just an example how Mupdf works. All what you need is the MuPDFReaderView/MuPDFCore/MuPDFPageAdapter. MuPDFReaderView extends from View/ViewGroup, so you can just add it to your layout. Try it like this (totally untested!!):

1.) XML --> The base layout for the fragment (mupdf_wrapper.xml):

<RelativeLayoutandroid:id="@+id/mupdf_wrapper"android:layout_width="match_parent"android:layout_height="wrap_content"></RelativeLayout>

2.) JAVA:

publicclassDummySectionFragmentextendsFragment {

    publicDummySectionFragment() {
    }

    @Overridepublic View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

        ViewrootView=null;

        rootView = inflater.inflate(R.layout.mupdf_wrapper, container, false);
        RelativeLayout mupdfWrapper(RelativeLayout)rootView.findViewById(R.id.mupdf_wrapper);
        Stringpath="path/To/Your/PDF/File.pdf";
        MuPDFCorecore=newMuPDFCore(getActivity(), path);
        MuPDFReaderViewmDocView=newMuPDFReaderView(getActivity());
        mDocView.setAdapter(newMuPDFPageAdapter(getActivity(), getActivity(), core));
        mupdfWrapper .addView(mDocView, newLayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
        return rootView;
    }

}

Solution 2:

Converting activity to fragment :

publicclassa extend activity{

     publicvoidoncreate(Bundle Saveinstance)
     {
     super.oncreate(saveinstance);
     setcontentview(r.layout.xyz);
     }    
    }

Converting ... :

publicclassa extend fragment{


 publicvoidonstart()
 {
 super.onstart();

 }   

@OverridepublicViewonCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    // TODO Auto-generated method stubreturn inflater.inflate(com.example.login.R.layout.fragment, container, false);

} 
}

If you have a function or you wanna make a Toast , and you have xyz.this replace him with getActivity()

Toast.makeText(xyz.this, e.getMessage(),Toast.LENGTH_LONG).show(); 
Toast.makeText(getActivity(), e.getMessage(),Toast.LENGTH_LONG).show();

Post a Comment for "Mupdf For Android: Option For Fragment Instead Activity"