【Dialer】android6.0拨号界面分析<一>

来源:互联网 发布:北京网络问政平台官网 编辑:程序博客网 时间:2024/05/21 06:55

题记

工作需要,最近对拨号模块进行研究,下文主要介绍Android6.0下拨号应用主界面。

Dialer代码目录

Dialer上层代码主要有以下部分组成:

  • /packages/apps/Dialer/ –拨号应用主入口
  • /packages/apps/ContactsCommon –与Contacts共用的代码
  • /packages/apps/PhoneCommon
  • /packages/apps/InCallUI –通话界面

Dialer主界面

下面我们就对Dialer主界面进行分析,界面如下图:

由Dialer应用的AndroidManifest文件得知,Dialer的主activity为DialtactsActivity:

<activity android:name=".DialtactsActivity"            android:label="@string/launcherActivityLabel"            android:theme="@style/DialtactsActivityTheme"            android:launchMode="singleTask"            android:clearTaskOnLaunch="true"            android:icon="@mipmap/ic_launcher_phone"                                     android:windowSoftInputMode="stateAlwaysHidden|adjustNothing"            android:screenOrientation="portrait">            <intent-filter>                <action android:name="android.intent.action.MAIN" />                <category android:name="android.intent.category.DEFAULT" />                <category android:name="android.intent.category.LAUNCHER" />                <category android:name="android.intent.category.BROWSABLE" />            </intent-filter>            ... ...        </activity>

那么我们就开始分析DialtactsActivity.java;
首先查看onCreate函数,该函数对界面完成初始化:
1. 主界面布局

setContentView(R.layout.dialtacts_activity);
  1. 初始化actionBar 主界面最上方
    onCreate中代码如下,该处只列出初始化过程,不对actionbar的功能进行叙述。
        //获取ActionBar        final ActionBar actionBar = getActionBar();        //设置ActionBar的布局        actionBar.setCustomView(R.layout.search_edittext);        actionBar.setDisplayShowCustomEnabled(true);        actionBar.setBackgroundDrawable(null);
  1. 加载视图
    由于dialtacts_activity.xml中只是空布局,onCreate中进行布局的加载,添加相应的fragment;
            getFragmentManager().beginTransaction()                    .add(R.id.dialtacts_frame, new ListsFragment(), TAG_FAVORITES_FRAGMENT)                    .add(R.id.dialtacts_container, new DialpadFragment(), TAG_DIALPAD_FRAGMENT)                    .commit();

此时onCreate就完成了,布局的加载;乍一看然而并没有对下面的ViewPagerTabs和mViewPager(也就是拨号的快速拨号、通话记录、联系人页面)进行初始化。
仔细跟踪代码,可以发现这些界面是在ListsFragment()中进行初始化的,下面来进行介绍。

(快速拨号、通话记录、联系人页面)主要布局初始化

下面主要分析ListFragment(/DialtactsActivity/src/com/android/dialer/list/ListsFragment.java);
Fragment的学习可参照我之前的一篇博客:

http://blog.csdn.net/uestcyms/article/details/50472352
直接查看onCreateView()的实现:

整体fragment的布局:

final View parentView = inflater.inflate(R.layout.lists_fragment, container, false);

布局文件内容如下:

<FrameLayout    xmlns:android="http://schemas.android.com/apk/res/android"    android:id="@+id/lists_frame"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:animateLayoutChanges="true" >    <LinearLayout        android:layout_width="match_parent"        android:layout_height="match_parent"        android:orientation="vertical">        <!-- TODO: Apply background color to ActionBar instead of a FrameLayout. For now, this is             the easiest way to preserve correct pane scrolling and searchbar collapse/expand             behaviors. -->        <FrameLayout            android:layout_width="match_parent"            android:layout_height="@dimen/action_bar_height_large"            android:background="@color/actionbar_background_color"            android:elevation="@dimen/tab_elevation" />        <com.android.contacts.common.list.ViewPagerTabs            android:id="@+id/lists_pager_header"            android:layout_width="match_parent"            android:layout_height="@dimen/tab_height"            android:textAllCaps="true"            android:orientation="horizontal"            android:layout_gravity="top"            android:elevation="@dimen/tab_elevation"            style="@style/DialtactsActionBarTabTextStyle" />        <android.support.v4.view.ViewPager            android:id="@+id/lists_pager"            android:layout_width="match_parent"            android:layout_height="0dp"            android:layout_weight="1" />    </LinearLayout>    <com.android.dialer.list.RemoveView        android:id="@+id/remove_view"        android:layout_width="match_parent"        android:layout_height="@dimen/tab_height"        android:layout_marginTop="@dimen/action_bar_height_large"        android:layout_alignParentTop="true" >        <LinearLayout            android:id="@+id/remove_view_content"            android:layout_height="match_parent"            android:layout_width="match_parent"            android:background="@color/actionbar_background_color"            android:gravity="center"            android:orientation="horizontal"            android:visibility="gone" >            <ImageView                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:layout_marginTop="8dp"                android:layout_marginBottom="8dp"                android:id="@+id/remove_view_icon"                android:src="@drawable/ic_remove"                android:contentDescription="@string/remove_contact"                android:tint="@color/remove_text_color" />            <TextView                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:id="@+id/remove_view_text"                android:textSize="@dimen/remove_text_size"                android:textColor="@color/remove_text_color"                android:text="@string/remove_contact" />        </LinearLayout>    </com.android.dialer.list.RemoveView ></FrameLayout>

此处的com.android.contacts.common.list.ViewPagerTabs即为图中ViewPagerTabs;android.support.v4.view.ViewPager为图中的mViewPager;
通过ViewPagerTabs、ViewPager、ViewPagerAdapter三者之间的交互完成主要布局的初始化;代码如下,下章进行介绍分析三者之间的交互;

ViewPager、Adapter、fragment的使用,可参照如下帖子进行学习,非常的详细:

http://blog.csdn.net/harvic880925/article/details/38660861

主要涉及代码目录:
/DialtactsActivity/src/com/android/dialer/list/ListsFragment.java
/ContactsCommon/src/com/android/contacts/common/list/ViewPagerTabs.java

后记

一步一个坑。

1 2
原创粉丝点击