Skip to content

Instantly share code, notes, and snippets.

View jacquesgiraudel's full-sized avatar

Jacques Giraudel jacquesgiraudel

View GitHub Profile
var findByTitle: (String) -> (MutableList<Movie>) -> List<Movie> =
{ query -> { collection ->
val predicate = matches(query)
filter(predicate)(collection)
}}
val filter: ((Movie) -> Boolean) -> (List<Movie>) -> List<Movie> =
{ predicate -> { collection ->
collection.filter(predicate)
}}
val findByTitle = {query: String -> {collection: MutableList<Movie> ->
val predicate = matches(query)
filter(predicate)(collection)
}}
val filter = {predicate: (Movie) -> Boolean -> {collection: List<Movie> ->
collection.filter(predicate)
}}
val matches = {query: String -> { movie: Movie ->
fun findByTitle(query: String, collection: MutableList<Movie>): List<Movie>{
var results: MutableList<Movie> = mutableListOf()
do {
val movie = collection.removeAt(0)
if (movie.title.contains(query)){
results.add(movie)
}
}
public class SplashScreenActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
((AnimationDrawable) getWindow().getDecorView().getBackground()).start();
// Launch main activity
...
}
}
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="fr.jgl.animatedsplashscreen">
...
<activity android:name=".SplashScreenActivity" android:theme="@style/SplashTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<resources>
...
<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowBackground">@drawable/splash_animation</item>
</style>
...
</resources>
<?xml version="1.0" encoding="utf-8"?>
<animation-list
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/splash_animation" android:oneshot="false">
<item android:drawable="@drawable/blue_circle" android:duration="330" />
<item android:drawable="@drawable/red_circle" android:duration="330" />
<item android:drawable="@drawable/yellow_circle" android:duration="330" />
<item android:drawable="@drawable/blue_circle" android:duration="330" />
<item android:drawable="@drawable/green_circle" android:duration="330" />
<item android:drawable="@drawable/red_circle" android:duration="330" />
@jacquesgiraudel
jacquesgiraudel / NetworkPhotoView.java
Created August 8, 2016 18:33
Zoomable and scrollable NetworkImageView for Volley
/**
* 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.
public class ObserverActivity extends Activity implements Observer{
...
@Override
protected void onCreate(Bundle savedInstanceState) {
...
MyObservable myObservable = new MyObservable();
// Registering of the observer (here the activity)
myObservable.addObserver(this);
// Changing the state of the observable
myObservable.setValue("Hello ! ");
public class ReceiveFromServiceActivity extends AppCompatActivity {
// Message handler of the service
class ResponseHandler extends Handler {
@Override public void handleMessage(Message message) {
Toast.makeText(ReceiveFromServiceActivity.this, "message from service : " + message.getData().getString("message"),
Toast.LENGTH_SHORT).show();
}
}
// Messenger toward the activity