[Q][ECLIPSE] Possible to decompile app back to source with eclipse? - IDEs, Libraries, & Programming Tools

Hello.
Ok, so I havent been able to find anything about this really, and nothing in the ide itself. So let me explain.
this is not a "How do I decompile apk" thread, or a "how do i setup eclipse" thread. ive done ROMs and Apps so I'm familliar with all that.
I built a map with a bunch of markers on it. Somehow, the source has disappeared from my computer. not in the recycle bin with other stuff, and not in the workspaces. This was not released either, but is still on my phone. Im rewriting the app, But really don't want to go back in and do all the markers manually. i started and it was very tedious as I also had titles and snippets for each marker.
I used Virtuos Ten studio to decompile to source, and while it was pretty good, There were many little weird syntax type things that didnt make sense(main using resource numbers(0700303) instead of (r.layout.activity_main).
example
virtuos java
Code:
super.onCreate(bundle);
setContentView(0x7f030000);
googleMap = ((SupportMapFragment)getSupportFragmentManager().findFragmentById(0x7f040005)).getMap();
Object obj = new LatLng(0.000000999999998D, -0.0000000000006D);
googleMap.setMapType(4);
googleMap.addMarker((new MarkerOptions()).position(((LatLng) (obj))).title("title").snippet("subtitle").icon(BitmapDescriptorFactory.defaultMarker(210F)));
Object obj1 = new LatLng(0.0000002999999999D, -0.00000033000000004D);
googleMap.addMarker((new MarkerOptions()).position(((LatLng) (obj1))).title("title").snippet("NEW").icon(BitmapDescriptorFactory.defaultMark
versus original code
Code:
private GoogleMap mMap;
[user=439709]@override[/user]
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
SupportMapFragment mapFragment =
(SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
GoogleMap googleMap=null;
LatLng latLng = new LatLng(0.0002987699, -0.00073300078900);
googleMap.setMapType(GoogleMap.MAP_TYPE_HYBRID);
googleMap.addMarker(new MarkerOptions()
.position(latLng)
.title("Title")
.snippet("subtitle")
.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE)));
LatLng latLng2 = new LatLng(0.000560000000, -0.0002000000);
googleMap.setMapType(GoogleMap.MAP_TYPE_HYBRID);
googleMap.addMarker(new MarkerOptions()
.position(latLng2)
.title("Title")
.snippet("stuff")
.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE)));
LatLng latLng3 = new LatLng(0.000560000000, -0.0007000000);
googleMap.setMapType(GoogleMap.MAP_TYPE_HYBRID);
Is there anyway to get this back? Or am i stuck going the long way?

out of ideas said:
virtuos java
Code:
super.onCreate(bundle);
setContentView(0x7f030000);
googleMap = ((SupportMapFragment)getSupportFragmentManager().findFragmentById(0x7f040005)).getMap();
Object obj = new LatLng(0.000000999999998D, -0.0000000000006D);
googleMap.setMapType(4);
googleMap.addMarker((new MarkerOptions()).position(((LatLng) (obj))).title("title").snippet("subtitle").icon(BitmapDescriptorFactory.defaultMarker(210F)));
Object obj1 = new LatLng(0.0000002999999999D, -0.00000033000000004D);
googleMap.addMarker((new MarkerOptions()).position(((LatLng) (obj1))).title("title").snippet("NEW").icon(BitmapDescriptorFactory.defaultMark
versus original code
Code:
private GoogleMap mMap;
[user=439709]@override[/user]
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
SupportMapFragment mapFragment =
(SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
GoogleMap googleMap=null;
LatLng latLng = new LatLng(0.0002987699, -0.00073300078900);
googleMap.setMapType(GoogleMap.MAP_TYPE_HYBRID);
googleMap.addMarker(new MarkerOptions()
.position(latLng)
.title("Title")
.snippet("subtitle")
.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE)));
LatLng latLng2 = new LatLng(0.000560000000, -0.0002000000);
googleMap.setMapType(GoogleMap.MAP_TYPE_HYBRID);
googleMap.addMarker(new MarkerOptions()
.position(latLng2)
.title("Title")
.snippet("stuff")
.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE)));
LatLng latLng3 = new LatLng(0.000560000000, -0.0007000000);
googleMap.setMapType(GoogleMap.MAP_TYPE_HYBRID);
Is there anyway to get this back? Or am i stuck going the long way?
Click to expand...
Click to collapse
Actually I think you getting very good decompiled codes with VT. AFAIK, decompilation can never give you back the exact source codes. As for the resource numbers instead of codes, they're just the internal auto-generated ID inside R.java. If you can get the original R.java, you maybe able to translate them back.
So always have a backup around next time. Good luck!

