向社区致以问候
我正在使用 ITEXT 库生成 PDF 报告。
'com.itextpdf:itextpdf:5.0.6'
我正在这样做
Run Code Online (Sandbox Code Playgroud)Document document = new Document();
fileName = FileName + Common.getCurrentDateTime() + ".pdf";
fileName1 = FileName + Common.getCurrentDateTime() + ".pdf";
String dest = context.getExternalFilesDir(null) + "/RTS";
File dir = new File(dest);
if (!dir.exists())
dir.mkdirs();
try {
File file = new File(dest, fileName);
file.createNewFile();
FileOutputStream fOut = new FileOutputStream(file, false);
//FileOutputStream fOut = new FileOutputStream(file);
//PdfWriter.getInstance(document, new FileOutputStream(dest));
PdfWriter.getInstance(document, fOut);
// PdfWriter.getInstance(document, fOut);
} catch (DocumentException e) {
e.printStackTrace();
Log.v("PdfError", e.toString());
// dialog.dismiss();
} …Run Code Online (Sandbox Code Playgroud) 通常设置inputType=textPassword用户可以在其中输入任何有风险的内容的字段,例如......密码。当用户键入时,他们键入的每个字符都会短暂闪烁,让用户知道实际输入的内容,然后变成星号,以便临时观察者(间谍)更难以看到键入的内容。
一般来说,这工作得很好。
我有一个特定的情况,出于安全原因,该字符不得闪烁。相反,我想简单地显示星号。
我可以通过 单独处理每个水龙头setOnKeyListener(),但这似乎应该很容易。但是我没有看到任何内置解决方案。请告诉我我错过了一些东西。
我正在使用 Silicompressor 库进行视频压缩。我的视频大小为 15 MB,压缩视频大小将达到 500 kb,因为压缩大小非常小,当单击压缩视频的播放按钮时,它会显示“无法播放视频”的错误。
如何获得以 MB 为单位的压缩大小?
这是我压缩后的代码
File imageFile = new File(compressedFilePath);
float length = imageFile.length() / 1024f; // Size in KB
System.out.println("length = " + length);
String value;
if (length >= 1024)
value = length / 1024f + " MB";
else
value = length + " KB";
Run Code Online (Sandbox Code Playgroud)
任何其他适用于视频压缩的替代库?
我正在使用 Material 组件创建 DatePicker。据我了解,colorPrimary用于确定对话框顶部部分的颜色,以及按钮上文本的颜色,特别是CANCEL和OK。
浏览文档,我似乎找不到一种方法来更改底部按钮的颜色?可以这样做吗?
当前代码:
<style name="ThemeOverlay.App.DatePicker" parent="@style/ThemeOverlay.MaterialComponents.MaterialCalendar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorOnPrimary">@android:color/white</item>
<item name="shapeAppearanceSmallComponent">@style/ShapeAppearance.App.SmallComponent</item>
<item name="shapeAppearanceMediumComponent">@style/ShapeAppearance.App.MediumComponent
</item>
<item name="materialCalendarHeaderTitle">@style/MyHeaderTitle</item>
<item name="colorOnPrimarySurface">@android:color/white</item>
</style>
<style name="MyHeaderTitle" parent="Widget.MaterialComponents.MaterialCalendar.HeaderTitle">
<item name="android:textColor">@android:color/white</item>
</style>
<style name="ThemeMaterialCalendarTextButton" parent="Widget.MaterialComponents.Button.TextButton.Dialog.Flush">
<item name="android:textColor">@android:color/white</item>
<item name="iconTint">@android:color/white</item>
</style>
<style name="ShapeAppearance.App.SmallComponent" parent="ShapeAppearance.MaterialComponents.SmallComponent">
<item name="android:textSize">24sp</item>
<item name="cornerSize">16dp</item>
</style>
<style name="ShapeAppearance.App.MediumComponent" parent="ShapeAppearance.MaterialComponents.MediumComponent">
<item name="android:textSize">30sp</item>
<item name="cornerSize">16dp</item>
</style>
Run Code Online (Sandbox Code Playgroud)
这是我的代码,我不喜欢警告。
currentFlag.inc()正在发出警告:无法访问的代码,如果(currentFlag == 1)正在发出警告:未使用的等于表达式
private fun processGather() {
TODO("process Gather implemented")
currentFlag.inc()
if (currentFlag == 1) {
this.binding.ivStep1.setImageDrawable(AppCompatResources.getDrawable(this, R.drawable.step2))
}
}
Run Code Online (Sandbox Code Playgroud) 首先,我创建了名为 UpdaterWorker 的工作类。之后,我在应用程序类中重写了 getWorkManagerConfiguration 。我创建了一个 WorkerFactory 类。
这就是我所要做的一切,还是我错过了什么?
如何创建一次性请求?
当我尝试将更新程序工作线程注入主活动时,出现此错误:Dagger 不支持注入 @AssistedInject 类型,.workmanager.UpdaterWorker。您的意思是注入其辅助工厂类型吗?
**Updater worker**
@HiltWorker
class UpdaterWorker @AssistedInject constructor(
private val api: ReservationApi,
private val updaterUrl: String,
private val prefManager: PrefManager,
@Assisted private val context: Context,
@Assisted workerParams: WorkerParameters
) : Worker(context, workerParams) {
...
}
** Worker Factory**
class WorkerFactory @Inject constructor(
private val api: ReservationApi,
@param:Named("update_url") private val updaterUrl: String,
private val prefManager: PrefManager,
) : WorkerFactory() {
override fun createWorker(
appContext: Context,
workerClassName: String,
workerParameters: WorkerParameters …Run Code Online (Sandbox Code Playgroud) 我试图让我的 TextField 仅接受使用keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Text)以下字符:
TextField(
value = query3.value,
onValueChange = { newValue ->
query3.value = newValue
},
singleLine = true,
label = {
Text(
"Bank name",
color = colorResource(id = R.color.bright_green),
fontFamily = FontFamily(Font(R.font.poppins_regular)),
fontSize = with(LocalDensity.current) { dimensionResource(id =
R.dimen._12ssp).toSp() },
)
},
interactionSource = interactionSource,
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Text),
.
.
.
Run Code Online (Sandbox Code Playgroud)
但软键盘仍然允许输入数字。如何让软键盘只允许输入字符?
android textfield android-softkeyboard android-jetpack-compose
为什么存在文件描述符模式(r、w、rw)以及它们的用途是什么?
contentResolver.openFileDescriptor(uri, "w")
Run Code Online (Sandbox Code Playgroud)
它们在文档中是这样描述的:
如果使用独占的“r”或“w”模式打开,则返回的 ParcelFileDescriptor 可以是管道或套接字对以启用数据流。以“rw”模式打开意味着磁盘上的文件支持查找。如果可能,请始终使用独占模式,为底层 ContentProvider 提供最大的灵活性。
我有一个在片段上调用的 livedata 对象。第一次工作正常,它只触发一次,但第二次我输入片段时它触发两次,不明白为什么。
这就是我所说的观察:
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
return inflater.inflate(R.layout.activity_train_with_famous_detail, container, false)
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
setupUi(view)
(activity as TrainingWithFamousActivity).hideToolbar()
setupListCategoryVideos(view)
viewModel.getVideosData()
viewModel.videosData.observe(viewLifecycleOwner, Observer {
//second time I enter the fragment it triggers his twice
videoCategoryAdapter.loadItems(it)
})
viewModel.videoSelected?.let { loadTrainWithFamousDetailsData(it) }
}
Run Code Online (Sandbox Code Playgroud)
这是我的视图模型中的方法:
val videosData = MutableLiveData<List<DtoCelebrityResource>>()
fun getVideosData() {
showLoader()
trainingWithFamousUseCase
.build(this)
.executeWithError({
videosData.value = it
hideLoader()
}, {
hideLoader()
})
}
Run Code Online (Sandbox Code Playgroud) 基本上,我创建了一个 Android 应用程序,用户在其中充值,然后 Firestore 的值更改为新值,但如果 Android 应用程序没有更改,则需要更改活动或重新启动应用程序,值已更新,但我希望更新值实时反映在 Android 应用程序中。
\n\n这是我的代码:
\nDocumentReference reference = \nFirebaseFirestore.getInstance().collection("Users").document(mobile);\n reference.get().addOnCompleteListener(new OnCompleteListener<DocumentSnapshot>() {\n @Override\n public void onComplete(@NonNull Task<DocumentSnapshot> task) {\n if (task.isSuccessful()) {\n DocumentSnapshot snapshot = task.getResult();\n if (snapshot.getString("Wallet") != null) {\n String wallet = snapshot.getString("Wallet");\n walletshow.setText(wallet); // This value was update in real time if his wallet changes to\n } else { // 100\xe2\x82\xb9 to 150\xe2\x82\xb9 the user need to relaunch or change the activity to refresh the values\n walletshow.setText("Activate your account …Run Code Online (Sandbox Code Playgroud) java android firebase google-cloud-platform google-cloud-firestore