package cn.sleepycoder.customaccount;
import android.annotation.TargetApi;
import android.content.Context;
import android.content.Intent;
import android.content.res.Configuration;
import android.media.Ringtone;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.support.v7.app.ActionBar;
import android.preference.PreferenceFragment;
import android.preference.PreferenceManager;
import android.preference.RingtonePreference;
import android.text.TextUtils;
import android.view.MenuItem;
import java.util.List;
/**
* A {@link PreferenceActivity} that presents a set of application settings. On
* handset devices, settings are presented as a single list. On tablets,
* settings are split by category, with category headers shown to the left of
* the list of settings.
* <p>
* See <a href="http://developer.android.com/design/patterns/settings.html">
* Android Design: Settings</a> for design guidelines and the <a
* href="http://developer.android.com/guide/topics/ui/settings.html">Settings
* API Guide</a> for more information on developing a Settings UI.
*/
//这个设置页面是android的模板自动生成的 实现不必关心
public class SyncSettingsActivity extends AppCompatPreferenceActivity {
/**
* A preference value change listener that updates the preference's summary
* to reflect its new value.
*/
private static Preference.OnPreferenceChangeListener sBindPreferenceSummaryToValueListener = new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object value) {
String stringValue = value.toString();
if (preference instanceof ListPreference) {
// For list preferences, look up the correct display value in
// the preference's 'entries' list.
ListPreference listPreference = (ListPreference) preference;
int index = listPreference.findIndexOfValue(stringValue);
// Set the summary to reflect the new value.
preference.setSummary(
index >= 0
? listPreference.getEntries()[index]
: null);
} else if (preference instanceof RingtonePreference) {
// For ringtone preferences, look up the correct display value
// using RingtoneManager.
if (TextUtils.isEmpty(stringValue)) {
// Empty values correspond to 'silent' (no ringtone).
preference.setSummary(R.string.pref_ringtone_silent);
} else {
Ringtone ringtone = RingtoneManager.getRingtone(
preference.getContext(), Uri.parse(stringValue));
if (ringtone == null) {
// Clear the summary if there was a lookup error.
preference.setSummary(null);
} else {
// Set the summary to reflect the new ringtone display
// name.
String name = ringtone.getTitle(preference.getContext());
preference.setSummary(name);
}
}
} else {
// For all other preferences, set the summary to the value's
// simple string representation.
preference.setSummary(stringValue);
}
return true;
}
};
/**
* Helper method to determine if the device has an extra-large screen. For
* example, 10" tablets are extra-large.
*/
private static boolean isXLargeTablet(Context context) {
return (context.getResources().getConfiguration().screenLayout
& Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_XLARGE;
}
/**
* Binds a preference's summary to its value. More specifically, when the
* preference's value is changed, its summary (line of text below the
* preference title) is updated to reflect the value. The summary is also
* immediately updated upon calling this method. The exact display format is
* dependent on the type of preference.
*
* @see #sBindPreferenceSummaryToValueListener
*/
private static void bindPreferenceSummaryToValue(Preference preference) {
// Set the listener to watch for value changes.
preference.setOnPreferenceChangeListener(sBindPreferenceSummaryToValueListener);
// Trigger the listener immediately with the preference's
// current value.
sBindPreferenceSummaryToValueListener.onPreferenceChange(preference,
PreferenceManager
.getDefaultSharedPreferences(preference.getContext())
.getString(preference.getKey(), ""));
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setupActionBar();
}
/**
* Set up the {@link android.app.ActionBar}, if the API is available.
*/
private void setupActionBar() {
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
// Show the Up button in the action bar.
actionBar.setDisplayHomeAsUpEnabled(true);
}
}
/**
* {@inheritDoc}
*/
@Override
public boolean onIsMultiPane() {
return isXLargeTablet(this);
}
/**
* {@inheritDoc}
*/
@Override
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public void onBuildHeaders(List<Header> target) {
loadHeadersFromResource(R.xml.pref_headers, target);
}
/**
* This method stops fragment injection in malicious applications.
* Make sure to deny any unknown fragments here.
*/
protected boolean isValidFragment(String fragmentName) {
return PreferenceFragment.class.getName().equals(fragmentName)
|| GeneralPreferenceFragment.class.getName().equals(fragmentName)
|| DataSyncPreferenceFragment.class.getName().equals(fragmentName)
|| NotificationPreferenceFragment.class.getName().equals(fragmentName);
}
/**
* This fragment shows general preferences only. It is used when the
* activity is showing a two-pane settings UI.
*/
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public static class GeneralPreferenceFragment extends PreferenceFragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.pref_general);
setHasOptionsMenu(true);
// Bind the summaries of EditText/List/Dialog/Ringtone preferences
// to their values. When their values change, their summaries are
// updated to reflect the new value, per the Android Design
// guidelines.
bindPreferenceSummaryToValue(findPreference("example_text"));
bindPreferenceSummaryToValue(findPreference("example_list"));
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == android.R.id.home) {
startActivity(new Intent(getActivity(), SyncSettingsActivity.class));
return true;
}
return super.onOptionsItemSelected(item);
}
}
/**
* This fragment shows notification preferences only. It is used when the
* activity is showing a two-pane settings UI.
*/
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public static class NotificationPreferenceFragment extend
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
Android自定义账户类型和同步适配器.zip (93个子文件)
CustomAccount
.gitignore 118B
gradle
wrapper
gradle-wrapper.jar 52KB
gradle-wrapper.properties 233B
local.properties 430B
build.gradle 498B
gradlew.bat 2KB
gradlew 5KB
app
.gitignore 7B
build.gradle 1KB
proguard-rules.pro 659B
app.iml 13KB
libs
src
test
java
cn
sleepycoder
customaccount
ExampleUnitTest.java 406B
main
AndroidManifest.xml 2KB
java
cn
sleepycoder
customaccount
SyncSettingsActivity.java 10KB
AppCompatPreferenceActivity.java 3KB
MainActivity.java 2KB
account
AccountAuthenticator.java 3KB
LoginActivity.java 4KB
service
AuthService.java 491B
SyncService.java 701B
syncadapter
SyncAdapter.java 1KB
SyncContentProvider.java 992B
res
values
styles.xml 383B
colors.xml 208B
strings.xml 2KB
dimens.xml 211B
mipmap-xxhdpi
ic_launcher.png 8KB
layout
activity_main.xml 820B
activity_login.xml 1KB
xml
pref_headers.xml 858B
pref_notification.xml 1KB
sync_adapter.xml 396B
pref_general.xml 1KB
pref_data_sync.xml 951B
account_preferences.xml 613B
authenticator.xml 356B
mipmap-xhdpi
ic_launcher.png 5KB
mipmap-hdpi
ic_launcher.png 3KB
drawable
ic_notifications_black_24dp.xml 465B
ic_info_black_24dp.xml 374B
ic_sync_black_24dp.xml 514B
mipmap-mdpi
ic_launcher.png 2KB
values-w820dp
dimens.xml 358B
mipmap-xxxhdpi
ic_launcher.png 10KB
androidTest
java
cn
sleepycoder
customaccount
ExampleInstrumentedTest.java 760B
.DS_Store 6KB
.gradle
2.14.1
tasks
_app_compileDebugJavaWithJavac
localJarClasspathSnapshot
localJarClasspathSnapshot.bin 21KB
localJarClasspathSnapshot.lock 17B
localClassSetAnalysis
localClassSetAnalysis.lock 17B
localClassSetAnalysis.bin 102KB
taskArtifacts
fileSnapshotsToTreeSnapshotsIndex.bin 29KB
cache.properties 30B
fileSnapshots.bin 4.52MB
cache.properties.lock 17B
fileHashes.bin 159KB
taskArtifacts.bin 134KB
gradle.properties 730B
.idea
libraries
jsr305_2_0_1.xml 322B
javax_annotation_api_1_2.xml 350B
rules_0_5.xml 721B
support_media_compat_24_2_1.xml 972B
runner_0_5.xml 727B
javax_inject_1.xml 316B
support_core_utils_24_2_1.xml 779B
support_compat_24_2_1.xml 930B
support_annotations_24_2_1.xml 513B
espresso_core_2_2_2.xml 630B
support_v4_24_2_1.xml 411B
appcompat_v7_24_2_1.xml 761B
javawriter_2_1_1.xml 322B
hamcrest_integration_1_3.xml 346B
animated_vector_drawable_24_2_1.xml 648B
hamcrest_library_1_3.xml 334B
design_24_2_1.xml 725B
espresso_idling_resource_2_2_2.xml 685B
recyclerview_v7_24_2_1.xml 779B
support_fragment_24_2_1.xml 944B
exposed_instrumentation_api_publish_0_5.xml 703B
support_vector_drawable_24_2_1.xml 643B
support_core_ui_24_2_1.xml 937B
hamcrest_core_1_3.xml 516B
junit_4_12.xml 467B
runConfigurations.xml 564B
workspace.xml 176KB
encodings.xml 159B
misc.xml 3KB
modules.xml 363B
copyright
profiles_settings.xml 74B
compiler.xml 686B
gradle.xml 705B
CustomAccount.iml 867B
.DS_Store 6KB
settings.gradle 15B
共 93 条
- 1
资源评论
- 贵公子2021-02-20不值得参考 浪费我的C币
ASleepyCoder
- 粉丝: 128
- 资源: 11
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功