我正在使用以下代码来设置屏幕亮度,这在大多数手机上都可以正常工作:
protected fun setBrightness(value: Float) {
//Set the system brightness using the brightness variable value
Settings.System.putInt(contentResolver, Settings.System
.SCREEN_BRIGHTNESS, (value * 255).toInt())
//Get the current window attributes
val layoutpars = window.getAttributes()
//Set the brightness of this window
layoutpars.screenBrightness = value
//Apply attribute changes to this window
window.setAttributes(layoutpars)
}
Run Code Online (Sandbox Code Playgroud)
当我传递一个值 1 时,这意味着最大值,这被转换为 255,据说这是设置屏幕亮度的最大值。但是,在小米 Mi8 上,将值设置为 255 不会将亮度设置为全范围,如下图所示:
打印一些调试值并进行试验后,看起来在小米 Mi8 上,最大亮度值实际上是 1024(或者至少,将该值乘以 1 设置完整的亮度条)。
似乎不同的 android 设备可能有不同的亮度等级。是否有一些 API 可以获得亮度的最大值,所以我不需要对不同的常量进行硬编码?
我写了一个Nim程序,
echo("Hello.")
Run Code Online (Sandbox Code Playgroud)
然后我试着为Linux机器交叉编译,
nim c --cpu:i386 --os:linux -c hello.nim
Run Code Online (Sandbox Code Playgroud)
这产生了以下输出:
config/nim.cfg(45, 2) Hint: added path: '/Users/connor/.babel/pkgs/' [Path]
config/nim.cfg(46, 2) Hint: added path: '/Users/connor/.nimble/pkgs/' [Path]
Hint: used config file '/usr/local/lib/nim-0.10.2/config/nim.cfg' [Conf]
Hint: system [Processing]
Hint: hello [Processing]
Hint: operation successful (8753 lines compiled; 0.140 sec total; 14.148MB)[SuccessX]
Run Code Online (Sandbox Code Playgroud)
此时我更改了nimcache/目录并尝试执行:
gcc hello.c -o hello.o
Run Code Online (Sandbox Code Playgroud)
但这给了我一个错误:
hello.c:5:10: fatal error: 'nimbase.h' file not found
#include "nimbase.h"
^
1 error generated.
Run Code Online (Sandbox Code Playgroud)
我想,"没什么大不了的,我只会找到nimbase.h并放在nimcache那里的目录中",但在那之后我得到了一个新的错误,
In file included from hello.c:5:
./nimbase.h:385:28: error: 'assert_numbits' …Run Code Online (Sandbox Code Playgroud) 我想编写一个方便的扩展来从 Map 中提取值,同时解析它们。如果解析失败,函数应该返回一个默认值。这一切正常,但我想告诉 Kotlin 编译器,当默认值不为空时,结果也不会为空。我可以通过@Contract注释在 Java 中做到这一点,但它似乎在 Kotlin 中不起作用。这能做到吗?合同不适用于扩展功能吗?这是 kotlin 尝试:
import org.jetbrains.annotations.Contract
private const val TAG = "ParseExtensions"
@Contract("_, !null -> !null")
fun Map<String, String>.optLong(key: String, default: Long?): Long? {
val value = get(key)
value ?: return default
return try {
java.lang.Long.valueOf(value)
} catch (e: NumberFormatException) {
Log.e(TAG, e)
Log.d(TAG, "Couldn't convert $value to long for key $key")
default
}
}
fun test() {
val a = HashMap<String, String>()
val something: Long = a.optLong("somekey", 1)
}
Run Code Online (Sandbox Code Playgroud)
在上面的代码中, …
与此问题类似,在将项目升级到 Android Studio 3.5 后,该.idea/misc.xml文件在两个开发人员之间不断切换,一个在 mac 上,另一个在 linux 上,如下行:
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
- <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK">
+ <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="JDK" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">
Run Code Online (Sandbox Code Playgroud)
本质上,该project-jdk-name属性在值JDK或之间不断切换1.8。我查看了许多配置选项,但似乎找不到可以设置此值的位置,以避免它在两个平台上的提交之间发生更改。或者也许有一种方法可以忽略此特定行更改,同时允许更改文件的其余部分?
我正在使用自定义绘制视图实现ListView活动,并具有以下代码:
@Override
public void onDraw(Canvas canvas)
{
super.onDraw(canvas);
....
canvas.drawText(String.format("%02d: %dx%d", position, w, h),
10, 15, cached_paint);
}
Run Code Online (Sandbox Code Playgroud)
在onDraw方法中几乎没有别的东西,所以这让我很生气,为什么滚动如此糟糕.我偶然把drawText参数更改为不使用String.format,然后突然滚动了黄油丝.事实上,以下几乎是相同但表现良好:
canvas.drawText("" + position + ": " + w + "x" + h,
10, 15, cached_paint);
Run Code Online (Sandbox Code Playgroud)
我惊呆了.为什么后者比调用String.format更快?我希望对象连接产生更多的中间对象和一般的垃圾性能,但我发现完全相反.事实上,当使用String.format运行时,我从vm获得了大量的分配/释放消息.
那么为什么String.format显然可以更快(至少来自其他编程语言,其中对象创建是昂贵的)时,它是如此之慢?
在Nim项目本身的代码中,我发现一些由"magic"pragma修饰的proc错过了proc定义(例子).没有文档可以解释这个编译指示,我猜proc的定义是在其他地方并且在编译时合并.但是我仍然无法通过搜索整个项目找到定义.
我是否误解了"神奇"的实用主义?它的含义是什么?以及如何使用它?

