Friday, August 28, 2015

Enemies V

GitHub

Bugfixes


Last night, I showed a friend the app and he pointed out that, while he couldn't enter an empty text field he could enter a blank one that's just full of spaces. To fix it, I just used trim() on my input variables before validation. I also noticed a few other things while I was at it.


When users edit a text field, I have the previous text show up in the edittext. The cursor was always at the beginning of the text, and I would always have to place it at the end. After a little research, I figured out that I could amend this with the edittext's setselection() property. It was still a little tricky. I was using it in a dialog builder, and it wasn't having any effect. I realized that the setselection() statement has to be the last thing before I call builder.setview().


I also decided to institute a 30 character limit for Enemy names, which I put into the textWatcher that I had already set up. I disabled the submit button and displayed a toast. A problem then arose that every character the user entered after the limit would generate it's own subsequent toast. So I set up a Toast variable set to null, and a displayToast() method, which checks for the value of toast. If the toast is null, it is created and displayed, otherwise the toast is cancelled. Fuck. I just realized that this won't work if there are multiple Enemies, because there is only one toast value. I guess I'll have to set the toast to null after a certain point, like after submit is clicked, that way the Toast variable will start out fresh for every new entry. I guess when the Add or edit buttons are pressed.


I've still got to tackled Data persistence to finish this up. I've been looking into it, and I think my best option is to use a combination of shared preferences and Gson to convert my Enemy and Reason objects into json data.

Thursday, August 27, 2015

Enemies IV

                                

GitHub

Changes

So, I styled my cards a bit and increased the text size. I also did move to a new library for my FAButton and it works pretty much like I want it to. Like in my other ListView, I added delete/edit function onLongItemClick. The biggest change was another update to my data model, mostly to support the date for my timestamp. I could have probably made one before, but I was concerned that if the data wasn't attached specifically to each description, I'd have a lot of trouble saving it. 


Previous Model
Enemy Class:
Name(String), Descriptions(ArrayList<String>) 

New Model
Enemy Class:
name(String), Reasons(ArrayList<Reason>)
Reason Class:
description(String), time(Date)


This made completing my CardAdapter much easier, because I really needed a description and a timestamp that were attached to the same object. I used a viewholder pattern for my card adapter.


I've come to a realization

Last night, after literally three hours of scouring google and stackoverflow and fighting with my code, I decided that it really wasn't worth it to style my dialogs. I had some other cool ideas in mind for this app too: Swipe to delete with a snackbar, longClick select for my detail page that would switch out the add FAB with one for deleting posts. I'm not doing those either. The 1.0 version of Enemies is going to look pretty much as it does now. At this point, it is just an egregious waste of time to spend hours trying to implement some design feature(The brown and yellow dialogs I had in mind would have looked horrible anyway.) I want to be pushing myself in new directions and learning valuable new things. Basically, learning how to effectively work with java is going to take precedence right now. I'll be back eventually to style the crap out of this app, and hopefully when I do, it will come a lot easier.


So now all that's left is data persistence.



 


Wednesday, August 26, 2015

Enemies III


                         

New things


  • I've got a good looking FAButton that does a neat little animation when the activity  first starts.

  • The Button prompts a dialog, with which the user can add a 280 characters of text to their list.

  • The dialog has a little counter the live-updates as characters are typed. 

  • The counter changes color to red if the user goes over the character limit, and they can't submit if the input is either empty or over the limit.





                         

Github



Some Frustration



I'm making progress, but it's a bit wearying. I'm doing this to sort of get away from it for a bit. I know exactly what I'd like to do and pretty much how to do it. But actually executing my plan, is taking a lot longer than I expected. The things that I thought would be the most difficult, we're actually pretty easy to implement with the help of 3rd party libraries.  I'm using this library for my fab now, but I think I'm going to switch to this one. There's not as much customization, and I'm going to lose that animation, but the functionality is closer to what I want. I'd ideally Like the FAB to float above the listview and disappear when scrolled. That's what I'm going to tackle next. 


I've also got cards now for my listView. I've still got to do a bit of work on the CardAdapter. I added a date property to my Enemy class, and I want to use that to get a time stamp on my cards. Just realized that won't work. I need to have a date for each String in the ArrayList. Maybe a Hashmap? I don't know.




Choices I

So this is just an idea at the moment. It's going to be my next app once I finish with Enemies. It's something that I came up with the other day when I was trying to decide where to get take-out from. It basically a coin flip with multiple, specific choices.

Users will be able to add items to a list, and press a button. The button will choose one item. I was thinking maybe the chosen item would be highlighted a different color, the items that aren't chosen could slide away. I may implement a drop down menu so users can select weight so some items have a greater chance of being selected than others. Users will be able to save lists and reuse them. I'm thinking a navigation drawer that holds and archive of saved searches.

Tuesday, August 25, 2015

Enemies II

