Tuesday, October 29, 2013

Saving to device

UWS and Grubby Boston use a remote file for data, an XML on a website. According to the Android himself, these are the storage methods apps can utilize:
Shared Preferences - Store private primitive data in key-value pairs.
Internal Storage - Store private data on the device memory.
External Storage - Store public data on the shared external storage.
SQLite Databases - Store structured data in a private database.
Network Connection - Store data on the web with your own network server
The next app to come from Butterfruit Labs will store a user profile on the device directly, as in, Internal Storage. External storage saves space on the device, but takes more battery to download and upload. Since the files for our next undisclosed app will be so small, we go internal. From my research, the only read/write permissions are:
 
READ_EXTERNAL_STORAGE
WRITE_EXTERNAL_STORAGE

So its not even necessary to add an extra permission to write internally. To do that, just:

fileoutputstream = new FileOutputStream( root + "/" saveFileName );
 

Saturday, October 26, 2013

Update released

Upper West Sliders version 1.1 has just been released.

Updates:
More deals in the 90's and 100's
New no deals button (hopefully you will never see this)
Food search bug fix
Faster splash screen


 Check it out on Google Play here:
https://play.google.com/store/apps/details?id=labs.butterfruit.upperwestsliders

Button vs ImageButton

All ImageButtons are buttons but not necessarily Buttons, and obviously not all buttons are ImageButtons. Are all TextButtons Buttons? Yes, but it's a trick question, because TextButtons don't exist, since Buttons are text buttons.

When Upper West Sliders couldn't come up with any deals (rare),  some simple text would be displayed informing the user of this sorry state. That's not really helpful, so I wanted to turn that text into a Button, which lets them search again. What's a Button? According to Google, inventor of the Android Button, a Button:

"Represents a push-button widget. Push-buttons can be pressed, or clicked, by the user to perform an action.
A typical use of a push-button in an activity would be the following:
 public class MyActivity extends Activity {
     protected void onCreate(Bundle icicle) {
         super.onCreate(icicle);

         setContentView(R.layout.content_layout_id);

         final Button button = (Button) findViewById(R.id.button_id);
         button.setOnClickListener(new View.OnClickListener() {
             public void onClick(View v) {
                 // Perform action on click
             }
         });
     }
 }"
 
A button looks pretty basic. Instead of just some text with a rectangular background, why not make the button look like something fun, and delicious, like a hamburger? Yes, Hindus will not like this app, but it will be a big hit in Johnson Market (a Muslim meat market, not a gay bar). To do that we need an ImageButton. Remember that dude, mkyong, I love? Let's ask him for help with an ImageButton:

"
In Android, you can use “android.widget.ImageButton” to display a normal “Button“, with a customized background image.
In this tutorial, we show you how to display a button with a background image named “android_button.png“, when user click on it, display a short message. As simple as that.
1. Add Image to Resources
Put image “android_button.png” into “res/drawable-?dpi” folder. So that Android know where to find your image.
2. Add ImageButton
Open “res/layout/main.xml” file, add a “ImageButton” tag, and defined the background image via “android:src“.
3. Code Code
Here’s the code, add a click listener on image button.
package com.mkyong.android;
 
import android.app.Activity;
import android.os.Bundle;
import android.widget.ImageButton;
import android.widget.Toast;
import android.view.View;
import android.view.View.OnClickListener;
 
public class MyAndroidAppActivity extends Activity {
 
 ImageButton imageButton;
 
 @Override
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main);
 
  addListenerOnButton();
 
 }
 
 public void addListenerOnButton() {
 
  imageButton = (ImageButton) findViewById(R.id.imageButton1);
 
  imageButton.setOnClickListener(new OnClickListener() {
 
   @Override
   public void onClick(View arg0) {
 
      Toast.makeText(MyAndroidAppActivity.this,
    "ImageButton is clicked!", Toast.LENGTH_SHORT).show();
 
   }
 
  });
 
 }
 
}

4. Demo

Run the application.
1. Result, a button with a customized background image.
2. Click on the button, a short message is displayed.

Android help shoutout

Lars (see post below) has helped me out a lot with my apps, but I'd like to recognize another super star, 
I won't even hide his Android page in a hyperlink:
http://www.mkyong.com/tutorials/android-tutorial/
Such great tutorials. If you poke around his site, you'll see tutorials for lots of other languages, too. What's his real name? Nobody knows. Actually, I just checked his Google+ page and it says his name is Yong Mook Kim. Here is a picture of this handsome hero:

XML from a remote database

UWS uses an XML format data file, hosted on the internet. To help me with this, I went to the site of Lars Vogel. Thank you please, Lars. First, you have to chose a built in parser

" The Java programming language provides several standard libraries for processing XML files. The SAX and the DOM XML parsers are also available on Android.
The SAX and DOM parsers API is on Android the same as in standard Java. SAX and DOM have their limitations, therefore it is not recommended to use them on Android. Therefore this tutorial does not give an example for the usage of this library.
The Java standard provides also the Stax parser. This parser is not part of the Android platform.
Android provides for XML parsing and writing the XmlPullParser class. This parser is not available in standard Java but is similar to the Stax parser. The parser is hosted at http://www.xmlpull.org/ .
On Android it is recommended to use the XmlPullParser. It has a relatively simple API compared to SAX and DOM and is fast and requires less memory then the DOM API."

With one of these parsers ready, add the permission to open external web pages, then point your parser to the page you want! I made my page very simple, with only XML data. 

Friday, October 25, 2013

Live, planned updates, listview intro

Upper West Sliders is already on the market, but I have updates in the works. UWS relies heavily on ListView. 
"ListView is a view group that displays a list of scrollable items. The list items are automatically inserted to the list using an Adapter that pulls content from a source such as an array or database query and converts each item result into a view that's placed into the list."
Right now, when there are no deals to be shown, you just get a little message saying so. I am going to learn how to make a ListView entry that shows when the next deal is happening. That's a lot more helpful. 
Here is an example of a ListView populated with burgers and maybe a pizza:

Thursday, October 24, 2013

New app published

Nirmal has just uploaded a new APK to the Google Play App Store, it will go live in a few hours! And, it is free, as in mangoes.