我已将Robolectric添加到Android项目中.我在19.0.1中使用带有Build Tools的Android Studio.
我可以运行测试:
$./gradlew test
Run Code Online (Sandbox Code Playgroud)
哪个执行得好.
如果我尝试:
$ gradle installDebug
Run Code Online (Sandbox Code Playgroud)
它也执行得很好:
$ ./gradlew installDebug
WARNING: Dependency commons-logging:commons-logging:1.1.1 is ignored for debugTest as it may be conflicting with the internal version provided by Android.
In case of problem, please repackage it with jarjar to change the class packages
WARNING: Dependency org.apache.httpcomponents:httpclient:4.0.3 is ignored for debugTest as it may be conflicting with the internal version provided by Android.
In case of problem, please repackage it with jarjar to change the class …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用新的Android数据绑定库绑定自定义视图上的事件,但遇到了问题.
这是我的自定义视图的相关部分:
public class SuperCustomView extends FrameLayout {
private OnToggleListener mToggleListener;
public interface OnToggleListener {
void onToggle(boolean switchPosition);
}
public void setOnToggleListener(OnToggleListener listener) {
mToggleListener = listener;
}
.../...
}
Run Code Online (Sandbox Code Playgroud)
我正在尝试使用此自定义视图并onToggle使用以下内容绑定事件:
<data>
<variable
name="controller"
type="com.xxx.BlopController"/>
</data>
<com.company.views.SuperCustomView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:onToggle="@{controller.toggleStrokeLimitation}"
app:custom_title="Blah"
app:custom_summary="Bloh"
app:custom_widget="toggle"/>
Run Code Online (Sandbox Code Playgroud)
toggleStrokeLimitation控制器上的方法在哪里:
public void toggleStrokeLimitation(boolean switchPosition) {
maxStrokeEnabled.set(switchPosition);
}
Run Code Online (Sandbox Code Playgroud)
编译时出现此错误:
> java.lang.RuntimeException: Found data binding errors.
****/ data binding error ****msg:Cannot find the setter for attribute 'app:onToggle' with parameter type java.lang.Object. file:/path/to/androidapp/app/src/main/res/layout/fragment_stroke.xml loc:36:35 - 36:67 …Run Code Online (Sandbox Code Playgroud) 我正在尝试将音频文件与视频文件合并.我有两个选择:
有一个非常小的视频文件(例如,10秒),当音频文件没有结束时循环.
有一个很长的视频文件(比我的任何音频文件都长),我可以附加音频文件.我想在音频结束时剪切视频.
我使用后者和ffmpeg的-t选项.这意味着我必须获取音频文件的持续时间才能将其输入ffmpeg.有可能避免这一步吗?
第一个解决方案的任何指针?
我正在使用以下内容缓存索引操作:
caches_action :index, :cache_path => Proc.new { |c| c.params }
expire_action :action => :index
Run Code Online (Sandbox Code Playgroud)
expire_action似乎只在没有任何参数的情况下使索引操作失效.如何使与索引相关的所有caches_action失效?
(这是一个Rails 2.3.5应用程序)
我使用的是AVCaptureSession具有AVCaptureVideoPreviewLayer与AVLayerVideoGravityResizeAspectFill重力.
self.captureSession =[[AVCaptureSession alloc] init];
captureSession.sessionPreset = AVCaptureSessionPresetPhoto;
self.previewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:self.captureSession];
[self.previewLayer setVideoGravity: AVLayerVideoGravityResizeAspectFill];
Run Code Online (Sandbox Code Playgroud)
如何知道如何调整视频大小以适应预览区域AVLayerVideoGravityResizeAspectFill?在预览区域中可以看到图像的哪个部分?
来自doc:
AVLayerVideoGravityResizeAspectFill:这会保留纵横比,但会填充可用的屏幕区域,必要时裁剪视频
基本上,如何准确获取previewLayer中显示的内容?
我正在尝试在运行时重置TextView的TextColor.我想将TextView的默认颜色作为a @ColorInt.我相信当前的主题知道这一点.
这是我试过的:
public @ColorInt int getDefaultThemeColor(int attribute) {
TypedArray themeArray = mContext.getTheme().obtainStyledAttributes(new int[] {attribute});
try {
int index = 0;
int defaultColourValue = 0;
return themeArray.getColor(index, defaultColourValue);
}
finally {
themeArray.recycle();
}
}
Run Code Online (Sandbox Code Playgroud)
其中属性是:
android.R.attr.textColorandroid.R.attr.textColorPrimaryandroid.R.attr.textColorSecondary他们都没有努力找回正确的颜色.我还尝试用以下方法替换方法的第一行:
TypedArray themeArray = mContext.getTheme().obtainStyledAttributes(R.style.AppTheme, new int[] {attribute});
Run Code Online (Sandbox Code Playgroud)
我不想要肮脏的解决方案:
任何提示?
我有以下代码:
let fetcher = DiagnosticFetcher(commandSender: sender)
fetcher.fetch()
.observeOn(MainScheduler.instance)
.subscribe(
onNext: { self.store.save(content: $0) },
onError: { self.view.showError("Error") },
onCompleted: { log.verbose("Diagnostic fetched") })
Run Code Online (Sandbox Code Playgroud)
它不会编译:Extra argument 'onError' in call。如果使用onSuccess或onDoesNotExistButShowTheBug代替,则会出现相同的错误onNext。
该fetch()方法返回一个Observable<String>(其最后一个运算符为reduce)。subscribe()通话似乎只需要一个lambda:
fetcher.fetch()
.observeOn(MainScheduler.instance)
.subscribe(onNext: { self.store.save(content: $0) })
Run Code Online (Sandbox Code Playgroud)
结果:Extraneous argument label 'onNext:' in call。和:
fetcher.fetch()
.observeOn(MainScheduler.instance)
.subscribe({ self.store.save(content: $0) })
Run Code Online (Sandbox Code Playgroud)
编译良好。
我觉得我得到了错误的subscribe()实现。我想要那个:
public func subscribe(onNext: ((ElementType) -> Void)? = nil,
onError: ((Swift.Error) …Run Code Online (Sandbox Code Playgroud) 我有一个包含在不同 android 应用程序中的内部库。这个库依赖于 ICU4J。这意味着我们向最终 APK 添加了约 10MB。
lib 使用 ICU4J 的一个子集,所以我想删除所有不必要的数据文件。
从ICU文档:
目前 ICU4J 没有提供任何工具来揭示数据文件之间的这些依赖关系,因此直接在 ICU4J 项目中修剪数据是一件难事。删除数据时的关键点是确保也删除对该数据的所有依赖项。
我想在构建应用程序时删除数据文件。
StackOverflow 上的一个问题是相关的:Exclude specific resources from a aar dep。不幸的是,该exploded-aar目录不再存在。
您知道我可以在哪一步从 ICU4J 依赖项中删除文件吗?这是我尝试删除cjdict.dict文件的内容:
tasks.create("excludeTask") << {
["java/com/ibm/icu/impl/data/icudt60b/brkitr/cjdict.dict"]
.collect { "${getGroup()}/${getName()}/${getVersion()}/${it}"}
.each {
// Question 2. From which dir should I remove the files?
File file = file("${buildDir}/intermediates/exploded-aar/${it}")
println("Excluding file " + file)
if (file.exists()) {
file.delete();
}
}
}
tasks.whenTaskAdded({
// Question 1. Before which task …Run Code Online (Sandbox Code Playgroud) 我在 Kotlin 中有以下课程:
class Example {
val name: String
val lazyVar: String by lazy {
name + " something else"
}
init {
name = "StackOverflow"
}
}
Run Code Online (Sandbox Code Playgroud)
当我name在惰性初始化块中使用时出现以下错误lazyVar(即使name在init块中初始化):
变量 'name' 必须被初始化
一个解决方案是在另一种方法中初始化变量:
class Example {
val name: String
val lazyVar: String by lazy {
initLazyVar()
}
init {
name = "StackOverflow"
}
private fun initLazyVar(): String {
return name + " something else"
}
}
Run Code Online (Sandbox Code Playgroud)
这种技术有效,但有没有办法保持内联惰性块的兼容性而不是依赖外部函数?
是否可以使用GraphAPI和我的应用程序令牌访问页面的完整提要并从应用程序发布消息?
但是,在使用我的用户令牌时,我可以完全访问此页面.
我正在使用Koala(在Ruby中).这是我正在使用的片段:
oauth = Koala::Facebook::OAuth.new(FACEBOOK_APP_ID, FACEBOOK_APP_SECRET)
token = oauth.get_app_access_token
graph = Koala::Facebook::GraphAPI.new(token)
pp graph.get_connections(ENTRY_ID, "comments")
Run Code Online (Sandbox Code Playgroud)
有了这个,我没有得到关于ENTRY_ID的所有评论.