客户需求:在点击录音按钮之后 需要显示计时 简单的计时器
首先 增加布局文件 资源文件中有多个layout 只要有call_card_fragment都增加
packages\apps\Dialer\InCallUI\res\layout\call_card_fragment.xml
<!-- M:fix ALPS02297097,recording icon still at the right
side as Arabic,correct layout_gravity from right to end -->
<ImageView android:id="@+id/voiceRecorderIcon"
android:layout_width="@dimen/incall_record_icon_size"
android:layout_height="@dimen/incall_record_icon_size"
android:layout_gravity="end"
android:layout_marginEnd="10dip"
android:layout_marginTop="10dip"
android:visibility="gone" />
<!--add start-->
<TextView
android:id="@+id/record_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/voiceRecorderIcon"
android:layout_centerVertical="true"
android:text="@string/roco_record_time" />
<!--end-->
然后初始化布局 加载资源
packages\apps\Dialer\InCallUI\src\com\android\incallui\CallCardFragment.java
/// M: [Voice Record]recording indication icon @{
private ImageView mVoiceRecorderIcon;
private TextView mRecordTime;//add by chch
private void initVoiceRecorderIcon(View view) {
mVoiceRecorderIcon = (ImageView) view.findViewById(R.id.voiceRecorderIcon);
mVoiceRecorderIcon.setImageResource(R.drawable.voice_record);
mRecordTime = (TextView) view.findViewById(R.id.record_time);//add by chch
mVoiceRecorderIcon.setVisibility(View.INVISIBLE);
mRecordTime.setVisibility(View.INVISIBLE);//add by chch
}
实现业务逻辑
@Override
public void updateVoiceRecordIcon(boolean show) {
mVoiceRecorderIcon.setVisibility(show ? View.VISIBLE : View.INVISIBLE);
mRecordTime.setVisibility(show ? View.VISIBLE : View.INVISIBLE);//add by chch
AnimationDrawable ad = (AnimationDrawable) mVoiceRecorderIcon.getDrawable();
if (ad != null) {
if (show && !ad.isRunning()) {
ad.start();
//add chch start
task=new TimerTask() {
@Override
public void run() {
// TODO Auto-generated method stub
Message message = new Message();
message.what = 1;
handler.sendMessage(message);
}
};
timer.schedule(task, 1000, 1000);
//add chch end
} else if (!show && ad.isRunning()) {
ad.stop();
//add chch start
timer.cancel();
i=1;
//add chch end
}
}
/// M:[RCS] plugin API @{
ExtensionManager.getRCSeCallCardExt().updateVoiceRecordIcon(show);
/// @}
}
/// @}
//add chch start
public Timer timer=new Timer();
public TimerTask task;
public int hour=1;
public int i=1;
Handler handler=new Handler(){
public void handleMessage(android.os.Message msg) {
switch (msg.what) {
case 1:
//do your thing.
String RecordTimeElapsed = DateUtils.formatElapsedTime(i);
mRecordTime.setText(RecordTimeElapsed);
i=i+1;
break;
default:
break;
}
super.handleMessage(msg);
};
};
//add chch end