1) 按钮后面没有表格 2) 表格已加载 3) 滚动后
如果我在 NSTableView 上放置一个按钮,我会在滚动后留下工件。有谁知道如何解决这一问题?
我目前的解决方案只是将带有表格的部分分成2个部分。下部是后台禁用的按钮。

刚开始用Nim语言编程(到目前为止我真的很喜欢).作为一个学习练习,我正在编写一个小型矩阵库.我有更多代码,但我只会展示与此问题相关的部分.
type
Matrix*[T; nrows, ncols: static[int]] = array[0 .. (nrows * ncols - 1), T]
# Get the index in the flattened array corresponding
# to row r and column c in the matrix
proc index(mat: Matrix, r, c: int): int =
result = r * mat.ncols + c
# Return the element at r, c
proc `[]`(mat: Matrix, r, c: int): Matrix.T =
result = mat[mat.index(r, c)]
# Set the element at r, c
proc `[]=`(mat: var Matrix, r, …Run Code Online (Sandbox Code Playgroud) 寻找一种使用Nim编程语言(版本0.11.2)从tar.gz存档读取文件的方法.说我有一个档案
/my/path/to/archive.tar.gz
Run Code Online (Sandbox Code Playgroud)
和该档案中的文件
my/path/to/archive/file.txt
Run Code Online (Sandbox Code Playgroud)
我的目标是能够在Nim中逐行读取文件的内容.在Python中,我可以使用tarfile模块执行此操作.在Nim中有libzip和zlib模块,但文档很少,没有示例.还有zipfiles模块,但我不确定它是否能够使用tar.gz档案.
I\'ve downloaded a fresh IntelliJ IDEA with the Kotlin multiplatform plugin and created a project using the Native application project template. This template creates a Main.kt file with the content:
fun main() {\n println("Hello, Kotlin/Native!")\n}\nRun Code Online (Sandbox Code Playgroud)\nAs well as many other gradle files referencing kotlin("multiplatform") version "1.7.20". I can build and run the project from inside IntelliJ IDEA, but I see no hello world:
我只能看到 gradle 输出和成功结果,但没有Hello Kotlin/Native! message anywhere. I\'ve tried changing the runDebugExecutableNative …
android ×4
nim-lang ×4
kotlin ×2
brightness ×1
c ×1
cocoa ×1
compilation ×1
file ×1
format ×1
gzip ×1
listview ×1
macos ×1
nstableview ×1
nullable ×1
performance ×1
string ×1
tar ×1