Android Development by fredyonge yo Flashcards

1
Q

dp

A

Measurement for pixels

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

alpha

A

Level of transparency

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

String

A

Class (not primitive) made of chars

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

sp

A

text pixel measurement

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

public

A

java code for accessible across entire application

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

static

A

Method relates to whole class and not just instances

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

extends

A

java code for passing attributes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

protected

A

java code for privately accessible to specific package

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

println

A

Java code stands for Print Line

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

“AS: create public View class called view that returns nothing > call it with clickFunction > Log ““info”” ““Button pressed”””

A

“public void clickFunction(View view) { Log.f(““Info””, ““Button Press””); }”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

AS: finde das Suchfehld email

A

EditText email = (EditText) findViewById(R.id.email);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

AS: get email ID text > parse to string > log email text

A

“Log.i(““Info””, email.getText().toString());”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Where do images get stored in Android Studio?

A

The drawable folder

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

AS: find image1 ID defniiere es als image

A

ImageView image = (ImageView) findViewById(R.id.image1);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

AS: set image resource of image as image2

A

image.setImageResource(R.drawable.image2);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

AS: get text > parse to string > parse to double

A

Double doubleName= Double.parseDouble(stringName.getText().toString());

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

“Java: create class called ““HelloWorld”” > print ““Hello World!”””

A

“public class HelloWorld { public static void main(String[] args) { System.out.println(““Hello World””); }}”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

What are classes in Java?

A

Type of object definition

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

What are methods in Java?

A

A chunk of code that does something

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

What is the main method in Java?

A

A method that runs when Java is executed

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

“Java: Log ““Hello World”””

A

“System.out.println(““Hello World””);”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

Java: 8 types of primitives > bit size > purpose

A

1- boolean(true or false)2- char(16-bit, unicode character)3- byte(8-bit, save mem in large array)4- short(16-bit, save mem large array)5- int(32-bit, number)6- float(32-bit, use for short decimals)7- double(64-bit, decimal number)8- long(64-bit, for large range values)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

What does Java do when you put a primitive in a string?

A

Converts it to a string

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

Java: create Arrays of Integers

A

