Open Custom dialog on text selection of webview - android

I have implement code of text selection in webview. It's working very fine without any issue. But I want to open custom dialog instead of default dialog. The which I have use its link is below
How to override default text selection of android webview os 4.1+?
But its not working for custom dialog.
Find code below
public class CustomWebView extends WebView {
private Context context;
private ActionMode mActionMode;
private ActionMode.Callback mSelectActionModeCallback;
private GestureDetector mDetector;
public CustomWebView(Context context) {
super(context);
this.context = context;
WebSettings webviewSettings = getSettings();
webviewSettings.setJavaScriptEnabled(true);
// add JavaScript interface for copy
WebAppInterface webAppInterface = new WebAppInterface(context);
addJavascriptInterface(webAppInterface, "JSInterface");
}
public CustomWebView(Context context, AttributeSet attrs) {
super(context, attrs);
this.context = context;
}
public CustomWebView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
this.context = context;
}
// this will over ride the default action bar on long press
#Override
public ActionMode startActionMode(ActionMode.Callback callback) {
ViewParent parent = getParent();
if (parent == null) {
return null;
}
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
String name = callback.getClass().toString();
if (name.contains("SelectActionModeCallback")) {
mSelectActionModeCallback = callback;
mDetector = new GestureDetector(context, new CustomGestureListener());
}
}
CustomActionModeCallback mActionModeCallback = new CustomActionModeCallback();
return super.startActionMode(mActionModeCallback);
}
private class CustomActionModeCallback implements ActionMode.Callback {
#Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
MenuInflater inflater = mode.getMenuInflater();
inflater.inflate(com.depressiv.R.menu.menu, menu);
return true;
}
#Override
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
return false;
}
#Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
switch (item.getItemId()) {
case R.id.copy:
getSelectedData();
mode.finish();
return true;
case R.id.share:
mode.finish();
return true;
default:
mode.finish();
return false;
}
}
#Override
public void onDestroyActionMode(ActionMode mode) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
clearFocus();
} else {
if (mSelectActionModeCallback != null) {
mSelectActionModeCallback.onDestroyActionMode(mode);
}
mActionMode = null;
}
}
}
private void getSelectedData() {
String js = "(function getSelectedText() {" +
"var txt;" +
"if (window.getSelection) {" +
"txt = window.getSelection().toString();" +
"} else if (window.document.getSelection) {" +
"txt = window.document.getSelection().toString();" +
"} else if (window.document.selection) {" +
"txt = window.document.selection.createRange().text;" +
"}" +
"JSInterface.getText(txt);" +
"})()";
// calling the js function
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
evaluateJavascript("javascript:" + js, null);
} else {
loadUrl("javascript:" + js);
}
}
private class CustomGestureListener extends GestureDetector.SimpleOnGestureListener {
#Override
public boolean onSingleTapUp(MotionEvent e) {
if (mActionMode != null) {
mActionMode.finish();
return true;
}
return false;
}
}
#Override
public boolean onTouchEvent(MotionEvent event) {
// Send the event to our gesture detector
// If it is implemented, there will be a return value
if (mDetector != null)
mDetector.onTouchEvent(event);
// If the detected gesture is unimplemented, send it to the superclass
return super.onTouchEvent(event);
}
}
WebAppInterface code
public class WebAppInterface {
Context mContext;
WebAppInterface(Context c) {
mContext = c;
}
#JavascriptInterface
public void getText(String text) {
// put selected text into clipdata
ClipboardManager clipboard = (ClipboardManager)
mContext.getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("simple text", text);
clipboard.setPrimaryClip(clip);
// gives the toast for selected text
Toast.makeText(mContext, text, Toast.LENGTH_SHORT).show();
}
}

Related

How to implement select all button to select all items in recyclerview using actionmode and selectiontracker?

