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
Q

Java: get array length

A

numbers.length;//No parenthesis

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

Java Standard: import all util framework

A

import java.util.*;

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

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

A

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());

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

Map

A

Erstellt paare von Aufgaben

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

Java new map named favorits add color:blue , add afavNum: 7 > log Color > remove Num > log map size

A

“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());”

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

Java: tells us number of items in hash

A

map.size();

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

AS: convert string to integer

A

Integer.parseInt();

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

AS: solution to Error:Execution failed for task ‘:app:buildInfoDebugLoader’ bug

A

Go to Run > Click clean and rerun

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

Where do you do version control with git and github in AS?

A

Under the VCS tab

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

Java: create a for loop > count by 2s > start at 0 > end at 10

A

for (x = 0; x <= 10; x += 2) {}

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

Java: create a while loop > count by 1s > start at 0 > end at 10

A

int x = 0;while (x <= 10) { x++ }

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

array namens family durchgehen, jeden einzelnen Namen ausgeben

A

for (String name : family) { System.out.println(name);}

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

Java: create a list called family > make list contain strings > add 2 family members

A

“ArrayList family = new ArrayList();family.add(““Tony””);family.add(““CJ””);”

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

How can you align elements in AS? (4)

A

1) center of screen2) relative to another element3) corners 4) margin away from the above

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

What do you use to sub group elements linearly? (2)

A

horizontal or vertical linear layouts

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

AS: animate ID image > change transparency to 50% > set change for 1 second duration

A

image.animate().alpha(0.5f).setDuration(1000);

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

animate()

A

AS: Method changes the style properties of an element

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

translationXBy() / YBy()

A

AS: Method paired with animate() moves element vertically or horizontally

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

Get Arraylist Value

A

list.get(2) ; 2 = Number in array, list = arraylist name

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

AS: animate ID image > move image down vertically by 2000 pixels > do so over 2 seconds

A

image.animate().translationYBy(2000f).setDuration(2000);

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

AS: set ID image to 2000 pixels left on app startup

A

In onCreate methodimage.setTranslationX(-2000f);

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

rotation()

A

AS: Method rotates the element clock-wise

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

AS: rotate element image once over 2 seconds

A

image.animate().rotation(360f).setDuration(2000);

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

Error: java.lang.NullPointerException

A

Error for trying to pass a null variable or instance

49
Q

AS: get image view that is clicked

A

ImageView image = (ImageView) view;

50
Q

What can you use grid layout for in AS?

A

You can define views inside the layout to keep elements together

51
Q

AS: method used to retrieve a tagged element

A

getTag();

52
Q

AS: import media player file > create new audio named audio > play audio

A

import android.media.MediaPlayer;MediaPlayer audio = MediaPlayer.create(this, R.raw.laugh); audio.start();

53
Q

AS: media player start > stop > pause

A

.start();.stop();.pause();

54
Q

AS: find video view called videoView > set the video path to demo/video > start the video

A

“VideoView videoView = (VideoView) findViewById(R.id.videoView);videoView.setVideoPath(““android.resource://”” + getPackageName() + “”/”” + R.raw.demo/video);videoView.start();”

55
Q

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

A

MediaController mediaController = new MediaController(this);mediaController.setAnchorView(videoView);videoView.setMediaController(mediaController);

56
Q

AS: Add your own code to a method that already exists

A

@Override

57
Q

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

A

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
Q

AS: get ID name of button clicked

A

Id = view.getResources().getResrouceEntryName(id);

59
Q

AS: get file name for raw file

A

“int resourcesId = getResources().getIdentifier(ourId, ““raw””, ““com.joncorrin.basicphrases””);”

60
Q

AS: create new Handler > create new Runnable > run a log every second

A

“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
Q

AS: create new countdown timer from 10 seconds > Log seconds left every second > Log finished on finish

A

“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
Q

AS: show textView > hide it

A

textView.setVisibility(View.VISIBLE);textView.setVisibility(View.INVISIBLE);

63
Q

Java: try creating new array > catch ArrayIndexOutOfBoundsException > catch general Exception

A

try { int[] array = new int[3] } catch(ArrayIndexOutOfBounds e){ //print error} catch(Exception e){ //print error}

64
Q

AS: set user permissions for internet in Android Manifest

A

””

65
Q

AS: Download image via url

A

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
Q

AS: Execute image downloader class to download images on specific URL

A

“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
Q

Java: Create a string with three names > split strings into array on spaces

A

“String string = ““Jon Tony CJ”“;String[] splitString = string.split(“” “”);”

68
Q

“.split(“”””);”

A

Method splits string into an array

69
Q

Java: convert string into a substring for any indexes

A

“String river = ““Mississippi”“;String riverPart = river.subString(2, 5);”

70
Q

Java: create a Pattern with regex > use matcher to match Pattern to string > use while loop to print while matcher finds pattern

A

“String river = ““Mississippi””; Pattern p = Pattern.compile(““Mi(.*?)pi””); Matcher m = p.matcher(river); while (m.find()) { System.out.println(m.group(1)); }”

71
Q

AS: Create download content from URL class

A

“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
Q

AS: Call download content from URL in onCreate

A

“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
Q

Steps for downloading content from the internet (3)

A

1- Create download content class 2- Call class in onCreate3- Set user permissions in AndroidManifest

74
Q

AS: Create random number

A

Random random = new Random();//Generates number -1 of given (50)randomNumber = random.nextInt(51);

75
Q

AS: What does AsyncTask allow us to do?

A

Perform actions in the background in a separate thread from the Main thread

76
Q

AS: How does InputStreamReader read data and store from a URL?

A

One char at a time

77
Q

AS: What method can we use to execute an action when the doInBackground method has completed?

A

@Overrideprotected void onpostExecute(String s){ super.onPostExecute(s);}

78
Q

AS: Convert a string into a JSON object

A

JSONObject jsonObject = new JSONObject(string);

79
Q

AS: get object from JSON as specific string

A

“jsonObject.getString(““string””);”

80
Q

AS: create a JSON array

A

//JSON has to be setup as an array with objects and propertiesJSONArray arr = new JSONArray(strings);

81
Q

AS: create a loop to iterate through JSON array and get each part as an object

A

for (int i =0; i JSONObject jsonPart = arr.getJSONObject(i);

82
Q

AS: Add new Geographical location

A

LatLng geonName = new LatLng(111, 111);

83
Q

AS: Add marker to Geo location > add marker title

A

“mMap.addMarker(new MarkerOptions().position(everest).title(““Mount Everest””));”

84
Q

AS: Move map camera to everest

A

mMap.moveCamera(CameraUpdateFactory.newLatLng(everest));

85
Q

AS: use blue default icon for google map marker

A

“mMap.addMarker(new MakrerOptions().position(everest).title(““Marker””).icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_BLUE)));”

86
Q

AS: zoom in on everest in map

A

mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(everest, 1));

