1 |
/**
|
2 |
* ZANavi, Zoff Android Navigation system.
|
3 |
* Copyright (C) 2014 Zoff <zoff@zoff.cc>
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* version 2 as published by the Free Software Foundation.
|
8 |
*
|
9 |
* This program is distributed in the hope that it will be useful,
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12 |
* GNU General Public License for more details.
|
13 |
*
|
14 |
* You should have received a copy of the GNU General Public License
|
15 |
* along with this program; if not, write to the
|
16 |
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
17 |
* Boston, MA 02110-1301, USA.
|
18 |
*/
|
19 |
|
20 |
package com.zoffcc.applications.zanavi;
|
21 |
|
22 |
import android.app.PendingIntent;
|
23 |
import android.appwidget.AppWidgetManager;
|
24 |
import android.appwidget.AppWidgetProvider;
|
25 |
import android.content.Context;
|
26 |
import android.content.Intent;
|
27 |
import android.os.Bundle;
|
28 |
import android.widget.RemoteViews;
|
29 |
|
30 |
public class ZANaviDriveHomeWidgetProvider extends AppWidgetProvider
|
31 |
{
|
32 |
// SimpleDateFormat df = new SimpleDateFormat("hh:mm:ss");
|
33 |
|
34 |
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds)
|
35 |
{
|
36 |
final int N = appWidgetIds.length;
|
37 |
|
38 |
// loop for each app widget
|
39 |
for (int i = 0; i < N; i++)
|
40 |
{
|
41 |
int appWidgetId = appWidgetIds[i];
|
42 |
|
43 |
// create an intent to launch ZANavi
|
44 |
Intent intent = new Intent(context, Navit.class);
|
45 |
// but some data into the intent
|
46 |
Bundle sendBundle = new Bundle();
|
47 |
sendBundle.putLong("ZANAVI_INTENT_type", Navit.NAVIT_START_INTENT_DRIVE_HOME);
|
48 |
intent.putExtras(sendBundle);
|
49 |
|
50 |
// if ZANavi main activity already running, then only bring to front, otherwise start it // Intent.FLAG_ACTIVITY_NEW_TASK
|
51 |
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
|
52 |
|
53 |
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_home);
|
54 |
views.setOnClickPendingIntent(R.id.icon_widget_home, pendingIntent);
|
55 |
|
56 |
appWidgetManager.updateAppWidget(appWidgetId, views);
|
57 |
}
|
58 |
}
|
59 |
}
|