Skip to content

Instantly share code, notes, and snippets.

View PierfrancescoSoffritti's full-sized avatar

Pierfrancesco Soffritti PierfrancescoSoffritti

View GitHub Profile
@PierfrancescoSoffritti
PierfrancescoSoffritti / MainActivity.kt
Last active February 14, 2019 07:33
How to build sample apps for Android libraries with just a few lines of code.
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val intent = Intent(this, SampleAppTemplateActivity::class.java)
intent.putExtra(Constants.TITLE.name, getString(R.string.title))
intent.putExtra(Constants.GITHUB_URL.name, "https://github.com/username/repo")
intent.putExtra(Constants.HOMEPAGE_URL.name(), "https://github.com/username/repo/README.md");
intent.putExtra(Constants.PLAYSTORE_PACKAGE_NAME.name(), "com.name.appname");
@PierfrancescoSoffritti
PierfrancescoSoffritti / theme.xml
Created February 14, 2019 07:10
How to build sample apps for Android libraries with just a few lines of code.
<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
@PierfrancescoSoffritti
PierfrancescoSoffritti / manifest.xml
Last active February 14, 2019 07:11
How to build sample apps for Android libraries with just a few lines of code
<application
android:theme="@style/AppTheme">
<activity android:name="com.psoffritti.librarysampleapptemplate.core.SampleAppTemplateActivity" />
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
@PierfrancescoSoffritti
PierfrancescoSoffritti / build.gradle
Created February 14, 2019 07:04
How to build sample apps for Android libraries with just a few lines of code
dependencies {
implementation "com.psoffritti.librarysampleapptemplate:core:$latest_version"
}
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<com.pierfrancescosoffritti.androidyoutubeplayer.core.player.views.YouTubePlayerView
android:id="@+id/youtube_player_view"
android:layout_width="match_parent"
YouTubePlayerView youTubePlayerView = findViewById(R.id.youtube_player_view);
getLifecycle().addObserver(youTubePlayerView);
youTubePlayerView.addYouTubePlayerListener(new AbstractYouTubePlayerListener() {
@Override
public void onReady(@NonNull YouTubePlayer youTubePlayer) {
String videoId = "S0Q4gqBUs7c";
youTubePlayer.loadVideo(videoId, 0f);
}
});
@PierfrancescoSoffritti
PierfrancescoSoffritti / Activity.java
Created February 11, 2019 19:03
android-youtube-player, an open source alternative to the official YouTube Player API: https://medium.com/@soffritti.pierfrancesco/how-to-play-youtube-videos-in-your-android-app-c40427215230
YouTubePlayerView youTubePlayerView = findViewById(R.id.youtube_player_view);
getLifecycle().addObserver(youTubePlayerView);
@PierfrancescoSoffritti
PierfrancescoSoffritti / layout.xml
Created February 11, 2019 19:02
android-youtube-player, an open source alternative to the official YouTube Player API: https://medium.com/@soffritti.pierfrancesco/how-to-play-youtube-videos-in-your-android-app-c40427215230
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<com.pierfrancescosoffritti.androidyoutubeplayer.core.player.views.YouTubePlayerView
android:id="@+id/youtube_player_view"
android:layout_width="match_parent"
@PierfrancescoSoffritti
PierfrancescoSoffritti / build.gradle
Created February 11, 2019 19:01
android-youtube-player, an open source alternative to the official YouTube Player API: https://medium.com/@soffritti.pierfrancesco/how-to-play-youtube-videos-in-your-android-app-c40427215230
dependencies {
implementation 'com.pierfrancescosoffritti.androidyoutubeplayer:core:last_version'
}
class CustomUiController {
private boolean isPlaying = false;
CustomUiController(View customPlayerUI, YouTubePlayer youTubePlayer) {
playPauseButton = customPlayerUI.findViewById(R.id.play_pause_button);
playPauseButton.setOnClickListener( view -> {
if(isPlaying) youTubePlayer.pause();
else youTubePlayer.play();