diff options
Diffstat (limited to 'android')
-rw-r--r-- | android/res/layout/buttons.xml | 18 | ||||
-rw-r--r-- | android/src/com/artifex/mupdfdemo/MuPDFActivity.java | 307 |
2 files changed, 141 insertions, 184 deletions
diff --git a/android/res/layout/buttons.xml b/android/res/layout/buttons.xml index 4a3bdeb2..7dea3bb1 100644 --- a/android/res/layout/buttons.xml +++ b/android/res/layout/buttons.xml @@ -89,13 +89,14 @@ android:background="@color/toolbar" > <ImageButton - android:id="@+id/cancel" + android:id="@+id/cancelSearch" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerVertical="true" android:layout_alignParentLeft="true" android:contentDescription="@string/cancel" android:background="@drawable/button" + android:onClick="OnCancelSearchButtonClick" android:src="@drawable/ic_cancel" /> <EditText @@ -104,7 +105,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerVertical="true" - android:layout_toRightOf="@+id/cancel" + android:layout_toRightOf="@+id/cancelSearch" android:layout_toLeftOf="@+id/searchBack" android:inputType="text" android:hint="@string/search" @@ -146,6 +147,7 @@ android:layout_alignParentLeft="true" android:contentDescription="@string/cancel" android:background="@drawable/button" + android:onClick="OnCancelSelectButtonClick" android:src="@drawable/ic_cancel" /> <ImageButton @@ -156,6 +158,7 @@ android:layout_toLeftOf="@+id/underlineButton" android:contentDescription="@string/highlight" android:background="@drawable/button" + android:onClick="OnHighlightButtonClick" android:src="@drawable/ic_highlight" /> <ImageButton @@ -166,6 +169,7 @@ android:layout_toLeftOf="@+id/strikeOutButton" android:contentDescription="@string/underline" android:background="@drawable/button" + android:onClick="OnUnderlineButtonClick" android:src="@drawable/ic_underline" /> <ImageButton @@ -176,6 +180,7 @@ android:layout_toLeftOf="@+id/copySelectButton" android:contentDescription="@string/strike_out" android:background="@drawable/button" + android:onClick="OnStrikeOutButtonClick" android:src="@drawable/ic_strike" /> <ImageButton @@ -186,6 +191,7 @@ android:layout_alignParentRight="true" android:contentDescription="@string/copy" android:background="@drawable/button" + android:onClick="OnCopySelectButtonClick" android:src="@drawable/ic_clipboard" /> </RelativeLayout> @@ -204,6 +210,7 @@ android:layout_alignParentLeft="true" android:contentDescription="@string/cancel" android:background="@drawable/button" + android:onClick="OnCancelDeleteButtonClick" android:src="@drawable/ic_cancel" /> <ImageButton @@ -214,6 +221,7 @@ android:layout_alignParentRight="true" android:contentDescription="@string/delete" android:background="@drawable/button" + android:onClick="OnDeleteButtonClick" android:src="@drawable/ic_trash" /> </RelativeLayout> @@ -232,6 +240,7 @@ android:layout_alignParentLeft="true" android:contentDescription="@string/cancel" android:background="@drawable/button" + android:onClick="OnCancelAnnotButtonClick" android:src="@drawable/ic_cancel" /> <ImageButton @@ -242,6 +251,7 @@ android:layout_toLeftOf="@+id/selectButton" android:contentDescription="@string/print" android:background="@drawable/button" + android:onClick="OnPrintButtonClick" android:src="@drawable/ic_print" /> <ImageButton @@ -252,6 +262,7 @@ android:layout_toLeftOf="@+id/inkButton" android:contentDescription="@string/select" android:background="@drawable/button" + android:onClick="OnSelectButtonClick" android:src="@drawable/ic_select" /> <ImageButton @@ -262,6 +273,7 @@ android:layout_alignParentRight="true" android:contentDescription="@string/ink" android:background="@drawable/button" + android:onClick="OnInkButtonClick" android:src="@drawable/ic_pen" /> </RelativeLayout> @@ -279,6 +291,7 @@ android:layout_alignParentLeft="true" android:contentDescription="@string/cancel" android:background="@drawable/button" + android:onClick="OnCancelInkButtonClick" android:src="@drawable/ic_cancel" /> <Button @@ -287,6 +300,7 @@ android:layout_height="wrap_content" android:layout_centerVertical="true" android:layout_alignParentRight="true" + android:onClick="OnSaveInkButtonClick" android:text="@string/save" /> </RelativeLayout> </ViewAnimator> diff --git a/android/src/com/artifex/mupdfdemo/MuPDFActivity.java b/android/src/com/artifex/mupdfdemo/MuPDFActivity.java index ce05f470..4cd3d8a4 100644 --- a/android/src/com/artifex/mupdfdemo/MuPDFActivity.java +++ b/android/src/com/artifex/mupdfdemo/MuPDFActivity.java @@ -60,22 +60,8 @@ public class MuPDFActivity extends Activity private TextView mInfoView; private ImageButton mSearchButton; private ImageButton mReflowButton; - private ImageButton mSelectButton; - private ImageButton mCancelSelectButton; - private ImageButton mCopySelectButton; - private ImageButton mHighlightButton; - private ImageButton mUnderlineButton; - private ImageButton mStrikeOutButton; - private ImageButton mCancelButton; private ImageButton mOutlineButton; - private ImageButton mDeleteButton; - private ImageButton mCancelDeleteButton; private ImageButton mAnnotButton; - private ImageButton mCancelAnnotButton; - private ImageButton mInkButton; - private Button mSaveInkButton; - private ImageButton mCancelInkButton; - private ImageButton mPrintButton; private ViewAnimator mTopBarSwitcher; private ImageButton mLinkButton; private TopBarMode mTopBarMode; @@ -491,150 +477,6 @@ public class MuPDFActivity extends Activity mAnnotButton.setVisibility(View.GONE); } - // Activate the select button - mSelectButton.setOnClickListener(new View.OnClickListener() { - public void onClick(View v) { - mDocView.setMode(MuPDFReaderView.Mode.Selecting); - mTopBarMode = TopBarMode.Text; - mTopBarSwitcher.setDisplayedChild(mTopBarMode.ordinal()); - showInfo("Select text"); - } - }); - - mCancelSelectButton.setOnClickListener(new View.OnClickListener() { - public void onClick(View v) { - MuPDFView pageView = (MuPDFView) mDocView.getDisplayedView(); - if (pageView != null) - pageView.deselectText(); - mDocView.setMode(MuPDFReaderView.Mode.Viewing); - mTopBarMode = TopBarMode.AnnotCreate; - mTopBarSwitcher.setDisplayedChild(mTopBarMode.ordinal()); - } - }); - - mInkButton.setOnClickListener(new View.OnClickListener() { - public void onClick(View v) { - mDocView.setMode(MuPDFReaderView.Mode.Drawing); - mTopBarMode = TopBarMode.InkCreate; - mTopBarSwitcher.setDisplayedChild(mTopBarMode.ordinal()); - showInfo("Draw annotation"); - } - }); - - mCancelInkButton.setOnClickListener(new View.OnClickListener() { - public void onClick(View v) { - MuPDFView pageView = (MuPDFView) mDocView.getDisplayedView(); - if (pageView != null) - pageView.cancelDraw(); - mDocView.setMode(MuPDFReaderView.Mode.Viewing); - mTopBarMode = TopBarMode.AnnotCreate; - mTopBarSwitcher.setDisplayedChild(mTopBarMode.ordinal()); - } - }); - - mPrintButton.setOnClickListener(new View.OnClickListener() { - public void onClick(View v) { - printDoc(); - } - }); - - mSaveInkButton.setOnClickListener(new View.OnClickListener() { - public void onClick(View v) { - MuPDFView pageView = (MuPDFView) mDocView.getDisplayedView(); - boolean success = false; - if (pageView != null) - success = pageView.saveDraw(); - mDocView.setMode(MuPDFReaderView.Mode.Viewing); - mTopBarMode = TopBarMode.Main; - mTopBarSwitcher.setDisplayedChild(mTopBarMode.ordinal()); - if (!success) - showInfo("Nothing to save"); - } - }); - - mCancelDeleteButton.setOnClickListener(new View.OnClickListener() { - public void onClick(View v) { - MuPDFView pageView = (MuPDFView) mDocView.getDisplayedView(); - if (pageView != null) - pageView.deselectAnnotation(); - mDocView.setMode(MuPDFReaderView.Mode.Viewing); - mTopBarMode = TopBarMode.Main; - mTopBarSwitcher.setDisplayedChild(mTopBarMode.ordinal()); - } - }); - - mCancelAnnotButton.setOnClickListener(new View.OnClickListener() { - public void onClick(View v) { - MuPDFView pageView = (MuPDFView) mDocView.getDisplayedView(); - if (pageView != null) - pageView.deselectText(); - mDocView.setMode(MuPDFReaderView.Mode.Viewing); - mTopBarMode = TopBarMode.Main; - mTopBarSwitcher.setDisplayedChild(mTopBarMode.ordinal()); - } - }); - - mCopySelectButton.setOnClickListener(new View.OnClickListener() { - public void onClick(View v) { - MuPDFView pageView = (MuPDFView) mDocView.getDisplayedView(); - boolean copied = false; - if (pageView != null) - copied = pageView.copySelection(); - mDocView.setMode(MuPDFReaderView.Mode.Viewing); - mTopBarMode = TopBarMode.Main; - mTopBarSwitcher.setDisplayedChild(mTopBarMode.ordinal()); - showInfo(copied?"Copied to clipboard":"No text selected"); - } - }); - - mHighlightButton.setOnClickListener(new View.OnClickListener() { - public void onClick(View v) { - MuPDFView pageView = (MuPDFView) mDocView.getDisplayedView(); - boolean success = false; - if (pageView != null) - success = pageView.markupSelection(Annotation.Type.HIGHLIGHT); - mDocView.setMode(MuPDFReaderView.Mode.Viewing); - mTopBarMode = TopBarMode.Main; - mTopBarSwitcher.setDisplayedChild(mTopBarMode.ordinal()); - if (!success) - showInfo("No text selected"); - } - }); - - mUnderlineButton.setOnClickListener(new View.OnClickListener() { - public void onClick(View v) { - MuPDFView pageView = (MuPDFView) mDocView.getDisplayedView(); - boolean success = false; - if (pageView != null) - success = pageView.markupSelection(Annotation.Type.UNDERLINE); - mDocView.setMode(MuPDFReaderView.Mode.Viewing); - mTopBarMode = TopBarMode.Main; - mTopBarSwitcher.setDisplayedChild(mTopBarMode.ordinal()); - if (!success) - showInfo("No text selected"); - } - }); - - mStrikeOutButton.setOnClickListener(new View.OnClickListener() { - public void onClick(View v) { - MuPDFView pageView = (MuPDFView) mDocView.getDisplayedView(); - boolean success = false; - if (pageView != null) - success = pageView.markupSelection(Annotation.Type.STRIKEOUT); - mDocView.setMode(MuPDFReaderView.Mode.Viewing); - mTopBarMode = TopBarMode.Main; - mTopBarSwitcher.setDisplayedChild(mTopBarMode.ordinal()); - if (!success) - showInfo("No text selected"); - } - }); - - mCancelButton.setOnClickListener(new View.OnClickListener() { - public void onClick(View v) { - searchModeOff(); - } - }); - // Search invoking buttons are disabled while there is no text specified mSearchBack.setEnabled(false); mSearchFwd.setEnabled(false); @@ -711,16 +553,6 @@ public class MuPDFActivity extends Activity mOutlineButton.setVisibility(View.GONE); } - mDeleteButton.setOnClickListener(new View.OnClickListener() { - public void onClick(View v) { - View cv = mDocView.getDisplayedView(); - if (cv != null) - ((MuPDFView)cv).deleteSelectedAnnotation(); - mTopBarMode = TopBarMode.Main; - mTopBarSwitcher.setDisplayedChild(mTopBarMode.ordinal()); - } - }); - // Reenstate last state if it was recorded SharedPreferences prefs = getPreferences(Context.MODE_PRIVATE); mDocView.setDisplayedViewIndex(prefs.getInt("page"+mFileName, 0)); @@ -999,22 +831,8 @@ public class MuPDFActivity extends Activity mInfoView = (TextView)mButtonsView.findViewById(R.id.info); mSearchButton = (ImageButton)mButtonsView.findViewById(R.id.searchButton); mReflowButton = (ImageButton)mButtonsView.findViewById(R.id.reflowButton); - mSelectButton = (ImageButton)mButtonsView.findViewById(R.id.selectButton); - mCancelSelectButton = (ImageButton)mButtonsView.findViewById(R.id.cancelSelectButton); - mCopySelectButton = (ImageButton)mButtonsView.findViewById(R.id.copySelectButton); - mHighlightButton = (ImageButton)mButtonsView.findViewById(R.id.highlightButton); - mUnderlineButton = (ImageButton)mButtonsView.findViewById(R.id.underlineButton); - mStrikeOutButton = (ImageButton)mButtonsView.findViewById(R.id.strikeOutButton); - mCancelButton = (ImageButton)mButtonsView.findViewById(R.id.cancel); mOutlineButton = (ImageButton)mButtonsView.findViewById(R.id.outlineButton); - mDeleteButton = (ImageButton)mButtonsView.findViewById(R.id.deleteButton); - mCancelDeleteButton = (ImageButton)mButtonsView.findViewById(R.id.cancelDeleteButton); mAnnotButton = (ImageButton)mButtonsView.findViewById(R.id.annotButton); - mCancelAnnotButton = (ImageButton)mButtonsView.findViewById(R.id.cancelAnnotButton); - mInkButton = (ImageButton)mButtonsView.findViewById(R.id.inkButton); - mSaveInkButton = (Button)mButtonsView.findViewById(R.id.saveInkButton); - mCancelInkButton = (ImageButton)mButtonsView.findViewById(R.id.cancelInkButton); - mPrintButton = (ImageButton)mButtonsView.findViewById(R.id.printButton); mTopBarSwitcher = (ViewAnimator)mButtonsView.findViewById(R.id.switcher); mSearchBack = (ImageButton)mButtonsView.findViewById(R.id.searchBack); mSearchFwd = (ImageButton)mButtonsView.findViewById(R.id.searchForward); @@ -1026,6 +844,131 @@ public class MuPDFActivity extends Activity mPageSlider.setVisibility(View.INVISIBLE); } + public void OnSelectButtonClick(View v) { + mDocView.setMode(MuPDFReaderView.Mode.Selecting); + mTopBarMode = TopBarMode.Text; + mTopBarSwitcher.setDisplayedChild(mTopBarMode.ordinal()); + showInfo("Select text"); + } + + public void OnCancelSelectButtonClick(View v) { + MuPDFView pageView = (MuPDFView) mDocView.getDisplayedView(); + if (pageView != null) + pageView.deselectText(); + mDocView.setMode(MuPDFReaderView.Mode.Viewing); + mTopBarMode = TopBarMode.AnnotCreate; + mTopBarSwitcher.setDisplayedChild(mTopBarMode.ordinal()); + } + + public void OnCopySelectButtonClick(View v) { + MuPDFView pageView = (MuPDFView) mDocView.getDisplayedView(); + boolean copied = false; + if (pageView != null) + copied = pageView.copySelection(); + mDocView.setMode(MuPDFReaderView.Mode.Viewing); + mTopBarMode = TopBarMode.Main; + mTopBarSwitcher.setDisplayedChild(mTopBarMode.ordinal()); + showInfo(copied?"Copied to clipboard":"No text selected"); + } + + public void OnHighlightButtonClick(View v) { + MuPDFView pageView = (MuPDFView) mDocView.getDisplayedView(); + boolean success = false; + if (pageView != null) + success = pageView.markupSelection(Annotation.Type.HIGHLIGHT); + mDocView.setMode(MuPDFReaderView.Mode.Viewing); + mTopBarMode = TopBarMode.Main; + mTopBarSwitcher.setDisplayedChild(mTopBarMode.ordinal()); + if (!success) + showInfo("No text selected"); + } + + public void OnUnderlineButtonClick(View v) { + MuPDFView pageView = (MuPDFView) mDocView.getDisplayedView(); + boolean success = false; + if (pageView != null) + success = pageView.markupSelection(Annotation.Type.UNDERLINE); + mDocView.setMode(MuPDFReaderView.Mode.Viewing); + mTopBarMode = TopBarMode.Main; + mTopBarSwitcher.setDisplayedChild(mTopBarMode.ordinal()); + if (!success) + showInfo("No text selected"); + } + + public void OnStrikeOutButtonClick(View v) { + MuPDFView pageView = (MuPDFView) mDocView.getDisplayedView(); + boolean success = false; + if (pageView != null) + success = pageView.markupSelection(Annotation.Type.STRIKEOUT); + mDocView.setMode(MuPDFReaderView.Mode.Viewing); + mTopBarMode = TopBarMode.Main; + mTopBarSwitcher.setDisplayedChild(mTopBarMode.ordinal()); + if (!success) + showInfo("No text selected"); + } + + public void OnCancelSearchButtonClick(View v) { + searchModeOff(); + } + + public void OnDeleteButtonClick(View v) { + View cv = mDocView.getDisplayedView(); + if (cv != null) + ((MuPDFView)cv).deleteSelectedAnnotation(); + mTopBarMode = TopBarMode.Main; + mTopBarSwitcher.setDisplayedChild(mTopBarMode.ordinal()); + } + + public void OnCancelDeleteButtonClick(View v) { + MuPDFView pageView = (MuPDFView) mDocView.getDisplayedView(); + if (pageView != null) + pageView.deselectAnnotation(); + mDocView.setMode(MuPDFReaderView.Mode.Viewing); + mTopBarMode = TopBarMode.Main; + mTopBarSwitcher.setDisplayedChild(mTopBarMode.ordinal()); + } + + public void OnCancelAnnotButtonClick(View v) { + MuPDFView pageView = (MuPDFView) mDocView.getDisplayedView(); + if (pageView != null) + pageView.deselectText(); + mDocView.setMode(MuPDFReaderView.Mode.Viewing); + mTopBarMode = TopBarMode.Main; + mTopBarSwitcher.setDisplayedChild(mTopBarMode.ordinal()); + } + + public void OnInkButtonClick(View v) { + mDocView.setMode(MuPDFReaderView.Mode.Drawing); + mTopBarMode = TopBarMode.InkCreate; + mTopBarSwitcher.setDisplayedChild(mTopBarMode.ordinal()); + showInfo("Draw annotation"); + } + + public void OnSaveInkButtonClick(View v) { + MuPDFView pageView = (MuPDFView) mDocView.getDisplayedView(); + boolean success = false; + if (pageView != null) + success = pageView.saveDraw(); + mDocView.setMode(MuPDFReaderView.Mode.Viewing); + mTopBarMode = TopBarMode.Main; + mTopBarSwitcher.setDisplayedChild(mTopBarMode.ordinal()); + if (!success) + showInfo("Nothing to save"); + } + + public void OnCancelInkButtonClick(View v) { + MuPDFView pageView = (MuPDFView) mDocView.getDisplayedView(); + if (pageView != null) + pageView.cancelDraw(); + mDocView.setMode(MuPDFReaderView.Mode.Viewing); + mTopBarMode = TopBarMode.AnnotCreate; + mTopBarSwitcher.setDisplayedChild(mTopBarMode.ordinal()); + } + + public void OnPrintButtonClick(View v) { + printDoc(); + } + private void showKeyboard() { InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); if (imm != null) |