implement Butterknife

This commit is contained in:
tibbi 2016-01-28 00:07:44 +01:00
parent 60aa0ef517
commit c0fe02026a
3 changed files with 27 additions and 9 deletions

View File

@ -24,4 +24,5 @@ dependencies {
testCompile 'junit:junit:4.12' testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1' compile 'com.android.support:appcompat-v7:23.1.1'
compile 'joda-time:joda-time:2.9.1' compile 'joda-time:joda-time:2.9.1'
compile 'com.jakewharton:butterknife:7.0.1'
} }

View File

@ -13,26 +13,29 @@ import org.joda.time.DateTime;
import java.text.DateFormatSymbols; import java.text.DateFormatSymbols;
import butterknife.Bind;
import butterknife.BindColor;
import butterknife.ButterKnife;
import butterknife.OnClick;
public class MainActivity extends AppCompatActivity { public class MainActivity extends AppCompatActivity {
@Bind(R.id.left_arrow) ImageView leftArrow;
@Bind(R.id.right_arrow) ImageView rightArrow;
@Bind(R.id.table_month) TextView monthTV;
@Bind(R.id.table_holder) TableLayout tableHolder;
@BindColor(R.color.darkGrey) int grey;
private DateTime targetDate; private DateTime targetDate;
private int grey;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); setContentView(R.layout.activity_main);
ButterKnife.bind(this);
grey = getResources().getColor(R.color.darkGrey);
final ImageView leftArrow = (ImageView) findViewById(R.id.left_arrow);
leftArrow.getDrawable().mutate().setColorFilter(grey, PorterDuff.Mode.SRC_ATOP); leftArrow.getDrawable().mutate().setColorFilter(grey, PorterDuff.Mode.SRC_ATOP);
final ImageView rightArrow = (ImageView) findViewById(R.id.right_arrow);
rightArrow.getDrawable().mutate().setColorFilter(grey, PorterDuff.Mode.SRC_ATOP); rightArrow.getDrawable().mutate().setColorFilter(grey, PorterDuff.Mode.SRC_ATOP);
final TextView monthTV = (TextView) findViewById(R.id.table_month);
final TableLayout tableHolder = (TableLayout) findViewById(R.id.table_holder);
final LayoutInflater inflater = getLayoutInflater(); final LayoutInflater inflater = getLayoutInflater();
final DateTime now = new DateTime(); final DateTime now = new DateTime();
@ -71,6 +74,16 @@ public class MainActivity extends AppCompatActivity {
} }
} }
@OnClick(R.id.left_arrow)
public void leftArrowClicked() {
}
@OnClick(R.id.right_arrow)
public void rightArrowClicked() {
}
private String getMonthName() { private String getMonthName() {
final String[] months = new DateFormatSymbols().getMonths(); final String[] months = new DateFormatSymbols().getMonths();
return months[targetDate.getMonthOfYear() - 1]; return months[targetDate.getMonthOfYear() - 1];

View File

@ -13,7 +13,9 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_alignBottom="@+id/table_month" android:layout_alignBottom="@+id/table_month"
android:layout_alignTop="@+id/table_month" android:layout_alignTop="@+id/table_month"
android:paddingBottom="@dimen/activity_margin"
android:paddingRight="@dimen/activity_margin" android:paddingRight="@dimen/activity_margin"
android:paddingTop="@dimen/activity_margin"
android:src="@mipmap/arrow_left"/> android:src="@mipmap/arrow_left"/>
<TextView <TextView
@ -33,7 +35,9 @@
android:layout_alignBottom="@+id/table_month" android:layout_alignBottom="@+id/table_month"
android:layout_alignParentRight="true" android:layout_alignParentRight="true"
android:layout_alignTop="@+id/table_month" android:layout_alignTop="@+id/table_month"
android:paddingBottom="@dimen/activity_margin"
android:paddingLeft="@dimen/activity_margin" android:paddingLeft="@dimen/activity_margin"
android:paddingTop="@dimen/activity_margin"
android:src="@mipmap/arrow_right"/> android:src="@mipmap/arrow_right"/>
<TableLayout <TableLayout