Android的世界时钟小工具模拟 [英] Android-World Clock Widget analog

查看:125
本文介绍了Android的世界时钟小工具模拟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我打算创造机器人的世界时钟部件。时钟应显示所选国家的时间,模拟时钟部件。但我感觉困难,因为我在android系统是一个初学者。

I am planning to create a world clock widget in android. The clock should show the selected country's time as an analog clock widget. But I'm feeling difficulties as I'm a beginner in android.

我widget.xml文件包含以下内容: -

My widget.xml file contains the following:-

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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_margin="8dip"
  android:background="@drawable/myshape" >
<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"/>

我使用我的插件的配置如下活动: -
(要显示的城市名单)
包nEx.Software.Tutorials.Widgets.AnalogClock;

I am using the following configuration activity for my widget:- (To display the city list) package nEx.Software.Tutorials.Widgets.AnalogClock;

import java.io.BufferedReader;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Calendar;
import android.app.Activity;
import android.app.PendingIntent;
import android.app.ProgressDialog;
import android.appwidget.AppWidgetManager;
import android.content.Intent;
import android.os.Bundle;
import android.content.Context;
import android.content.SharedPreferences;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.widget.AdapterView;
import android.widget.AnalogClock;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RemoteViews;
import android.widget.TextView;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
public class ConfigureApp extends Activity {
DateFormat df;
 private ListView cityList;

    public static String[][] citylist = new String[1242][10];
    String[] cities = new String[1242];
    String field[] = new String[20];
    String list[][] = new String[1242][10];                         
    String country = "";
    String line = null;
    int row = 0;
    int col = 0;

    // Variables for list view population
    String city = "";
    int position = 0;
    public int[] listArray = new int[1242];
    public static int len = 0;
    public String[][] adapterCityList = new String[1242][3];
    // Variables for passing intent data 
    public static final String citieslist = "com.world.citieslist";
   AppWidgetManager awm;
   Context c;
   int awID;

    @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);

        // Set the result to CANCELED.  This will cause the widget host to cancel
        // out of the widget placement if they press the back button.
        setResult(RESULT_CANCELED);
          try {
              citylist = getCityList();
          } catch (IOException e) {
              Log.e("Loading CityList", e.getMessage());
          }

          for (int i = 0; i < 1242; i++) {
              cities[i] = citylist[i][0];
          }
        // Set the view layout resource to use.
        setContentView(R.layout.configure);
    c = ConfigureApp.this;
    Intent intent = getIntent();
    Bundle extras = intent.getExtras();
    if (extras != null) {
          awID = extras.getInt(
        AppWidgetManager.EXTRA_APPWIDGET_ID, 
        AppWidgetManager.INVALID_APPWIDGET_ID);
   } else{
finish();
}

awm = AppWidgetManager.getInstance(c);



        cityList=(ListView)findViewById(R.id.CityList);
     // By using setAdpater method in listview we an add string array in list.
     cityList.setAdapter(new ArrayAdapter<String> (this,android.R.layout.simple_list_item_1, cities));
    // cityList.setOnItemClickListener(cityListListener);
          cityList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            public void onItemClick(AdapterView<?> av, View v, int pos, long id) {
                df = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
                  String str = ((TextView) v).getText().toString();

                  RemoteViews remoteViews = new RemoteViews(c.getPackageName(),
                        R.layout.widget);
                remoteViews.setTextViewText(R.id.mytext, str);
                remoteViews.setTextViewText(R.id.date, df.format(new Date()));
                 Intent in = new Intent(c,clock.class);

                PendingIntent pi = PendingIntent.getActivity(c, 0, in, 0);
                remoteViews.setOnClickPendingIntent(R.id.Widget, pi);
                                    awm.updateAppWidget(awID, remoteViews);
                    Intent result = new Intent();
                result.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID,awID);
                setResult(RESULT_OK, result);
                finish();

            }
        });
    }           
    private String[][] getCityList() throws IOException {
        Context context = getApplicationContext();

        InputStream instream = context.getResources().openRawResource(R.raw.cities_final);

        // if file the available for reading
        if (instream != null) {

            // prepare the file for reading
            InputStreamReader inputreader = new InputStreamReader(instream);
            BufferedReader buffreader = new BufferedReader(inputreader);

            while ((line = buffreader.readLine()) != null) {

                field = line.split(",");
                for (String x : field) {
                    list[row][col] = x;
                    col++;
                    if (x != null) {
                        country = x;
                    }
                }
                list[row][2] = country;
                row++;
                col = 0;
            }

            for (int i = 0; (i < list.length); i++) {
                for (int j = 0; (j < 3); j++) {
                    if (j == 1) {
                        list[i][j] = list[i][j].substring(0, 6);
                    }
                }
            }
        }
        return list;
    }       

}

我可以用我自己的自定义视图中的部件,除了模拟时钟?或者有没有其他的方式来显示时钟?象使用的ImageView作为时钟面和根据时间绘制拨盘?

Can I use my own custom view in the widget, apart from analog clock? Or is there any other way to show the clock? like use the Imageview as the clock face and to draw the dial according to the time?

请帮我对此!!!:(

推荐答案

可以更换时钟表盘,时钟分针和时钟指针小时与自己的图纸。然后,你有你自己的定制时钟。

You can replaced the clock dial, clock hand minute and clock hand hour with your own drawings. Then You'll have your own custom clock.

 android:dial="@drawable/YOUR_OWN_DIAL" 
 android:hand_hour="@drawable/YOUR_OWN_HOUR"
 android:hand_minute="@drawable/YOUR_OWN_MINUTE"

在测试图形布局工具的布局,看看它的样子。

Test the layout in the Graphical Layout Tool to see how it look like.

这篇关于Android的世界时钟小工具模拟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