refactor
This commit is contained in:
@@ -14,6 +14,11 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
||||
* For more information, please, contact se.solovyev@gmail.com
|
||||
*/
|
||||
|
||||
package org.solovyev.android.view;
|
||||
|
||||
import android.content.Context;
|
||||
@@ -102,7 +107,7 @@ public class ColorButton extends Button {
|
||||
measureText();
|
||||
}
|
||||
|
||||
private void drawMagicFlame(int duration, Canvas canvas) {
|
||||
public void drawMagicFlame(int duration, Canvas canvas) {
|
||||
int alpha = 255 - 255 * duration / CLICK_FEEDBACK_DURATION;
|
||||
int color = CLICK_FEEDBACK_COLOR | (alpha << 24);
|
||||
|
||||
@@ -121,8 +126,6 @@ public class ColorButton extends Button {
|
||||
drawMagicFlame(animDuration, canvas);
|
||||
postInvalidateDelayed(CLICK_FEEDBACK_INTERVAL);
|
||||
}
|
||||
} else if (isPressed()) {
|
||||
drawMagicFlame(0, canvas);
|
||||
}
|
||||
|
||||
CharSequence text = getText();
|
||||
|
22
src/main/java/org/solovyev/android/view/CursorControl.java
Normal file
22
src/main/java/org/solovyev/android/view/CursorControl.java
Normal file
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
||||
* For more information, please, contact se.solovyev@gmail.com
|
||||
*/
|
||||
|
||||
package org.solovyev.android.view;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
* Date: 9/13/11
|
||||
* Time: 12:08 AM
|
||||
*/
|
||||
public interface CursorControl {
|
||||
|
||||
public void setCursorOnStart();
|
||||
|
||||
public void setCursorOnEnd();
|
||||
|
||||
public void moveCursorLeft();
|
||||
|
||||
public void moveCursorRight();
|
||||
}
|
@@ -1,3 +1,8 @@
|
||||
/*
|
||||
* Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
||||
* For more information, please, contact se.solovyev@gmail.com
|
||||
*/
|
||||
|
||||
package org.solovyev.android.view;
|
||||
|
||||
import android.content.Context;
|
||||
@@ -41,6 +46,27 @@ public class DirectionDragButton extends DragButton {
|
||||
init(context, attrs);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getDirectionText(@NotNull DragDirection direction) {
|
||||
final String result;
|
||||
|
||||
switch (direction) {
|
||||
case up:
|
||||
result = this.getTextUp();
|
||||
break;
|
||||
|
||||
case down:
|
||||
result = this.getTextDown();
|
||||
break;
|
||||
|
||||
default:
|
||||
result = null;
|
||||
break;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
private void init(@NotNull Context context, @NotNull AttributeSet attrs) {
|
||||
|
||||
|
@@ -1,3 +1,8 @@
|
||||
/*
|
||||
* Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
||||
* For more information, please, contact se.solovyev@gmail.com
|
||||
*/
|
||||
|
||||
package org.solovyev.android.view;
|
||||
|
||||
import android.content.Context;
|
||||
@@ -71,24 +76,24 @@ public class DragButton extends ColorButton {
|
||||
|
||||
case MotionEvent.ACTION_UP:
|
||||
// stop tracking
|
||||
|
||||
|
||||
if (localStartPoint != null && localOnDragListener.onDrag(DragButton.this, new DragEvent(localStartPoint, event))) {
|
||||
if (localOnDragListener.isSuppressOnClickEvent()) {
|
||||
// prevent on click action
|
||||
setPressed(false);
|
||||
}
|
||||
|
||||
// sometimes setPressed(false); doesn't work so to prevent onClick action button disables
|
||||
if (v instanceof Button) {
|
||||
final Button button = (Button) v;
|
||||
|
||||
if (v instanceof Button) {
|
||||
final Button button = (Button)v;
|
||||
button.setEnabled(false);
|
||||
|
||||
button.setEnabled(false);
|
||||
|
||||
new Handler().postDelayed(new Runnable() {
|
||||
public void run() {
|
||||
button.setEnabled(true);
|
||||
}
|
||||
}, 500);
|
||||
new Handler().postDelayed(new Runnable() {
|
||||
public void run() {
|
||||
button.setEnabled(true);
|
||||
}
|
||||
}, 300);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -1,3 +1,8 @@
|
||||
/*
|
||||
* Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
||||
* For more information, please, contact se.solovyev@gmail.com
|
||||
*/
|
||||
|
||||
package org.solovyev.android.view;
|
||||
|
||||
public enum DragDirection {
|
||||
|
@@ -1,3 +1,8 @@
|
||||
/*
|
||||
* Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
||||
* For more information, please, contact se.solovyev@gmail.com
|
||||
*/
|
||||
|
||||
package org.solovyev.android.view;
|
||||
|
||||
import android.view.MotionEvent;
|
||||
|
@@ -1,3 +1,8 @@
|
||||
/*
|
||||
* Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
||||
* For more information, please, contact se.solovyev@gmail.com
|
||||
*/
|
||||
|
||||
package org.solovyev.android.view;
|
||||
|
||||
import android.widget.TextView;
|
||||
|
24
src/main/java/org/solovyev/android/view/HistoryControl.java
Normal file
24
src/main/java/org/solovyev/android/view/HistoryControl.java
Normal file
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
||||
* For more information, please, contact se.solovyev@gmail.com
|
||||
*/
|
||||
|
||||
package org.solovyev.android.view;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.solovyev.common.utils.history.HistoryAction;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
* Date: 9/16/11
|
||||
* Time: 11:42 PM
|
||||
*/
|
||||
public interface HistoryControl<T> {
|
||||
|
||||
void doHistoryAction(@NotNull HistoryAction historyAction);
|
||||
|
||||
void setCurrentHistoryState(@NotNull T editorHistoryState);
|
||||
|
||||
@NotNull
|
||||
T getCurrentHistoryState();
|
||||
}
|
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
||||
* For more information, please, contact se.solovyev@gmail.com
|
||||
*/
|
||||
|
||||
package org.solovyev.android.view;
|
||||
|
||||
import android.util.Log;
|
||||
import android.view.MotionEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.solovyev.android.view.*;
|
||||
import org.solovyev.common.utils.Point2d;
|
||||
import org.solovyev.common.utils.StringUtils;
|
||||
import org.solovyev.common.utils.history.HistoryAction;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
* Date: 9/16/11
|
||||
* Time: 11:36 PM
|
||||
*/
|
||||
public class HistoryDragProcessor<T> implements SimpleOnDragListener.DragProcessor {
|
||||
|
||||
@NotNull
|
||||
private final HistoryControl<T> historyControl;
|
||||
|
||||
public HistoryDragProcessor(@NotNull HistoryControl<T> historyControl) {
|
||||
this.historyControl = historyControl;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean processDragEvent(@NotNull DragDirection dragDirection, @NotNull DragButton dragButton, @NotNull Point2d startPoint2d, @NotNull MotionEvent motionEvent) {
|
||||
boolean result = false;
|
||||
|
||||
Log.d(String.valueOf(dragButton.getId()), "History on drag event start: " + dragDirection);
|
||||
|
||||
assert dragButton instanceof DirectionDragButton;
|
||||
String actionText = ((DirectionDragButton) dragButton).getDirectionText(dragDirection);
|
||||
if (!StringUtils.isEmpty(actionText)) {
|
||||
try {
|
||||
result = true;
|
||||
|
||||
final HistoryAction historyAction = HistoryAction.valueOf(actionText);
|
||||
historyControl.doHistoryAction(historyAction);
|
||||
} catch (IllegalArgumentException e) {
|
||||
Log.e(String.valueOf(dragButton.getId()), "Unsupported history action: " + actionText);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
@@ -1,3 +1,8 @@
|
||||
/*
|
||||
* Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
||||
* For more information, please, contact se.solovyev@gmail.com
|
||||
*/
|
||||
|
||||
package org.solovyev.android.view;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
@@ -1,3 +1,8 @@
|
||||
/*
|
||||
* Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
||||
* For more information, please, contact se.solovyev@gmail.com
|
||||
*/
|
||||
|
||||
package org.solovyev.android.view;
|
||||
|
||||
import android.util.Log;
|
||||
|
Reference in New Issue
Block a user