int[] numbers = {1, 2, 3, 4,};

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Java: get array length
numbers.length;//No parenthesis
26
Java Standard: import all util framework
import java.util.*;
27
Java: create List named listName > add new array constructor to list > add numbers to list > remove number to list > log an index > log entire array as string
ArrayList listName = new ArrayList(); listName.add(1);listName.add(2);listName.add(3);System.out.println(listName.get(2));listName.remove(2);System.out.println(listName.toString());
28
Map
Erstellt paare von Aufgaben
29
Java new map named favorits add color:blue , add afavNum: 7 > log Color > remove Num > log map size
"Map favorites = new HashMap();favorites.put(""color"", ""blue"");favorites.put(""num"", 7);System.out.println(favorites.get(""color""));favorites.remove(""num"");System.out.println(favorites.size());"
30
Java: tells us number of items in hash
map.size();
31
AS: convert string to integer
Integer.parseInt();
32
AS: solution to Error:Execution failed for task ':app:buildInfoDebugLoader' bug
Go to Run > Click clean and rerun
33
Where do you do version control with git and github in AS?
Under the VCS tab
34
Java: create a for loop > count by 2s > start at 0 > end at 10
for (x = 0; x <= 10; x += 2) {}
35
Java: create a while loop > count by 1s > start at 0 > end at 10
int x = 0;while (x <= 10) { x++ }
36
array namens family durchgehen, jeden einzelnen Namen ausgeben
for (String name : family) { System.out.println(name);}
37
Java: create a list called family > make list contain strings > add 2 family members
"ArrayList family = new ArrayList();family.add(""Tony"");family.add(""CJ"");"
38
How can you align elements in AS? (4)
1) center of screen2) relative to another element3) corners 4) margin away from the above
39
What do you use to sub group elements linearly? (2)
horizontal or vertical linear layouts
40
AS: animate ID image > change transparency to 50% > set change for 1 second duration
image.animate().alpha(0.5f).setDuration(1000);
41
animate()
AS: Method changes the style properties of an element
42
translationXBy() / YBy()
AS: Method paired with animate() moves element vertically or horizontally
43
Get Arraylist Value
list.get(2) ; 2 = Number in array, list = arraylist name
44
AS: animate ID image > move image down vertically by 2000 pixels > do so over 2 seconds
image.animate().translationYBy(2000f).setDuration(2000);
45
AS: set ID image to 2000 pixels left on app startup
In onCreate methodimage.setTranslationX(-2000f);
46
rotation()
AS: Method rotates the element clock-wise
47
AS: rotate element image once over 2 seconds
image.animate().rotation(360f).setDuration(2000);
48
Error: java.lang.NullPointerException
Error for trying to pass a null variable or instance
49
AS: get image view that is clicked
ImageView image = (ImageView) view;
50
What can you use grid layout for in AS?
You can define views inside the layout to keep elements together
51
AS: method used to retrieve a tagged element
getTag();
52
AS: import media player file > create new audio named audio > play audio
import android.media.MediaPlayer;MediaPlayer audio = MediaPlayer.create(this, R.raw.laugh); audio.start();
53
AS: media player start > stop > pause
.start();.stop();.pause();
54
AS: find video view called videoView > set the video path to demo/video > start the video
"VideoView videoView = (VideoView) findViewById(R.id.videoView);videoView.setVideoPath(""android.resource://"" + getPackageName() + ""/"" + R.raw.demo/video);videoView.start();"
55
AS: create new media controller named mediaController for video controls > Set mediaController as the anchor for the video view > set mediaController as the Media Controller for video view
MediaController mediaController = new MediaController(this);mediaController.setAnchorView(videoView);videoView.setMediaController(mediaController);
56
AS: Add your own code to a method that already exists
@Override
57
AS: call AudioManager called audioManager > get Audio Manager service in context Audio Service > set int max volume to stream music > set int current volume to steam music > set max volume to max > set progress to current volume > set stream volume in onProgressChanged to progress
AudioManager audioManager;audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); int maxVolume = audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC); int curVolume = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC);volumeControl.setMax(maxVolume); volumeControl.setProgress(curVolume); audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, progress, 0);
58
AS: get ID name of button clicked
Id = view.getResources().getResrouceEntryName(id);
59
AS: get file name for raw file
"int resourcesId = getResources().getIdentifier(ourId, ""raw"", ""com.joncorrin.basicphrases"");"
60
AS: create new Handler > create new Runnable > run a log every second
"final Handler handler = new Handler();Runnable run = new Runnable(); @Override public void run() { Log.i(""test"", ""run""); handler.postDelayed(this, 1000);}handler.post(run);"
61
AS: create new countdown timer from 10 seconds > Log seconds left every second > Log finished on finish
"new CountDownTimer(10000, 1000) { public void onTick(long millisecondsUntilDone) { Log.i(String.valueOf(millisecondsUntilDone / 1000), ""Left"");} public void onFinish() { Log.i(""Done"", ""Finished"");}}.start();"
62
AS: show textView > hide it
textView.setVisibility(View.VISIBLE);textView.setVisibility(View.INVISIBLE);
63
Java: try creating new array > catch ArrayIndexOutOfBoundsException > catch general Exception
try { int[] array = new int[3] } catch(ArrayIndexOutOfBounds e){ //print error} catch(Exception e){ //print error}
64
AS: set user permissions for internet in Android Manifest
""
65
AS: Download image via url
public class ImageDownloader extends AsyncTask { @Override protected Bitmap doInBackground(String... urls) { try { URL url = new URL(urls[0]); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.connect(); InputStream inputStream = connection.getInputStream(); Bitmap myBitmap = BitmapFactory.decodeStream(inputStream); return myBitmap; } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return null; } }
66
AS: Execute image downloader class to download images on specific URL
"ImageDownloader task = new ImageDownloader(); Bitmap myImage; try { myImage = task.execute(""https://url.com"").get(); downloadImage.setImageBitmap(myImage); } catch (InterruptedException e) { e.printStackTrace(); } catch (ExecutionException e) { e.printStackTrace(); }"
67
Java: Create a string with three names > split strings into array on spaces
"String string = ""Jon Tony CJ"";String[] splitString = string.split("" "");"
68
".split("""");"
Method splits string into an array
69
Java: convert string into a substring for any indexes
"String river = ""Mississippi"";String riverPart = river.subString(2, 5);"
70
Java: create a Pattern with regex > use matcher to match Pattern to string > use while loop to print while matcher finds pattern
"String river = ""Mississippi""; Pattern p = Pattern.compile(""Mi(.*?)pi""); Matcher m = p.matcher(river); while (m.find()) { System.out.println(m.group(1)); }"
71
AS: Create download content from URL class
"public class DownloadTask extends AsyncTask { @Override protected String doInBackground(String... urls) { String result = """"; URL url; HttpURLConnection urlConnection = null; try { url = new URL(urls[0]); urlConnection = (HttpURLConnection) url.openConnection(); InputStream in = urlConnection.getInputStream(); InputStreamReader reader = new InputStreamReader(in); int data = reader.read(); while (data != -1) { char current = (char) data; result += current; data = reader.read(); } return result; } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return null; } }"
72
AS: Call download content from URL in onCreate
"DownloadTask task = new DownloadTask(); String result = null; try { result = task.execute(""http://url.com"").get(); Log.i(""Content of URl"", result); } catch (InterruptedException e) { e.printStackTrace(); } catch (ExecutionException e) { e.printStackTrace(); }"
73
Steps for downloading content from the internet (3)
1- Create download content class 2- Call class in onCreate3- Set user permissions in AndroidManifest
74
AS: Create random number
Random random = new Random();//Generates number -1 of given (50)randomNumber = random.nextInt(51);
75
AS: What does AsyncTask allow us to do?
Perform actions in the background in a separate thread from the Main thread
76
AS: How does InputStreamReader read data and store from a URL?
One char at a time
77
AS: What method can we use to execute an action when the doInBackground method has completed?
@Overrideprotected void onpostExecute(String s){ super.onPostExecute(s);}
78
AS: Convert a string into a JSON object
JSONObject jsonObject = new JSONObject(string);
79
AS: get object from JSON as specific string
"jsonObject.getString(""string"");"
80
AS: create a JSON array
//JSON has to be setup as an array with objects and propertiesJSONArray arr = new JSONArray(strings);
81
AS: create a loop to iterate through JSON array and get each part as an object
for (int i =0; i JSONObject jsonPart = arr.getJSONObject(i);
82
AS: Add new Geographical location
LatLng geonName = new LatLng(111, 111);
83
AS: Add marker to Geo location > add marker title
"mMap.addMarker(new MarkerOptions().position(everest).title(""Mount Everest""));"
84
AS: Move map camera to everest
mMap.moveCamera(CameraUpdateFactory.newLatLng(everest));
85
AS: use blue default icon for google map marker
"mMap.addMarker(new MakrerOptions().position(everest).title(""Marker"").icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_BLUE)));"
86
AS: zoom in on everest in map
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(everest, 1));
87
AS: Set map type to hybrid
mMap.setMapType(GoogleMap.MAP_TYPE_HYBRID));
88
AS: Set user permissions for fine location
""
89
AS: Create location manager
LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
90
AS: Create location listener
LocationListener locationListener = new LocationListener() {creates onLocation changed, statusChanged, onProviderEnabled, onProviderDisabled methods}
91
AS: Check if location permission is granted > if it's not, request it > if it is, update location
if (ContextCompat.checkSelf(Permission(this, Manifest.permission.ACESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) { ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, 1); } else {locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener);}
92
AS: Listen for updates to location if permission is granted
public void onRequestPermissionsResult(...) { super.onRequestPermissionsResult(...);if(grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) { locationManager.requestLocationUpdate(LocationManager.GPS_PROVIDER, 0, 0, locationListener);}}
93
AS: Request location update on device using a build less than API 23 marshmellow
if (Build.VERSION.SDK_INT < 23) { locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener);}
94
AS: get users latitude and longitude as a new location
LatLng userLocation = new LatLng(location.getLatitude(), location.getLongitude());
95
AS: Get users last known location
Location lastKnownLocation = LocationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);LatLng location = new LatLng(lastKnownLocation.getLatitude(), lastKnownLocation.getLongitude());
96
AS: clear the google map
mMap.clear();
97
AS: Create a new geocoder with users location
Geocoder geocoder = new Geocoder(getApplicationContext(), Locale.getDefault());
98
AS: Create new list for users address
List listAddresses = geocoder.getFromLocation(location.getLatitude(), location.getLongitude(), 1);//1 means were getting 1 address
99
AS: log the users address
"if (listAddresses != null && listAddresses.size() > 0) { Log.i(""Address"", listAddresses.get(0).toString());}"
100
AS: Toast the country name of the users address
"if (listAddresses != null && listAddresses() > 0) { String address = """"; if (listAddresses.get(0).getCountryName() != null) { address += listAddresses.get(0).getCountryName;}}Toast.makeText(MainActivity.this, address, Toast.LENGTH_SHORT).show();//Same for all parts of address, just keep adding and put spaces in between"
101
AS: create code for button to switch over to another acitivity
Intent intent = new Intent(getApplicationContext(), MainActivity.class);startActivity(intent);
102
AS: method for passing variable to other activities
"intent.putExtra(""var"", ""var passed"");"
103
AS: method for getting variable from another activity
"In Oncreate: intent.getStringExtra(""var"");"
104
AS: create a new shared preferences instance > put username string: jon in it > get that string
"SharedPreferenes sharedPreferences = this.getSharedPreferences(""com.joncorrin.appName"", Context.MODE_PRIVATE); sharedPreferences.edit().putString(""username"", ""Jon"").apply(); String username = sharedPreferences.getString(""username"", ""defaultValue"");"
105
AS: Add new items to menu in xml
" android:id=@+id/settings"">"
106
AS: Link menu to main activity
@Override public boolean onCreateoptionsMenu(Menu menu) { MenuInflater menuInflater = getMenuInflater(); menuInflater.inflate(R.menu.main_menu, menu); return super.onCreateOptionsMenu(menu); }
107
AS: log item selected on item selection in menu
"@Override public boolean onOptionsItemSelected(MenuItem item) { super.onoptionsItemSelected(item); switch (item.getItemId()) { case R.id.settings: Log.i(""Menu item"", ""ItemName""); return true; case R.id.settings: Log.i(""Menu item"", ""ItemName""); return true; default: return false; } }"
108
AS: create a yes/no alert
"new AlertDialog.Builder(this) .setIcon(android.R.drawable.ic_dialog_alert) .setTitle(""Are you sure?"") .setMessage(""Do you want to do this?"") .setPositiveButton(""Yes"", new DialogInterface.onClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i){ Toast ...; } } .setNegativeButton(""No"", null) .show(); }"
109
AS: Create a new Users SQLite database
"SQLiteDatabase myDatabase = this.openorCreateDatabase(""Users"", MODE_PRIVATE, null);AS: Create a users table myDatabase.execSQL(""CREATE TABLE IF NOT EXISTS users(name VARCHAR, age INT(3))"");AS: Insert data into Users table myDatabase.execSQL(""INSERT INTO users (name, age) VALUES ('Rob', 34)"");AS: Get name data from users database Cursor c = myDatabase.rawQuery(""SELECT * FROM users"", null); int nameIndex = c.getColumnIndex(""name""); c.moveToFirst(); while (c != null) { Log.i('name"", c.getString(nameIndex)); c.moveToNext(); }"
110
AS: get data from SQLite where age is greater than 18 and name is Jon
"Cursor c = usersDB.rawQuery(""SELECT * FROM users WHERE age > 18 AND name = 'Jon'""), null);"
111
AS: get data from SQLite where the name starts has a k and limit it to the first result
"Cursor c = usersDB.rawQuery(""SELECT * FROM users WHERE name LIKE '%k%' LIMIT 1"", null);"
112
AS: delete 1 Jon user from users database
"usersDB.execSQL(""DELETE FROM users WHERE name = 'Jon' LIMIT 1"");"
113
AS: Display get webView > enable Javascript > set web view client > load webView URL
//Set internet permissions WebView webView = (WebView) findViewById(R.id.webview); webView.getSettings().setJavaScriptEnabled(true); webView.setWebViewClient(new WebViewClient());
114
AS: Display html webView data that says hello
"webView.loadData(""hello, ""text/html"", ""UTF-8""); webView.loadUrl(""https://www.url.com"");"
115
AS: Add new parse object called score > add new score of 86 > save in background
"ParseObject score = new ParseObject(""Score""); score.put(""score"", 86); score.saveInBackground(new SaveCallback() { @Override public void done(ParseException e) { if (e == null) { Log.i(""SaveInBackground"", ""Success""); } else { Log.i(""SaveInBackground"", ""failed"" + e.toString()); } } });"
116
AS: Get data from Parse server
"ParseQuery query = ParseQuery.getQuery(""Score""); query.getInBackground(""ObjectID"", new GetCallback() { @Override public void done(ParseObject object, ParseException e) { if (e == null && object != null) { Log.i(""Value"", object.getString(""username"")); } }});"
117
AS: Add a new color variable in res/values/color.xml
"#666666"
118
AS: Change the color of the navbar
"#0A65D9"
119
Connect ListView mit Array
"Listview listview = (ListView) findViewbyId(R.id.listView);ArrayList arrlist = new ArrayList()arrlist.add(""Fred"");ArrayAdapter arradap = new ArrayAdapter(this, layoutasuwählen, arrlist);listView.setAdapter(arrlist);listVIew.setOnItemClickListener(new AdapterView.OnItemClickListener)()"