mirror of
https://github.com/SimpleMobileTools/Simple-Calendar.git
synced 2025-06-05 21:59:17 +02:00
basic widget functionality + misc cleanup
This commit is contained in:
@@ -15,15 +15,14 @@ public class CalendarImpl {
|
|||||||
private final String today;
|
private final String today;
|
||||||
private DateTime targetDate;
|
private DateTime targetDate;
|
||||||
|
|
||||||
public CalendarImpl(Calendar callback, DateTime targetDate) {
|
public CalendarImpl(Calendar callback) {
|
||||||
this.callback = callback;
|
this.callback = callback;
|
||||||
this.targetDate = targetDate;
|
|
||||||
today = new DateTime().toString(DATE_PATTERN);
|
today = new DateTime().toString(DATE_PATTERN);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateCalendar(DateTime targetDateTime) {
|
public void updateCalendar(DateTime targetDate) {
|
||||||
this.targetDate = targetDateTime;
|
this.targetDate = targetDate;
|
||||||
getDays(targetDateTime);
|
getDays(targetDate);
|
||||||
getMonthName();
|
getMonthName();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -46,9 +46,8 @@ public class MainActivity extends AppCompatActivity implements MyDatePickerDialo
|
|||||||
dayTextSize /= getResources().getDisplayMetrics().density;
|
dayTextSize /= getResources().getDisplayMetrics().density;
|
||||||
todayTextSize /= getResources().getDisplayMetrics().density;
|
todayTextSize /= getResources().getDisplayMetrics().density;
|
||||||
|
|
||||||
DateTime now = new DateTime();
|
calendar = new CalendarImpl(this);
|
||||||
calendar = new CalendarImpl(this, now);
|
calendar.updateCalendar(new DateTime());
|
||||||
calendar.updateCalendar(now);
|
|
||||||
|
|
||||||
setupLabelSizes();
|
setupLabelSizes();
|
||||||
}
|
}
|
||||||
|
@@ -1,13 +1,88 @@
|
|||||||
package calendar.simplemobiletools.com;
|
package calendar.simplemobiletools.com;
|
||||||
|
|
||||||
|
import android.app.PendingIntent;
|
||||||
import android.appwidget.AppWidgetManager;
|
import android.appwidget.AppWidgetManager;
|
||||||
import android.appwidget.AppWidgetProvider;
|
import android.appwidget.AppWidgetProvider;
|
||||||
|
import android.content.ComponentName;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.graphics.Color;
|
||||||
|
import android.widget.RemoteViews;
|
||||||
|
|
||||||
public class MyWidgetProvider extends AppWidgetProvider {
|
import org.joda.time.DateTime;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class MyWidgetProvider extends AppWidgetProvider implements Calendar {
|
||||||
|
private static final String PREV = "prev";
|
||||||
|
private static final String NEXT = "next";
|
||||||
|
private static RemoteViews remoteViews;
|
||||||
|
private static int[] widgetIds;
|
||||||
|
private static AppWidgetManager widgetManager;
|
||||||
|
private static Intent intent;
|
||||||
|
private static Context cxt;
|
||||||
|
private static CalendarImpl calendar;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
|
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
|
||||||
|
initVariables(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initVariables(Context context) {
|
||||||
|
cxt = context;
|
||||||
|
final ComponentName component = new ComponentName(cxt, MyWidgetProvider.class);
|
||||||
|
widgetManager = AppWidgetManager.getInstance(cxt);
|
||||||
|
widgetIds = widgetManager.getAppWidgetIds(component);
|
||||||
|
|
||||||
|
remoteViews = new RemoteViews(cxt.getPackageName(), R.layout.activity_main);
|
||||||
|
remoteViews.setInt(R.id.table_month, "setTextColor", Color.WHITE);
|
||||||
|
|
||||||
|
intent = new Intent(cxt, MyWidgetProvider.class);
|
||||||
|
setupButtons();
|
||||||
|
|
||||||
|
calendar = new CalendarImpl(this);
|
||||||
|
calendar.updateCalendar(new DateTime());
|
||||||
|
|
||||||
|
widgetManager.updateAppWidget(widgetIds, remoteViews);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setupIntent(String action, int id) {
|
||||||
|
intent.setAction(action);
|
||||||
|
final PendingIntent pendingIntent = PendingIntent.getBroadcast(cxt, 0, intent, 0);
|
||||||
|
remoteViews.setOnClickPendingIntent(id, pendingIntent);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setupButtons() {
|
||||||
|
setupIntent(PREV, R.id.left_arrow);
|
||||||
|
setupIntent(NEXT, R.id.right_arrow);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onReceive(Context context, Intent intent) {
|
||||||
|
if (remoteViews == null || widgetManager == null || widgetIds == null || calendar == null)
|
||||||
|
initVariables(context);
|
||||||
|
|
||||||
|
final String action = intent.getAction();
|
||||||
|
switch (action) {
|
||||||
|
case PREV:
|
||||||
|
calendar.getPrevMonth();
|
||||||
|
break;
|
||||||
|
case NEXT:
|
||||||
|
calendar.getNextMonth();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
super.onReceive(context, intent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateDays(List<Day> days) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateMonth(String month) {
|
||||||
|
remoteViews.setTextViewText(R.id.table_month, month);
|
||||||
|
widgetManager.updateAppWidget(widgetIds, remoteViews);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -28,7 +28,7 @@
|
|||||||
android:paddingBottom="@dimen/activity_margin"
|
android:paddingBottom="@dimen/activity_margin"
|
||||||
android:paddingTop="@dimen/activity_margin"
|
android:paddingTop="@dimen/activity_margin"
|
||||||
android:textColor="@color/darkGrey"
|
android:textColor="@color/darkGrey"
|
||||||
android:textSize="24sp"/>
|
android:textSize="22sp"/>
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/right_arrow"
|
android:id="@+id/right_arrow"
|
||||||
|
Reference in New Issue
Block a user