Darrin Smith

Ranch Hand
+ Follow
since Aug 04, 2003
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Darrin Smith

Adrian Burkett wrote:There appear to be various tools to convert HTML to Markdown. Can you not use one of those ?



Ahh! I was looking for Javadoc and I bet that was what was causing me to come up empty. I'll search for HTML to Markdown instead.

Thanks.
12 years ago
From reviewing you code, I am not certain that you are understanding Intents all that well. I suggest that you remove the startActivity method and set a break point on line 7 and step through to discover what is going on. It will help you understand things.
12 years ago
You don't need to use buttons.

I suggest that you do this:

1) Use an ImageView
2) Set android:scaleType="matrix"
3) Implement your own OnTouchListener
4) Override onTouch
5) In onTouch look for these cases:
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_POINTER_UP:
mode = NONE;
float[] coords = getPointerCoords(view, rawEvent); //view is passed to onTouch
imagePt.x = coords[0];
imagePt.y = coords[1];
6) Make getPointerCoords(view, rawEvent) look like this:

final float[] getPointerCoords(ImageView view, MotionEvent e)
{
final int index = e.getActionIndex();
final float[] coords = new float[] { e.getX(index), e.getY(index) };
Matrix matrix = new Matrix();
view.getImageMatrix().invert(matrix);
matrix.postTranslate(view.getScrollX(), view.getScrollY());
matrix.mapPoints(coords);
return coords;
}



That will return the point upon where the image was touched.
12 years ago
I've searched and cannot find any tool to convert Javadoc to Markdown format (in short, strip out the HTML and replace it with Markdown).

Anyone seen such an animal in the wild? I have run across a tool or two to allow the output be in Markdown but nothing to convert already written Javadoc.

Thanks!
12 years ago
To save it to the gallery (which is what I think you may really want to do).



If you really want to save it to the SD card, then this should walk you through it (note that a simple Google search provided this): http://android-er.blogspot.com/2010/07/save-file-to-sd-card.html
12 years ago
I have a little Android application that allows you to draw a little bit on the screen. I want to be able to save off the image but all I ever get is a blank bitmap.

What I do is

create a bitmap
assign the bitmap to a canvas
assign the bitmap to an image view

If then draw on the thing a little and attempt to save it off by doing

View v = findViewById(android.R.id.content);

v.setDrawingCacheEnabled(true);
Bitmap tmpBmp = v.getDrawingCache();


This doesn't seem to work, but what is really odd is that if I load a bitmap into the image just before I do that, it does work just fine. The code I use to do that looks like this:

//This works, so it isn't downstream from here....it's here not saving the right image!
Bitmap tmpBmp = BitmapFactory.decodeResource(getResources(), R.drawable.myapp_icon);
mBitmap = tmpBmp;
mCanvas.setBitmap(tmpBmp);
mImageView.setImageBitmap(tmpBmp);


It's acting like it just doesn't see the drawing done on the canvas that I do like this:

mCanvas.drawLine(inputDownX, inputDownY, inputUpX, inputUpY, thisPaint);

So any idea what it is that is going on here?
13 years ago
The best way to relate my question is by scenario:

You have an application that draws an image on a screen. Let's say that image is just a big box. You select the point directly on the top left corner of the box. Let's say that point ON THE SCREEN is 100, 100 to make it easy. The user then moves that image to the right and zooms it. No rotation was involved. He then selects the same spot on the box...very top left. Of course since the box moved the screen coordinates are no longer 100, 100. Let's say they are now 120, 90.

How can you translate the 120, 90 back to what it would have been (100, 100) if the user had not panned and zoomed the image?


The code to move the image after the user pans and zooms looks like this. Note that the mState object also holds the X/Y coordinate the user touched on.

What is the formula that needs to be applied to that point to get it back to what it would have been pre-translation and scale in this code?


13 years ago
Yes Winston, but now I have horrible memories from IBM Assembler class back in 1985 to deal with. Thanks! LOL


Winston Gutkowski wrote:

Darrin Smith wrote:I didn't spell it out well. After 20+ years of it, starting out with a Tandy Model III and working on VAX, DEC, IBM 360 and everything since, I assure you I understand how things are stored internally.

I was just looking for a way to stuff a number up to 255 into two consecutive bytes in a stream. I'll just write a little routine for this.


Are you sure you're not thinking of packed decimal? It's more than a decade since I've seen it, but it's the only standardized "hexadecimal" format I can think of. In the above case it would be stored as 0x255C (or 255F for unsigned), which does fit into 2 bytes.

Winston

13 years ago
Here is the simple solution to my problem...and thank you for helping!



So in short (no pun intended) I just stuff the size into a char and append the char to a StringBuffer at the proper position.

char cLength = (char)size;
buff.append(cLength);


Jeff Verdegan wrote:

Darrin Smith wrote:
I was just looking for a way to stuff a number up to 255 into two consecutive bytes in a stream. I'll just write a little routine for this.



