2015年7月30日 星期四

Android-圖片處理 OOM

未完成

Picasso
Glide


ImageView imageView = new ImageView(context);Picasso.with(getActivity()).load(phothLink).resize(300,300).into(imageView);

<application
        android:largeHeap="true"
        android:name=".activity.MyApplication"
        android:allowBackup="true"
        .
        .
        .

2015年7月28日 星期二

Android-半透明 Button Activity

以下方法可以產生 : 透明、半透明 效果
1 . 半透明
android:background="#e0000000"

2 . 透明
android:background="#00000000"

但是此方法是
針對元件!!!
針對元件!!!
針對元件!!!

如果真的要達到 Activity 透明
那就要使用主題了
有兩種方法可以選擇( 二選一 ) :

1 . 在 AndroidManifest 的 activity 中,添加原生風格( 全透明 )
<activity
    android:name="HelloActivity"
    android:theme="@android:style/Theme.Transparent" >
</activity>

2 . 自訂風格
1) 新增要使用的透明顏色
<color name="my_theme_color">#e0000000</color>

2) 自定義風格
<style name="Theme.Transparent" parent="android:Theme">
    <item name="android:windowBackground">@color/my_theme_color</item>
    <item name="android:windowContentOverlay">@null</item>
    <item name="android:windowIsTranslucent">true</item>
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowIsFloating">true</item>
    <item name="android:backgroundDimEnabled">false</item>
</style>

3) 在 AndroidManifest 的 activity, 套用自定義風格
<activity
    android:name="MyActivity"
    android:theme="@style/Theme.Transparent" >
</activity>


參考資訊 : Activity透明/半透明效果
參考資訊 : [Android]Button背景透明或半透明
參考資料 : [Android] 背景が半透明の Activity を作る

參考資料:设置 DialogFragment 的背景颜色透明
參考資訊 : 如何在 Android 裡製作一個透明背景的 Activity?
歡迎轉載,請註明出處。

2015年7月27日 星期一

2015年7月26日 星期日

2015年7月24日 星期五

Android-Gradle 版本管控

為甚麼要用Gradle
其中之一是,可以管理相關的Jar

比如說 : 
A 工程師開發有遇到問題請教 B 工程師
但B的工程師開發環境都跟A相同嗎??

雙方用的 Jar 版本跟來源也都會一致嗎?

為了解決這問題
AS在 build.gradle內已經針對此問題作管理

Project -> build.gradle

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:22.2.0'
}

在 Maven 內
可以找到您所需要的

Maven

更簡單的說明 :
如果您不用下載 Gson.jar
只要在 Gradle新增
如圖對應的位置

















dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:22.2.0'
    compile 'com.google.code.gson:gson:2.3.1'
}

之行第一次後就會存一份在您Local端,不需在下載
如果B工程師也用相對應的方式
就直接抓對應的 Jar

記得,如果要只用 Jar 請先 Refresh!!!

歡迎轉載,請註明出處。

2015年7月21日 星期二

Android-Activity 繼承與實作

想必大家對繼承不陌生吧
先來舉幾個簡單的範例
比如 : 
今天客戶要求設計10頁風格、擺設一樣的介面
您不可能一頁一頁慢慢的設計
如果心血來潮,又要更改擺設跟風格
又加上這次是100頁,那豈不是改到海枯石爛都改不完
這時繼承就是您的好朋友
您只需要更改特定的模板
全部被套用的也跟著一起更改
這就是繼承的好處?

介面只需要三個 TextView

首先我們要寫一個模板

public abstract class MainTitle extends Activity{

    //------ 1 . Start -------//
    private TextView leftText;
    
    public void setLeftName(String strLeftTitle){
        leftText.setText(strLeftTitle);
    }

    //------ End -------//
    
    //------ 2 . Start -------//
    public abstract String getTextTitle();
    //------ End -------//
    
    //------ 3 . Start -------//
    public void onCreateRightTitle(TextView rightTitle){}
    //------ End -------//
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_base_title);

        leftText = (TextView)findViewById(R.id.text_Left);
        
        TextView centerText = (TextView)findViewById(R.id.text_Center);
        centerText.setText(getTextTitle());
        
        TextView rightText = (TextView)findViewById(R.id.text_Right);
        onCreateRightTitle(rightText);

    };
    
}

