Skip to content

Commit

Permalink
Add in missing lesson 2 exercise
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeremy Silver authored and Asser committed Oct 2, 2017
1 parent c47de01 commit 95f7929
Show file tree
Hide file tree
Showing 39 changed files with 671 additions and 32 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#Wed Dec 07 11:59:24 PST 2016
#Mon Dec 12 10:00:07 PST 2016
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,6 @@ android {
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:25.0.1'

// COMPLETED (32) Remove the ConstraintLayout dependency as we aren't using it for these simple projects
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,39 +22,25 @@

public class MainActivity extends AppCompatActivity {

// COMPLETED (26) Create an EditText variable called mSearchBoxEditText
private EditText mSearchBoxEditText;

// COMPLETED (27) Create a TextView variable called mUrlDisplayTextView
private TextView mUrlDisplayTextView;
// COMPLETED (28) Create a TextView variable called mSearchResults TextView
private TextView mSearchResultsTextView;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

// COMPLETED (29) Use findViewById to get a reference to mSearchBoxEditText
mSearchBoxEditText = (EditText) findViewById(R.id.et_search_box);

// COMPLETED (30) Use findViewById to get a reference to mUrlDisplayTextView
mUrlDisplayTextView = (TextView) findViewById(R.id.tv_url_display);
// COMPLETED (31) Use findViewById to get a reference to mSearchResultsTextView
mSearchResultsTextView = (TextView) findViewById(R.id.tv_github_search_results_json);
}

// Do 2 - 7 in menu.xml ///////////////////////////////////////////////////////////////////////
// TODO (2) Create a menu in xml called main.xml
// TODO (3) Add one menu item to your menu
// TODO (4) Give the menu item an id of @+id/action_search
// TODO (5) Set the orderInCategory to 1
// TODO (6) Show this item if there is room (use app:showAsAction, not android:showAsAction)
// TODO (7) Set the title to the search string ("Search") from strings.xml
// Do 2 - 7 in menu.xml ///////////////////////////////////////////////////////////////////////


// TODO (8) Override onCreateOptionsMenu
// TODO (9) Within onCreateOptionsMenu, use getMenuInflater().inflate to inflate the menu
// TODO (10) Return true to display your menu

// TODO (11) Override onOptionsItemSelected
// TODO (12) Within onOptionsItemSelected, get the ID of the item that was selected
// TODO (13) If the item's ID is R.id.action_search, show a Toast and return true to tell Android that you've handled this menu click
// TODO (14) Don't forgot to call .show() on your Toast
// TODO (15) If you do NOT handle the menu click, return super.onOptionsItemSelected to let Android handle the menu click
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
<!--COMPLETED (1) Change the ConstraintLayout to a LinearLayout-->
<!--COMPLETED (2) Make the orientation vertical-->
<!--COMPLETED (3) Give left, right, and top padding of 16dp-->
<!--COMPLETED (4) Remove the line that declares the id, we don't need it-->
<!--COMPLETED (5) Remove the xmlns:app declaration, we don't need that anymore-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
Expand All @@ -24,13 +29,25 @@
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.android.datafrominternet.MainActivity">

<!--COMPLETED (6) Delete this TextView-->
<!--COMPLETED (7) Add an EditText-->
<!--COMPLETED (8) Give the EditText an id of @+id/et_search_box-->
<!--COMPLETED (9) Set the text size to 22sp-->
<!--COMPLETED (10) Set the width to match_parent and the height to wrap_content-->
<!--COMPLETED (11) Provide a hint telling the user to enter a query and then click search-->
<EditText
android:id="@+id/et_search_box"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter a query, then click Search"
android:textSize="22sp" />

<!--COMPLETED (12) Add a TextView-->
<!--COMPLETED (13) Give the TextView an id of @+id/tv_url_display-->
<!--COMPLETED (14) Set the text size to 22sp-->
<!--COMPLETED (15) Set the width to wrap_content and the height to wrap_content-->
<!--COMPLETED (16) Give the TextView a top margin of 8dp-->
<!--COMPLETED (17) Set the text to tell the user their search URL will show up here when they click search-->
<TextView
android:id="@+id/tv_url_display"
android:layout_width="wrap_content"
Expand All @@ -39,11 +56,19 @@
android:text="Click search and your URL will show up here!"
android:textSize="22sp" />

<!--COMPLETED (18) Add a ScrollView-->
<!--COMPLETED (19) Set the width to match_parent and the height to wrap_content-->
<!--COMPLETED (20) Set the top margin to 16dp-->
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp">

<!--COMPLETED (21) Within the ScrollView, add a TextView-->
<!--COMPLETED (22) Give the TextView an id of @+id/tv_github_search_results_json-->
<!--COMPLETED (23) Set the text size to 18sp-->
<!--COMPLETED (24) Set the height and width to wrap_content-->
<!--COMPLETED (25) Set the text to something that tells the user to make a search-->
<TextView
android:id="@+id/tv_github_search_results_json"
android:layout_width="wrap_content"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,4 @@
-->
<resources>
<string name="app_name">Github Query</string>
<!--TODO (1) Add a string resource called search with the title "Search"-->
</resources>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#Wed Dec 07 11:59:24 PST 2016
#Mon Dec 12 10:00:07 PST 2016
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
Expand Down
41 changes: 41 additions & 0 deletions Lesson02-GitHub-Repo-Search/T02.02-Exercise-AddMenu/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
.DS_Store

# built application files
*.apk
*.ap_

# files for the dex VM
*.dex

# Java class files
*.class

# generated files
bin/
out/
gen/

# Libraries used by the app
# Can explicitly add if we want, but shouldn't do so blindly. Licenses, bloat, etc.
/libs


# Build stuff (auto-generated by android update project ...)
build.xml
ant.properties
local.properties
project.properties

# Eclipse project files
.classpath
.project

# idea project files
.idea/
*.iml
*.ipr
*.iws

# Gradle-based build
.gradle
build/
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 25
buildToolsVersion "25.0.1"

defaultConfig {
applicationId "com.example.android.datafrominternet"
minSdkVersion 10
targetSdkVersion 25
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
}
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:25.0.1'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android.datafrominternet">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name="com.example.android.datafrominternet.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>

<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Copyright (C) 2016 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.example.android.datafrominternet;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.EditText;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

private EditText mSearchBoxEditText;

private TextView mUrlDisplayTextView;
private TextView mSearchResultsTextView;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

mSearchBoxEditText = (EditText) findViewById(R.id.et_search_box);

mUrlDisplayTextView = (TextView) findViewById(R.id.tv_url_display);
mSearchResultsTextView = (TextView) findViewById(R.id.tv_github_search_results_json);
}

