16
16
17
17
package com .android .contacts .common .util ;
18
18
19
+ import android .app .Activity ;
19
20
import android .app .AlertDialog ;
20
21
import android .app .Dialog ;
21
22
import android .content .Context ;
@@ -52,44 +53,44 @@ public class AccountSelectionUtil {
52
53
public static class AccountSelectedListener
53
54
implements DialogInterface .OnClickListener {
54
55
55
- final private Context mContext ;
56
+ final private Activity mActivity ;
56
57
final private int mResId ;
57
58
58
59
final protected List <AccountWithDataSet > mAccountList ;
59
60
60
- public AccountSelectedListener (Context context , List <AccountWithDataSet > accountList ,
61
+ public AccountSelectedListener (Activity activity , List <AccountWithDataSet > accountList ,
61
62
int resId ) {
62
63
if (accountList == null || accountList .size () == 0 ) {
63
64
Log .e (LOG_TAG , "The size of Account list is 0." );
64
65
}
65
- mContext = context ;
66
+ mActivity = activity ;
66
67
mAccountList = accountList ;
67
68
mResId = resId ;
68
69
}
69
70
70
71
public void onClick (DialogInterface dialog , int which ) {
71
72
dialog .dismiss ();
72
- doImport (mContext , mResId , mAccountList .get (which ));
73
+ doImport (mActivity , mResId , mAccountList .get (which ));
73
74
}
74
75
}
75
76
76
- public static Dialog getSelectAccountDialog (Context context , int resId ) {
77
- return getSelectAccountDialog (context , resId , null , null );
77
+ public static Dialog getSelectAccountDialog (Activity activity , int resId ) {
78
+ return getSelectAccountDialog (activity , resId , null , null );
78
79
}
79
80
80
- public static Dialog getSelectAccountDialog (Context context , int resId ,
81
+ public static Dialog getSelectAccountDialog (Activity activity , int resId ,
81
82
DialogInterface .OnClickListener onClickListener ) {
82
- return getSelectAccountDialog (context , resId , onClickListener , null );
83
+ return getSelectAccountDialog (activity , resId , onClickListener , null );
83
84
}
84
85
85
86
/**
86
87
* When OnClickListener or OnCancelListener is null, uses a default listener.
87
88
* The default OnCancelListener just closes itself with {@link Dialog#dismiss()}.
88
89
*/
89
- public static Dialog getSelectAccountDialog (Context context , int resId ,
90
+ public static Dialog getSelectAccountDialog (Activity activity , int resId ,
90
91
DialogInterface .OnClickListener onClickListener ,
91
92
DialogInterface .OnCancelListener onCancelListener ) {
92
- final AccountTypeManager accountTypes = AccountTypeManager .getInstance (context );
93
+ final AccountTypeManager accountTypes = AccountTypeManager .getInstance (activity );
93
94
final List <AccountWithDataSet > writableAccountList = accountTypes .getAccounts (true );
94
95
95
96
Log .i (LOG_TAG , "The number of available accounts: " + writableAccountList .size ());
@@ -98,11 +99,11 @@ public static Dialog getSelectAccountDialog(Context context, int resId,
98
99
99
100
// Wrap our context to inflate list items using correct theme
100
101
final Context dialogContext = new ContextThemeWrapper (
101
- context , android .R .style .Theme_Light );
102
+ activity , android .R .style .Theme_Light );
102
103
final LayoutInflater dialogInflater = (LayoutInflater )dialogContext
103
104
.getSystemService (Context .LAYOUT_INFLATER_SERVICE );
104
105
final ArrayAdapter <AccountWithDataSet > accountAdapter =
105
- new ArrayAdapter <AccountWithDataSet >(context , android .R .layout .simple_list_item_2 ,
106
+ new ArrayAdapter <AccountWithDataSet >(activity , android .R .layout .simple_list_item_2 ,
106
107
writableAccountList ) {
107
108
108
109
@ Override
@@ -133,7 +134,7 @@ public View getView(int position, View convertView, ViewGroup parent) {
133
134
134
135
if (onClickListener == null ) {
135
136
AccountSelectedListener accountSelectedListener =
136
- new AccountSelectedListener (context , writableAccountList , resId );
137
+ new AccountSelectedListener (activity , writableAccountList , resId );
137
138
onClickListener = accountSelectedListener ;
138
139
}
139
140
if (onCancelListener == null ) {
@@ -143,21 +144,21 @@ public void onCancel(DialogInterface dialog) {
143
144
}
144
145
};
145
146
}
146
- return new AlertDialog .Builder (context )
147
+ return new AlertDialog .Builder (activity )
147
148
.setTitle (R .string .dialog_new_contact_account )
148
149
.setSingleChoiceItems (accountAdapter , 0 , onClickListener )
149
150
.setOnCancelListener (onCancelListener )
150
151
.create ();
151
152
}
152
153
153
- public static void doImport (Context context , int resId , AccountWithDataSet account ) {
154
+ public static void doImport (Activity activity , int resId , AccountWithDataSet account ) {
154
155
switch (resId ) {
155
156
case R .string .import_from_sim : {
156
- doImportFromSim (context , account );
157
+ doImportFromSim (activity , account );
157
158
break ;
158
159
}
159
160
case R .string .import_from_sdcard : {
160
- doImportFromSdCard (context , account );
161
+ doImportFromSdCard (activity , account );
161
162
break ;
162
163
}
163
164
}
@@ -175,8 +176,8 @@ public static void doImportFromSim(Context context, AccountWithDataSet account)
175
176
context .startActivity (importIntent );
176
177
}
177
178
178
- public static void doImportFromSdCard (Context context , AccountWithDataSet account ) {
179
- Intent importIntent = new Intent (context , ImportVCardActivity .class );
179
+ public static void doImportFromSdCard (Activity activity , AccountWithDataSet account ) {
180
+ Intent importIntent = new Intent (activity , ImportVCardActivity .class );
180
181
if (account != null ) {
181
182
importIntent .putExtra ("account_name" , account .name );
182
183
importIntent .putExtra ("account_type" , account .type );
@@ -189,6 +190,6 @@ public static void doImportFromSdCard(Context context, AccountWithDataSet accoun
189
190
}
190
191
mVCardShare = false ;
191
192
mPath = null ;
192
- context . startActivity (importIntent );
193
+ activity . startActivityForResult (importIntent , 0 );
193
194
}
194
195
}
0 commit comments