Paste from clipboard to input? - PHP or ANDROID - android

I'm preparing an application it's 50% Native 50% Webview. Some users doesn't know how to paste from clipboard on mobile that's why I wanna make an button and user when click this button, it's must paste from clipboard to input. Javascript or Android or PHP I need.
Can you help me about it?

CharSequence pasteData="";
ClipData.Item item = clipboard.getPrimaryClip().getItemAt(0);
pasteData = item.getText();
Then use the pasteData.
As you want to give it to the web, use the message transport from java to javascript. See this: How to call javascript from Android?
Then you only need to send the pasteData to js, use js to change the data of the input.
(If you find it helpful, please mark this as the accepted answer.)

Related

Android Input Method / custom emoticons

I am trying to create a custom IME for Android, with custom emoticoons that are really just images showing on the keys.
Sending text from the keyboard to the focused text field is easy, by using the InputConnection in the KeyboardActionListener
InputConnection ic = getCurrentInputConnection();
ic.commitText(String.valueOf(code),1);
However sending images is quite challenging. I've seen the keyboard example suggested by many answer in SO (https://github.com/chiragjain/Emoticons-Keyboard) and a few other examples, and it always uses a method similar to this:
Spanned cs = Html.fromHtml("<img src ='"+ index +"'/>", imageGetter, null);
int cursorPosition = content.getSelectionStart();
content.getText().insert(cursorPosition, cs);
While this seems to work well if the focused text field is in part of the activity created by the programmer, it does not work with the OS text field (e.g. it adds an empty square instead of the image when trying to add the image to an EMail message I am writing).
I also tried other methods to send my custom image from the virtual keyboard when pressed. I tried using the clipboard to copy-paste the binary of the image and the link, but it did not work.
I tried sending an intent with the image after saving it to the media library. This works better, it lets the user choose the app to receive the image and when the app receives it, the image is properly displayed. However, it always creates a new message. For example, I am in the email app, open the custom keyboard and select an image. This launches the intent, which brings the chooser. I choose mail, and the image is added to a new message instead of the one I am currently editing.
I am now running out of ideas. Is it even possible to have custom emoticoones / images displayed on the virtual keyboard with a reliable way to send them to the OS applications?

Implement "Copy Link Text" feature in the app

I have Android WebView which displays search results. Using the contextMenu and WebView HitTestResult, I have successfully implemented a list of options like open, save, copy link url.Now, I would like to implement copy link text feature as present in Google chrome android which should copy only link text (title). A similar(not exact) feature is present in default Android browser as "Select text" option. I don't want the code for copying text using clipboard instead my main motto is to determine the way of retrieving the link title. The link url can be retrieved using HitTestResult getExtra() method likewise is there any way to retrieve the link text (title) ?
I have referred How to get loaded web page title in Android WebView? but it gives title after the webpage is loaded not when the link is pressed.
Unfortunately, the link you posted is the fastest way to get the page title (you may refer to the second answer, which is probably faster).
The reason behind this is that a website needs to be loaded before you can read the page title. The advantage of onReceivedTitle() (the second answer of your link) is that it doesn't wait until the whole page is loaded. It waits until enough is loaded to retrieve the title from the document. It also notifies you every time the page title gets change (due to JavaScript or whatever).
Edit:
What chrome does with Copy link text is to copy the text of the link like this:
Linktext
This is very difficult to achieve via a webview, since you need access to the html-content of the webpage. There are some workarounds out there (see here).
The are two APIs (selectText and copySelection) which are pending API council approval, they would help you to do this, but they are not available at the moment.
A clear, official way to do this is not available.
For copy the text try this:-
if(android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB) {
android.text.ClipboardManager clipboard = (android.text.ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
clipboard.setText(mPostCode);
Toast.makeText(getApplicationContext(), "Your code is copied.", Toast.LENGTH_SHORT).show();
} else {
android.content.ClipboardManager clipboard = (android.content.ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
android.content.ClipData clip = android.content.ClipData.newPlainText("Copied Text", mPostCode);
clipboard.setPrimaryClip(clip);
}

Android: Displaying a hyperlink and image inside email's body

I am trying to open email activity and to display in the email's body the following:
Display a hyperlink to a web site.
Display (not attach) an image logo (.png file).
I tried using html/text/image mime type and nothing works for both things.
I even tried to copy the png file to an sdcard and displaying it from sdcard path instead of using the "Assets" location that may be restricted and private only to the application, but it did not help as well!
Can anyone give me a code which works for both things??
Waiting for you help guys!!
Have you tried :
Linkify.addLinks(yourEmailString, Linkify.WEB_URLS);
yourTextView.setMovementMethod(LinkMovementMethod.getInstance());
It will make all links in the message clickable, not sure if this is what you are searching though :)?

Android linkify an address without displaying the full address

So I'm writing an app for a specific area where the user really doesn't need to see the full address. I want to turn a textview into a map address link, but don't want to have to explicitly type the full address.
Pretty simple, I only want to display the address number and street name, but leave the city, state, and zip out. Does anyone know how I can do this? Here's a chunk of my code.
textView.setText(towedVehicle.getAddress());
Linkify.addLinks(textView, Linkify.MAP_ADDRESSES);
After a little searching I was able to solve it pretty easily
Intent searchAddress = new Intent(Intent.ACTION_VIEW, Uri.parse("geo:0,0?q=address+of+location"));
startActivity(searchAddress);
I made the textview clickable and underlined it to look like a normal link.
SpannableString towedToAddress = new SpannableString(towedVehicle.getTowedToAddress());
towedToAddress.setSpan(new UnderlineSpan(), 0,towedToAddress.length(), 0);
towedToAddress.setSpan(new ForegroundColorSpan(0x990000FF), 0, towedToAddress.length(), 0);
textView.setText(towedToAddress);
textView.setClickable(true);
Opens up in Google maps and works great.
You should be able to do this using Transformfilters in the addLinks method. For an example please check this link.

Is there any way to have WebView auto-link URLs and phone numbers in Android?

If a page has a URL or a phone number on it that isn't a link is there any way to have WebView recognize it and automatically turn it into a link like you can with TextViews?
With a TextView you would simply set the android:autoLink to the desired settings:
<TextView
android:autoLink="web|phone"
... />
but I can't find any equivalent for WebView.
If you are loading your own (web) content from a String, then you can do something like this:
final String content = "My email is: firstname#email.com ...";
Spannable sp = new SpannableString(content);
Linkify.addLinks(sp, Linkify.ALL);
final String html = "<body>" + Html.toHtml(sp) + "</body>";
myWebView.loadData(html, "text/html", "utf-8");
I don't know about any way which would make this work just by changing a setting, but a workaround would be to wait until the web page finishes loading and then do:
yourWebView.loadUrl("javascript:(function(){ /* code that creates links */ })()");
This will inject javaScript into the already loaded web page.
There's a slightly longer example available here: http://lexandera.com/2009/01/injecting-javascript-into-a-webview/.
You can find the JavaScript source for creating links if you take a look at the source of Linkify script for Greasemonkey (it's a plugin for Firefox in case you're not familiar with it). I believe it comes with the default install.

Categories

Resources