Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7815873
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T05:39:51+00:00 2026-06-02T05:39:51+00:00

Actually I have to make a analog clock widget showing world’s time after selecting

  • 0

Actually I have to make a analog clock widget showing world’s time after selecting the particular time zone. I have created a analog clock with
option of selecting the time zones.I want that the same clock with updated time zone should be displayed as a widget.I am not getting how to bring only the clock view as a widget.

My code is:

package nEx.Software.Tutorials.Widgets.AnalogClock;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.TimeZone;
import java.util.Timer;
import java.util.TimerTask;
//import nEx.Software.Tutorials.Widgets.AnalogClock.main.CustomClock;
//import nEx.Software.Tutorials.Widgets.AnalogClock.main.MyTime;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
public class Info extends Activity implements RadioGroup.OnCheckedChangeListener
{

     Context context;
        TextView tv;
        RadioButton rb1, rb2, rb3;
        RadioGroup r1;
        FrameLayout fl1;
        LinearLayout l1;
        Timer timer;
        Date result;
        ViewGroup.LayoutParams lp1;
        Drawable bck;
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState); setContentView(R.layout.main);

        context = this;
        tv = (TextView) findViewById(R.id.TextView01);
        r1 = (RadioGroup) findViewById(R.id.RadioGroup01);
        rb1 = (RadioButton) findViewById(R.id.RadioButton01);
        rb2 = (RadioButton) findViewById(R.id.RadioButton02);
        rb3 = (RadioButton) findViewById(R.id.RadioButton03);
        fl1 = (FrameLayout) findViewById(R.id.FrameLayout01);
        bck = this.getResources().getDrawable(R.drawable.clockface);
         fl1.setBackgroundDrawable(bck);
        lp1 = fl1.getLayoutParams();
        r1.setOnCheckedChangeListener(this);
        result = null;
    }
    private void updateTime(String str) {
        // TODO Auto-generated method stub
        if (timer != null) {
            timer.cancel();
            timer = null;
        }
        timer = new Timer();        //digital clock
        MyTime mt = new MyTime(this, str);
        timer.schedule(mt, 1, 1000);
    }
    public void onCheckedChanged(RadioGroup group, int checkedId) {
        // TODO Auto-generated method stub
        if (rb1.isChecked() == true) {
            updateTime("GMT");

        }
        if (rb2.isChecked() == true) {
            updateTime("EST");
        }
        if (rb3.isChecked() == true) {
            updateTime("MST");
        }
    }
    public class MyTime extends TimerTask {
        String tz;
        public MyTime(Context context, String str) {
            tz = str;
        }
        @Override
        public void run() {
            // TODO Auto-generated method stub
            try {
                Date date = new Date();
                date = getDateInTimeZone(date, tz);
                //System.out.println(date.toLocaleString());
                result = date;
                handler.sendEmptyMessage(0);
            } catch (Exception e) {
            }
        }
        private Date getDateInTimeZone(Date currentDate, String timeZoneId) {
            TimeZone tz = TimeZone.getTimeZone(timeZoneId);
            Calendar mbCal = new GregorianCalendar(tz);
            mbCal.setTimeInMillis(currentDate.getTime());
            Calendar cal = Calendar.getInstance();
            cal.set(Calendar.YEAR, mbCal.get(Calendar.YEAR));
            cal.set(Calendar.MONTH, mbCal.get(Calendar.MONTH));
            cal.set(Calendar.DAY_OF_MONTH, mbCal.get(Calendar.DAY_OF_MONTH));
            cal.set(Calendar.HOUR_OF_DAY, mbCal.get(Calendar.HOUR_OF_DAY));
            cal.set(Calendar.MINUTE, mbCal.get(Calendar.MINUTE));
            cal.set(Calendar.SECOND, mbCal.get(Calendar.SECOND));
            cal.set(Calendar.MILLISECOND, mbCal.get(Calendar.MILLISECOND));
            return cal.getTime();
        }
    }
    Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            tv.setText(result.toLocaleString());
            //System.out.println(result.getHours()+" "+result.getMinutes());
            fl1.removeAllViews();
            fl1.addView(new CustomClock(context, lp1.height / 2, lp1.width / 2, result));
        }
    };
    public class CustomClock extends View {
        private final float x;
        private final float y;
        private final int r = 70;
        private final Date date;
        private final Paint mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
        public CustomClock(Context context, float x, float y, Date date) {
            super(context);
            this.x = x;
            this.y = y;
            this.date = date;
        }
        @Override
        protected void onDraw(Canvas canvas) {
            super.onDraw(canvas);
            //canvas.drawCircle(x, y, r, mPaint);
            float sec = (float) date.getSeconds();
            float min = (float) date.getMinutes();
            float hour = (float) date.getHours() + min / 60.0f;
            mPaint.setColor(0xFFFF0000);
            canvas.drawLine(x, y, (float) (x + (r - 15) * Math.cos(Math.toRadians((hour / 12.0f * 360.0f) - 90f))), (float) (y + (r - 10) * Math.sin(Math.toRadians((hour / 12.0f * 360.0f) - 90f))), mPaint);
            canvas.save();
            mPaint.setColor(0xFF0000FF);
            canvas.drawLine(x, y, (float) (x + r * Math.cos(Math.toRadians((min / 60.0f * 360.0f) - 90f))), (float) (y + r * Math.sin(Math.toRadians((min / 60.0f * 360.0f) - 90f))), mPaint);
            canvas.save();
            mPaint.setColor(0xFFA2BC13);
            canvas.drawLine(x, y, (float) (x + (r + 10) * Math.cos(Math.toRadians((sec / 60.0f * 360.0f) - 90f))), (float) (y + (r + 15) * Math.sin(Math.toRadians((sec / 60.0f * 360.0f) - 90f))), mPaint);
        }
    }
//}
  //  }


}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T05:39:53+00:00Added an answer on June 2, 2026 at 5:39 am

    app widgets are quite limited to a few views called “remote views” . even they are not so flexible .
    the reason behind this decision is probably security . you would have to get a workaround for this problem , since you cannot create your own customized view as an appwidget .
    here’s a list of all of the available remote views:
    http://developer.android.com/guide/topics/appwidgets/index.html#CreatingLayout

    you can use their analog clock if you wish.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I make the problem shorter. Actually I have data much longer than this. I
Anyone have any experience yet getting Radiant CMS extensions to actually make it onto
How to use array( Varray) in store procedure. Actually,i have make a stored procedure
I actually have right now two questions: 1) What font faces are preferred for
I actually have two questions regarding exception/error handling in the iPhone app that I
I actually have 2 queries: How do I display the data of a variable
I actually have two questions, the on in the title being the main one.
I actually have some questions (real childish). 1) If I know that a website
This is a minimal test case of some code that I actually have. It
I started to use Borland's Turbo C++ a few days ago. I actually have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.