I am on the project RichTextEditor and completed almost all functionality. I can insert image and can save the file with image and also getting the image and all styles while opening the file again.I am stuck at one point ie. when copying all the content of the Edittext, while pasting except Image all things got paste, but in image area i got like this
any idea or workaround to copy and paste the image.
Thanks.
I have the same problem. After get the editText field's string, I find the "obj" character, and then replace it with image's link. I created a ArrayList to store the images' links. And moreover, I think I need to catch the delete action. If an image is deleted, I deleted its link in the image list. Below is the code I use to replace the "obj" character.
private String replaceSpecialCharactorFromNote(){
String noteString = edt_note.getText().toString();
char[] noteCharacters = noteString.toCharArray();
for(int i=0; i<noteCharacters.length; i++){
if((int)noteCharacters[i] <1 || (int)noteCharacters[i]>254 ){//compare the ascii code
Log.i("the first abnormal charactor is ", "" + noteCharacters[i]);
if(imageIndex < imgsList.size()){
Log.i("replace triggered", "special char index is "+i);
Log.i("replace triggered", "replaced image index is "+imageIndex);
Log.i("replace triggered", "image is "+imgsList.get(imageIndex));
String beforeString = noteString.substring(0, i);
String afterString = noteString.substring(i+1);
noteString = beforeString + imgsList.get(imageIndex) + afterString;
Log.i("replace triggered", "note is "+noteString);
}
imageIndex++;
}
}
return noteString;
}
Overall, I do not think the way I did is the best way to solve the problem. The best way probably will be to create a custom field to handle it.
Did you check the content on the clipboard? How is the image handled in the clipboard? You will have to make your RichTextView handle the paste operation (is the image copied as a bimap / are you referencing a path to the bitmap) from the clipboard.
Related
So far I have this without crashing.
String logoImage = JO.getString("logo");
if (JO.getString("logo") == "able")
{
channel.ivLogoPic.setImageResource(R.drawable.able);
}
The problem is, It's not changing the image.
I've tried the .setDrawable and that didn't work either.
String logoImage = JO.getString("logo");
if (JO.getString("logo") == "able")
{
//int drawable1 = R.drawable.abc;
channel.ivLogoPic.setDrawable(R.drawable.able);
}
Though [ #sunil sunny ] has already mentioned a helping link, I would also like to add some solution here that could be handy.
Remember, the efficiency of this solution, in cases like yours, will decrease with increasing number of drawable resources. Meaning, do this if there are not many drawables to use.
What you can do is first get the drawables as global variables in the recyclerview adapter:
int drawable1 = R.drawable.drawable1, drawable2 = R.drawable.drawable2 ... etc.
Then inside onBindViewHolder() simply use the resources depending upon what is obtained from the JSON response.
Like:
if(logo == 1)
{
logoImageView.setDrawable(drawable1);
}
One advantage to note of this is you can change drawables easily, and not have to resort to changing names in both resource file as well as the API. Meaning, decouples the two.
PS: The codes written here are for reference only.
i figured it out in my backgroundTask.Java file I have
while (count<jsonArray.length())
{
JSONObject JO = jsonArray.getJSONObject(count);
count++;
Channel channel = new Channel(JO.getString("name"),JO.getString("logo"));
Channel logoImage = new Channel(JO.getString("logo"));
if (logoImage.equals("axle"))
{
channel.ivLogoPic.setImageResource(R.drawable.axle);
Then I had to set the change in the Adapter
if(channel.getLogo().equals("axle")){
holder.ivLogoPic.setImageResource(R.drawable.axle);
}
I am trying to put a link on a textview, but when I click this link the application breaks!! This is my code:
final TextView msg = (TextView)view_aux.findViewById(R.id.accordion_msg);
msg.setText(Html.fromHtml(dbStructure.getMsg()));
msg.setTypeface(tF);
msg.setTextColor(Color.DKGRAY);
msg.setMovementMethod(LinkMovementMethod.getInstance());
Where dbStructure.getMsg() returns a String. This String could be something like:
< a href="/reference/android/widget/RelativeLayout.html">RelativeLayout< /a>
lets child views specify their position relative to the parent view or to each other (specified by ID). So you can align two elements by right border, or make one below another, centered in the screen, centered left, and so on.
It seems nice, but the app stops when I press it.
EDIT
The error thrown ActivityNotFoundException.
the link you are trying to open is broken
/reference/android/widget/RelativeLayout.html
there is nothing corresponding to the above link.
replace it with the proper url like this
http://developer.android.com/reference/android/widget/RelativeLayout.html
Thank you very much for every one... the problem is (as #Antonio #danidee #TheRedFox and #Arslan say) the format of the url... it doesn´t start with http.
With permission from you all, I am going to answer my own question:
final TextView msg = (TextView)view_aux.findViewById(R.id.accordion_msg);
String msg_text = dbStructure.getMsg();
if(msg_text.contains("href=\"")) {
String[] msg_aux = msg_text.split("<a href=\"");
if (!msg_aux[1].toLowerCase().startsWith("http"))
msg_aux[1] = "href=\"http://" + msg_aux[1];
else
msg_aux[1] = "href=\"" + msg_aux[1];
msg_text = msg_aux[0] + msg_aux[1];
}
msg.setText(Html.fromHtml(msg_text));
msg.setTypeface(tF);
msg.setTextColor(Color.DKGRAY);
msg.setMovementMethod(LinkMovementMethod.getInstance());
Thank you.
EDIT on the code, these lines:
else
msg_aux[1] = "href=\"" + msg_aux[1];
I have deleted characters in edittext objects with this code
edit = etcalle.getEditableText();
if (edit.length() > 0)
edit.delete(edit.length() - 1, edit.length());
It has been working but when my string looks like this +81 901 it doesn't delete the space. It gets to it and stops deleting characters.
How can I remove the space in my text?
EDIT:
Just to be clear, I don't want to remove everything at once. Just one character at every time I hit my delete button
String original = etcalle.getText().toString();
then
etcalle.setText(original.substring(0,original.length-1));
of course be sure to check that the original is not null or length < 1
use this it will remove all the spaces
String str = "99 85263 9633";
str.replace(" ", ""); // Output is 99852639633
Then Its magic you can do this with this
String str = "99 85263 9633";
str.replaceFirst(" ",""); // Output is 9985263 9633
I have a string like this:
_id:2 thread_id:189 address:0292 m_size:null person:0 date:1372494272447 date_sent:0 protocol:0 read:1 status:-1 type:1 reply_path_present:0 subject:null body:Ok. Reply message. service_center:051108 locked:0 sim_id:0 error_code:0 seen:1 _id:1 thread_id:189 address:292 m_size:null person:0 date:1372493695831 date_sent:0 protocol:null read:1 status:-1 type:2 reply_path_present:null subject:null body:Test message service_center:null locked:0 sim_id:0 error_code:0 seen:0
I want to retrieve only parts of this string, for example the address:0292 and the body:xyz from the entire string. I want all instances of these two from a very large String (above is just a sample). Let's assume its more than 20000 characters.
How can I achieve this?
Looks like every address is followed by m_size, so use the string.split() function, to split over the keyword address then select the string.substring() (from each string in the resulting array) until reaching the keyword m_size. And repeat the entire thing for the keywords body and service_center. I can't think of any other way.
You are right, it doesn't seem pretty. But it works :)
String[] splitString = string.split(" ");
for (int i = 0; i < splitString.length; i++) {
if (splitString[i].startsWith("body") || splitString[i].startsWith("address"))
Log.i(TAG, "Found: " + splitString[i]);
// Do whatever you need to do
}
I'm attempting to download webpages for a user to view later. So far, I've downloaded the html, and the images. I can get the HTML to show up nicely formatted, but I cannot get the images to inline.
The code I'm using so far:
This is my method to get the article.
MyImageGetter mig = new MyImageGetter(this, urlId);
Spanned span = Html.fromHtml(contents[1], mig, null);
contents[1] = span.toString();
titleView.setText(contents[0]);
content.setText(contents[1]);
contents[] is an array that contains two strings. contents[0] is a simple string, contents[1] is a string with HTML markup.
MyImageGetter:
public class MyImageGetter implements Html.ImageGetter{
String urlId = null;
Context c = null;
public MyImageGetter(ArticleViewer articleViewer, String urlId2) {
c = articleViewer;
urlId = urlId2;
}
public Drawable getDrawable(String source) {
String[] brokenUrl = source.split("/");
String imgName = brokenUrl[brokenUrl.length-1];
File image = new File("/data/data/com.theHoloDev.Reader/Offline/" + urlId + "/" + imgName);
Log.w("MyApp", image.getAbsolutePath());
Bitmap bm = BitmapFactory.decodeFile(image.getAbsolutePath());
Drawable d = new BitmapDrawable(c.getResources(), bm);
return d;
}
}
When I have it log image.getAbsolutePath() it comes up with a file that exists in ddms. The Text content is there perfectly, but there are still little black boxes that say obj in each image. I had thought a textview would still be able to display images in that fashion, but either I'm doing something wrong, or there is another way to do this.
What is your desired end result? It is confusing to see that you are displaying html but you want the user to see the page... without html or did you do that for debugging? I assume the users will not see the html but rather the the page itself. In this case, I would go for a webview.
http://developer.android.com/reference/android/webkit/WebView.html
I don't think the text view is meant to be used like you are using it.
Good luck.
I figured it out. Instead of:
Spanned span = Html.fromHtml(contents[1], mig, null);
contents[1] = span.toString();
content.setText(contents[1]);
I need:
Spanned span = Html.fromHtml(contents[1], mig, null);
content.setText(span);
I was running into problems setting span to string.