87
Q

AS: Set map type to hybrid

A

mMap.setMapType(GoogleMap.MAP_TYPE_HYBRID));

88
Q

AS: Set user permissions for fine location

A

””

89
Q

AS: Create location manager

A

LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);

90
Q

AS: Create location listener

A

LocationListener locationListener = new LocationListener() {creates onLocation changed, statusChanged, onProviderEnabled, onProviderDisabled methods}

91
Q

AS: Check if location permission is granted > if it’s not, request it > if it is, update location

A

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
Q

AS: Listen for updates to location if permission is granted

A

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
Q

AS: Request location update on device using a build less than API 23 marshmellow

A

if (Build.VERSION.SDK_INT < 23) { locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener);}

94
Q

AS: get users latitude and longitude as a new location

A

LatLng userLocation = new LatLng(location.getLatitude(), location.getLongitude());

95
Q

AS: Get users last known location

A

Location lastKnownLocation = LocationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);LatLng location = new LatLng(lastKnownLocation.getLatitude(), lastKnownLocation.getLongitude());

96
Q

AS: clear the google map

A

mMap.clear();

97
Q

AS: Create a new geocoder with users location

A

Geocoder geocoder = new Geocoder(getApplicationContext(), Locale.getDefault());

98
Q

AS: Create new list for users address

A

List listAddresses = geocoder.getFromLocation(location.getLatitude(), location.getLongitude(), 1);//1 means were getting 1 address

99
Q

AS: log the users address

A

“if (listAddresses != null && listAddresses.size() > 0) { Log.i(““Address””, listAddresses.get(0).toString());}”

100
Q

AS: Toast the country name of the users address

A

“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
Q

AS: create code for button to switch over to another acitivity

A

Intent intent = new Intent(getApplicationContext(), MainActivity.class);startActivity(intent);

102
Q

AS: method for passing variable to other activities

A

“intent.putExtra(““var””, ““var passed””);”

103
Q

AS: method for getting variable from another activity

A

“In Oncreate: intent.getStringExtra(““var””);”

104
Q

AS: create a new shared preferences instance > put username string: jon in it > get that string

A

“SharedPreferenes sharedPreferences = this.getSharedPreferences(““com.joncorrin.appName””, Context.MODE_PRIVATE); sharedPreferences.edit().putString(““username””, ““Jon””).apply(); String username = sharedPreferences.getString(““username””, ““defaultValue””);”

105
Q

AS: Add new items to menu in xml

A

” android:id=@+id/settings””>”

106
Q

AS: Link menu to main activity

A

@Override public boolean onCreateoptionsMenu(Menu menu) { MenuInflater menuInflater = getMenuInflater(); menuInflater.inflate(R.menu.main_menu, menu); return super.onCreateOptionsMenu(menu); }

107
Q

AS: log item selected on item selection in menu

A

“@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
Q

AS: create a yes/no alert

A

“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
Q

AS: Create a new Users SQLite database

A

“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
Q

AS: get data from SQLite where age is greater than 18 and name is Jon

A

“Cursor c = usersDB.rawQuery(““SELECT * FROM users WHERE age > 18 AND name = ‘Jon’””), null);”

111
Q

AS: get data from SQLite where the name starts has a k and limit it to the first result

A

“Cursor c = usersDB.rawQuery(““SELECT * FROM users WHERE name LIKE ‘%k%’ LIMIT 1””, null);”

112
Q

AS: delete 1 Jon user from users database

A

“usersDB.execSQL(““DELETE FROM users WHERE name = ‘Jon’ LIMIT 1””);”

113
Q

AS: Display get webView > enable Javascript > set web view client > load webView URL

A

//Set internet permissions WebView webView = (WebView) findViewById(R.id.webview); webView.getSettings().setJavaScriptEnabled(true); webView.setWebViewClient(new WebViewClient());

114
Q

AS: Display html webView data that says hello

A

“webView.loadData(““hello, ““text/html””, ““UTF-8””); webView.loadUrl(““https://www.url.com””);”

115
Q

AS: Add new parse object called score > add new score of 86 > save in background

A

“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
Q

AS: Get data from Parse server

A

“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
Q

AS: Add a new color variable in res/values/color.xml

A

“#666666”

118
Q

AS: Change the color of the navbar

A

“#0A65D9”

119
Q

Connect ListView mit Array

A

“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)()”