Football Fans: Download the 2012 Schedule App from Google Play!


Go Back   Android Forums > Android Development > Application Development

Application Development Dev Lounge for the Coder Folks



Reply
 
LinkBack Thread Tools
Old October 5th, 2011, 04:54 AM   #1 (permalink)
New Member
 
Join Date: Oct 2011
Posts: 6
 
Device(s):
Thanks: 0
Thanked 0 Times in 0 Posts
Red face Newbie help with Clocks in Eclipse, please read!

Hi there, I am in desperate need of some seasoned help. I started working on this about a month ago and have hit a brick wall. I have been following the tutorial at Tutorial – Creating a Custom Analog Clock Widget and have turned it into a pretty nice analog clock, but now I want to add a box inside the design that has a digital readout of the time and date, but everytime I try to in the layout and the test the app, it gives me an error. I know it is probably something simple, but I am not to good at this kind of stuff. Please, if anybody can help, I would really appreciate it. I have been reading through these threads and I have seen that many newbie questions go unread and especially unanswered and I am sort of hoping that somebody can take a few minutes to help me out. Who knows, maybe it can help somebody else out in the future.

I am enclosing a zip file of my workspace folder from eclipse. If you want to take a look at my files and then let me know what I need to do to add this I would be so appreciative. Thanks again.
Attached Files
File Type: zip AnalogClockWidget.zip (402.5 KB, 7 views)

johnperry9 is offline  
Reply With Quote
Sponsors
Old October 5th, 2011, 11:15 PM   #2 (permalink)
New Member
 
Join Date: Oct 2011
Posts: 6
 
Device(s):
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Please does anybody have any suggestions?? ANYTHING at all would be so greatly appreciated for a really embarrassed and frustrated newbie, lol. Thanks again.
johnperry9 is offline  
Reply With Quote
Old October 9th, 2011, 07:54 AM   #3 (permalink)
Developer
 
stevealbright's Avatar
 
Join Date: Apr 2011
Location: York, PA
Posts: 130
 
Device(s): Samsung Galaxy Nexus, HTC Thunderbolt, HTC Incredible, HTC Eris
Thanks: 97
Thanked 178 Times in 71 Posts
steve.albright@gmail.com
Default

Could you post the code snippet of what your having issues with? Also... post what errors you are getting the console. If you provide this we can help you a little better. Thanks!
stevealbright is online now  
Reply With Quote
Old October 12th, 2011, 01:15 AM   #4 (permalink)
New Member
 
Join Date: Oct 2011
Posts: 6
 
Device(s):
Thanks: 0
Thanked 0 Times in 0 Posts
Default Thank you!!! Thank you!!!

Ok, I am so very thankful to you for offering to help. Here is what I am doing. I am taking the files that you have already seen and loading them into Eclipse. Then I opened the res/layout/widget.xml file. I then loaded up the "Graphical Layout" view and then dragged the "DigitalClock" option on top of my background.

Enclosed is a screenshot of the graphical layout view

The snippit looks like this:
Code:
<?xmlversion="1.0"encoding="utf-8"?>
<RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:id="@+id/Widget"android:layout_width="fill_parent"android:layout_height="fill_parent"android:gravity="center"> 
<AnalogClockandroid:id="@+id/AnalogClock"android:layout_width="wrap_content"android:layout_height="wrap_content"android:dial="@drawable/widgetdial"android:hand_hour="@drawable/widgethour"android:hand_minute="@drawable/widgetminute"/>

<DigitalClockandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:id="@+id/digitalClock1"android:text="DigitalClock"android:layout_alignBottom="@+id/AnalogClock"android:layout_centerHorizontal="true"android:layout_marginBottom="101dp"></DigitalClock>
</RelativeLayout>
Then when I try to test my app it shows a grayed box wherever I put the widget on the homescreen and it says "Problem loading widget." If I go back into Eclipse and remove the DigitalClock part and then retest the widget it loads fine.



Once again, thank you for taking the time to help me. I can't say thank you enough.

The only other issue I am having is, it is supposedly able to launch the alarmclock features when you click on the widget on the homescreen. It works on version 1.6 but if I test the widget on 2.3 or something like that it doesn't do anything when you press the clock??

