Merge "Move "Add Account" to ActionBar"
This commit is contained in:
commit
2148d9b2e6
24
res/menu/account_settings_add_account_option.xml
Normal file
24
res/menu/account_settings_add_account_option.xml
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- Copyright (C) 2010 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.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<!-- A menu for Account Settings to provide the "Add Account" option -->
|
||||||
|
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<item android:id="@+id/add_new_account"
|
||||||
|
android:title="@string/add_account_action"
|
||||||
|
android:icon="@android:drawable/ic_menu_add"
|
||||||
|
android:showAsAction="ifRoom|withText"
|
||||||
|
/>
|
||||||
|
</menu>
|
@ -42,6 +42,8 @@ import android.os.Bundle;
|
|||||||
import android.preference.PreferenceActivity;
|
import android.preference.PreferenceActivity;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
|
import android.view.Menu;
|
||||||
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.View.OnClickListener;
|
import android.view.View.OnClickListener;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
@ -65,7 +67,7 @@ import java.util.List;
|
|||||||
* sense to use a loader for the accounts list, because it would provide better support for
|
* sense to use a loader for the accounts list, because it would provide better support for
|
||||||
* dealing with accounts being added/deleted and triggering the header reload.
|
* dealing with accounts being added/deleted and triggering the header reload.
|
||||||
*/
|
*/
|
||||||
public class AccountSettingsXL extends PreferenceActivity implements OnClickListener {
|
public class AccountSettingsXL extends PreferenceActivity {
|
||||||
|
|
||||||
// Intent extras for our internal activity launch
|
// Intent extras for our internal activity launch
|
||||||
/* package */ static final String EXTRA_ACCOUNT_ID = "AccountSettingsXL.account_id";
|
/* package */ static final String EXTRA_ACCOUNT_ID = "AccountSettingsXL.account_id";
|
||||||
@ -100,7 +102,6 @@ public class AccountSettingsXL extends PreferenceActivity implements OnClickList
|
|||||||
/* package */ Fragment mCurrentFragment;
|
/* package */ Fragment mCurrentFragment;
|
||||||
private long mDeletingAccountId = -1;
|
private long mDeletingAccountId = -1;
|
||||||
private boolean mShowDebugMenu;
|
private boolean mShowDebugMenu;
|
||||||
private Button mAddAccountButton;
|
|
||||||
private List<Header> mGeneratedHeaders;
|
private List<Header> mGeneratedHeaders;
|
||||||
|
|
||||||
// Async Tasks
|
// Async Tasks
|
||||||
@ -162,17 +163,6 @@ public class AccountSettingsXL extends PreferenceActivity implements OnClickList
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
mShowDebugMenu = i.getBooleanExtra(EXTRA_ENABLE_DEBUG, false);
|
mShowDebugMenu = i.getBooleanExtra(EXTRA_ENABLE_DEBUG, false);
|
||||||
|
|
||||||
// Add Account as header list footer
|
|
||||||
// TODO: This probably should be some sort of themed layout with a button in it
|
|
||||||
if (hasHeaders()) {
|
|
||||||
mAddAccountButton = new Button(this);
|
|
||||||
mAddAccountButton.setText(R.string.add_account_action);
|
|
||||||
mAddAccountButton.setOnClickListener(this);
|
|
||||||
mAddAccountButton.setEnabled(false);
|
|
||||||
setListFooter(mAddAccountButton);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -181,8 +171,8 @@ public class AccountSettingsXL extends PreferenceActivity implements OnClickList
|
|||||||
updateAccounts();
|
updateAccounts();
|
||||||
|
|
||||||
// When we're resuming, enable/disable the add account button
|
// When we're resuming, enable/disable the add account button
|
||||||
if (mAddAccountButton != null && hasHeaders()) {
|
if (hasHeaders()) {
|
||||||
mAddAccountButton.setEnabled(shouldShowNewAccount());
|
invalidateOptionsMenu();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -213,10 +203,27 @@ public class AccountSettingsXL extends PreferenceActivity implements OnClickList
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public boolean onCreateOptionsMenu(Menu menu) {
|
||||||
if (v == mAddAccountButton) {
|
super.onCreateOptionsMenu(menu);
|
||||||
onAddNewAccount();
|
getMenuInflater().inflate(R.menu.account_settings_add_account_option, menu);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onPrepareOptionsMenu(Menu menu) {
|
||||||
|
return shouldShowNewAccount();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
|
switch (item.getItemId()) {
|
||||||
|
case R.id.add_new_account:
|
||||||
|
onAddNewAccount();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return super.onOptionsItemSelected(item);
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -455,8 +462,8 @@ public class AccountSettingsXL extends PreferenceActivity implements OnClickList
|
|||||||
}
|
}
|
||||||
|
|
||||||
// When we're changing fragments, enable/disable the add account button
|
// When we're changing fragments, enable/disable the add account button
|
||||||
if (mAddAccountButton != null && hasHeaders()) {
|
if (hasHeaders()) {
|
||||||
mAddAccountButton.setEnabled(shouldShowNewAccount());
|
invalidateOptionsMenu();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user