套用模板
public class GActivity extends MainTitle {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        // 1 
        setLeftName("左邊");
        
    }

    // 2 
    @Override
    public String getTextTitle() {
        
        return "中間";
    }

    // 3 
    @Override
    public void onCreateRightTitle(TextView rightTitle) {
        super.onCreateRightTitle(rightTitle);
        rightTitle.setText("右邊");
    }

}



歡迎轉載,請註明出處。

2015年7月15日 星期三

Android-MonkeyTalk


buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.1.1'
        classpath 'com.uphyca.gradle:gradle-android-aspectj-plugin:0.9.12'
    }
}
apply plugin: 'com.android.application'
apply plugin: 'android-aspectj'

repositories {
    jcenter()
}

android {
    compileSdkVersion 22
    buildToolsVersion "22.0.1"

    defaultConfig {
        applicationId "com.helloandroid.hello"
        minSdkVersion 9
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_6
        targetCompatibility JavaVersion.VERSION_1_6
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        monkeytalk.initWith(buildTypes.debug)
        monkeytalk {
            applicationIdSuffix ".monkey"
        }
    }
}

dependencies {
    monkeytalkCompile fileTree(dir: 'monkey-libs', include: ['*.jar'])
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:22.2.0'
}



參考資料 : Using MonkeyTalk in AndroidStudio

2015年7月14日 星期二

Android-Appium 自動化測試 ( 二 )_腳本TestNG

IDE : Eclipse
編輯器 : TestNG

















  • 創立 Java Project
  • 點擊 Project右鍵 configure
  • 點選 Convert to Maven Project
  • 出現 Create new POM 不需做額外設定,直接點 Finish
  • 在 Java Project 下新增 apps ( floder )
  • 在上一步生成的檔案下新增 ContactManager ( floder )
  • 在 ContactManager floder 放置您要測試的App.apk


在 pom.xml 新增
    .    
    .
    .
        </plugins>
    </build>
    <dependencies>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>LATEST</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.appium</groupId>
            <artifactId>java-client</artifactId>
            <version>3.2.0</version>
        </dependency>
        <dependency>
            <groupId>com.saucelabs</groupId>
            <artifactId>sauce_junit</artifactId>
            <version>2.1.20</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>6.1.1</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
    .
    .
    .


新增完畢後,點選 pom.xml 右鍵( Run As -> Maven install )

--------------------------------------


在 Src 下,新增 AndroidContactsTest.java
import java.io.File;
import java.net.URL;
import java.util.HashMap;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.Capabilities;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.HasTouchScreen;
import org.openqa.selenium.interactions.TouchScreen;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteTouchScreen;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.remote.RemoteWebElement;

public class AndroidContactsTest {

    private WebDriver driver;

    @Before
    public void setUp() throws Exception {
        
        // 不用更改(因Apk直接放在路徑下)
        File classpathRoot = new File(System.getProperty("user.dir"));
        // 預設路徑
        File appDir = new File(classpathRoot, "/apps/ContactManager");
        // 測試App的完整名稱
        File app = new File(appDir, "adapterCallback.apk");
        
        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
        capabilities.setCapability("device", "Android");     
        capabilities.setCapability("platformName", "Android");


        // 模擬器
        capabilities.setCapability("deviceName","Android Emulator");
        // 實體手機
        capabilities.setCapability("deviceName","Android");
        // 手機/模擬器版本
        capabilities.setCapability("platformVersion", "4.4");
        capabilities.setCapability("app", app.getAbsolutePath());
        // Laurch "package"
        capabilities.setCapability("appPackage", "com.example.adaptercallback");
        // Laurch "Activity"
        capabilities.setCapability("appActivity", ".MainActivity");
        // Appium IP Address : Port *Appium主機位置
        driver = new SwipeableWebDriver(new URL("http://192.168.0.105:4723/wd/hub")
                        , capabilities);

    }

    @After
    public void tearDown() throws Exception {
        driver.quit();
    }

    @Test
    public void addContact(){
        // 腳本
        WebElement btn = driver.findElement(By.id("button"));
        btn.click();

        WebElement editText = driver.findElement(By.id("editText_0"));
        editText.sendKeys("Hello");
        
    }

