我正在编写一个以全屏横向模式运行的Android游戏,并在窗口的左下角和右下角放置了按钮.问题是其中一个按钮是(在许多手机上)菜单按钮旁边,因此播放器可能会意外按下菜单.
如果短暂按下,我只需暂停游戏并显示游戏内菜单.没问题.
但如果按下按钮的时间更长,Android会打开屏幕下半部分的软键盘.由于它阻碍了,并且在此Activity中完全没用,我想禁用它.
我尝试了以下方法.
由于我只有一个视图(a GLSurfaceView)我在我的尝试中Activity.onCreate():
InputMethodManager imm = ((InputMethodManager)getSystemService(INPUT_METHOD_SERVICE));
imm.hideSoftInputFromInputMethod(glSurfaceView.getApplicationWindowToken(), 0);
Run Code Online (Sandbox Code Playgroud)
它不起作用:菜单长按时软键盘仍然出现.
我把它添加到我的清单中:
<activity
android:windowSoftInputMode="stateAlwaysHidden"
>
Run Code Online (Sandbox Code Playgroud)
还有很多东西.
那么......还有办法吗?怎么样?
在Java中,我有一个VertexJava3D类的子类Point3f.现在Point3f根据equals()其坐标值计算,但对于我的Vertex类,我想要更严格:如果它们是同一个对象,则两个顶点相等.到现在为止还挺好:
class Vertex extends Point3f {
// ...
public boolean equals(Object other) {
return this == other;
}
}
Run Code Online (Sandbox Code Playgroud)
我知道这违反了合同equals(),但由于我只将顶点与其他顶点进行比较,这不是问题.
现在,为了能够将顶点放入a中HashMap,该hashCode()方法必须返回与之一致的结果equals().它目前正在这样做,但可能将其返回值基于其字段Point3f,因此将为Vertex具有相同坐标的不同对象提供哈希冲突.
因此,我想hashCode()基于对象的地址,而不是从Vertex字段中计算它.我知道这个Object类会这样做,但是我不能调用它的hashCode()方法,因为Point3f它会覆盖它.
所以,实际上我的问题是双重的:
equals()吗?编辑:我只想到了一些东西......我可以int在对象创建时生成一个随机值,并将其用于哈希码.这是一个好主意吗?为什么不)?
所以我试图使用os.walk()来生成目录结构的XML表示.我似乎得到了大量的重复.它正确地将目录放在彼此之间,并将文件放在xml文件的第一部分的正确位置; 但是,在它正确完成后,它会继续错误地遍历.我不太清楚为什么......
这是我的代码:
def dirToXML(self,directory):
curdir = os.getcwd()
os.chdir(directory)
xmlOutput=""
tree = os.walk(directory)
for root, dirs, files in tree:
pathName = string.split(directory, os.sep)
xmlOutput+="<dir><name><![CDATA["+pathName.pop()+"]]></name>"
if len(files)>0:
xmlOutput+=self.fileToXML(files)
for subdir in dirs:
xmlOutput+=self.dirToXML(os.path.join(root,subdir))
xmlOutput+="</dir>"
os.chdir(curdir)
return xmlOutput
Run Code Online (Sandbox Code Playgroud)
fileToXML只是解析列表,所以不必担心.
目录结构很简单:
images/
images/testing.xml
images/structure.xml
images/Hellos
images/Goodbyes
images/Goodbyes/foo
images/Goodbyes/bar
images/Goodbyes/square
Run Code Online (Sandbox Code Playgroud)
并生成的xml文件变为:
<structure>
<dir>
<name>images</name>
<files>
<file>
<name>structure.xml</name>
</file>
<file>
<name>testing.xml</name>
</file>
</files>
<dir>
<name>Hellos</name>
</dir>
<dir>
<name>Goodbyes</name>
<dir>
<name>foo</name>
</dir>
<dir>
<name>bar</name>
</dir>
<dir>
<name>square</name>
</dir>
</dir>
<dir>
<name>foo</name>
</dir>
<dir>
<name>bar</name>
</dir>
<dir> …Run Code Online (Sandbox Code Playgroud) 我正在使用GitPython 包从 Python 访问 Git 存储库。这会引入async 包。在 中async/__init__.py,发生以下情况:
def _init_signals():
"""Assure we shutdown our threads correctly when being interrupted"""
import signal
# ...
signal.signal(signal.SIGINT, thread_interrupt_handler)
_init_signals()
Run Code Online (Sandbox Code Playgroud)
如果一切都在主线程中,这可以正常工作。然而,当第一次导入git(和因此async) 发生在另一个线程上时,事情会变得繁荣:
ValueError: signal only works in main thread
Run Code Online (Sandbox Code Playgroud)
由于所有这些都在 Django 框架内运行,因此我无法控制线程。
我发现的一种解决方法是 put import asyncinto settings.py,它(显然)在主线程上导入。然而,这需要在每次安装的基础上完成,所以对我的 Django 应用程序的用户来说不是很好。
我尝试捕获异常,但引发异常的导入未完全完成,因此下一个import async也会失败。
你能想出任何半途而废的方法来解决这个问题吗?
更新:我注意到 Apache 的 mod_wsgi 足够聪明,可以忽略signal调用:
[Tue Sep 07 19:53:11 2010] [warn] mod_wsgi (pid=28595): Callback registration for …Run Code Online (Sandbox Code Playgroud) 以下动画应该做什么?
<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="0"
android:toDegrees="360"
android:pivotX="50%"
android:pivotY="50%"
android:interpolator="@android:anim/linear_interpolator"
android:duration="1000" />
Run Code Online (Sandbox Code Playgroud)
很容易.它应代表围绕中心的顺时针旋转.只需旋转一下,然后停下来.对?
当我将它应用于View时,它确实......
但是当我为活动转换设置动画时,会发生完全不同的事情.活动开始逆时针旋转,但同时它飞离屏幕的右上角.然后它返回,仍然逆时针旋转,现在倒置,然后飞离屏幕的左下角.最后,它回来并直立结束旋转.
不管是什么我指定pivotX和pivotY,行为始终是相同的.它们似乎完全被忽略了.无论哪种方式,事情肯定不会围绕任何固定的枢轴旋转!
这是什么废话?这是一个错误吗?
为了完整起见,我将此动画保存为res/anim/spin.xml,并按如下方式调用它:
startActivity(intent);
overridePendingTransition(R.anim.spin, R.anim.spin);
Run Code Online (Sandbox Code Playgroud)
(对于in和out使用相同的动画没有任何意义,但这是最小的例子.)
我已经整理了一个最小的Android项目来演示这个问题.主要活动如下:
package com.example.animtest;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
public class MainActivity extends Activity {
private View rootView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
rootView = getLayoutInflater().inflate(R.layout.main, null);
setContentView(rootView);
}
public void animateRootView(View view) {
Animation spin = AnimationUtils.loadAnimation(getApplicationContext(), …Run Code Online (Sandbox Code Playgroud) 我很好奇这两者之间的区别.
irb(main):001:0> require 'active_support/core_ext'
=> true
irb(main):002:0> 1.second.from_now == 1.seconds.from_now
=> false
Run Code Online (Sandbox Code Playgroud)
他们看起来和我一样
irb(main):003:0> p 1.second.from_now; p 1.seconds.from_now; nil
2013-06-14 17:50:28 +0530
2013-06-14 17:50:28 +0530
=> nil
Run Code Online (Sandbox Code Playgroud)
他们都有同一个班级
irb(main):004:0> 1.second.from_now.class == 1.seconds.from_now.class
=> true
Run Code Online (Sandbox Code Playgroud) 我想做一些事情:
SELECT some_things
FROM `myproject.mydataset.mytable_@suffix`
Run Code Online (Sandbox Code Playgroud)
但这不起作用,因为参数未在表名内展开。
这确实有效,使用通配符表:
SELECT some_things
FROM `myproject.mydataset.mytable_*`
WHERE _TABLE_SUFFIX = @suffix
Run Code Online (Sandbox Code Playgroud)
但是,它有一些问题:
If I mistype the parameter, this query silently returns zero rows, rather than yelling at me loudly.
Query caching stops working when querying with a wildcard.
If other tables exist with the mytable_ prefix, they must have the same schema, even if they don't match the suffix. Otherwise, weird stuff happens. It seems like BigQuery either computes the union of …
更新(2019-02-07):该问题现已修复,因此如果仍然遇到此问题,请尝试gcloud components update。
在过去几个月中的某个时候,我的bq工具停止工作了。即使是简单的事情也会显示此错误:
$ bq show
BigQuery error in show operation: Cannot contact server. Please try again.
Traceback: Traceback (most recent call last):
File "/opt/google-cloud-sdk/platform/bq/bigquery_client.py", line 685, in BuildApiClient
response_metadata, discovery_document = http.request(discovery_url)
File "/opt/google-cloud-sdk/platform/bq/third_party/oauth2client_4_0/transport.py", line 176, in new_request
redirections, connection_type)
File "/opt/google-cloud-sdk/platform/bq/third_party/oauth2client_4_0/transport.py", line 283, in request
connection_type=connection_type)
File "/opt/google-cloud-sdk/platform/bq/third_party/httplib2/__init__.py", line 1626, in request
(response, content) = self._request(conn, authority, uri, request_uri, method, body, headers, redirections, cachekey)
File "/opt/google-cloud-sdk/platform/bq/third_party/httplib2/__init__.py", line 1368, in _request
(response, …Run Code Online (Sandbox Code Playgroud) 在Cloud SQL for PostgreSQL定价示例中,我看到我应该能够db-f1-micro使用共享CPU和0.6 GB RAM 创建实例,价格为每月9美元。
但是,当我尝试实际创建这样的实例时,没有看到该选项。用户界面仅允许我创建一个自定义机器类型,该机器类型至少具有1个vCPU和3.75 GB RAM,每月费用为$ 51:
有趣的是,对于MySQL,我确实可以选择创建db-f1-micro实例。但是我不能在这个项目中使用MySQL。
这里的文档有误吗?还是有一个db-f1-micro使用PostgreSQL 实际创建预算实例的技巧?
我正在阅读问题The Trait `std::fmt::Write` is not Implemented for `Stdout` ,而它应该是提问者指出的地方,rust 文档显示 std::io::Write 特征是为两者实现的&Stdout和标准输出。
我不明白为什么这是必要的或者你将如何使用它。您定义的所有内容不是Thing总是为 实现吗&Thing?为什么你要实现某些东西&Thing而不实现它的定义?