Widget to show build version at a glance.
Extremely useful when working with different builds on several otherwise-identical devices.
This commit is contained in:
16
apps/BuildWidget/Android.mk
Normal file
16
apps/BuildWidget/Android.mk
Normal file
@@ -0,0 +1,16 @@
|
||||
LOCAL_PATH:= $(call my-dir)
|
||||
include $(CLEAR_VARS)
|
||||
|
||||
LOCAL_MODULE_TAGS := samples tests
|
||||
|
||||
# Only compile source java files in this apk.
|
||||
LOCAL_SRC_FILES := $(call all-java-files-under, src)
|
||||
|
||||
LOCAL_PACKAGE_NAME := BuildWidget
|
||||
|
||||
LOCAL_SDK_VERSION := current
|
||||
|
||||
include $(BUILD_PACKAGE)
|
||||
|
||||
# Use the following include to make our test apk.
|
||||
include $(call all-makefiles-under,$(LOCAL_PATH))
|
||||
18
apps/BuildWidget/AndroidManifest.xml
Normal file
18
apps/BuildWidget/AndroidManifest.xml
Normal file
@@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.android.buildwidget"
|
||||
android:versionCode="1"
|
||||
android:versionName="1.0">
|
||||
|
||||
<uses-sdk android:minSdkVersion="3" />
|
||||
<application android:icon="@drawable/icon" android:label="@string/app_name">
|
||||
<receiver android:name=".BuildWidget" android:label="@string/widget_name">
|
||||
<intent-filter>
|
||||
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
|
||||
</intent-filter>
|
||||
<meta-data android:name="android.appwidget.provider" android:resource="@xml/widget_build" />
|
||||
</receiver>
|
||||
<service android:name=".BuildWidget$UpdateService" />
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
BIN
apps/BuildWidget/res/drawable-hdpi/icon.png
Normal file
BIN
apps/BuildWidget/res/drawable-hdpi/icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 5.0 KiB |
BIN
apps/BuildWidget/res/drawable-mdpi/icon.png
Normal file
BIN
apps/BuildWidget/res/drawable-mdpi/icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 3.1 KiB |
44
apps/BuildWidget/res/layout/widget.xml
Normal file
44
apps/BuildWidget/res/layout/widget.xml
Normal file
@@ -0,0 +1,44 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (C) 2009 The Android Open Source Project
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/widget"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:padding="6dip"
|
||||
>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/build_info"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="left"
|
||||
style="@style/Text.BuildInfo.Fancy"
|
||||
android:textSize="18dip"
|
||||
/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/build_changelist"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="left"
|
||||
android:layout_marginTop="4dip"
|
||||
style="@style/Text.BuildInfo.Fancy"
|
||||
android:textSize="9dip"
|
||||
/>
|
||||
|
||||
</LinearLayout>
|
||||
4
apps/BuildWidget/res/values/colors.xml
Normal file
4
apps/BuildWidget/res/values/colors.xml
Normal file
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<color name="droidgreen">#FFA4C639</color>
|
||||
</resources>
|
||||
20
apps/BuildWidget/res/values/strings.xml
Normal file
20
apps/BuildWidget/res/values/strings.xml
Normal file
@@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (C) 2009 The Android Open Source Project
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
|
||||
<resources>
|
||||
<string name="app_name">Build Number</string>
|
||||
<string name="widget_name">Build Number</string>
|
||||
</resources>
|
||||
20
apps/BuildWidget/res/values/styles.xml
Normal file
20
apps/BuildWidget/res/values/styles.xml
Normal file
@@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<style name="Text" />
|
||||
|
||||
<style name="Text.BuildInfo">
|
||||
<!-- <item name="android:typeface">monospace</item>-->
|
||||
<item name="android:textSize">12sp</item>
|
||||
<item name="android:textStyle">bold</item>
|
||||
<item name="android:textColor">@color/droidgreen</item>
|
||||
<item name="android:shadowColor">@android:color/black</item>
|
||||
<item name="android:shadowDx">0</item>
|
||||
<item name="android:shadowDy">0</item>
|
||||
<item name="android:shadowRadius">3.0</item>
|
||||
</style>
|
||||
|
||||
<style name="Text.BuildInfo.Fancy">
|
||||
<item name="android:textColor">@android:color/white</item>
|
||||
<item name="android:shadowColor">@color/droidgreen</item>
|
||||
</style>
|
||||
</resources>
|
||||
21
apps/BuildWidget/res/xml/widget_build.xml
Normal file
21
apps/BuildWidget/res/xml/widget_build.xml
Normal file
@@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (C) 2009 The Android Open Source Project
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
|
||||
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:minWidth="150dip"
|
||||
android:minHeight="72dip"
|
||||
android:updatePeriodMillis="0"
|
||||
android:initialLayout="@layout/widget" />
|
||||
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* Copyright (C) 2009 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.buildwidget;
|
||||
|
||||
import android.app.PendingIntent;
|
||||
import android.app.Service;
|
||||
import android.appwidget.AppWidgetManager;
|
||||
import android.appwidget.AppWidgetProvider;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.res.Resources;
|
||||
import android.net.Uri;
|
||||
import android.os.IBinder;
|
||||
import android.text.format.Time;
|
||||
import android.util.Log;
|
||||
import android.widget.RemoteViews;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* Define a simple widget that shows the Wiktionary "Word of the day." To build
|
||||
* an update we spawn a background {@link Service} to perform the API queries.
|
||||
*/
|
||||
public class BuildWidget extends AppWidgetProvider {
|
||||
@Override
|
||||
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
|
||||
int[] appWidgetIds) {
|
||||
// To prevent any ANR timeouts, we perform the update in a service
|
||||
context.startService(new Intent(context, UpdateService.class));
|
||||
}
|
||||
|
||||
public static class UpdateService extends Service {
|
||||
@Override
|
||||
public void onStart(Intent intent, int startId) {
|
||||
// Build the widget update
|
||||
RemoteViews updateViews = buildUpdate(this);
|
||||
|
||||
// Push update for this widget to the home screen
|
||||
ComponentName thisWidget = new ComponentName(this, BuildWidget.class);
|
||||
AppWidgetManager manager = AppWidgetManager.getInstance(this);
|
||||
manager.updateAppWidget(thisWidget, updateViews);
|
||||
}
|
||||
|
||||
public RemoteViews buildUpdate(Context context) {
|
||||
// Pick out month names from resources
|
||||
Resources res = context.getResources();
|
||||
RemoteViews updateViews = new RemoteViews(
|
||||
context.getPackageName(), R.layout.widget);
|
||||
|
||||
PendingIntent pendingIntent = PendingIntent.getActivity(context,
|
||||
0 /* no requestCode */,
|
||||
new Intent(android.provider.Settings.ACTION_DEVICE_INFO_SETTINGS),
|
||||
0 /* no flags */);
|
||||
updateViews.setOnClickPendingIntent(R.id.widget, pendingIntent);
|
||||
|
||||
updateViews.setTextViewText(R.id.build_info,
|
||||
android.os.Build.VERSION.CODENAME + " " +
|
||||
android.os.Build.ID);
|
||||
updateViews.setTextViewText(R.id.build_changelist,
|
||||
android.os.Build.FINGERPRINT
|
||||
);
|
||||
return updateViews;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBinder onBind(Intent intent) {
|
||||
// We don't need to bind to this service
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user