Skip to content

Commit 7b1ee92

Browse files
committed
Initial commit
0 parents  commit 7b1ee92

File tree

58 files changed

+1113
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+1113
-0
lines changed

.gitignore

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
*.iml
2+
.gradle
3+
/local.properties
4+
/.idea/libraries
5+
/.idea/modules.xml
6+
/.idea/workspace.xml
7+
.DS_Store
8+
/build
9+
/captures
10+
.externalNativeBuild

.idea/caches/build_file_checksums.ser

536 Bytes
Binary file not shown.

.idea/codeStyles/Project.xml

+29
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/gradle.xml

+18
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

+34
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/runConfigurations.xml

+12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

app/build.gradle

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
apply plugin: 'com.android.application'
2+
3+
android {
4+
compileSdkVersion 27
5+
defaultConfig {
6+
applicationId "com.perceptualstudios.androidyoutubelist1"
7+
minSdkVersion 19
8+
targetSdkVersion 27
9+
versionCode 1
10+
versionName "1.0"
11+
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
12+
}
13+
buildTypes {
14+
release {
15+
minifyEnabled false
16+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17+
}
18+
}
19+
}
20+
21+
dependencies {
22+
implementation fileTree(include: ['*.jar'], dir: 'libs')
23+
implementation 'com.android.support:appcompat-v7:27.1.1'
24+
implementation 'com.android.support.constraint:constraint-layout:1.1.1'
25+
testImplementation 'junit:junit:4.12'
26+
androidTestImplementation 'com.android.support.test:runner:1.0.2'
27+
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
28+
implementation files('libs/google-api-client-1.23.0.jar')
29+
implementation files('libs/google-api-client-android-1.23.0.jar')
30+
implementation files('libs/google-api-client-jackson2-1.23.0.jar')
31+
implementation files('libs/google-api-services-youtube-v3-rev202-1.18.0-rc.jar')
32+
implementation files('libs/google-http-client-1.23.0.jar')
33+
implementation files('libs/google-http-client-android-1.23.0.jar')
34+
implementation files('libs/google-http-client-jackson2-1.23.0.jar')
35+
implementation files('libs/google-oauth-client-1.23.0.jar')
36+
implementation files('libs/gson-2.1.jar')
37+
implementation files('libs/jackson-core-2.1.3.jar')
38+
implementation files('libs/jackson-core-asl-1.9.11.jar')
39+
implementation files('libs/jsr305-1.3.9.jar')
40+
implementation files('libs/picasso-2.5.2.jar')
41+
implementation files('libs/protobuf-java-2.6.1.jar')
42+
implementation files('libs/YouTubeAndroidPlayerApi.jar')
43+
//design
44+
implementation 'com.android.support:design:27.1.1'
45+
}

app/libs/YouTubeAndroidPlayerApi.jar

104 KB
Binary file not shown.

app/libs/google-api-client-1.23.0.jar

195 KB
Binary file not shown.
10.2 KB
Binary file not shown.
2.64 KB
Binary file not shown.
Binary file not shown.
349 KB
Binary file not shown.
11.7 KB
Binary file not shown.
6.52 KB
Binary file not shown.
60.3 KB
Binary file not shown.

app/libs/gson-2.1.jar

176 KB
Binary file not shown.

app/libs/jackson-core-2.1.3.jar

202 KB
Binary file not shown.

app/libs/jackson-core-asl-1.9.11.jar

227 KB
Binary file not shown.

app/libs/jsr305-1.3.9.jar

32.2 KB
Binary file not shown.

app/libs/picasso-2.5.2.jar

118 KB
Binary file not shown.

app/libs/protobuf-java-2.6.1.jar

583 KB
Binary file not shown.

app/proguard-rules.pro

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Add project specific ProGuard rules here.
2+
# You can control the set of applied configuration files using the
3+
# proguardFiles setting in build.gradle.
4+
#
5+
# For more details, see
6+
# http://developer.android.com/guide/developing/tools/proguard.html
7+
8+
# If your project uses WebView with JS, uncomment the following
9+
# and specify the fully qualified class name to the JavaScript interface
10+
# class:
11+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12+
# public *;
13+
#}
14+
15+
# Uncomment this to preserve the line number information for
16+
# debugging stack traces.
17+
#-keepattributes SourceFile,LineNumberTable
18+
19+
# If you keep the line number information, uncomment this to
20+
# hide the original source file name.
21+
#-renamesourcefileattribute SourceFile
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.perceptualstudios.androidyoutubelist1;
2+
3+
import android.content.Context;
4+
import android.support.test.InstrumentationRegistry;
5+
import android.support.test.runner.AndroidJUnit4;
6+
7+
import org.junit.Test;
8+
import org.junit.runner.RunWith;
9+
10+
import static org.junit.Assert.*;
11+
12+
/**
13+
* Instrumented test, which will execute on an Android device.
14+
*
15+
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
16+
*/
17+
@RunWith(AndroidJUnit4.class)
18+
public class ExampleInstrumentedTest {
19+
@Test
20+
public void useAppContext() {
21+
// Context of the app under test.
22+
Context appContext = InstrumentationRegistry.getTargetContext();
23+
24+
assertEquals("com.perceptualstudios.androidyoutubelist1", appContext.getPackageName());
25+
}
26+
}

