我想尝试使用EGTS协议编写一个数据接收服务。
我将从 GLONASS 导航装置接收数据。
我还没有真正的设备。
请告诉我在哪里可以获取/生成测试数据?
如您所知,List.of
它Java
返回一个不可变的列表。这不是来自 a 的糟糕语言设计吗Liskov Substitution Principle
?
维基百科的定义:
如果 S 是 T 的子类型,则程序中类型 T 的对象可以用类型 S 的对象替换,而无需对该程序所需的属性进行任何更改。
毕竟,如果有某种方法:
void addElement(List<String> list){
list.add("Liskov");
}
那么如果将通过创建的 List 传递给该方法,则会抛出异常List.of
,这与方法相矛盾LSP
。当然,尽管整件事solid
只是一组建议。
如果你认为Kotlin
,那么在我看来,就语言设计而言,他们做得更正确。我们创建了集合List
(不可变)和MutableList
.
还是我还是有误解LSP
?
如果有的话,请告诉我一个用于在地图上显示交通拥堵的免费 API。我想在一个封闭的 Android 商业移动应用程序中使用它。我知道我想要很多,但如果 :) 虽然我自己找不到。
我正在尝试在 Android webview 上实现一个 web 应用程序。尝试从这个 Web 应用程序通过手机扫描 NFC 标签时出现问题。使用以下文本引发错误:“错误,扫描无法启动。NotAllowedError:NFC 权限请求被拒绝。” 在 Web 视图中。确保应用程序具有所需的权限。
在清单中,写入了必要权限的请求:
<uses-permission android:name="android.permission.NFC" />
在此页面上测试,它可以从浏览器 https://nu-book.github.io/test-form-generator/mod-nfc.html
如果可能,请告诉我如何为 WebView 转移对 NFC 的访问。
Android 应用程序有一个任务是侦听 websocket,但它不会在打盹模式下执行此操作。看起来 Android WorkManager 用它的 PeriodicWorkRequest 解决了这个问题。每 15 分钟一次,肯定会为应用程序提供一个检查更新的窗口。
但是 WhatsApp 和 Telegram 应用程序清楚地传递消息,即使不是即时的,也是非常快速的,并且打盹模式对它们来说不是障碍。该文档指出,即使设备处于打盹模式,来自 Firebase 的消息也会立即传递。有谁知道他们是如何实现的?通过 Firebase 或其他工具(请提供姓名)?
以我的一点经验与 Firebase 混在一起有点糊涂,尤其是在阅读了一篇关于初创公司如何以 72,000 美元的价格疯狂使用 Firebase 的文章之后。
在没有第三方库的情况下,我找不到在 Java 中使用 Fragment for Android 实现 MVP 模式的示例。也许有人弄错了?我以 Presenter 的形式想象它,它命令 Activity - 要加载哪个片段。
我尝试处理此存储库中的示例,但在我看来它并不存在: https ://github.com/android/architecture-samples
我不明白为什么会这样?那么为什么不直接使用 Activity,因为使用 Fragment 没有任何好处。这几乎不是错误的架构示例,它似乎是 Google 员工的存储库。
需要更有经验的开发人员的帮助。我在 android 中使用滚动的 Fragment 模板有问题。您不能以横向屏幕格式将屏幕滚动到最后。位于最底部的部分信息不显示。问题似乎是片段占用的空间超过了它可以在屏幕上显示的空间。我不明白我哪里出错了。请告诉我。
fragment_main.xml 标记
<?xml version="1.0" encoding="utf-8"?>
<ScrollView android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:fillViewport="true">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:context=".MainFragment">
<TextView
android:id="@+id/text_view_location"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:gravity="center"
android:textSize="36sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/text_view_date"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:gravity="center"
android:textSize="18sp"
app:layout_constraintBottom_toTopOf="@+id/weather_icon"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/text_view_location" />
<ImageView
android:id="@+id/weather_icon"
android:layout_width="240dp"
android:layout_height="240dp"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:adjustViewBounds="true"
android:contentDescription="@string/weatherIcon"
android:scaleType="fitStart"
app:layout_constraintBottom_toTopOf="@+id/temperature_view_text"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/text_view_date" />
<TextView
android:id="@+id/temperature_view_text"
style="@style/Widget.AppCompat.TextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:text="@string/temp_temperature"
android:textSize="48sp"
app:layout_constraintBottom_toTopOf="@+id/text_view_description"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/weather_icon" />
<TextView
android:id="@+id/text_view_description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:gravity="center"
android:textSize="36sp"
app:layout_constraintBottom_toTopOf="@+id/tableRow"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/temperature_view_text" />
<TableRow
android:id="@+id/tableRow"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/text_view_description">
<ImageView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:contentDescription="@string/feels_like"
android:src="@drawable/ic_scarf" />
<TextView
android:id="@+id/text_view_feels_like"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="start"
android:textSize="24sp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:contentDescription="@string/myWind"
android:src="@drawable/ic_wind" />
<TextView
android:id="@+id/text_view_wind_speed"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="start"
android:textSize="24sp" />
</TableRow>
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>
嵌入此 Fragment 的主要活动的横向布局标记。
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<include
android:id="@+id/include"
layout="@layout/app_bar_main"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="0dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/include">
<androidx.fragment.app.FragmentContainerView
android:id="@+id/frag_cont_view_second"
android:name="ru.skillsnet.falchio.SecondFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
tools:layout="@layout/fragment_second" />
<androidx.fragment.app.FragmentContainerView
android:id="@+id/frag_cont_view_main"
android:name="ru.skillsnet.falchio.MainFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
tools:layout="@layout/fragment_main" />
</TableRow>
</androidx.constraintlayout.widget.ConstraintLayout>