我正在编辑一个从互联网上获得的Android项目,该项目使用的是旧版gradle
。我不想更新gradle
,因为它使用了已弃用的SherlockFragment
之类的东西,我需要先完成更改,然后再更新。
然后我遇到了问题。以前,它显示了一些EditTextPreference
甚至对其进行了动画处理。但是现在,它没有动画,甚至没有显示。在查看了一些代码之后,我在布局文件中看到了这一点。
这是在下面的BasePrefsWizard上使用的Wizards_prefs_base.xml。
<ListView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:drawSelectorOnTop="false"
android:layoutAnimation="@anim/layout_slide_right"
android:persistentDrawingCache="animation|scrolling" />
这是layout_slide_right.xml文件。
<?xml version="1.0" encoding="utf-8"?>
<layoutAnimation xmlns:android="http://schemas.android.com/apk/res/android"
android:delay="30%"
android:animationOrder="normal"
android:animation="@anim/slide_right" />
这是slide_right.xml文件。
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_interpolator">
<translate android:fromXDelta="-100%"
android:toXDelta="0"
android:duration="500" />
<alpha android:fromAlpha="0.0"
android:toAlpha="1.0"
android:duration="500" />
</set>
所以,我想这应该做点什么。该代码确实完成得很整齐,我不明白它是如何完成它需要做的大多数事情的。
以下是我应该显示EditTextPreference
的代码。
public class BasePrefsWizard extends GenericPrefs {
public static final int SAVE_MENU = Menu.FIRST + 1;
public static final int TRANSFORM_MENU = Menu.FIRST + 2;
public static final int FILTERS_MENU = Menu.FIRST + 3;
public static final int DELETE_MENU = Menu.FIRST + 4;
private static final String THIS_FILE = "Base Prefs wizard";
protected SipProfile account = null;
private Button saveButton;
private String wizardId = "";
private WizardIface wizard = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
// Get back the concerned account and if any set the current (if not a
// new account is created)
Intent intent = getIntent();
long accountId = intent.getLongExtra(SipProfile.FIELD_ID, SipProfile.INVALID_ID);
// TODO : ensure this is not null...
setWizardId(intent.getStringExtra(SipProfile.FIELD_WIZARD));
account = SipProfile.getProfileFromDbId(this, accountId, DBProvider.ACCOUNT_FULL_PROJECTION);
super.onCreate(savedInstanceState);
// Bind buttons to their actions
Button bt = (Button) findViewById(R.id.cancel_bt);
bt.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
setResult(RESULT_CANCELED, getIntent());
finish();
}
});
saveButton = (Button) findViewById(R.id.save_bt);
saveButton.setEnabled(false);
saveButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
saveAndFinish();
}
});
wizard.fillLayout(account);
}
private boolean isResumed = false;
@Override
protected void onResume() {
super.onResume();
isResumed = true;
updateDescriptions();
updateValidation();
wizard.onStart();
}
@Override
protected void onPause() {
super.onPause();
isResumed = false;
wizard.onStop();
}
private boolean setWizardId(String wId) {
if (wizardId == null) {
return setWizardId(WizardUtils.EXPERT_WIZARD_TAG);
}
WizardInfo wizardInfo = WizardUtils.getWizardClass(wId);
if (wizardInfo == null) {
if (!wizardId.equals(WizardUtils.EXPERT_WIZARD_TAG)) {
return setWizardId(WizardUtils.EXPERT_WIZARD_TAG);
}
return false;
}
try {
wizard = (WizardIface) wizardInfo.classObject.newInstance();
} catch (IllegalAccessException e) {
Log.e(THIS_FILE, "Can't access wizard class", e);
if (!wizardId.equals(WizardUtils.EXPERT_WIZARD_TAG)) {
return setWizardId(WizardUtils.EXPERT_WIZARD_TAG);
}
return false;
} catch (InstantiationException e) {
Log.e(THIS_FILE, "Can't access wizard class", e);
if (!wizardId.equals(WizardUtils.EXPERT_WIZARD_TAG)) {
return setWizardId(WizardUtils.EXPERT_WIZARD_TAG);
}
return false;
}
wizardId = wId;
wizard.setParent(this);
if(getSupportActionBar() != null) {
getSupportActionBar().setIcon(WizardUtils.getWizardIconRes(wizardId));
}
return true;
}
@Override
protected void beforeBuildPrefs() {
// Use our custom wizard view
setContentView(R.layout.wizard_prefs_base);
}
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
if(isResumed) {
updateDescriptions();
updateValidation();
}
}
/**
* Update validation state of the current activity.
* It will check if wizard can be saved and if so
* will enable button
*/
public void updateValidation() {
saveButton.setEnabled(wizard.canSave());
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
menu.add(Menu.NONE, SAVE_MENU, Menu.NONE, R.string.save).setIcon(android.R.drawable.ic_menu_save);
if (account.id != SipProfile.INVALID_ID) {
menu.add(Menu.NONE, TRANSFORM_MENU, Menu.NONE, R.string.choose_wizard).setIcon(android.R.drawable.ic_menu_edit);
menu.add(Menu.NONE, FILTERS_MENU, Menu.NONE, R.string.filters).setIcon(R.drawable.ic_menu_filter);
menu.add(Menu.NONE, DELETE_MENU, Menu.NONE, R.string.delete_account).setIcon(android.R.drawable.ic_menu_delete);
}
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
menu.findItem(SAVE_MENU).setVisible(wizard.canSave());
return super.onPrepareOptionsMenu(menu);
}
private static final int CHOOSE_WIZARD = 0;
private static final int MODIFY_FILTERS = CHOOSE_WIZARD + 1;
private static final int FINAL_ACTIVITY_CODE = MODIFY_FILTERS;
private int currentActivityCode = FINAL_ACTIVITY_CODE;
public int getFreeSubActivityCode() {
currentActivityCode ++;
return currentActivityCode;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case SAVE_MENU:
saveAndFinish();
return true;
case TRANSFORM_MENU:
startActivityForResult(new Intent(this, WizardChooser.class), CHOOSE_WIZARD);
return true;
case DELETE_MENU:
if (account.id != SipProfile.INVALID_ID) {
getContentResolver().delete(ContentUris.withAppendedId(SipProfile.ACCOUNT_ID_URI_BASE, account.id), null, null);
setResult(RESULT_OK, getIntent());
finish();
}
return true;
case FILTERS_MENU:
if (account.id != SipProfile.INVALID_ID) {
Intent it = new Intent(this, AccountFilters.class);
it.putExtra(SipProfile.FIELD_ID, account.id);
it.putExtra(SipProfile.FIELD_DISPLAY_NAME, account.display_name);
it.putExtra(SipProfile.FIELD_WIZARD, account.wizard);
startActivityForResult(it, MODIFY_FILTERS);
return true;
}
break;
default:
break;
}
return super.onOptionsItemSelected(item);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == CHOOSE_WIZARD && resultCode == RESULT_OK && data != null && data.getExtras() != null) {
String wizardId = data.getStringExtra(WizardUtils.ID);
if (wizardId != null) {
saveAccount(wizardId);
setResult(RESULT_OK, getIntent());
finish();
}
}
if(requestCode > FINAL_ACTIVITY_CODE) {
wizard.onActivityResult(requestCode, resultCode, data);
}
}
/**
* Save account and end the activity
*/
public void saveAndFinish() {
saveAccount();
Intent intent = getIntent();
setResult(RESULT_OK, intent);
finish();
}
/*
* Save the account with current wizard id
*/
private void saveAccount() {
saveAccount(wizardId);
}
@Override
protected void onDestroy() {
super.onDestroy();
getSharedPreferences(WIZARD_PREF_NAME, MODE_PRIVATE).edit().clear().commit();
}
/**
* Save the account with given wizard id
* @param wizardId the wizard to use for account entry
*/
private void saveAccount(String wizardId) {
boolean needRestart = false;
PreferencesWrapper prefs = new PreferencesWrapper(getApplicationContext());
account = wizard.buildAccount(account);
account.wizard = wizardId;
if (account.id == SipProfile.INVALID_ID) {
// This account does not exists yet
prefs.startEditing();
wizard.setDefaultParams(prefs);
prefs.endEditing();
applyNewAccountDefault(account);
Uri uri = getContentResolver().insert(SipProfile.ACCOUNT_URI, account.getDbContentValues());
// After insert, add filters for this wizard
account.id = ContentUris.parseId(uri);
List<Filter> filters = wizard.getDefaultFilters(account);
if (filters != null) {
for (Filter filter : filters) {
// Ensure the correct id if not done by the wizard
filter.account = (int) account.id;
getContentResolver().insert(SipManager.FILTER_URI, filter.getDbContentValues());
}
}
// Check if we have to restart
needRestart = wizard.needRestart();
} else {
// TODO : should not be done there but if not we should add an
// option to re-apply default params
prefs.startEditing();
wizard.setDefaultParams(prefs);
prefs.endEditing();
getContentResolver().update(ContentUris.withAppendedId(SipProfile.ACCOUNT_ID_URI_BASE, account.id), account.getDbContentValues(), null, null);
}
// Mainly if global preferences were changed, we have to restart sip stack
if (needRestart) {
Intent intent = new Intent(SipManager.ACTION_SIP_REQUEST_RESTART);
sendBroadcast(intent);
}
}
/**
* Apply default settings for a new account to check very basic coherence of settings and auto-modify settings missing
* @param account
*/
private void applyNewAccountDefault(SipProfile account) {
if(account.use_rfc5626) {
if(TextUtils.isEmpty(account.rfc5626_instance_id)) {
String autoInstanceId = (UUID.randomUUID()).toString();
account.rfc5626_instance_id = "<urn:uuid:"+autoInstanceId+">";
}
}
}
@Override
protected int getXmlPreferences() {
return wizard.getBasePreferenceResource();
}
@Override
protected void updateDescriptions() {
wizard.updateDescriptions();
}
@Override
protected String getDefaultFieldSummary(String fieldName) {
return wizard.getDefaultFieldSummary(fieldName);
}
private static final String WIZARD_PREF_NAME = "Wizard";
@Override
public SharedPreferences getSharedPreferences(String name, int mode) {
return super.getSharedPreferences(WIZARD_PREF_NAME, mode);
}
}
这是我发现的代码,它似乎设置了EditTextPreference
的内容。
public class Basic extends BaseImplementation {
protected static final String THIS_FILE = "Basic W";
private EditTextPreference accountDisplayName;
private EditTextPreference accountUserName;
private EditTextPreference accountServer;
private EditTextPreference accountPassword;
private void bindFields() {
accountDisplayName = (EditTextPreference) findPreference("display_name");
accountUserName = (EditTextPreference) findPreference("username");
accountServer = (EditTextPreference) findPreference("server");
accountPassword = (EditTextPreference) findPreference("password");
}
public void fillLayout(final SipProfile account) {
bindFields();
accountDisplayName.setText(account.display_name);
String serverFull = account.reg_uri;
if (serverFull == null) {
serverFull = "";
}else {
serverFull = serverFull.replaceFirst("sip:", "");
}
ParsedSipContactInfos parsedInfo = SipUri.parseSipContact(account.acc_id);
accountUserName.setText(parsedInfo.userName);
accountServer.setText(serverFull);
accountPassword.setText(account.data);
}
public void updateDescriptions() {
setStringFieldSummary("display_name");
setStringFieldSummary("username");
setStringFieldSummary("server");
setPasswordFieldSummary("password");
}
private static HashMap<String, Integer>SUMMARIES = new HashMap<String, Integer>(){/**
*
*/
private static final long serialVersionUID = -5743705263738203615L;
{
put("display_name", R.string.w_common_display_name_desc);
put("username", R.string.w_basic_username_desc);
put("server", R.string.w_common_server_desc);
put("password", R.string.w_basic_password_desc);
}};
@Override
public String getDefaultFieldSummary(String fieldName) {
Integer res = SUMMARIES.get(fieldName);
if(res != null) {
return parent.getString( res );
}
return "";
}
public boolean canSave() {
boolean isValid = true;
isValid &= checkField(accountDisplayName, isEmpty(accountDisplayName));
isValid &= checkField(accountPassword, isEmpty(accountPassword));
isValid &= checkField(accountServer, isEmpty(accountServer));
isValid &= checkField(accountUserName, isEmpty(accountUserName));
return isValid;
}
public SipProfile buildAccount(SipProfile account) {
Log.d(THIS_FILE, "begin of save ....");
account.display_name = accountDisplayName.getText().trim();
String[] serverParts = accountServer.getText().split(":");
account.acc_id = "<sip:" + SipUri.encodeUser(accountUserName.getText().trim()) + "@"+serverParts[0].trim()+">";
String regUri = "sip:" + accountServer.getText();
account.reg_uri = regUri;
account.proxies = new String[] { regUri } ;
account.realm = "*";
account.username = getText(accountUserName).trim();
account.data = getText(accountPassword);
account.scheme = SipProfile.CRED_SCHEME_DIGEST;
account.datatype = SipProfile.CRED_DATA_PLAIN_PASSWD;
//By default auto transport
account.transport = SipProfile.TRANSPORT_UDP;
return account;
}
@Override
public int getBasePreferenceResource() {
return R.xml.w_basic_preferences;
}
@Override
public boolean needRestart() {
return false;
}
}
这是SherlockPreferenceActivity类。
public abstract class SherlockPreferenceActivity extends PreferenceActivity implements OnCreatePanelMenuListener, OnPreparePanelListener, OnMenuItemSelectedListener, OnActionModeStartedListener, OnActionModeFinishedListener {
private ActionBarSherlock mSherlock;
protected final ActionBarSherlock getSherlock() {
if (mSherlock == null) {
mSherlock = ActionBarSherlock.wrap(this, ActionBarSherlock.FLAG_DELEGATE);
}
return mSherlock;
}
///////////////////////////////////////////////////////////////////////////
// Action bar and mode
///////////////////////////////////////////////////////////////////////////
public ActionBar getSupportActionBar() {
return getSherlock().getActionBar();
}
public ActionMode startActionMode(ActionMode.Callback callback) {
return getSherlock().startActionMode(callback);
}
@Override
public void onActionModeStarted(ActionMode mode) {}
@Override
public void onActionModeFinished(ActionMode mode) {}
///////////////////////////////////////////////////////////////////////////
// General lifecycle/callback dispatching
///////////////////////////////////////////////////////////////////////////
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
getSherlock().dispatchConfigurationChanged(newConfig);
}
@Override
protected void onPostResume() {
super.onPostResume();
getSherlock().dispatchPostResume();
}
@Override
protected void onPause() {
getSherlock().dispatchPause();
super.onPause();
}
@Override
protected void onStop() {
getSherlock().dispatchStop();
super.onStop();
}
@Override
protected void onDestroy() {
getSherlock().dispatchDestroy();
super.onDestroy();
}
@Override
protected void onPostCreate(Bundle savedInstanceState) {
getSherlock().dispatchPostCreate(savedInstanceState);
super.onPostCreate(savedInstanceState);
}
@Override
protected void onTitleChanged(CharSequence title, int color) {
getSherlock().dispatchTitleChanged(title, color);
super.onTitleChanged(title, color);
}
@Override
public final boolean onMenuOpened(int featureId, android.view.Menu menu) {
if (getSherlock().dispatchMenuOpened(featureId, menu)) {
return true;
}
return super.onMenuOpened(featureId, menu);
}
@Override
public void onPanelClosed(int featureId, android.view.Menu menu) {
getSherlock().dispatchPanelClosed(featureId, menu);
super.onPanelClosed(featureId, menu);
}
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
if (getSherlock().dispatchKeyEvent(event)) {
return true;
}
return super.dispatchKeyEvent(event);
}
///////////////////////////////////////////////////////////////////////////
// Native menu handling
///////////////////////////////////////////////////////////////////////////
public MenuInflater getSupportMenuInflater() {
return getSherlock().getMenuInflater();
}
public void invalidateOptionsMenu() {
getSherlock().dispatchInvalidateOptionsMenu();
}
public void supportInvalidateOptionsMenu() {
getSherlock().dispatchInvalidateOptionsMenu();
}
@Override
public final boolean onCreateOptionsMenu(android.view.Menu menu) {
return getSherlock().dispatchCreateOptionsMenu(menu);
}
@Override
public final boolean onPrepareOptionsMenu(android.view.Menu menu) {
return getSherlock().dispatchPrepareOptionsMenu(menu);
}
@Override
public final boolean onOptionsItemSelected(android.view.MenuItem item) {
return getSherlock().dispatchOptionsItemSelected(item);
}
@Override
public void openOptionsMenu() {
if (!getSherlock().dispatchOpenOptionsMenu()) {
super.openOptionsMenu();
}
}
@Override
public void closeOptionsMenu() {
if (!getSherlock().dispatchCloseOptionsMenu()) {
super.closeOptionsMenu();
}
}
///////////////////////////////////////////////////////////////////////////
// Sherlock menu handling
///////////////////////////////////////////////////////////////////////////
@Override
public boolean onCreatePanelMenu(int featureId, Menu menu) {
if (featureId == Window.FEATURE_OPTIONS_PANEL) {
return onCreateOptionsMenu(menu);
}
return false;
}
public boolean onCreateOptionsMenu(Menu menu) {
return true;
}
@Override
public boolean onPreparePanel(int featureId, View view, Menu menu) {
if (featureId == Window.FEATURE_OPTIONS_PANEL) {
return onPrepareOptionsMenu(menu);
}
return false;
}
public boolean onPrepareOptionsMenu(Menu menu) {
return true;
}
@Override
public boolean onMenuItemSelected(int featureId, MenuItem item) {
if (featureId == Window.FEATURE_OPTIONS_PANEL) {
return onOptionsItemSelected(item);
}
return false;
}
public boolean onOptionsItemSelected(MenuItem item) {
return false;
}
///////////////////////////////////////////////////////////////////////////
// Content
///////////////////////////////////////////////////////////////////////////
@Override
public void addContentView(View view, LayoutParams params) {
getSherlock().addContentView(view, params);
}
@Override
public void setContentView(int layoutResId) {
getSherlock().setContentView(layoutResId);
}
@Override
public void setContentView(View view, LayoutParams params) {
getSherlock().setContentView(view, params);
}
@Override
public void setContentView(View view) {
getSherlock().setContentView(view);
}
public void requestWindowFeature(long featureId) {
getSherlock().requestFeature((int)featureId);
}
///////////////////////////////////////////////////////////////////////////
// Progress Indication
///////////////////////////////////////////////////////////////////////////
public void setSupportProgress(int progress) {
getSherlock().setProgress(progress);
}
public void setSupportProgressBarIndeterminate(boolean indeterminate) {
getSherlock().setProgressBarIndeterminate(indeterminate);
}
public void setSupportProgressBarIndeterminateVisibility(boolean visible) {
getSherlock().setProgressBarIndeterminateVisibility(visible);
}
public void setSupportProgressBarVisibility(boolean visible) {
getSherlock().setProgressBarVisibility(visible);
}
public void setSupportSecondaryProgress(int secondaryProgress) {
getSherlock().setSecondaryProgress(secondaryProgress);
}
}
我在Android Studio
上使用了调试器,但似乎没有调用任何与动画相关的类。
我找到了PreferenceScreen
xml文件。
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
<EditTextPreference
android:dialogMessage="@string/w_common_display_name_desc"
android:key="display_name"
android:singleLine="true"
android:summary="@string/w_common_display_name_desc"
android:title="@string/w_common_display_name" />
<EditTextPreference
android:dialogMessage="@string/w_basic_username_desc"
android:inputType="textVisiblePassword"
android:key="username"
android:singleLine="true"
android:summary="@string/w_basic_username_desc"
android:title="@string/w_basic_username" />
<EditTextPreference
android:dialogMessage="@string/w_common_server_desc"
android:inputType="textVisiblePassword"
android:key="server"
android:singleLine="true"
android:summary="@string/w_common_server_desc"
android:title="@string/w_common_server" />
<com.csipsimple.widgets.PasswordPreference
android:dialogMessage="@string/w_basic_password_desc"
android:key="password"
android:password="true"
android:singleLine="true"
android:summary="@string/w_basic_password_desc"
android:title="@string/w_basic_password" />
</PreferenceScreen>