-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
190 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
Lab3/app/src/main/java/com/example/zyz/lab3/NewAppWidget.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package com.example.zyz.lab3; | ||
|
||
import android.app.PendingIntent; | ||
import android.appwidget.AppWidgetManager; | ||
import android.appwidget.AppWidgetProvider; | ||
import android.content.ComponentName; | ||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.os.Bundle; | ||
import android.widget.RemoteViews; | ||
|
||
/** | ||
* Implementation of App Widget functionality. | ||
*/ | ||
public class NewAppWidget extends AppWidgetProvider { | ||
private static final String STATICACTION = "com.example.zyz.lab3.MyStaticFilter"; | ||
private static final String DYNAMICACTION = "com.example.zyz.lab3.MyDynamicFilter"; | ||
private Items items; | ||
|
||
static void updateAppWidget(Context context, AppWidgetManager appWidgetManager, | ||
int appWidgetId) { | ||
|
||
//CharSequence widgetText = context.getString(R.string.appwidget_text); | ||
// Construct the RemoteViews object | ||
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.new_app_widget); | ||
Intent intent = new Intent(context,MainActivity.class); | ||
PendingIntent pendingIntent = PendingIntent.getActivity(context,0,intent,PendingIntent.FLAG_UPDATE_CURRENT); | ||
views.setOnClickPendingIntent(R.id.widget_image,pendingIntent); | ||
ComponentName componentName = new ComponentName(context,NewAppWidget.class); | ||
//views.setTextViewText(R.id.appwidget_text, widgetText); | ||
|
||
// Instruct the widget manager to update the widget | ||
appWidgetManager.updateAppWidget(componentName, views); | ||
} | ||
|
||
@Override | ||
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { | ||
// There may be multiple widgets active, so update all of them | ||
for (int appWidgetId : appWidgetIds) { | ||
updateAppWidget(context, appWidgetManager, appWidgetId); | ||
} | ||
} | ||
|
||
@Override | ||
public void onEnabled(Context context) { | ||
// Enter relevant functionality for when the first widget is created | ||
} | ||
|
||
@Override | ||
public void onDisabled(Context context) { | ||
// Enter relevant functionality for when the last widget is disabled | ||
} | ||
|
||
@Override | ||
public void onReceive(Context context,Intent intent) | ||
{ | ||
super.onReceive(context,intent); | ||
// AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context); | ||
// Bundle bundle = intent.getExtras(); | ||
if(intent.getAction().equals(STATICACTION)) | ||
{ | ||
items = (Items) intent.getExtras().get("item"); | ||
assert items != null; | ||
Intent local_intent = new Intent(context,ItemInfo.class); | ||
|
||
Bundle bundle = new Bundle(); | ||
bundle.putSerializable("item",items); | ||
local_intent.putExtras(bundle); | ||
RemoteViews remoteViews = new RemoteViews(context.getPackageName(),R.layout.new_app_widget); | ||
PendingIntent pendingIntent = PendingIntent.getActivity(context,0,local_intent,PendingIntent.FLAG_UPDATE_CURRENT); | ||
remoteViews.setTextViewText(R.id.appwidget_text,items.getName()+"仅售¥ "+items.getPrice()); | ||
remoteViews.setImageViewResource(R.id.widget_image,items.getImg()); | ||
remoteViews.setOnClickPendingIntent(R.id.widget_image,pendingIntent); | ||
ComponentName componentName = new ComponentName(context,NewAppWidget.class); | ||
AppWidgetManager.getInstance(context).updateAppWidget(componentName,remoteViews); | ||
} | ||
} | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:background="#00000000" | ||
android:orientation="horizontal" | ||
android:padding="@dimen/widget_margin"> | ||
|
||
<TextView | ||
android:id="@+id/appwidget_text" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_centerVertical="true" | ||
android:layout_margin="8dp" | ||
android:background="#00000000" | ||
android:contentDescription="@string/appwidget_text" | ||
android:text="@string/appwidget_text" | ||
android:layout_toRightOf="@+id/widget_image" | ||
android:textColor="#ffffff" | ||
android:textSize="15sp" | ||
android:textStyle="bold|italic" /> | ||
|
||
<ImageView | ||
android:id="@+id/widget_image" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_centerVertical="true" | ||
android:layout_alignParentStart="true" | ||
android:src="@drawable/shoplist" | ||
app:srcCompat="@drawable/arla" /> | ||
|
||
</RelativeLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
|
||
<!-- | ||
Refer to App Widget Documentation for margin information | ||
http://developer.android.com/guide/topics/appwidgets/index.html#CreatingLayout | ||
--> | ||
<dimen name="widget_margin">0dp</dimen> | ||
|
||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
|
||
<!-- | ||
Refer to App Widget Documentation for margin information | ||
http://developer.android.com/guide/topics/appwidgets/index.html#CreatingLayout | ||
--> | ||
<dimen name="widget_margin">8dp</dimen> | ||
|
||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:initialKeyguardLayout="@layout/new_app_widget" | ||
android:initialLayout="@layout/new_app_widget" | ||
android:minHeight="40dp" | ||
android:minWidth="40dp" | ||
android:previewImage="@drawable/example_appwidget_preview" | ||
android:resizeMode="horizontal|vertical" | ||
android:updatePeriodMillis="86400000" | ||
android:widgetCategory="home_screen"></appwidget-provider> |