So..

0x0000 = 0
0x0001 = 1
...
0x00FE = 254
0x00FF = 255

Yes?

You can use a short for that.

On the other hand if you don't care about your Java process interpreting the bytes as the int value 255, and you just care about the bit pattern 0xFF, then simply (byte)0xFF or (byte)255 will do. Your goal still isn't clear though, so it's hard to give concrete advice.

13 years ago
Actually he didn't. He just did exactly what I said I already tried. Using Integer.toHexString().


Jeff Verdegan wrote:Vivekk, please do not do the OP's work for him. This site is NotACodeMill(⇐click), and, as it says clearly at the top of the topics page: We're all here to learn, so when responding to others, please focus on helping them discover their own solutions, instead of simply providing answers.

13 years ago
I didn't spell it out well. After 20+ years of it, starting out with a Tandy Model III and working on VAX, DEC, IBM 360 and everything since, I assure you I understand how things are stored internally.

I was just looking for a way to stuff a number up to 255 into two consecutive bytes in a stream. I'll just write a little routine for this.

Thanks.


Paul Clapham wrote:

Darrin Smith wrote:Well, I need the actual number in hex, not the character representation of it!



Sorry, but you have fundamentally misunderstood how numbers are stored in computers. You can have a byte which contains the decimal value 27. This byte also contains the hexadecimal value 1B and it also contains the octal value 33, because those three things are the same thing. But it doesn't contain any representation of the number. The number is therefore just an abstraction, which you can choose to represent in many ways as a string.

So what was your original requirement which made you think that you needed "a number in hex" as opposed to the character representation in hex?

13 years ago
I need to convert a decimal number to a hex number but using the Integer.toHexString() does not work.

The reason is that I need to store the number into two consecutive bytes in a stream.

For example, if you start with the number 27 and use Integer.toHexString(27) it will yield 31 62 not 1B as I want. The reason is that 31 hex is the letter 1 and 62 is the letter b each in their own character. Well, I need the actual number in hex, not the character representation of it as two chars.

So, how can I convert up to 255 into two consecutive bytes so I can store it into a byte array?

THANKS!
13 years ago
I have instances where I seem to be missing header information sent to me over a Bluetooth data stream. I am also wondering if I am getting all of the data or not (truncating before the end).

My app is based off of the BluettothChat application for Android. Here is the code I am wondering about:





Now to me, this LOOKS like it could miss data since it never checks for a -1 that I understand indicates when the end the stream has been reached.

Anyone have an idea based on this code (which again, comes from Google's BluetoothChat example app) might not get the beginning bytes of a stream on occasion and also, if it looks like it will get all of the stream given it never checks for the end of it.

Thanks!!!



13 years ago
I tried that and it did work on the string I sent but failed on others (sometimes no decimal was sent, etc.). I modified it slightly and ended up with this which works great!

private static final Pattern getStatusPattern = Pattern.compile("GN=(-?[0-9]+\\.?[0-9]?),(-?[0-9]+\\.?[0-9]?),(-?[0-9]+\\.?[0-9]?),(-?[0-9]+\\.?[0-9]?),(-?[0-9]+\\.?[0-9]?),(-?[0-9]+\\.?[0-9]?),(-?[0-9]+\\.?[0-9]?)");

Thanks!



Winston Gutkowski wrote:

Darrin Smith wrote:I tried doing this too...no help:
...
Pattern.compile(".*=(-?[0-9]+\\.[0-9]+?),([0-9]+),(-?[0-9]+\\.[0-9]+?),(-?[0-9]+\\.[0-9]+?),(-?[0-9]+\\.[0-9]+?),([0-9]*),([0-9]*),([0-9]*)");
...
Again though, using a tool it works. Just not when I run it in a Java application.


That's not quite what I was thinking of. I tried this:
Pattern.compile("GN=-?[0-9]+([.][0-9]+)?(,-?[0-9]+([.][0-9]+)?){7}");
against your test string and it worked just fine.

I suspect you should also make your initial ".*" string ".*?" or "[^=]*".

Winston

Just FYI, my code:
and the output:

13 years ago

Winston Gutkowski wrote:

Darrin Smith wrote:Why does m.matches() return false?


Well, I suspect you don't need the '|' because you don't appear to be matching on it, but I wouldn't have thought it would need escaping inside square brackets.
I also think that "(-?[0-9]+([.][0-9]+)?)" is more correct for a decimal number.

Winston



I tried doing this too...no help:

public static final Pattern pattern = Pattern.compile(".*=(-?[0-9]+\\.[0-9]+?),([0-9]+),(-?[0-9]+\\.[0-9]+?),(-?[0-9]+\\.[0-9]+?),(-?[0-9]+\\.[0-9]+?),([0-9]*),([0-9]*),([0-9]*)");


Again though, using a tool it works. Just not when I run it in a Java application.
13 years ago