Skip to content
This repository was archived by the owner on Feb 25, 2022. It is now read-only.

Commit 873d30f

Browse files
author
Hisanobu Tomari
committed
Add Blue Javabutton app widget
1 parent 619930a commit 873d30f

File tree

15 files changed

+62
-7
lines changed

15 files changed

+62
-7
lines changed

app/src/main/AndroidManifest.xml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,25 @@
3131
<category android:name="android.intent.category.LAUNCHER" />
3232
</intent-filter>
3333
</activity>
34-
<receiver android:name="JavaButtonWidgetProvider" >
34+
<receiver android:name="JavaButtonWidgetProvider"
35+
android:label="@string/redjavabo_name">
3536
<intent-filter >
3637
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
3738
<action android:name="com.example.javabutton.JavaButtonWidgetProvider.JAVA_ACTION" />
3839
</intent-filter>
3940
<meta-data android:name="android.appwidget.provider"
4041
android:resource="@xml/javabutton_appwidget_info" />
4142
</receiver>
43+
<receiver android:name="AoiJavaboWidgetProvider"
44+
android:label="@string/blujavabo_name">
45+
<intent-filter>
46+
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
47+
<action android:name="com.example.javabutton.JavaButtonWidgetProvider.AOI_ACTION" />
48+
</intent-filter>
49+
<meta-data
50+
android:name="android.appwidget.provider"
51+
android:resource="@xml/aoi_appwidget_info" />
52+
</receiver>
4253
<activity
4354
android:name="com.example.javabutton.SettingsActivity"
4455
android:label="@string/settings_title" >
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.example.javabutton;
2+
3+
/**
4+
* Created by davy on 15/09/18.
5+
*/
6+
public class AoiJavaboWidgetProvider extends JavaButtonWidgetProvider {
7+
@Override
8+
protected String getJavaActionName() { return "com.example.javabutton.javabuttonwidget.AOI_ACTION"; }
9+
@Override
10+
protected int getJavaboLayoutId() { return R.layout.aoi_appwidget; }
11+
@Override
12+
protected int getJavaBotanId() { return R.id.aoiButton; }
13+
}

app/src/main/java/com/example/javabutton/JavaButtonWidgetProvider.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@
1111
import android.widget.RemoteViews;
1212

1313
public class JavaButtonWidgetProvider extends AppWidgetProvider {
14-
public static final String JAVA_ACTION="com.example.javabutton.javabuttonwidget.JAVA_ACTION";
1514
final Uri voiceuri= Uri.parse("android.resource://com.example.javabutton/raw/java22");
1615
JavaPlayer jp=new JavaPlayer(voiceuri);
16+
protected String getJavaActionName() { return "com.example.javabutton.javabuttonwidget.JAVA_ACTION"; }
17+
protected int getJavaboLayoutId() { return R.layout.javabutton_appwidget; }
18+
protected int getJavaBotanId() { return R.id.redButton; }
1719

1820
public void onReceive(Context context, Intent intent) {
1921
SharedPreferences shrP=PreferenceManager.getDefaultSharedPreferences(context);
20-
if(intent.getAction().equals(JAVA_ACTION)) {
22+
if(getJavaActionName().equals(intent.getAction())) {
2123
jp.play(context);
2224
SharedPreferences.Editor e=shrP.edit();
2325
long javaCounter=shrP.getLong(SettingsActivity.pref_counterPress, 0l);
@@ -32,13 +34,13 @@ public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] a
3234
final int N = appWidgetIds.length;
3335
for(int i=0; i<N; i++) {
3436
int appWidgetId = appWidgetIds[i];
35-
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.javabutton_appwidget);
36-
Intent javaIntent=new Intent(context,JavaButtonWidgetProvider.class);
37-
javaIntent.setAction(JAVA_ACTION);
37+
RemoteViews views = new RemoteViews(context.getPackageName(), getJavaboLayoutId());
38+
Intent javaIntent=new Intent(context,this.getClass());
39+
javaIntent.setAction(getJavaActionName());
3840
javaIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetIds[i]); // Not used
3941
PendingIntent javaPendingIntent=PendingIntent.getBroadcast(context,0,javaIntent,
4042
PendingIntent.FLAG_UPDATE_CURRENT);
41-
views.setOnClickPendingIntent(R.id.redButton, javaPendingIntent);
43+
views.setOnClickPendingIntent(getJavaBotanId(), javaPendingIntent);
4244
appWidgetManager.updateAppWidget(appWidgetId, views);
4345
}
4446
}
7.71 KB
Loading
7.53 KB
Loading
5.1 KB
Loading
4.99 KB
Loading
7 KB
Loading
6.76 KB
Loading
10.6 KB
Loading

0 commit comments

Comments
 (0)