由于接到了一个修改系统app---Settings条目是需求,接着也看到了一个博主的文章http://blog.csdn.net/wangjinyu501/article/details/22077803 这篇文章写的很好,基本满足了需求,我这里再做下整理,作为对知识的总结和梳理。
首先我们下载源码,可以从https://android.googlesource.com/上下载,接着我们找到AndroidManifest,xml文件。找到入口,代码如下
<activity android:name="Settings"
android:label="@string/settings_label_launcher"
android:taskAffinity="com.android.settings"
android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<action android:name="android.settings.SETTINGS" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
接着我们找到Settings.java。代码如下
/*
* Copyright (C) 2008 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings;
import com.android.internal.util.ArrayUtils;
import com.android.settings.ChooseLockGeneric.ChooseLockGenericFragment;
import com.android.settings.accounts.AccountSyncSettings;
import com.android.settings.accounts.AuthenticatorHelper;
import com.android.settings.accounts.ManageAccountsSettings;
import com.android.settings.applications.InstalledAppDetails;
import com.android.settings.applications.ManageApplications;
import com.android.settings.bluetooth.BluetoothEnabler;
import com.android.settings.deviceinfo.Memory;
import com.android.settings.fuelgauge.PowerUsageSummary;
import com.android.settings.vpn2.VpnSettings;
import com.android.settings.wifi.WifiEnabler;
import android.accounts.Account;
import android.accounts.AccountManager;
import android.accounts.OnAccountsUpdateListener;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.INetworkManagementService;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.UserHandle;
import android.os.UserManager;
import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.preference.PreferenceFragment;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ListAdapter;
import android.widget.Switch;
import android.widget.TextView;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
/**
* Top-level settings activity to handle single pane and double pane UI layout.
*/
public class Settings extends PreferenceActivity
implements ButtonBarHandler, OnAccountsUpdateListener {
private static final String LOG_TAG = "Settings";
private static final String META_DATA_KEY_HEADER_ID =
"com.android.settings.TOP_LEVEL_HEADER_ID";
private static final String META_DATA_KEY_FRAGMENT_CLASS =
"com.android.settings.FRAGMENT_CLASS";
private static final String META_DATA_KEY_PARENT_TITLE =
"com.android.settings.PARENT_FRAGMENT_TITLE";
private static final String META_DATA_KEY_PARENT_FRAGMENT_CLASS =
"com.android.settings.PARENT_FRAGMENT_CLASS";
private static final String EXTRA_CLEAR_UI_OPTIONS = "settings:remove_ui_options";
private static final String SAVE_KEY_CURRENT_HEADER = "com.android.settings.CURRENT_HEADER";
private static final String SAVE_KEY_PARENT_HEADER = "com.android.settings.PARENT_HEADER";
private String mFragmentClass;
private int mTopLevelHeaderId;
private Header mFirstHeader;
private Header mCurrentHeader;
private Header mParentHeader;
private boolean mInLocalHeaderSwitch;
// Show only these settings for restricted users
private int[] SETTINGS_FOR_RESTRICTED = {
R.id.wireless_section,
R.id.wifi_settings,
R.id.bluetooth_settings,
R.id.data_usage_settings,
R.id.wireless_settings,
R.id.device_section,
R.id.sound_settings,
R.id.display_settings,
R.id.storage_settings,
R.id.application_settings,
R.id.battery_settings,
R.id.personal_section,
R.id.location_settings,
R.id.security_settings,
R.id.language_settings,
R.id.user_settings,
R.id.account_settings,
R.id.account_add,
R.id.system_section,
R.id.date_time_settings,
R.id.about_settings,
R.id.accessibility_settings
};
private SharedPreferences mDevelopmentPreferences;
private SharedPreferences.OnSharedPreferenceChangeListener mDevelopmentPreferencesListener;
// TODO: Update Call Settings based on airplane mode state.
protected HashMap<Integer, Integer> mHeaderIndexMap = new HashMap<Integer, Integer>();
private AuthenticatorHelper mAuthenticatorHelper;
private Header mLastHeader;
private boolean mListeningToAccountUpdates;
@Override
protected void onCreate(Bundle savedInstanceState) {
if (getIntent().getBooleanExtra(EXTRA_CLEAR_UI_OPTIONS, false)) {
getWindow().setUiOptions(0);
}
mAuthenticatorHelper = new AuthenticatorHelper();
mAuthenticatorHelper.updateAuthDescriptions(this);
mAuthenticatorHelper.onAccountsUpdated(this, null);
mDevelopmentPreferences = getSharedPreferences(DevelopmentSettings.PREF_FILE,
Context.MODE_PRIVATE);
getMetaData();
mInLocalHeaderSwitch = true;
super.onCreate(savedInstanceState);
mInLocalHeaderSwitch = false;
if (!onIsHidingHeaders() && onIsMultiPane()) {
highlightHeader(mTopLevelHeaderId);
// Force the title so that it doesn't get overridden by a direct launch of
// a specific settings screen.
setTitle(R.string.settings_label);
}
// Retrieve any saved state
if (savedInstanceState != null) {
mCurrentHeader = savedInstanceState.getParcelable(SAVE_KEY_CURRENT_HEADER);
mParentHeader = savedInstanceState.getParcelable(SAVE_KEY_PARENT_HEADER);
}
// If the current header was saved, switch to it
if (savedInstanceState != nul