In eclipse without special plugins you can't decompile APK.

Not into Eclipse directly, but JD-GUI can help. There's another tool involved, I think, but I forgot.

bassie1995 said:
Not into Eclipse directly, but JD-GUI can help. There's another tool involved, I think, but I forgot.
Click to expand...
Click to collapse
dex2jar
I have used both VTS and JD-Gui in the past with fairly pleasing results. I will say though that whichever way you do it, you will need to rewrite large portions of the code to fix syntax and logic errors.

Jonny said:
dex2jar
I have used both VTS and JD-Gui in the past with fairly pleasing results. I will say though that whichever way you do it, you will need to rewrite large portions of the code to fix syntax and logic errors.
Click to expand...
Click to collapse
Yes, dex2jar! Thanks
Also, Jonny is right. The code is probably obfuscated, and you might not have some libs, apart from differing packages names and such.
Sent from my Nexus 7 using Tapatalk HD

Related

Learning how to program for Windows Mobile?

I've done some searching, and I know Windows CE uses Win32, which I know to an extent. I was curious if there are any good free resources for learning WinCE-Win32, or if I should simply use my existing books for MFC/Win32. Microsoft's site kinda sketchy, and MSDN not being very useful. I did get Microsoft Embedded Visual C++ working and compiled a test app which worked on my MDA and on the emulator.
i would just start coding
miniMFC and compact .net framework is soo close it's only
some controls and options you dont have
ortherwise it's the same thing
learning by doing and having ones fingers down and dirty
into the code is where you learn the most
Yep, that's just how I learned when I switched to coding for PPCs.
Any way here are a few major differences to start you off:
1) All API's that use strings are in UNICODE. ASCII versions were removed.
2) For most API's that have an 'ext' version the regular version was removed. Example: ExtTextOut - yes, TextOut - no.
3) When dealing with files, all paths must be absolute. No '..\file.x' and 'file.x' will give you the file in device root and not the app directory.
And here is a nice site for pocket PC specific apps:
www.pocketpcdn.com
Has articles on just about everything from making dialogs not full screen to writing today plug-ins.
levenum said:
Yep, that's just how I learned when I switched to coding for PPCs.
Any way here are a few major differences to start you off:
1) All API's that use strings are in UNICODE. ASCII versions were removed.
2) For most API's that have an 'ext' version the regular version was removed. Example: ExtTextOut - yes, TextOut - no.
3) When dealing with files, all paths must be absolute. No '..\file.x' and 'file.x' will give you the file in device root and not the app directory.
And here is a nice site for pocket PC specific apps:
www.pocketpcdn.com
Has articles on just about everything from making dialogs not full screen to writing today plug-ins.
Click to expand...
Click to collapse
I knew about how everything was Unicode. Is there an easy way to create unicode strings? I remember there was something in MFC macro like TEXT() that did something like that, but the specifics are missing. I remember there was a knowledge base article on this, but I can't find it.
Also, what's the difference between the Ext version and the non-ext versions of an app?
EDIT: Unless I'm mistaken, I just need to put my strings in _T("*string*")
Yes, you're right, this is how you write strings in your code:
Code:
WCHAR uniStr[] = L"Unicode string";
or if you are using MFC:
Code:
CString uniStr = _T("Unicode string");
and if you have a ASCII string you want converted to UNICODE
use mbstowcs function. (CString class has a built in conversion)
As for the 'ext' API's they just give you more parameters to better control the result of whatever they are doing. In desktop windows if you didn't want to call a function with 10 parameters you usually had a simpler version of it where some things were default.
Example:
Code:
BOOL TextOut(
HDC hdc, // handle to DC
int nXStart, // x-coordinate of starting position
int nYStart, // y-coordinate of starting position
LPCTSTR lpString, // character string
int cbString // number of characters
); //5 parameters
BOOL ExtTextOut(
HDC hdc, // handle to DC
int X, // x-coordinate of reference point
int Y, // y-coordinate of reference point
UINT fuOptions, // text-output options
CONST RECT *lprc, // optional dimensions
LPCTSTR lpString, // string
UINT cbCount, // number of characters in string
CONST INT *lpDx // array of spacing values
); // 8 parameters
what would be your suggestion for a newbie to learn programming for PPC?
I'm beggining to have interest in doing this but have absolutely no idea where to start.
thanks for any advise.
For complete newbies, I wrote this post a while back:
http://forum.xda-developers.com/viewtopic.php?p=209136#209136
V

