This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ext { | |
sourceCompatibilityVersion = JavaVersion.VERSION_1_8 | |
targetCompatibilityVersion = JavaVersion.VERSION_1_8 | |
versions = [ | |
annotations: [ | |
jsr305: '3.0.1' | |
], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.content.Context; | |
import android.content.res.TypedArray; | |
import android.graphics.Canvas; | |
import android.graphics.Rect; | |
import android.graphics.drawable.Drawable; | |
import android.support.v4.content.ContextCompat; | |
import android.text.Editable; | |
import android.text.TextWatcher; | |
import android.util.AttributeSet; | |
import android.view.MotionEvent; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<resources> | |
<declare-styleable name="ClearableEditText"> | |
<attr name="clearIcon" format="reference"/> | |
</declare-styleable> | |
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public final class YourLibraryInitProvider extends ContentProvider { | |
public YourLibraryInitProvider() { | |
} | |
@Override | |
public boolean onCreate() { | |
// get the context (Application context) | |
Context context = getContext(); | |
// initialize whatever you need |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<manifest package="some.library.packagename" | |
xmlns:android="http://schemas.android.com/apk/res/android"> | |
<application> | |
<provider | |
android:authorities="${applicationId}.yourlibraryinitprovider" | |
android:exported="false" | |
android:enabled="true" | |
android:name=".YourLibraryInitProvider" /> | |
</application> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public final class YourLibraryInitProvider extends ContentProvider { | |
... | |
@Override | |
public void attachInfo(Context context, ProviderInfo providerInfo) { | |
if (providerInfo == null) { | |
throw new NullPointerException("YourLibraryInitProvider ProviderInfo cannot be null."); | |
} | |
// So if the authorities equal the library internal ones, the developer forgot to set his applicationId |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class YourApplication extends Application { | |
@Override | |
public void onCreate() { | |
super.onCreate(); | |
SomeLibrary.init(this); | |
SomeOtherLibrary.init(this); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// use SparseArray on android! I just did this to make clear what happens here | |
Map<Integer, String> annotationRegistration = new HashMap<>(); | |
List<CallAdapter.Factory> factories = new ArrayList<>(); | |
// add all your CallAdapter.Factories here | |
factories.add(...) | |
// add default CallAdapter as the last item. This is mandatory! | |
factories.add(Retrofit2Platform.defaultCallAdapterFactory(null)); | |
CustomAnnotationCallAdapterFactory callAdapterFactory = | |
new CustomAnnotationCallAdapterFactory(factories, annotationRegistration); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package retrofit2; | |
import java.util.concurrent.Executor; | |
import retrofit2.CallAdapter.Factory; | |
public final class Retrofit2Platform { | |
private Retrofit2Platform() { | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CustomAnnotationInterceptor implements Interceptor { | |
private final Map<Integer, String> registration; | |
public CustomAnnotationInterceptor(Map<Integer, String> reg) { | |
this.registration = reg; | |
} | |
private Integer identify(Request request) { | |
// make sure this is the same method you use in the CallAdapter | |
return (request.url() + request.method()).hashCode(); |