Java源码示例:trikita.anvil.Anvil
示例1
@Override
public void onCreate() {
super.onCreate();
App.instance = this;
this.windowController = new WindowController();
PersistanceController persistanceController = new PersistanceController(this);
State initialState = persistanceController.getSavedState();
if (initialState == null) {
initialState = State.Default.build(this);
}
StorageController sc = new StorageController(this);
this.store = new Store<>(new State.Reducer(),
initialState,
// new Logger<>("Slide"),
persistanceController,
this.windowController,
sc);
sc.dumpToFile(false); // false - with no delay
this.store.subscribe(Anvil::render);
}
示例2
@Override
public void onCreate() {
super.onCreate();
App.instance = this;
PersistanceController persistanceController = new PersistanceController(this);
State initialState = persistanceController.getSavedState();
if (initialState == null) {
initialState = State.Default.build();
}
this.store = new Store<>(new State.Reducer(),
initialState,
new Logger<>("Talalarmo"),
persistanceController,
new AlarmController(this));
this.store.subscribe(Anvil::render);
}
示例3
private void slide(int from, int to, float fromAlpha, float toAlpha) {
if (mRunningAnims == ANIMS_PER_NAVIGATION) {
return;
}
mRunningAnims++;
// Set initial values before animation and start animation
Anvil.currentView().setX(from);
Anvil.currentView().setAlpha(fromAlpha);
Anvil.currentView().animate()
.x(to)
.alpha(toAlpha)
.setDuration(ANIM_DURATION)
.withEndAction(() -> {
// When animation is finished - decrease the number of pending
// animations and if counted down to zero - pop current transition from
// the stack
mRunningAnims--;
if (mRunningAnims == 0) {
mIndex += (mNavQueue.poll() == Navigation.PREV ? -1 : +1);
Anvil.render();
}
});
}
示例4
private void list() {
expandableListView(() -> {
size(0, FILL);
weight(1);
adapter(mAdapter);
for (int i = 0; i < GROUP.length; i++) {
if (expanded[i]) {
((ExpandableListView) Anvil.currentView()).expandGroup(i);
} else {
((ExpandableListView) Anvil.currentView()).collapseGroup(i);
}
}
onGroupCollapse(this::onColapsed);
onGroupExpand(this::onExpanded);
});
}
示例5
private void editor() {
relativeLayout(() -> {
Style.Editor.background();
v(Editor.class, () -> {
size(FILL, FILL);
gravity(TOP | START);
text(App.getState().text());
Style.Editor.textStyle();
backgroundDrawable(null);
init(() -> {
mEditor = Anvil.currentView();
mEditor.setOnSelectionChangedListener(pos -> {
App.dispatch(new Action<>(ActionType.SET_CURSOR, pos));
});
});
onTextChanged(chars -> {
String s = chars.toString();
App.dispatch(new Action<>(ActionType.SET_TEXT, s));
App.dispatch(new Action<>(ActionType.SET_CURSOR, mEditor.getSelectionStart()));
});
});
textView(() -> {
Style.Editor.menuButton();
onClick(this::onOpenMenu);
});
frameLayout(() -> {
Style.Editor.previewContainer();
v(Preview.class, () -> {
Style.Editor.previewSize();
onClick(v -> App.dispatch(new Action<>(ActionType.OPEN_PRESENTATION)));
Anvil.currentView().invalidate();
});
});
});
}
示例6
private void presentation() {
relativeLayout(() -> {
size(FILL, FILL);
Style.Preview.background(App.getState().colorScheme());
v(Preview.class, () -> {
size(FILL, WRAP);
centerInParent();
Anvil.currentView().invalidate();
});
linearLayout(() -> {
size(FILL, FILL);
Style.Preview.touchPlaceholder(v -> App.dispatch(new Action<>(ActionType.PREV_PAGE)));
Style.Preview.touchPlaceholder(v -> App.dispatch(new Action<>(ActionType.TOGGLE_TOOLBAR)));
Style.Preview.touchPlaceholder(v -> App.dispatch(new Action<>(ActionType.NEXT_PAGE)));
});
button(() -> {
Style.Preview.button(App.getState().colorScheme());
margin(0, 0, 0, dip(25));
alignParentBottom();
centerHorizontal();
visibility(App.getState().toolbarShown());
onClick(v -> App.dispatch(new Action<>(ActionType.CLOSE_PRESENTATION)));
});
});
}
示例7
@Override
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
cacheBitmap = bitmap;
if (from != Picasso.LoadedFrom.MEMORY) {
Anvil.render();
}
}
示例8
private void bindingViews() {
//Bindings Defaults
Anvil.mount(findViewById(R.id.activity_gif_list), () -> {
withId(R.id.loading, () -> visibility(mGifProgressVisibility));
if (mAnvilRenderListener != null) mAnvilRenderListener.onAnvilRendered();
});
}
示例9
private void setupEndlessScrolling() {
//TODO: PR on Anvil Recycler to exposes addOnScrollListener
((RecyclerView) Anvil.currentView())
.addOnScrollListener(new EndlessRecyclerScrollListener(mLayoutManager) {
@Override
public void onLoadMore(int page, int totalItemsCount, RecyclerView view) {
if (mHasMoreGifs) {
GifListActionCreator.getInstance().fetchGifs();
}
}
});
}
示例10
public void onResume() {
super.onResume();
updateTheme();
Anvil.render();
Promote.after(7).days().every(7).days().rate(this);
Promote.after(3).days().every(14).days().share(this,
Promote.FACEBOOK_TWITTER,
"https://github.com/trikita/talalarmo",
"Talalarmo: elegant open-source alarm clock");
}
示例11
private static void bottomBar() {
linearLayout(() -> {
size(FILL, dip(62));
backgroundColor(Theme.get(App.getState().settings().theme()).backgroundTranslucentColor);
Theme.materialIcon(() -> {
text("\ue857"); // ALARM OFF
textSize(dip(32));
textColor(Theme.get(App.getState().settings().theme()).secondaryTextColor);
padding(dip(15));
visibility(App.getState().alarm().on());
onClick(v -> App.dispatch(new Action<>(Actions.Alarm.OFF)));
});
textView(() -> {
size(0, FILL);
weight(1f);
margin(dip(10), 0);
typeface("fonts/Roboto-Light.ttf");
textSize(dip(16));
textColor(Theme.get(App.getState().settings().theme()).primaryTextColor);
gravity(CENTER | CENTER_VERTICAL);
text(formatAlarmTime(Anvil.currentView().getContext()));
});
Theme.materialIcon(() -> {
text("\ue5d4"); // "more vert"
textSize(dip(32));
textColor(Theme.get(App.getState().settings().theme()).secondaryTextColor);
padding(dip(15));
onClick(AlarmLayout::showSettingsMenu);
});
});
}
示例12
public static void deleteButton(Anvil.Renderable r) {
textView(() -> {
size(dip(36), dip(36));
gravity(Gravity.CENTER);
margin(Base.margin);
text(R.string.clear_icon);
iconNormal();
r.view();
});
}
示例13
public static void windowBackground(Anvil.Renderable r) {
linearLayout(() -> {
size(FILL, FILL);
orientation(LinearLayout.VERTICAL);
backgroundResource(Base.background);
r.view();
});
}
示例14
public static void bottomBar(Anvil.Renderable r) {
button(() -> {
size(FILL, dip(64));
layoutGravity(Gravity.BOTTOM);
text(R.string.delete_icon);
textSize(Base.textSize * 1.5f);
textColor(Base.iconInverseColor);
typeface(Base.iconFont);
backgroundResource(R.drawable.bottom_bar_background);
r.view();
});
}
示例15
public static void layout(Anvil.Renderable r) {
linearLayout(() -> {
size(FILL, dip(54));
margin(Base.margin * 3);
gravity(Gravity.CENTER_VERTICAL);
backgroundResource(R.drawable.input_background);
r.view();
});
}
示例16
public static void text(Anvil.Renderable r) {
editText(() -> {
size(0, WRAP);
weight(1);
padding(Base.padding);
hint(R.string.todo_input_hint);
imeOptions(EditorInfo.IME_ACTION_DONE);
singleLine(true);
textNormal();
r.view();
});
}
示例17
public static void checkbox(Anvil.Renderable r) {
checkBox(() -> {
size(0, WRAP);
weight(1);
margin(Base.margin * 2, Base.margin * 5);
padding(Base.padding, 0, 0, 0);
textInverse();
r.view();
});
}
示例18
public void onLoginFinished(boolean success) {
mIsLoggingIn = false;
mLoginFailed = !success;
if (success) {
// Logged in successfully, show toast at least
Toast
.makeText(getContext(), R.string.login_successful, Toast.LENGTH_SHORT)
.show();
}
// This callback happens in the background, so call Anvil.render explicitly
Anvil.render();
}
示例19
public CountDownView(Context c) {
super(c);
mUnsubscriber = App.store().subscribe(() -> {
Anvil.render();
});
if (App.state().currentTask() == null) {
App.dispatch(new CountdoneAction(CountdoneAction.Type.NEW_TASK, new Pair("New task", 25*60*1000L)));
}
}
示例20
private void update(Mutable<Float> value) {
// If "dummy" value is the first sum,
// then set second sum's value,
// and set second sum as "reactive" value
if (value == mFirstSum) {
mSecondSum.set(mCurrencyManager.
exchange(mFirstIndex.get(), mSecondIndex.get(), value.get()));
// Vice versa
} else {
mFirstSum.set(mCurrencyManager.
exchange(mSecondIndex.get(), mFirstIndex.get(), value.get()));
}
// Re-render now
Anvil.render();
}
示例21
@Override
protected void notifyStateListeners(AppState newState, AppState oldState) {
super.notifyStateListeners(newState, oldState);
Anvil.render();
}
示例22
private void renderGifView(Gif gif) {
v(GifView.class, () -> ((GifView) Anvil.currentView())
.withGifDrawable(createDrawable(gif))
.withGif(gif));
onAnvilRendered();
}
示例23
public static Void textInputLayout(Anvil.Renderable r) {
return BaseDSL.v(TextInputLayout.class, r);
}
示例24
public static Void recyclerView(Anvil.Renderable r) {
return BaseDSL.v(RecyclerView.class, r);
}
示例25
public static Void textInputEditText(Anvil.Renderable r) {
return BaseDSL.v(TextInputEditText.class, r);
}
示例26
public static Void cardView(Anvil.Renderable r) {
return BaseDSL.v(CardView.class, r);
}
示例27
public static Void actionMenuItemView(Anvil.Renderable r) {
return BaseDSL.v(ActionMenuItemView.class, r);
}
示例28
public static Void expandedMenuView(Anvil.Renderable r) {
return BaseDSL.v(ExpandedMenuView.class, r);
}
示例29
public static Void listMenuItemView(Anvil.Renderable r) {
return BaseDSL.v(ListMenuItemView.class, r);
}
示例30
public static Void actionBarContainer(Anvil.Renderable r) {
return BaseDSL.v(ActionBarContainer.class, r);
}