« first day    last day (18 days later) » 

7:48 AM
So I should find out the path of where all my emulated images go and reference that instead? :)
I used /images/Car1.png because that's the path in app/images/car1.png
Going to work
 
Easiest thing to do is to put it in your assets folder. That gets wrapped up in the apk that gets installed on the device. You can load assets using the following code InputStream in=getAssets().open(fileName); config = Config.ImageFormat.RGB565; Options options = new Options();
options.inPreferredConfig = config; bitmap = BitmapFactory.decodeStream(in, null, options);
Note you may have to change Config.ImageFormat.RGB565 depending on the format of the image
Cool, bye
Or actually this describes an easier way; stackoverflow.com/questions/18973550/…
 
8:24 AM
Hi Richard o/ out and about today but I'l be here periodically
 
8:43 AM
Ahh, so I could use asset.open("drawable-xhdpi/Car1.png")
 
Android is a little bit magic with its drawable folders. The idea is that default resources go in drawable/ and all the drawable-SOMETHING specify alternative resources for different screen sizes/resolutions. So only Extra High DPI phones load from drawable-xhdpi/.
Putting the image in a drawable folder is an alternative to the assets folder. You can relatively easily load from this folder (one second)
 
I like the little bit magic part :P
 
Looking at it you get a Drawable by loading from the drawables folder. Which is ideal for drawing on the screen, less so for getting the raw bitmap
 
I see a lot of drawable -???????
but no specific drawable folder
 
9:07 AM
You can just make one, it will be automatically picked up
 
Inside res? or app?
 
Yeah inside res so res/drawable.
 
and then the path is "drawable://Car1.png"
 
yes. but drawables are accessed indirectly so (within an activity) getResources().getDrawable(R.drawable.NAMEOFDRAWABLE) but that gives you a drawable rather than a bitmap
 
I'm confused. Sorry...
Oh wait...
Nope, I don't get it haha
 
9:11 AM
Looks like Bitmap bmp=BitmapFactory.decodeResource(getResources(), R.drawable.IMAGENAME); will give you a bitmap rather than a drawable
 
I thought I had to use a different method to redraw it?
 
You are still trying to do the conversion of an image to a string right?
 
To be honest doing that on the phone is probably complicating matters. Personally I'd use a conventional java program to create the string for the database (well personally I wouldn't use the database at all, but I',m assuming that makes sense later)
 
So you'd make a program that does the string part for us, then using that just insert the string to convert
 
9:15 AM
Also your screen shot looks correct
 
Is Car1 purple because it detected it inside my drawable folder?
 
If it couldn't you'd get an compile time error
R is an automatically generated file that does all the "magic" of getting the correct resources
 
That's pretty cool!
So, R.FOLDERNAME.IMAGENAME
 
Not exactly. R only does its magic for certain folders. R.drawable (which typically varies based on screen size and density) R.string which pulls things from res/values/strings (which typically varies based on user language - this makes internationalising the app easy) R.id which allows you to refer to named views within layouts are the 3 main ones
Incidently starting java with android is really jumping in at the deep end
 
That's pretty cool :)
Is there any particular reason getResources() can't resolve method? I imported android.content.Context
Which I had to google :P Because it didn't offer to import
 
9:22 AM
getResources is a method of an Activity, are you calling it within (or on) an activity?
 
At the moment this is inside ByteConvert.Java
http://puu.sh/aoUY9/26a9648ec4.png

Should all this be inside MyActivity.java? haha
 
Then you'll need to pass a reference to an activity to the method
Thats an option, but I would pass a reference instead
 
MyActivity.getResources()?
ahh, I can extend ByteConvert with MyActivity?
fixed :)
public String imageTobMap() {
Bitmap bMap = BitmapFactory.decodeResource(getResources(), R.drawable.Car1);
//String bMapString = bMap.toString();

return encodeTobase64(bMap);
}
and all I did was extend MyActivity
Uhh that's causing issues with

db.createCar(new Car(cars.get_id(),cars.get_address(),cars.get_postcode(), ByteConvert.imageTobMap()));
Reverted back.
So, I can't grab a non-static method from a static context. However, when I make imageTobMap a non-static it says the same for MyActivity.java
 
