change the way we are creating the table so it can be reused in a widget
This commit is contained in:
parent
523149b7b0
commit
69fba230e7
|
@ -3,7 +3,6 @@ package calendar.simplemobiletools.com;
|
|||
import android.graphics.PorterDuff;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.view.LayoutInflater;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
@ -46,25 +45,9 @@ public class MainActivity extends AppCompatActivity implements MyDatePickerDialo
|
|||
targetDate = new DateTime();
|
||||
today = targetDate.toString(DATE_PATTERN);
|
||||
|
||||
createDays();
|
||||
fillCalendar();
|
||||
}
|
||||
dayTextSize /= getResources().getDisplayMetrics().density;
|
||||
|
||||
private void createDays() {
|
||||
final String[] days = {"M", "T", "W", "T", "F", "S", "S"};
|
||||
final LayoutInflater inflater = getLayoutInflater();
|
||||
for (int i = 0; i < 7; i++) {
|
||||
final LinearLayout row = (LinearLayout) inflater.inflate(R.layout.table_row, tableHolder, false);
|
||||
tableHolder.addView(row);
|
||||
for (int j = 0; j < 7; j++) {
|
||||
final TextView day = (TextView) inflater.inflate(R.layout.table_day, row, false);
|
||||
if (i == 0) {
|
||||
day.setText(days[j]);
|
||||
day.setTextSize(dayTextSize);
|
||||
}
|
||||
row.addView(day);
|
||||
}
|
||||
}
|
||||
fillCalendar();
|
||||
}
|
||||
|
||||
private void fillCalendar() {
|
||||
|
@ -78,9 +61,11 @@ public class MainActivity extends AppCompatActivity implements MyDatePickerDialo
|
|||
int thisMonthDays = 1;
|
||||
int nextMonthsDay = 1;
|
||||
|
||||
for (int i = 1; i < 7; i++) {
|
||||
final int rowsCnt = tableHolder.getChildCount();
|
||||
for (int i = 1; i < rowsCnt; i++) {
|
||||
final LinearLayout row = (LinearLayout) tableHolder.getChildAt(i);
|
||||
for (int j = 0; j < 7; j++) {
|
||||
final int daysCnt = row.getChildCount();
|
||||
for (int j = 0; j < daysCnt; j++) {
|
||||
final TextView day = (TextView) row.getChildAt(j);
|
||||
day.setTextSize(dayTextSize);
|
||||
|
||||
|
|
|
@ -50,6 +50,348 @@
|
|||
android:layout_marginBottom="@dimen/activity_margin"
|
||||
android:layout_marginTop="@dimen/activity_margin"
|
||||
android:gravity="center"
|
||||
android:orientation="vertical"/>
|
||||
android:orientation="vertical">
|
||||
|
||||
<include
|
||||
layout="@layout/first_row"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"/>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/day_0"
|
||||
style="@style/dayView"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/day_1"
|
||||
style="@style/dayView"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/day_2"
|
||||
style="@style/dayView"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/day_3"
|
||||
style="@style/dayView"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/day_4"
|
||||
style="@style/dayView"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/day_5"
|
||||
style="@style/dayView"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/day_6"
|
||||
style="@style/dayView"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"/>
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/day_7"
|
||||
style="@style/dayView"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/day_8"
|
||||
style="@style/dayView"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/day_9"
|
||||
style="@style/dayView"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/day_10"
|
||||
style="@style/dayView"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/day_11"
|
||||
style="@style/dayView"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/day_12"
|
||||
style="@style/dayView"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/day_13"
|
||||
style="@style/dayView"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"/>
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/day_14"
|
||||
style="@style/dayView"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/day_15"
|
||||
style="@style/dayView"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/day_16"
|
||||
style="@style/dayView"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/day_17"
|
||||
style="@style/dayView"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/day_18"
|
||||
style="@style/dayView"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/day_19"
|
||||
style="@style/dayView"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/day_20"
|
||||
style="@style/dayView"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"/>
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/day_21"
|
||||
style="@style/dayView"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/day_22"
|
||||
style="@style/dayView"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/day_23"
|
||||
style="@style/dayView"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/day_24"
|
||||
style="@style/dayView"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/day_25"
|
||||
style="@style/dayView"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/day_26"
|
||||
style="@style/dayView"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/day_27"
|
||||
style="@style/dayView"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"/>
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/day_28"
|
||||
style="@style/dayView"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/day_29"
|
||||
style="@style/dayView"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/day_30"
|
||||
style="@style/dayView"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/day_31"
|
||||
style="@style/dayView"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/day_32"
|
||||
style="@style/dayView"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/day_33"
|
||||
style="@style/dayView"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/day_34"
|
||||
style="@style/dayView"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"/>
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/day_35"
|
||||
style="@style/dayView"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/day_36"
|
||||
style="@style/dayView"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/day_37"
|
||||
style="@style/dayView"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/day_38"
|
||||
style="@style/dayView"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/day_39"
|
||||
style="@style/dayView"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/day_40"
|
||||
style="@style/dayView"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/day_41"
|
||||
style="@style/dayView"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"/>
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
</RelativeLayout>
|
||||
|
|
|
@ -0,0 +1,65 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/label_0"
|
||||
style="@style/dayView"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:text="M"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/label_1"
|
||||
style="@style/dayView"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:text="T"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/label_2"
|
||||
style="@style/dayView"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:text="W"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/label_3"
|
||||
style="@style/dayView"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:text="T"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/label_4"
|
||||
style="@style/dayView"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:text="F"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/label_5"
|
||||
style="@style/dayView"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:text="S"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/label_6"
|
||||
style="@style/dayView"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:text="S"/>
|
||||
|
||||
</LinearLayout>
|
|
@ -1,10 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<TextView
|
||||
android:id="@+id/day"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:gravity="center"
|
||||
android:textColor="@color/lightGrey"
|
||||
android:textSize="@dimen/day_text_size"/>
|
|
@ -1,8 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout
|
||||
android:id="@+id/row"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:orientation="horizontal"/>
|
|
@ -1,6 +1,5 @@
|
|||
<resources>
|
||||
<dimen name="activity_margin">16dp</dimen>
|
||||
|
||||
<dimen name="day_text_size">10sp</dimen>
|
||||
<dimen name="today_text_size">20sp</dimen>
|
||||
<dimen name="day_text_size">16sp</dimen>
|
||||
<dimen name="today_text_size">22sp</dimen>
|
||||
</resources>
|
||||
|
|
|
@ -8,4 +8,10 @@
|
|||
<item name="colorAccent">@color/colorAccent</item>
|
||||
</style>
|
||||
|
||||
<style name="dayView" parent="AppTheme">
|
||||
<item name="android:gravity">center</item>
|
||||
<item name="android:textColor">@color/lightGrey</item>
|
||||
<item name="android:textSize">@dimen/day_text_size</item>
|
||||
</style>
|
||||
|
||||
</resources>
|
||||
|
|
Loading…
Reference in New Issue