app/src/main/AndroidManifest.xml

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="com.perceptualstudios.androidyoutubelist1">
4+
5+
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
6+
7+
<application
8+
android:allowBackup="true"
9+
android:icon="@mipmap/ic_launcher"
10+
android:label="@string/app_name"
11+
android:roundIcon="@mipmap/ic_launcher_round"
12+
android:supportsRtl="true"
13+
android:theme="@style/AppTheme">
14+
<activity android:name=".SearchActivity">
15+
<intent-filter>
16+
<action android:name="android.intent.action.MAIN" />
17+
18+
<category android:name="android.intent.category.LAUNCHER" />
19+
</intent-filter>
20+
</activity>
21+
<activity android:name=".PlayerActivity"></activity>
22+
</application>
23+
24+
</manifest>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.perceptualstudios.androidyoutubelist1;
2+
3+
import android.os.Bundle;
4+
import android.widget.Toast;
5+
6+
import com.google.android.youtube.player.YouTubeBaseActivity;
7+
import com.google.android.youtube.player.YouTubeInitializationResult;
8+
import com.google.android.youtube.player.YouTubePlayer;
9+
import com.google.android.youtube.player.YouTubePlayerView;
10+
11+
public class PlayerActivity extends YouTubeBaseActivity implements YouTubePlayer.OnInitializedListener {
12+
13+
private YouTubePlayerView playerView;
14+
15+
@Override
16+
protected void onCreate(Bundle savedInstanceState) {
17+
super.onCreate(savedInstanceState);
18+
setContentView(R.layout.activity_player);
19+
20+
playerView = (YouTubePlayerView) findViewById(R.id.player_view);
21+
playerView.initialize(YoutubeConnector.KEY,this);
22+
23+
}
24+
25+
@Override
26+
public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer youTubePlayer, boolean b) {
27+
if(!b){
28+
youTubePlayer.cueVideo(getIntent().getStringExtra("VIDEO_ID"));
29+
}
30+
}
31+
32+
@Override
33+
public void onInitializationFailure(YouTubePlayer.Provider provider, YouTubeInitializationResult youTubeInitializationResult) {
34+
Toast.makeText(this, "initialization failed",Toast.LENGTH_SHORT).show();
35+
}
36+
}//class
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
package com.perceptualstudios.androidyoutubelist1;
2+
3+
import android.content.Intent;
4+
import android.os.Handler;
5+
import android.support.v7.app.AppCompatActivity;
6+
import android.os.Bundle;
7+
import android.view.KeyEvent;
8+
import android.view.View;
9+
import android.view.ViewGroup;
10+
import android.view.inputmethod.EditorInfo;
11+
import android.widget.AdapterView;
12+
import android.widget.ArrayAdapter;
13+
import android.widget.EditText;
14+
import android.widget.ImageView;
15+
import android.widget.ListView;
16+
import android.widget.TextView;
17+
18+
import com.squareup.picasso.Picasso;
19+
20+
import java.util.List;
21+
22+
public class SearchActivity extends AppCompatActivity {
23+
24+
//member variables
25+
private EditText searchInput;
26+
private ListView videosFound;
27+
private Handler handler;
28+
private List<VideoItem> searchResults;
29+
30+
@Override
31+
protected void onCreate(Bundle savedInstanceState) {
32+
super.onCreate(savedInstanceState);
33+
setContentView(R.layout.activity_search);
34+
35+
searchInput = (EditText) findViewById(R.id.search_input);
36+
videosFound = (ListView) findViewById(R.id.list_view);
37+
handler = new Handler();
38+
39+
//listen for user input
40+
searchInput.setOnEditorActionListener(new TextView.OnEditorActionListener() {
41+
@Override
42+
public boolean onEditorAction(TextView textView, int actionId, KeyEvent event) {
43+
if (actionId == EditorInfo.IME_ACTION_DONE) {
44+
searchOnYoutube(textView.getText().toString());
45+
return false;
46+
}
47+
return true;
48+
}
49+
});
50+
addClickListener();
51+
}
52+
53+
//perform search on background thread
54+
private void searchOnYoutube(final String keywords){
55+
new Thread(){
56+
public void run(){
57+
YoutubeConnector yc = new YoutubeConnector(SearchActivity.this);
58+
searchResults = yc.search(keywords);
59+
handler.post(new Runnable(){
60+
public void run(){
61+
updateVideosFound();
62+
}
63+
});
64+
}
65+
}.start();
66+
}
67+
68+
private void updateVideosFound(){
69+
ArrayAdapter<VideoItem> adapter = new ArrayAdapter<VideoItem>(getApplicationContext(), R.layout.video_item, searchResults){
70+
@Override
71+
public View getView(int position, View convertView, ViewGroup parent) {
72+
if(convertView == null){
73+
convertView = getLayoutInflater().inflate(R.layout.video_item, parent, false);
74+
}
75+
ImageView thumbnail = (ImageView)convertView.findViewById(R.id.video_thumbnail);
76+
TextView title = (TextView)convertView.findViewById(R.id.video_title);
77+
TextView description = (TextView)convertView.findViewById(R.id.video_description);
78+
79+
VideoItem searchResult = searchResults.get(position); //
80+
81+
Picasso.with(getApplicationContext()).load(searchResult.getThumbnailURL()).into(thumbnail);
82+
title.setText(searchResult.getTitle());
83+
description.setText(searchResult.getDescription());
84+
return convertView;
85+
}
86+
};
87+
88+
videosFound.setAdapter(adapter);
89+
}
90+
private void addClickListener(){
91+
videosFound.setOnItemClickListener(new AdapterView.OnItemClickListener() {
92+
@Override
93+
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
94+
Intent intent = new Intent(getApplication(), PlayerActivity.class);
95+
intent.putExtra("VIDEO_ID", searchResults.get(position).getId());
96+
startActivity(intent);
97+
}
98+
});
99+
}
100+
101+
}//class
102+
103+
104+
105+
106+
107+
108+
109+
110+
111+
112+
113+
114+
115+
116+
117+
118+
119+
120+
121+
122+
123+
124+
125+

0 commit comments

Comments
 (0)