/*
* To change this template, choose Tools | Templates
* && open the template in the editor.
*/
package com.packtpub.roboticreview;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Calendar;
import android.app.TabActivity;
import android.app.TimePickerDialog;
import android.app.DatePickerDialog;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.SeekBar;
import android.widget.TabHost;
import android.widget.Gallery;
import android.widget.TextView;
import android.widget.ImageView;
import android.widget.DatePicker;
import android.widget.TimePicker;
import android.widget.AdapterView;
import android.widget.TextSwitcher;
import android.widget.ViewSwitcher;
/**
*
* @author Jason Morris
*/
public class ReviewActivity extends TabActivity
implements ViewSwitcher.ViewFactory,
Runnable,
AdapterView.OnItemSelectedListener,
SeekBar.OnSeekBarChangeListener,
View.OnClickListener,
DatePickerDialog.OnDateSetListener,
TimePickerDialog.OnTimeSetListener {
// the "review" tab fields
private final Handler switchCommentHandler = new Handler();
private String[] comments;
private int commentIndex = 0;
private TextSwitcher switcher;
// the "photos" tab fields
private ImageView photo;
// the "reservation" tab fields
private String peopleLabelFormat;
private TextView peopleLabel;
private SimpleDateFormat dateFormat;
private Button date;
private SimpleDateFormat timeFormat;
private Button time;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
createTabs();
}
private void initReveiwTab() {
comments = getResources().getStringArray(R.array.comments);
switcher = (TextSwitcher)findViewById(R.id.reviews);
switcher.setFactory(this);
}
private void initGalleryTab() {
photo = ((ImageView)findViewById(R.id.photo));
final Gallery photos = ((Gallery)findViewById(R.id.gallery));
photos.setAdapter(new GalleryAdapter());
photos.setOnItemSelectedListener(this);
}
private void initReservationTab() {
peopleLabel = (TextView)findViewById(R.id.people_label);
peopleLabelFormat = peopleLabel.getText().toString();
date = (Button)findViewById(R.id.date);
dateFormat = new SimpleDateFormat(date.getText().toString());
time = (Button)findViewById(R.id.time);
timeFormat = new SimpleDateFormat(time.getText().toString());
final Calendar calendar = Calendar.getInstance();
if(calendar.get(Calendar.HOUR_OF_DAY) >= 16) {
calendar.add(Calendar.DATE, 1);
}
calendar.set(Calendar.HOUR_OF_DAY, 18);
calendar.clear(Calendar.MINUTE);
calendar.clear(Calendar.SECOND);
calendar.clear(Calendar.MILLISECOND);
final Date reservationDate = calendar.getTime();
date.setText(dateFormat.format(reservationDate));
time.setText(timeFormat.format(reservationDate));
date.setOnClickListener(this);
time.setOnClickListener(this);
final SeekBar people = (SeekBar)findViewById(R.id.people);
people.setOnSeekBarChangeListener(this);
peopleLabel.setText(String.format(
peopleLabelFormat,
people.getProgress() + 1));
}
private TabHost.TabSpec createTabSpec(
final TabHost host,
final String tag,
final int content,
final int textString,
final int icon) {
return host.newTabSpec(tag).
setContent(content).
setIndicator(
getString(textString),
getResources().getDrawable(icon));
}
private Calendar parseCalendar(
final CharSequence text,
final SimpleDateFormat format) {
try {
final Date parsedDate = format.parse(text.toString());
final Calendar calendar = Calendar.getInstance();
calendar.setTime(parsedDate);
return calendar;
} catch(final ParseException pe) {
Log.e("DateParse", "Couldn't parse date: " + text, pe);
throw new RuntimeException(pe);
}
}
private void createTabs() {
final TabHost tabs = getTabHost();
getLayoutInflater().inflate(
R.layout.main,
tabs.getTabContentView(),
true);
tabs.addTab(createTabSpec(
tabs,
"review",
R.id.review,
R.string.review,
R.drawable.review));
tabs.addTab(createTabSpec(
tabs,
"photos",
R.id.photos,
R.string.gallery,
R.drawable.photos));
tabs.addTab(createTabSpec(
tabs,
"reservation",
R.id.reservation,
R.string.reservation,
R.drawable.reservation));
initReveiwTab();
initGalleryTab();
initReservationTab();
}
@Override
protected void onStart() {
super.onStart();
switchCommentHandler.postDelayed(this, 5 * 1000l);
}
@Override
protected void onStop() {
super.onStop();
switchCommentHandler.removeCallbacks(this);
}
public View makeView() {
return getLayoutInflater().inflate(R.layout.review_comment, null);
}
public void run() {
try {
if(switcher != null) {
switcher.setText(comments[commentIndex++]);
if(commentIndex >= comments.length) {
commentIndex = 0;
}
}
} finally {
switchCommentHandler.postDelayed(this, 5 * 1000l);
}
}
public void onItemSelected(
final AdapterView<?> parent,
final View view,
final int index,
final long id) {
photo.setImageResource((int)id);
}
public void onNothingSelected(final AdapterView<?> view) {
// ignore this
}
public void onProgressChanged(
final SeekBar bar,
final int progress,
final boolean fromUser) {
peopleLabel.setText(String.format(peopleLabelFormat, progress + 1));
}
public void onStartTrackingTouch(final SeekBar bar) {
}
public void onStopTrackingTouch(final SeekBar bar) {
}
public void onClick(final View view) {
if(view == date) {
final Calendar calendar = parseCalendar(
date.getText(),
dateFormat);
new DatePickerDialog(
this,
this,
calendar.get(Calendar.YEAR),
calendar.get(Calendar.MONTH),
calendar.get(Calendar.DAY_OF_MONTH)).show();
} else if(view == time) {
final Calendar calendar = parseCalendar(
time.getText(),
timeFormat);
new TimePickerDialog(
this,
this,
calendar.get(Calendar.HOUR_OF_DAY),
calendar.get(Calendar.MINUTE),
false).show();
}
}
public void onDateSet(
final DatePicker picker,
final int year,
final int month,
final int day) {
final Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.YEAR, year);
calendar.set(Calendar.MONTH, month);
calendar.set(Calendar.DAY_OF_MONTH, day);
date.setText(dateFormat.format(calendar.getTime()));
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
Android User Interface Development: Beginner's Guide 源代码 Jason Morris (Author) Publisher: Packt Publishing (March 10, 2011) Language: English 学习android就是要多看源代码,这本书的代码相信对刚学android很有帮助
资源推荐
资源详情
资源评论
收起资源包目录
Android User Interface Development: Beginner's Guide 源代码 (195个子文件)
proguard.cfg 1KB
proguard.cfg 1KB
proguard.cfg 1KB
proguard.cfg 1KB
proguard.cfg 1KB
proguard.cfg 1KB
proguard.cfg 1KB
proguard.cfg 1KB
proguard.cfg 1KB
proguard.cfg 1KB
ReviewActivity.java 8KB
ListItemSelectionActivity.java 5KB
CalculatorActivity.java 4KB
TableLayoutActivity.java 4KB
PizzaToppingsAdapter.java 4KB
MainActivity.java 3KB
ShopActivity.java 3KB
QuestionActivity.java 3KB
Calculator.java 3KB
ValidatingDatePickerDialog.java 2KB
MicksPizzaActivity.java 2KB
GuessActivity.java 2KB
CircleLayout.java 2KB
LayoutSelectorActivity.java 2KB
FruitAdapter.java 2KB
BurgerAdapter.java 2KB
AmountBox.java 2KB
Recipe.java 2KB
SelectRestaurantActivity.java 2KB
FourBucketsActivity.java 2KB
ViewRecipeActivity.java 2KB
NewsFeedActivity.java 1KB
TheBurgerPlaceActivity.java 1KB
GalleryAdapter.java 1KB
ColorAdapter.java 1KB
FrameLayoutActivity.java 1KB
AnimationSelector.java 1KB
ColorSelectorActivity.java 1KB
Album.java 911B
VanishingButtonActivity.java 855B
PizzaTopping.java 677B
Ingredient.java 549B
Track.java 513B
RelativeLayoutActivity.java 509B
SlidingDrawerActivity.java 507B
CircleLayoutActivity.java 505B
PizzaCatagory.java 487B
Artist.java 474B
FruitItem.java 391B
Burger.java 168B
curry_view.jpg 81KB
jai.jpg 68KB
jaipal.jpg 68KB
curry_view_thn.jpg 22KB
jai_thn.jpg 21KB
kiwi.png 26KB
kiwi.png 26KB
album_art.png 24KB
strawberry.png 23KB
strawberry.png 23KB
orange.png 22KB
orange.png 22KB
blackberry.png 22KB
blackberry.png 22KB
lime.png 22KB
lime.png 22KB
coconut.png 21KB
coconut.png 21KB
lemon.png 21KB
lemon.png 21KB
watermelon.png 21KB
watermelon.png 21KB
grapes.png 20KB
grapes.png 20KB
peach.png 20KB
peach.png 20KB
apple.png 20KB
apple.png 20KB
cherries.png 15KB
cherries.png 15KB
banana.png 15KB
banana.png 15KB
face.png 15KB
sherlock.png 5KB
ic_tab_selres.png 4KB
ic_tab_unselres.png 4KB
ic_tab_unselstar.png 4KB
ic_tab_selstar.png 4KB
ic_tab_selpho.png 4KB
ic_tab_unselpho.png 4KB
button_down.9.png 3KB
play.png 703B
button_focus.9.png 668B
button_up.9.png 576B
build.properties 697B
build.properties 697B
build.properties 697B
build.properties 697B
build.properties 697B
build.properties 697B
共 195 条
- 1
- 2
资源评论
- yuanmanpku2012-06-26正在看这本书,有代码正好,谢谢哈
- xikakaxi2222012-03-02代码写得非常好,虽然版本比较老,但是在用户界面上还是有很多的借鉴之处。 正如此书扉页说的,从做中学,少写理论,多些结果。
- liuwanzhen_ren2012-11-01例子是有,不过里面的界面很丑
- charlesma2013-05-05版本较老,但是例子代码写的都不错。赞
lysndsc
- 粉丝: 2
- 资源: 49
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- HM2305B-VB一款P-Channel沟道SOT23的MOSFET晶体管参数介绍与应用说明
- 基于52单片机、ADC0832、LCD1602、两个74HC393和一个74HC08的频率测量计 不能用,请私我
- HM2302-VB一款N-Channel沟道SOT23的MOSFET晶体管参数介绍与应用说明
- python实战项目-学生成绩管理系统(基础版)
- 微信小程序源码 实现查公交 滴滴公交 app 源码下载
- HM2302E-VB一款N-Channel沟道SOT23的MOSFET晶体管参数介绍与应用说明
- 基于C#图片相似度比较,感知哈希算法
- VR开发的概要介绍与分析
- 自动驾驶定位系列教程七:点云畸变补偿.pdf
- HM2302D-VB一款N-Channel沟道SOT23的MOSFET晶体管参数介绍与应用说明
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功