| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.content; |
| 18 |
|
| 19 |
import com.android.internal.R; |
| 20 |
import android.accounts.Account; |
| 21 |
import android.app.Activity; |
| 22 |
import android.os.Bundle; |
| 23 |
import android.view.View; |
| 24 |
import android.view.ViewGroup; |
| 25 |
import android.widget.AdapterView; |
| 26 |
import android.widget.ArrayAdapter; |
| 27 |
import android.widget.LinearLayout; |
| 28 |
import android.widget.ListAdapter; |
| 29 |
import android.widget.ListView; |
| 30 |
import android.widget.TextView; |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
public class SyncActivityTooManyDeletes extends Activity |
| 39 |
implements AdapterView.OnItemClickListener { |
| 40 |
|
| 41 |
private long mNumDeletes; |
| 42 |
private Account mAccount; |
| 43 |
private String mAuthority; |
| 44 |
private String mProvider; |
| 45 |
|
| 46 |
@Override |
| 47 |
protected void onCreate(Bundle savedInstanceState) { |
| 48 |
super.onCreate(savedInstanceState); |
| 49 |
|
| 50 |
Bundle extras = getIntent().getExtras(); |
| 51 |
if (extras == null) { |
| 52 |
finish(); |
| 53 |
return; |
| 54 |
} |
| 55 |
|
| 56 |
mNumDeletes = extras.getLong("numDeletes"); |
| 57 |
mAccount = (Account) extras.getParcelable("account"); |
| 58 |
mAuthority = extras.getString("authority"); |
| 59 |
mProvider = extras.getString("provider"); |
| 60 |
|
| 61 |
|
| 62 |
CharSequence[] options = new CharSequence[]{ |
| 63 |
getResources().getText(R.string.sync_really_delete), |
| 64 |
getResources().getText(R.string.sync_undo_deletes), |
| 65 |
getResources().getText(R.string.sync_do_nothing) |
| 66 |
}; |
| 67 |
|
| 68 |
ListAdapter adapter = new ArrayAdapter<CharSequence>(this, |
| 69 |
android.R.layout.simple_list_item_1, |
| 70 |
android.R.id.text1, |
| 71 |
options); |
| 72 |
|
| 73 |
ListView listView = new ListView(this); |
| 74 |
listView.setAdapter(adapter); |
| 75 |
listView.setItemsCanFocus(true); |
| 76 |
listView.setOnItemClickListener(this); |
| 77 |
|
| 78 |
TextView textView = new TextView(this); |
| 79 |
CharSequence tooManyDeletesDescFormat = |
| 80 |
getResources().getText(R.string.sync_too_many_deletes_desc); |
| 81 |
textView.setText(String.format(tooManyDeletesDescFormat.toString(), |
| 82 |
mNumDeletes, mProvider, mAccount.name)); |
| 83 |
|
| 84 |
final LinearLayout ll = new LinearLayout(this); |
| 85 |
ll.setOrientation(LinearLayout.VERTICAL); |
| 86 |
final LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams( |
| 87 |
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT, 0); |
| 88 |
ll.addView(textView, lp); |
| 89 |
ll.addView(listView, lp); |
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
setContentView(ll); |
| 107 |
} |
| 108 |
|
| 109 |
public void onItemClick(AdapterView<?> parent, View view, int position, long id) { |
| 110 |
|
| 111 |
if (position == 0) startSyncReallyDelete(); |
| 112 |
else if (position == 1) startSyncUndoDeletes(); |
| 113 |
finish(); |
| 114 |
} |
| 115 |
|
| 116 |
private void startSyncReallyDelete() { |
| 117 |
Bundle extras = new Bundle(); |
| 118 |
extras.putBoolean(ContentResolver.SYNC_EXTRAS_OVERRIDE_TOO_MANY_DELETIONS, true); |
| 119 |
extras.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true); |
| 120 |
extras.putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, true); |
| 121 |
extras.putBoolean(ContentResolver.SYNC_EXTRAS_UPLOAD, true); |
| 122 |
ContentResolver.requestSync(mAccount, mAuthority, extras); |
| 123 |
} |
| 124 |
|
| 125 |
private void startSyncUndoDeletes() { |
| 126 |
Bundle extras = new Bundle(); |
| 127 |
extras.putBoolean(ContentResolver.SYNC_EXTRAS_DISCARD_LOCAL_DELETIONS, true); |
| 128 |
extras.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true); |
| 129 |
extras.putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, true); |
| 130 |
extras.putBoolean(ContentResolver.SYNC_EXTRAS_UPLOAD, true); |
| 131 |
ContentResolver.requestSync(mAccount, mAuthority, extras); |
| 132 |
} |
| 133 |
} |