9:45 AM
Indeed. an instance method (non static) must have an object to act on. Think of this analogy. A car object have a method accelerate it is an instance method because it needs an actual car to act on. if you just called accelerate() without an actual car what should happen? On the other hand `convertMPHToKPH(double MPH) doesn't require an instance to work on because it doesn't car what car its in reference to
getResources() is an instance method not to annoy you but because it needs to be connected up the the assets pipeline. It needs the "state" of an Activity object to work
Incidently just changing to ByteConvert extends Activity won't work because although the method will then be available it won't actually connect to the resources underneath (android adds a lot of state to the Activity when it starts it). You would need to manually connect to those resources if you used an "artificial" activity
*doesn't care what car its in reference to
 
Okay, so. I've gone into ByteConvert.java and made the class extend MyActivity. Ontop of this I've made imageTobMap() not static.

Taking your analogy, I added this to MyActivity.java:

imageTobMap imagetobmap = new ByteConvert().imageTobMap();
oh wait, sorry didn't see what you wrote
I'l remove the extend in that case
So, now that it's not static. I need to create an object for it to act on?
 
To give an annother analogy for why`ByteConvert extends Activity` won't work; you want to get refined oil. On the one hand ESSO will give you a reference to OilRefinary where you can call .getOil()but you think "I can cut out the middle man" and create your own OilRefinary. That seems to work great and you can call .getOil() on it, but the pipes are dry; the reason: theres no crude oil flowing into your OilRefinary (which esso connected up to their OilRefinary object )
Yes, pass a reference to the object you need to act on in the method
 
I think I get it... but what's the object I need to act on? It's .getResources no?
Because I'm not working with any objects at the moment inside imageTobMap? Only methods
 
no, .getResources() is a method. You want to pass the Activity object (aka a MyActivity, you can pass the current object by passing this)
So you would change to String imageTobMap(Activity resourceProvider){.....}
Then call resourceProvider.getResources(). (and then the rest)
 
so when I call imageTobMap in MyActivity it will ask for those two parameters?
 
9:58 AM
Thats just one parameter. Because java is a statically typed language Activity states the kind of object you will be passing resourceProvider gives it a name
 
so what is resourceProvider in terms of MyActivity.java? because I have db.createCar(new Car(cars.get_id(),cars.get_address(),cars.get_postcode(), ByteConvert.imageTobMap())); atm
or have I got to create what resourceProvider is? I'm getting a slight jist of this I think
It's referencing whatever I do in all my classes?
ahh! it can be static now!
Because I'm passing throught the Activity part!
BINGO :D
 
No resourceprovider is "part of" the state of an activity, much like you could call Car car=new Car(); car.getEngine().repair() you can call someActivity.getResourceProvider() or this.getResourceProvider() if you're inside an Activity
Exactly!
 
So the only part I'm still confused about is... what exactly is resourceProvider? Sorry Richard, I am slowly getting there :P I promise! This will flow much better if I get this job and get training
 
A ResourceProvider is annother object. You don't need to worry about how it works only that it will provide resources (like images)
 
But I need to provide a param in ByteConvert.imageTobMap())); :P
 
10:09 AM
so getResourceProvider() provides that object. Again you don't need to worry about where it gets it from
Yes, provide this if you are within an activities (non static) methods
 
As in literally the word "this"
 
as if I were doing this.object
but without the object part :P
 
yeah exactly
 
So, let me evaluate what I have so far!
db.createCar(new Car(cars.get_id(),cars.get_address(),cars.get_postcode(), ByteConvert.imageTobMap(this)));

This creates a new database entry...
which converts Car1.png into Bytes
 
10:13 AM
That all looks good
 
Damn it xD
file name needs all lowercase haha
what a stupid mistake :P
 
Where physically is this database, on a server somewhere? Or on the phone?
 
in Android Studio in general
 
Yeah, I've never been sure why android has that requirement
 
I named them all like Car1, Car2 etc :P
Let's try again!
No error!
Now I can check the database to see if it's added it? :)
 
10:21 AM
yes, where exactly did you put the database?
 
the database is automatically placed in Android studio
I have to export it, use a special program to edit it
then put it back :P
yay!
 
So, In theory.
All I have to do now, is draw it?
 
Well the reverse decoding as per stackoverflow.com/questions/9768611/… and then draw it
 
Not long left! :)
Richard, if this works and I get the position, I will forever be in your debt :p
 
10:27 AM
How long have you got?
No problem
 
If you ever need web design help, I'm here ;)
and tomorrow really... deadline was last night
but I got an extension (I think they know they're pushing me, but they want to see if I can push myself that bit further)
 
This is indeed quite advanced for an interview assignment
 
 
1 hour later…
11:50 AM
I agree, but I'm determined to learn!
Sorry, office re-arranging haha
 
 
3 hours later…
2:57 PM
Hey Richard, am I right in thinking I now need to decode the string in my database?
wait, no. That's what imageTobMap does :D
 
I though decodeBase64() did that?
 
ignore that :3 I was mixing up my methods... imageTobMap decodesResource and reutrns encodeTobase64
I need to decodeBase64 now :)
ByteConvert.decodeBase64();
ByteConvert.decodeBase64(cars);
wait, I've created the new car, db.createCar(new Car(cars.get_id(),cars.get_address(),cars.get_postcode(), ByteConvert.imageTobMap(this)));

and now I'm doing ByteConvert.decodeBase64();
 
3:11 PM
@RichardTingle Can I ask some advice? I'm using imageTobMap() to return encodeTobase64(bMap);

then in my MainActivity, I'm doing ByteConvert.decodeBase64(ByteConvert.bMap); but it can't resolve the symbol bMap, however, I thought it would return as the value bMap?
 
bMpa? As opposed to Bitmap?
 
oh! decodeBase64 only decodes Strings! where as ByteConvert.imageTobMap returns a Bitmap
 
What is ByteConvert.bMap supposed to represent here?
 
I should be grabbing the string from the database
not the Bitmap from the imageTobMap
 
decodeBase64 should take a string and return a Bitmap yes
 
3:13 PM
public static String imageTobMap(MyActivity resourceProvider) {
    Bitmap bMap = BitmapFactory.decodeResource(resourceProvider.getResources(), R.drawable.car3);
    //String bMapString = bMap.toString();
    return encodeTobase64(bMap);
}
This returns a string
db.createCar(new Car(cars.get_id(),cars.get_address(),cars.get_postcode(), ByteConvert.imageTobMap(this)));

Then this puts it in a database
ByteConvert.decodeBase64();

then I need to grab the image string from the db and put it in the parenthesis?
 
Indeed!
 
    // Initiate Database
    DatabaseHandler db = new DatabaseHandler(this); // "this" refer to the context
    // Grab current Car for use.
    Car cars = db.getCurrentCar();
    // Create new Car based on the ByteConvert.java (car1,car2,car3)
    db.createCar(new Car(cars.get_id(),cars.get_address(),cars.get_postcode(), ByteConvert.imageTobMap(this)));
    //Grab String from database and decode to Base64
    ByteConvert.decodeBase64();
Just made it easy to understand ^.^
I leave this for a few hours and forget where I'm at! haha
 
Seems odd that you still have the "adding it to the database" code in there. Isn't it already in the database now?
 
Yea, but I will be adding 2 more cars in before I comment that out ^.^
ByteConvert.decodeBase64(cars.get_image());
!!!! :P
 
Ah thats cool, also that looks good
I'm afraid i'm going to be away from the computer for a little while so i may be slow to respond
 
3:21 PM
No worries! Life takes over :) Have fun
 
 
2 hours later…
4:51 PM
Back :)
 
5:23 PM
@RichardTingle I got it working :) :) :)
 
Awesome!
 
@RichardTingle Adding 3 more images so it pulls 4 random images in a grid
 
5:51 PM
@RichardTingle are you available? I think I'm having a brain fart moment
 
I'm on mobile but I am about for the next 10 mins or so
 
I actually think I have it :) sorry to bother you
 
6:27 PM
@RichardTingle is there a way to force logcat to work? It's not showing errors
 
 
4 hours later…
10:10 PM
It's hard to diagnose that. In eclipse logcat "just works" so this must be an android studio thing. The one thing I would say is that errors that occure "off the main thread" are sometimes swallowed silently (its incredibly annoying). Could this be your problem? (You would know if you were multithreading)
 
@RichardTingle Hey! I actually made a nice bit of progress while you were gone :)
@RichardTingle doing this at the moment github.com/jgilfelt/android-sqlite-asset-helper
Because, I was wondering, how does a phone access a database if it's not package with the app :P
@RichardTingle I guess I actually made 0 progress...
Caused by: java.lang.ArrayIndexOutOfBoundsException
at android.graphics.BitmapFactory.decodeByteArray(BitmapFactory.java:424)
at com.example.brad.myapplication.MyActivity.onCreate(MyActivity.java:72)
@RichardTingle fixed ;) all because you taught me debugging ;)
 
 
1 hour later…
11:33 PM
Nice! Debugging is wildly useful, I use it almost every day
And I'm assuming the database is either accessed "internet style" or it actually is packaged with the app. (Anything in resources or assets will be packaged up). But it's not an area I'm super familiar with
 
11:50 PM
@RichardTingle ahh I assume that means you couldn't help? :P stackoverflow.com/questions/24945851/…
 

« first day    last day (18 days later) »