如何使用硬件键盘在Android中获得大写锁定状态?在纯Java中,它可以被检测到
boolean isOn = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
Run Code Online (Sandbox Code Playgroud)
但这不适用于Android ...
我开发了一个 npm 包(“node_commons”),它包含在我的其他项目中,如下所示:
package.json(其他项目)
"node-commons": "git+ssh://git@stash.custom.domain.net:7999/npm/libs/node_commons.git"
Run Code Online (Sandbox Code Playgroud)
node_commons 包是用 ES6 编写的,但以后不支持此版本,因此我使用 postinstall 脚本将其与 babel 转译。
package.json (node_commons)
"postinstall": "babel src -d src"
Run Code Online (Sandbox Code Playgroud)
这工作正常。当包作为依赖项包含在我的项目中时,文件将被转换。
我的问题:当我开发 node_commons 包时,我npm install用来安装内部依赖项。但后来我不想转译它。当包作为依赖项安装时(例如在我的其他项目中),我只想转译。有没有办法做到这一点?
像这样的东西:
package.json (node_commons)
"postinstall-as-dependency": "babel src -d src"
Run Code Online (Sandbox Code Playgroud) 我想写一个单元测试.因此我需要MutableLiveData.我从一个非常基本的设置测试开始,但我无法实例化MutableLiveData对象.当我运行测试时,我总是为空.我必须嘲笑任何东西吗?有什么建议?
@RunWith(MockitoJUnitRunner.class)
public class DefaultLiveDataTest {
private static final int EXPECTED = 5;
private final MutableLiveData<Integer> underTest = new MutableLiveData<>();
@Test
public void exampleTest() {
underTest.setValue(EXPECTED); //underTest is Null
assertEquals(underTest.getValue().intValue(), EXPECTED);
}
}
java.lang.NullPointerException
at android.arch.core.executor.DefaultTaskExecutor.isMainThread(DefaultTaskExecutor.java:58)
at android.arch.core.executor.ArchTaskExecutor.isMainThread(ArchTaskExecutor.java:116)
at android.arch.lifecycle.LiveData.assertMainThread(LiveData.java:434)
at android.arch.lifecycle.LiveData.setValue(LiveData.java:279)
at android.arch.lifecycle.MutableLiveData.setValue(MutableLiveData.java:33)
at com.mypackage.DefaultLiveDataTest.test_that_live_data_has_default_value(DefaultLiveDataTest.java:22)
Run Code Online (Sandbox Code Playgroud)
的build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
defaultConfig {
applicationId 'com.mypackage.title'
minSdkVersion 16
targetSdkVersion 27
versionCode 1
versionName '1.0'
testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner'
}
testOptions {
unitTests.returnDefaultValues = true
}
dependencies {
implementation fileTree(dir: 'libs', …Run Code Online (Sandbox Code Playgroud) 我想检查我的测试是否使用特定类的参数调用函数。
class Foo:
...
Run Code Online (Sandbox Code Playgroud)
我找到了mock.ANY,但在那里我无法通过任何课程。想要的是:
test_mock.assert_called_with("expected string", ANY(spec=Foo))
Run Code Online (Sandbox Code Playgroud) 我实现了可在其中绘画的自定义视图。我想将其设置为MATCH_PARENT,以便它独立于屏幕方向填充整个屏幕。当我将方向更改为横向时,它仅占宽度的50%。
我更改了onMeasure(),但没有效果:
public class DrawScreen extends View{
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
if(context.getResources().getConfiguration().orientation==Configuration.ORIENTATION_LANDSCAPE){
setMeasuredDimension(screenWidth, screenHeight);
}else{
setMeasuredDimension(screenHeight, screenWidth);
}
}
}
public class MyService extends Service{
...
windowManager.addView(toolbox, params);
}
Run Code Online (Sandbox Code Playgroud) 我想使用交互式闪亮应用程序生成R降价页面。它工作正常,但输出在带有滚动条的很小区域中。我想摆脱滚动条,并显示不带滚动条的全宽和全高2个图形。我该如何实现?
我已经尝试过:
options(width = 800)
Run Code Online (Sandbox Code Playgroud)
---
title: "Spielercluster"
output: html_document
runtime: shiny
---
```{r,echo=FALSE}
library(ggplot2)
library(shiny)
data<-read.csv2('data.csv',header=T,sep=",")
rawData<-read.csv2('rawData.csv',header=T,sep=",")
cluster<-read.csv2('cluster.csv',header=T,sep=",")
colors<-c("green","red","black")
ui<-fluidPage(plotOutput("plot1", hover = "plot_hover"),
plotOutput("plot2", hover = "plot_hover"),
verbatimTextOutput("info")
)
server <- function(input, output) {
output$plot1 <- renderPlot({
ggplot(rawData, aes(koerpergewicht, groesse, color = factor(data$gruppe))) +
geom_point() + labs(title = paste(nlevels(factor(colors))))+geom_point(size=8)+geom_text(aes(label=position),vjust=-1.5)+scale_color_manual(name = "Gruppe",
labels = c("1 schwer", "2 leicht","3 Zwischengruppe"),
values = c(rgb(0.9725490196078431,0.4627450980392157,0.4274509803921569,1),rgb(0,0.7294117647058824,0.2196078431372549,1),rgb(0.3803921568627451,0.6117647058823529,1,1)))+ggtitle("Original")
})
output$plot2 <- renderPlot({
ggplot(rawData, aes(koerpergewicht, groesse, color = factor(cluster$x))) +
geom_point() + labs(title = paste(nlevels(factor(colors))))+geom_point(size=8)+geom_text(aes(label=position),vjust=-1.5)+scale_color_manual(name = …Run Code Online (Sandbox Code Playgroud) 我想为我的按钮使用背景。但是当我使用 png 时,它会减慢应用程序的速度。因此我想使用 xml 形状,但我不知道如何进行切角(如图所示)。

现在我有以下形状,它只是一个矩形:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/blue_semi_transparent"/>
<padding android:bottom="10dp" android:right="10dp" android:top="10dp" android:left="10dp"/>
<margin android:bottom="10dp" android:right="10dp" android:top="10dp" android:left="10dp"/>
</shape>
Run Code Online (Sandbox Code Playgroud)
如何绘制右下角?
我想在单独的线程中运行一个方法。因此我尝试使用@Async但它不起作用。打印输出始终引用相同的线程 ID。
我的应用程序.java
@SpringBootApplication
@EnableAsync
@EnableConfigurationProperties(ConfigProperties.class)
public class MyApp {
public static void main(String[] args) throws Exception {
SpringApplication.run(MyApp.class, args);
}
@Bean("threadPoolTaskExecutor")
public TaskExecutor getAsyncExecutor() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setCorePoolSize(20);
executor.setMaxPoolSize(1000);
executor.setWaitForTasksToCompleteOnShutdown(true);
executor.setThreadNamePrefix("Async-");
return executor;
}
}
Run Code Online (Sandbox Code Playgroud)
MyService.java
@Slf4j
@Service
public class MyService implements ISichtServiceBroker {
@Inject
public MyService(Helper helper) {
this.helper = helper;
}
@Transactional
public void handle(Message message) {
System.out.println("Execute method synchronously - " + Thread.currentThread().getName());
handleAsync(message);
}
@Async("threadPoolTaskExecutor")
public void handleAsync(Message message) {
System.out.println("Execute method …Run Code Online (Sandbox Code Playgroud) android ×4
asynchronous ×1
babeljs ×1
capslock ×1
custom-view ×1
knitr ×1
mocking ×1
npm ×1
npm-scripts ×1
onmeasure ×1
python ×1
r ×1
r-markdown ×1
shape ×1
shiny ×1
skew ×1
spring-boot ×1