android: set layerView to TextCursorView{Layer} when available
Change-Id: I3dbb7747ad6d5ce44ca286023e6c8fbc5a19a6b7
This commit is contained in:
parent
656d3f9ee4
commit
626e1a2d6d
@ -155,18 +155,19 @@ public class LibreOfficeMainActivity extends ActionBarActivity {
|
||||
sLOKitThread.clearQueue();
|
||||
}
|
||||
|
||||
mTextSelection = new TextSelection(mAppContext);
|
||||
mTextCursorLayer = new TextCursorLayer(mAppContext);
|
||||
|
||||
mLayerClient = new GeckoLayerClient(this);
|
||||
mLayerClient.setZoomConstraints(new ZoomConstraints(true));
|
||||
LayerView layerView = (LayerView) findViewById(R.id.layer_view);
|
||||
// register TextSelection and TextCursorLayer in LayerView
|
||||
mLayerClient.setView(layerView);
|
||||
layerView.addLayer(mTextSelection);
|
||||
layerView.addLayer(mTextCursorLayer);
|
||||
layerView.setInputConnectionHandler(new LOKitInputConnectionHandler());
|
||||
mLayerClient.notifyReady();
|
||||
|
||||
// create and register TextSelection in LayerView
|
||||
mTextSelection = new TextSelection(mAppContext);
|
||||
layerView.addLayer(mTextSelection);
|
||||
|
||||
// create TextCursorLayer
|
||||
mTextCursorLayer = new TextCursorLayer(mAppContext, layerView);
|
||||
}
|
||||
|
||||
private boolean copyFileToTemp() {
|
||||
|
@ -32,11 +32,13 @@ public class TextCursorLayer extends Layer {
|
||||
private float mViewTop;
|
||||
private float mViewZoom;
|
||||
|
||||
public TextCursorLayer(Activity context) {
|
||||
public TextCursorLayer(Activity context, LayerView layerView) {
|
||||
mCursorView = (TextCursorView) context.findViewById(R.id.text_cursor_view);
|
||||
if (mCursorView == null) {
|
||||
Log.e(LOGTAG, "Failed to initialize TextCursorLayer - CursorView is null");
|
||||
}
|
||||
layerView.addLayer(this);
|
||||
mCursorView.initialize(layerView);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -57,25 +57,23 @@ public class TextCursorView extends View implements View.OnTouchListener {
|
||||
|
||||
public TextCursorView(Context context) {
|
||||
super(context);
|
||||
initialize();
|
||||
}
|
||||
|
||||
public TextCursorView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
initialize();
|
||||
}
|
||||
|
||||
public TextCursorView(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
initialize();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the selection and cursor view.
|
||||
*/
|
||||
private void initialize() {
|
||||
public void initialize(LayerView layerView) {
|
||||
if (!mInitialized) {
|
||||
setOnTouchListener(this);
|
||||
mLayerView = layerView;
|
||||
|
||||
mCursorPaint.setColor(Color.BLACK);
|
||||
mCursorPaint.setAlpha(0xFF);
|
||||
@ -100,15 +98,9 @@ public class TextCursorView extends View implements View.OnTouchListener {
|
||||
* @param position - new position of the cursor
|
||||
*/
|
||||
public void changeCursorPosition(RectF position) {
|
||||
LayerView layerView = LOKitShell.getLayerView();
|
||||
if (layerView == null) {
|
||||
Log.e(LOGTAG, "Can't position cursor because layerView is null");
|
||||
return;
|
||||
}
|
||||
|
||||
mCursorPosition = position;
|
||||
|
||||
ImmutableViewportMetrics metrics = layerView.getViewportMetrics();
|
||||
ImmutableViewportMetrics metrics = mLayerView.getViewportMetrics();
|
||||
repositionWithViewport(metrics.viewportRectLeft, metrics.viewportRectTop, metrics.zoomFactor);
|
||||
}
|
||||
|
||||
@ -287,6 +279,10 @@ public class TextCursorView extends View implements View.OnTouchListener {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void setLayerView(LayerView layerView) {
|
||||
this.mLayerView = layerView;
|
||||
}
|
||||
}
|
||||
|
||||
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
||||
|
Loading…
x
Reference in New Issue
Block a user