Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲
 Android教程網 >> Android技術 >> Android開發 >> 關於android開發 >> Android系統之路(初識MTK) ------ System-Bluetooth name/WiFi AP name/sleep add never/Notification popup

Android系統之路(初識MTK) ------ System-Bluetooth name/WiFi AP name/sleep add never/Notification popup

編輯:關於android開發

Android系統之路(初識MTK) ------ System-Bluetooth name/WiFi AP name/sleep add never/Notification popup


今天拿到一個客戶新的訂單需求,大概有40多個需求,今天先講更改系統的藍牙/wifi 熱點/消息通知/sleep 添加 never選項,分別是:

藍牙:系統界面顯示名字,重命名前的默認名字

wifi 熱點:連接名字,重命名前默認 Network name

Notification popup :系統 Notification popup 默認不勾選

休眠添加never選項,默認30s:添加永不休眠,默認30s

首先我們要知道系統默認的藍牙名字 ANDROID BT

Linux input ...> find 你的源碼根目錄/ -type f|xargs grep "ANDROID BT" -l

這句命令是找出源碼下所有帶有字符串 ANDROID BT 所在的文件,搜索無果,直接進入源碼

packages\apps\Settings\src\com\android\settings\bluetooth\BluetoothSettins.java

跟蹤源碼找到如下代碼

    @Override
    public void onResume() {
        ......

        if (mLocalAdapter != null) {
            updateContent(mLocalAdapter.getBluetoothState());
        }
    }
跟蹤updateContent函數,修改如下代碼
                if (mMyDevicePreference == null) {
                    mMyDevicePreference = new Preference(getActivity());
                }

                // Engineer-Jsp add default bluetooth name
            	if (android.os.SystemProperties.isWalPadVersion()) {  
            		mMyDevicePreference.setSummary(getResources().getString(
            				R.string.bluetooth_is_visible_message, "Walpad C"));
            	}else{
            		mMyDevicePreference.setSummary(getResources().getString(
            				R.string.bluetooth_is_visible_message, mLocalAdapter.getName()));
            	} 
            	
                mMyDevicePreference.setSelectable(false);

其中 isWalpadVersion 函數是我在frameworks/base/core/java/android/os/SystemProperties.java中定義的
	public static boolean isWalPadVersion(){  
    return SystemProperties.get("ro.product.model").contains("Walpad");  
   }  
根據編譯文件設置的客戶平板型號定制產品而定,這樣寫有人可能會覺得多此一舉,顯的麻煩,但是作為一個系統,能把它做成兼容模式豈不是更好?

因為下次再有系統定制訂單需求,我們只需要修改配置文件和分支就夠了,輕松方便,而不需要再去new 代碼了

setSummary(...,...)函數就是藍牙設置打開藍牙之後在界面顯示的效果

R.string.bluetooth.is.visible_message 內容:

%1$s is visible to nearby devices while Bluetooth Settings is open.
device_name 即為我們替換的名字,即Walpad C,效果圖:

\

接下來修改重名命選項的藍牙設備名稱,onOptionsItemSelected(MenuItem item) 根據 item 追蹤重命名的 Dialog 找到如下邏輯:

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
	
	   ......

        mAlertDialog = new AlertDialog.Builder(getActivity())
                .setTitle(R.string.bluetooth_rename_device)
                .setView(createDialogView(deviceName))// 繼續追蹤createDialogView(deviceName)方法
				......


        return mAlertDialog;
    }
根據邏輯,修改如下:
    private View createDialogView(String deviceName) {
         ......
        // Engineer-Jsp add default bluetooth name
    	if (android.os.SystemProperties.isWalPadVersion()) {// 根據model顯示名稱
    		mDeviceNameView.setText("Walpad C");
    	}else{
    		mDeviceNameView.setText(deviceName);    // set initial value before adding listener
    	} 
        ......
        return view;
    }
效果圖:

\

修改wifi重命名前的名字,根據信息搜索到源碼packages\apps\Settings\src\com\android\settings\wifi\WifiApDialog.java

根據邏輯,查找到如下代碼:

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        Context context = getContext();
        ......
        if (mWifiConfig != null) {
            // Engineer-Jsp add default bluetooth name
        	if (android.os.SystemProperties.isWalPadVersion()) {  //根據型號顯示ssid
        		mSsid.setText("Walpad C");
        	}else{
        		mSsid.setText(mWifiConfig.SSID);
        	} 

            /// M: set selection
            mSecurity.setSelection(mExt.getSelection(mSecurityTypeIndex));

            if (mSecurityTypeIndex == WPA2_INDEX) {
                  mPassword.setText(mWifiConfig.preSharedKey);
            }
            ///M: get configured channel @{
            mChannel = mWifiConfig.channel;
            mChannelWidth = mWifiConfig.channelWidth;
            /// @}
        }
      ......
    }

效果:

\

 

連接名字:

\


修改系統 Notification popup 默認不勾選

搜索關鍵字:源碼目錄...>find ./ -name ".xml" | xargs grep "Popup notification"

找到xml文件之後找到對應string name 名稱,發現他被一個布局文件調用,packages\apps\Mms\res\xml\notificationpreferences.xml - pref_summary_popup_notification -
defaultValue="false" 把這個默認false,即可

效果:

\

修改休眠選項默認 30s 添加永不休眠選項:

默認休眠30s修改:frameworks\base\packages\SettingsProvider\res\values\defaults.xml

30000
添加永不休眠選項:
    private static final boolean sNeedScreenTimeoutNever = true;    
        
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

		......
        if (sNeedScreenTimeoutNever && mScreenTimeoutPreference != null) { //rmt add
        	Resources res = getResources();
        	final String[] entries = res.getStringArray(R.array.screen_timeout_entries);
            final String[] values  = res.getStringArray(R.array.screen_timeout_values);
            
            int entriesLength = entries.length;
            final String[] newEntries = new String[entriesLength + 1];
            for (int i = 0; i < entriesLength + 1; i++) {
            	if (i != entriesLength) {
            		newEntries[i] = entries[i];
            	} else {
            		newEntries[i] = res.getString(R.string.zen_mode_when_never);
                }
            }
            
            int valuesLength = values.length;
            final String[] newValues  = new String[valuesLength + 1];
            for (int i = 0; i < valuesLength + 1; i++) {
            	if (i != valuesLength) {
            		newValues[i] = values[i];
            	} else {
            		newValues[i] = "2147483647";
                }
            }
            
            mScreenTimeoutPreference.setEntries(newEntries);
            mScreenTimeoutPreference.setEntryValues(newValues);
            ......
    }
	    private void updateTimeoutPreferenceDescription(long currentTimeout) {
      
	    ......
        } else if(currentTimeout == Integer.MAX_VALUE) { //Engineer-Jsp add 
		       summary = preference.getContext().getString(R.string.zen_mode_when_never);
		}
		.......
    }
效果:

\

  1. 上一頁:
  2. 下一頁:
熱門文章
閱讀排行版
Copyright © Android教程網 All Rights Reserved