我目前正在摆弄Android编程,但我在检测不同的触摸事件时遇到一个小问题,即正常触摸按下(按下屏幕并立即释放),长按(触摸屏幕并按住手指) )和移动(在屏幕上拖动).
我想要做的是在屏幕上有一个图像(圆圈),我可以拖动它.然后,当我按一次(短/正常按下)时,Toast会提供一些关于它的基本信息.当我长按它时,会出现一个带有列表的AlertDialog来选择不同的图像(圆形,矩形或三角形).
我使用自己的OnTouchListener创建了一个自定义视图来检测事件并在onDraw中绘制图像.OnTouchListener.onTouch是这样的:
// has a touch press started?
private boolean touchStarted = false;
// co-ordinates of image
private int x, y;
public boolean onTouch(View v, MotionEvent event) {
int action = event.getAction();
if (action == MotionEvent.ACTION_DOWN) {
touchStarted = true;
}
else if (action == MotionEvent.ACTION_MOVE) {
// movement: cancel the touch press
touchStarted = false;
x = event.getX();
y = event.getY();
invalidate(); // request draw
}
else if (action == MotionEvent.ACTION_UP) {
if (touchStarted) {
// touch …
Run Code Online (Sandbox Code Playgroud) 我在一个应用程序中有两个单独的REST服务.让我们说一个主要的"人"服务和一个辅助"管理"服务.我想要的是在服务器上的不同路径中公开它们.我正在使用JAX-RS,RESTEasy和Spring.
例:
@Path("/people")
public interface PeopleService {
// Stuff
}
@Path("/management")
public interface ManagementService {
// Stuff
}
Run Code Online (Sandbox Code Playgroud)
在web.xml
我目前有如下设置:
<listener>
<listener-class>org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap</listener-class>
</listener>
<listener>
<listener-class>org.jboss.resteasy.plugins.spring.SpringContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>resteasy.servlet.mapping.prefix</param-name>
<param-value>/public</param-value>
</context-param>
<servlet>
<servlet-name>Resteasy</servlet-name>
<servlet-class>
org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Resteasy</servlet-name>
<url-pattern>/public/*</url-pattern>
</servlet-mapping>
Run Code Online (Sandbox Code Playgroud)
在PeopleService
和ManagementService
实施只是春豆.上面的web.xml
配置将它们都暴露在外/public
(因此分别具有/public/people
和/public/management
).
我想要完成的是暴露PeopleService
on /public
,以便完整路径将成为/public/people
并暴露ManagementService
on /internal
,以便它的完整路径将成为/internal/management
.
不幸的是,我无法更改@Path
注释的值.
我该怎么办?
这是我认为应该很容易的事情,但到目前为止我还没有能够让它发挥作用.
我想要做的是将我的根路径映射到Spring MVC控制器.正常情况下Servlet
,我只想/
在我的" "中添加一个" " 的映射web.xml
,它会很好地发现它.但是使用Spring MVC,并非如此.
我尝试了很多组合,但似乎都没有.我认为以下一个应该有效.
在web.xml
:
<servlet-mapping>
<servlet-name>myDispatcherServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
Run Code Online (Sandbox Code Playgroud)
在我的contextConfigLocation
档案中:
<bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="alwaysUseFullPath" value="true"/>
<property name="mappings">
<util:map>
<entry key="/" value-ref="rootController"/>
</util:map>
</property>
</bean>
<bean id="rootController" class="my.package.RootController">
Run Code Online (Sandbox Code Playgroud)
显然,控制器本身就是这种情况.我不知道如何将方法映射到实际的根路径.我的尝试是这样的:
public class RootController extends MultiActionController {
@RequestMapping("/")
public ModelAndView display(HttpServletRequest request, HttpServletResponse response) throws Exception {
final Map<String, Object> model = new HashMap<String, Object>();
model.put("someVariable", "Hello, MVC world.");
return new ModelAndView("rootPage", model);
}
}
Run Code Online (Sandbox Code Playgroud)
所以,假设我的应用程序运行http://localhost:8080/app/
,我想要确切的URL来执行该方法display …
java ×3
spring ×2
android ×1
jax-rs ×1
long-press ×1
mapping ×1
move ×1
rest ×1
resteasy ×1
spring-mvc ×1
touch ×1
url-routing ×1