我有一个iOS应用程序的样式指南,它指定PT中的高度,宽度,填充,字体大小等(1x作为基础).我已经成功地将它们转换为像iPhone 5,6,6s Plus,7,iPad等各种iPhone的像素.
现在我需要为Android App使用相同的样式指南,但我无能为力如何将iOS PT转换为Android DP或像素?
有没有任何常见的方法或可以指定的东西:1x iOS的30pt转换为mdpi android的X dp(或像素)?
我搜索过但找不到这个暗示.如果有人能在这里帮助我,那就太好了.
我正在开发AlarmManager用于某些流程的应用程序。我想问一下,如果我在 Playstore 上更新我的应用程序。(更新不是新安装)注册的警报会被取消吗?也会SharedPreference重置值吗?
对于ViewModels只有编译时依赖项,我使用ViewModelProvider.Factory来自架构的组件,如下所示:
class ViewModelFactory<T : ViewModel> @Inject constructor(private val viewModel: Lazy<T>) : ViewModelProvider.Factory {
@Suppress("UNCHECKED_CAST")
override fun <T : ViewModel?> create(modelClass: Class<T>): T = viewModel.get() as T
}
Run Code Online (Sandbox Code Playgroud)
在我Activity或Fragment我得到ViewModel以下方式:
@Inject
lateinit var viewModelFactory: ViewModelFactory<ProductsViewModel>
Run Code Online (Sandbox Code Playgroud)
这工作正常,直到我ViewModel需要一个仅在运行时可用的依赖项。
场景是,我有一个列表Product,我在RecyclerView. 对于每个Product,我都有ProductViewModel。
现在,ProductViewModel需要各种依赖关系的喜欢ResourceProvider,AlertManager等这些都可以编译时,我可以Inject他们使用 constructor 或者我可以Provide他们使用Module。但是,除了上述依赖项之外,它还需要Product对象,该对象仅在运行时可用,因为我通过 API 调用获取产品列表。
我不知道如何注入仅在运行时可用的依赖项。所以我现在正在做以下事情: …
android dependency-injection assisted-inject dagger-2 android-viewmodel
我是Observable在create(). 现在在里面,我检查了一些条件并基于此,我想通知订阅者有关错误的信息。这是我创建可观察对象的方式:
public Observable<User> loginUser(String email, String password) {
return Observable.create(
emitter -> {
myAsynchronousWork.onCompleteListener(
result -> {
if(!result.isSuccess()) {
// This causes the crash.
emitter.onError(new Throwable(result.getError()));
} else {
// Process result & create User object & return it. This works as expected.
emitter.onNext(user);
emitter.onComplete();
}
}
);
}
);
}
Run Code Online (Sandbox Code Playgroud)
然后我订阅loginUser()喜欢:
loginUser("", "")
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(user -> {
Log.d("TAG", "logged in user => " + user.getUuid());
Log.d("TAG", "user name => " + …Run Code Online (Sandbox Code Playgroud) 当我发送mutable-content时,没有显示通知:1,推送有效负载既不会到达Notification服务扩展中的断点,但是如果没有显示可变内容推送,Notification内容扩展也正常工作.我没有修改Notification服务扩展中的代码,它是xcode生成的默认代码.在创建通知服务扩展时我是否遗漏了某些内容,或者可能是设备设置的问题.我几天前在同一台设备上进行了测试,通知服务扩展工作正常.
以下是我的服务扩展代码
import UserNotifications
class NotificationService: UNNotificationServiceExtension {
var contentHandler: ((UNNotificationContent) -> Void)?
var bestAttemptContent: UNMutableNotificationContent?
override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
self.contentHandler = contentHandler
bestAttemptContent = (request.content.mutableCopy() as? UNMutableNotificationContent)
if let bestAttemptContent = bestAttemptContent {
// Modify the notification content here...
bestAttemptContent.title = "\(bestAttemptContent.title) [modified]"
contentHandler(bestAttemptContent)
}
}
override func serviceExtensionTimeWillExpire() {
// Called just before the extension will be terminated by the system.
// Use this as an opportunity to deliver your …Run Code Online (Sandbox Code Playgroud) notifications apple-push-notifications ios ios10 serviceextension
我正在尝试在我的项目中添加Room,这是Java + Kotlin,但是当我尝试编译项目时,它失败并:app:kaptDebugKotlin出现以下错误:
e: java.lang.IllegalStateException: failed to analyze: java.lang.IllegalArgumentException: void cannot be converted to an Element
at org.jetbrains.kotlin.analyzer.AnalysisResult.throwIfError(AnalysisResult.kt:57)
at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.compileModules(KotlinToJVMBytecodeCompiler.kt:138)
at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:154)
at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:58)
at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.java:103)
at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.java:51)
at org.jetbrains.kotlin.cli.common.CLITool.exec(CLITool.kt:92)
at org.jetbrains.kotlin.daemon.CompileServiceImpl$compile$1$2.invoke(CompileServiceImpl.kt:386)
at org.jetbrains.kotlin.daemon.CompileServiceImpl$compile$1$2.invoke(CompileServiceImpl.kt:96)
at org.jetbrains.kotlin.daemon.CompileServiceImpl$doCompile$$inlined$ifAlive$lambda$2.invoke(CompileServiceImpl.kt:889)
at org.jetbrains.kotlin.daemon.CompileServiceImpl$doCompile$$inlined$ifAlive$lambda$2.invoke(CompileServiceImpl.kt:96)
at org.jetbrains.kotlin.daemon.common.DummyProfiler.withMeasure(PerfUtils.kt:137)
at org.jetbrains.kotlin.daemon.CompileServiceImpl.checkedCompile(CompileServiceImpl.kt:916)
at org.jetbrains.kotlin.daemon.CompileServiceImpl.doCompile(CompileServiceImpl.kt:888)
at org.jetbrains.kotlin.daemon.CompileServiceImpl.compile(CompileServiceImpl.kt:385)
at sun.reflect.GeneratedMethodAccessor88.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:346)
at sun.rmi.transport.Transport$1.run(Transport.java:200)
at sun.rmi.transport.Transport$1.run(Transport.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:196)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:568)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:826)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:683)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:682)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at …Run Code Online (Sandbox Code Playgroud) 我想在我的应用程序中每隔几秒做一些事情,为此目的,我已经实现HandlerThread并handler通过以下代码
handlerThread = new HandlerThread(getClass().getSimpleName());
handlerThread.start();
handler = new Handler(handlerThread.getLooper(), new Callback() {
@Override
public boolean handleMessage(Message msg) {
//my code here
return l.this.handleMessage(msg);
}
});
Run Code Online (Sandbox Code Playgroud)
我通过发送消息来启动此处理程序 onCreate()
我按如下方式处理消息:
private boolean handleMessage(Message msg) {
switch (msg.what) {
default:
return false;
case MY_MESSAGE:
if(handler_stop==0)
{
checkLauncher();
sendMessage(MY_MESSAGE); // I Send the message from here to make //this continuous
}
}
return true;
}
Run Code Online (Sandbox Code Playgroud)
它工作正常,但它发送的信息太快,我的意思是不断,而我希望这个消息在2或3秒后发送,简而言之,我想每2-3秒重复一次任务.
我如何在上面的代码上执行此操作?请一些帮助
这是我的代码段。
@Override
public void onDestroy() {
super.onDestroy();
disposableSingleObserver.dispose();
}
/**
* fetches json by making http calls
*/
private void fetchContacts() {
disposableSingleObserver = new DisposableSingleObserver<List<Contact>>() {
@Override
public void onSuccess(List<Contact> movies) {
//Toast.makeText(getActivity(), "Success", Toast.LENGTH_SHORT).show();
contactList.clear();
contactList.addAll(movies);
mAdapter.notifyDataSetChanged();
// Received all notes
}
@Override
public void onError(Throwable e) {
// Network error
}
};
// Fetching all movies
apiService.getContacts()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribeWith(disposableSingleObserver);
}
Run Code Online (Sandbox Code Playgroud)
我收到警告,未使用subscribeWith的结果。
解决此问题的正确方法是什么?