通话界面去除接听键的动画效果,增加简约的电话键button的方法

     日前主要工作是,继续跟进宇朔的智能服务终端的项目。随着项目的推进,对系统的定制越来越深入,对系统底层的GPIO再到到应用层APP,进行了一次深层次的定制。现在讲述一下对通话界面(应用层APP)进行的部分定制。

     本次任务是:通话界面去除接听键的动画效果,增加简约的电话键button

定制前的界面:

 
定制后的界面:
 
实施步骤:
1. 首先,需要将定之前的接听键动画效果去掉
在packages/apps/InCallUI/src/com/android/incallui/AnswerFragment.java文件中去掉showAnswerUi方法中的内容,屏蔽动画效果

  1. @Override
  2.      public void showAnswerUi(boolean show) {
  3.    /* mGlowpad.setVisibility(show ? View.VISIBLE : View.GONE);

  4.          Log.d(this, "Show answer UI: " + show);
  5.          if (show) {
  6.              mGlowpad.startPing();
  7.          } else {
  8.              mGlowpad.stopPing();
  9. }*/
  10. }
复制代码

2. 添加button控件的xml资源文件
在packages/apps/InCallUI/res/layout/answer_fragment.xml资源文件中添加:
  1. +    <!-- Add by LCJ for answer call 20180125 BEGIN -->
  2. +    <FrameLayout
  3. +        android:id="@+id/in_call_reject"
  4. +        android:layout_width="@dimen/end_call_floating_action_button_diameter"
  5. +        android:layout_height="@dimen/end_call_floating_action_button_diameter"
  6. +        android:background="@drawable/fab_green"
  7. +        android:layout_centerHorizontal="true"
  8. +        android:layout_marginBottom="@dimen/answer_fragment_layout_marginBottom"
  9. +        android:layout_alignParentBottom="true"
  10. +        android:visibility="gone" >
  11. +
  12. +        <ImageButton android:id="@+id/in_call_reject_button"
  13. +            android:layout_width="match_parent"
  14. +            android:layout_height="match_parent"
  15. +            android:background="@drawable/end_call_background"
  16. +            android:src="@drawable/fab_ic_call_xhdpi"
  17. +            android:scaleType="center"
  18. +            android:contentDescription="@string/onscreenEndCallText" />
  19. +    </FrameLayout>
  20. +
  21. +    <FrameLayout
  22. +        android:id="@+id/end_call_reject"
  23. +        android:layout_width="@dimen/end_call_floating_action_button_diameter"
  24. +        android:layout_height="@dimen/end_call_floating_action_button_diameter"
  25. +        android:background="@drawable/fab_red"
  26. +        android:layout_toLeftOf="@id/in_call_reject"
  27. +        android:layout_marginRight="@dimen/answer_fragment_layout_marginLeft"
  28. +        android:layout_marginBottom="@dimen/answer_fragment_layout_marginBottom"
  29. +        android:layout_alignParentBottom="true"
  30. +        android:visibility="gone" >
  31. +
  32. +        <ImageButton android:id="@+id/end_call_reject_button"
  33. +            android:layout_width="match_parent"
  34. +            android:layout_height="match_parent"
  35. +            android:background="@drawable/end_call_background"
  36. +            android:src="@drawable/fab_ic_end_call_xhdpi"
  37. +            android:scaleType="center"
  38. +            android:contentDescription="@string/onscreenEndCallText" />
  39. +   </FrameLayout>
  40. +
  41. +   <FrameLayout
  42. +        android:id="@+id/text_message_reject"
  43. +        android:layout_width="@dimen/end_call_floating_action_button_diameter"
  44. +        android:layout_height="@dimen/end_call_floating_action_button_diameter"
  45. +        android:background="@drawable/fab_blue"
  46. +        android:layout_toRightOf="@id/in_call_reject"
  47. +        android:layout_marginLeft="@dimen/answer_fragment_layout_marginLeft"
  48. +        android:layout_marginBottom="@dimen/answer_fragment_layout_marginBottom"
  49. +        android:layout_alignParentBottom="true"
  50. +        android:visibility="gone" >
  51. +
  52. +        <ImageButton android:id="@+id/text_message_reject_button"
  53. +            android:layout_width="match_parent"
  54. +            android:layout_height="match_parent"
  55. +            android:background="@drawable/end_call_background"
  56. +            android:src="@drawable/fab_ic_message_xhdpi"
  57. +            android:scaleType="center"
  58. +            android:contentDescription="@string/onscreenEndCallText" />
  59. +    </FrameLayout>
  60. +    <!-- Add by LCJ for answer call 20180125 END -->
