Upgrade to Pro — share decks privately, control downloads, hide ads and more …

CodePath Android with Deonna: Week 4, Unit 4 - Twitter Part 2

CodePath Android with Deonna: Week 4, Unit 4 - Twitter Part 2

Deonna Hodges

October 10, 2020
Tweet

More Decks by Deonna Hodges

Other Decks in Programming

Transcript

  1. New York Times API Lab what will we cover? Breakout

    rooms Twitter Part 2: Concepts Live Coding: Passing Data Deonna’s opinions on Android that no one asked for (time permitting)
  2. Character Count Compose Passing Data twitter part 2: user stories

    https://courses.codepath.org/courses/android_university/unit/4#!assignment
  3. Creating Menu XML https://guides.codepath.com/android/Defining-The-ActionBar#adding-action-items // res/menu/menu_main.xml <menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto"> <item

    android:id="@+id/compose" android:icon="@drawable/ic_compose" app:showAsAction="ifRoom" android:title="Compose"> </item> <item android:id="@+id/profile" android:icon="@drawable/ic_profile" app:showAsAction="ifRoom" android:title="Profile"> </item> </menu>
  4. Inflating the Menu https://guides.codepath.com/android/Defining-The-ActionBar#adding-action-items // MainActivity.java public class MainActivity extends

    AppCompatActivity { @Override public boolean onCreateOptionsMenu(Menu menu) { // This adds items to the AppBar if it is present. getMenuInflater().inflate(R.menu.menu_main, menu); return true; } }
  5. Handling Clicks https://guides.codepath.com/android/Defining-The-ActionBar#handling-actionbar-clicks // MainActivity.java @Override public boolean onOptionsItemSelected(MenuItem item)

    { // Handle clicks on the app bar items switch (item.getItemId()) { case R.id.compose: composeMessage(); return true; case R.id.profile: showProfileView(); return true; default: return super.onOptionsItemSelected(item); } }
  6. Intent Review https://guides.codepath.com/android/Using-Intents-to-Create-Flows#passing-data-to-launched-activities // ActivityOne.java public void launchComposeView() { //

    First param is the context // Second param is the activity to launch Intent i = new Intent(ActivityOne.this, ActivityTwo.class); // Put data into the bundle for access in the second // activity i.putExtra("username", "deonna"); // Bring up the second activity startActivity(i); } // ActivityTwo.java protected void onCreate(Bundle savedInstanceState) { // Can access any data passed from ActivityOne String username = getIntent().getStringExtra("username"); doSomethingWithUsername(username); }
  7. Handle Intent in MainActivity Passing Data Between Activities Store data

    in new activity Intent Finish new activity Start new activity from MainActivity https://guides.codepath.com/android/Using-Intents-to-Create-Flows#passing-data-to-launched-activities
  8. Starting New Activity https://guides.codepath.com/android/Using-Intents-to-Create-Flows#passing-data-to-launched-activities // MainActivity.java // REQUEST_CODE can be

    any value we want // REQUEST_CODE is used to determine the result type later private final int REQUEST_CODE = 20; public void onClick(View view) { Intent i = new Intent(MainActivity.this, ComposeActivity.class); startActivityForResult(i, REQUEST_CODE); }
  9. Storing and Sending Data https://guides.codepath.com/android/Using-Intents-to-Create-Flows#passing-data-to-launched-activities // ComposeActivity.java // This activity

    is launched for a result public void onDone(View v) { EditText tweet = (EditText) findViewById(R.id.tweet); Intent data = new Intent(); // Pass relevant data back as a result data.putExtra("new tweet", tweet.getText().toString()); setResult(RESULT_OK, data); // Close the activity and pass data to parent finish(); }
  10. Handling Data https://guides.codepath.com/android/Using-Intents-to-Create-Flows#passing-data-to-launched-activities // MainActivity.java // Time to handle the

    result of ComposeActivity @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (resultCode == RESULT_OK && requestCode == REQUEST_CODE) { // Extract tweet value String newTweet = data.getStringExtra("new tweet"); doSomethingWithNewTweet(newTweet); } }
  11. Java to Kotlin Cheat Sheet Constants and Variables: https://github.com/MindorksOpenSource/from-java-to-kotlin#constants-and-variables Assigning

    the Null Value: https://github.com/MindorksOpenSource/from-java-to-kotlin#assigning-the-null-value Nullability: https://github.com/MindorksOpenSource/from-java-to-kotlin#verify-if-value-is-null String Concat: https://github.com/MindorksOpenSource/from-java-to-kotlin#concatenation-of-strings Typechecking + Casting: https://github.com/MindorksOpenSource/from-java-to-kotlin#check-the-type-and-casting Switch Statement: https://github.com/MindorksOpenSource/from-java-to-kotlin#multiple-conditions-switch-case Defining Methods: https://github.com/MindorksOpenSource/from-java-to-kotlin#defining-methods-with-return Constructors: https://github.com/MindorksOpenSource/from-java-to-kotlin#constructors Getters + Setters: https://github.com/MindorksOpenSource/from-java-to-kotlin#getters-and-setters Anonymous Classes: https://github.com/MindorksOpenSource/from-java-to-kotlin#anonymous-class
  12. breakout rooms what new habits / hobbies have you gotten

    into in 2020 that you want to continue? what is your favorite app? how would you improve it? if you could be a kitchen appliance what would you be? what was the last truly great show you’ve watched or book you’ve read? android or iOS?