This page explains what you need to do to get Remixer running on your app. However, if you're the kind of person who learns by example, you may want to look at our example app.
You can read our javadoc for the current release (1.0) and the javadoc for HEAD generated by jitpack.
Using gradle it's super easy to start using Remixer following these instructions.
In your main build.gradle file make sure you have the following dependencies and repositories set up:
buildscript {
dependencies {
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
}
}
allprojects {
repositories {
jcenter()
maven { url "https://jitpack.io" }
}
}And in your modules, apply the android-apt plugin and add the remixer dependencies:
apply plugin: 'android-apt'
dependencies {
compile 'com.github.material-foundation.material-remixer-android:remixer:1.0'
provided 'com.github.material-foundation.material-remixer-android:remixer_annotation:1.0'
}Notice the dependency on remixer_annotation is a provided clause instead of compile, this is on purpose as this is not a regular dependency but a compiler plugin.
Important: Once you start depending on Remixer, your build will fail if no google-services.json exists on your app module. This is because Remixer has the option of using firebase to store and sync values, and whether you use it or not the build system looks for that file. It can be an empty file or the one we provide in remixer_example/src/main/google-services.json.
- Subclass the
android.app.Application. - Declare it in your Android Manifest.
- Call the
RemixerInitialization#initRemixer(Application)method. - Set a synchronization mechanism for Remixer (you have a few options):
com.google.android.libraries.remixer.sync.LocalValueSyncing, this is the default (you don't need to set it if this is what you want), it doesn't persist any values but makes sure values sync across different contexts (Activities).- Recommended:
com.google.android.libraries.remixer.storage.LocalStorage, this stores values locally in a SharedPreferences file. com.google.android.libraries.remixer.storage.FirebaseRemoteControllerSyncer, this syncs values to and from a firebase instance to use it as a remote controller. Take a look at the Firebase Remote Controller Set-up document for more information.
For example:
import android.app.Application;
import com.google.android.libraries.remixer.Remixer;
import com.google.android.libraries.remixer.storage.LocalStorage;
import com.google.android.libraries.remixer.ui.RemixerInitialization;
class MyApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
RemixerInitialization.initRemixer(this);
Remixer.getInstance().setSynchronizationMechanism(new LocalStorage(getApplicationContext()));
}
}You can define variables in an activity by writing methods that take one argument of the correct type and annotate them. The methods contain your logic to handle changes to these variables (update the UI accordingly).
You can rest assured those methods will run in the main UI thread.
There are a few very simple examples here, but you should look at the example activity and documentation for these annotations for more information.
For example:
@RangeVariableMethod(minValue = 15, maxValue = 70, initialValue = 20)
public void setFontSize(Float fontSize) {
titleText.setTextSize(TypedValue.COMPLEX_UNIT_SP, size);
}Additionally, you need to add RemixerBinder.bind(this) at the end of your activity's onCreate(Bundle).
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//...
RemixerBinder.bind(this);
}You can configure the RemixerFragment in the Activity's onCreate(Bundle) method, after the call to RemixerBinder.bind(this). You have 3 (not mutually-exclusive) options:
- Attach the RemixerFragment to a button click,
RemixerFragment#attachToButton(FragmentActivity, Button) - Attach the RemixerFragment to a FAB,
RemixerFragment#attachToFab(FragmentActivity, FloatingActionButton) - Attach the RemixerFragment to a multi-touch gesture,
RemixerFragment#attachToButton(FragmentActivity, Button) - Attach the RemixerFragment to a ShakeListener,
RemixerFragment#attachToShake(FragmentActivity, double). In order to conserve battery, you must callattachToShakefromonResumeand calldetachFromShakefromonPause
Detailed examples can be found on the Configure the UI page.
You may not want to use the RemixerFragment in case you only want to use a FirebaseRemoteController. Adding a RemixerFragment does affect the UI you may be playing with, so it may be desirable not to use it and adjust values remotely instead.