Android Samples
Revision | f66d4e972cc9aa1475c14dbf69a1110572254912 (tree) |
---|---|
Zeit | 2014-05-30 17:46:37 |
Autor | Masahiko, SAWAI <say@user...> |
Commiter | Masahiko, SAWAI |
Added android.text.format.DateFormat example
@@ -0,0 +1,24 @@ | ||
1 | +<?xml version="1.0" encoding="utf-8"?> | |
2 | +<manifest | |
3 | + xmlns:android="http://schemas.android.com/apk/res/android" | |
4 | + package="com.example.hello.android.dateformat_hello" | |
5 | + android:versionCode="1" | |
6 | + android:versionName="1.0" | |
7 | +> | |
8 | + <uses-sdk android:minSdkVersion="3" android:targetSdkVersion="19" /> | |
9 | + | |
10 | + <application android:label="@string/app_name"> | |
11 | + <activity android:name=".MainActivity" | |
12 | + android:label="@string/app_name" | |
13 | + > | |
14 | + <intent-filter> | |
15 | + <action android:name="android.intent.action.MAIN" /> | |
16 | + <category android:name="android.intent.category.LAUNCHER" /> | |
17 | + </intent-filter> | |
18 | + </activity> | |
19 | + </application> | |
20 | + | |
21 | + <!-- | |
22 | + <uses-permission android:name="android.permission.INTERNET" /> | |
23 | + --> | |
24 | +</manifest> |
@@ -0,0 +1,47 @@ | ||
1 | +RELEASE_PROFILE=android-hello | |
2 | + | |
3 | +all : package | |
4 | + | |
5 | +#################### build | |
6 | + | |
7 | +compile : | |
8 | + mvn $@ | |
9 | + | |
10 | +gen : | |
11 | + mvn android:generate-sources | |
12 | + | |
13 | +package : | |
14 | + mvn $@ | |
15 | + | |
16 | +release : | |
17 | + mvn clean && mvn -P$(RELEASE_PROFILE) package | |
18 | + | |
19 | +install : | |
20 | + mvn $@ | |
21 | + | |
22 | +deploy : | |
23 | + mvn package android:deploy | |
24 | + | |
25 | +undeploy : | |
26 | + mvn android:undeploy | |
27 | + | |
28 | +rebuild : | |
29 | + mvn clean package | |
30 | + | |
31 | +redeploy : | |
32 | + mvn clean package android:deploy | |
33 | + | |
34 | + | |
35 | +#################### emulator | |
36 | +start : | |
37 | + mvn android:emulator-start | |
38 | + | |
39 | +stop : | |
40 | + mvn android:emulator-stop | |
41 | + | |
42 | +#################### project | |
43 | +dist : | |
44 | + mvn assembly:assembly | |
45 | + | |
46 | +clean : | |
47 | + mvn $@ |
@@ -0,0 +1,60 @@ | ||
1 | +! dateformat-hello | |
2 | + | |
3 | +android.text.format.DateFormat による日付の文字列化のサンプル。。 | |
4 | + | |
5 | +以下の4つのフォーマット取得メソッドを試す。 | |
6 | + | |
7 | +* DateFormat.getDateFormat(Context context) : java.text.DateFormat | |
8 | +* DateFormat.getLongDateFormat(Context context) : java.text.DateFormat | |
9 | +* DateFormat.getMediumDateFormat(Context context) : java.text.DateFormat | |
10 | +* DateFormat.getTimeFormat(Context context) : java.text.DateFormat | |
11 | + | |
12 | +!! 結果 | |
13 | + | |
14 | +日本語 | |
15 | + | |
16 | + getDateFormat() : 2014/05/30 | |
17 | + getMediumDateFormat() : 2014/05/30 | |
18 | + getLongDateFormat() : 2014年5月30日 | |
19 | + getTimeFormat() : 5:38午後 | |
20 | + | |
21 | +日本語 + 24時間フォーマット | |
22 | + | |
23 | + getDateFormat() : 2014/05/30 | |
24 | + getMediumDateFormat() : 2014/05/30 | |
25 | + getLongDateFormat() : 2014年5月30日 | |
26 | + getTimeFormat() : 17:31 | |
27 | + | |
28 | +English (United States) | |
29 | + | |
30 | + getDateFormat() : 5/30/2014 | |
31 | + getMediumDateFormat() : May 30, 2014 | |
32 | + getLongDateFormat() : May 30, 2014 | |
33 | + getTimeFormat() : 5:33 PM | |
34 | + | |
35 | +English (United States) + 24-Hours format | |
36 | + | |
37 | + getDateFormat() : 5/30/2014 | |
38 | + getMediumDateFormat() : May 30, 2014 | |
39 | + getLongDateFormat() : May 30, 2014 | |
40 | + getTimeFormat() : 17:35 | |
41 | + | |
42 | + | |
43 | + | |
44 | +############################################################ | |
45 | +!! ビルドターゲット | |
46 | + | |
47 | +http://maven-android-plugin-m2site.googlecode.com/svn/plugin-info.html | |
48 | + | |
49 | +* mvn compile - アプリケーションのコンパイル | |
50 | +* mvn package - apk の作成 | |
51 | +* mvn clean - ビルドファイルの削除 | |
52 | +* mvn install - maven の local リポジトリにインストール | |
53 | + | |
54 | +* mvn android:deploy - エミュレータやデバイスにインストール | |
55 | +* mvn android:generate-sources | |
56 | + | |
57 | +* mvn install - アプリケーションのインストール | |
58 | +* mvn uninstall - アプリケーションのアンインストール | |
59 | + | |
60 | + |
@@ -0,0 +1,142 @@ | ||
1 | +<?xml version="1.0" encoding="UTF-8" ?> | |
2 | +<project | |
3 | + xmlns="http://maven.apache.org/POM/4.0.0" | |
4 | + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
5 | + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd" | |
6 | +> | |
7 | + <modelVersion>4.0.0</modelVersion> | |
8 | + <groupId>com.example.hello</groupId> | |
9 | + <artifactId>dateformat-hello</artifactId> | |
10 | + <packaging>apk</packaging> | |
11 | + <version>1.0.0</version> | |
12 | + <name>Android DateFormat Hello</name> | |
13 | + <url>http://www.example.com/</url> | |
14 | + | |
15 | + <parent> | |
16 | + <groupId>com.example.hello</groupId> | |
17 | + <artifactId>android-samples</artifactId> | |
18 | + <version>1.0.0</version> | |
19 | + </parent> | |
20 | + | |
21 | + <dependencies> | |
22 | + | |
23 | + <dependency> | |
24 | + <groupId>android</groupId> | |
25 | + <artifactId>android</artifactId> | |
26 | + <version>1.5_r4</version> | |
27 | + <!-- | |
28 | + <version>1.5_r3</version> | |
29 | + <version>1.5_r4</version> | |
30 | + <version>1.6_r2</version> | |
31 | + <version>2.1.2</version> | |
32 | + <version>2.1_r1</version> | |
33 | + <version>2.2.1</version> | |
34 | + <version>2.3.1</version> | |
35 | + <version>2.3.3</version> | |
36 | + <version>4.0.1.2</version> | |
37 | + --> | |
38 | + <scope>provided</scope> | |
39 | + </dependency> | |
40 | + | |
41 | + <dependency> | |
42 | + <groupId>junit</groupId> | |
43 | + <artifactId>junit</artifactId> | |
44 | + <scope>test</scope> | |
45 | + </dependency> | |
46 | + </dependencies> | |
47 | + | |
48 | + <build> | |
49 | + <sourceDirectory>src</sourceDirectory> | |
50 | + | |
51 | + <plugins> | |
52 | + <plugin> | |
53 | + <groupId>com.jayway.maven.plugins.android.generation2</groupId> | |
54 | + <artifactId>android-maven-plugin</artifactId> | |
55 | + <configuration> | |
56 | + <sdk> | |
57 | + <!--<path>${env.ANDROID_HOME}</path>--> | |
58 | + <platform>8</platform> | |
59 | + </sdk> | |
60 | + </configuration> | |
61 | + <extensions>true</extensions> | |
62 | + </plugin> | |
63 | + | |
64 | + <!-- mvn compile --> | |
65 | + <plugin> | |
66 | + <groupId>org.apache.maven.plugins</groupId> | |
67 | + <artifactId>maven-compiler-plugin</artifactId> | |
68 | + <configuration> | |
69 | + <source>1.5</source> | |
70 | + <target>1.5</target> | |
71 | + <encoding>UTF-8</encoding> | |
72 | + </configuration> | |
73 | + </plugin> | |
74 | + | |
75 | + <!-- mvn assembly:assembly --> | |
76 | + <plugin> | |
77 | + <groupId>org.apache.maven.plugins</groupId> | |
78 | + <artifactId>maven-assembly-plugin</artifactId> | |
79 | + <configuration> | |
80 | + <descriptorRefs> | |
81 | + <!-- | |
82 | + <descriptorRef>jar-with-dependencies</descriptorRef> | |
83 | + <descriptorRef>bin</descriptorRef> | |
84 | + <descriptorRef>src</descriptorRef> | |
85 | + --> | |
86 | + <descriptorRef>project</descriptorRef> | |
87 | + </descriptorRefs> | |
88 | + </configuration> | |
89 | + </plugin> | |
90 | + | |
91 | + <!-- mvn resources:resources --> | |
92 | + <plugin> | |
93 | + <groupId>org.apache.maven.plugins</groupId> | |
94 | + <artifactId>maven-resources-plugin</artifactId> | |
95 | + <configuration> | |
96 | + <encoding>UTF-8</encoding> | |
97 | + </configuration> | |
98 | + </plugin> | |
99 | + | |
100 | + <!-- mvn site --> | |
101 | + <plugin> | |
102 | + <groupId>org.apache.maven.plugins</groupId> | |
103 | + <artifactId>maven-site-plugin</artifactId> | |
104 | + <configuration> | |
105 | + <locales>en</locales> | |
106 | + <inputEncoding>UTF-8</inputEncoding> | |
107 | + <outputEncoding>UTF-8</outputEncoding> | |
108 | + | |
109 | + <reportPlugins> | |
110 | + <plugin> | |
111 | + <groupId>org.apache.maven.plugins</groupId> | |
112 | + <artifactId>maven-project-info-reports-plugin</artifactId> | |
113 | + </plugin> | |
114 | + | |
115 | + <!-- mvn javadoc:javadoc --> | |
116 | + <plugin> | |
117 | + <groupId>org.apache.maven.plugins</groupId> | |
118 | + <artifactId>maven-javadoc-plugin</artifactId> | |
119 | + <configuration> | |
120 | + <charset>utf-8</charset> | |
121 | + </configuration> | |
122 | + </plugin> | |
123 | + </reportPlugins> | |
124 | + </configuration> | |
125 | + </plugin> | |
126 | + | |
127 | + </plugins> | |
128 | + | |
129 | + <!-- mvn resources:resources --> | |
130 | + <resources> | |
131 | + <resource> | |
132 | + <directory>res</directory> | |
133 | + <filtering>false</filtering> | |
134 | + <includes> | |
135 | + <include>**/*.properties</include> | |
136 | + </includes> | |
137 | + </resource> | |
138 | + </resources> | |
139 | + </build> | |
140 | + | |
141 | + | |
142 | +</project> |
@@ -0,0 +1,47 @@ | ||
1 | +<?xml version="1.0" encoding="utf-8"?> | |
2 | +<LinearLayout | |
3 | + xmlns:android="http://schemas.android.com/apk/res/android" | |
4 | + android:layout_width="fill_parent" | |
5 | + android:layout_height="fill_parent" | |
6 | + android:orientation="vertical" | |
7 | +> | |
8 | + <TextView | |
9 | + style="@style/format_label" | |
10 | + android:text="@string/date_format" | |
11 | + /> | |
12 | + <TextView | |
13 | + style="@style/formatted_text" | |
14 | + android:id="@+id/date_format_textview" | |
15 | + /> | |
16 | + <View style="@style/hline" /> | |
17 | + | |
18 | + <TextView | |
19 | + style="@style/format_label" | |
20 | + android:text="@string/medium_date_format" | |
21 | + /> | |
22 | + <TextView | |
23 | + style="@style/formatted_text" | |
24 | + android:id="@+id/medium_date_format_textview" | |
25 | + /> | |
26 | + <View style="@style/hline" /> | |
27 | + | |
28 | + <TextView | |
29 | + style="@style/format_label" | |
30 | + android:text="@string/long_date_format" | |
31 | + /> | |
32 | + <TextView | |
33 | + style="@style/formatted_text" | |
34 | + android:id="@+id/long_date_format_textview" | |
35 | + /> | |
36 | + <View style="@style/hline" /> | |
37 | + | |
38 | + <TextView | |
39 | + style="@style/format_label" | |
40 | + android:text="@string/time_format" | |
41 | + /> | |
42 | + <TextView | |
43 | + style="@style/formatted_text" | |
44 | + android:id="@+id/time_format_textview" | |
45 | + /> | |
46 | + <View style="@style/hline" /> | |
47 | +</LinearLayout> | |
\ No newline at end of file |
@@ -0,0 +1,8 @@ | ||
1 | +<?xml version="1.0" encoding="utf-8"?> | |
2 | +<resources> | |
3 | + <string name="app_name">DateFormat Hello</string> | |
4 | + <string name="date_format">DateFormat.getDateFormat()</string> | |
5 | + <string name="medium_date_format">DateFormat.getMediumDateFormat()</string> | |
6 | + <string name="long_date_format">DateFormat.getLongDateFormat()</string> | |
7 | + <string name="time_format">DateFormat.getTimeFormat()</string> | |
8 | +</resources> |
@@ -0,0 +1,16 @@ | ||
1 | +<?xml version="1.0" encoding="utf-8"?> | |
2 | +<resources> | |
3 | + <!-- common --> | |
4 | + <style name="format_label"> | |
5 | + <item name="android:layout_width">fill_parent</item> | |
6 | + <item name="android:layout_height">wrap_content</item> | |
7 | + <item name="android:textSize">18sp</item> | |
8 | + <item name="android:textColor">?android:textColorSecondary</item> | |
9 | + </style> | |
10 | + <style name="formatted_text"> | |
11 | + <item name="android:layout_width">fill_parent</item> | |
12 | + <item name="android:layout_height">wrap_content</item> | |
13 | + <item name="android:textSize">20sp</item> | |
14 | + <item name="android:textColor">?android:textColorPrimary</item> | |
15 | + </style> | |
16 | +</resources> |
@@ -0,0 +1,17 @@ | ||
1 | +<?xml version="1.0" encoding="utf-8"?> | |
2 | +<resources> | |
3 | + <!-- common --> | |
4 | + <style name="dot"> | |
5 | + <item name="android:layout_width">1dip</item> | |
6 | + <item name="android:layout_height">1dip</item> | |
7 | + <item name="android:layout_weight">0</item> | |
8 | + <item name="android:layout_margin">4dip</item> | |
9 | + <item name="android:background">#333</item> | |
10 | + </style> | |
11 | + <style name="vline" parent="dot" > | |
12 | + <item name="android:layout_height">fill_parent</item> | |
13 | + </style> | |
14 | + <style name="hline" parent="dot" > | |
15 | + <item name="android:layout_width">fill_parent</item> | |
16 | + </style> | |
17 | +</resources> |
@@ -0,0 +1,59 @@ | ||
1 | +package com.example.hello.android.dateformat_hello; | |
2 | + | |
3 | +import android.app.Activity; | |
4 | +import android.os.Bundle; | |
5 | +import android.text.format.DateFormat; | |
6 | +import android.util.Log; | |
7 | +import android.view.View; | |
8 | +import android.widget.TextView; | |
9 | +import java.util.Date; | |
10 | + | |
11 | +public class MainActivity extends Activity | |
12 | +{ | |
13 | + | |
14 | + private static final String LOG_TAG = "XXX"; | |
15 | + | |
16 | + @Override | |
17 | + public void onCreate(Bundle savedInstanceState) | |
18 | + { | |
19 | + super.onCreate(savedInstanceState); | |
20 | + setContentView(R.layout.main_activity); | |
21 | + | |
22 | + updateFormattedText(); | |
23 | + } | |
24 | + | |
25 | + private void updateFormattedText() | |
26 | + { | |
27 | + Date now = new Date(); | |
28 | + java.text.DateFormat format; | |
29 | + String formattedText; | |
30 | + | |
31 | + // DateFormat.getDateFormat() | |
32 | + TextView dateFormatTextView = (TextView) findViewById(R.id.date_format_textview); | |
33 | + format = DateFormat.getDateFormat(this); | |
34 | + formattedText = format.format(now); | |
35 | + dateFormatTextView.setText(formattedText); | |
36 | + Log.d(LOG_TAG, "getDateFormat() : " + formattedText); | |
37 | + | |
38 | + // DateFormat.getMediumDateFormat() | |
39 | + TextView mediumDateFormatTextView = (TextView) findViewById(R.id.medium_date_format_textview); | |
40 | + format = DateFormat.getMediumDateFormat(this); | |
41 | + formattedText = format.format(now); | |
42 | + mediumDateFormatTextView.setText(formattedText); | |
43 | + Log.d(LOG_TAG, "getMediumDateFormat() : " + formattedText); | |
44 | + | |
45 | + // DateFormat.getLongDateFormat() | |
46 | + TextView longDateFormatTextView = (TextView) findViewById(R.id.long_date_format_textview); | |
47 | + format = DateFormat.getLongDateFormat(this); | |
48 | + formattedText = format.format(now); | |
49 | + longDateFormatTextView.setText(formattedText); | |
50 | + Log.d(LOG_TAG, "getLongDateFormat() : " + formattedText); | |
51 | + | |
52 | + // DateFormat.getTimeFormat() | |
53 | + TextView timeFormatTextView = (TextView) findViewById(R.id.time_format_textview); | |
54 | + format = DateFormat.getTimeFormat(this); | |
55 | + formattedText = format.format(now); | |
56 | + timeFormatTextView.setText(formattedText); | |
57 | + Log.d(LOG_TAG, "getTimeFormat() : " + formattedText); | |
58 | + } | |
59 | +} |
@@ -53,6 +53,8 @@ | ||
53 | 53 | |
54 | 54 | <module>bitmap-drawing-and-save</module> |
55 | 55 | <module>bitmap-drawing-and-show</module> |
56 | + | |
57 | + <module>dateformat-hello</module> | |
56 | 58 | <module>drawable-xml-gradient-types</module> |
57 | 59 | <module>drawable-xml-hello</module> |
58 | 60 | <module>drawable-xml-shape-types</module> |