Skip to content

Instantly share code, notes, and snippets.

View jacquesgiraudel's full-sized avatar

Jacques Giraudel jacquesgiraudel

View GitHub Profile
EventBus.getDefault().post(new MessageEvent("Hello !"));
// Reading of events of type MessageEvent (free method name)
@Subscribe
public void onMessageEvent(MessageEvent event){
Toast.makeText(getActivity(), event.message, Toast.LENGTH_SHORT).show();
}
@jacquesgiraudel
jacquesgiraudel / fragmentlistener-snippet.java
Created March 16, 2016 06:26
fragmentlistener-snippet
// Class consuming the interaction
public class ExempleActivity extends Activity implements ExempleFragment.OnFragmentInteractionListener {
...
@Override
public void onFragmentInteraction(Uri uri) {
// Consumption of the interaction
}
}
public class ExampleActivity extends AppCompatActivity {
...
// Declaration of the broadcast receiver
private BroadcastReceiver mMessageReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
// Retrieving of the parcelable object
ComplexObject complexObject =
intent.getParcelableExtra("MyComplexObject");
textView.setText(complexObject.getMessage());
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
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 ! ");
@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.
<?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" />
<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"?>
<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>