Use Executor thread pool instead of creating my own threads on the fly
This commit is contained in:
parent
135cf2e572
commit
4a21d3f4f9
@ -328,14 +328,14 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
||||
mSearch.setOnEditorActionListener(search);
|
||||
mSearch.setOnTouchListener(search);
|
||||
|
||||
new Thread(new Runnable() {
|
||||
BrowserApp.getTaskThread().execute(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
initializeSearchSuggestions(mSearch);
|
||||
}
|
||||
|
||||
}).run();
|
||||
});
|
||||
|
||||
mDrawerLayout.setDrawerShadow(R.drawable.drawer_right_shadow, GravityCompat.END);
|
||||
mDrawerLayout.setDrawerShadow(R.drawable.drawer_left_shadow, GravityCompat.START);
|
||||
@ -1480,42 +1480,49 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
||||
* previously searched URLs
|
||||
*/
|
||||
private void initializeSearchSuggestions(final AutoCompleteTextView getUrl) {
|
||||
getUrl.setThreshold(1);
|
||||
getUrl.setDropDownWidth(-1);
|
||||
getUrl.setDropDownAnchor(R.id.toolbar_layout);
|
||||
getUrl.setOnItemClickListener(new OnItemClickListener() {
|
||||
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> adapterView, View view, int pos, long l) {
|
||||
String url = null;
|
||||
CharSequence urlString = ((TextView) view.findViewById(R.id.url)).getText();
|
||||
if (urlString != null) {
|
||||
url = urlString.toString();
|
||||
}
|
||||
if (url == null || url.startsWith(BrowserActivity.this.getString(R.string.suggestion))) {
|
||||
CharSequence searchString = ((TextView) view.findViewById(R.id.title)).getText();
|
||||
if (searchString != null) {
|
||||
url = searchString.toString();
|
||||
}
|
||||
}
|
||||
if (url == null) {
|
||||
return;
|
||||
}
|
||||
getUrl.setText(url);
|
||||
searchTheWeb(url);
|
||||
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
imm.hideSoftInputFromWindow(getUrl.getWindowToken(), 0);
|
||||
final LightningView currentTab = mTabsManager.getCurrentTab();
|
||||
if (currentTab != null) {
|
||||
currentTab.requestFocus();
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
getUrl.setSelectAllOnFocus(true);
|
||||
mSearchAdapter = new SearchAdapter(this, mDarkTheme, isIncognito());
|
||||
getUrl.setAdapter(mSearchAdapter);
|
||||
|
||||
getUrl.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
getUrl.setThreshold(1);
|
||||
getUrl.setDropDownWidth(-1);
|
||||
getUrl.setDropDownAnchor(R.id.toolbar_layout);
|
||||
getUrl.setOnItemClickListener(new OnItemClickListener() {
|
||||
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> adapterView, View view, int pos, long l) {
|
||||
String url = null;
|
||||
CharSequence urlString = ((TextView) view.findViewById(R.id.url)).getText();
|
||||
if (urlString != null) {
|
||||
url = urlString.toString();
|
||||
}
|
||||
if (url == null || url.startsWith(BrowserActivity.this.getString(R.string.suggestion))) {
|
||||
CharSequence searchString = ((TextView) view.findViewById(R.id.title)).getText();
|
||||
if (searchString != null) {
|
||||
url = searchString.toString();
|
||||
}
|
||||
}
|
||||
if (url == null) {
|
||||
return;
|
||||
}
|
||||
getUrl.setText(url);
|
||||
searchTheWeb(url);
|
||||
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
imm.hideSoftInputFromWindow(getUrl.getWindowToken(), 0);
|
||||
final LightningView currentTab = mTabsManager.getCurrentTab();
|
||||
if (currentTab != null) {
|
||||
currentTab.requestFocus();
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
getUrl.setSelectAllOnFocus(true);
|
||||
getUrl.setAdapter(mSearchAdapter);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -16,6 +16,7 @@ public class BrowserApp extends Application {
|
||||
|
||||
private static AppComponent mAppComponent;
|
||||
private static final Executor mIOThread = Executors.newSingleThreadExecutor();
|
||||
private static final Executor mTaskThread = Executors.newCachedThreadPool();
|
||||
|
||||
@Inject Bus mBus;
|
||||
|
||||
@ -41,6 +42,11 @@ public class BrowserApp extends Application {
|
||||
return mIOThread;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static Executor getTaskThread() {
|
||||
return mTaskThread;
|
||||
}
|
||||
|
||||
public static Bus getBus(@NonNull Context context) {
|
||||
return get(context).mBus;
|
||||
}
|
||||
|
@ -228,7 +228,7 @@ public class DownloadHandler {
|
||||
} else {
|
||||
final DownloadManager manager = (DownloadManager) context
|
||||
.getSystemService(Context.DOWNLOAD_SERVICE);
|
||||
new Thread() {
|
||||
BrowserApp.getTaskThread().execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
@ -243,7 +243,7 @@ public class DownloadHandler {
|
||||
eventBus.post(new BrowserEvents.ShowSnackBarMessage(R.string.problem_location_download));
|
||||
}
|
||||
}
|
||||
}.start();
|
||||
});
|
||||
eventBus.post(new BrowserEvents.ShowSnackBarMessage(
|
||||
context.getString(R.string.download_pending) + ' ' + filename));
|
||||
}
|
||||
|
@ -137,7 +137,7 @@ public class BookmarkSettingsFragment extends PreferenceFragment implements Pref
|
||||
exportpref.setOnPreferenceClickListener(this);
|
||||
importpref.setOnPreferenceClickListener(this);
|
||||
|
||||
new Thread(mInitializeImportPreference).start();
|
||||
BrowserApp.getTaskThread().execute(mInitializeImportPreference);
|
||||
}
|
||||
|
||||
private final Runnable mInitializeImportPreference = new Runnable() {
|
||||
|
@ -170,7 +170,7 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener,
|
||||
setupNavigationButton(view, R.id.action_toggle_desktop, R.id.icon_desktop);
|
||||
|
||||
// Must be called here, only here we have a reference to the ListView
|
||||
new Thread(mInitBookmarkManager).run();
|
||||
BrowserApp.getTaskThread().execute(mInitBookmarkManager);
|
||||
return view;
|
||||
}
|
||||
|
||||
|
@ -175,13 +175,12 @@ public class PrivacySettingsFragment extends LightningPreferenceFragment impleme
|
||||
new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface arg0, int arg1) {
|
||||
Thread clear = new Thread(new Runnable() {
|
||||
BrowserApp.getTaskThread().execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
clearCookies();
|
||||
}
|
||||
});
|
||||
clear.start();
|
||||
}
|
||||
})
|
||||
.setNegativeButton(getResources().getString(R.string.action_no), null).show();
|
||||
|
@ -96,12 +96,10 @@ public class SearchAdapter extends BaseAdapter implements Filterable {
|
||||
mSearchSubtitle = mContext.getString(R.string.suggestion);
|
||||
mDarkTheme = dark || incognito;
|
||||
mIncognito = incognito;
|
||||
Thread delete = new Thread(new ClearCacheRunnable(BrowserApp.get(context)));
|
||||
BrowserApp.getTaskThread().execute(new ClearCacheRunnable(BrowserApp.get(context)));
|
||||
mSearchDrawable = ThemeUtils.getThemedDrawable(context, R.drawable.ic_search, mDarkTheme);
|
||||
mBookmarkDrawable = ThemeUtils.getThemedDrawable(context, R.drawable.ic_bookmark, mDarkTheme);
|
||||
mHistoryDrawable = ThemeUtils.getThemedDrawable(context, R.drawable.ic_history, mDarkTheme);
|
||||
delete.setPriority(Thread.MIN_PRIORITY);
|
||||
delete.start();
|
||||
mLanguage = Locale.getDefault().getLanguage();
|
||||
if (mLanguage.isEmpty()) {
|
||||
mLanguage = DEFAULT_LANGUAGE;
|
||||
|
@ -55,7 +55,7 @@ public class AdBlock {
|
||||
}
|
||||
|
||||
private void loadBlockedDomainsList(@NonNull final Context context) {
|
||||
Thread thread = new Thread(new Runnable() {
|
||||
BrowserApp.getTaskThread().execute(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
@ -77,7 +77,6 @@ public class AdBlock {
|
||||
}
|
||||
}
|
||||
});
|
||||
thread.start();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -140,7 +139,7 @@ public class AdBlock {
|
||||
* @param context the context needed to read the file
|
||||
*/
|
||||
private void loadHostsFile(@NonNull final Context context) {
|
||||
Thread thread = new Thread(new Runnable() {
|
||||
BrowserApp.getTaskThread().execute(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
@ -181,6 +180,5 @@ public class AdBlock {
|
||||
}
|
||||
}
|
||||
});
|
||||
thread.start();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user