Skip to content

Commit

Permalink
view binder
Browse files Browse the repository at this point in the history
  • Loading branch information
caodongping committed Aug 30, 2016
1 parent ec607d5 commit ae6dd04
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 51 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ dependencies {
compile 'net.steamcrafted:materialiconlib:1.0.9'
compile 'com.pnikosis:materialish-progress:1.7'
compile project(':snowball')
compile 'com.github.mzule.layoutannotation:library:1.0.3'
compile 'com.github.mzule.layoutannotation:library:1.0.4'
apt 'com.github.mzule.layoutannotation:compiler:1.0.3'
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,34 @@
import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.github.mzule.androidweekly.R;
import com.github.mzule.androidweekly.ui.view.base.BaseLinearLayout;
import com.github.mzule.layoutannotation.Layout;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
* Created by CaoDongping on 4/5/16.
*/
public class NaviBar extends LinearLayout {
@Layout(R.layout.view_navi_bar)
public class NaviBar extends BaseLinearLayout {

@Bind(R.id.leftTextView)
TextView leftTextView;
@Bind(R.id.rightTextView)
TextView rightTextView;

public NaviBar(Context context) {
super(context);
init(null);
}

public NaviBar(Context context, AttributeSet attrs) {
super(context, attrs);
init(attrs);
}

public NaviBar(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(attrs);
if (attrs != null) {
TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.NaviBar);
leftTextView.setText(a.getString(R.styleable.NaviBar_nb_left_text));
rightTextView.setText(a.getString(R.styleable.NaviBar_nb_right_text));
a.recycle();
}
}

@OnClick(R.id.backButton)
Expand All @@ -46,19 +41,6 @@ void back() {
}
}

private void init(AttributeSet attrs) {
setOrientation(VERTICAL);
LayoutInflater.from(getContext()).inflate(R.layout.view_navi_bar, this);
ButterKnife.bind(this);

if (attrs != null) {
TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.NaviBar);
leftTextView.setText(a.getString(R.styleable.NaviBar_nb_left_text));
rightTextView.setText(a.getString(R.styleable.NaviBar_nb_right_text));
a.recycle();
}
}

public void setLeftText(String text) {
leftTextView.setText(text);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,19 @@
import android.animation.ObjectAnimator;
import android.app.Activity;
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.AccelerateInterpolator;
import android.widget.FrameLayout;
import android.widget.RelativeLayout;

import com.github.mzule.androidweekly.R;
import com.github.mzule.androidweekly.ui.view.base.BaseRelativeLayout;


/**
* Created by CaoDongping on 11/30/15.
*/
public abstract class PopupView<T> extends RelativeLayout {
public abstract class PopupView<T> extends BaseRelativeLayout {
public static final int ANIMATION_DIRECTION_BOTTOM_TO_TOP = 0;
public static final int ANIMATION_DIRECTION_TOP_TO_BOTTOM = 1;
public static final int ANIMATION_DIRECTION_LEFT_TO_RIGHT = 2;
Expand All @@ -27,15 +26,7 @@ public abstract class PopupView<T> extends RelativeLayout {
private boolean inAnimation;

public PopupView(Context context) {
super(context);
}

public PopupView(Context context, AttributeSet attrs) {
super(context, attrs);
}

public PopupView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
super(context, null, 0);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;

Expand All @@ -16,14 +15,15 @@
import com.github.mzule.androidweekly.api.DictionaryApi;
import com.github.mzule.androidweekly.entity.Dict;
import com.github.mzule.androidweekly.util.Keyboard;
import com.github.mzule.layoutannotation.Layout;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
* Created by CaoDongping on 3/30/16.
*/
@Layout(R.layout.view_translate)
public class TranslateView extends PopupView<Void> {
@Bind(R.id.queryInput)
EditText queryInput;
Expand All @@ -34,7 +34,6 @@ public class TranslateView extends PopupView<Void> {

public TranslateView(Context context) {
super(context);
init();
}

@OnClick(R.id.maskView)
Expand Down Expand Up @@ -76,11 +75,6 @@ public void onFailure(Exception e) {
});
}

private void init() {
LayoutInflater.from(getContext()).inflate(R.layout.view_translate, this);
ButterKnife.bind(this);
}

@Override
protected void render(Void data) {
String paste = getPasteText();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.github.mzule.androidweekly.ui.view.base;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.LinearLayout;

import com.github.mzule.layoutannotation.LayoutBinder;

import butterknife.ButterKnife;

/**
* Created by CaoDongping on 8/30/16.
*/

public class BaseLinearLayout extends LinearLayout {

public BaseLinearLayout(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init();
}

private void init() {
LayoutBinder.bind(this);
ButterKnife.bind(this);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.github.mzule.androidweekly.ui.view.base;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.RelativeLayout;

import com.github.mzule.layoutannotation.LayoutBinder;

import butterknife.ButterKnife;

/**
* Created by CaoDongping on 8/30/16.
*/

public class BaseRelativeLayout extends RelativeLayout {

public BaseRelativeLayout(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init();
}

private void init() {
LayoutBinder.bind(this);
ButterKnife.bind(this);
}

}
4 changes: 2 additions & 2 deletions app/src/main/res/layout/view_navi_bar.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
Expand Down Expand Up @@ -48,4 +48,4 @@
</RelativeLayout>

<View style="@style/HorizontalLine" />
</merge>
</LinearLayout>

0 comments on commit ae6dd04

Please sign in to comment.