25 changed files with 281 additions and 54 deletions
@ -1,5 +0,0 @@
|
||||
package sh.ftp.rocketninelabs.meditationassistant; |
||||
|
||||
public class MeditationProvider1 extends MeditationProvider { |
||||
|
||||
} |
@ -1,5 +0,0 @@
|
||||
package sh.ftp.rocketninelabs.meditationassistant; |
||||
|
||||
public class MeditationProvider2 extends MeditationProvider { |
||||
|
||||
} |
@ -1,5 +0,0 @@
|
||||
package sh.ftp.rocketninelabs.meditationassistant; |
||||
|
||||
public class MeditationProvider3 extends MeditationProvider { |
||||
|
||||
} |
@ -0,0 +1,5 @@
|
||||
package sh.ftp.rocketninelabs.meditationassistant; |
||||
|
||||
public class WidgetPresetProvider1 extends WidgetPresetProvider { |
||||
|
||||
} |
@ -0,0 +1,5 @@
|
||||
package sh.ftp.rocketninelabs.meditationassistant; |
||||
|
||||
public class WidgetPresetProvider2 extends WidgetPresetProvider { |
||||
|
||||
} |
@ -0,0 +1,5 @@
|
||||
package sh.ftp.rocketninelabs.meditationassistant; |
||||
|
||||
public class WidgetPresetProvider3 extends WidgetPresetProvider { |
||||
|
||||
} |
@ -0,0 +1,60 @@
|
||||
package sh.ftp.rocketninelabs.meditationassistant; |
||||
|
||||
import android.app.PendingIntent; |
||||
import android.app.Service; |
||||
import android.appwidget.AppWidgetManager; |
||||
import android.content.Intent; |
||||
import android.os.IBinder; |
||||
import android.util.Log; |
||||
import android.widget.RemoteViews; |
||||
|
||||
public class WidgetPresetService extends Service { |
||||
public IBinder onBind(Intent intent) { |
||||
return null; |
||||
} |
||||
|
||||
@Override |
||||
public int onStartCommand(Intent intent, int flags, int startId) { |
||||
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(this |
||||
.getApplicationContext()); |
||||
Log.d("MeditationAssistant", "Widget onStartCommand(): " + String.valueOf(intent)); |
||||
|
||||
if (intent == null) { |
||||
Log.d("MeditationAssistant", "Widget intent was null, exiting..."); |
||||
return START_STICKY; |
||||
} |
||||
|
||||
int[] allWidgetIds = intent.getIntArrayExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS); |
||||
if (allWidgetIds != null && allWidgetIds.length > 0) { |
||||
for (int widgetId : allWidgetIds) { |
||||
RemoteViews updateViews = new RemoteViews(this.getPackageName(), |
||||
R.layout.widget_preset); |
||||
|
||||
Log.d("MA", "Update view class " + updateViews.getClass()); |
||||
|
||||
MeditationAssistant ma = (MeditationAssistant) this |
||||
.getApplication(); |
||||
|
||||
updateViews.setTextColor(R.id.txtWidgetPresetText, ma.getPrefs().getInt("pref_widgetcolor", -16777216)); |
||||
|
||||
String label = ma.getPrefs().getString("pref_preset_1_label", ""); |
||||
if (label.equals("")) { |
||||
label = "Preset"; |
||||
} |
||||
// TODO: How to identify different preset widgets?
|
||||
updateViews.setTextViewText(R.id.txtWidgetPresetText, label); |
||||
|
||||
Intent clickintent = new Intent(getApplicationContext(), MainActivity.class); |
||||
clickintent.setAction("widgetclick"); |
||||
PendingIntent pendingIntent = PendingIntent.getActivity( |
||||
getApplicationContext(), 0, clickintent, 0); |
||||
updateViews.setOnClickPendingIntent(R.id.layWidget, pendingIntent); |
||||
updateViews.setOnClickPendingIntent(R.id.txtWidgetPresetText, pendingIntent); |
||||
|
||||
appWidgetManager.updateAppWidget(widgetId, updateViews); |
||||
} |
||||
} |
||||
|
||||
return START_STICKY; |
||||
} |
||||
} |
@ -0,0 +1,48 @@
|
||||
package sh.ftp.rocketninelabs.meditationassistant; |
||||
|
||||
import android.appwidget.AppWidgetManager; |
||||
import android.appwidget.AppWidgetProvider; |
||||
import android.content.ComponentName; |
||||
import android.content.Context; |
||||
import android.content.Intent; |
||||
import android.util.Log; |
||||
|
||||
public class WidgetStreakProvider extends AppWidgetProvider { |
||||
|
||||
private int[] mergeInts(int[] arg1, int[] arg2) { |
||||
int[] result = new int[arg1.length + arg2.length]; |
||||
System.arraycopy(arg1, 0, result, 0, arg1.length); |
||||
System.arraycopy(arg2, 0, result, arg1.length, arg2.length); |
||||
return result; |
||||
} |
||||
|
||||
@Override |
||||
public void onEnabled(Context context) { |
||||
Log.d("MeditationAssistant", "Widget onEnabled"); |
||||
super.onEnabled(context); |
||||
} |
||||
|
||||
@Override |
||||
public void onReceive(Context context, Intent intent) { |
||||
super.onReceive(context, intent); |
||||
|
||||
if (intent != null && intent.getAction() != null && intent.getAction().equals(AppWidgetManager.ACTION_APPWIDGET_UPDATE)) { |
||||
AppWidgetManager gm = AppWidgetManager.getInstance(context); |
||||
int[] ids = gm.getAppWidgetIds(new ComponentName(context, WidgetStreakProvider.class)); |
||||
ids = mergeInts(ids, gm.getAppWidgetIds(new ComponentName(context, WidgetStreakProvider1.class))); |
||||
ids = mergeInts(ids, gm.getAppWidgetIds(new ComponentName(context, WidgetStreakProvider2.class))); |
||||
ids = mergeInts(ids, gm.getAppWidgetIds(new ComponentName(context, WidgetStreakProvider3.class))); |
||||
|
||||
onUpdate(context, gm, ids); |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { |
||||
Intent intent = new Intent(context, WidgetStreakService.class); |
||||
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, appWidgetIds); |
||||
context.startService(intent); |
||||
|
||||
super.onUpdate(context, appWidgetManager, appWidgetIds); |
||||
} |
||||
} |
@ -0,0 +1,5 @@
|
||||
package sh.ftp.rocketninelabs.meditationassistant; |
||||
|
||||
public class WidgetStreakProvider1 extends WidgetStreakProvider { |
||||
|
||||
} |
@ -0,0 +1,5 @@
|
||||
package sh.ftp.rocketninelabs.meditationassistant; |
||||
|
||||
public class WidgetStreakProvider2 extends WidgetStreakProvider { |
||||
|
||||
} |
@ -0,0 +1,5 @@
|
||||
package sh.ftp.rocketninelabs.meditationassistant; |
||||
|
||||
public class WidgetStreakProvider3 extends WidgetStreakProvider { |
||||
|
||||
} |
@ -0,0 +1,26 @@
|
||||
<FrameLayout |
||||
android:id="@+id/layWidget" |
||||
xmlns:android="http://schemas.android.com/apk/res/android" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="match_parent" |
||||
android:clickable="true" |
||||
android:padding="@dimen/widget_margin"> |
||||
|
||||
<LinearLayout |
||||
android:layout_width="match_parent" |
||||
android:layout_height="match_parent" |
||||
android:orientation="horizontal"> |
||||
|
||||
<TextView |
||||
android:id="@+id/txtWidgetPresetText" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content" |
||||
android:layout_gravity="center_vertical" |
||||
android:clickable="true" |
||||
android:gravity="right" |
||||
android:text="" |
||||
android:textAppearance="?android:attr/textAppearanceMedium" |
||||
android:textSize="18sp"/> |
||||
</LinearLayout> |
||||
|
||||
</FrameLayout> |
@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android" |
||||
xmlns:tools="http://schemas.android.com/tools" |
||||
android:initialLayout="@layout/widget_preset" |
||||
android:minHeight="40dp" |
||||
android:minWidth="40dp" |
||||
android:resizeMode="horizontal" |
||||
android:theme="@style/MeditationDarkTheme" |
||||
android:updatePeriodMillis="43200000" |
||||
android:widgetCategory="keyguard|home_screen" |
||||
tools:ignore="UnusedAttribute"> |
||||
|
||||
</appwidget-provider> |
@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android" |
||||
xmlns:tools="http://schemas.android.com/tools" |
||||
android:initialLayout="@layout/widget_preset" |
||||
android:minHeight="40dp" |
||||
android:minWidth="110dp" |
||||
android:resizeMode="horizontal" |
||||
android:theme="@style/MeditationDarkTheme" |
||||
android:updatePeriodMillis="43200000" |
||||
android:widgetCategory="keyguard|home_screen" |
||||
tools:ignore="UnusedAttribute"> |
||||
|
||||
</appwidget-provider> |
@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android" |
||||
xmlns:tools="http://schemas.android.com/tools" |
||||
android:initialLayout="@layout/widget_preset" |
||||
android:minHeight="40dp" |
||||
android:minWidth="180dp" |
||||
android:resizeMode="horizontal" |
||||
android:theme="@style/MeditationDarkTheme" |
||||
android:updatePeriodMillis="43200000" |
||||
android:widgetCategory="keyguard|home_screen" |
||||
tools:ignore="UnusedAttribute"> |
||||
|
||||
</appwidget-provider> |
@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android" |
||||
xmlns:tools="http://schemas.android.com/tools" |
||||
android:initialLayout="@layout/widget_layout" |
||||
android:initialLayout="@layout/widget_streak" |
||||
android:minHeight="40dp" |
||||
android:minWidth="40dp" |
||||
android:resizeMode="horizontal" |
@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android" |
||||
xmlns:tools="http://schemas.android.com/tools" |
||||
android:initialLayout="@layout/widget_layout" |
||||
android:initialLayout="@layout/widget_streak" |
||||
android:minHeight="40dp" |
||||
android:minWidth="110dp" |
||||
android:resizeMode="horizontal" |
@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android" |
||||
xmlns:tools="http://schemas.android.com/tools" |
||||
android:initialLayout="@layout/widget_layout" |
||||
android:initialLayout="@layout/widget_streak" |
||||
android:minHeight="40dp" |
||||
android:minWidth="180dp" |
||||
android:resizeMode="horizontal" |
Loading…
Reference in new issue