今天原计划是完成第一个模块【时间小计】的页面框架及功能:
时间小计的第一个显示页面,即app进入后的第一个页面,通过大的圆圈和24小时字样显示。点击大的圆圈显示第二个页面,即设置学习、休闲、睡眠的三个选项,设置后更新第一个页面,在圆圈中通过四种颜色蓝、红、绿、黑分别表示学习、休闲、睡眠和未设置的时间。
但是由于个人时间的安排和外部原因,浪费了5-6小时的时间,另外因为拓展式的需求设计,确实遇到很多以前没有涉及或者没有深入学习的内容,这与本人自学的水平有比较大的鸿沟,所以深深的感觉自己学习之路才开始,路艰且又长。当然一般按照软件相关工作的计划,一般都是要双倍时间才能完成的,不过粗略计算了一下,感觉其实今天只完成1/4的计划内容,主要工作如下:
1、完成了第一个模块,第一个页面的初步的绘制。
- 主要代码:Hour24Cycle.java,主要绘制一个圆环,主要代码如下:
package com.noodles.timelocus.view;
import android.content.Context;
import android.content.Intent;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.view.View;
import com.noodles.timelocus.activity.HourSet;
/**
* 绘制一个圆环
* Created by noodles on 2016/3/21.
*/
public class Hour24Cycle extends View implements View.OnClickListener {
private Paint mpaint;
private Rect mRect;
private Context mContext;
/* public Hour24Cycle(Context context) {
super(context);
}*/
public Hour24Cycle(Context context, AttributeSet attrs) {
super(context, attrs);
mContext = context;
mpaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mRect = new Rect();
setOnClickListener(this);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
float pointX = getWidth() / 2;
float pointY = getHeight() / 3;
float radius = 200;
mpaint.setColor(Color.BLUE);
setDraw(canvas, mpaint, pointX, pointY, radius, 0, 360);
mpaint.setColor(Color.WHITE);
setDraw(canvas, mpaint, pointX, pointY, radius - 50, 0, 360);
/*
* 绘制一个24的数字
*/
mpaint.setColor(Color.BLACK);
mpaint.setTextSize(100);
mpaint.getTextBounds("24", 0, 2, mRect);
float textWidth = mRect.width();
float textHeight = mRect.height();
canvas.drawText("24", pointX - textWidth / 2, pointY + textHeight / 2, mpaint);
}
/**
* 绘制两个360的弧度,里面的小圆弧为白色,外面大圆弧蓝色,所以看起来像一个圆环
*/
private void setDraw(Canvas canvas, Paint paint, float pointX, float pointY, float radius, float startAngle, float sweepAngle) {
RectF mRectf = new RectF(pointX - radius, pointY - radius, pointX + radius, pointY + radius);
canvas.drawArc(mRectf, startAngle, sweepAngle, false, paint);
}
/**
* 跳转到第二个页面
*/
@Override
public void onClick(View v) {
Intent intent = new Intent(mContext, HourSet.class);
mContext.startActivity(intent);
}
}
- 2.底部导航栏:bottom_action_bar.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="60dp"
android:baselineAligned="false">
<LinearLayout
android:id="@+id/time_subtotal"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/time_subtotal" />
</LinearLayout>
<LinearLayout
android:id="@+id/date_record"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/date_record" />
</LinearLayout>
<LinearLayout
android:id="@+id/review"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/review" />
</LinearLayout>
</LinearLayout>
<strong><span style="white-space:pre"> </span>3.连接以上两个页面的显示页面:index_activity.xml</strong>
<pre name="code" class="java"><?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".activity.TimeSubtotal">
<com.noodles.timelocus.view.Hour24Cycle
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"/>
<include
layout="@layout/bottom_action_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" />
</RelativeLayout>
这是本人菜鸟学步,我知道存在很多的问题,主要是先把自己犯的每一个愚蠢的错误和不足都暴露出来,一是可以敞开心胸,正视自己,另外一个就是把每天的事情大致都记录下来,提醒自己不能再自甘堕落了,比较很多人比我现在都已经强10倍不值,别人还比我更努力,必须向大神们学习。