Fix several issues in the gestures libraries.
This mostly fixes how gestures libraries are saved and loaded. Saving a library twice in a row was erasing the entire library, which was preventing the sketch test app from working propertly.
This commit is contained in:
@ -47497,6 +47497,17 @@
|
||||
visibility="public"
|
||||
>
|
||||
</method>
|
||||
<method name="hasChanged"
|
||||
return="boolean"
|
||||
abstract="false"
|
||||
native="false"
|
||||
synchronized="false"
|
||||
static="false"
|
||||
final="false"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
</method>
|
||||
<method name="load"
|
||||
return="void"
|
||||
abstract="false"
|
||||
|
@ -61,17 +61,21 @@ public final class GestureLibraries {
|
||||
}
|
||||
|
||||
public boolean save() {
|
||||
final File file = mPath;
|
||||
if (!file.canWrite()) return false;
|
||||
if (!mStore.hasChanged()) return true;
|
||||
|
||||
if (!file.getParentFile().exists()) {
|
||||
if (!file.getParentFile().mkdirs()) {
|
||||
final File file = mPath;
|
||||
|
||||
final File parentFile = file.getParentFile();
|
||||
if (!parentFile.exists()) {
|
||||
if (!parentFile.mkdirs()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
boolean result = false;
|
||||
try {
|
||||
//noinspection ResultOfMethodCallIgnored
|
||||
file.createNewFile();
|
||||
mStore.save(new FileOutputStream(file), true);
|
||||
result = true;
|
||||
} catch (FileNotFoundException e) {
|
||||
|
@ -287,8 +287,10 @@ public class GestureOverlayView extends FrameLayout {
|
||||
path.computeBounds(bounds, true);
|
||||
|
||||
mPath.rewind();
|
||||
mPath.addPath(path, (getWidth() - bounds.width()) / 2.0f,
|
||||
(getHeight() - bounds.height()) / 2.0f);
|
||||
mPath.addPath(path, -bounds.left + (getWidth() - bounds.width()) / 2.0f,
|
||||
-bounds.top + (getHeight() - bounds.height()) / 2.0f);
|
||||
|
||||
mResetGesture = true;
|
||||
|
||||
invalidate();
|
||||
}
|
||||
@ -367,10 +369,10 @@ public class GestureOverlayView extends FrameLayout {
|
||||
}
|
||||
|
||||
public void clear(boolean animated) {
|
||||
clear(animated, false);
|
||||
clear(animated, false, true);
|
||||
}
|
||||
|
||||
private void clear(boolean animated, boolean fireActionPerformed) {
|
||||
private void clear(boolean animated, boolean fireActionPerformed, boolean immediate) {
|
||||
setPaintAlpha(255);
|
||||
removeCallbacks(mFadingOut);
|
||||
mResetGesture = false;
|
||||
@ -389,15 +391,19 @@ public class GestureOverlayView extends FrameLayout {
|
||||
mIsFadingOut = false;
|
||||
mFadingHasStarted = false;
|
||||
|
||||
if (fireActionPerformed) {
|
||||
postDelayed(mFadingOut, mFadeOffset);
|
||||
} else if (mHandleGestureActions) {
|
||||
if (immediate) {
|
||||
mCurrentGesture = null;
|
||||
mPath.rewind();
|
||||
invalidate();
|
||||
} else if (fireActionPerformed) {
|
||||
postDelayed(mFadingOut, mFadeOffset);
|
||||
} else if (mGestureStrokeType == GESTURE_STROKE_TYPE_MULTIPLE) {
|
||||
mFadingOut.resetMultipleStrokes = true;
|
||||
postDelayed(mFadingOut, mFadeOffset);
|
||||
} else {
|
||||
mCurrentGesture = null;
|
||||
mPath.rewind();
|
||||
invalidate();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -647,7 +653,8 @@ public class GestureOverlayView extends FrameLayout {
|
||||
listeners.get(i).onGestureEnded(this, event);
|
||||
}
|
||||
|
||||
clear(mHandleGestureActions && mFadeEnabled, mHandleGestureActions && mIsGesturing);
|
||||
clear(mHandleGestureActions && mFadeEnabled, mHandleGestureActions && mIsGesturing,
|
||||
false);
|
||||
} else {
|
||||
cancelGesture(event);
|
||||
|
||||
|
@ -206,6 +206,10 @@ public class GestureStore {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasChanged() {
|
||||
return mChanged;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save the gesture library
|
||||
*/
|
||||
@ -214,10 +218,6 @@ public class GestureStore {
|
||||
}
|
||||
|
||||
public void save(OutputStream stream, boolean closeStream) throws IOException {
|
||||
if (!mChanged) {
|
||||
return;
|
||||
}
|
||||
|
||||
DataOutputStream out = null;
|
||||
|
||||
try {
|
||||
|
Reference in New Issue
Block a user