我有一个Android应用程序,它有几个片段.
在其中一个片段中,有
在自定义视图(第2项)中,我需要绘制几个图形,其中一个图形与视图的大小相关联,即应该有一个带有圆边的矩形,其大小等于画布的大小减去填充.
为了做到这一点,我需要获得画布的宽度和高度.
我试过以下事情:
onSizeChanged(新宽度/高度).onLayout.onDrawmethod(canvas.getWidth()/getHeight(), View.getMeasuredWidth()/getMeasuredHeight())中获取视图的尺寸.所有三种方法都返回相同的宽度和高度,并且它们都不起作用 - 图形太窄(仅填充可用空间的约60%而不是100%)并且太高(图中的底部不可见) ).
确定RectF自定义视图的尺寸(实例)的正确方法是什么?
请注意,我在横向模式下在Nexus 7仿真器上测试此应用程序.
更新1(28.03.2013 21:42 MSK)
相应片段的XML文件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/simulation_fragment"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Simulation"
android:textAppearance="?android:attr/textAppearanceLarge" />
<co.mycompany.ccp.android.impl.simulationcanvas.SimulationCanvasView
android:id="@+id/simulation_canvas_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.8" />
<LinearLayout
android:id="@+id/simulationExecutionPanel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.1" >
<Button
android:id="@+id/restartSimulationButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/restart_simulation" />
<Button
android:id="@+id/simulationStepButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/simulation_step" />
<Button
android:id="@+id/pauseButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/pause" /> …Run Code Online (Sandbox Code Playgroud) 想象一下,我有以下课程:
public class TestClass {
public class Index<X> {
}
public class IndexData {
private final Index<?> index;
private final ReentrantReadWriteLock lock =
new ReentrantReadWriteLock();
public IndexData(final Index<?> index) {
super();
this.index = index;
}
public Index<?> getIndex() {
return index;
}
public Lock getReadLock() {
return lock.readLock();
}
public Lock getWriteLock() {
return lock.writeLock();
}
}
public void add(final InputClass input)
{
final IndexData index = getIndex(input);
final Lock lock = index.getWriteLock();
lock.lock();
try {
// Do something here, …Run Code Online (Sandbox Code Playgroud) 我有一些数据三元组,我想用某种基本的OWL本体编写.我有三胞胎喜欢:
Delhi is part of India
Run Code Online (Sandbox Code Playgroud)
要么
India is an Asian country
Run Code Online (Sandbox Code Playgroud)
请注意,我的关系类似于"is-a","part-of"或"related-to".构建本体的最简单方法是什么?任何工作示例或对示例网站的引用都将是很有帮助的!
我有一个Java的Web应用程序,它使用一些外部程序(调用命令行工具).
我想使命令行程序的路径可配置,以便我可以更改它而无需重新构建我的应用程序.
问题:
1)我应该使用哪个参数(在web.xml中可用的参数),如果它只设置一次(在部署时),之后永远不会更改?
2)如何在Java代码中访问此参数?
提前致谢
德米特里
我有一个Maven项目,DefaultViewTypeToFragmentMapperTest.java在目录中有一个测试用例/src/test/java/test/com/mycompany/myproduct/android/viewtype2fragmentmapper/.
我希望将此测试用例排除在单元测试覆盖率计算之外.为了实现这个结果,我配置了这样的插件:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>2.5.2</version>
<configuration>
<formats>
<format>html</format>
<format>xml</format>
</formats>
<instrumentation>
<excludes>
<exclude>test/co/**/*.class</exclude>
</excludes>
</instrumentation>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)
但我仍然在报道报告中看到上述类别.
如何修复它以使测试用例不出现在报告中,并且不考虑其覆盖范围(根据报告为0%)?
我有一个Spring bean定义beans.xml如下:
<context:annotation-config />
[...]
<bean id="myBackend" class="mycompany.BackendBean" scope="singleton" />
Run Code Online (Sandbox Code Playgroud)
bean内部有两个方法,必须在Web应用程序的开始和结束之前执行:
public class BackendBean implements IBackend {
private static final Logger LOGGER = LoggerFactory
.getLogger(BackendBean.class);
@PostConstruct
public void init()
{
LOGGER.debug("init");
}
@PreDestroy
public void destroy()
{
LOGGER.debug("destroy");
}
}
Run Code Online (Sandbox Code Playgroud)
当我运行server(mvn jetty:run)时,我可以init在控制台中看到该方法的输出,从中我得出结论该init方法已执行.
当我按下Ctrl-C并且Jetty开始关闭时,我看不到destroy方法的输出.
destroy当应用程序终止时,为了执行该方法,我应该更改什么?
我有一个Postgres数据库,其中包含一个包含时间戳(timeOfProcessing TIMESTAMP)的表.
我有一个Java datetime值(java.util.Date dateTime),并希望将其值存储在该时间戳字段中(没有时区).
当我使用查询时
"INSERT INTO mytable(..., timeOfCreation, ...) VALUES(..., to_timestamp(" + Long.toString(dateTime.getTime()) + "),...)"
然后读取保存的值(SELECT timeOfCreation FROM mytable),它们是不同的(resultSet.getTimestamp(...).getTime()不等于dateTime.getTime()).
如何更改insert语句以便正确存储日期时间?
我需要编写一个应用程序,每隔5分钟确定一次移动电话的当前位置(使用所有免费的可用位置提供商)并将其发送到服务器.
如果某个位置提供程序在应用程序启动时不起作用,但稍后可用,则应用程序也应处理其位置数据.
为了做到这一点,我实施了以下课程.在我的一个活动中,我创建了一个实例并调用它的startTrackingUpdates方法.locationChangeHandler处理位置数据.
public class LocationTracker implements ILocationTracker, LocationListener {
public static final long MIN_TIME_BETWEEN_UPDATES = 1000 * 60 * 5; // 5 minutes
public static final long MIN_DISTANCE_CHANGE_FOR_UPDATES = 10; // 10 meters
private ILocationManager locationManager;
private ILocationChangeHandler locationChangeHandler;
public LocationTracker(final ILocationManager aLocationManager,
final ILocationChangeHandler aLocationChangeHandler) {
this.locationManager = aLocationManager;
this.locationChangeHandler = aLocationChangeHandler;
}
public void startTrackingUpdates() {
final List<String> providers = locationManager.getAllProviders();
for (final String curProviderName : providers)
{
final ILocationProvider provider = locationManager.getLocationProvider(curProviderName); …Run Code Online (Sandbox Code Playgroud) 我想以编程方式检测何时有人将比特币发送到某个地址。这发生在我开始使用这个docker-compose.yml文件的本地测试网上。
\n本地测试网运行后,我使用以下命令创建一个新地址
\ndocker exec -it minimal-crypto-exchange_node_1 bitcoin-cli getnewaddress\nRun Code Online (Sandbox Code Playgroud)\n假设它返回2N23tWAFEtBtTgxNjBNmnwzsiPdLcNek181。
我把这个地址放入下面的Java代码中:
\nimport org.bitcoinj.core.Address;\nimport org.bitcoinj.core.Coin;\nimport org.bitcoinj.core.NetworkParameters;\nimport org.bitcoinj.core.Transaction;\nimport org.bitcoinj.wallet.Wallet;\nimport org.bitcoinj.wallet.listeners.WalletCoinsReceivedEventListener;\n\npublic class WalletObserver {\n public void init() {\n final NetworkParameters netParams = NetworkParameters.fromID(NetworkParameters.ID_REGTEST);\n\n try {\n final Wallet wallet = Wallet.createBasic(netParams);\n\n wallet.addWatchedAddress(Address.fromString(netParams, "2N23tWAFEtBtTgxNjBNmnwzsiPdLcNek181"));\n\n wallet.addCoinsReceivedEventListener(new WalletCoinsReceivedEventListener() {\n @Override\n public void onCoinsReceived(final Wallet wallet, final Transaction transaction, final Coin prevBalance, final Coin newBalance) {\n System.out.println("Heyo!");\n }\n });\n }\n catch (Exception exception) {\n exception.printStackTrace();\n }\n }\n}\nRun Code Online (Sandbox Code Playgroud)\n …