MuPDF Android版:选片段,而不是活动
在我现有的Android应用程序,使用MuPDF IM,我移植用的这个文档。 现在,当我想打开里面活动的PDF文件,我使用: 开放的我们的uri = Uri.parse(路径);
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);
Intent intent = new Intent(this, MuPDFActivity.class);
intent.setAction(Intent.ACTION_VIEW);
intent.setData(uri);
startActivity(intent);
这触发一个新的活动,我的问题是:(1)我如何开始片段来查看PDF文件? (2)是否MuPDF支持片段,我可以在我的醋栗Android的选项卡,查看通话? (3)有没有办法把它转换成活性片段?
which fires a new activity, My problem is: (1) how can I start Fragment to view pdf? (2) Does MuPDF supports Fragment that I can call under my currant Android-Tab-View? (3) Is there a Way Converting this activity into fragment?
目前我在做什么:
public class DummySectionFragment extends Fragment {
public DummySectionFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = null;
rootView = inflater.inflate(R.layout.activity_dummy_section_fragment, container, false);
Intent myIntent = new Intent(getActivity(), MuPDFActivity.class);
myIntent.setAction(Intent.ACTION_VIEW);
myIntent.setData(uri);
getActivity().startActivity(myIntent);
return rootView;
}
}
其中:开场就我目前的标签视图布局,这看起来并不大的新的活动,因为它涵盖了整个标签布局,用户必须点击返回
键查看选项卡视图。
Which: opens a new activity on my current Tab View layout, which does not look great as it covers entire tab layout and user have to click BACK
button to view tab view.
也许你不应该使用MuPDFActivity在您的项目 - 这只是一个例子Mupdf是如何工作的。所有你需要的是在MuPDFReaderView / MuPDFCore / MuPDFPageAdapter。 MuPDFReaderView从View / ViewGroup中延伸,所以你可以把它添加到您的布局。尝试像这样(没有经过测试的!!):
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 - >的片段(mupdf_wrapper.xml)基本布局:
1.) XML --> The base layout for the fragment (mupdf_wrapper.xml):
<RelativeLayout
android:id="@+id/mupdf_wrapper"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</RelativeLayout>
2)JAVA:
2.) JAVA:
public class DummySectionFragment extends Fragment {
public DummySectionFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = null;
rootView = inflater.inflate(R.layout.mupdf_wrapper, container, false);
RelativeLayout mupdfWrapper (RelativeLayout)rootView.findViewById(R.id.mupdf_wrapper);
String path = "path/To/Your/PDF/File.pdf";
MuPDFCore core = new MuPDFCore(getActivity(), path);
MuPDFReaderView mDocView = new MuPDFReaderView(getActivity());
mDocView.setAdapter(new MuPDFPageAdapter(getActivity(), getActivity(), core));
mupdfWrapper .addView(mDocView, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
return rootView;
}
}