From 66d214478e5f04fe2fe32026ca595ed91f7f89b1 Mon Sep 17 00:00:00 2001 From: Jack Yoo Date: Tue, 27 Oct 2015 16:27:49 -0700 Subject: Gallery3d: TrueScanner feature Adding TrueScanner feature Change-Id: Ib29010f8319addf783dbdf8c91c33959bc7f56ca CRs-Fixed: 967806 --- res/drawable/truescanner.xml | 63 ++++++ res/layout/filtershow_main_panel.xml | 20 ++ res/values/filtershow_ids.xml | 1 + res/values/filtershow_strings.xml | 2 + res/values/strings.xml | 2 + .../gallery3d/filtershow/EditorPlaceHolder.java | 3 +- .../gallery3d/filtershow/FilterShowActivity.java | 35 ++- .../filtershow/category/CategoryAdapter.java | 5 + .../filtershow/category/CategoryPanel.java | 6 + .../gallery3d/filtershow/category/MainPanel.java | 40 +++- .../filtershow/editors/TrueScannerEditor.java | 79 +++++++ .../filtershow/filters/BaseFiltersManager.java | 15 ++ .../filtershow/filters/TrueScannerActs.java | 184 +++++++++++++++ .../filters/TrueScannerWhiteBoardActs.java | 63 ++++++ .../gallery3d/filtershow/imageshow/ImageShow.java | 2 + .../filtershow/imageshow/ImageTrueScanner.java | 249 +++++++++++++++++++++ .../filtershow/pipeline/ProcessingService.java | 2 + .../filtershow/editors/EditorManager.java | 1 + 18 files changed, 764 insertions(+), 8 deletions(-) create mode 100644 res/drawable/truescanner.xml create mode 100644 src/com/android/gallery3d/filtershow/editors/TrueScannerEditor.java create mode 100644 src/com/android/gallery3d/filtershow/filters/TrueScannerActs.java create mode 100644 src/com/android/gallery3d/filtershow/filters/TrueScannerWhiteBoardActs.java create mode 100644 src/com/android/gallery3d/filtershow/imageshow/ImageTrueScanner.java diff --git a/res/drawable/truescanner.xml b/res/drawable/truescanner.xml new file mode 100644 index 000000000..49236ef07 --- /dev/null +++ b/res/drawable/truescanner.xml @@ -0,0 +1,63 @@ + + + + + + + + + + diff --git a/res/layout/filtershow_main_panel.xml b/res/layout/filtershow_main_panel.xml index d0e624665..36e21b7ae 100644 --- a/res/layout/filtershow_main_panel.xml +++ b/res/layout/filtershow_main_panel.xml @@ -110,6 +110,16 @@ android:scaleType="centerInside" android:visibility="gone" android:src="@drawable/dualcamera"/> + + + + diff --git a/res/values/filtershow_ids.xml b/res/values/filtershow_ids.xml index 7dc34c357..8251604a2 100644 --- a/res/values/filtershow_ids.xml +++ b/res/values/filtershow_ids.xml @@ -54,4 +54,5 @@ + diff --git a/res/values/filtershow_strings.xml b/res/values/filtershow_strings.xml index 8e1c4e27f..cd671bd2e 100644 --- a/res/values/filtershow_strings.xml +++ b/res/values/filtershow_strings.xml @@ -132,6 +132,8 @@ + + True Scanner Exposure diff --git a/res/values/strings.xml b/res/values/strings.xml index 977475f24..e57529936 100755 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -1187,4 +1187,6 @@ CHAR LIMIT = NONE] --> Trimface Bigeye drawer + Normal + WhiteBoard diff --git a/src/com/android/gallery3d/filtershow/EditorPlaceHolder.java b/src/com/android/gallery3d/filtershow/EditorPlaceHolder.java index 95fc56d4f..86cc87034 100644 --- a/src/com/android/gallery3d/filtershow/EditorPlaceHolder.java +++ b/src/com/android/gallery3d/filtershow/EditorPlaceHolder.java @@ -66,7 +66,8 @@ public class EditorPlaceHolder { } public void hide() { - mContainer.setVisibility(View.GONE); + if(mContainer != null) + mContainer.setVisibility(View.GONE); } public void hideOldViews() { diff --git a/src/com/android/gallery3d/filtershow/FilterShowActivity.java b/src/com/android/gallery3d/filtershow/FilterShowActivity.java index ab921e689..4c2e6ef67 100644 --- a/src/com/android/gallery3d/filtershow/FilterShowActivity.java +++ b/src/com/android/gallery3d/filtershow/FilterShowActivity.java @@ -94,6 +94,7 @@ import com.android.gallery3d.filtershow.editors.EditorDualCamFusion; import com.android.gallery3d.filtershow.editors.EditorManager; import com.android.gallery3d.filtershow.editors.EditorPanel; import com.android.gallery3d.filtershow.editors.ImageOnlyEditor; +import com.android.gallery3d.filtershow.editors.TrueScannerEditor; import com.android.gallery3d.filtershow.filters.FilterDrawRepresentation; import com.android.gallery3d.filtershow.filters.FilterMirrorRepresentation; import com.android.gallery3d.filtershow.filters.FilterRepresentation; @@ -102,6 +103,7 @@ import com.android.gallery3d.filtershow.filters.FilterUserPresetRepresentation; import com.android.gallery3d.filtershow.filters.FiltersManager; import com.android.gallery3d.filtershow.filters.ImageFilter; import com.android.gallery3d.filtershow.filters.SimpleMakeupImageFilter; +import com.android.gallery3d.filtershow.filters.TrueScannerActs; import com.android.gallery3d.filtershow.history.HistoryItem; import com.android.gallery3d.filtershow.history.HistoryManager; import com.android.gallery3d.filtershow.imageshow.ImageShow; @@ -181,6 +183,7 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL private CategoryAdapter mCategoryBordersAdapter = null; private CategoryAdapter mCategoryGeometryAdapter = null; private CategoryAdapter mCategoryFiltersAdapter = null; + private CategoryAdapter mCategoryTrueScannerAdapter = null; private CategoryAdapter mCategoryVersionsAdapter = null; private CategoryAdapter mCategoryMakeupAdapter = null; private CategoryAdapter mCategoryDualCamAdapter = null; @@ -571,6 +574,7 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL fillBorders(); fillTools(); fillEffects(); + fillTrueScanner(); fillVersions(); fillMakeup(); fillDualCamera(); @@ -696,6 +700,21 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL } } + private void fillTrueScanner() { + FiltersManager filtersManager = FiltersManager.getManager(); + ArrayList trueScannerRepresentations = filtersManager.getTrueScanner(); + if (mCategoryTrueScannerAdapter != null) { + mCategoryTrueScannerAdapter.clear(); + } + mCategoryTrueScannerAdapter = new CategoryAdapter(this); + for (FilterRepresentation representation : trueScannerRepresentations) { + if (representation.getTextId() != 0) { + representation.setName(getString(representation.getTextId())); + } + mCategoryTrueScannerAdapter.add(new Action(this, representation)); + } + } + private void fillTools() { FiltersManager filtersManager = FiltersManager.getManager(); ArrayList filtersRepresentations = filtersManager.getTools(); @@ -834,6 +853,10 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL return mCategoryFiltersAdapter; } + public CategoryAdapter getCategoryTrueScannerAdapter() { + return mCategoryTrueScannerAdapter; + } + public CategoryAdapter getCategoryVersionsAdapter() { return mCategoryVersionsAdapter; } @@ -1646,10 +1669,14 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL } public void showDefaultImageView() { - mEditorPlaceHolder.hide(); - mImageShow.setVisibility(View.VISIBLE); - MasterImage.getImage().setCurrentFilter(null); - MasterImage.getImage().setCurrentFilterRepresentation(null); + if(mEditorPlaceHolder != null) + mEditorPlaceHolder.hide(); + if(mImageShow != null) + mImageShow.setVisibility(View.VISIBLE); + if(MasterImage.getImage() != null) { + MasterImage.getImage().setCurrentFilter(null); + MasterImage.getImage().setCurrentFilterRepresentation(null); + } } public void backToMain() { diff --git a/src/com/android/gallery3d/filtershow/category/CategoryAdapter.java b/src/com/android/gallery3d/filtershow/category/CategoryAdapter.java index 9571d8b16..83ab5b2a3 100644 --- a/src/com/android/gallery3d/filtershow/category/CategoryAdapter.java +++ b/src/com/android/gallery3d/filtershow/category/CategoryAdapter.java @@ -88,6 +88,11 @@ public class CategoryAdapter extends ArrayAdapter { if (category == MainPanel.DUALCAM) { mSelectedPosition = 0; } + + if (category == MainPanel.TRUESCANNER) { + mSelectedPosition = 0; + } + if (category == MainPanel.VERSIONS) { mAddButtonText = getContext().getString(R.string.filtershow_add_button_versions); } diff --git a/src/com/android/gallery3d/filtershow/category/CategoryPanel.java b/src/com/android/gallery3d/filtershow/category/CategoryPanel.java index 3ee9e45eb..62071f309 100644 --- a/src/com/android/gallery3d/filtershow/category/CategoryPanel.java +++ b/src/com/android/gallery3d/filtershow/category/CategoryPanel.java @@ -88,6 +88,12 @@ public class CategoryPanel extends Fragment implements View.OnClickListener { mAdapter.initializeSelection(MainPanel.DUALCAM); } activity.updateCategories(); + } + case MainPanel.TRUESCANNER: { + mAdapter = activity.getCategoryTrueScannerAdapter(); + if (mAdapter != null) { + mAdapter.initializeSelection(MainPanel.TRUESCANNER); + } break; } case MainPanel.VERSIONS: { diff --git a/src/com/android/gallery3d/filtershow/category/MainPanel.java b/src/com/android/gallery3d/filtershow/category/MainPanel.java index 0d7d6f6ce..17766dfd1 100644 --- a/src/com/android/gallery3d/filtershow/category/MainPanel.java +++ b/src/com/android/gallery3d/filtershow/category/MainPanel.java @@ -31,6 +31,7 @@ import android.util.Log; import com.android.gallery3d.R; import com.android.gallery3d.filtershow.FilterShowActivity; import com.android.gallery3d.filtershow.filters.SimpleMakeupImageFilter; +import com.android.gallery3d.filtershow.filters.TrueScannerActs; import com.android.gallery3d.filtershow.imageshow.MasterImage; import com.android.gallery3d.filtershow.state.StatePanel; import com.android.gallery3d.filtershow.tools.DualCameraNativeEngine; @@ -51,6 +52,7 @@ public class MainPanel extends Fragment { private View mEffectsTextContainer; private FrameLayout mCategoryFragment; private View mBottomView; + private ImageButton trueScannerButton; public static final String FRAGMENT_TAG = "MainPanel"; public static final String EDITOR_TAG = "coming-from-editor-panel"; @@ -61,6 +63,7 @@ public class MainPanel extends Fragment { public static final int MAKEUP = 4; public static final int DUALCAM = 5; public static final int VERSIONS = 6; + public static final int TRUESCANNER = 7; private int mCurrentSelected = -1; private int mPreviousToggleVersions = -1; @@ -98,6 +101,10 @@ public class MainPanel extends Fragment { dualCamButton.setSelected(value); break; } + case TRUESCANNER: { + //trueScannerButton.setSelected(value); + break; + } } } @@ -129,19 +136,19 @@ public class MainPanel extends Fragment { mBottomView = mMainView.findViewById(R.id.bottom_panel); mEffectsContainer = mMainView.findViewById(R.id.effectsContainer); mEffectsTextContainer = mMainView.findViewById(R.id.effectsText); - if(SimpleMakeupImageFilter.HAS_TS_MAKEUP) { + if (SimpleMakeupImageFilter.HAS_TS_MAKEUP) { makeupButton = (ImageButton) mMainView.findViewById(R.id.makeupButton); makeupButton.setVisibility(View.VISIBLE); TextView beautify = (TextView) mEffectsTextContainer .findViewById(R.id.tvBeautify); beautify.setVisibility(View.VISIBLE); } - boolean showPanel = false; + boolean showPanel = false; if (getArguments() != null) { showPanel = getArguments().getBoolean(EDITOR_TAG); } - if(makeupButton != null) { + if (makeupButton != null) { makeupButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { @@ -149,6 +156,12 @@ public class MainPanel extends Fragment { } }); } + TextView trueScannerTv = (TextView) mMainView.findViewById(R.id.tvTrueScanner); + trueScannerButton = (ImageButton) mMainView.findViewById(R.id.trueScannerButton); + if (!TrueScannerActs.isTrueScannerEnabled()) { + trueScannerTv.setVisibility(View.GONE); + trueScannerButton.setVisibility(View.GONE); + } looksButton.setOnClickListener(new View.OnClickListener() { @Override @@ -183,6 +196,13 @@ public class MainPanel extends Fragment { updateDualCameraButton(); + trueScannerButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + showPanel(TRUESCANNER); + } + }); + FilterShowActivity activity = (FilterShowActivity) getActivity(); //showImageStatePanel(activity.isShowingImageStatePanel()); if (showPanel) { @@ -290,6 +310,16 @@ public class MainPanel extends Fragment { selection(mCurrentSelected, true); } + public void loadCategoryTrueScannerPanel() { + boolean fromRight = isRightAnimation(TRUESCANNER); + selection(mCurrentSelected, false); + CategoryPanel categoryPanel = new CategoryPanel(); + categoryPanel.setAdapter(TRUESCANNER); + setCategoryFragment(categoryPanel, fromRight); + mCurrentSelected = TRUESCANNER; + selection(mCurrentSelected, true); + } + public void loadCategoryFiltersPanel() { /*if (mCurrentSelected == FILTERS) { return; @@ -361,6 +391,10 @@ public class MainPanel extends Fragment { loadCategoryDualCamPanel(); break; } + case TRUESCANNER: { + loadCategoryTrueScannerPanel(); + break; + } case VERSIONS: { loadCategoryVersionsPanel(); break; diff --git a/src/com/android/gallery3d/filtershow/editors/TrueScannerEditor.java b/src/com/android/gallery3d/filtershow/editors/TrueScannerEditor.java new file mode 100644 index 000000000..30f099ca5 --- /dev/null +++ b/src/com/android/gallery3d/filtershow/editors/TrueScannerEditor.java @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2016, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package com.android.gallery3d.filtershow.editors; + +import android.content.Context; +import android.widget.FrameLayout; + +import com.android.gallery3d.R; +import com.android.gallery3d.filtershow.filters.FilterBasicRepresentation; +import com.android.gallery3d.filtershow.filters.TrueScannerActs; +import com.android.gallery3d.filtershow.imageshow.ImageShow; +import com.android.gallery3d.filtershow.imageshow.ImageTrueScanner; +import com.android.gallery3d.filtershow.imageshow.MasterImage; + +/** + * The editor with no slider for filters without UI + */ +public class TrueScannerEditor extends Editor { + public final static int ID = R.id.trueScannerEditor; + private final String LOGTAG = "TrueScannerEditor"; + protected ImageTrueScanner mImageTrueScanner; + + public TrueScannerEditor() { + super(ID); + } + + protected TrueScannerEditor(int id) { + super(id); + } + + public boolean useUtilityPanel() { + return true; + } + + @Override + public void createEditor(Context context, FrameLayout frameLayout) { + super.createEditor(context, frameLayout); + mView = mImageShow = mImageTrueScanner = new ImageTrueScanner(context); + mImageTrueScanner.setEditor(this); + } + + @Override + public void finalApplyCalled() { + super.finalApplyCalled(); + } + + @Override + public boolean showsSeekBar() { + return false; + } + +} diff --git a/src/com/android/gallery3d/filtershow/filters/BaseFiltersManager.java b/src/com/android/gallery3d/filtershow/filters/BaseFiltersManager.java index 3de93cf5a..9970cfa65 100644 --- a/src/com/android/gallery3d/filtershow/filters/BaseFiltersManager.java +++ b/src/com/android/gallery3d/filtershow/filters/BaseFiltersManager.java @@ -39,6 +39,7 @@ public abstract class BaseFiltersManager implements FiltersManagerInterface { protected ArrayList mEffects = new ArrayList(); protected ArrayList mMakeup = new ArrayList(); protected ArrayList mDualCam = new ArrayList(); + protected ArrayList mTrueScanner = new ArrayList(); private static int mImageBorderSize = 4; // in percent protected void init() { @@ -46,6 +47,7 @@ public abstract class BaseFiltersManager implements FiltersManagerInterface { mRepresentationLookup = new HashMap(); Vector filters = new Vector(); addFilterClasses(filters); + addTrueScannerClasses(filters); for (Class filterClass : filters) { try { Object filterInstance = filterClass.newInstance(); @@ -155,6 +157,11 @@ public abstract class BaseFiltersManager implements FiltersManagerInterface { } } + protected void addTrueScannerClasses(Vector filters) { + filters.add(TrueScannerActs.class); + filters.add(TrueScannerWhiteBoardActs.class); + } + public ArrayList getLooks() { return mLooks; } @@ -178,6 +185,9 @@ public abstract class BaseFiltersManager implements FiltersManagerInterface { public ArrayList getMakeup() { return mMakeup; } + public ArrayList getTrueScanner() { + return mTrueScanner; + } public void addBorders(Context context) { // Do not localize @@ -335,6 +345,11 @@ public abstract class BaseFiltersManager implements FiltersManagerInterface { } } + public void addTrueScanner() { + mTrueScanner.add(getRepresentation(TrueScannerActs.class)); + mTrueScanner.add(getRepresentation(TrueScannerWhiteBoardActs.class)); + } + public void addTools(Context context) { int[] textId = { diff --git a/src/com/android/gallery3d/filtershow/filters/TrueScannerActs.java b/src/com/android/gallery3d/filtershow/filters/TrueScannerActs.java new file mode 100644 index 000000000..63c3a1299 --- /dev/null +++ b/src/com/android/gallery3d/filtershow/filters/TrueScannerActs.java @@ -0,0 +1,184 @@ +/* + * Copyright (c) 2016, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package com.android.gallery3d.filtershow.filters; + +import android.graphics.Bitmap; +import android.util.Log; +import android.widget.Toast; + +import com.android.gallery3d.R; +import com.android.gallery3d.app.GalleryActivity; +import com.android.gallery3d.filtershow.FilterShowActivity; +import com.android.gallery3d.filtershow.editors.TrueScannerEditor; +import com.android.gallery3d.filtershow.imageshow.ImageTrueScanner; +import com.android.gallery3d.filtershow.imageshow.MasterImage; + +import static com.android.gallery3d.filtershow.imageshow.ImageTrueScanner.*; + +public class TrueScannerActs extends SimpleImageFilter { + public static final String SERIALIZATION_NAME = "TrueScannerActs"; + private static final int MIN_WIDTH = 512; + private static final int MIN_HEIGHT = 512; + private static final boolean DEBUG = false; + private static boolean isTrueScannerEnabled = true; + private static boolean isPointsAcquired; + private final static int POINTS_LEN = 8; + private static int[] mAcquiredPoints = new int[POINTS_LEN+2]; + protected boolean isWhiteBoard = false; + private boolean mLocked = false; + private Bitmap rectifiedImage = null; + private Bitmap whiteboardImage = null; + private int[] oldPts = new int[POINTS_LEN]; + + private void printDebug(String str) { + if(DEBUG) + android.util.Log.d("TrueScanner", str); + } + + public static boolean isTrueScannerEnabled() { + return isTrueScannerEnabled; + } + + public TrueScannerActs() { + mName = "TrueScannerActs"; + isPointsAcquired = false; + } + + public FilterRepresentation getDefaultRepresentation() { + FilterBasicRepresentation representation = (FilterBasicRepresentation) super.getDefaultRepresentation(); + representation.setName("TrueScanner"); + representation.setSerializationName(SERIALIZATION_NAME); + representation.setFilterClass(TrueScannerActs.class); + representation.setTextId(R.string.truescanner_normal); + representation.setMinimum(0); + representation.setMaximum(10); + representation.setValue(0); + representation.setDefaultValue(0); + representation.setSupportsPartialRendering(false); + representation.setEditorId(TrueScannerEditor.ID); + + return representation; + } + + private native int[] processImage(Bitmap orgBitmap, Bitmap rectifiedBitmap, Bitmap whiteboardBitmap, int[] cornerPts); + private native int[] getPoints(Bitmap orgBitmap); + + public static int[] getPoints() { + if(!isPointsAcquired) + return null; + return mAcquiredPoints; + } + + private synchronized boolean acquireLock(boolean isAcquiring) { + if(mLocked != isAcquiring) { + mLocked = isAcquiring; + return true; + } + return false; + } + + private boolean isReNewed(int pts[]) { + if(rectifiedImage == null || whiteboardImage == null) { + return true; + } else { + for(int i=0; i mSegPoints[i*2] - CHECK_RADIUS && x < mSegPoints[i*2] + CHECK_RADIUS + && y > mSegPoints[i*2+1] - CHECK_RADIUS && y < mSegPoints[i*2+1] + CHECK_RADIUS) { + isTouched[i] = true; + } + } + } + + private void moveTouch(float x, float y) { + int i; + for(i=0; i= mSegPoints[2]-mMarginalGapX) + mSegPoints[0] = mSegPoints[2]-mMarginalGapX; + if(mSegPoints[1] < mBitmapBound.top) mSegPoints[1] = (int)mBitmapBound.top; + if(mSegPoints[1] >= mSegPoints[7]-mMarginalGapY) + mSegPoints[1] = mSegPoints[7]-mMarginalGapY; + break; + case 1: + if(mSegPoints[2] > mBitmapBound.right) mSegPoints[2] = (int)mBitmapBound.right; + if(mSegPoints[2] <= mSegPoints[0]+mMarginalGapX) + mSegPoints[2] = mSegPoints[0]+mMarginalGapX; + if(mSegPoints[3] < mBitmapBound.top) mSegPoints[3] = (int)mBitmapBound.top; + if(mSegPoints[3] >= mSegPoints[5]-mMarginalGapY) + mSegPoints[3] = mSegPoints[5]-mMarginalGapY; + break; + case 2: + if(mSegPoints[4] > mBitmapBound.right) mSegPoints[4] = (int)mBitmapBound.right; + if(mSegPoints[4] <= mSegPoints[6]+mMarginalGapX) + mSegPoints[4] = mSegPoints[6]+mMarginalGapX; + if(mSegPoints[5] > mBitmapBound.bottom) mSegPoints[5] = (int)mBitmapBound.bottom; + if(mSegPoints[5] <= mSegPoints[3]+mMarginalGapY) + mSegPoints[5] = mSegPoints[3]+mMarginalGapY; + break; + case 3: + if(mSegPoints[6] < mBitmapBound.left) mSegPoints[6] = (int)mBitmapBound.left; + if(mSegPoints[6] >= mSegPoints[4]-mMarginalGapX) + mSegPoints[6] = mSegPoints[4]-mMarginalGapX; + if(mSegPoints[7] > mBitmapBound.bottom) mSegPoints[7] = (int)mBitmapBound.bottom; + if(mSegPoints[7] <= mSegPoints[1]+mMarginalGapY) + mSegPoints[7] = mSegPoints[1]+mMarginalGapY; + break; + } + } + + @Override + public boolean onTouchEvent(MotionEvent event) { + float x = event.getX(); + float y = event.getY(); + + switch (event.getActionMasked()) { + case (MotionEvent.ACTION_DOWN): + checkPointTouch(x, y); + case (MotionEvent.ACTION_MOVE): + moveTouch(x,y); + break; + case (MotionEvent.ACTION_UP): + for(int i=0; i