accelerometer(lg gm750) method signatures

attached the.dll of the lg gm750 in case they serve of something
USER iamspv
First take a look at the Unified Sensor Api at codeplex.
My solution is based on the Samsung sensor class, modified to meet the peculiarities of the LG GM750.
First of all, the import of the DeviceIoControl in NativeMethods.cs must be modified such way dwIoControlCode is type uint, and the buffers are byte:
Code:
[DllImport("coredll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern bool DeviceIoControl(IntPtr hDevice, uint dwIoControlCode, [In] byte[] inBuffer, int nInBufferSize, [Out] byte[] outBuffer, int nOutBufferSize, ref int pBytesReturned, IntPtr lpOverlapped);
After a long time dissassembling the accelsensor.dll and and a lot of trial and error testing I came to this conclusion that works:
The constant that starts/stops data output becomes:
Code:
const uint ACCOnRot = 0x1014EE8;
const uint ACCOffRot = 0x1014EE8;
and for reading values:
Code:
const uint ACCReadValues = 0x1014F10;
The difference between start and stop comes from the input given in DeviceIoControl method as follows:
Code:
Code:
public static LGAccSensor Create()
{
DeviceIoControl(ACCOnRot, new byte[1] {1}, new byte[4] );
return new LGAccSensor();
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
DeviceIoControl(ACCOffRot, new byte[1] {0}, new byte[1] );
}
The DeviceIoControl inside the accelerometer class becomes
Code:
Code:
public static void DeviceIoControl(uint controlCode, byte[] inBuffer, byte[] outBuffer)
{
IntPtr file = NativeMethods.CreateFile("ACC1:", 0, 0, IntPtr.Zero, ECreationDisposition.OpenExisting, 0, IntPtr.Zero);
if (file == (IntPtr)(-1))
throw new InvalidOperationException("Unable to Create File");
try
{
int bytesReturned = 0;
int inSize = sizeof(byte) * inBuffer.Length;
int outSize = sizeof(byte) * outBuffer.Length;
if (!NativeMethods.DeviceIoControl(file, controlCode, inBuffer, inSize, outBuffer, outSize, ref bytesReturned, IntPtr.Zero))
throw new InvalidOperationException("Unable to perform operation.");
}
finally
{
NativeMethods.CloseHandle(file);
}
}
Note that the accelerometer device is called ACC1:.
Further the method that returns the three component vector becomes
Code:
Code:
public override GVector GetGVector()
{
byte[] outBuffer = new byte[4];
DeviceIoControl(ACCReadValues, new byte[1] {1}, outBuffer);
GVector ret = new GVector();
int accx = outBuffer[2];
if (accx <=31)
ret.X = accx/2.17;
else
ret.X = (accx-64)*0.47;
ret.X = -ret.X;
int accy = outBuffer[1] ;
if (accy <=31)
ret.Y = accy/2.17;
else
ret.Y = (accy - 64) * 0.47;
int accz = outBuffer[0] ;
if (accz <=31)
ret.Z = accz/2.17;
else
ret.Z = (accz - 64) * 0.47;
double somefactor = 1; return ret.Scale(somefactor);
}
Note that the when called with AccReadValues parameter, the DeviceIoControl returns three bytes each of them containing a signed 6 bit 2's complement value.Basicly there are values on 6 bit ranging from -32 to +31. In the docs below there are tables that put in correspondence these values with acceleration in range -1.5g +1.5g which are the limits of the device. The code I wrote returns acceleration in meters/second2 where 1g=9.8 m/s2. That information I extracted from the technical specifications of the MMA7660FC accelerometer, as found at(try a google search). Also, the type of the accelerometer circuit is found in the service manual (I only found the service manual for LG GM730 which is pretty close).The same thing I also posted at codeplex.
Reply With Quote
It already works! There is nothing more to do about it than use the code in your applications (I speak as a programmer and for programmers). I only showed everyone interested in developing for LG GM750 the steps to modify the SamsungGSensor class from "Unified Sensor Api" at codeplex to work with a LG. Just get the rest of the code from there and put it toghether.
Now there are two directions:
Direction #1
If you want to develop applications that aim to be portable between HTC, Samsung, LG, Toshiba, etc, and you want to use Unified Sensor Api then..
the person responsible for the unified api project at codeplex should make the update to the library as soon as possible such way the library should keep compatibility with the adressed devices. I'm just contributing with some results. That's because the initial code was not very general (ie. the initial parameter types to deviceiocontrol invoked from coredll didn't work with this solution) I had to make some modifications to the code that work with the LG but affect other devices' sensor classes. Now, if the update doesn't come up soon, no problem, anyone just gets the code from codeplex, adds a new class for LG, copies code from Samsung, renames Samsung with LG, adds my modifications, corrects syntax errors, compiles, et voila . . the library is updated to support LG GM750.
Direction #2
If you develop only for LG, just write a LG class as presented above and don't care about other devices.
If you don't know how to use your new class, the project at codeplex has some examples and you'll easily see inside the code how to instantiate sensors, how to read data at certain moments using a timer, and how to capture screen rotation events.
And for your long awaited joy to see it working, I attached the sensor test program along with a version of sensors.dll compiled by me, that works for GM750.
Now get your fingers toghether on the keyboard and start developing for LG
now should work in an emulator as that one of htc in omnia splitting of what we arrange
great work!
thanks much!
htcemu v0.91 /sensors.dll Problems
Hello all,
when I last November asked for a htcemu for LG750, I have not expected that there will be a emu dll so soon.
Thanks to iamspv and others, we now can use g-sensor apps as normal.
Nearly - some apps does not work or crash.
So my favorite alarm clock, klaxon crashes when alarm is activated. Waterlevel also does not work. It looks that both apps use the managed code dll sensors.dll. Even if I exchange the original dll with the one posted here from beginning of february, it does not work. Does anybody has a solution for this ?
For using landscape mode in app I now got best results with changescreen which works almost perfect. It is also possible to exclude some programs like some LG apps which do not support landscape mode.
how did you make other apps work? on my layla only test works and nothing else
creative232 said:
attached the.dll of the lg gm750 in case they serve of something
Click to expand...
Click to collapse
Did you create a running VS 2008 solution for this?. I'm interested.
Will this work on other LG's?

VB.net help needed for an app Im halfway through writing.

Ive got to a point where Ive got to the limit of my knowledge.
(admitedly, I no pro, I just dont know how to do this)
Ive got a loop which finds out how many images are in a folder
and it makes a new picturebox for each image, sets the image
property to show that image and gives it a name, height, width,
location and parent.
My problem is I want to add a mouseclick event for each of these
items as I create them. I just dont have a clue how to do this.
Anyone got any ideas?
Ive tried this kinda thing, but it didnt work (stupid compact framework):
Code:
picturebox.MouseClicked += new MouseEventHandler(function_name);
Good Help Forum
http://www.vbforums.com/
It must work... Not sure how it is in VB.NET, but in C# it is this:
... in some method ...
PictureBox pb = new PictureBox();
.. setting properties
pb.Click += new EventHandler(PictureBox_Click);
... end of the method
private void PictureBox_Click(object sender, EventArgs e)
{
... here goes your code, the picturebox clicked is in (sender as PictureBox), event args are in e
}
Thanks for you help
Ive not managed to get anything working properly so far
but I have within the past 10 mins figured out how to get around having to do this ^_^
See, this is a autoload image:
Me.PictureBox1.Image = New System.Drawing.Bitmap("figure2.bmp")
And Example:
http://social.msdn.microsoft.com/Forums/en-US/vblanguage/thread/2896d5cd-06d1-4a70-a561-a2c3497e325c
I think this wouldn't have been a problem with older VB technology if it had supported WM development. By that I mean it supported object arrays and provided a method with an 'Index'. From what I can see .NET doesn't offer such a luxury.
Your code looks right (syntax); but would I be right in thinking that your loop recreates 'picturebox' each time it loops and you are trying to associate an array of 'picturebox' to a single 'MouseEventHandler' function?
Code:
picturebox.MouseClicked += new MouseEventHandler(function_name);
My method of programming .NET is pretty much trial and error so I can't say for sure, just waffling
This is an example on how i did this with c# and the paint event. You dont want the paint event but it should be easy enough to change.
private void GenerateDynamicControls(string extt)
{
PicBox = new PictureBox();
PicBox.Image = Properties.Resources.phone;
PicBox.Name = "picturebox" + extt.ToString();
PicBox.Width = 75;
PicBox.Height = 75;
PicBox.BackgroundImageLayout = ImageLayout.Center;
flowLayoutPanel1.Controls.Add(PicBox);
PicBox.Paint += new PaintEventHandler(picpaint);
}
private void picpaint(object Sender,System.Windows.Forms.PaintEventArgs e)
{
//Do whatever you need done here
}
//To Create the control do this.
GenerateDynamicControls(namethecontrolsomething);
Hope this helps.
In VB.Net, you need to use AddHandler. Quick search on the tutorial and I found, http://www.thescarms.com/dotnet/EventHandler.aspx
Hope this help.
smart device applcation
Sorry guys but I will use this thread to ask for your help regarding VB.Net.
Does anyone know how to browse the device and select a picture into a picture box?
Example:
I have a form with a picturebox and a button and what I want is by pressing the button to explore my device, choose a picture and update my picturebox with the picture selected.
There are loads of youtube videos with Windows Forms Applications tutorial but I just can not find one for a smart device applcation.
Any help?
Thanks

dynamically setting image resources

greetings
was referred to this forum from someone at androidcommunity.com regarding this...
i searched the forum but couldnt find any relevant posts - can anyone point me in the right direction for doing this properly?
specifically how could one set an image resource based on a string variable being used for part of the image's file name
i tried this based on a post i saw elsewhere:
myContext.getResources().getIdentifier(myStringVariable + "_thumbnail", "drawable", myContext.getPackageName()));
but it returnes a string(or an integer?) of numbers (the resource id?) that setImageResource couldnt use unless i just wasnt doing it properly.
is there perhaps a way to get the resource name based on that id number or whatever it is that im getting?
apreesh
33 views
dang
getIdentifier() returns int and yes, it could be used in setImageResource() method.
But why you want to set resources from strings?
because the image being set is based on user selection and is not just one image its several associated images so there is a number sequence to the image file names as well that i did not show in the snippet i posted.
but i went back and plugged some of those returned values (resources ids?) from getIdentifier() into setImageResource() and it does indeed work so thanks for that - i have an idea what i was doing wrong before but for the sake of moving on im using a different solution now - in short i am now defining each group of images as a separate class member int[] and i will probably use a switch case to plug the correct one into the gridview. its ugly, but i currently only have 11 different groups and no more than 16 images per group so it will work for now until i can study the resource object more and figure out a way to get counts of associated image resources based on a part of the resource name, like with a regular expression or something, because thats the next problem i will have to deal with if i am not pre-defining all of these arrays.
if you know of a way to do that that would be awesome but ill will probably look into it more myself once i get this app closed up and can go back and fix stuff. im pressed for time right now.
thanks
It's really bad thing to use getIdentifier() method, we should always use R class. I think your problem resides somewhere before, you try to do something, that you shouldn't
How do you get these strings? You mentioned they are from user, but he doesn't write them by hand, right? If this is some selectable list, etc., they should be ints, enums, or some objects from the beginning. Not strings. Parsing strings is always ugly.
Ahh and if you have group of many small images, it is usually better to concatenate them into one big image - it's more efficient and you don't have to use 200 R constants in your code.
the string comes from the tag associated with a clickable imageView selected from the previous screen - a menu item if you will. the string will serve several purposes, retrieving related data, etc, but the first thing i needed to work out was retrieving the correct images and displaying them. i dont know how i could concatenate the images into one big image because each one needs to be clickable itself and handle certain events associated with itself.
i will go ahead and admit this is my first app so im basically figuring stuff out as i go. and learning most of my oop from flash has probably handicapped me
i appreciate your help dude
Brut.all said:
it's more efficient and you don't have to use 200 R constants in your code.
Click to expand...
Click to collapse
the only other thing i could think of trying was creating an xml doc to group the associated resource names together and figure out how to read from that to know which images to set
i dont see any methods in the R class i could use for sorting, grouping and then retrieving certain resources based on user interaction
switch cant eval string types...!?
kadmos said:
switch cant eval string types...!?
Click to expand...
Click to collapse
Nope
As I said, strings aren't good for identifying things - regardless of the language used. This is why people created int constants and/or enums.
And no, I doubt there are some mechanisms of grouping resources, etc. It must be simple, you are trying to complicate everything
I have a strong feeling that you should change your app architecture and get rid of strings. But here quick general fix (not a good solution! but just works).
Map your strings to R ints:
Code:
Map<String, Integer> map = new HashMap<String, Integer>();
map.put("button_normal", R.drawable.button_normal);
map.put("button_pressed", R.drawable.button_pressed);
// etc
Accessing will be done:
Code:
map.get("button_" + state); // Return int id, use as you need.
This is a bad practice, but it will work. Consider re-archirecturing your app.
@Brut.all: do you have any plans on updating apktool with 2.2 support?
@kadmos
Full example:
Code:
public static enum Planet {
MERCURY(R.string.planet_mercury, R.drawable.planet_mercury),
VENUS(R.string.planet_venus, R.drawable.planet_venus),
EARTH(R.string.planet_earth, R.drawable.planet_earth),
MARS(R.string.planet_mars, R.drawable.planet_mars);
public final int nameResId;
public final int imageResId;
public static Planet findByNameResId(int nameResId) {
for (Planet p : values()) {
if (p.nameResId == nameResId) {
return p;
}
}
return null;
}
private Planet(int nameResId, int imageResId) {
this.nameResId = nameResId;
this.imageResId = imageResId;
}
}
You have enum of planets, each of them has its name and image. Then you could do something like:
Code:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
for (Planet planet : Planet.values()) {
menu.add(0, planet.nameResId, 0, planet.nameResId);
}
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
Planet planet = Planet.findByNameResId(item.getItemId());
doSomethingWithPlanetImage(planet.imageResId);
return true;
}
You identifies planets by ints (nameResId in this example - of course it must be unique), not by strings. Operations on ints are several times faster, than on strings, this is why Google decided to identify all things: resources, menu items, etc. just by ints.
Ahh and no, writing switch-cases to do something depending on given object isn't true OOP. OOP is above: enums know, which drawable is connected to them, there is no need for switches.
AuxLV said:
@Brut.all: do you have any plans on updating apktool with 2.2 support?
Click to expand...
Click to collapse
Yeah, of course, I want to work on apktool this weekend. Unfortunately baksmali doesn't support Froyo yet, so I can't support it fully neither.
@Brut.all:
Ha, I recognise that example It's from the Java Trail/tutorial on enums isn't it? Except they used gravity rather than drawable references.
@kadmos:
Are all the images known from the beginning? In other words, is the user creating them at runtime or are you including them with your app? If they are included with your APK then normally, as Brut said, you should be able to use the identifiers directly.
Concatenating the images all into one isn't hard to do, as you can still draw the specific bitmaps out using the Bitmap.create(bitmapToGetAPartOutOf, ....) method. You can then make those individual bitmaps into ImageViews and only have to remember the 'grid reference' for where they came out of the big image. That said, you'd have to balance the added complexity of creating the big images against the ease of not having loads of R constants. I can't really say anymore because I'm not fully following what you're trying to achieve.
Steven__ said:
@Brut.all:
Ha, I recognise that example It's from the Java Trail/tutorial on enums isn't it? Except they used gravity rather than drawable references.
Click to expand...
Click to collapse
I took planets example, because it's good, but everything was written from scratch
Steven__ said:
Concatenating the images (...)
Click to expand...
Click to collapse
I'm pretty sure I saw this concatenating approach somewhere in official Android's guidelines for performance, but now I can't find it :-/ Also I don't have much experience in Android development, so if no one else suggest this approach, then I think kadmos could forget about it.
Brut.all said:
You identifies planets by ints (nameResId in this example - of course it must be unique), not by strings. Operations on ints are several times faster, than on strings, this is why Google decided to identify all things: resources, menu items, etc. just by ints.
Ahh and no, writing switch-cases to do something depending on given object isn't true OOP. OOP is above: enums know, which drawable is connected to them, there is no need for switches.
Click to expand...
Click to collapse
i know its not true oop i didnt want to have to do that but i have not yet seen a way to pass any value from a selected item into a method that could use that value to retrieve x amount of associated resources (images in this case).
Steven__ said:
Are all the images known from the beginning? In other words, is the user creating them at runtime or are you including them with your app? If they are included with your APK then normally, as Brut said, you should be able to use the identifiers directly.
...I can't really say anymore because I'm not fully following what you're trying to achieve.
Click to expand...
Click to collapse
using the planets example, say i had x (varying) amount of pics of each planet's surface in my drawables and wanted only those planet's pics to display in a grid view when a user selects whichever planet. thats really all this is. being new to this i just dont know the most efficient way to do it. if this was Flash i could just group all the images file names/paths in an external xml doc and use that to load them from whatever folder at runtime - i wouldnt need any of those 200 or so images declared as anything or even as assets in my library (and i would only need the xml because flash cant access a file system on its own to see and filter files that it would or wouldnt need based on, say, a string comparison - though there is third party software like Zinc that gives Flash that capability.)
so i did get this to work by passing a number as a tag (string) in a bundle though an imageView click event and then casting the string as an int to use in the switch - which as of now leads to one of 11 different int arrays of resources names (images) ive got declared in my ImageAdapter class to populate my gridView.
the way i wished i could made this work would have been to use a string (like a planet name) ,passed from whatever planet image/menu item/whatever was clicked, and use that string to compare and determine which and how many images in drawables were associated with that planet and then use that to create my gridView at runtime.
kadmos said:
so i did get this to work by passing a number as a tag (string) in a bundle though an imageView click event and then casting the string as an int to use in the switch - which as of now leads to one of 11 different int arrays of resources names (images) ive got declared in my ImageAdapter class to populate my gridView.
Click to expand...
Click to collapse
I see what you're saying, that makes sense. Just as a quick note though, if you're declaring your ImageViews programmatically, you don't have to use a string object for the tag. You can directly give the integer and then cast it back when you get the tag. Just remember to use (Integer) as the tag is actually just an unspecified object.
kadmos said:
the way i wished i could made this work would have been to use a string (like a planet name) ,passed from whatever planet image/menu item/whatever was clicked, and use that string to compare and determine which and how many images in drawables were associated with that planet and then use that to create my gridView at runtime.
Click to expand...
Click to collapse
Yes, I can see why you'd want to do it this way. Your current problem is that if you add more images, you have to manually update your arrays. Unfortunately I can't think of a better, 'clean' way of doing it.
@kadmos
Now I have problems understanding you ;-) But if you don't want to declare all images in sources, but in XMLs, then you could use XML arrays.
Code:
<resources>
<string-array name="planet_names">
<item>mercury</item>
<item>venus</item>
<item>earth</item>
<item>mars</item>
</string-array>
<integer-array name="planet_images">
<item>@array/mercury_images</item>
<item>@array/venus_images</item>
<item>@array/earth_images</item>
<item>@array/mars_images</item>
</integer-array>
<integer-array name="mercury_images">
<item>@drawable/mercury_0</item>
<item>@drawable/mercury_1</item>
<item>@drawable/mercury_2</item>
</integer-array>
<integer-array name="venus_images">
<item>@drawable/venus_0</item>
<item>@drawable/venus_1</item>
<item>@drawable/venus_2</item>
</integer-array>
<integer-array name="earth_images">
<item>@drawable/earth_0</item>
<item>@drawable/earth_1</item>
<item>@drawable/earth_2</item>
</integer-array>
<integer-array name="mars_images">
<item>@drawable/mars_0</item>
<item>@drawable/mars_1</item>
<item>@drawable/mars_2</item>
</integer-array>
</resources>
When user will open planet selector, you will iterate through contents of R.array.planet_names array, each item (planet) in this selector will have itemId set to array index. When user will click on something, you will get itemId of clicked item, then you will find array of its images as R.array.planet_images[itemId] (not exactly - it's conceptual example).
You will be able to add new images or even planets through XML editing.
Steven__ said:
Yes, I can see why you'd want to do it this way. Your current problem is that if you add more images, you have to manually update your arrays. Unfortunately I can't think of a better, 'clean' way of doing it.
Click to expand...
Click to collapse
Brut.all said:
But if you don't want to declare all images in sources, but in XMLs, then you could use XML arrays...
...You will be able to add new images or even planets through XML editing.
Click to expand...
Click to collapse
as i posted earlier this was the idea that i had - i havent tried it yet because i wanted to get some feedback from you guys just to see if i was completely off base. so right now its coming down to what would make for the more memory efficient final product - declaring all these images as class array constants (which i already have working) or using xml and coding the operations for parsing, counting, filtering, assigning, etc?
again thank you guys for your time and help
kadmos said:
or using xml and coding the operations for parsing, counting, filtering, assigning, etc?
Click to expand...
Click to collapse
Do you mean parsing XMLs? My example above uses standard Android resources. You don't have to parse these XMLs, you will get them as arrays And yes, it's super efficient, because they are compiled to easy-to-read form
ok then im going to go ahead and try it
be back soon
i hope

[Q] Linkify vs TextView vs setMovementMethod

hi,
I'm loading a standard HTML code into a text view and would like to see the links to be possible to click and call the browser (web intent)
from all my readings the following code was supposed to work:
Code:
TextView tx = new TextView(this);
tx.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
tx.setText(Html.fromHtml(item.get_text()));
tx.setMovementMethod(LinkMovementMethod.getInstance());
mLayout.addView(tx);
but the fact is.. it does not work!
according to google API example link.java
Code:
TextView t3 = (TextView) findViewById(R.id.text3);
t3.setText(
Html.fromHtml(
"<b>text3:</b> Text with a " +
"link " +
"created in the Java source code using HTML."));
t3.setMovementMethod(LinkMovementMethod.getInstance());
it was supposed to be that simple, in it's declaration text3 have no special tags.
I tried several options using Linkify(tx, Lkinkify.ALL); tx.setClickable(true); tx.setLinksClickable(true); setAutoLinkMask(Linkify.ALL) and regardless of what combination I tried I cannot make those HTML links clickable!
important to note that every time I use setMovementMethod the underline on the links disappear from the TextView
any help please??
Have you tried just putting the html from their example in the fromHTML method? It shouldnt be any different but when stuff doesn't work its good to simplify.
Maybe your item.getText is wonky
From something awesome
Just to "close" the post.
at the end I guess was just some mixed binaries floating in my phones flash.. cause after I unistall the app, re-copy the code from the examples and tried it just worked... go figure.
in case anywant fancy.. the final code is:
Code:
TextView tx = new TextView(this);
tx.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
tx.setTextColor(getResources().getColor(R.color.txt));
tx.setLinkTextColor(getResources().getColor(R.color.txt));
tx.setMaxWidth((int) (getResources().getDisplayMetrics().density * 360));
tx.setText(Html.fromHtml(item.text));
tx.setMovementMethod(LinkMovementMethod.getInstance());
TextLayout.addView(tx);
if any forum moderator sees this feel free to close the thread.

Categories

Resources