    public class SwipeableWebDriver extends RemoteWebDriver implements 
                HasTouchScreen {
            
        private RemoteTouchScreen touch;

        public SwipeableWebDriver(URL remoteAddress, 
            Capabilities desiredCapabilities) {
            
            super(remoteAddress, desiredCapabilities);
            touch = new RemoteTouchScreen(getExecuteMethod());
        }

        @Override
        public TouchScreen getTouch() {
        
            return touch;
        }
    }
}


以下是腳本功能指令 :

輸入文字 :
WebElement btn_00 = driver.findElement(By.id("edit_WriteString"));
btn_00.sendKeys(new String[] { "sample567977" });

點擊按鈕 :
WebElement btn_01 = driver.findElement(By.id("button_Click"));
btn_01.click();

隱藏鍵盤 :
driver.hideKeyboard();

實體按鍵 :
driver.pressKeyCode(4);

KEYCODE_HOME is 3
KEYCODE_BACK is 4
KEYCODE_MENU is 82

利用 JUnit Test 執行
( PS : 一定要開 Appium )

參考資料 : TestNG使用Eclipse建立Test Case

參考資料 : How to click on home back and recent button in android?

參考資料 : Appium手機自動化測試模擬手勢的基本操作

參考資料 : Appium手機自動化測試從頭學 –Windows/Android環境安裝篇
參考資訊 : Android自动化工具Appium的使用
參考資訊 : maven学习教程:What、How、Why
參考資訊 : The following desired capabilities are required, but were not provided: platformName, deviceName

2015年7月9日 星期四

Android-Fragment 簡易說明

建立Fragment頁面時到底要匯入V4開發包?原生SDK?

簡單的說 : 

V4 開發包 : 針對Android 3.0 以下(API 11 以下用戶 )設置。
原生SDK : 針對Android 3.0以上 ( API 11 以上用戶 ) 設置。

加載方式 : 靜態 、 動態
靜態加載
fragment
動態加載
LinearLayout

直接介紹最常用的動態加載

剛開始接觸的大大一定會被網路上多個範例搞得頭昏腦脹吧 !
我們直接用手機介面介紹( 官方有介紹平板跟手機的應用 )

以下的圖,是我所想到離生活最近的範例。













其實真的不用想太多
1 . 在 Activity 劃一個投影區塊(LinearLayout)
2 . 新增繼承 Fragment 的頁面
3 . 在 Activity 的 LinearLayout 載入 Fragment
4 . 結束

以下有範例,只需要新增此程式,不須註冊 Activity

frist_fragment.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="match_parent"
    android:gravity="center"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="20sp"
        android:text="Frist" />

</LinearLayout>

FristFragment.java
import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

public class FristFragment extends Fragment{
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        
        // 
        View view = inflater.inflate(R.layout.frist_fragment, container, false);

        return view;
    }

}

activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <LinearLayout
        android:id="@+id/linearLayout_01"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/textView1"
            android:visibility="gone"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="TextView" />

    </LinearLayout>

</RelativeLayout>

MainActivity.java


import android.app.Activity;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.os.Bundle;

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        FristFragment fragment2=new FristFragment();
        FragmentManager fragmentManager = getFragmentManager();
        FragmentTransaction beginTransaction = fragmentManager.beginTransaction();
        beginTransaction.add(R.id.linearLayout_01, fragment2);
        beginTransaction.addToBackStack(null);
        beginTransaction.commit();

        // 或

        if (savedInstanceState == null) {
            getFragmentManager()
                .beginTransaction()
                .add(R.id.linearLayout_1, new FristFragment())
                .commit();
        }
        
    }
}

至於為什麼要加 addToBackStack?















參考資訊 : Android Fragment

歡迎轉載,請註明出處。

Android-自定義按鍵處發顏色


相關聯結 : Android: change font color on click
相關聯結 : Android Shape

Android-桌面懸浮效果

連結 : Android桌面悬浮窗效果实现,仿360手机卫士悬浮窗效果

2015年7月8日 星期三

2015年7月7日 星期二

Android-Drag and Drop 拖放功能

更新項目 : 20150901( 資料佈局、動作說明 )

View imageView = new ImageView(this);

imageView.setOnDragListener(this);

// 以下為官方範例擷取
protected class myDragEventListener implements View.OnDragListener {

