我制作了一个应用程序,可以在屏幕锁定时显示未接来电,但我不知道如何在锁定屏幕上显示未接来电的数量。调用图像来自已经定义的
如何在图片中显示数字(例如图片中的位置2)?
编辑1:
现在我已经在应用程序中获取到正确的未接来电数量,但是它没有正常显示。
类:
然后我得到了这个:
现在我想在圆心(图片中鼠标位置)显示未接来电号码,但我不知道该如何实现。
MultiWaveView
,我已经尝试使用OnDraw
、Canvas
和paint
,绘制指定坐标,但是它没有起作用。所以有人可以帮助我吗?非常感谢。如何在图片中显示数字(例如图片中的位置2)?
编辑1:
现在我已经在应用程序中获取到正确的未接来电数量,但是它没有正常显示。
类:
framework\base\core\java\com\android\internal\widget\multiwaveview\MissedCallView.java
public class MissedCallView extends View {
private static final String TAG = "MissedCallViews";
public static final int UPDATESTART = 10;
private static final int DELAYTIME = 10000;
private int sTempMissedCallCount=-1;
Context mContext;
Canvas mCanvas;
public MissedCallView(Context context)
{
super(context);
Log.i(TAG, "MissedCallView1");
mCanvas=new Canvas();
}
public MissedCallView(Context context, AttributeSet attrs)
{
super(context, attrs);
Log.i(TAG, "MissedCallView2");
mCanvas=new Canvas();
}
public MissedCallView(Context context,int missedCallNum) {
super(context);
sTempMissedCallCount=missedCallNum;
Log.i(TAG, "MissedCallView3");
mCanvas=new Canvas();
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
if(sTempMissedCallCount>0)
{
Paint paint=new Paint(Paint.ANTIALIASFLAG);
paint.setColor(Color.RED); Log.i(TAG,"Integer.toString(sTempMissedCallCount)is:"+Integer.toString(sTempMissedCallCount)); canvas.drawText(Integer.toString(sTempMissedCallCount),40,310,paint);//50 invalidate();
Log.i(TAG, "invalidate");
}
}
这是一个自定义视图,只有 MissedCallView(Context context,int missedCallNum)
起作用,在 public class MissCallObserver extends ContentObserver
监听未接来电号码时调用。但是 onDraw 不起作用,因此应用程序无法显示我收到的号码。
编辑2:
现在我在我的自定义 handler 中每 10 秒钟调用这个函数。
private final Handler mUpdateMissCallNum = new Handler() {
@Override
public void handleMessage(Message msg) {
Log.i(TAG, "mUpdateMissCallNum");
switch (msg.what) {
case UPDATESTART:
Log.i(TAG, "UPDATESTART");
sNewMissedCallCount = getMissedCallCount(mContext);
if (sNewMissedCallCount != sTempMissedCallCount)
{
Log.i(TAG, "sNewMissedCallCount != sTempMissedCallCount");
new Thread(new Runnable()
{
public void run()
{
Log.i(TAG, "sNewMissedCallCount is:"+sNewMissedCallCount);
Log.i(TAG, "sTempMissedCallCount is:"+sTempMissedCallCount);
sTempMissedCallCount = sNewMissedCallCount;
mMissedCallView=new MissedCallView(mContext,sTempMissedCallCount);
//call my costum view here
Log.i(TAG, "sTempMissedCallCount is:"+sTempMissedCallCount);
}
}
).start();
}
break;
default:
break;
}
}
}
我使用canvas和paint进行绘制,没有使用XML文件。
然后在XML中锁定屏幕:Keyguardscreentabunlock.xml(framework\base\core\res\res\layout)。
这在系统中使用了Ripple Lock。
<com.android.internal.widget.multiwaveview.MultiWaveView
android:id="@+id/unlockwidget"
android:orientation="horizontal"
android:layoutwidth="matchparent"
android:layoutheight="matchparent"
android:layout_alignParentBottom="true"
android:targetDrawables="@array/lockscreen_targets_with_camera"
android:targetDescriptions="@array/lockscreen_target_descriptions_with_camera"
android:directionDescriptions="@array/lockscreen_direction_descriptions"
android:handleDrawable="@drawable/ic_lockscreen_handle"
android:waveDrawable="@drawable/ic_lockscreen_outerring"
android:outerRadius="@dimen/multiwaveview_target_placement_radius"
android:snapMargin="@dimen/multiwaveview_snap_margin"
android:hitRadius="@dimen/multiwaveview_hit_radius"
android:rightChevronDrawable="@drawable/ic_lockscreen_chevron_right"
android:horizontalOffset="0dip"
android:verticalOffset="60dip"
android:feedbackCount="3"
android:vibrationDuration="20"
/>
然后我得到了这个:
![enter image description here](https://istack.dev59.com/6gNh3.webp)
flag:FLAG_SHOW_WHEN_LOCKED
,我想请问一下使用步骤,如果您愿意的话。 - Amour Ring