Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename copy bug #98 #200

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@
import io.github.subhamtyagi.lastlauncher.LauncherActivity;
import io.github.subhamtyagi.lastlauncher.R;
import io.github.subhamtyagi.lastlauncher.utils.DbUtils;
import io.github.subhamtyagi.lastlauncher.views.textview.MyEditText;

public class RenameInputDialogs extends Dialog implements TextView.OnEditorActionListener {

final private String appPackage;
private final LauncherActivity launcherActivity;
private final String oldAppName;


private EditText mAppName;
private MyEditText mAppName;

public RenameInputDialogs(Context context, String appPackage, String oldAppName, LauncherActivity launcherActivity) {
super(context);
Expand All @@ -53,7 +53,7 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.dialog_rename_input);
mAppName = findViewById(R.id.ed_input);
mAppName = (MyEditText) findViewById(R.id.ed_input);
mAppName.setText(oldAppName);
mAppName.setOnEditorActionListener(this);
mAppName.setEnabled(true);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@

package io.github.subhamtyagi.lastlauncher.views.textview;

import android.annotation.SuppressLint;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.text.Layout;
import android.util.AttributeSet;
import android.util.Log;
import android.view.ContextMenu;
import android.view.Gravity;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.widget.EditText;
import android.widget.PopupWindow;
import android.widget.Toast;

/**
* An EditText, which notifies when something was cut/copied/pasted inside it.
*
* @author Lukas Knuth
* @version 1.0
*/
@SuppressLint("NewApi")
public class MyEditText extends EditText implements
MenuItem.OnMenuItemClickListener {
private static final int ID_SELECTION_MODE = android.R.id.selectTextMode;
// Selection context mode
private static final int ID_SELECT_ALL = android.R.id.selectAll;
private static final int ID_SELECT_START = android.R.id.startSelectingText;
private static final int ID_SELECT_END = android.R.id.stopSelectingText;
private static final int ID_SELECT = android.R.id.selectedIcon;
private static final int ID_CUT = android.R.id.cut;
private static final int ID_COPY = android.R.id.copy;
private static final int ID_PASTE = android.R.id.paste;

private final Context mContext;

/*
* Just the constructors to create a new EditText...
*/
public MyEditText(Context context) {
super(context);
this.mContext = context;
}

public MyEditText(Context context, AttributeSet attrs) {
super(context, attrs);
this.mContext = context;
}

public MyEditText(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
this.mContext = context;
}
//代码效果,有弹出框选择 粘贴,复制,剪切,类似qq效果.....
@Override
protected void onCreateContextMenu(ContextMenu menu) {
menu.add(0, ID_PASTE, 0, "paste").setOnMenuItemClickListener(this);
menu.add(0, ID_CUT, 1, "cut").setOnMenuItemClickListener(this);
menu.add(0, ID_COPY, 1, "copy").setOnMenuItemClickListener(this);
menu.add(0, ID_SELECT_ALL, 1, "select all").setOnMenuItemClickListener(this);
super.onCreateContextMenu(menu);
}

@Override
public boolean onMenuItemClick(MenuItem item) {
return onTextContextMenuItem(item.getItemId());
}

@Override
public boolean onTextContextMenuItem(int id) {
boolean consumed = super.onTextContextMenuItem(id);
switch (id) {
case android.R.id.cut:
onTextCut();
break;
case android.R.id.paste:
onTextPaste();
break;
case android.R.id.copy:
onTextCopy();
}
return consumed;
}

/**
* Text was cut from this EditText.
*/
public void onTextCut() {Toast.makeText(mContext, "Cut success", Toast.LENGTH_SHORT).show();}
/**
* Text was copied from this EditText.
*/
public void onTextCopy() {Toast.makeText(mContext, "Copy success", Toast.LENGTH_SHORT).show();}
/**
* Text was pasted into the EditText.
*/
public void onTextPaste() {
Toast.makeText(mContext, "Paste sucess", Toast.LENGTH_SHORT).show();
}


}




//public static class Builder {
// private TextView mTextView;
// private int mCursorHandleColor = 0xFF1379D6;
// private int mSelectedColor = 0xFFAFE1F4;
// private float mCursorHandleSizeInDp = 24;
//
// public Builder(TextView textView) {
// mTextView = textView;
// }
//
// public Builder setCursorHandleColor(@ColorInt int cursorHandleColor) {
// mCursorHandleColor = cursorHandleColor;
// return this;
// }
//
// public Builder setCursorHandleSizeInDp(float cursorHandleSizeInDp) {
// mCursorHandleSizeInDp = cursorHandleSizeInDp;
// return this;
// }
//
// public Builder setSelectedColor(@ColorInt int selectedBgColor) {
// mSelectedColor = selectedBgColor;
// return this;
// }
//
// public SelectableTextHelper build() {
// return new SelectableTextHelper(this);
// }
//}
//}


8 changes: 4 additions & 4 deletions app/src/main/res/layout/dialog_rename_input.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
~ along with this program. If not, see <http://www.gnu.org/licenses/>.
-->


<EditText
<io.github.subhamtyagi.lastlauncher.views.textview.MyEditText

xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ed_input"
Expand All @@ -33,7 +32,8 @@
android:textSelectHandle="@drawable/edit_text_select_handle"
android:textSelectHandleLeft="@drawable/edit_text_select_handle"
android:textSelectHandleRight="@drawable/edit_text_select_handle"
android:textIsSelectable="false"
android:textIsSelectable="true"
android:drawSelectorOnTop="true"
android:textCursorDrawable="@drawable/cursor"
android:background="@drawable/edit_text"
android:autofillHints="App Name"></EditText>
android:autofillHints="App Name" />
20 changes: 20 additions & 0 deletions app/src/main/res/layout/edit_text.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<io.github.subhamtyagi.lastlauncher.views.textview.MyEditText
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textIsSelectable="true"
android:textSize="12dp"

android:textSelectHandle="@drawable/edit_text_select_handle"
android:textSelectHandleLeft="@drawable/edit_text_select_handle"
android:textSelectHandleRight="@drawable/edit_text_select_handle"
android:textCursorDrawable="@drawable/cursor"
/>

</RelativeLayout>