Skip to content

Instantly share code, notes, and snippets.

@PierfrancescoSoffritti
PierfrancescoSoffritti / eventBus.js
Last active February 15, 2024 14:16
A simple implementation of an event bus in Javascript. More details here: https://medium.com/@soffritti.pierfrancesco/create-a-simple-event-bus-in-javascript-8aa0370b3969
/**
* subscriptions data format:
* { eventType: { id: callback } }
*/
const subscriptions = { }
const getNextUniqueId = getIdGenerator()
function subscribe(eventType, callback) {
const id = getNextUniqueId()
@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 / 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 / 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 / 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'
}