Bug 1367079 - 5. Add TextSelection support in custom tabs and PWA; r=snorp

Add TextSelection support in custom tabs and PWA.

MozReview-Commit-ID: AcHjMfJ8onU
This commit is contained in:
Jim Chen 2017-09-14 17:50:58 -04:00
Родитель db5353e4ca
Коммит 69541254bf
2 изменённых файлов: 54 добавлений и 4 удалений

Просмотреть файл

@ -22,6 +22,7 @@ import android.support.design.widget.Snackbar;
import android.support.v4.util.SparseArrayCompat;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.view.ActionMode;
import android.support.v7.widget.Toolbar;
import android.text.TextUtils;
import android.util.Log;
@ -50,6 +51,7 @@ import org.mozilla.gecko.permissions.Permissions;
import org.mozilla.gecko.prompts.Prompt;
import org.mozilla.gecko.prompts.PromptListItem;
import org.mozilla.gecko.prompts.PromptService;
import org.mozilla.gecko.text.TextSelection;
import org.mozilla.gecko.util.ActivityUtils;
import org.mozilla.gecko.util.Clipboard;
import org.mozilla.gecko.util.ColorUtil;
@ -57,12 +59,14 @@ import org.mozilla.gecko.util.GeckoBundle;
import org.mozilla.gecko.util.IntentUtils;
import org.mozilla.gecko.util.PackageUtil;
import org.mozilla.gecko.util.ThreadUtils;
import org.mozilla.gecko.widget.ActionModePresenter;
import org.mozilla.gecko.widget.GeckoPopupMenu;
import java.util.List;
public class CustomTabsActivity extends AppCompatActivity
implements GeckoMenu.Callback,
implements ActionModePresenter,
GeckoMenu.Callback,
GeckoView.ContentListener,
GeckoView.NavigationListener,
GeckoView.ProgressListener {
@ -84,6 +88,9 @@ public class CustomTabsActivity extends AppCompatActivity
private DoorHangerPopup mDoorHangerPopup;
private FormAssistPopup mFormAssistPopup;
private ActionMode mActionMode;
private TextSelection mTextSelection;
private boolean mCanGoBack = false;
private boolean mCanGoForward = false;
private boolean mCanStop = false;
@ -125,6 +132,9 @@ public class CustomTabsActivity extends AppCompatActivity
mFormAssistPopup = (FormAssistPopup) findViewById(R.id.form_assist_popup);
mFormAssistPopup.create(mGeckoView);
mTextSelection = TextSelection.Factory.create(mGeckoView, this);
mTextSelection.create();
final GeckoViewSettings settings = mGeckoView.getSettings();
settings.setBoolean(GeckoViewSettings.USE_MULTIPROCESS, false);
@ -138,6 +148,7 @@ public class CustomTabsActivity extends AppCompatActivity
@Override
public void onDestroy() {
mTextSelection.destroy();
mFormAssistPopup.destroy();
mDoorHangerPopup.destroy();
mPromptService.destroy();
@ -670,4 +681,18 @@ public class CustomTabsActivity extends AppCompatActivity
return null;
}
}
@Override // ActionModePresenter
public void startActionMode(final ActionMode.Callback callback) {
endActionMode();
mActionMode = startSupportActionMode(callback);
}
@Override // ActionModePresenter
public void endActionMode() {
if (mActionMode != null) {
mActionMode.finish();
mActionMode = null;
}
}
}

Просмотреть файл

@ -20,6 +20,7 @@ import android.os.Bundle;
import android.support.customtabs.CustomTabsIntent;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.view.ActionMode;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.View;
@ -29,19 +30,22 @@ import android.widget.TextView;
import org.mozilla.gecko.ActivityHandlerHelper;
import org.mozilla.gecko.AppConstants;
import org.mozilla.gecko.customtabs.CustomTabsActivity;
import org.mozilla.gecko.DoorHangerPopup;
import org.mozilla.gecko.GeckoScreenOrientation;
import org.mozilla.gecko.GeckoView;
import org.mozilla.gecko.GeckoViewSettings;
import org.mozilla.gecko.R;
import org.mozilla.gecko.customtabs.CustomTabsActivity;
import org.mozilla.gecko.permissions.Permissions;
import org.mozilla.gecko.prompts.PromptService;
import org.mozilla.gecko.R;
import org.mozilla.gecko.text.TextSelection;
import org.mozilla.gecko.util.ActivityUtils;
import org.mozilla.gecko.util.ColorUtil;
import org.mozilla.gecko.widget.ActionModePresenter;
public class WebAppActivity extends AppCompatActivity
implements GeckoView.NavigationListener {
implements ActionModePresenter,
GeckoView.NavigationListener {
private static final String LOGTAG = "WebAppActivity";
public static final String MANIFEST_PATH = "MANIFEST_PATH";
@ -52,6 +56,9 @@ public class WebAppActivity extends AppCompatActivity
private PromptService mPromptService;
private DoorHangerPopup mDoorHangerPopup;
private ActionMode mActionMode;
private TextSelection mTextSelection;
private boolean mIsFullScreenMode;
private boolean mIsFullScreenContent;
private boolean mCanGoBack;
@ -93,6 +100,9 @@ public class WebAppActivity extends AppCompatActivity
mPromptService = new PromptService(this, mGeckoView.getEventDispatcher());
mDoorHangerPopup = new DoorHangerPopup(this, mGeckoView.getEventDispatcher());
mTextSelection = TextSelection.Factory.create(mGeckoView, this);
mTextSelection.create();
final GeckoViewSettings settings = mGeckoView.getSettings();
settings.setBoolean(GeckoViewSettings.USE_MULTIPROCESS, false);
@ -108,6 +118,7 @@ public class WebAppActivity extends AppCompatActivity
@Override
public void onDestroy() {
mTextSelection.destroy();
mDoorHangerPopup.destroy();
mPromptService.destroy();
@ -284,4 +295,18 @@ public class WebAppActivity extends AppCompatActivity
mIsFullScreenMode = fullScreen;
updateFullScreen();
}
@Override // ActionModePresenter
public void startActionMode(final ActionMode.Callback callback) {
endActionMode();
mActionMode = startSupportActionMode(callback);
}
@Override // ActionModePresenter
public void endActionMode() {
if (mActionMode != null) {
mActionMode.finish();
mActionMode = null;
}
}
}