目前,未接電話個數也要獲取到。存在的問題就是如何在電話圖標右上角顯示未接電話個數?
電話圖標是控件MultiWaveView上的圖標,該類是系統已經定義好的。我想通過直接集成View來自定義自己的View,然後在OnDraw函數通過Canvas和paint,指定坐標來畫。但始終是沒有顯示出來。自定義view的OnDraw函數也有跑到。請指教要實現這效果,該怎樣是畫未接個數呢?效果圖:
我是在自定義的handler中調用構造函數。每10s就會handler處理。
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);
Log.i(TAG, "sTempMissedCallCount is:"+sTempMissedCallCount);
}
}
).start();
}
break;
default:
break;
}
}
}
mMissedCallView=new MissedCallView(mContext,sTempMissedCallCount);這就是我調用自定義view的地方。通過直接用坐標和canvas,paint畫,不要再在xml文件裡去寫吧。
鎖屏用到的xml文件:Keyguardscreentabunlock.xml (framework\base\core\res\res\layout)該文件中用系統自定義的波紋鎖屏
<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"
/>
效果圖:
我們只是把相機改成了撥號,就是在這撥號圖標上打算畫上未接電話數。請指教,謝謝!
這個類存放位置: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");
}
}
}
這是自定義view。只跑了 這個構造函數MissedCallView(Context context,int missedCallNum)。是在我定義的public class MissCallObserver extends ContentObserver監聽未接電話個數類中調用的。為什麼沒有跑onDraw函數?請指教。未接電話個數獲取是正確的。關鍵是顯示了。
布局使用FrameLayout,將電話圖標控件放下面,默認顯示,未接個數控件放上面,默認隱藏;
邏輯采用ContentObserver監聽電話數據庫的變化,數據變化時查詢數據庫,得到未接電話個數