在我的项目中,我得到了json格式的API响应.我得到一个UTC时间格式的字符串值,如下所示Jul 16, 2013 12:08:59 AM
.
我需要将其更改为本地时间.这就是我们使用此应用程序需要显示当地时间的地方.我该怎么做?
这是我尝试过的一些代码:
String aDate = getValue("dateTime", aEventJson);
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("MMM dd, yyyy HH:mm:ss z");
simpleDateFormat.setTimeZone(TimeZone.getDefault());
String formattedDate = simpleDateFormat.format(aDate);
Run Code Online (Sandbox Code Playgroud)
假设aDate包含 Jul 16, 2013 12:08:59 AM
我发现了一段我不理解的代码.
我正在JSONArray
变成一个List
.
Kotlin提供了mapTo
它的功能stdlib
(链接)
mapTo
Run Code Online (Sandbox Code Playgroud)inline fun <T, R, C : MutableCollection<in R>> Iterable<T>.mapTo( destination: C, transform: (T) -> R ): C (source)
将给定的转换函数应用于原始集合的每个元素,并将结果附加到给定目标.
这个函数有2个参数,可以像这样使用(如预期的那样):
(0..jsonArray.length() - 1).mapTo(targetList, {it -> jsonArray[it].toString()})
Run Code Online (Sandbox Code Playgroud)
但显然这也是有效的语法(不是预期的):
(0..jsonArray.length()-1).mapTo(targetList) {it -> jsonArray[it].toString()}
Run Code Online (Sandbox Code Playgroud)
如您所见,函数参数结束后outputList
,lambda表达式只是放在函数调用的末尾.
此外,这是合法的(如预期):
val transformation = {it : Int -> jsonArray[it].toString()}
(0..jsonArray.length()-1).mapTo(targetList, transformation)
Run Code Online (Sandbox Code Playgroud)
但这不是(???):
val transformation = {it : Int -> jsonArray[it].toString()}
(0..jsonArray.length()-1).mapTo(targetList) transformation
Run Code Online (Sandbox Code Playgroud) 我最近在Android Gradle插件中发现了属性testOptions.animationsDisabled.
我希望这将有助于与咖啡执行UI测试时禁用我的设备上的动画,但它不是,即我还是要手动禁用动画或使用一个的几个 选项可用.否则一些UI测试变得不稳定.
由于这个属性的描述相当短,有没有人知道它的用途是什么意思?
我的gradle文件如下:
apply plugin: 'com.android.application'
android {
testOptions {
animationsDisabled = true
}
}
Run Code Online (Sandbox Code Playgroud)
谢谢.
android android-testing android-gradle-plugin android-espresso
我有这样的java代码
mDataManager.getObservable("hello").subscribe( subscriber );
Run Code Online (Sandbox Code Playgroud)
我想要verify
以下Observable.subscribe()
我试图模仿getObservable()
和verify
Observable<Response> res = mock(Observable.class);
when(mDataManager.getObservable("hello")).thenReturn(res);
verify(res).subscribe();
Run Code Online (Sandbox Code Playgroud)
但是有一个错误
Caused by: java.lang.IllegalStateException: onSubscribe function can not be null.
at rx.Observable.subscribe(Observable.java:8167)
at rx.Observable.subscribe(Observable.java:8158)
at rx.Observable.subscribe(Observable.java:7962)
....
Caused by: rx.exceptions.OnErrorThrowable$OnNextValue: OnError while emitting onNext value: omni.neo.hk.omniapiservice.v4.model.external.UserLoginBean.class
at rx.exceptions.OnErrorThrowable.addValueAsLastCause(OnErrorThrowable.java:109)
at rx.exceptions.Exceptions.throwOrReport(Exceptions.java:187)
at rx.internal.operators.OperatorDoOnEach$1.onNext(OperatorDoOnEach.java:82)
... 48 more
Run Code Online (Sandbox Code Playgroud)
我认为mock
这里不可能是一个Observable,但是如果没有一个模拟的Observable我就做不到verify(res).subscribe()
在这种情况下的任何建议?
我无法在Android Studio中打开现有的密钥库文件或使用jarsigner
命令行中的命令行.
在这两种情况下,错误消息是:
java.security.cert.CertificateException:无法初始化,java.io.IOException:DerInputStream.getLength():找到冗余长度字节
显然这是一个应该用JDK8_131解决的问题,但对我不起作用.(我们都在使用OSX)
我也在travis上得到了同样的错误.(参见下面的"更新"部分.)
我发现另一个SO问题(签署Android应用程序抛出IOException:发现冗余长度字节)他们将.pkc12
文件转换为.keystore
但我们已经在使用.keystore
我发现构建也开始在travis上失败,因为他们正在将构建版本移动到新的发行版trusty
,下载最新的JDK,而precise
默认使用JDK7.添加dist: precise
到.travis.yml
文件的顶部现在可以工作,但这绝对不是永久的解决方案.
我们是否只希望JDK更新能解决问题,还是有办法从密钥库中删除冗余长度字节?
我想构建一个Repository
返回a 的类Single<Something>
.
该类应首先查看Cache
返回的内容Maybe<Something>
,如果Maybe
完成后Service
返回到我返回的内容Single<Something>
interface Cache {
fun getSomething(): Maybe<Something>
}
interface Service {
fun getSomething(): Single<Something>
}
class Repository (
private val cache: Cache,
private val service: Service
) {
fun getSomething(): Single<Something> {
return cache.getSomething()
.????(feed.getSomething()) //onCompleteTransformToSingle() or similar
}
}
Run Code Online (Sandbox Code Playgroud)
我已经搜索了JavaDoc,但似乎并不存在这种情况的变换器.
有一个很好的处理方式吗?
如果您有大量数据,使用嵌套关系或PrimaryKeyRelated字段会更好吗?
我有一个关系很深的模特.
为简单起见,我没有添加colums.
模型:
用例:
题:
我想跟踪每个锻炼计划>锻炼>锻炼的进展情况.因此,随着时间的推移,用户可能已完成了数十次锻炼,因此如果数据库中已有数百套,则数百次.
如果我现在使用嵌套的关系,我可能会加载很多我不需要的数据.但是如果我使用PrimaryKeyRelatedFields,我必须分别加载我需要的所有数据,这意味着我的前端会有更多的努力.
在这种情况下哪种方法更受欢迎?
编辑:
如果我使用PrimaryKeyRelatedFields,我如何区分是否例如Workoutplan中的Workouts是带有主键的数组还是带有加载对象的数组?
我使用官方指南创建了一个全屏对话框
问题是,我的工具栏与状态栏重叠,我无法弄清楚如何解决这个问题.
DialogFragment
public class CreateAccountDialogFragment extends BaseDialogFragment {
@Inject
CreateAccountViewModel viewModel;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
//InjectDependencies....
View rootView = createDataBinding(inflater, container);
createToolbar(rootView);
return rootView;
}
private View createDataBinding(LayoutInflater inflater, ViewGroup container) {
CreateAccountDialogFragmentBinding binding =
DataBindingUtil.inflate(inflater, R.layout.create_account_dialog_fragment, container, false);
binding.setViewModel(viewModel);
return binding.getRoot();
}
private void createToolbar(View rootView) {
Toolbar toolbar = (Toolbar) rootView.findViewById(R.id.toolbar);
// Set an OnMenuItemClickListener to handle menu item clicks
toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) { …
Run Code Online (Sandbox Code Playgroud) 我尝试监控CloudService的内存使用情况,并偶然发现了Application Insights.
当我尝试添加它时,我收到以下错误消息:
我们正在使用VS2015和Windows 10
编辑:
有趣的是我可以Microsoft.ApplicationInsights.Web
通过nuget-console 安装2.0.0版.但是当我之后尝试再次添加ApplicationInsights时,它会抛出相同的错误,并显示package-manager-console:
\ Path\To\Project\packages\Microsoft.Bcl.1.0.14中的程序包无法卸载.重新启动Visual Studio以完成该过程.
我尝试创建一个方法,返回我的屏幕方向依赖于设备是手持设备或平板电脑.
public int getScreenOrientation(boolean isTablet){
if(isTablet){
return ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
} else {
return ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
}
}
Run Code Online (Sandbox Code Playgroud)
但是当我使用时,setRequestedOrientation(getScreenOrientation));
我得到一个lint-error Must be one of: ActivityInfo.SCREEN_ORIENTATION_.........
,我可以抑制它,但这看起来不像干净的代码.
所以我发现,它getRequestedOrientation
使用@ActivityInfo.ScreenOrientation
Annotation.所以我试着自己使用它:
@ActivityInfo.ScreenOrientation
public int getScreenOrientation(boolean isTablet){
.
.
.
}
Run Code Online (Sandbox Code Playgroud)
但IDE给出了一个错误,指出@ActivityInfo.ScreenOrientation
无法找到Annotation .但它在官方-android-source中被公开.