    // This is the method that the system calls when it dispatches a drag event to the
    // listener.
    public boolean onDrag(View v, DragEvent event) {

        // Defines a variable to store the action type for the incoming event
        final int action = event.getAction();

        switch(action) {

            case DragEvent.ACTION_DRAG_STARTED:
                // 圖形拔除
                return false;

            case DragEvent.ACTION_DRAG_ENTERED:
               // 圖形貼上
                return true;

            case DragEvent.ACTION_DRAG_LOCATION:
               // 正在設置監聽的區塊內
                return true;

            case DragEvent.ACTION_DRAG_EXITED:
               // 離開設置監聽的區塊內
                return true;

            case DragEvent.ACTION_DROP:
              // 拖曳
                return true;

            case DragEvent.ACTION_DRAG_ENDED:
                return true;

            default:

                break;
        }
        
        return false;
    }
};


圖形解說 :











未整理


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/LinearLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <LinearLayout
        android:id="@+id/toplinear"
        android:layout_width="fill_parent"
        android:layout_height="170dp"
        android:background="#aaaaaa"
        android:layout_marginBottom="10dp" >

        <ImageView
            android:id="@+id/image_2"
            android:layout_width="50dip"
            android:layout_height="50dip"
            android:layout_margin="4dip"
            android:src="@drawable/m_2" />
        <ImageView
            android:id="@+id/image_3"
            android:layout_width="50dip"
            android:layout_height="50dip"
            android:layout_margin="4dip"
            android:src="@drawable/m_3" />
        <ImageView
            android:id="@+id/image_4"
            android:layout_width="50dip"
            android:layout_height="50dip"
            android:layout_margin="4dip"
            android:src="@drawable/m_4" />
        

    </LinearLayout>

    <LinearLayout
        android:id="@+id/bottomlinear"
        android:layout_width="fill_parent"
        android:layout_height="170dp"
        android:background="#555555"
        android:layout_marginBottom="10dp" >

        <TextView
            android:id="@+id/text"
            android:layout_width="100dp"
            android:layout_height="100dp"
            android:text="Drag the image and drop it here..." />

    </LinearLayout>
    
    <LinearLayout
        android:id="@+id/bottomlinear_2"
        android:layout_width="fill_parent"
        android:layout_height="170dp"
        android:background="#555555" >

        <TextView
            android:id="@+id/text_2"
            android:layout_width="100dp"
            android:layout_height="100dp"
            android:text="Drag the image and drop it here..." />

    </LinearLayout>
</LinearLayout>


