Skip to content

Commit

Permalink
fix package name
Browse files Browse the repository at this point in the history
  • Loading branch information
jaeger committed Sep 9, 2016
1 parent 69f7111 commit 07e5621
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 29 deletions.
2 changes: 1 addition & 1 deletion library/src/main/java/com/jaeger/library/L.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.jaeger.selectabletexthelper;
package com.jaeger.library;

import android.util.Log;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.jaeger.selectabletexthelper;
package com.jaeger.library;

/**
* Created by Jaeger on 16/8/30.
Expand Down
2 changes: 1 addition & 1 deletion library/src/main/java/com/jaeger/library/SelectUtil.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.jaeger.selectabletexthelper;
package com.jaeger.library;

import android.content.Context;
import android.text.Layout;
Expand Down
28 changes: 17 additions & 11 deletions library/src/main/java/com/jaeger/library/SelectableTextHelper.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.jaeger.library;

import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
Expand Down Expand Up @@ -28,13 +30,13 @@ public class SelectableTextHelper {
private final static String TAG = SelectableTextHelper.class.getSimpleName();

private final static int DEFAULT_SELECT_LENGTH = 1;
private static final int DEFAULT_SHOW_DURATION = 200;
private static final int DEFAULT_SHOW_DURATION = 100;

private CursorHandle mStartHandle;
private CursorHandle mEndHandle;
private OperateWindow mOperateWindow;
private com.jaeger.selectabletexthelper.SelectionInfo mSelectionInfo = new com.jaeger.selectabletexthelper.SelectionInfo();
private com.jaeger.selectabletexthelper.OnSelectListener mSelectListener;
private SelectionInfo mSelectionInfo = new SelectionInfo();
private OnSelectListener mSelectListener;

private Context mContext;
private TextView mTextView;
Expand Down Expand Up @@ -180,7 +182,7 @@ private void show(int x, int y) {
if (mStartHandle == null) mStartHandle = new CursorHandle(mTextView, true);
if (mEndHandle == null) mEndHandle = new CursorHandle(mTextView, false);

int startOffset = com.jaeger.selectabletexthelper.SelectUtil.getPreciseOffset(mTextView, x, y);
int startOffset = SelectUtil.getPreciseOffset(mTextView, x, y);
int endOffset = startOffset + DEFAULT_SELECT_LENGTH;
if (mTextView.getText() instanceof Spannable) {
mSpannable = (Spannable) mTextView.getText();
Expand Down Expand Up @@ -223,7 +225,7 @@ private void selectText(int startPos, int endPos) {
}
}

public void setSelectListener(com.jaeger.selectabletexthelper.OnSelectListener selectListener) {
public void setSelectListener(OnSelectListener selectListener) {
mSelectListener = selectListener;
}

Expand Down Expand Up @@ -258,10 +260,12 @@ public OperateWindow(final Context context) {
contentView.findViewById(R.id.tv_copy).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ClipboardManager clip = (ClipboardManager) mContext.getSystemService(Context.CLIPBOARD_SERVICE);
clip.setPrimaryClip(
ClipData.newPlainText(mSelectionInfo.mSelectionContent, mSelectionInfo.mSelectionContent));
if (mSelectListener != null) {
mSelectListener.onTextSelected(mSelectionInfo.mSelectionContent);
}
//Toast.makeText(context, mSelectionInfo.mSelectionContent, Toast.LENGTH_SHORT).show();
SelectableTextHelper.this.removeSelect();
SelectableTextHelper.this.hideSelect();
}
Expand All @@ -281,8 +285,8 @@ public void show() {
int posY = layout.getLineTop(layout.getLineForOffset(mSelectionInfo.mStart)) + mTempCoors[1] - mHeight - 16;
if (posX <= 0) posX = 16;
if (posY < 0) posY = 16;
if (posX + mWidth > com.jaeger.selectabletexthelper.SelectUtil.getScreenWidth(mContext)) {
posX = com.jaeger.selectabletexthelper.SelectUtil.getScreenWidth(mContext) - mWidth - 16;
if (posX + mWidth > SelectUtil.getScreenWidth(mContext)) {
posX = SelectUtil.getScreenWidth(mContext) - mWidth - 16;
}
mWindow.showAtLocation(mTextView, Gravity.NO_GRAVITY, posX, posY);
}
Expand Down Expand Up @@ -393,7 +397,7 @@ public void update(int x, int y) {
//x += mTempCoors[0] - mTextView.getPaddingLeft();
y = y - mTempCoors[1];

int offset = com.jaeger.selectabletexthelper.SelectUtil.getHysteresisOffset(mTextView, x, y, oldOffset);
int offset = SelectUtil.getHysteresisOffset(mTextView, x, y, oldOffset);

if (offset != oldOffset) {
removeSelect();
Expand Down Expand Up @@ -440,10 +444,12 @@ private void updateCursor() {
}

public void show(int x, int y) {
com.jaeger.selectabletexthelper.L.d("show x is " + x + " show y is " + y);
mTextView.getLocationInWindow(mTempCoors);
int offset = isLeft ? mWidth : 0;
mPopupWindow.showAtLocation(mTextView, Gravity.NO_GRAVITY, +x - offset + getExtraX(), y + getExtraY());
if (isLeft) {
L.d("y is " + y + "extra y is " + getExtraY());
}
mPopupWindow.showAtLocation(mTextView, Gravity.NO_GRAVITY, x - offset + getExtraX(), y + getExtraY());
}

public int getExtraX() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.jaeger.selectabletexthelper;
package com.jaeger.library;

/**
* Created by Jaeger on 16/8/30.
Expand Down
1 change: 0 additions & 1 deletion sample/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
<activity android:name="com.jaeger.selectabletexthelper.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>

<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package com.jaeger.selectabletexthelper;

import android.content.ClipData;
import android.content.Context;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import com.jaeger.library.OnSelectListener;
import com.jaeger.library.SelectableTextHelper;

public class MainActivity extends AppCompatActivity {
Expand All @@ -29,20 +28,12 @@ protected void onCreate(Bundle savedInstanceState) {
//mTvTest.setTextIsSelectable(true);

mSelectableText = new SelectableTextHelper(mTvTest);
mSelectableText.setSelectListener(new com.jaeger.selectabletexthelper.OnSelectListener() {
mSelectableText.setSelectListener(new OnSelectListener() {
@Override
public void onTextSelected(CharSequence content) {
android.content.ClipboardManager clip =
(android.content.ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
clip.setPrimaryClip(ClipData.newPlainText(content, content));
//Toast.makeText(MainActivity.this, content.toString(), Toast.LENGTH_SHORT).show();


}
});
}

@Override
protected void onPause() {
//mSelectableText.destroy();
super.onPause();
}
}

0 comments on commit 07e5621

Please sign in to comment.