小编Yur*_*kov的帖子

如何在PlantUML类图中对齐块?

我正在使用PlantUML来制作简单的类图,并且该工具很棒,但除了将它们放入包或使用像Alice -left-*Bob之类的关系之外,我找不到任何方法将类彼此对齐.我需要的是:

@startuml  
class Bob  
class Alice  
class Dan  
**Dan aligned Alice: horizontally**  
'or using a grid?  
**Bob at grid (2, 3)**  
@enduml
Run Code Online (Sandbox Code Playgroud)

有办法吗?

uml plantuml

25
推荐指数
6
解决办法
1万
查看次数

有没有办法在Eclipse中自动生成包装器?

我必须创建几个代理,例如添加日志记录.像这样的东西:

interface IMath {
    public int add(a, b);
}

class Math implements IMath {
    public int add(a, b) { return a + b; }
}

class MathWithLogs implements IMath {
    private IMath realMath;
    public int add(a, b) {
        Log.d("tag", "valueable info");
        return realMath.add(a, b);
    }
}
Run Code Online (Sandbox Code Playgroud)

一切都很好,只要这些接口不是20种方法,我只需要添加一些东西.

我的问题是,有没有办法用eclipse的一些插件自动生成包装类?

或者除非另有说明(比如@Override),否则有一种方法可以使用注释来调用realMath中的方法?

java wrapper

20
推荐指数
3
解决办法
5250
查看次数

为什么在使用AlarmManager.setAlarmClock()进行设置时,警报图标仅在Samsung Android 9设备上不显示?

我使用AlarmManager.setAlarmClock()设置警报。在装有Samsung 9的三星设备上,所有设备(包括三星)都将发出警报,但是时钟附近(屏幕右上角)的小警报图标丢失了。

我知道该问题也影响了Google Clock应用程序,但该问题已在最近得到解决。

我的代码:

val pendingAlarm = Intent(ACTION_FIRED)
    .apply {
        setClass(mContext, AlarmsReceiver::class.java)
        putExtra(EXTRA_ID, id)
        putExtra(EXTRA_TYPE, typeName)
     }
     .let { PendingIntent.getBroadcast(mContext, pendingAlarmRequestCode, it, PendingIntent.FLAG_UPDATE_CURRENT) }

 val pendingShowList = PendingIntent.getActivity(
     mContext,
     100500,
     Intent(mContext, AlarmsListActivity::class.java), PendingIntent.FLAG_UPDATE_CURRENT)

 am.setAlarmClock(AlarmManager.AlarmClockInfo(calendar.timeInMillis, pendingShowList), pendingAlarm)
Run Code Online (Sandbox Code Playgroud)

android alarmmanager samsung-mobile samsung-galaxy android-9.0-pie

11
推荐指数
1
解决办法
217
查看次数

如何避免 Kotlin 中的 Lateinit 字段部分覆盖

我有一个用 Kotlin 编写的 Android 服务,我使用 Guice 注入它。它有不能为空的 Lateinit 字段,但它们必须是 Lateinit 因为我不能使用构造函数注入。

围绕这些线的一些东西:

class VibrationService : Service() {
    @Inject
    private lateinit var pm: PowerManager
    private lateinit var wakeLock: WakeLock

    override fun onCreate() {
        AlarmApplication.guice().injectMembers(this)
        wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "VibrationService")
        wakeLock.acquire()
    }
}
Run Code Online (Sandbox Code Playgroud)

现在,当我创建 JaCoCo 报告时,访问任何 Lateinit 字段的所有行都被标记为部分覆盖。我认为 Kotlin 编译器对字节码添加了一些检查,以确保字段在访问之前已初始化。

有什么办法可以禁用这些检查吗?我想要 100% 的覆盖率:-)

android kotlin

8
推荐指数
1
解决办法
3157
查看次数

如何在 Java 类中继承 KDoc 文档?

我有带有 KDoc 的 Kotlin 类,例如:

abstract class Something {
  /** # Documentation */
  abstract fun someFun()
}
Run Code Online (Sandbox Code Playgroud)

这个类由 Kotlin 和 Java 类扩展。KDoc 由 Kotlin 类正确继承。在子类中的 Intellij 中单击 Ctrl+Q 时会显示 KDoc。但是,如果子类是用 Java 编写的,则它不起作用。在这种情况下,不会继承 KDoc。

如何在 Java 中继承 KDoc?

java javadoc intellij-idea kotlin kdoc

6
推荐指数
0
解决办法
157
查看次数

为什么ContentProvider在App更新后返回空游标?

我最近为我的应用程序发布了一个更新,并且我收到一些用户的反馈,称他们的数据丢失了。经过分析,我确定我使用的单个内容提供程序始终返回一个空游标。