I have this code in my MainActivity
recyclerView.setAdapter(customAdapter);
customAdapter.submitList(path_list);
selectionTracker = new SelectionTracker.Builder<>(
"my-selection-id",
recyclerView,
new ScrollKeyProvider(1, path_list),
new ScrollItemDetailsLookup(recyclerView),
StorageStrategy.createLongStorage()
)
.withOnItemActivatedListener(new OnItemActivatedListener<Long>() {
#Override
public boolean onItemActivated(#NonNull ItemDetailsLookup.ItemDetails<Long> item, #NonNull MotionEvent e) {
Log.d("TAG", "Selected ItemId: " + item.toString());
return true;
}
})
.withOnDragInitiatedListener(new OnDragInitiatedListener() {
#Override
public boolean onDragInitiated(#NonNull MotionEvent e) {
Log.d("TAG", "onDragInitiated");
return true;
}
}).build();
customAdapter.setSelectionTracker(selectionTracker);
selectionTracker.addObserver(new SelectionTracker.SelectionObserver() {
#Override
public void onItemStateChanged(#NonNull Object key, boolean selected) {
super.onItemStateChanged(key, selected);
}
#Override
public void onSelectionRefresh() {
super.onSelectionRefresh();
}
#Override
public void onSelectionChanged() {
super.onSelectionChanged();
if (selectionTracker.hasSelection() && actionMode == null) {
actionMode = startSupportActionMode(new ActionModeController(ScrollActivity.this, selectionTracker));
actionMode.getMenu().findItem(R.id.action_item_count).setTitle("" + selectionTracker.getSelection().size());
} else if (!selectionTracker.hasSelection() && actionMode != null) {
actionMode.finish();
actionMode = null;
} else {
actionMode.getMenu().findItem(R.id.action_item_count).setTitle("" + selectionTracker.getSelection().size());
}
Iterator<String> itemIterable = selectionTracker.getSelection().iterator();
while (itemIterable.hasNext()) {
Log.i("TAG", itemIterable.next());
}
}
#Override
public void onSelectionRestored() {
super.onSelectionRestored();
}
});
This is my ActionMode callback code
public class ActionModeController implements ActionMode.Callback {
private final Context context;
private final SelectionTracker selectionTracker;
public ActionModeController(Context context, SelectionTracker selectionTracker) {
this.context = context;
this.selectionTracker = selectionTracker;
}
#Override
public boolean onCreateActionMode(androidx.appcompat.view.ActionMode mode, Menu menu) {
mode.getMenuInflater().inflate(R.menu.action_menu, menu);
return true;
}
#Override
public boolean onPrepareActionMode(androidx.appcompat.view.ActionMode mode, Menu menu) {
return false;
}
#Override
public boolean onActionItemClicked(androidx.appcompat.view.ActionMode mode, MenuItem item) {
if(item.getItemId()==R.id.action_clear){
if (selectionTracker.hasSelection()){
selectionTracker.clearSelection();
}
}
else if(item.getItemId()==R.id.action_select_all){
// **THIS IS PLACE WHERE I NEED HELP TO ENTER CODE FOR SELECT ALL FUNCTIONALITY**
}
return false;
}
#Override
public void onDestroyActionMode(androidx.appcompat.view.ActionMode mode) {
selectionTracker.clearSelection();
}
}
What should I do in select all section in onActionItemClicked for selecting all items in Recyclerview using SelectionTracker?
You can see for the clear option in onActionItemClicked, I have used functions of selectionTracker to clear all the selected items. I am expecting similar solution for select all option too.
Kotlin version using PagingDataAdapter - can be reworked replacing the snapshot to items in your implementation.
var itemsArray = arrayListOf<Long>()
adapter?.snapshot()?.items?.forEach {
if (!selectionTracker.isSelected(it.id.toLong()))
itemsArray.add(it.id.toLong())
}
selectionTracker?.setItemsSelected(itemsArray.asIterable(), true)

Android - WebView Default Selected Toolbar's Copy Button doesn't Work

