mirror of
https://github.com/SimpleMobileTools/Simple-Calendar.git
synced 2025-01-30 18:34:52 +01:00
fill in month days
This commit is contained in:
parent
a439b4790e
commit
a28d5ed2d1
@ -1,8 +1,6 @@
|
||||
package com.simplemobiletools.calendar.activities;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Color;
|
||||
import android.os.Bundle;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
@ -10,15 +8,12 @@ import android.view.View;
|
||||
import android.widget.DatePicker;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.NumberPicker;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.simplemobiletools.calendar.Config;
|
||||
import com.simplemobiletools.calendar.Constants;
|
||||
import com.simplemobiletools.calendar.Formatter;
|
||||
import com.simplemobiletools.calendar.R;
|
||||
import com.simplemobiletools.calendar.Utils;
|
||||
import com.simplemobiletools.calendar.adapters.MyPagerAdapter;
|
||||
import com.simplemobiletools.calendar.models.Day;
|
||||
import com.simplemobiletools.calendar.views.MyViewPager;
|
||||
|
||||
import org.joda.time.DateTime;
|
||||
@ -33,9 +28,6 @@ import butterknife.ButterKnife;
|
||||
import butterknife.OnClick;
|
||||
|
||||
public class MainActivity extends SimpleActivity {
|
||||
/*@BindView(R.id.top_left_arrow) ImageView mLeftArrow;
|
||||
@BindView(R.id.top_right_arrow) ImageView mRightArrow;
|
||||
@BindView(R.id.calendar_holder) View mCalendarHolder;*/
|
||||
@BindView(R.id.view_pager) MyViewPager mPager;
|
||||
|
||||
@BindDimen(R.dimen.day_text_size) float mDayTextSize;
|
||||
@ -43,33 +35,12 @@ public class MainActivity extends SimpleActivity {
|
||||
|
||||
private static final int PREFILLED_MONTHS = 73;
|
||||
|
||||
private Resources mRes;
|
||||
private String mPackageName;
|
||||
|
||||
private int mTextColor;
|
||||
private int mWeakTextColor;
|
||||
private int mTextColorWithEvent;
|
||||
private int mWeakTextColorWithEvent;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_main);
|
||||
ButterKnife.bind(this);
|
||||
|
||||
final int baseColor = mConfig.getIsDarkTheme() ? Color.WHITE : Color.BLACK;
|
||||
mRes = getResources();
|
||||
mTextColor = Utils.adjustAlpha(baseColor, Constants.HIGH_ALPHA);
|
||||
mTextColorWithEvent = Utils.adjustAlpha(mRes.getColor(R.color.colorPrimary), Constants.HIGH_ALPHA);
|
||||
mWeakTextColor = Utils.adjustAlpha(baseColor, Constants.LOW_ALPHA);
|
||||
mWeakTextColorWithEvent = Utils.adjustAlpha(mRes.getColor(R.color.colorPrimary), Constants.LOW_ALPHA);
|
||||
//mLeftArrow.getDrawable().mutate().setColorFilter(mTextColor, PorterDuff.Mode.SRC_ATOP);
|
||||
//mRightArrow.getDrawable().mutate().setColorFilter(mTextColor, PorterDuff.Mode.SRC_ATOP);
|
||||
|
||||
mPackageName = getPackageName();
|
||||
mDayTextSize /= mRes.getDisplayMetrics().density;
|
||||
mTodayTextSize /= mRes.getDisplayMetrics().density;
|
||||
|
||||
final String today = new DateTime().toString(Formatter.DAYCODE_PATTERN);
|
||||
final List<String> codes = getMonths(today);
|
||||
final MyPagerAdapter adapter = new MyPagerAdapter(getSupportFragmentManager(), codes);
|
||||
@ -121,48 +92,6 @@ public class MainActivity extends SimpleActivity {
|
||||
return months;
|
||||
}
|
||||
|
||||
private void updateDays(List<Day> days) {
|
||||
final int len = days.size();
|
||||
|
||||
for (int i = 0; i < len; i++) {
|
||||
final Day day = days.get(i);
|
||||
final TextView dayTV = (TextView) findViewById(mRes.getIdentifier("day_" + i, "id", mPackageName));
|
||||
if (dayTV == null)
|
||||
continue;
|
||||
|
||||
int curTextColor = day.getHasEvent() ? mWeakTextColorWithEvent : mWeakTextColor;
|
||||
float curTextSize = mDayTextSize;
|
||||
|
||||
if (day.getIsThisMonth()) {
|
||||
curTextColor = day.getHasEvent() ? mTextColorWithEvent : mTextColor;
|
||||
}
|
||||
|
||||
if (day.getIsToday()) {
|
||||
curTextSize = mTodayTextSize;
|
||||
}
|
||||
|
||||
dayTV.setText(String.valueOf(day.getValue()));
|
||||
dayTV.setTextColor(curTextColor);
|
||||
dayTV.setTextSize(curTextSize);
|
||||
|
||||
dayTV.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
openDay(day.getCode());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void openDay(String code) {
|
||||
if (code.isEmpty())
|
||||
return;
|
||||
|
||||
final Intent intent = new Intent(getApplicationContext(), DayActivity.class);
|
||||
intent.putExtra(Constants.DAY_CODE, code);
|
||||
startActivity(intent);
|
||||
}
|
||||
|
||||
/*@OnClick(R.id.top_left_arrow)
|
||||
public void leftArrowClicked() {
|
||||
mCalendar.getPrevMonth();
|
||||
@ -205,5 +134,4 @@ public class MainActivity extends SimpleActivity {
|
||||
final NumberPicker dayPicker = (picker1.getMaxValue() > picker2.getMaxValue()) ? picker1 : picker2;
|
||||
dayPicker.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,9 +1,11 @@
|
||||
package com.simplemobiletools.calendar.fragments;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
@ -18,6 +20,7 @@ import com.simplemobiletools.calendar.Constants;
|
||||
import com.simplemobiletools.calendar.Formatter;
|
||||
import com.simplemobiletools.calendar.R;
|
||||
import com.simplemobiletools.calendar.Utils;
|
||||
import com.simplemobiletools.calendar.activities.DayActivity;
|
||||
import com.simplemobiletools.calendar.models.Day;
|
||||
|
||||
import java.util.List;
|
||||
@ -41,6 +44,7 @@ public class MonthFragment extends Fragment implements Calendar {
|
||||
private String mPackageName;
|
||||
private Config mConfig;
|
||||
|
||||
private String mCode;
|
||||
private int mTextColor;
|
||||
private int mWeakTextColor;
|
||||
private int mTextColorWithEvent;
|
||||
@ -51,23 +55,29 @@ public class MonthFragment extends Fragment implements Calendar {
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
mView = inflater.inflate(R.layout.calendar_layout, container, false);
|
||||
ButterKnife.bind(this, mView);
|
||||
mRes = getResources();
|
||||
|
||||
final String code = getArguments().getString(Constants.DAY_CODE);
|
||||
mCalendar = new CalendarImpl(this, getContext());
|
||||
mCalendar.updateCalendar(Formatter.getDateTimeFromCode(code));
|
||||
mCode = getArguments().getString(Constants.DAY_CODE);
|
||||
mConfig = Config.newInstance(getContext());
|
||||
mSundayFirst = mConfig.getIsSundayFirst();
|
||||
|
||||
mRes = getResources();
|
||||
setupColors();
|
||||
|
||||
mPackageName = getActivity().getPackageName();
|
||||
mDayTextSize /= mRes.getDisplayMetrics().density;
|
||||
mTodayTextSize /= mRes.getDisplayMetrics().density;
|
||||
setupLabels();
|
||||
|
||||
return mView;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
mCalendar = new CalendarImpl(this, getContext());
|
||||
mCalendar.updateCalendar(Formatter.getDateTimeFromCode(mCode));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
@ -80,6 +90,7 @@ public class MonthFragment extends Fragment implements Calendar {
|
||||
@Override
|
||||
public void updateCalendar(String month, List<Day> days) {
|
||||
mMonthTV.setText(month);
|
||||
updateDays(days);
|
||||
}
|
||||
|
||||
private void setupColors() {
|
||||
@ -119,4 +130,46 @@ public class MonthFragment extends Fragment implements Calendar {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void updateDays(List<Day> days) {
|
||||
final int len = days.size();
|
||||
|
||||
for (int i = 0; i < len; i++) {
|
||||
final Day day = days.get(i);
|
||||
final TextView dayTV = (TextView) mView.findViewById(mRes.getIdentifier("day_" + i, "id", mPackageName));
|
||||
if (dayTV == null)
|
||||
continue;
|
||||
|
||||
int curTextColor = day.getHasEvent() ? mWeakTextColorWithEvent : mWeakTextColor;
|
||||
float curTextSize = mDayTextSize;
|
||||
|
||||
if (day.getIsThisMonth()) {
|
||||
curTextColor = day.getHasEvent() ? mTextColorWithEvent : mTextColor;
|
||||
}
|
||||
|
||||
if (day.getIsToday()) {
|
||||
curTextSize = mTodayTextSize;
|
||||
}
|
||||
|
||||
dayTV.setText(String.valueOf(day.getValue()));
|
||||
dayTV.setTextColor(curTextColor);
|
||||
dayTV.setTextSize(curTextSize);
|
||||
|
||||
dayTV.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
openDay(day.getCode());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void openDay(String code) {
|
||||
if (code.isEmpty())
|
||||
return;
|
||||
|
||||
final Intent intent = new Intent(getContext(), DayActivity.class);
|
||||
intent.putExtra(Constants.DAY_CODE, code);
|
||||
startActivity(intent);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user