我没有更改内容提供者本身的代码或查询它的代码。数据格式没有改变。该问题仅在少数设备上可见,并且似乎仅限于Android 6.0(主要是三星,但也包括某些LG设备)。不仅会丢失初始数据,而且所有后续插入操作也不会持久化

可以通过全新安装应用(删除+安装)解决此问题。

有谁知道如何解决/解决方法?

我认为这无关紧要,但这是代码:

Cursor cursor = contentResolver.query(Columns.contentUri(), Columns.ALARM_QUERY_COLUMNS, null, null, Columns.DEFAULT_SORT_ORDER);

List<AlarmActiveRecord> alarms = new ArrayList<AlarmActiveRecord>();
try {
    if (cursor.moveToFirst()) {
        do {
            alarms.add(factory.create(cursor));
        } while (cursor.moveToNext());
    }
} finally {
    cursor.close();
}
return alarms;
Run Code Online (Sandbox Code Playgroud)

和内容提供者:

@Override
public Cursor query(Uri url, String[] projectionIn, String selection, String[] selectionArgs, String sort) {
    SQLiteQueryBuilder qb = new SQLiteQueryBuilder();

    // Generate the body of the query
    Preconditions.checkArgument(sURLMatcher.match(url) == ALARMS, "Invalid URL %s", url);
    qb.setTables("alarms");

    SQLiteDatabase db = …
Run Code Online (Sandbox Code Playgroud)

java android android-contentprovider android-sqlite

6
推荐指数
1
解决办法
183
查看次数

如何使用 Jetpack Compose AdapterList 保留滚动位置?

我有一个带有使用 Jetpack Compose 构建的 List-Detail 流的应用程序。从详细信息视图返回到列表视图时,我想保留滚动位置

根据模型状态交换表面:

@Composable
private fun AppContent() {
    val scrollerPosition = ScrollerPosition()
    Crossfade(State.currentScreen) { screen ->
        Surface(color = MaterialTheme.colors.background) {
            when (screen) {
                is Screen.List -> ListScreen(scrollerPosition)
                is Screen.Details -> DetailsScreen(screen.transaction)
                is Screen.New -> NewScreen()
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

ListScreen 曾经有一个 VerticalScroller,我给它一个 ScrollerPosition 以在屏幕更改后保留位置。但是,此解决方案不适用于 AdapterList。

这是以前的样子:

@Composable
private fun TransactionsList(modifier: Modifier, scrollerPosition: ScrollerPosition) {
    Box(modifier = modifier.fillMaxSize().wrapContentSize(Alignment.Center)) {
        VerticalScroller(scrollerPosition = scrollerPosition) {
            AdapterList(State.transactions, itemCallback = { transaction ->
                TransactionListRow(transaction)
                ListDivider()
            })
        }
    }
} …
Run Code Online (Sandbox Code Playgroud)

android kotlin android-jetpack-compose

6
推荐指数
1
解决办法
1854
查看次数

如何使用自定义主题设置DialogPreference的样式?

在我的应用程序中,我使用Theme.Holo和Theme.Holo.Light没有任何问题.当使用Holo主题并单击DialogPreference/ListPreference时,弹出的对话框也以Holo为主题.对于Holo.Light来说也是如此.但是,当我的自定义主题(来自Holo.Light)设置了PreferencesActivity样式时,所有对话框都以Holo.Light为主题.我想我在主题中缺少某些东西.谁能帮助我?非常感谢!

这是我的主题代码:

  <?xml version="1.0" encoding="utf-8"?>

<!-- Generated with http://android-holo-colors.com -->
<resources xmlns:android="http://schemas.android.com/apk/res/android">

  <style name="GreenTheme" parent="android:Theme.Holo.Light">

    <item name="android:editTextBackground">@drawable/edit_text_holo_light</item>

    <item name="android:autoCompleteTextViewStyle">@style/AutoCompleteTextViewGreenTheme</item>

    <item name="android:listChoiceIndicatorMultiple">@drawable/btn_check_holo_light</item>

    <item name="android:listChoiceIndicatorSingle">@drawable/btn_radio_holo_light</item>

    <item name="android:buttonStyle">@style/ButtonGreenTheme</item>

    <item name="android:imageButtonStyle">@style/ImageButtonGreenTheme</item>

    <item name="android:dropDownSpinnerStyle">@style/SpinnerGreenTheme</item>

    <item name="android:tabWidgetStyle">@style/TabWidgetGreenTheme</item>

    <item name="android:progressBarStyleHorizontal">@style/ProgressBarGreenTheme</item>

    <item name="android:seekBarStyle">@style/SeekBarGreenTheme</item>

    <item name="android:buttonStyleToggle">@style/ToggleGreenTheme</item>

    <item name="android:listChoiceBackgroundIndicator">@drawable/list_selector_holo_light</item>

    <item name="android:activatedBackgroundIndicator">@drawable/activated_background_holo_light</item>

    <item name="android:fastScrollThumbDrawable">@drawable/fastscroll_thumb_holo</item>

    <item name="android:actionBarStyle">@style/ActionBar.Solid.Greenactionbar</item>

    <item name="android:buttonBarButtonStyle">@style/ButtonBarButtonStyleGreenTheme</item>

    <item name="android:preferenceStyle">@style/TimePickerDialogFragmentGreen</item>
  </style>

      <style name="TimePickerDialogFragmentGreen" parent="@android:style/Theme.Holo.Light.Dialog">
         <item name="android:editTextBackground">@drawable/edit_text_holo_light</item>

    <item name="android:autoCompleteTextViewStyle">@style/AutoCompleteTextViewGreenTheme</item>

    <item name="android:listChoiceIndicatorMultiple">@drawable/btn_check_holo_light</item>

    <item name="android:listChoiceIndicatorSingle">@drawable/btn_radio_holo_light</item>

    <item name="android:buttonStyle">@style/ButtonGreenTheme</item>

    <item name="android:imageButtonStyle">@style/ImageButtonGreenTheme</item>

    <item name="android:dropDownSpinnerStyle">@style/SpinnerGreenTheme</item>

    <item name="android:tabWidgetStyle">@style/TabWidgetGreenTheme</item>

    <item name="android:progressBarStyleHorizontal">@style/ProgressBarGreenTheme</item>

    <item name="android:seekBarStyle">@style/SeekBarGreenTheme</item>

    <item name="android:buttonStyleToggle">@style/ToggleGreenTheme</item>

    <item name="android:listChoiceBackgroundIndicator">@drawable/list_selector_holo_light</item>

    <item name="android:activatedBackgroundIndicator">@drawable/activated_background_holo_light</item>

    <item …
Run Code Online (Sandbox Code Playgroud)

android themes styles

5
推荐指数
1
解决办法
2196
查看次数

如何为Android 26+实现强大的闹钟应用程序

我将“闹钟”应用程序作为一种爱好进行维护,最近我已开始将其迁移到目标API级别26。由于后台服务的限制,我的应用程序无法再可靠运行。

当前的实现方式如下:

  1. 用户在用户界面中设置警报
  2. 使用PendingIntent.getBroadcast作为有效负载调用android.app.AlarmManager#setAlarmClock
  3. 警报触发时,BroadcastReceiver会收到警报
  4. 首先,它抓住了一个Wakelock
  5. 然后启动服务
  6. 服务处理事件并产生更多事件,例如,为音乐提供其他服务,启动活动或通知
  7. 唤醒锁被释放

使用Target SDK 25,一切都很好。使用taraget API 26,应用程序可以从Doze可靠地唤醒,但是.5点有时会失败,因为该应用程序在后台:

    AlarmsService$Receiver: java.lang.IllegalStateException: Not allowed to start service Intent { act=com.better.alarm.ACTION_FIRED flg=0x14 cmp=com.better.alarm/.model.AlarmsService (has extras) }: app is in background
Run Code Online (Sandbox Code Playgroud)

.6点中的服务可以是前台服务,我对此没有任何问题,但.5点中的服务不仅处理警报触发的事件,还处理时区更改,从通知中分派的多个用户交互意图,等等。前台服务。

Android文档建议在这种情况下使用JobScheduler,但JobScheduler不保证作业能及时执行。这种破坏闹钟的目的。

触发使用android.app.AlarmManager#setAlarmClock设置的警报时,我必须可靠地执行代码的哪些选项?

谢谢

android alarmmanager android-service android-alarms android-8.1-oreo

5
推荐指数
1
解决办法
407
查看次数

C++编译器会为每种模板类型生成代码吗?

我有两个关于C++模板的问题.让我们想象一下我编写了一个简单的List,现在我想在我的程序中使用它来存储指向不同对象类型的指针(A*,B*... ALot*).我的同事说,对于每种类型,都会生成一段专用代码,即使所有指针实际上都具有相同的大小.

如果这是真的,有人可以解释一下为什么吗?例如,在Java中,泛型与C++中的指针模板具有相同的目的.泛型仅用于预编译类型检查,并在编译之前被删除.当然,所有内容都使用相同的字节代码.

第二个问题是,还会为char和short生成专用代码(考虑到它们都具有相同的大小并且没有专门化).

如果这有任何区别,我们正在讨论嵌入式应用程序.

我发现了一个类似的问题,但它并没有完全回答我的问题:C++模板类是否重复使用每种指针类型的代码?

非常感谢!

c++ templates

2
推荐指数
2
解决办法
1379
查看次数