As you know, when selecting a text, it appears a popup menu.
When I click the "copy" on the menu, I can't get selected/copied text but the event is fired. (in MyMenuItemOnMenuItemClickListener class > OnMenuItemClick method)
--
If I copy it using "Share > Copy to Clipboard" menu, I can get it. The event isn't fired. (This is not our goal. Just for comparison.)
And if I copy any text except the WebView and then click the copy button (not 'copy to clipboard') I could get last copied text. What's wrong with Webview's copy button? Why I couldn't get selected text?
There is no problem with iOS.
--
Xaml;
CustomWebView Class;
public class CustomWebView : WebView
{
public static readonly BindableProperty UriProperty = BindableProperty.Create(
propertyName: "Uri",
returnType: typeof(string),
declaringType: typeof(CustomWebView),
defaultValue: default(string));
public string Uri
{
get { return (string)GetValue(UriProperty); }
set { SetValue(UriProperty, value); }
}
}
Custom Renderer;
[assembly: ExportRenderer(typeof(CustomWebView), typeof(WebViewRendererDroid))]
namespace TApp.Droid
{
public class WebViewRendererDroid : ViewRenderer<CustomWebView, Android.Webkit.WebView>, IOnPrimaryClipChangedListener /* ViewRenderer<CustomWebView, Android.Webkit.WebView>*/
{
Context _context;
public WebViewRendererDroid(Context context) : base(context)
{
_context = context;
}
protected override void OnElementChanged(ElementChangedEventArgs<CustomWebView> e)
{
base.OnElementChanged(e);
if (Control == null)
{
var webView = new Android.Webkit.WebView(_context);
webView.Settings.JavaScriptEnabled = true;
webView.Settings.AllowContentAccess = true;
webView.LoadUrl("https://learn.microsoft.com/en-us/xamarin/ios/");
SetNativeControl(webView);
}
if (e.NewElement != null)
{
Control.LoadUrl("https://learn.microsoft.com/en-us/xamarin/ios/");
}
}
ClipboardManager myClipBoard;
public void OnPrimaryClipChanged()
{
ClipData clipData = myClipBoard.PrimaryClip;
ClipData.Item item = clipData.GetItemAt(0);
MessagingCenter.Send<object, string>(this, "Hi", item.Text);
}
}
}
MainActivity.cs;
namespace TApp.Droid
{
[Activity(Label = "TApp", Icon = "#mipmap/icon", Theme = "#style/MainTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
protected override void OnCreate(Bundle savedInstanceState)
{
TabLayoutResource = Resource.Layout.Tabbar;
ToolbarResource = Resource.Layout.Toolbar;
base.OnCreate(savedInstanceState);
global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
LoadApplication(new App());
}
public override void OnActionModeStarted(ActionMode mode)
{
IMenu menu = mode.Menu;
menu.GetItem(0).SetOnMenuItemClickListener(new MyMenuItemOnMenuItemClickListener(this));
base.OnActionModeStarted(mode);
}
}
public class MyMenuItemOnMenuItemClickListener : Java.Lang.Object, IMenuItemOnMenuItemClickListener
{
private MainActivity mContext;
public MyMenuItemOnMenuItemClickListener(MainActivity activity)
{
this.mContext = activity;
}
public bool OnMenuItemClick(IMenuItem item)
{
var clipboard = (ClipboardManager)mContext.GetSystemService(Context.ClipboardService);
var clipboard2 = (Android.Text.ClipboardManager)Android.App.Application.Context.GetSystemService(Context.ClipboardService);
var pasteData = "";
string aaa = clipboard.Text;
if (!(clipboard.HasPrimaryClip))
{
// If it does contain data, decide if you can handle the data.
}
else if (!(clipboard.PrimaryClipDescription.HasMimeType(ClipDescription.MimetypeTextPlain)))
{
// since the clipboard has data but it is not plain text
}
else
{
//since the clipboard contains plain text
var copiedText = clipboard.PrimaryClip.GetItemAt(0);
// Gets the clipboard as text
pasteData = copiedText.Text;
}
Toast.MakeText(mContext, pasteData, ToastLength.Short).Show();
return true;
}
}
}
i write a simple sample,you could check it :
1.define an Interface ActionSelectListener in your Android.Project:
public interface ActionSelectListener
{
void onClick(string selectText);
}
2.custom a WebView CustomActionWebViewin your Android.Project:
class CustomActionWebView:WebView,IMenuItemOnMenuItemClickListener
{
public CustomActionWebView(Context context):base(context)
{
_context = context;
}
public CustomActionWebView(Context context, IAttributeSet attrs):base(context,attrs)
{
_context = context;
}
public CustomActionWebView(Context context, IAttributeSet attrs, int defStyleAttr):base(context,attrs,defStyleAttr)
{
_context = context;
}
private Context _context;
ActionMode mActionMode;
static ActionSelectListener mActionSelectListener;
private ActionMode resolveActionMode(ActionMode actionMode)
{
if (actionMode != null)
{
IMenu menu = actionMode.Menu;
mActionMode = actionMode;
IMenuItem menuItem = menu.GetItem(0);//here only handle the copy button
menuItem.SetOnMenuItemClickListener(this);
}
mActionMode = actionMode;
return actionMode;
}
public override ActionMode StartActionMode(ActionMode.ICallback callback)
{
ActionMode actionMode = base.StartActionMode(callback);
return resolveActionMode(actionMode);
}
public override ActionMode StartActionMode(ActionMode.ICallback callback, [GeneratedEnum] ActionModeType type)
{
ActionMode actionMode = base.StartActionMode(callback, type);
return resolveActionMode(actionMode);
}
private void releaseAction()
{
if (mActionMode != null)
{
mActionMode.Finish();
mActionMode = null;
}
}
/**
* When you click, get the selected text from the page and drop it back to the native js interface
* #param passes in the text of the clicked item, which is returned to the native interface via js
*/
private void getSelectedData()
{
String js = "(function getSelectedText() {" +
"var txt;" +
"if (window.getSelection) {" +
"txt = window.getSelection().toString();" +
"} else if (window.document.getSelection) {" +
"txt = window.document.getSelection().toString();" +
"} else if (window.document.selection) {" +
"txt = window.document.selection.createRange().text;" +
"}" +
"JSInterface.callback(txt);" +
"})()";
if (Build.VERSION.SdkInt >= Build.VERSION_CODES.Kitkat)
{
EvaluateJavascript( js, null);
}
else
{
LoadUrl("javascript:" + js);
}
}
public void linkJSInterface()
{
AddJavascriptInterface(new ActionSelectInterface(_context), "JSInterface");
}
/**
* click call back
* #param actionSelectListener
*/
public void setActionSelectListener(ActionSelectListener actionSelectListener)
{
mActionSelectListener = actionSelectListener;
}
public bool OnMenuItemClick(IMenuItem item)
{
getSelectedData();
releaseAction();
return true;
}
/**
* js call back interface
*/
class ActionSelectInterface : Java.Lang.Object
{
Context mContext;
public ActionSelectInterface(Context c)
{
mContext = c;
}
[JavascriptInterface]
[Export]
public void callback(string value)
{
if (mActionSelectListener != null)
{
mActionSelectListener.onClick(value);
}
}
}
}
3.use in your CustomRenderer :
[assembly: ExportRenderer(typeof(CustomWebView), typeof(WebViewRendererDroid))]
namespace TApp.Droid
{
public class WebViewRendererDroid : ViewRenderer<CustomWebView, Android.Webkit.WebView>, ActionSelectListenerr /* ViewRenderer<CustomWebView, Android.Webkit.WebView>*/
{
Context _context;
public WebViewRendererDroid(Context context) : base(context)
{
_context = context;
}
protected override void OnElementChanged(ElementChangedEventArgs<CustomWebView> e)
{
base.OnElementChanged(e);
if (Control == null)
{
var webView = new CustomActionWebView(_context);
webView.Settings.JavaScriptEnabled = true;
webView.Settings.AllowContentAccess = true;
webView.linkJSInterface();
webView.LoadUrl("https://learn.microsoft.com/en-us/xamarin/ios/");
SetNativeControl(webView);
}
}
public void onClick(string selectText)
{
ClipboardManager cm = (ClipboardManager)_context.GetSystemService(Context.ClipboardService);
// Place the text in the system clipboard.
ClipData clipData = ClipData.NewPlainText(null, selectText);
// Set (copy) the dataset to the clipboard
cm.PrimaryClip = clipData;
}
}

(Chromium for android studio) How to use addPossiblyUnsafeJavascriptInterface?

In ChromeActivity.Java, I customized some code, but it's not working like webview's addJavascriptInterface I did:
import org.chromium.content.browser.JavascriptInterface;
#SuppressLint("JavascriptInterface")
#Override
public void createContextualSearchTab(String searchUrl) {
Tab currentTab = getActivityTab();
if (currentTab == null) return;
Class<? extends Annotation> requiredAnnotation = JavascriptInterface.class;
currentTab.getWebContents().addPossiblyUnsafeJavascriptInterface(new MyJavaScriptInterface(this), "MyJS", requiredAnnotation);
TabCreator tabCreator = getTabCreator(currentTab.isIncognito());
if (tabCreator == null) return;
tabCreator.createNewTab(
new LoadUrlParams(searchUrl, PageTransition.LINK),
TabModel.TabLaunchType.FROM_LINK, currentTab);
}
public class MyJavaScriptInterface {
ChromeActivity context;
public MyJavaScriptInterface(ChromeActivity activity) {
this.context = activity;
}
#JavascriptInterface
#SuppressWarnings("unused")
public void closeApp(){
this.context._closeApp();
}
}
Chromium for android studio source code: https://github.com/kuoruan/Chromium-Android
Since Chromium 65, addPossiblyUnsafeJavascriptInterface has been changed to addPossiblyUnsafeInterface
mTabModelSelectorTabObserver = new TabModelSelectorTabObserver(mTabModelSelector) {
#Override
public void onShown(Tab tab) {
setStatusBarColor(tab, tab.getThemeColor());
JavascriptInjector ji = JavascriptInjector.fromWebContents(tab.getWebContents());
ji.setAllowInspection(true);
ji.addPossiblyUnsafeInterface(new MyJavaScriptInterface(ChromeActivity.this), "BEEB", JavascriptInterface.class);
}
}
public class MyJavaScriptInterface {
ChromeActivity context;
public MyJavaScriptInterface(ChromeActivity activity) {
this.context = activity;
}
#JavascriptInterface
public void closeApp(){
Context context = getApplicationContext();
int duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(context, "ccccccccccccccccccccccccccccccc", duration);
toast.show();
}
}

Swiping the view pager fragment should not move the tabs

My program has a boolean variable name "isCorrect". I want, when isCorrect is false then the user should not able to open any other tab. (Either by swiping or by selecting tab). I tried to do this by below given logic but this cause the application to hang.
final boolean isCorrect=false;
tabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
#Override
public void onTabSelected(TabLayout.Tab tab) {
if(!isCorrect){
if(tab.getPosition()==1){
mViewPager.setCurrentItem(0);
}
}else{
mViewPager.setCurrentItem(1);
}
}
Define a custom ViewPager subclass. The class inherits from ViewPager and includes a new method called setSwipeable to control if swipe events are enabled or not. Make sure to change layout file.
public class LockableViewPager extends ViewPager {
private boolean swipeable;
public LockableViewPager(Context context) {
super(context);
}
public LockableViewPager(Context context, AttributeSet attrs) {
super(context, attrs);
this.swipeable = true;
}
#Override
public boolean onTouchEvent(MotionEvent event) {
if (this.swipeable) {
return super.onTouchEvent(event);
}
return false;
}
#Override
public boolean onInterceptTouchEvent(MotionEvent event) {
if (this.swipeable) {
return super.onInterceptTouchEvent(event);
}
return false;
}
public void setSwipeable(boolean swipeable) {
this.swipeable = swipeable;
}
}
When flag is false disable swipe.
if (!flag) {
mViewPager.setSwipeable(false);
} else {
mViewPager.setSwipeable(true);
}

RelativeLayout onClick onTouch not working

I am having trouble attaching onTouch/onClick events for a RelativeLayout. I have searched a lot on internet, and could find the possible solution as using dispatchTouchEvent(MotionEvent). But I don't want to use this way, as I am having some trouble implementing that as well. Code is attached below.
public class ConnectMeDigit extends RelativeLayout implements AddressAware {
public ConnectMeDigit(Context context, AttributeSet attrs) {
super(context, attrs);
View view = LayoutInflater.from(context).inflate(R.layout.numpad_digit, this);
Typeface face=Typeface.createFromAsset(context.getAssets(), "helveticathin.ttf");//"helveticaultralight.ttf");
String xmlProvidedSize = attrs.getAttributeValue("http://schemas.android.com/apk/res/android", "tag");
TextView keypadnumber = (TextView) view.findViewById(R.id.keypadnumber);
TextView keypadalphabets = (TextView) view.findViewById(R.id.keypadalphabets);
TextView keypadplussubscript = (TextView) view.findViewById(R.id.keypadplussubscript);
keypadnumber.setTypeface(face);
keypadalphabets.setTypeface(face);
keypadplussubscript.setTypeface(face);
keypadplussubscript.setVisibility(View.GONE);
keypadnumber.setText(xmlProvidedSize);
if(xmlProvidedSize.equals("1")) {
keypadalphabets.setVisibility(View.GONE);
}
else if(xmlProvidedSize.equals("2")) {
keypadalphabets.setText("ABC");
}
else if(xmlProvidedSize.equals("3")) {
keypadalphabets.setText("DEF");
}
else if(xmlProvidedSize.equals("4")) {
keypadalphabets.setText("GHI");
}
else if(xmlProvidedSize.equals("5")) {
keypadalphabets.setText("JKL");
}
else if(xmlProvidedSize.equals("6")) {
keypadalphabets.setText("MNO");
}
else if(xmlProvidedSize.equals("7")) {
keypadalphabets.setText("PQRS");
}
else if(xmlProvidedSize.equals("8")) {
keypadalphabets.setText("TUV");
}
else if(xmlProvidedSize.equals("9")) {
keypadalphabets.setText("WXYZ");
}
else if(xmlProvidedSize.equals("0")) {
keypadplussubscript.setVisibility(View.VISIBLE);
keypadalphabets.setVisibility(View.GONE);
}
else if(xmlProvidedSize.equals("*")) {
keypadalphabets.setVisibility(View.GONE);
}
else if(xmlProvidedSize.equals("#")) {
keypadalphabets.setVisibility(View.GONE);
}
System.out.println("ConnectMeDigit.this.getTag(): " + ConnectMeDigit.this.getTag());
System.out.println("xmlProvidedSize: " + xmlProvidedSize);
setEnabled(true);
setFocusable(true);
setFocusableInTouchMode(true);//setFocusable(true);
setClickable(true);
setLongClickable(true);
DialKeyListener lListener = new DialKeyListener(xmlProvidedSize);
setOnClickListener(lListener);
setOnTouchListener(lListener);
if (xmlProvidedSize.equals("0")) {//("0+".equals(text)) {
setOnLongClickListener(lListener);
}
}
private AddressText mAddress;
public void setAddressWidget(AddressText address) {
mAddress = address;
}
private boolean mPlayDtmf;
public void setPlayDtmf(boolean play) {
mPlayDtmf = play;
}
private class DialKeyListener implements OnClickListener, OnTouchListener, OnLongClickListener {
final char mKeyCode;
boolean mIsDtmfStarted;
/*DialKeyListener() {
mKeyCode = ConnectMeDigit.this.getText().subSequence(0, 1).charAt(0);
}*/
DialKeyListener(String character) {
mKeyCode = character.charAt(0); //ConnectMeDigit.this.getText().subSequence(0, 1).charAt(0);
System.out.println("mKeyCode: " + mKeyCode);
}
private boolean linphoneServiceReady() {
if (!LinphoneService.isReady()) {
Log.w("Service is not ready while pressing digit");
Toast.makeText(getContext(), getContext().getString(R.string.skipable_error_service_not_ready), Toast.LENGTH_SHORT).show();
return false;
}
return true;
}
public void onClick(View v) {
if (mPlayDtmf) {
if (!linphoneServiceReady()) return;
LinphoneCore lc = LinphoneManager.getLc();
lc.stopDtmf();
mIsDtmfStarted =false;
if (lc.isIncall()) {
lc.sendDtmf(mKeyCode);
}
}
if (mAddress != null) {
int lBegin = mAddress.getSelectionStart();
if (lBegin == -1) {
lBegin = mAddress.length();
}
if (lBegin >= 0) {
mAddress.getEditableText().insert(lBegin,String.valueOf(mKeyCode));
}
}
}
public boolean onTouch(View v, MotionEvent event) {
if (!mPlayDtmf) return false;
if (!linphoneServiceReady()) return true;
if (InCallActivity.isInstanciated()) {
InCallActivity.instance().resetControlsHidingCallBack();
}
LinphoneCore lc = LinphoneManager.getLc();
if (event.getAction() == MotionEvent.ACTION_DOWN && !mIsDtmfStarted) {
LinphoneManager.getInstance().playDtmf(getContext().getContentResolver(), mKeyCode);
mIsDtmfStarted = true;
} else {
if (event.getAction() == MotionEvent.ACTION_UP) {
lc.stopDtmf();
mIsDtmfStarted = false;
}
}
return false;
}
public boolean onLongClick(View v) {
if (mPlayDtmf) {
if (!linphoneServiceReady()) return true;
// Called if "0+" dtmf
LinphoneCore lc = LinphoneManager.getLc();
lc.stopDtmf();
}
if (mAddress == null) return true;
int lBegin = mAddress.getSelectionStart();
if (lBegin == -1) {
lBegin = mAddress.getEditableText().length();
}
if (lBegin >= 0) {
mAddress.getEditableText().insert(lBegin,"+");
}
return true;
}
};
}
I have tried setEnabled(true) setFocusable(true) setFocusableInTouchMode(true) setClickable(true) setLongClickable(true) and none of them seems to work.
Try using
view.setOnClickListener(lListener);
view.setOnTouchListener(lListener);
instead of
setOnClickListener(lListener);
setOnTouchListener(lListener);

Categories

Resources