Thanks again for everything.
Attached Images
File Type: jpg screen1.jpg (67.1 KB, 3 views)
johnperry9 is offline  
Last edited by stevealbright; October 12th, 2011 at 10:37 PM. Reason: Fixed formatting by adding code brakets.
Reply With Quote
Old October 12th, 2011, 11:01 AM   #5 (permalink)
New Member
 
Join Date: Oct 2011
Posts: 6
 
Device(s):
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I will tell you what I don't have much but I am so desperate if somebody can help me and use my files and then get me the eclipse project files with this working I will pay you. I need the working very quickly and it seems like there is a shortness of people offering advice. Please this is so very important. All I need is to make it so that I have "digital" readout of the time on top of my analog clock and maybe the same thing with the date and then also when you touch the clock the alarm program opens up where it works with all versions of the android software. Right now it ONLY works if I test it on version 1.6 but nothing later.

Please I am SO VERY desperate for help. Please do the right thing and offer a helping hand. Its like that Pay It Forward.
johnperry9 is offline  
Reply With Quote
Old October 13th, 2011, 01:04 AM   #6 (permalink)
Developer
 
stevealbright's Avatar
 
Join Date: Apr 2011
Location: York, PA
Posts: 130
 
Device(s): Samsung Galaxy Nexus, HTC Thunderbolt, HTC Incredible, HTC Eris
Thanks: 97
Thanked 178 Times in 71 Posts
steve.albright@gmail.com
Default

Ok..so where do I start... ha.

First, you need to read this: Android Doc Link

For anyone too lazy to click and read, it basically stats which layouts and views you can use with App Widgets.

The reason your project does not work as intended is simply it is not supported by the SDK.


Solution?


You will first need to remove the DigitalClock from the layout. This WILL NOT EVER work. Replace this with an ImageView like the following:

Code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/widget"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_gravity="center">

    <AnalogClock android:id="@+id/AnalogClock"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:dial="@drawable/widgetdial"
        android:hand_hour="@drawable/widgethour"
        android:hand_minute="@drawable/widgetminute"/>

    <ImageView
      android:id="@+id/digitalclock"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
        />

</RelativeLayout>
Get system time
Code:
long epoch = System.currentTimeMillis()/1000;
time = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss").format(new Date(epoch*1000));
Use the buildUpdate function to create a image based on the time
Code:
RemoteViews views = new RemoteViews(getPackageName(), R.layout.widget);
views.setImageViewBitmap(R.id.digitalclock, buildUpdate(time));
Function used above (I even attached the font for you where you can drop it right into the asset folder)
Code:
public Bitmap buildUpdate(String time) 
    {
    Bitmap myBitmap = Bitmap.createBitmap(160, 84, Bitmap.Config.ARGB_4444);
    Canvas myCanvas = new Canvas(myBitmap);
    Paint paint = new Paint();
    Typeface clock = Typeface.createFromAsset(this.getAssets(),"Clockopia.ttf");
    paint.setAntiAlias(true);
    paint.setSubpixelText(true);
    paint.setTypeface(clock);
    paint.setStyle(Paint.Style.FILL);
    paint.setColor(Color.WHITE);
    paint.setTextSize(65);
    paint.setTextAlign(Align.CENTER);
    myCanvas.drawText(time, 80, 60, paint);
    return myBitmap;
    }
Now this is NOT the complete answer. What is left is you need to create a service that will update the time. This is a little more complex then just using a AnalogClock so I will let you look up how you can create a service. Most likely you will need to use the @Override(s) onEnabled and onDisabled of the AppWidgetProvider. So when the widget starts... the service starts. Then use the @Override for onUpdate of the AppWidgetProvider which should then tricker an intent to tell the service to get an updated time and recreate the image.

I hope this helps you out and I am sorry I can not just provide a quick solution for you. Maybe some others can shed some insite or if anyone has created a service like this already could share with the community.

Good Luck!

Steve
Attached Files
File Type: zip Clockopia.ttf.zip (4.3 KB, 4 views)
stevealbright is online now  
Last edited by stevealbright; October 13th, 2011 at 01:06 AM. Reason: added font attachment
Reply With Quote
Reply

Bookmarks

Tags
analog clock, android, digital clock widget, eclipse


Go Back   Android Forums > Android Development > Application Development User CP
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -5. The time now is 11:48 AM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
Custom vBulletin Skins by: Relivo