How to Android Studio

By Jenny Wang on June 21, 2017
~3 min. read

PIXELS AND SCREEN COMPATIBILITY

================================

dp to pixels

  • float scale = getResources().getDisplayMetrics().density;
  • numPixels = (int) (dp * scale + 0.5f);

ViewConfiguration

  • .get(myContext).getScaledTouchSlop()
    • returns int of the distance in pixels a touch
    • can wander before we think the user is scrolling

android.util package

=====================

Log

  • log stuff to console
  • .i
    • information
  • .e
    • error
  • .d
    • debug

USER INPUT

=======

Button

  • android:onClick- the function to call when button is clicked
  • alternative\/\/\/

      .setOnClickListener(new View.onClickListener() {
          @Override
          public void onClick(View v) {
              //do something
          }
      }
    

ImageButton

  • a button that can have an image on it
  • see Button

CheckBox

  • yes/no input
  • checkBoxElem.isChecked()
    • to get yes/no

Spinner

  • dropdown menu but in popup form
  • selection choices are strings in an array in strings.xml
    • see string arrays in strings.xml below
  • spinnerElem.getSelectedItem().toString()
    • to get selected item

EditText

  • collect text input
  • lines- number of lines the textbox will have
  • editTextElem.getText().toString()
    • to get entered text

LAYOUT

=======

ScrollView

<ScrollView></ScrollView>
  • things inside are scrollable

LinearLayout

  • one thing after another

      <LinearLayout>
          <Element/>
          <Element/>
      </LinearLayout>
    

strings.xml

===========

  • stores app-wide string values/names

      <string-array name="name">
          <item>@string/stringName</item>
    
    • accessed with @array/name
<color name="white">#FFFFFF</color>
  • add color
  • can be accessed in code w/ @color/white

METHODS

========

findViewById(int id)

  • get an element from the UI
  • ex: final EditText nameField = (EditText)findViewById(R.id.EditText’sId);
    • where EditText’sId is found in id=”@+id/EditText’sId”

getBaseContext()

  • returns base context (replaces this)

finish()

  • sends activity to the background
Tags: coding_notes

How to Git

By Jenny Wang on April 22, 2017
~3 min. read

COMMAND PROMPT

===============

pwd

  • get your directory

cd

  • go to that directory (follow pwd’s format)

SETUP

=======

git config

  • –global
    • change setting on all repos
    • disclusion = only change setting on this repo
  • –help
    • get local help page
  • user.name [“name”]
    • get/set username
      • (put “name” after if you want to set it)
  • user.email [“email”]
    • get/set email
  • core.editor [“directory”]
    • get/set default editor to type values in when prompted
    • ex: core.editor “atom –wait”

git init

  • creates new git repository
    • first cd to the correct folder
    • if you want to see it, go to file manager, options, show hidden files (roughly)

DOING STUFF

============

git status

  • shows status of all files in repo
  • untracked- hasn’t been anywhere yet
  • unmodified- unchanged from last commit/ from after pulling
  • modified- changed, but not set to commit yet
  • staged- going to commit soon

git add <filename> [<filename> <filename> ...]

  • add file’s content to next commit
    • -start TRACKING that file, STAGE files, mark
      • merge-conflicted files as RESOLVED, etc
  • see names of untracked files w/ git status
  • ex: git add README
  • -s
    • makes output shorter
    • M = modified
    • A = added
    • ?? = not tracked
    • 2 columns of symbols ^^
      • left = staging area status
      • right = working area status git commit
  • commits the changes in staging area (see git status)
  • w/o -m
    • opens core editor to type message describing commit
    • close core editor window to proceed
  • -m
    • type commit message w/o opening core editor
  • -a
    • commit everything that was changed (skip staging area)

cat .gitignore <press enter> <what to ignore> <enter> <etc>

  • make those files not show up in git status
    • *.[extension] - ignore w/ that extension
    • *[part of name] - ignore w/ that in end of name
    • (note the * in front)
    • disregards lines with # (comment)
  • no .a files
    • *.a
  • but do track lib.a, even though you’re ignoring .a files above
    • !lib.a
  • only ignore the TODO file in the current directory, not subdir/TODO
    • /TODO
  • ignore all files in the build/ directory
    • build/
  • ignore doc/notes.txt, but not doc/server/arch.txt
    • doc/*.txt
  • ignore all .pdf files in the doc/ directory
    • doc/*/.pdf

git diff <filename>

  • shows difference between working directory and staging area
    • ex: lines of code that were changed
  • if discluded, shows all files i think

git log

  • gives list of commits w/ their message

git show <commit>

  • display what changed in that commit (git log?)
  • can be HEAD => the commit you're currently on

git checkout <commit> <filename>

  • restore that file in working directory to that commit’s version

git help <commandName>

  • your friend. opens up local help page (html file)
Tags: coding_notes

How to XML

By Jenny Wang on February 26, 2017
~3 min. read

.xml FILE STRUCTURE

<?xml version="1.0" encoding="UTF-8"?>
<firstThing>
    <second attribute="this">actual thing</second>
    <yeah lang="en">alsdkjfa</yeah>
</firstThing>

see https://www.w3schools.com/xml/dom_nodes.asp

HOW TO ACCESS

setup

var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
    if (this.readyState == 4 && this.status == 200) {
        myFunction(this);
    }
};
xhttp.open("GET", "books.xml", true);
xhttp.send();

get elements

var xmlDoc = xml.responseXML;
var x = xmlDoc.getElementsByTagName("title");

get value

x[3].childNodes[0].nodeValue;
    ^^ 4th child of doc + the 1st child of that element's value/text

OBJECT DESCRIPTION

XMLHttpRequest
    .open(requestType, url, asynchronous/synchronous)
        requestType- "GET" or "POST"
        url- "http://aldkjfalsd" or "file.xml"
        last boolean- true = asyncrhonous (one thing at a time)
            false = synchronous (all at once/real time)
    .send()
        send the request
    .onreadystatechange (event)
        this.
            readyState
                0- request not intialized
                1- server connection established
                2- request recieved
                3- processing request
                4- request finished and response ready
            status
                200- ok
                404- page not found
Tags: coding_notes