7. Android Apps

7.1 Getting Started with Android Studio

developer.android.com/studio Prior to starting the Java training, we recommend downloading Android Studio and start updating it. This will save valuable time later when you start the Android App Dev training. We recommend using Windows or Mac. I could not get it to work on Linux. If you would like to use Linux, please document your install and share it with us.
  1. Visit developer.android.com/studio and download the latest version of Android Studio.
  2. Download the Java SE Dev Kit if you don't have it.
  3. Follow the direction to install it on your operating system.
  4. Consider bookmarking the Meet Android Studio page, User Guide and the Java documentation. They might be useful later.
  5. At the welcome screen, click configure and download all the SDK stuff
7.1.2 Set up GitHub
  1. Download Git.
  2. At the Android Studio welcome screen, click "configure" on the bottom of the screen
  3. click "settings"
  4. click triangle on "Version Control"
  5. click "GitHub"
  6. Enter username and password
  7. Click "Test"
  8. Click "Apply"
7.1.3 Android Resources
Geny Motion: genymotion.com Android emulator Android Asset Studio: romannurik.github.io/AndroidAssetStudio Make launcher icons and other fun stuff.

7.2 Introduction to Java

www.udacity.com/course/intro-to-java-programming--cs046 www.codecademy.com/learn/learn-java Prior to taking the Udacity Android course, Udacity recommends having experience with Java or Python or C++, and Github. You should have some experience with Python and Github after completing our level 3 trainingJavaScript is not the same as Java, but you may see some similarities. You may also notice some similarities to C++ as well. You can take Udacity's Java course if you like videos or you can take Codecademy's course if you their interactive environment. Or you can just skip ahead to the Android course if you feel confident in your coding skills.

7.3 Pushing to GitHub

http://www.goprogramming.space/connecting-an-android-studio-project-with-github/ I am not entirely sure if publishing an Android Studio App on GitHub is included in Udacity Android Course or not. I did not see a lesson on it. It may be assumed you already know how to do it. Even though I had used GitHub before, I was confused about how to put an Android Studio app on GitHub. You may want to download Git before following the London App Developer tutorial. I did not get this to work. I used the GitHub Desktop App instead. Let us know if it works for you.

7.4 Udacity Android Course

https://www.udacity.com/course/developing-android-apps--ud853 Google suggests taking this course. It has lots of videos. The video playlist is below if you want to watch the videos. [youtube https://www.youtube.com/watch?v=videoseries?list=PLAwxTw4SYaPnMwH5-FNkErnnq_aSy706S&w=560&h=315]

 7.5 Argue4Liberty

7.5.1.a Download the Repository with GitHub Desktop App
While there are likely other ways to do this, this is the way I did it. If another way works better for you, let us know by commenting below.
  1. Download the GitHub Desktop App
  2. Go to github.com/coders4liberty/argue4liberty4me4 and fork it.
  3. Open the GitHub Desktop App
    1. Clone the argue4liberty4me4 repository you just forked.
    2. click the + sign
    3. Click Clone
    4. Click argue4liberty4me
    5. Click the check mark at the bottom
    6. Select a directory you can find easily or the Android Studio Projects directory
  4. Open Android Studio and click "Open Existing Project" and navigate to where you downloaded the repository and open it.
  5. Ignore the dialogues about Git and GitHub until you figure out how to fix it. Then let us know how you fixed it.
7.5.2 Add New Features & Arguments
Use your extensive knowledge of Java and Android to add a button or add more arguments to the app.
7.5.2.1 Arrays
http://www.tutorialspoint.com/java/java_arrays.htm In order to have more than 1 argument per category, it helps to have arrays. There is more than one way to declare arrays. They added another version to help C++ coders who use Java. The preferred way:
final String[] taxList = {getString(R.string.tax0), getString(R.string.tax1)};
You should put your strings in the XML file and use the getString method to get the string from the resource using the integer value represented by R.string.yourstring. I know, it sounds crazy. But it might make it easier to translate the app. To add an argument to the app, go to the strings page in the res (resources). It might be buried in the values. argue4liberty4me4/app/src/main/res/values/strings.xml

Then you find the category you want to add it to and add it like so:

Please use the category name and number it to help keep it nice and neat. Then go to the main activity:

argue4liberty4me4/app/src/main/java/us/votedifferent/code4liberty/argue4me/MainActivity.java

and add the string to the array like so:

final String[] categoryList = {getString(R.string.category0), getString(R.string.category1)};
7.5.2.2 Random
http://stackoverflow.com/questions/363681/generating-random-integers-in-a-specific-range If you don't know, look it up in the reference. If you still don't know, Google it. If you still don't know, ask a friend. But for that second step, Googling, you will likely find Stack Overflow. And that's where we got the random number generate to randomly pick an element from the array. However, when you're dealing with arrays your minimum is 0 and your maximum is 1 less than the length of the array, so the formula we found on Stack Overflow simplifies quite nicely. You would only need this if you're making a new category, but you can probably just copy and paste it and change the variables.
Random rand = new Random();
int w = + rand.nextInt(warList.length);
sendLine(warList[w]);
7.5.2.3 Copy to Clipboard
https://developer.android.com/guide/topics/text/copy-paste.html#Pasting You shouldn't have to mess with this at all, but this is the code used in the app:
 copyButton.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        // if the user selects copy
        //case R.id.menu_copy:

// Gets a handle to the clipboard service.
        ClipboardManager clipboard = (ClipboardManager)
                getSystemService(Context.CLIPBOARD_SERVICE);
// Creates a clip object with the Intent in it. Its label is "Intent" and its data is
// the Intent object created previously
        ClipData clip = ClipData.newPlainText("argument", receivedArgument);

        // Set the clipboard's primary clip.
        clipboard.setPrimaryClip(clip);
        TextView newLine = (TextView) findViewById(R.id.copy);
        String copied = getString(R.string.copied);
        newLine.setText(copied);
    }
});
7.5.3.a Reupload the Repository to GitHub
  1. When you are done, click the disk icon to save and close Android Studio
  2. Go back to the GitHub Desktop App
  3. Click "Sync"
  4. Write what you added in the update field and describe it in more detail in the description field.

7.5.4. Generate an APK

  1. If you don't see menus on the left side, click box in lower left hand corner
  2. click "Build Variants"
  3. click "debug" and select "release" from drop-down menu
  4. Click "Build" in the top menu
  5. Select "Generate signed APK"
  6. Click "Create New" to create a new key. This is like a digital signature.
    1. Pick an easy to find folder to save your key.
    2. Enter password and confirm it
    3. Enter your code name in the alias field
    4. Enter Password and confirm it
    5. Pick an arbitrary number of years. Consider how long you will want to use this key
    6. You only have to fill out one field in the Certificate section. i.e. you could put "Coders for Liberty" in as the organization.
    7. Click OK to finish your key.
  7. Enter your passwords and alias
  8. Click "Next"
  9. Pick a convenient place to save the APK
  10. Click "Finish"
  11. Click "Show in Folder" link in the pop up window.
  12. APK will be called app-release.apk. You might want to change the name to something like a4L.apk
Congratulations! You have completed the level 7 training! Great work!