trikita.anvil.Anvil Java Examples

The following examples show how to use trikita.anvil.Anvil. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ExpandableListLayout.java    From anvil-examples with MIT License 6 votes vote down vote up
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);
    });
}
 
Example #2
Source File: App.java    From slide with MIT License 6 votes vote down vote up
@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);
    }
 
Example #3
Source File: AnimatedPickerView.java    From anvil-examples with MIT License 6 votes vote down vote up
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();
			}
		});
}
 
Example #4
Source File: App.java    From talalarmo with MIT License 6 votes vote down vote up
@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);
}
 
Example #5
Source File: MainLayout.java    From slide with MIT License 5 votes vote down vote up
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)));
        });
    });
}
 
Example #6
Source File: CurrencyView.java    From anvil-examples with MIT License 5 votes vote down vote up
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();
}
 
Example #7
Source File: LoginView.java    From anvil-examples with MIT License 5 votes vote down vote up
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();
}
 
Example #8
Source File: CountDownView.java    From anvil-examples with MIT License 5 votes vote down vote up
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)));
	}
}
 
Example #9
Source File: Style.java    From todo-jedux with MIT License 5 votes vote down vote up
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();
    });
}
 
Example #10
Source File: Style.java    From todo-jedux with MIT License 5 votes vote down vote up
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();
    });
}
 
Example #11
Source File: Style.java    From todo-jedux with MIT License 5 votes vote down vote up
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();
    });
}
 
Example #12
Source File: Style.java    From todo-jedux with MIT License 5 votes vote down vote up
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();
    });
}
 
Example #13
Source File: Style.java    From todo-jedux with MIT License 5 votes vote down vote up
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();
    });
}
 
Example #14
Source File: Slide.java    From slide with MIT License 5 votes vote down vote up
@Override
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
    cacheBitmap = bitmap;
    if (from != Picasso.LoadedFrom.MEMORY) {
        Anvil.render();
    }
}
 
Example #15
Source File: MainLayout.java    From slide with MIT License 5 votes vote down vote up
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();
            });
        });
    });
}
 
Example #16
Source File: GifListActivity.java    From redux-android-sample with Apache License 2.0 5 votes vote down vote up
private void bindingViews() {
    //Bindings Defaults
    Anvil.mount(findViewById(R.id.activity_gif_list), () -> {
        withId(R.id.loading, () -> visibility(mGifProgressVisibility));

        if (mAnvilRenderListener != null) mAnvilRenderListener.onAnvilRendered();
    });
}
 
Example #17
Source File: FeedView.java    From redux-android-sample with Apache License 2.0 5 votes vote down vote up
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();
                    }
                }
            });
}
 
Example #18
Source File: MainActivity.java    From talalarmo with MIT License 5 votes vote down vote up
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");
}
 
Example #19
Source File: AlarmLayout.java    From talalarmo with MIT License 5 votes vote down vote up
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);
        });
    });
}
 
Example #20
Source File: Style.java    From todo-jedux with MIT License 5 votes vote down vote up
public static void windowBackground(Anvil.Renderable r) {
    linearLayout(() -> {
        size(FILL, FILL);
        orientation(LinearLayout.VERTICAL);
        backgroundResource(Base.background);
        r.view();
    });
}
 
Example #21
Source File: AppCompatv7DSL.java    From anvil with MIT License 4 votes vote down vote up
public static Void linearLayoutCompat(Anvil.Renderable r) {
  return BaseDSL.v(LinearLayoutCompat.class, r);
}
 
Example #22
Source File: SupportCoreUiDSL.java    From anvil with MIT License 4 votes vote down vote up
public static Void drawerLayout(Anvil.Renderable r) {
  return BaseDSL.v(DrawerLayout.class, r);
}
 
Example #23
Source File: SupportCoreUiDSL.java    From anvil with MIT License 4 votes vote down vote up
public static Void nestedScrollView(Anvil.Renderable r) {
  return BaseDSL.v(NestedScrollView.class, r);
}
 
Example #24
Source File: SupportCoreUiDSL.java    From anvil with MIT License 4 votes vote down vote up
public static Void pagerTitleStrip(Anvil.Renderable r) {
  return BaseDSL.v(PagerTitleStrip.class, r);
}
 
Example #25
Source File: SupportCoreUiDSL.java    From anvil with MIT License 4 votes vote down vote up
public static Void slidingPaneLayout(Anvil.Renderable r) {
  return BaseDSL.v(SlidingPaneLayout.class, r);
}
 
Example #26
Source File: AppCompatv7DSL.java    From anvil with MIT License 4 votes vote down vote up
public static Void switchCompat(Anvil.Renderable r) {
  return BaseDSL.v(SwitchCompat.class, r);
}
 
Example #27
Source File: DesignDSL.java    From anvil with MIT License 4 votes vote down vote up
public static Void tabLayout(Anvil.Renderable r) {
  return BaseDSL.v(TabLayout.class, r);
}
 
Example #28
Source File: AppCompatv7DSL.java    From anvil with MIT License 4 votes vote down vote up
public static Void scrollingTabContainerView(Anvil.Renderable r) {
  return BaseDSL.v(ScrollingTabContainerView.class, r);
}
 
Example #29
Source File: AppCompatv7DSL.java    From anvil with MIT License 4 votes vote down vote up
public static Void searchView(Anvil.Renderable r) {
  return BaseDSL.v(SearchView.class, r);
}
 
Example #30
Source File: AppCompatv7DSL.java    From anvil with MIT License 4 votes vote down vote up
public static Void viewStubCompat(Anvil.Renderable r) {
  return BaseDSL.v(ViewStubCompat.class, r);
}