Sunday, January 24, 2016

Choices I

             

GitHub

I thought I had already made, a post about this one, but I guess this will be the first. This is a simple app. A user will be able to add items to a list, press a button, and one of the list items will be selected. I'd like to have a navigation drawer that will contain previous lists that users have made.

 I did a bit of work on this last month, I just wanted to see if I could set up a search view, and it worked out pretty well. All that code is commented out at the moment. Today I've been experimenting a bit with Circular Progress Buttons, Ideally, each list item will be a CPB, and when the decision button is pressed, they will change color or disappear or animate or something.

Next, I want to just get get it working, so that I can add items, and use the decision button to select one.




Monday, January 4, 2016

Calculator VIII: It Doesn't Quite Add Up

GitHub

So I noticed a couple issues with my calculator a few days ago and I've been putting off fixing them. The idea of going back into code that I wrote months ago didn't seem appealing. How would I remember how certain things worked? If I changed one thing, would it mess up something important that I had done before. But I jumped into it today, and saw that I had done a good enough job the first time that, even without comments, I was able to remember how it fit together pretty easily, and it's all fairly modular, so I was making changes to specific things rather than having to fix things multiple times across my code.

There were three problems initially. The "-" button was only worked if there was already a number onscreen, so users couldn't start a calculation with a negative number. Also, if the square root button was pressed while a negative number was onscreen the app would crash. And finally, app allows users to chain operations i.e. 5 + 5 + 6, rather than having to press 5 + 5 = 10 + 6, but when the square root button is pressed for a second operation, it would give the square root of the second number and completely disregard the first. In fixing these issues, I realized that I had another problem with operations not displaying correctly after square root was pressed. After pressing SR, the value for the next operation would always be 0.

The negative problem was fairly easy to solve. When pressing "-", I just needed to check if the screen was empty, and if so use my pressKey() method to display a negative symbol onscreen. I also just had to add a check to see if just "-" was onscreen, so two operation buttons couldn't be pressed in a row. The SR, crashes I dealt with by adding a boolean in my pressSqrt() method that is false unless the first character onscreen is "-", and then adding a check against this boolean before Math.sqrt is used.

The other issues were a bit trickier. I ran into the operational errors with the SR button, but wasn't exactly sure what was causing it. I knew though, that this operational button was set up differently than the others, because it was meant to be used with just one value rather than two like the +/- buttons. So I used my operation() method as an example. I saw that in that method I was setting the value that would be used in my operation display. I wasn't doing this in my pressSqrt() method, and that was my problem.

With this out of the way, I turned to the SR button's the mid-operation problem. Again, because the button is meant to be used with just one value, I wanted to disable it's use mid operation. I thought the best way to do this, would be just checking the contents of the operation TextView, so that if there were anything there, SR wouldn't do anything. I checked to see if "" was in the operation TextView, but this did not work. Even if the TextView was cleared(which happens automatically after "=" or "AC" is pressed), the SR button would be completely disabled. I took a look at my variable and saw that in those situations, it contained not "", but "", and line break and another blank space. The operation TextView contains two lines, one for the value, and one for the operator, hence my problem. I fixed it by adding a trim() to my check, and viola, a perfectly(until I realize something else is wrong) working calculator.