import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.content.ClipData;
import android.content.ClipDescription;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.DragEvent;
import android.view.View;
import android.view.View.DragShadowBuilder;
import android.view.View.OnDragListener;
import android.view.View.OnLongClickListener;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends Activity {

    private List<String> listInfo;
    
    private ImageView myImage_2;
    private ImageView myImage_3;
    private ImageView myImage_4;
    
    private static final String IMAGEVIEW_TAG = "The Android Logo";

    /** Called when the activity is first created. */

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        listInfo = new ArrayList<String>();
        for(int i = 0; i<10; i++){
            String a = null;
            a = ""+ i%3;
            listInfo.add(""+ a);
        }
        
        init();

        setListener();

    }

    private void init(){
        
        myImage_2 = (ImageView)findViewById(R.id.image_2);
        myImage_3 = (ImageView)findViewById(R.id.image_3);
        myImage_4 = (ImageView)findViewById(R.id.image_4);
        // Sets the tag
        myImage_2.setTag(IMAGEVIEW_TAG);
        myImage_3.setTag(IMAGEVIEW_TAG);
        myImage_4.setTag(IMAGEVIEW_TAG);
        
    }

    private void setListener(){
        
        // set the listener to the dragging data
        myImage_2.setOnLongClickListener(new MyClickListener());
        myImage_3.setOnLongClickListener(new MyClickListener());
        myImage_4.setOnLongClickListener(new MyClickListener());

        findViewById(R.id.toplinear).setOnDragListener(new MyDragListener());
        findViewById(R.id.bottomlinear).setOnDragListener(new MyDragListener());
        findViewById(R.id.bottomlinear_2).setOnDragListener(new MyDragListener());
        
    }

    private final class MyClickListener implements OnLongClickListener {

        // called when the item is long-clicked
        @Override
        public boolean onLongClick(View view) {
            // TODO Auto-generated method stub

            // create it from the object's tag
            ClipData.Item item = new ClipData.Item((CharSequence)view.getTag());

            String[] mimeTypes = { ClipDescription.MIMETYPE_TEXT_PLAIN };
            ClipData data = new ClipData(view.getTag().toString(), mimeTypes, item);
            DragShadowBuilder shadowBuilder = new View.DragShadowBuilder(view);

            view.startDrag( data, //data to be dragged
                    shadowBuilder, //drag shadow
                    view, //local data about the drag and drop operation
                    0   //no needed flags
                    );


            view.setVisibility(View.INVISIBLE);
            return true;
        }    
    }

    class MyDragListener implements OnDragListener {
        Drawable normalShape = getResources().getDrawable(R.drawable.normal_shape);
        Drawable targetShape = getResources().getDrawable(R.drawable.target_shape);

        @Override
        public boolean onDrag(View v, DragEvent event) {

            // Handles each of the expected events
            switch (event.getAction()) {

            //signal for the start of a drag and drop operation.
            case DragEvent.ACTION_DRAG_STARTED:
                // do nothing
                break;

                //the drag point has entered the bounding box of the View
            case DragEvent.ACTION_DRAG_ENTERED:
                v.setBackground(targetShape);    //change the shape of the view
                break;

                //the user has moved the drag shadow outside the bounding box of the View
            case DragEvent.ACTION_DRAG_EXITED:
                v.setBackground(normalShape);    //change the shape of the view back to normal
                break;

                //drag shadow has been released,the drag point is within the bounding box of the View
            case DragEvent.ACTION_DROP:
                // if the view is the bottomlinear, we accept the drag item
                if(v == findViewById(R.id.bottomlinear)) {
                    View view = (View) event.getLocalState();
                    ViewGroup viewgroup = (ViewGroup) view.getParent();
                    viewgroup.removeView(view);

                    //change the text
                    TextView text = (TextView) v.findViewById(R.id.text);
                    text.setText("The item is dropped");

                    LinearLayout containView = (LinearLayout) v;
                    containView.addView(view);
                    view.setVisibility(View.VISIBLE);
                } else if(v == findViewById(R.id.bottomlinear_2)) {
                    View view = (View) event.getLocalState();
                    ViewGroup viewgroup = (ViewGroup) view.getParent();
                    viewgroup.removeView(view);

                    //change the text
                    TextView text = (TextView) v.findViewById(R.id.text_2);
                    text.setText("The item is dropped");

                    LinearLayout containView = (LinearLayout) v;
                    containView.addView(view);
                    view.setVisibility(View.VISIBLE);
                } else if(v == findViewById(R.id.toplinear)) {
                    View view = (View) event.getLocalState();
                    ViewGroup viewgroup = (ViewGroup) view.getParent();
                    viewgroup.removeView(view);

                    LinearLayout containView = (LinearLayout) v;
                    containView.addView(view);
                    view.setVisibility(View.VISIBLE);
                } else {
                    View view = (View) event.getLocalState();
                    view.setVisibility(View.VISIBLE);
                    Context context = getApplicationContext();
                    Toast.makeText(context, "You can't drop the image here", 
                            Toast.LENGTH_LONG).show();
                    break;
                }
                break;

                //the drag and drop operation has concluded.
            case DragEvent.ACTION_DRAG_ENDED:
                v.setBackground(normalShape);    //go back to normal shape

            default:
                break;
            }
            return true;
        }
    }


參考 : 連結
參考 : CoolDragAndDrop
參考 : Using drag and drop in your application
參考 : Extending GridView with Drag and Drop for Grouping and Variable Sized Items
參考 : Drag and Drop between ListView and GridView

Android-Increase multi ImageView on View

未整理

XML
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button" />

    <LinearLayout
        android:id="@+id/inhorizontalscrollview"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <HorizontalScrollView
            android:id="@+id/horizontalScrollView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="horizontal" >

                <ImageView
                    android:id="@+id/imageView1"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:src="@drawable/ic_launcher"
                    android:visibility="gone" />

            </LinearLayout>
        </HorizontalScrollView>

    </LinearLayout>

    <Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button" />

    <LinearLayout
        android:id="@+id/inscrollview"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

        <ScrollView
            android:id="@+id/scrollView1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical" >

                <ImageView
                    android:id="@+id/imageView2"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:src="@drawable/ic_launcher"
                    android:visibility="gone" />

            </LinearLayout>
        </ScrollView>

    </LinearLayout>

