Click here to Skip to main content
15,884,472 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
ASM
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:


HTML
<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" >



    <receiver android:name=".Clock_ActionsC" android:icon="@drawable/cicon" android:label="JB White">
        <intent-filter>
            <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
        </intent-filter>
        <meta-data android:name="android.appwidget.provider"
            android:previewImage="@drawable/cpreview_white" 
            android:resource="@xml/cwidget_config" />
    </receiver>
    <receiver android:name=".Clock_ActionsC_BL" android:icon="@drawable/cblicon" android:label="JB Black">
        <intent-filter>
            <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
        </intent-filter>
        <meta-data android:name="android.appwidget.provider"
            android:previewImage="@drawable/cpreview_black" 
            android:resource="@xml/cblwidget_config" />
    </receiver>
    <receiver android:name=".Clock_ActionsC_B" android:icon="@drawable/cbicon" android:label="JB Blue">
        <intent-filter>
            <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
        </intent-filter>
        <meta-data android:name="android.appwidget.provider"
            android:previewImage="@drawable/cpreview_blue" 
            android:resource="@xml/cbwidget_config" />
    </receiver>
    <receiver android:name=".Clock_ActionsC_R" android:icon="@drawable/cricon" android:label="JB Red">
        <intent-filter>
            <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
        </intent-filter>
        <meta-data android:name="android.appwidget.provider"
            android:previewImage="@drawable/cpreview_red" 
            android:resource="@xml/crwidget_config" />
    </receiver>
    <receiver android:name=".Clock_ActionsC_P" android:icon="@drawable/cpicon" android:label="JB Pink">
        <intent-filter>
            <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
        </intent-filter>
        <meta-data android:name="android.appwidget.provider"
            android:previewImage="@drawable/cpreview_pink" 
            android:resource="@xml/cpwidget_config" />
    </receiver>
    <receiver android:name=".Clock_ActionsC_G" android:icon="@drawable/cgicon" android:label="JB Green">
        <intent-filter>
            <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
        </intent-filter>
        <meta-data android:name="android.appwidget.provider"
            android:previewImage="@drawable/cpreview_green" 
            android:resource="@xml/cgwidget_config" />
    </receiver>
    <receiver android:name=".Clock_ActionsC_Y" android:icon="@drawable/cyicon" android:label="JB Yellow">
        <intent-filter>
            <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
        </intent-filter>
        <meta-data android:name="android.appwidget.provider"
            android:previewImage="@drawable/cpreview_yellow" 
            android:resource="@xml/cywidget_config" />
    </receiver>
</application>


And this the .class for the BLUE Clock:

Java
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))
    {

        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 < 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
Updated 4-May-13 20:07pm
v2

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900