2014年11月27日 星期四

android viewpager solve setCurrentItem not working

mActivity.runOnUiThread(new Runnable() {  
         public void run()  
         {  
          try{
mPager.setCurrentItem(page);
          }catch(Exception e){
       
          }
     
         }  
     });  

Android 解決android AnimationDrawable out of memory 問題

在 AndroidManifest.xml  的 application 裡加  android:largeHeap="true",可能是圖片過大造成
參考網址 http://stackoverflow.com/questions/22256097/out-of-memory-error-when-using-animationdrawable

2014年11月26日 星期三

Android 抓取網路圖片(picasso)

目前我都是用picasso來抓取,速度滿快的,語法簡單又有緩存功能

官網參考

使用方法

ImageView  imageView  = (ImageView) findViewById(R.id.image);

Picasso.with(context).load("http://i.imgur.com/DvpvklR.png").into(imageView);

andorid TextView 限定行數+...

 //限定3行
android:maxLines="3"

//超過maxLines+...
  android:ellipsize="end"


android:scrollHorizontally="true"
android:singleLine="true"

Android 解決點擊按钮弹出Dialog,第二次出現問題

 參考網址 http://www.eoeandroid.com/thread-264875-1-1.html AlertDialog.Builder builder = new AlertDialog.Builder(mActivity); LayoutInflater factory = LayoutInflater.from(mActivity); v1 = factory.inflate(R.layout.share, null); builder.setView(v1);

Liferay 更改數據庫為MySQL

tomcat-7.0.27\webapps\ROOT\WEB-INF\classes裡創protal-ext.properties

Liferay中自帶有一個示例數據庫(HSQL),如何更改為自己想要的數據庫呢?一.刪除示例數據庫 [liferay-home]/tomcat-[version number]/webapps\sevencogs-hook 將該目錄移除(備份到別的地方而非刪除)二.安裝MySQL,創建數據庫lportal 三.連接Liferay和MySQL 1.[liferay-home]/目錄新建文件portal-ext.properties 因為該文件的優先級高於默認配置文件,因此將覆蓋原文件中liferay與HQL連接2.portlet-ext.properties文件內容
1
#
2
# MySQL
3
#
4
jdbc.default.driverClassName=com.mysql.jdbc.Driver
5
jdbc.default.url=jdbc:mysql://localhost/lportal?
6
useUnicode=true&characterEncoding=UTF-8&useFastDateParsing=false
7
jdbc.default.username=你的用戶名
8
jdbc.default.password=你的密碼
3.關於JDBC驅動
Liferay已自帶MySQL JDBC驅動,位於[Tomcat Home]/lib/ext/mysql.jar 
如果使用其他Database,將驅動複製到該目錄下即可四.啟動Server,自動創建相關的表格

Liferay 同時連接不同資料庫

更改額外DB
1.建立portal-ext.properties (\tomcat-7.0.27\webapps\ROOT\WEB-INF\classes)
2.建立service.xml and bulid
3.建立ext-spring.xml (文件路徑/ WEB-INF/src/META-INF/ext-spring.xml) and bulid



portal-ext.properties 如下

jdbc.default.url=jdbc\:mysql\://localhost/liferay612?useUnicode\=true&characterEncoding\=UTF-8&useFastDateParsing\=false
jdbc.default.driverClassName=com.mysql.jdbc.Driver
jdbc.default.username=root
jdbc.default.password=root
jdbc.test .driverClassName=com.mysql.jdbc.Driver
jdbc.test .url=jdbc:mysql://localhost/testE?useUnicode=true&characterEncoding=UTF-8&useFastDateParsing=false
jdbc.test .username=root
jdbc.test .password=root


service.xml 如下
<entity name="TableFromAnotherDataSource" table="TableFromAnotherDataSource" local-service="true" remote-service="true" data-source="anotherDataSource" session-factory="anotherSessionFactory">
<column name="testId" type="long" primary="true" />
<column name="description" type="String" />
/entity>
資料庫的資料表要自己建,額外DB不會自動建。



ext-spring.xml file 如下






<?xml version="1.0"?>
<beans default-destroy-method="destroy" default-init-method="afterPropertiesSet"
xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">

