2015年2月28日 星期六
2015年2月27日 星期五
WheelView numberpicker
private WheelView picker;
picker = (WheelView) this.convertView.findViewById(R.id.picker);
picker.setVisibleItems(5); // Number of items
picker.setWheelBackground(R.drawable.wheel_bg);
picker.setWheelForeground(R.drawable.wheel_val);
picker.setShadowColor(0xFF000000, 0x88000000, 0x00000000);
AmountAdapter amountAdapter = new AmountAdapter(context);
picker.setViewAdapter( amountAdapter);
int pickAmount=picker.getCurrentItem();
https://github.com/maarek/android-wheel
picker = (WheelView) this.convertView.findViewById(R.id.picker);
picker.setVisibleItems(5); // Number of items
picker.setWheelBackground(R.drawable.wheel_bg);
picker.setWheelForeground(R.drawable.wheel_val);
picker.setShadowColor(0xFF000000, 0x88000000, 0x00000000);
AmountAdapter amountAdapter = new AmountAdapter(context);
picker.setViewAdapter( amountAdapter);
int pickAmount=picker.getCurrentItem();
https://github.com/maarek/android-wheel
2015年2月22日 星期日
viewflow內的spinner
https://github.com/pakerfeldt/android-viewflow/issues/73
http://bbs.csdn.net/topics/390608927
http://developer.android.com/reference/android/R.attr.html#descendantFocusability
http://bbs.csdn.net/topics/390608927
http://developer.android.com/reference/android/R.attr.html#descendantFocusability
2015年2月20日 星期五
TransactionHandler //控制fragment畫面切換
package com.lfo.suntone.transaction;
import android.app.Fragment;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.os.Bundle;
import com.lfo.suntone.fragment.MainFragment;
import com.lfo.suntone.constant.ALLFragmentName;
import com.lfo.suntone.utils.Utils;
/**
* Created by Administrator on 2015/2/16.
*/
public class TransactionHandler {
//控制fragment畫面切換
private static TransactionHandler instance = new TransactionHandler();
protected MainFragment mainFragment;
protected Boolean isInitial = false;
protected FragmentManager fragmentManager;
private SecondFrameLayoutTransaction secondFrameLayoutTransaction;
private CenterFrameLayoutTransaction centerFrameLayoutTransaction;
private CategoryFrameLayoutTransation categoryFrameLayoutTransation;
protected TransactionHandler() {
}
public static TransactionHandler getInstance() {
return instance;
}
public void initial(MainFragment mainFragment) {
if (isInitial == false) {
this.mainFragment = mainFragment;
fragmentManager = mainFragment.getChildFragmentManager();
Utils.log("TransactionHandler initial");
isInitial = true;
}
}
public CategoryFrameLayoutTransation getCategoryFrameLayoutTransaction() {
if (isInitial) {
categoryFrameLayoutTransation = new CategoryFrameLayoutTransation();
categoryFrameLayoutTransation.initial(mainFragment);
return categoryFrameLayoutTransation;
}
Utils.logE("TransactionHandler not Initial yet");
return null;
}
public SecondFrameLayoutTransaction getSecondFrameLayoutTransaction() {
if (isInitial) {
secondFrameLayoutTransaction = new SecondFrameLayoutTransaction();
secondFrameLayoutTransaction.initial(mainFragment);
return secondFrameLayoutTransaction;
}
Utils.logE("TransactionHandler not Initial yet");
return null;
}
public CenterFrameLayoutTransaction getCenterFrameLayoutTransaction() {
if (isInitial) {
centerFrameLayoutTransaction = new CenterFrameLayoutTransaction();
centerFrameLayoutTransaction.initial(mainFragment);
return centerFrameLayoutTransaction;
}
Utils.logE("TransactionHandler not Initial yet");
return null;
}
protected void hideSecondLayout() {
mainFragment.hideSecondLayout();
}
protected Fragment getFragmentInMainFragment(ALLFragmentName fragmentname) {
mainFragment.resetBackKeyPressedCount();//轉移頁面時把ackKeyPressedCount歸零
Fragment fragment = fragmentManager.findFragmentByTag(fragmentname.toString());
if (fragment == null) {
return null;
}
return fragment;
}
protected void passvalueAndCommit(Bundle whatyouwantpass, Fragment result, int layoutId) {
try {
if (whatyouwantpass != null) {
result.setArguments(whatyouwantpass);
}
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.setTransition(FragmentTransaction.TRANSIT_ENTER_MASK);
//layoutId=R.id.secondFrameLayout;
fragmentTransaction.addToBackStack(null);
fragmentTransaction.replace(layoutId, result, result.getClass().getSimpleName());
fragmentTransaction.commitAllowingStateLoss();
//Utils.log("passvalueAndCommit and commit");
} catch (Exception e) {
//bug http://stackoverflow.com/questions/15207305/getting-the-error-java-lang-illegalstateexception-activity-has-been-destroyed
e.printStackTrace();
}
}
}
package com.lfo.suntone.transaction;
import android.app.Fragment;
import android.content.Context;
import android.os.Bundle;
import com.lfo.suntone.R;
import com.lfo.suntone.fragment.CategoryFragment;
import com.lfo.suntone.fragment.news.NewsPageFragment;
import com.lfo.suntone.constant.ALLFragmentName;
public class SecondFrameLayoutTransaction extends TransactionHandler {
//1.new class and extend TransactionHandler
//2.define variable layoutid
//3.create method where you want to fragment
//4.add to TransactionHandler
final private int layoutId = R.id.secondFrameLayout;
protected SecondFrameLayoutTransaction() {
}
public void toNewsPageFragment(Context context,Bundle whatyouwantpass) {
NewsPageFragment fragment = (NewsPageFragment) getFragmentInMainFragment(ALLFragmentName.NewsPageFragment);
if (fragment == null) {
fragment = new NewsPageFragment();
fragment= (NewsPageFragment) Fragment.instantiate(context,fragment.getClass().getName());
}
hideSecondLayout();
passvalueAndCommit(whatyouwantpass, fragment, layoutId);
}
public void toCategoryFragment(Context context,Bundle whatyouwantpass) {
CategoryFragment fragment = (CategoryFragment) getFragmentInMainFragment(ALLFragmentName.CategoryFragment);
if (fragment == null) {
fragment = new CategoryFragment();
fragment= (CategoryFragment) Fragment.instantiate(context, fragment.getClass().getName());
}
hideSecondLayout();
passvalueAndCommit(whatyouwantpass, fragment, layoutId);
}
}
import android.app.Fragment;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.os.Bundle;
import com.lfo.suntone.fragment.MainFragment;
import com.lfo.suntone.constant.ALLFragmentName;
import com.lfo.suntone.utils.Utils;
/**
* Created by Administrator on 2015/2/16.
*/
public class TransactionHandler {
//控制fragment畫面切換
private static TransactionHandler instance = new TransactionHandler();
protected MainFragment mainFragment;
protected Boolean isInitial = false;
protected FragmentManager fragmentManager;
private SecondFrameLayoutTransaction secondFrameLayoutTransaction;
private CenterFrameLayoutTransaction centerFrameLayoutTransaction;
private CategoryFrameLayoutTransation categoryFrameLayoutTransation;
protected TransactionHandler() {
}
public static TransactionHandler getInstance() {
return instance;
}
public void initial(MainFragment mainFragment) {
if (isInitial == false) {
this.mainFragment = mainFragment;
fragmentManager = mainFragment.getChildFragmentManager();
Utils.log("TransactionHandler initial");
isInitial = true;
}
}
public CategoryFrameLayoutTransation getCategoryFrameLayoutTransaction() {
if (isInitial) {
categoryFrameLayoutTransation = new CategoryFrameLayoutTransation();
categoryFrameLayoutTransation.initial(mainFragment);
return categoryFrameLayoutTransation;
}
Utils.logE("TransactionHandler not Initial yet");
return null;
}
public SecondFrameLayoutTransaction getSecondFrameLayoutTransaction() {
if (isInitial) {
secondFrameLayoutTransaction = new SecondFrameLayoutTransaction();
secondFrameLayoutTransaction.initial(mainFragment);
return secondFrameLayoutTransaction;
}
Utils.logE("TransactionHandler not Initial yet");
return null;
}
public CenterFrameLayoutTransaction getCenterFrameLayoutTransaction() {
if (isInitial) {
centerFrameLayoutTransaction = new CenterFrameLayoutTransaction();
centerFrameLayoutTransaction.initial(mainFragment);
return centerFrameLayoutTransaction;
}
Utils.logE("TransactionHandler not Initial yet");
return null;
}
protected void hideSecondLayout() {
mainFragment.hideSecondLayout();
}
protected Fragment getFragmentInMainFragment(ALLFragmentName fragmentname) {
mainFragment.resetBackKeyPressedCount();//轉移頁面時把ackKeyPressedCount歸零
Fragment fragment = fragmentManager.findFragmentByTag(fragmentname.toString());
if (fragment == null) {
return null;
}
return fragment;
}
protected void passvalueAndCommit(Bundle whatyouwantpass, Fragment result, int layoutId) {
try {
if (whatyouwantpass != null) {
result.setArguments(whatyouwantpass);
}
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.setTransition(FragmentTransaction.TRANSIT_ENTER_MASK);
//layoutId=R.id.secondFrameLayout;
fragmentTransaction.addToBackStack(null);
fragmentTransaction.replace(layoutId, result, result.getClass().getSimpleName());
fragmentTransaction.commitAllowingStateLoss();
//Utils.log("passvalueAndCommit and commit");
} catch (Exception e) {
//bug http://stackoverflow.com/questions/15207305/getting-the-error-java-lang-illegalstateexception-activity-has-been-destroyed
e.printStackTrace();
}
}
}
package com.lfo.suntone.transaction;
import android.app.Fragment;
import android.content.Context;
import android.os.Bundle;
import com.lfo.suntone.R;
import com.lfo.suntone.fragment.CategoryFragment;
import com.lfo.suntone.fragment.news.NewsPageFragment;
import com.lfo.suntone.constant.ALLFragmentName;
public class SecondFrameLayoutTransaction extends TransactionHandler {
//1.new class and extend TransactionHandler
//2.define variable layoutid
//3.create method where you want to fragment
//4.add to TransactionHandler
final private int layoutId = R.id.secondFrameLayout;
protected SecondFrameLayoutTransaction() {
}
public void toNewsPageFragment(Context context,Bundle whatyouwantpass) {
NewsPageFragment fragment = (NewsPageFragment) getFragmentInMainFragment(ALLFragmentName.NewsPageFragment);
if (fragment == null) {
fragment = new NewsPageFragment();
fragment= (NewsPageFragment) Fragment.instantiate(context,fragment.getClass().getName());
}
hideSecondLayout();
passvalueAndCommit(whatyouwantpass, fragment, layoutId);
}
public void toCategoryFragment(Context context,Bundle whatyouwantpass) {
CategoryFragment fragment = (CategoryFragment) getFragmentInMainFragment(ALLFragmentName.CategoryFragment);
if (fragment == null) {
fragment = new CategoryFragment();
fragment= (CategoryFragment) Fragment.instantiate(context, fragment.getClass().getName());
}
hideSecondLayout();
passvalueAndCommit(whatyouwantpass, fragment, layoutId);
}
}
JACKSON IN android studio
JACKSON
1.下載JAR https://github.com/FasterXML/jackson-databind
http://repo1.maven.org/maven2/com/fasterxml/jackson/core/jackson-databind/2.5.1/
Since package also depends on
都需要!
案例
http://stackoverflow.com/questions/10094300/noclassdeffounderror-jsonautodetect-while-parsing-json-object
2. build.gradle增加packagingOptions 因為
jackson-core和jackson-databind有重複的地方
apply plugin: 'com.android.application'
android {
compileSdkVersion 17
buildToolsVersion '21.1.2'
defaultConfig {
applicationId 'com.lfo.sumone'
minSdkVersion 17
targetSdkVersion 17
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
sourceSets {
main {
manifest.srcFile 'src/main/AndroidManifest.xml'
java.srcDirs = ['src/main/java', 'src/main/java-gen']
res.srcDirs = ['src/main/res']
}
}
productFlavors {
}
packagingOptions{
exclude 'META-INF/LICENSE'
exclude 'META-INF/NOTICE'
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile('org.simpleframework:simple-xml:2.7.1') {
exclude group: 'stax', module: 'stax-api'
exclude group: 'xpp3', module: 'xpp3'
}
compile 'com.mcxiaoke.volley:library:1.0.10'
compile 'de.greenrobot:greendao:1.3.7'
compile 'com.android.support:support-v4:21.0.3'
compile 'com.google.android.gms:play-services:6.5.87'
compile 'de.greenrobot:eventbus:2.4.0'
compile 'org.jsoup:jsoup:1.8.1'
compile project(':viewflow')
compile files('src/libs/jackson-databind-2.5.1.jar')
compile 'com.fasterxml.jackson.core:jackson-core:2.5.1'
}
1.下載JAR https://github.com/FasterXML/jackson-databind
http://repo1.maven.org/maven2/com/fasterxml/jackson/core/jackson-databind/2.5.1/
jackson-corehttp://repo1.maven.org/maven2/com/fasterxml/jackson/core/jackson-core/2.5.1/jackson-core-2.5.1.jar jackson-annotationshttp://repo1.maven.org/maven2/com/fasterxml/jackson/core/jackson-annotations/2.5.1/jackson-annotations-2.5.1.jar Since package also depends on
jackson-core and jackson-annotations packages 都需要!
案例
http://stackoverflow.com/questions/10094300/noclassdeffounderror-jsonautodetect-while-parsing-json-object
2. build.gradle增加packagingOptions 因為
jackson-core和jackson-databind有重複的地方
apply plugin: 'com.android.application'
android {
compileSdkVersion 17
buildToolsVersion '21.1.2'
defaultConfig {
applicationId 'com.lfo.sumone'
minSdkVersion 17
targetSdkVersion 17
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
sourceSets {
main {
manifest.srcFile 'src/main/AndroidManifest.xml'
java.srcDirs = ['src/main/java', 'src/main/java-gen']
res.srcDirs = ['src/main/res']
}
}
productFlavors {
}
packagingOptions{
exclude 'META-INF/LICENSE'
exclude 'META-INF/NOTICE'
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile('org.simpleframework:simple-xml:2.7.1') {
exclude group: 'stax', module: 'stax-api'
exclude group: 'xpp3', module: 'xpp3'
}
compile 'com.mcxiaoke.volley:library:1.0.10'
compile 'de.greenrobot:greendao:1.3.7'
compile 'com.android.support:support-v4:21.0.3'
compile 'com.google.android.gms:play-services:6.5.87'
compile 'de.greenrobot:eventbus:2.4.0'
compile 'org.jsoup:jsoup:1.8.1'
compile project(':viewflow')
compile files('src/libs/jackson-databind-2.5.1.jar')
compile 'com.fasterxml.jackson.core:jackson-core:2.5.1'
}
MyDaoGenerator class
http://my.oschina.net/u/1052509/blog/312635
package pl.surecase.eu;
/**
* Created by Nijugon on 2015/2/19.
*/
import de.greenrobot.daogenerator.DaoGenerator;
import de.greenrobot.daogenerator.Entity;
import de.greenrobot.daogenerator.Property;
import de.greenrobot.daogenerator.PropertyType;
import de.greenrobot.daogenerator.Schema;
import de.greenrobot.daogenerator.ToMany;
public class MyDaoGenerator {
public static void main(String[] args) throws Exception {
//Schema schema = new Schema(version, defaultJavaPackageme);
Schema schema = new Schema(1, "greendao");
setNews(schema);
setUserHistory(schema);
setCategoryAndProduct(schema);
new DaoGenerator().generateAll(schema,"../app/src/main/java-gen");
}
private static void setCategoryAndProduct(Schema schema) {
Entity category = schema.addEntity("Category");
category.addIdProperty().primaryKey().autoincrement();
category.addIntProperty("pcId");//http://www.suntone.com.tw/ProdClass.aspx?PC_ID=1
category.addStringProperty("name");
category.addStringProperty("topBannerUrl");
category.addStringProperty("topBannerName");
category.addStringProperty("sourceUrl");
Entity product = schema.addEntity("Product");
product.addIdProperty().primaryKey().autoincrement();
product.addIntProperty("pNo");
product.addStringProperty("name");
product.addStringProperty("price");
product.addStringProperty("url");
product.addStringProperty("sheifLife");
product.addStringProperty("matertial");
product.addStringProperty("imgUrl");
product.addStringProperty("imgName");
product.addStringProperty("buyAmount");
Property productProperty = product.addLongProperty("categoryId")
.notNull().getProperty();
category.addToMany(product,productProperty,"productsInCategory");//這個one to many關係的名稱
}
private static Entity setNews(Schema schema) {
Entity entity = schema.addEntity("News");
entity.addIdProperty().primaryKey().autoincrement();
entity.addStringProperty("pageId");
entity.addStringProperty("title");
entity.addStringProperty("annosDate");
entity.addStringProperty("content");
return entity;
}
private static Entity setUserHistory(Schema schema) {
Entity entity = schema.addEntity("UserHistory");
entity.addIdProperty().primaryKey().autoincrement();
entity.addStringProperty("type");
entity.addStringProperty("methodName");
entity.addDateProperty("time");
return entity;
}
}
package pl.surecase.eu;
/**
* Created by Nijugon on 2015/2/19.
*/
import de.greenrobot.daogenerator.DaoGenerator;
import de.greenrobot.daogenerator.Entity;
import de.greenrobot.daogenerator.Property;
import de.greenrobot.daogenerator.PropertyType;
import de.greenrobot.daogenerator.Schema;
import de.greenrobot.daogenerator.ToMany;
public class MyDaoGenerator {
public static void main(String[] args) throws Exception {
//Schema schema = new Schema(version, defaultJavaPackageme);
Schema schema = new Schema(1, "greendao");
setNews(schema);
setUserHistory(schema);
setCategoryAndProduct(schema);
new DaoGenerator().generateAll(schema,"../app/src/main/java-gen");
}
private static void setCategoryAndProduct(Schema schema) {
Entity category = schema.addEntity("Category");
category.addIdProperty().primaryKey().autoincrement();
category.addIntProperty("pcId");//http://www.suntone.com.tw/ProdClass.aspx?PC_ID=1
category.addStringProperty("name");
category.addStringProperty("topBannerUrl");
category.addStringProperty("topBannerName");
category.addStringProperty("sourceUrl");
Entity product = schema.addEntity("Product");
product.addIdProperty().primaryKey().autoincrement();
product.addIntProperty("pNo");
product.addStringProperty("name");
product.addStringProperty("price");
product.addStringProperty("url");
product.addStringProperty("sheifLife");
product.addStringProperty("matertial");
product.addStringProperty("imgUrl");
product.addStringProperty("imgName");
product.addStringProperty("buyAmount");
Property productProperty = product.addLongProperty("categoryId")
.notNull().getProperty();
category.addToMany(product,productProperty,"productsInCategory");//這個one to many關係的名稱
}
private static Entity setNews(Schema schema) {
Entity entity = schema.addEntity("News");
entity.addIdProperty().primaryKey().autoincrement();
entity.addStringProperty("pageId");
entity.addStringProperty("title");
entity.addStringProperty("annosDate");
entity.addStringProperty("content");
return entity;
}
private static Entity setUserHistory(Schema schema) {
Entity entity = schema.addEntity("UserHistory");
entity.addIdProperty().primaryKey().autoincrement();
entity.addStringProperty("type");
entity.addStringProperty("methodName");
entity.addDateProperty("time");
return entity;
}
}
2015年2月19日 星期四
build.gradle MyDaoGenerator
project(':MyDaoGenerator') {
apply plugin: 'java'
apply plugin: 'application'
mainClassName = "pl.surecase.eu.MyDaoGenerator"
// edit output direction
outputDir = "../app/src/main/java-gen"
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'de.greenrobot:greendao-generator:1.3.1'
}
task createDocs {
def docs = file(outputDir)
docs.mkdirs()
}
run {
args outputDir
}
}
apply plugin: 'java'
apply plugin: 'application'
mainClassName = "pl.surecase.eu.MyDaoGenerator"
// edit output direction
outputDir = "../app/src/main/java-gen"
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'de.greenrobot:greendao-generator:1.3.1'
}
task createDocs {
def docs = file(outputDir)
docs.mkdirs()
}
run {
args outputDir
}
}
ChildFragmentManager中找
Note: Each fragment requires a unique identifier that the system can use to restore the fragment if the activity is restarted (and which you can use to capture the fragment to perform transactions, such as remove it). There are three ways to provide an ID for a fragment:
- Supply the android:id attribute with a unique ID.
- Supply the android:tag attribute with a unique string.
- If you provide neither of the previous two, the system uses the ID of the container view.
NewsListFragment fragmet = (NewsListFragment) getChildFragmentManager().findFragmentById( R.id.centerFrameLayout);
the best way enum ->siglone
// Enum singleton - the preferred approach
public enum Elvis {
INSTANCE;
public void leaveTheBuilding() { ... }
}
Activity has been destroyed 的錯誤 (not use finish() -> System.exit(0); because onDetach bug)
public void onEvent(FinishApp event) {
FinishAppListener finishAppListener = new FinishAppListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (which == AlertDialogWhich.Y) {
try{
dialog.dismiss();
System.exit(0);////not use finish(); because onDetach bug
}catch (Exception e){
e.printStackTrace();
}
}
}
};
Utils.showAlertDialogYorN(this, getResources().getString(R.string.askExistApp), finishAppListener);
}
http://stackoverflow.com/questions/15207305/getting-the-error-java-lang-illegalstateexception-activity-has-been-destroyed
在每個fragmnet加上
FinishAppListener finishAppListener = new FinishAppListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (which == AlertDialogWhich.Y) {
try{
dialog.dismiss();
System.exit(0);////not use finish(); because onDetach bug
}catch (Exception e){
e.printStackTrace();
}
}
}
};
Utils.showAlertDialogYorN(this, getResources().getString(R.string.askExistApp), finishAppListener);
}
http://stackoverflow.com/questions/15207305/getting-the-error-java-lang-illegalstateexception-activity-has-been-destroyed
在每個fragmnet加上
@Override
public void onDetach() {
super.onDetach();
try {
Field childFragmentManager = Fragment.class.getDeclaredField("mChildFragmentManager");
childFragmentManager.setAccessible(true);
childFragmentManager.set(this, null);
} catch (NoSuchFieldException e) {
throw new RuntimeException(e);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
}
不然的話你就會看到
Activity has been destroyed 的錯誤
2015年2月18日 星期三
tomcat MySQL data source
http://tomcat.apache.org/tomcat-8.0-doc/jndi-datasource-examples-howto.html
For example:
2. Context configuration
Configure the JNDI DataSource in Tomcat by adding a declaration for your resource to your Context.For example:
<Context>
<!-- maxTotal: Maximum number of database connections in pool. Make sure you
configure your mysqld max_connections large enough to handle
all of your db connections. Set to -1 for no limit.
-->
<!-- maxIdle: Maximum number of idle database connections to retain in pool.
Set to -1 for no limit. See also the DBCP documentation on this
and the minEvictableIdleTimeMillis configuration parameter.
-->
<!-- maxWaitMillis: Maximum time to wait for a database connection to become available
in ms, in this example 10 seconds. An Exception is thrown if
this timeout is exceeded. Set to -1 to wait indefinitely.
-->
<!-- username and password: MySQL username and password for database connections -->
<!-- driverClassName: Class name for the old mm.mysql JDBC driver is
org.gjt.mm.mysql.Driver - we recommend using Connector/J though.
Class name for the official MySQL Connector/J driver is com.mysql.jdbc.Driver.
-->
<!-- url: The JDBC connection url for connecting to your MySQL database.
-->
<Resource name="jdbc/TestDB" auth="Container" type="javax.sql.DataSource"
maxTotal="100" maxIdle="30" maxWaitMillis="10000"
username="javauser" password="javadude" driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/javatest"/>
</Context>
3. web.xml configuration
Now create aWEB-INF/web.xml for this test application.<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">
<description>MySQL Test App</description>
<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/TestDB</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
</web-app>
date to time
public static Calendar DateToCalendar(Date date){
Calendar cal = Calendar.getInstance();
cal.setTime(date);
return cal;
}
獲得現在時間
Calendar calendar= Calendar.getInstance();
Date ss = calendar.getTime();
Utils.log("s:"+ss.toString()); //Wed Feb 18 13:40:59 GMT 2015
GPS intent
https://gist.github.com/adsl99801/f8d8b48b1900234b177e
tvaddr.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {try {//Uri gmmIntentUri = Uri.parse("google.streetview:cbll=25.042137,121.578063");Uri gmmIntentUri = Uri.parse("geo:25.042137,121.578063?q=三統好食品有限公司");Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);mapIntent.setPackage("com.google.android.apps.maps");startActivity(mapIntent);} catch (Exception e) {e.printStackTrace();}}});
dependy Library Project.
http://stackoverflow.com/questions/27536491/how-to-import-android-project-as-library-and-not-compile-it-as-apk-android-stud
解决方案:
在Android工作室,你不能依赖一个Android应用程序模块(APK作为其输出)。你只能依赖于Java库(编译JAR)或Android库模块编译(AAR)
1.delete library project 's AndroidManifest.xml contents:
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
and
2.import as moudule
3.
解决方案:
在Android工作室,你不能依赖一个Android应用程序模块(APK作为其输出)。你只能依赖于Java库(编译JAR)或Android库模块编译(AAR)
1.delete library project 's AndroidManifest.xml contents:
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
and
applicationId
2.import as moudule
3.
In library project's build.gradle file, you'll see a statement like this:
which tells Gradle to build it as an application, generating an APK. If you change it to this:
|
2015年2月17日 星期二
Scroll textview
http://sunylin.pixnet.net/blog/post/91068996-android-textview%E5%A4%9A%E8%A1%8C%E6%9C%AC%E6%96%87%E6%BB%BE%E5%8B%95%E8%BC%95%E9%AC%86%E5%AF%A6%E7%8F%BE
<TextView android:id="@+id/tvCWJ" android:layout_width="fill_parent" android:layout_height="wrap_content" android:scrollbars="vertical" <!--垂直滾動條 --> android:singleLine="false" <!--實現多行 --> android:maxLines="15" <!--最多不超過15行 --> android:textColor="#FF0000" />
gitignore
| # Built application files |
| *.apk |
| *.ap_ |
| # Files for the Dalvik VM |
| *.dex |
| # Java class files |
| *.class |
| # Generated files |
| bin/ |
| gen/ |
| # Gradle files |
| .gradle/ |
| build/ |
| # Local configuration file (sdk path, etc) |
| local.properties |
| # Proguard folder generated by Eclipse |
| proguard/ |
| # Log Files |
| *.log |
2015年2月16日 星期一
避免不小心離開APP
https://gist.github.com/adsl99801/a64698938d097bed612a#file-gistfile1-javaprivate void backKeyPressed(){backKeyPressedCount++;Utils.log("getBackStackEntryCount:" + getChildFragmentManager().getBackStackEntryCount()+",backKeyPressedCount:"+backKeyPressedCount);if (backKeyPressedCount<4) {getChildFragmentManager().popBackStack();showSecondLayout();return;}FinishAppListener finishAppListener = new FinishAppListener() {@Overridepublic void onClick(DialogInterface dialog, int which) {if(which== AlertDialogWhich.Y){EventBus.getDefault().unregister(this);dialog.dismiss();getActivity().finish();}}};resetBackKeyPressedCount();Utils.showAlertDialog(v.getContext(), getResources().getString(R.string.askExistApp),finishAppListener);}
intent phone android
Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + "Your Phone_number"));
startActivity(intent);
Permission in Manifest:
<uses-permission android:name="android.permission.CALL_PHONE" />
color.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<item name="blue5" type="color">#FF33B5E5</item>
<item name="purple" type="color">#FFAA66CC</item>
<item name="green" type="color">#FF99CC00</item>
<item name="orange" type="color">#FFFFBB33</item>
<item name="red" type="color">#FFFF4444</item>
<item name="darkblue" type="color">#FF0099CC</item>
<item name="darkpurple" type="color">#FF9933CC</item>
<item name="darkgreen" type="color">#FF669900</item>
<item name="darkorange" type="color">#FFFF8800</item>
<item name="darkred" type="color">#FFCC0000</item>
<color name="blue">#FF0000FF</color>
<color name="white">#FFFFFF</color>
<color name="black">#000000</color>
</resources>
http://style77125tech.pixnet.net/blog/post/16515723-%5Bandroid%5D-color.xml
<resources>
<item name="blue5" type="color">#FF33B5E5</item>
<item name="purple" type="color">#FFAA66CC</item>
<item name="green" type="color">#FF99CC00</item>
<item name="orange" type="color">#FFFFBB33</item>
<item name="red" type="color">#FFFF4444</item>
<item name="darkblue" type="color">#FF0099CC</item>
<item name="darkpurple" type="color">#FF9933CC</item>
<item name="darkgreen" type="color">#FF669900</item>
<item name="darkorange" type="color">#FFFF8800</item>
<item name="darkred" type="color">#FFCC0000</item>
<color name="blue">#FF0000FF</color>
<color name="white">#FFFFFF</color>
<color name="black">#000000</color>
</resources>
http://style77125tech.pixnet.net/blog/post/16515723-%5Bandroid%5D-color.xml
extends BaseAdapter
http://iamshiao.blogspot.tw/2010/12/androidbaseadapterlistview.html
public class NewsListAdapter extends BaseAdapter {
private String tag =this.getClass().getSimpleName();
private LayoutInflater inflater;
private ArrayList<News> newses;
private ViewHolder holder;
public NewsListAdapter(Context context,ArrayList<News> newses){
inflater = LayoutInflater.from(context);
this.newses=newses;
}
@Override
public int getCount() {
return newses.size();
}
@Override
public Object getItem(int position) {
return newses.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView==null){
convertView = inflater.inflate(R.layout.newslistadapter, parent,false);
holder = new ViewHolder();
holder.tvtitle = (TextView) convertView.findViewById(R.id.tvtitle);
holder.tvdate = (TextView) convertView.findViewById(R.id.tvdate);
convertView.setTag(holder);
}else{
holder = (ViewHolder) convertView.getTag();
}
setValues(position);
return convertView;
}
private void setValues(int position){
News news = newses.get(position);
try{
holder.tvtitle.setText(news.getTitle());
holder.tvdate.setText(news.getAnnosDate());
}catch (Exception e){
e.printStackTrace();
}
}
class ViewHolder {
TextView tvtitle;
TextView tvdate;
}
}
public class NewsListAdapter extends BaseAdapter {
private String tag =this.getClass().getSimpleName();
private LayoutInflater inflater;
private ArrayList<News> newses;
private ViewHolder holder;
public NewsListAdapter(Context context,ArrayList<News> newses){
inflater = LayoutInflater.from(context);
this.newses=newses;
}
@Override
public int getCount() {
return newses.size();
}
@Override
public Object getItem(int position) {
return newses.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView==null){
convertView = inflater.inflate(R.layout.newslistadapter, parent,false);
holder = new ViewHolder();
holder.tvtitle = (TextView) convertView.findViewById(R.id.tvtitle);
holder.tvdate = (TextView) convertView.findViewById(R.id.tvdate);
convertView.setTag(holder);
}else{
holder = (ViewHolder) convertView.getTag();
}
setValues(position);
return convertView;
}
private void setValues(int position){
News news = newses.get(position);
try{
holder.tvtitle.setText(news.getTitle());
holder.tvdate.setText(news.getAnnosDate());
}catch (Exception e){
e.printStackTrace();
}
}
class ViewHolder {
TextView tvtitle;
TextView tvdate;
}
}
2015年2月15日 星期日
volley
private void volley(String url) {
RequestQueue queue = Volley.newRequestQueue(this);
StringRequest request = new StringRequest(Request.Method.GET, url,
new Response.Listener<String>()
{
@Override
public void onResponse(String response) {
// convert the String response to XML
// if you use Simple, something like following should do it
Serializer serializer = new Persister();
try {
} catch (Exception e) {
e.printStackTrace();
}
}
},
new Response.ErrorListener()
{
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(getApplicationContext(), "error:" + error.getMessage(), Toast.LENGTH_LONG).show();
}
}
);
queue.add(request);
}
RequestQueue queue = Volley.newRequestQueue(this);
StringRequest request = new StringRequest(Request.Method.GET, url,
new Response.Listener<String>()
{
@Override
public void onResponse(String response) {
// convert the String response to XML
// if you use Simple, something like following should do it
Serializer serializer = new Persister();
try {
} catch (Exception e) {
e.printStackTrace();
}
}
},
new Response.ErrorListener()
{
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(getApplicationContext(), "error:" + error.getMessage(), Toast.LENGTH_LONG).show();
}
}
);
queue.add(request);
}
android studio Error:Unable to start the daemon process
http://stackoverflow.com/questions/23663299/android-studio-gradle-project-sync-failed/23663535#23663535
http://www.thedevline.com/2014/06/android-studio-unable-to-start-daemon.html
http://www.thedevline.com/2014/06/android-studio-unable-to-start-daemon.html
Just a blind guess: try to add something like this to your gradle.properties file in the project:
org.gradle.jvmargs=-Xmx512m -XX:MaxPermSize=512m
ec2-tomcat8 上傳war問題
http://juristr.com/blog/2010/12/tomcat-illegalstateexception-no-output/
chown -R Juri apache-tomcat-6.0.29
2015年2月14日 星期六
TomcatHibernate hibernate.cfg.xml
http://wiki.apache.org/tomcat/TomcatHibernate
http://www.journaldev.com/2905/hibernate-tomcat-jndi-datasource-example-tutorial
http://www.blogjava.net/amigoxie/archive/2007/12/29/171395.html
http://www.journaldev.com/2905/hibernate-tomcat-jndi-datasource-example-tutorial
http://www.blogjava.net/amigoxie/archive/2007/12/29/171395.html
xml read simple
http://simple.sourceforge.net/download/stream/doc/tutorial/tutorial.php
butAdd.setOnClickListener(new Button.OnClickListener(){
@Override
public void onClick(View v) {
String response="<XML_Head><Infos><Info Id=\"C1_315080500H_000007\" Name=\"水璉、牛山海岸\" Zone=\"\" /></Infos></XML_Head>";
tv1.setText(response);
Serializer serializer = new Persister();
//Infos data= null;
XML_Head xML_Head=null;
try {
xML_Head = serializer.read(XML_Head.class, response, false);
String name=xML_Head.getInfos().getInfo().getName();
Toast.makeText(getApplicationContext(), "name:" + name, Toast.LENGTH_LONG).show();
} catch (Exception e) {
e.printStackTrace();
tv1.setText(e.toString());
}
}
});
字串長得像這樣
<XML_Head>
<Infos>
<Info Id="C1_315080500H_000007" Name="水璉、牛山海岸" Zone="" />
</Infos>
</XML_Head>
記得要填
(name="XML_Head")
butAdd.setOnClickListener(new Button.OnClickListener(){
@Override
public void onClick(View v) {
String response="<XML_Head><Infos><Info Id=\"C1_315080500H_000007\" Name=\"水璉、牛山海岸\" Zone=\"\" /></Infos></XML_Head>";
tv1.setText(response);
Serializer serializer = new Persister();
//Infos data= null;
XML_Head xML_Head=null;
try {
xML_Head = serializer.read(XML_Head.class, response, false);
String name=xML_Head.getInfos().getInfo().getName();
Toast.makeText(getApplicationContext(), "name:" + name, Toast.LENGTH_LONG).show();
} catch (Exception e) {
e.printStackTrace();
tv1.setText(e.toString());
}
}
});
字串長得像這樣
<XML_Head>
<Infos>
<Info Id="C1_315080500H_000007" Name="水璉、牛山海岸" Zone="" />
</Infos>
</XML_Head>
記得要填
(name="XML_Head")
2015年2月9日 星期一
derby
http://www.vogella.com/tutorials/EclipseDataToolsPlatform/article.html
http://dbeaver.jkiss.org/
http://help.eclipse.org/luna/index.jsp?topic=%2Forg.eclipse.datatools.common.doc.user%2Fdoc%2Fhtml%2Fasc1229700386276.html
CREATE TABLE player (
`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
name varchar null,
lv int null,
exp int null,
hp int null
);
http://dbeaver.jkiss.org/
http://help.eclipse.org/luna/index.jsp?topic=%2Forg.eclipse.datatools.common.doc.user%2Fdoc%2Fhtml%2Fasc1229700386276.html
CREATE TABLE player (
`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
name varchar null,
lv int null,
exp int null,
hp int null
);
2015年2月1日 星期日
訂閱:
意見 (Atom)