</LinearLayout>

java
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;

public class MainActivity extends Activity {

    Button addinHorizontalScrollView, addinScrollView;
    LinearLayout inHorizontalScrollView, inScrollView;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        
        inHorizontalScrollView = 
                (LinearLayout)findViewById(R.id.inhorizontalscrollview);
        inScrollView = 
                (LinearLayout)findViewById(R.id.inscrollview);

        addinHorizontalScrollView = (Button)findViewById(R.id.button1);
        addinHorizontalScrollView.setOnClickListener(new OnClickListener(){

            @Override
            public void onClick(View arg0) {
                addImageView(inHorizontalScrollView);
            }});

        addinScrollView = (Button)findViewById(R.id.button2);
        addinScrollView.setOnClickListener(new OnClickListener(){

            @Override
            public void onClick(View arg0) {
                addImageView(inScrollView);
            }});

    }

    private void addImageView(LinearLayout layout){
        ImageView imageView = new ImageView(this);
        imageView.setImageResource(R.drawable.ic_launcher);
        layout.addView(imageView);
    }

}

如果要設示ImageView的長寬
.
.
.
// 設置元件 "寬度"、"高度"
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(300, 500);
// 設置元件間距 "左"、"上"、"右"、"下"
params.setMargins(50, 5, 5, 5);
layout.addView(imageView, params);


來源 : 連結
如果要採用自己的介面 : LayoutInflater.inflate方法解析

2015年7月6日 星期一

Android-Monkey 點擊手機 壓力測試

Monkey 壓力測試

Monkey不等於Monkey Talk!
Monkey不等於Monkey Talk!
Monkey不等於Monkey Talk!

1 . 有需要額外安裝檔嗎?

A : Monkey 是 Android SDK 自帶的工具。

----------------------------------------------------------------

2 . 那Monkey 跟 Monkey Talk 差異?

Monkey : 偏向在應用程式隨機亂點。

Monkey Talk : 有腳本,會著您錄製的流程點擊。

----------------------------------------------------------------

3 . 如何測試

首先一定要先設置環境變數(教學)
在命令提示字元輸入

adb shell monkey -v 100
( 在手機畫面隨機點擊100下,也包括海苔條!!! )
PS :  第一次點擊參數別超過100!!!

相關設定及參數請參考以下連結。

連結 : 位置

歡迎轉載,請註明出處。

2015年7月5日 星期日

Arduino-ESP8266 Wifi 模組


AT Command
功能
-AT
測試溝通
-AT+RST
重製裝置
-AT+GMS
顯示韌體版本

AT Command
功能
備註
-AT+CWMODE?
顯示模組現在的模式

-AT+CWMODE=1(123)
設定模組現在模式
1 . Station
2 . AP
3 . AP & Station
-AT+CWLAP
掃描周邊Wifi
Mode:1
若不是1,則無法掃描顯示
-AT+CWJAP
連線
PS : 
-AT+CWJAP="SSID","pass"
-AT+CWQAP
離線



AT Command
功能
備註
-AT+CIPSR
查詢IP位置

-AT+CIPSTART
連到伺服器
-AT+CIPSTART="TCP",
"www.yahoo.com.tw",80
-AT+CIPSTATUS
顯示連線位置

-AT+CIPSEND
發送訊息。先送字串Btye
-AT+CIPSEND=5
hello
-AT+CIPCLOSE
停止發送訊號


AT Command
功能
-+IPD
接收Service傳來的封包


2015年7月3日 星期五

Android-Fabric Crashlytics

官方網站 :
安裝檔案 : 連結

1 . 在 Gradlew 底下新增
目前更新 2.5.0 無法Build過
請先更改2.4.0 版本
.
.
.
dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:22.2.0'
    compile('com.crashlytics.sdk.android:crashlytics:2.4.0@aar') {
        transitive = true;
    }
    .
    .
    .
}

2 . 在 libs 底下放置 felix.jar

Android-httpclient

http://solvedstack.com/questions/android-project-using-httpclient-http-client-apache-post-get-method