在packages/apps/InCallUI/res/values/dimens.xml文件中设置参数,方便参数的统一修改,代码中前面的加号代表新添加的
  1. -    <dimen name="end_call_floating_action_button_diameter">72dp</dimen>
  2. +    <dimen name="end_call_floating_action_button_diameter">112dp</dimen>
  3.      <dimen name="end_call_floating_action_button_small_diameter">56dp</dimen>

  4. +    <dimen name="answer_fragment_layout_marginLeft">100dp</dimen>
  5. +    <dimen name="answer_fragment_layout_marginBottom">36dp</dimen>
  6. +
  7.      <dimen name="conference_call_manager_padding_top">64dp</dimen>
  8.      <dimen name="conference_call_manager_button_dimension">46dp</dimen>


3. 添加执行的逻辑,当有button被触发,执行相应的操作——接听、挂断、发短息
在packages/apps/InCallUI/src/com/android/incallui/AnswerFragment.java文件中添加语句,‘+’号代表新添加的

  1. import android.widget.EditText;
  2. import android.widget.ListView;
  3. import android.widget.TextView;

  4. +import android.widget.ImageButton;
  5. import com.google.common.base.Preconditions;
  6. import com.google.common.collect.Lists;

  7. +import android.telecom.VideoProfile;
  8. import java.util.ArrayList;
  9. import java.util.List;

  10.      private TextView mPromptView;

  11. +    private View mEndCall;

  12. +    private View mInCall;

  13. +    private View mTextMessage;

  14. +    private ImageButton mEndCallButton;

  15. +    private ImageButton mInCallButton;

  16. +    private ImageButton mTextMessageButton;

  17.      public AnswerFragment() {
  18.      }

  19.          mGlowpad = (GlowPadWrapper) parent.findViewById(R.id.glow_pad_view);
  20.          mPromptView = (TextView) parent.findViewById(R.id.incoming_call_prompt_view);

  21. +        mInCall = parent.findViewById(R.id.in_call_reject);
  22. +        mInCallButton = (ImageButton) parent.findViewById(R.id.in_call_reject_button);
  23. +
  24. +        mEndCall = parent.findViewById(R.id.end_call_reject);
  25. +        mEndCallButton = (ImageButton) parent.findViewById(R.id.end_call_reject_button);
  26. +
  27. +        mTextMessage = parent.findViewById(R.id.text_message_reject);
  28. +        mTextMessageButton = (ImageButton) parent.findViewById(R.id.text_message_reject_button);
  29. +
  30. +        mInCallButton.setOnClickListener(new View.OnClickListener() {
  31. +            @Override
  32. +            public void onClick(View v) {
  33. +                getPresenter().onAnswer(VideoProfile.VideoState.AUDIO_ONLY, getContext());
  34. +            }
  35. +        });
  36. +
  37. +        mEndCallButton.setOnClickListener(new View.OnClickListener() {
  38. +            @Override
  39. +            public void onClick(View v) {
  40. +                getPresenter().onDecline();
  41. +            }
  42. +        });
  43. +
  44. +        mTextMessageButton.setOnClickListener(new View.OnClickListener() {
  45. +            @Override
  46. +            public void onClick(View v) {
  47. +                getPresenter().onText();
  48. +            }
  49. +        });
  50. +
  51.          Log.d(this, "Creating view for answer fragment ", this);
  52.          Log.d(this, "Created from activity", getActivity());
  53.          mGlowpad.setAnswerListener(this);


4. button图片和图片背景的使用

   button图片使的是:packages/apps/InCallUI/res/drawable-mdpi文件下的 fab_ic_call.png(接听)、fab_ic_end_call.png(挂断)、fab_ic_message.png(短信);图片背景使用的是:packages/apps/InCallUI/res/drawable-mdpi文件下的fab_red.png、fab_green.png、fab_blue.png。

     关于图片的大小问题,button图片需要用大或者小的一点图片,则需要的图片packages/apps/InCallUI/res/drawable-mdpi文件下,并在packages/apps/InCallUI/res/layout/answer_fragment.xml文件下android:src="@drawable/fab_ic_call_xxx"指定该图片文件。button背景图片的大小,只需要修改packages/apps/InCallUI/res/values/dimens.xml中的<dimen name="end_call_floating_action_button_diameter">112dp</dimen>,比如将112dp改小为72dp,则button背景图片就会减小。
        
      至此,就完成了“通话界面去除接听键的动画效果和增加简约的电话button”。本次修改,比较费时的是在button排布和图标大小的协调上面,其他方面直接引用系统原有的内容。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值