Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Android
I have spent almost 10 days searching for a tutorial or any help describing how to add a color picker to my Clock Widget.
 
My widget is a simple clock with 7 colors, but I want to make it completely usable free. "the user chooses what color he/she like", "the clock, NOT the background".
 
Could you please direct me and help me to find the way to make it like that?
 
Manifest:
 
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.koshmen.clock.aimen"
android:versionCode="3"
android:versionName="1.2" >
 
<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="16" />
 
<supports-screens
    android:anyDensity="true"
    android:largeScreens="true"
    android:normalScreens="true"
    android:resizeable="true"
    android:smallScreens="true"
    android:xlargeScreens="true" />
 
<application
    android:allowBackup="true"
    android:icon="@drawable/appicon"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
 
<pre>
&lt;receiver android:name=".Clock_ActionsC" android:icon="@drawable/cicon" android:label="JB White"&gt;
    &lt;intent-filter&gt;
        &lt;action android:name="android.appwidget.action.APPWIDGET_UPDATE" /&gt;
    &lt;/intent-filter&gt;
    &lt;meta-data android:name="android.appwidget.provider"
        android:previewImage="@drawable/cpreview_white" 
        android:resource="@xml/cwidget_config" /&gt;
&lt;/receiver&gt;
&lt;receiver android:name=".Clock_ActionsC_BL" android:icon="@drawable/cblicon" android:label="JB Black"&gt;
    &lt;intent-filter&gt;
        &lt;action android:name="android.appwidget.action.APPWIDGET_UPDATE" /&gt;
    &lt;/intent-filter&gt;
    &lt;meta-data android:name="android.appwidget.provider"
        android:previewImage="@drawable/cpreview_black" 
        android:resource="@xml/cblwidget_config" /&gt;
&lt;/receiver&gt;
&lt;receiver android:name=".Clock_ActionsC_B" android:icon="@drawable/cbicon" android:label="JB Blue"&gt;
    &lt;intent-filter&gt;
        &lt;action android:name="android.appwidget.action.APPWIDGET_UPDATE" /&gt;
    &lt;/intent-filter&gt;
    &lt;meta-data android:name="android.appwidget.provider"
        android:previewImage="@drawable/cpreview_blue" 
        android:resource="@xml/cbwidget_config" /&gt;
&lt;/receiver&gt;
&lt;receiver android:name=".Clock_ActionsC_R" android:icon="@drawable/cricon" android:label="JB Red"&gt;
    &lt;intent-filter&gt;
        &lt;action android:name="android.appwidget.action.APPWIDGET_UPDATE" /&gt;
    &lt;/intent-filter&gt;
    &lt;meta-data android:name="android.appwidget.provider"
        android:previewImage="@drawable/cpreview_red" 
        android:resource="@xml/crwidget_config" /&gt;
&lt;/receiver&gt;
&lt;receiver android:name=".Clock_ActionsC_P" android:icon="@drawable/cpicon" android:label="JB Pink"&gt;
    &lt;intent-filter&gt;
        &lt;action android:name="android.appwidget.action.APPWIDGET_UPDATE" /&gt;
    &lt;/intent-filter&gt;
    &lt;meta-data android:name="android.appwidget.provider"
        android:previewImage="@drawable/cpreview_pink" 
        android:resource="@xml/cpwidget_config" /&gt;
&lt;/receiver&gt;
&lt;receiver android:name=".Clock_ActionsC_G" android:icon="@drawable/cgicon" android:label="JB Green"&gt;
    &lt;intent-filter&gt;
        &lt;action android:name="android.appwidget.action.APPWIDGET_UPDATE" /&gt;
    &lt;/intent-filter&gt;
    &lt;meta-data android:name="android.appwidget.provider"
        android:previewImage="@drawable/cpreview_green" 
        android:resource="@xml/cgwidget_config" /&gt;
&lt;/receiver&gt;
&lt;receiver android:name=".Clock_ActionsC_Y" android:icon="@drawable/cyicon" android:label="JB Yellow"&gt;
    &lt;intent-filter&gt;
        &lt;action android:name="android.appwidget.action.APPWIDGET_UPDATE" /&gt;
    &lt;/intent-filter&gt;
    &lt;meta-data android:name="android.appwidget.provider"
        android:previewImage="@drawable/cpreview_yellow" 
        android:resource="@xml/cywidget_config" /&gt;
&lt;/receiver&gt;

</application>
And this the .class for the BLUE Clock:
 
public class Clock_ActionsC_B extends AppWidgetProvider{
 
public void onReceive(Context context, Intent intent)
{
    String action = intent.getAction();
    PendingIntent pendingIntent;
    if (AppWidgetManager.ACTION_APPWIDGET_UPDATE.equals(action))
    {
 
<pre>
    RemoteViews views = new RemoteViews(context.getPackageName(),
            R.layout.cbmain);
 
    pendingIntent = PendingIntent.getActivity(context, 0,getAlarmPackage(context), 0);
    views.setOnClickPendingIntent(R.id.analogClock1, pendingIntent);
 
    AppWidgetManager
            .getInstance(context)
            .updateAppWidget(
                    intent.getIntArrayExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS),
                    views);
}

}

public Intent getAlarmPackage(Context context)
{
PackageManager packageManager = context.getPackageManager();
Intent AlarmClockIntent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_LAUNCHER);
 
String clockImpls[][] = {
        { "Standard Alarm", "com.android.alarmclock",
                "com.android.alarmclock.AlarmClock" },
        { "HTC Alarm ClockDT", "com.htc.android.worldclock",
                "com.htc.android.worldclock.WorldClockTabControl" },
        { "Standard Alarm ClockDT", "com.android.deskclock",
                "com.android.deskclock.AlarmClock" },
        { "Froyo Nexus Alarm ClockDT",
                "com.google.android.deskclock",
                "com.android.deskclock.DeskClock" },
        { "Moto Blur Alarm ClockDT",
                "com.motorola.blur.alarmclock",
                "com.motorola.blur.alarmclock.AlarmClock" },
        { "Samsung Galaxy S", "com.sec.android.app.clockpackage",
                "com.sec.android.app.clockpackage.ClockPackage" } };
 
boolean foundClockImpl = false;
 
for (int i = 0; i &lt; clockImpls.length; i++)
{
    String packageName = clockImpls[i][1];
    String className = clockImpls[i][2];
    try
    {
        ComponentName cn = new ComponentName(packageName, className);
        packageManager.getActivityInfo(cn,PackageManager.GET_META_DATA);
        AlarmClockIntent.setComponent(cn);
        foundClockImpl = true;
    } catch (NameNotFoundException nf)
    {
    }
}
if (foundClockImpl)
{
    return AlarmClockIntent;
}
else
{
    return null;
}

}
This tutorial http://wptrafficanalyzer.in/blog/android-home-screen-app-widget-with-onclick-event/[^] was a perfect for me, BUT I could't change "I didn't know" how to make it change the clock color it self, NOT the background of that clock.
Posted 4-May-13 21:05pm
Edited 4-May-13 21:07pm
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 490
1 Sergey Alexandrovich Kryukov 395
2 Maciej Los 285
3 ProgramFOX 265
4 CHill60 200
0 OriginalGriff 490
1 Sergey Alexandrovich Kryukov 395
2 Maciej Los 285
3 ProgramFOX 265
4 CHill60 200


Advertise | Privacy | Mobile
Web02 | 2.8.150331.1 | Last Updated 5 May 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100