// Do 2 - 7 in menu.xml ///////////////////////////////////////////////////////////////////////
// TODO (2) Create a menu in xml called main.xml
// TODO (3) Add one menu item to your menu
// TODO (4) Give the menu item an id of @+id/action_search
// TODO (5) Set the orderInCategory to 1
// TODO (6) Show this item if there is room (use app:showAsAction, not android:showAsAction)
// TODO (7) Set the title to the search string ("Search") from strings.xml
// Do 2 - 7 in menu.xml ///////////////////////////////////////////////////////////////////////


// TODO (8) Override onCreateOptionsMenu
// TODO (9) Within onCreateOptionsMenu, use getMenuInflater().inflate to inflate the menu
// TODO (10) Return true to display your menu

// TODO (11) Override onOptionsItemSelected
// TODO (12) Within onOptionsItemSelected, get the ID of the item that was selected
// TODO (13) If the item's ID is R.id.action_search, show a Toast and return true to tell Android that you've handled this menu click
// TODO (14) Don't forgot to call .show() on your Toast
// TODO (15) If you do NOT handle the menu click, return super.onOptionsItemSelected to let Android handle the menu click
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* Copyright (C) 2016 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.example.android.datafrominternet.utilities;

import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Scanner;

/**
* These utilities will be used to communicate with the network.
*/
public class NetworkUtils {

final static String GITHUB_BASE_URL =
"https://api.github.com/search/repositories";

final static String PARAM_QUERY = "q";

/*
* The sort field. One of stars, forks, or updated.
* Default: results are sorted by best match if no field is specified.
*/
final static String PARAM_SORT = "sort";
final static String sortBy = "stars";

/**
* Builds the URL used to query Github.
*
* @param githubSearchQuery The keyword that will be queried for.
* @return The URL to use to query the weather server.
*/
public static URL buildUrl(String githubSearchQuery) {
return null;
}

/**
* This method returns the entire result from the HTTP response.
*
* @param url The URL to fetch the HTTP response from.
* @return The contents of the HTTP response.
* @throws IOException Related to network and stream reading
*/
public static String getResponseFromHttpUrl(URL url) throws IOException {
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
try {
InputStream in = urlConnection.getInputStream();

Scanner scanner = new Scanner(in);
scanner.useDelimiter("\\A");

boolean hasInput = scanner.hasNext();
if (hasInput) {
return scanner.next();
} else {
return null;
}
} finally {
urlConnection.disconnect();
}
}
}
Loading

0 comments on commit 95f7929

Please sign in to comment.