It's been a while since my last update, and I feel like I know some much more than I did then. I've been going through a couple books, and whatever app tutorials I could find online, just making as many apps as I could. Now I feel like I'm really ready to start cranking out my own stuff.


  
Github


Progress I've made


So the app looks pretty much the same, but I completely overhauled the code and made another activity. Before, all I really had was a list that you could add and delete things from, now I've got a real data model. I made an Enemy class, and an EnemyAdapter to add them to my listview. Having theses new classes. will make it far easier to access and modify my data. I also did a bit of refactoring. My onCreate method a real mess before. I created a few methods, mostly to setup click listeners, and the whole thing's a lot more tidy and modular.


Next Steps


1. The Enemy class consists of a name and an Arraylist of strings , which will contain the reasons why this person or company is hated. I need to display the contents of this ArrayList on my DetailActivity. I'd like to use card views. I've never used them before though, so I've got to figure out how they work.

2. Users also need to be able to add more reasons on the detail page. I think I might implement a FAB in the bottom right corner. Another view element that I've never worked with before.

3. I think I might try to use a viewholder pattern in my adapter to make my listview a bit more efficient.

4. And most importantly, users need to be able to save their data. I think I'm going to use shared preferences for this.



Tuesday, August 4, 2015

Calculator VII: The Final Mathening



My first app, completed without the assistance of any kind of tutorial, is finally finished. 

Last Steps


The issue I had before with the operation method was easily fixed. I just needed to call my calculate method before I changed the value of the operator. 

I also added a toast that will let users know if they've gone over the maximum number of digits. To facilitate this addition, I refactored all the keypresses on my number pad into a keypress method. This method only adds a number to the screen if the user is under the limit and displays the toast otherwise.

It could be recency bias, but it really felt like getting the formatting right was the most difficult and frustrating part of this entire project. When previous parts of this didn't work I generally had some idea why, here I was completely unsure of what was going wrong. At first, it seemed pretty easy, I even jumped the gun a bit and made a "final" commit after my first formatting method appeared to be working. I noticed though, that it was formatting pretty much everything: a number like 742.34348 would end up in exponent notation. 

In my method, I had set up a variable to determine if a '.' existed in a number and where it was. Then I tried to set up conditions based on this that would determine how to format the number. No matter how I changed the conditions, the results were always the same, so I realized that my formatting, with the exception of the one in my final "else" clause, wasn't being used at all. 

Instead of using breakpoints and debugging, I thought it would be easier to isolate the issue in a context where I could quickly manipulate data, so I just pasted my formatting method into Eclipse. I had the method return just the decimal index for certain values, and the results were not as I expected. So then I made the method output just the value of the number and I found my problem. The numbers, which I had defined as Doubles, were being displayed in exponent notation before I even had a chance to format them. To remedy this, and I left this commented out in my code, I thought that I could use my original formatting and then format it again based the value of the exponent. This wouldn't have worked anyway, and was crashing my app because I was trying to format a String like it was a Double.  

After a bit of research, I found out about the BigDecimal. This seemed perfect, my numbers would not be converted before I got a chance to format them, and I could get my output to look the way I wanted. I thought that I could just plug them into my code in place of Doubles. The problem is, BigDecimals are immutable, so I couldn't do arithmetic on them and there's not an easy way to get their square root. To make this work, before a Double is displayed onscreen, I convert it into a new BigDecimal, and then use my formatter on the BigDecimal. Now I've got a working calculator. 

So, that's the app I thought would be easy. I can't wait to see what it's like dealing with something more complex, like something with more than one activity for instance. Enemies, I'd like to finish next, but I'm also going to start working on a to do list app and maybe an alarm clock. 

Monday, August 3, 2015

Calculator VI

Github


What I've done


My UI is now finished. I added a calculator font that looks pretty nice, changed the color of my screen and buttons, and I made a small change to my button placement that I think looks better. Changing the button color was a bit more convoluted than I had hoped. I assumed that I could just change each one's background XML attribute, but that gave me a colored square instead of a colored button. I looked it up and learned about setcolorfilter(), with which I changed each button's color programmatically. I set up a colors.xml file, but the setcolorfilter() doesn't seem to give me a way to reference an xml file, so I had to enter the hex codes for each color I wanted.

I noticed an issue--the app crashed whenever just a period is onscreen and an operation button is pressed. So I added a condition to the relevant methods, that will prevent them from running if the screen just has "." on it.

I also added a second textview that shows operations and a method in my code that displays the correct number and operator.


Lingering Issues


My second textview helped me realize that I have a problem with my operation method. In the cases where I'm chaining together operations, the operator is being changed to the new operator too early. So 1 + 3 - 1, will evaluate as 1 - 3 - 1. So, I've got to fix this, and besides that the only thing left is formatting. I played around with decimal format a bit but it's still not to my working like I had hoped. I think I'm going to just make a method that will format my doubles, and change the formatting if they happen to be of a certain length.