зеркало из https://github.com/mozilla/gecko-dev.git
Bug 860879 - Refactor PromptService; r=wesj
This commit is contained in:
Родитель
8aa0616938
Коммит
e51dce96dc
|
@ -54,14 +54,13 @@ import java.util.concurrent.TimeUnit;
|
|||
public class PromptService implements OnClickListener, OnCancelListener, OnItemClickListener, GeckoEventResponder {
|
||||
private static final String LOGTAG = "GeckoPromptService";
|
||||
|
||||
private static LayoutInflater sInflater;
|
||||
private static SynchronousQueue<String> sPromptQueue = new SynchronousQueue<String>();
|
||||
|
||||
private String[] mButtons;
|
||||
private PromptInput[] mInputs;
|
||||
private boolean[] mSelected;
|
||||
private AlertDialog mDialog;
|
||||
|
||||
private final LayoutInflater mInflater;
|
||||
private final SynchronousQueue<String> mPromptQueue;
|
||||
private final int mGroupPaddingSize;
|
||||
private final int mLeftRightTextWithIconPadding;
|
||||
private final int mTopBottomTextWithIconPadding;
|
||||
|
@ -71,7 +70,8 @@ public class PromptService implements OnClickListener, OnCancelListener, OnItemC
|
|||
private final int mMinRowSize;
|
||||
|
||||
PromptService() {
|
||||
sInflater = LayoutInflater.from(GeckoApp.mAppContext);
|
||||
mInflater = LayoutInflater.from(GeckoApp.mAppContext);
|
||||
mPromptQueue = new SynchronousQueue<String>();
|
||||
|
||||
Resources res = GeckoApp.mAppContext.getResources();
|
||||
mGroupPaddingSize = (int) (res.getDimension(R.dimen.prompt_service_group_padding_size));
|
||||
|
@ -286,11 +286,14 @@ public class PromptService implements OnClickListener, OnCancelListener, OnItemC
|
|||
public String getResponse() {
|
||||
// we only handle one kind of message in handleMessage, and this is the
|
||||
// response we provide for that message
|
||||
String promptServiceResult = "";
|
||||
String result = null;
|
||||
try {
|
||||
promptServiceResult = waitForReturn();
|
||||
} catch (InterruptedException e) { }
|
||||
return promptServiceResult;
|
||||
while (null == (result = mPromptQueue.poll(1, TimeUnit.MILLISECONDS))) {
|
||||
GeckoAppShell.processNextNativeEvent();
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
}
|
||||
return result != null ? result : "";
|
||||
}
|
||||
|
||||
private View applyInputStyle(View view) {
|
||||
|
@ -326,7 +329,7 @@ public class PromptService implements OnClickListener, OnCancelListener, OnItemC
|
|||
PromptListAdapter adapter = new PromptListAdapter(GeckoApp.mAppContext, resourceId, aMenuList);
|
||||
if (mSelected != null && mSelected.length > 0) {
|
||||
if (aMultipleSelection) {
|
||||
adapter.listView = (ListView) sInflater.inflate(R.layout.select_dialog_list, null);
|
||||
adapter.listView = (ListView) mInflater.inflate(R.layout.select_dialog_list, null);
|
||||
adapter.listView.setOnItemClickListener(this);
|
||||
builder.setInverseBackgroundForced(true);
|
||||
adapter.listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
|
||||
|
@ -451,28 +454,18 @@ public class PromptService implements OnClickListener, OnCancelListener, OnItemC
|
|||
finishDialog(ret.toString());
|
||||
}
|
||||
|
||||
public static String waitForReturn() throws InterruptedException {
|
||||
String value;
|
||||
|
||||
while (null == (value = sPromptQueue.poll(1, TimeUnit.MILLISECONDS))) {
|
||||
GeckoAppShell.processNextNativeEvent();
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
public void finishDialog(String aReturn) {
|
||||
mInputs = null;
|
||||
mButtons = null;
|
||||
mDialog = null;
|
||||
mSelected = null;
|
||||
try {
|
||||
if (!sPromptQueue.offer(aReturn, 5, TimeUnit.SECONDS)) {
|
||||
if (!mPromptQueue.offer(aReturn, 5, TimeUnit.SECONDS)) {
|
||||
ThreadUtils.dumpAllStackTraces();
|
||||
throw new ThreadUtils.UiThreadBlockedException();
|
||||
}
|
||||
} catch(InterruptedException ex) {
|
||||
Log.d(LOGTAG, "sPromptQueue not ready yet");
|
||||
Log.d(LOGTAG, "mPromptQueue not ready yet");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -699,7 +692,7 @@ public class PromptService implements OnClickListener, OnCancelListener, OnItemC
|
|||
resourceId = R.layout.list_item_header;
|
||||
}
|
||||
|
||||
convertView = sInflater.inflate(resourceId, null);
|
||||
convertView = mInflater.inflate(resourceId, null);
|
||||
convertView.setMinimumHeight(mMinRowSize);
|
||||
|
||||
TextView tv = (TextView) convertView.findViewById(android.R.id.text1);
|
||||
|
|
Загрузка…
Ссылка в новой задаче