From 69fba230e7ac51b6711f333a045fcce778c5ee5d Mon Sep 17 00:00:00 2001 From: tibbi Date: Sat, 30 Jan 2016 18:30:33 +0100 Subject: [PATCH] change the way we are creating the table so it can be reused in a widget --- .../simplemobiletools/com/MainActivity.java | 27 +- app/src/main/res/layout/activity_main.xml | 344 +++++++++++++++++- app/src/main/res/layout/first_row.xml | 65 ++++ app/src/main/res/layout/table_day.xml | 10 - app/src/main/res/layout/table_row.xml | 8 - app/src/main/res/values/dimens.xml | 5 +- app/src/main/res/values/styles.xml | 6 + 7 files changed, 422 insertions(+), 43 deletions(-) create mode 100644 app/src/main/res/layout/first_row.xml delete mode 100644 app/src/main/res/layout/table_day.xml delete mode 100644 app/src/main/res/layout/table_row.xml diff --git a/app/src/main/java/calendar/simplemobiletools/com/MainActivity.java b/app/src/main/java/calendar/simplemobiletools/com/MainActivity.java index bb67f99c3..00245f893 100644 --- a/app/src/main/java/calendar/simplemobiletools/com/MainActivity.java +++ b/app/src/main/java/calendar/simplemobiletools/com/MainActivity.java @@ -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); diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 51b431073..f9e8c04ef 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -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"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/first_row.xml b/app/src/main/res/layout/first_row.xml new file mode 100644 index 000000000..5e8ab1fad --- /dev/null +++ b/app/src/main/res/layout/first_row.xml @@ -0,0 +1,65 @@ + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/table_day.xml b/app/src/main/res/layout/table_day.xml deleted file mode 100644 index 87f40e2c0..000000000 --- a/app/src/main/res/layout/table_day.xml +++ /dev/null @@ -1,10 +0,0 @@ - - diff --git a/app/src/main/res/layout/table_row.xml b/app/src/main/res/layout/table_row.xml deleted file mode 100644 index 9f42868ca..000000000 --- a/app/src/main/res/layout/table_row.xml +++ /dev/null @@ -1,8 +0,0 @@ - - diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml index ec0f81974..1a895c522 100644 --- a/app/src/main/res/values/dimens.xml +++ b/app/src/main/res/values/dimens.xml @@ -1,6 +1,5 @@ 16dp - - 10sp - 20sp + 16sp + 22sp diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 5885930df..f84c0416d 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -8,4 +8,10 @@ @color/colorAccent + +