<bean id="anotherDataSource"
class="org.springframework.jdbc.datasource.LazyConnectionDataSourceProxy">
<property name="targetDataSource" ref="anotherDataSourceWrapper" />
</bean>
<bean id="anotherDataSourceImpl"
class="com.liferay.portal.dao.jdbc.spring.DataSourceFactoryBean">
<property name="propertyPrefix" value="jdbc.test." />
</bean>
<bean id="anotherDataSourceWrapper" class="com.liferay.portal.dao.jdbc.util.DataSourceWrapper">
<constructor-arg ref="anotherDataSourceImpl" />
</bean>
<bean class="com.liferay.portal.dao.jdbc.util.DataSourceSwapper">
<property name="liferayDataSourceWrapper" ref="anotherDataSourceWrapper" />
</bean>
<bean id="anotherHibernateSessionFactory" class="com.liferay.portal.kernel.spring.util.SpringFactoryUtil"
factory-method="newBean">
<constructor-arg
value="com.liferay.portal.spring.hibernate.PortletHibernateConfiguration" />
<constructor-arg>
<map>
<entry key="dataSource" value-ref="anotherDataSource" />
</map>
</constructor-arg>
</bean>
<bean id="anotherSessionFactory" class="com.liferay.portal.kernel.spring.util.SpringFactoryUtil"
factory-method="newBean">
<constructor-arg
value="com.liferay.portal.dao.orm.hibernate.PortletSessionFactoryImpl" />
<constructor-arg>
<map>
<entry key="dataSource" value-ref="anotherDataSource" />
<entry key="sessionFactoryClassLoader" value-ref="portletClassLoader" />
<entry key="sessionFactoryImplementor" value-ref="anotherHibernateSessionFactory" />
</map>
</constructor-arg>
</bean>
</beans>

JAVA

TableFromAnotherDataSourceImpl tableFromDefaultDataSource = new TableFromAnotherDataSourceImpl();
long testId = CounterLocalServiceUtil.increment(TableFromAnotherDataSourceImpl.class.getName());
tableFromDefaultDataSource.setTestId(testId);
tableFromDefaultDataSource.setDescription("hi");
TableFromAnotherDataSourceLocalServiceUtil.addTableFromAnotherDataSource(tableFromDefaultDataSource);

Liferay ActionRequest

Liferay  ActionRequest



java 檔


package com.liferay.samples;


import java.io.IOException;

import javax.portlet.ActionRequest;

import javax.portlet.ActionResponse;

import javax.portlet.PortletException;

import javax.portlet.PortletPreferences;

import com.liferay.portal.kernel.servlet.SessionMessages;

import com.liferay.util.bridges.mvc.MVCPortlet;


public class MyGreetingPortlet extends MVCPortlet {

    @Override

    public void processAction(

            ActionRequest actionRequest, ActionResponse actionResponse)

        throws IOException, PortletException {

        PortletPreferences prefs = actionRequest.getPreferences();

        String greeting = actionRequest.getParameter("greeting");

        if (greeting != null) {

            prefs.setValue("greeting", greeting);

            prefs.store();

       

        }

        SessionMessages.add(actionRequest, "success");

        super.processAction(actionRequest, actionResponse);

    }

}


view.jsp


<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet"%>

<%@ taglib uri="http://liferay.com/tld/aui" prefix="aui"%>

<%@ taglib uri="http://liferay.com/tld/ui" prefix="liferay-ui"%>

<%@ page import="com.liferay.portal.kernel.util.ParamUtil"%>

<%@ page import="com.liferay.portal.kernel.util.Validator"%>

<%@ page import="javax.portlet.PortletPreferences"%>

<portlet:defineObjects />

<%

 PortletPreferences prefs = renderRequest.getPreferences();


 String greeting = (String) prefs.getValue("greeting",

 "Hello! Welcome to our portal.");

%>

<liferay-ui:success key="success" message="Greeting saved successfully!" />

<portlet:actionURL var="editGreetingURL">

 <portlet:param name="jspPage" value="/view.jsp" />

</portlet:actionURL>

<aui:form action="<%=editGreetingURL%>" method="post">

 <aui:input label="greeting" name="greeting" type="text"

 value="<%=greeting%>" />

 <aui:button type="submit" />

</aui:form>

<portlet:renderURL var="viewGreetingURL">

 <portlet:param name="jspPage" value="/view.jsp" />

</portlet:renderURL>

<p>

 <a href="<%=viewGreetingURL%>">Back</a>

</p>


注:

portlet.xml要加<portlet-class>package name.java name</portlet-class>