当前位置:  编程技术>移动开发
本页文章导读:
    ▪viewFlow实现相仿淘宝的自动播放        viewFlow实现类似淘宝的自动播放   ImageAdapter.java /* * Copyright (C) 2011 Patrik �kerfeldt * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * .........
    ▪ 图片热区点击之二(地界反弹,缩放,移动)        图片热区点击之二(边界反弹,缩放,移动) 背景:对图片的部分区域进行点击,响应相应的事件(可对图片进行放大,边界反弹,以及图片移动) 针对于前次的热区点击做了个补充  1.对图片的部分区.........
    ▪ spring xd 参照指南       spring xd 参考指南 http://docs.spring.io/spring-xd/docs/1.0.0.M2/reference/html/参考指南引言概观Spring XD is a unified, distributed, and extensible service for data ingestion, real time analytics, batch processing, and data export. Spr.........

[1]viewFlow实现相仿淘宝的自动播放
    来源: 互联网  发布时间: 2014-02-18
viewFlow实现类似淘宝的自动播放

 

ImageAdapter.java
/*
 * Copyright (C) 2011 Patrik �kerfeldt
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.viewflowtest.cjy;

import java.util.List;

import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.Toast;

import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.display.RoundedBitmapDisplayer;
import com.yooeee.ziyoutong.R;

public class ImageAdapter extends BaseAdapter {
//	private DisplayImageOptions options;
	protected ImageLoader imageLoader;
	private Context mContext;
	private List<String> list;
	private LayoutInflater mInflater;

	public ImageAdapter(Context context,List<String> list) {
		mContext = context;
		this.list = list;
		imageLoader = imageLoader.getInstance();
//		options = new DisplayImageOptions.Builder().showStubImage(R.drawable.ic_launcher).showImageForEmptyUri(R.drawable.ic_launcher).showImageOnFail(R.drawable.ic_launcher).cacheInMemory().cacheOnDisc().displayer(new RoundedBitmapDisplayer(15)).build();
		mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}

	@Override
	public int getCount() {
		return Integer.MAX_VALUE;   //返回很大的值使得getView中的position不断增大来实现循环
	}

	@Override
	public Object getItem(int position) {
		return position;
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		if (convertView == null) {
			convertView = mInflater.inflate(R.layout.image_item, null);
		}
		ImageView imageView = ((ImageView) convertView.findViewById(R.id.imgView));
		imageLoader.displayImage(list.get(position%list.size()), imageView);
		convertView.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				Toast.makeText(mContext, "" + position, Toast.LENGTH_SHORT).show();
//				Intent intent = new Intent(mContext,ABSclass.class);
				Bundle bundle = new Bundle();
				bundle.putString("image_id", list.get(position%list.size()));
//				intent.putExtras(bundle);
//				mContext.startActivity(intent);
			}
		});
		return convertView;
	}

}
 
application中
@Override
	public void onCreate() {
		// 初始化下载图片jar包
		initImageLoader(getApplicationContext());
	}

	public static void initImageLoader(Context context)
	{
		ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(context).threadPriority(Thread.NORM_PRIORITY - 2).denyCacheImageMultipleSizesInMemory().discCacheFileNameGenerator(new Md5FileNameGenerator()).tasksProcessingOrder(QueueProcessingType.LIFO).enableLogging().build();

		ImageLoader.getInstance().init(config);
	}
 在你用的activity中加入
  viewFlow = (ViewFlow)findViewById(R.id.viewflow);
        viewFlow.setAdapter(new ImageAdapter(this));
        viewFlow.setmSideBuffer(3); // 实际图片张数, 我的ImageAdapter实际图片张数为3
        
        CircleFlowIndicator indic = (CircleFlowIndicator) findViewById(R.id.viewflowindic);
        viewFlow.setFlowIndicator(indic);
        viewFlow.setTimeSpan(4500);
        viewFlow.setSelection(3*1000);	//设置初始位置
        viewFlow.startAutoFlowTimer();  //启动自动播放
 
传个源码和网络获取图片的jar包

 

 


    
[2] 图片热区点击之二(地界反弹,缩放,移动)
    来源: 互联网  发布时间: 2014-02-18
图片热区点击之二(边界反弹,缩放,移动)

背景:对图片的部分区域进行点击,响应相应的事件(可对图片进行放大,边界反弹,以及图片移动)

针对于前次的热区点击做了个补充

 1.对图片的部分区域进行可响应事件

 2.对图片进行缩放后,仍可响应区域点击事件

 3.对图片进行移动后.仍可响应区域点击事件

 4.当图片移出边界区域后,可进行回弹.

其效果图如下(GIF图片较大,只截取一部分,在模拟器上,缩放效果无法演示)

 部分关键性代码:

 a.对点击的区域进行判断,

		/**
		 * 检测是否在区域范围内
		 * @param rectf 从外部传可以重用
		 * @param x
		 * @param y
		 * @return
		 */
		public boolean isInArea(RectF rectf, float x, float y) {
			boolean resStatus = false;
			if(this.path != null) {
				rectf.setEmpty();
				path.computeBounds(rectf, true);
				if(isRectF) {
					//当是矩形时
					resStatus = rectf.contains(x, y);
				}else {
					//如果是多边形时
					Region region = new Region();
					region.setPath(path, region);
					region.setPath(path, new Region((int)rectf.left, (int)rectf.top, (int)rectf.right, (int)rectf.bottom));
					resStatus = region.contains((int)x, (int)y);
				}
			}
			return resStatus;
		}

 b. 滑动或缩放完成后,是否移出边界检测

	/**
	 * 边界反弹事件检测
	 * @param event
	 */
	protected void upToCheckOutOfSide(MotionEvent event) {
		float scale = getCurrentScale();
		float[] moveXY = getCurrentMoveXY();
		float curBitWidth = scale * BIT_WIDTH;
		float curBitHeight = scale * BIT_HEIGHT;
		float[] dstXY = new float[2];
		boolean needMove = false;
		dstXY[0] = moveXY[0];
		dstXY[1] = moveXY[1];
		//当图片的高度小于视图高度时
		if(curBitHeight <= VIEW_HEIGHT) {
			needMove = true;
			dstXY[1] = (VIEW_HEIGHT - curBitHeight) / 2.0f;
		}
		
		//当图片的宽度小于视图宽度时
		if(curBitWidth <= VIEW_WIDTH) {
			needMove = true;
			dstXY[0] = (VIEW_WIDTH - curBitWidth) / 2.0f;
		}
		
		//当图片高度大于视图的高度时
		if(curBitHeight > VIEW_HEIGHT) {
			float distance = event.getY() - mPointF.y;
			//手向下滑动
			if(distance > 0) {
				if(moveXY[1] > 0) {
					dstXY[1] = 0;
					needMove = true;
				}
				//手向上滑动
			}else if(distance < 0) {
				float goalY = VIEW_HEIGHT - curBitHeight;
				if(moveXY[1] < goalY) {
					dstXY[1] = goalY;
					needMove = true;
				}
			}
		}
		//图片的当前宽度大小视图的高度时
		if(curBitWidth > VIEW_WIDTH) {
			float distance = event.getX() - mPointF.x;
			//向右滑动
			if(distance > 0) {
				if(moveXY[0] > 0) {
					dstXY[0] = 0;
					needMove = true;
				}
				//向左滑动
			}else if(distance < 0) {
				float goalX = VIEW_WIDTH - curBitWidth;
				if(moveXY[0] < goalX) {
					dstXY[0] = goalX;
					needMove = true;
				}
			}
		}
		
		if(needMove) {
			mViewHandler.postDelayed(new MoveRunnable(moveXY[0], moveXY[1], dstXY[0], dstXY[1]), 0);
		}
	}

 c.边界移动的Runnable

	/**
	 * 反弹时的动画线程
	 */
	protected class MoveRunnable implements Runnable {
		
		//移动的步长
		private final static int MOVE_STEEP = 20;
		//移动的方向
		private float direct;
		//是X方向上的移动还是Y方向上的移动
		private boolean isMoveX;
		
		private float srcX, srcY, dstX, dstY;
		
		//一元一次方程
		private float a, b;
		
		public MoveRunnable(float srcX,  float srcY, float dstX, float dstY) {
			this.srcX = srcX;
			this.srcY = srcY;
			this.dstX = dstX;
			this.dstY = dstY;
			//求解A,B
			if((dstY - srcY) != 0 && (dstX - srcX) != 0) {
				a = (dstY - srcY) / (dstX - srcX);
				b = dstY - a * dstX;
			}
			//以长的作为出发点
			isMoveX = Math.abs(srcX - dstX) > Math.abs(srcY - dstY);
			direct = isMoveX ? ((dstX - srcX) > 0 ? 1.0f : -1.0f) : ((dstY - srcY) > 0 ? 1.0f : -1.0f);
			isAnimation = true;
		}
		@Override
		public void run() {
			float distanceX = 0;
			float distanceY = 0;
			boolean isEnd = false;
			if(isMoveX) {
				distanceX = direct * MOVE_STEEP;
				srcX += distanceX;
				if(direct > 0) {
					if(srcX >= dstX) {
						isEnd = true;
						srcX -= distanceX;
						distanceX = dstX - srcX;
						srcX = dstX;
					}
				}else {
					if(srcX <= dstX) {
						isEnd = true;
						srcX -= distanceX;
						distanceX = dstX - srcX;
						srcX = dstX;
					}
				}
				
				if(a == 0 && b == 0) {
					distanceY = 0;
				}else {
					float tempY = a * srcX + b;
					distanceY = tempY - srcY;
					srcY = tempY;
				}
			}else {
				distanceY = direct * MOVE_STEEP;
				srcY += distanceY;
				if(direct > 0 ) {
					if(srcY >= dstY) {
						isEnd = true;
						srcY -= distanceY;
						distanceY = dstY - srcY;
						srcY = dstY;
					}
				}else {
					if(srcY <= dstY) {
						isEnd = true;
						srcY -= distanceY;
						distanceY = dstY - srcY;
						srcY = dstY;
					}
				}
				
				if(a == 0 && b == 0 ) {
					distanceX = 0;
				}else {
					float tempX = (srcY - b) / a;
					distanceX = tempX - srcX;
					srcX = tempX;
				}
			}
			mViewHandler.obtainMessage(0, new Float[]{distanceX, distanceY}).sendToTarget();
			if(!isEnd) {
				mViewHandler.postDelayed(this, 10);
			}else {
				isAnimation = false;
				LogUtils.d(TAG, isAnimation + ", End!");
			}
		}
	}

  其它的一些代码在程序中均已经做过注释

 


    
[3] spring xd 参照指南
    来源: 互联网  发布时间: 2014-02-18
spring xd 参考指南
http://docs.spring.io/spring-xd/docs/1.0.0.M2/reference/html/
参考指南
引言
概观

Spring XD is a unified, distributed, and extensible service for data ingestion, real time analytics, batch processing, and data export.

Spring XD是一个统一的,分布式,可扩展的系统用于 data ingestion,实时分析,批量处理和数据导出。
The Spring XD project is an open source Apache 2 License licenced project whose goal is to tackle big data complexity.
该项目的目标是简化大数据应用的开发。

Much of the complexity in building real-world big data applications is related to integrating many disparate systems into one cohesive solution across a range of use-cases.
建立真实世界的大数据的应用程序的大部分复杂性是在于将许多不同的系统为一个完整的,在一个范围内的使用情况。
创建一个综合的大数据中常见的用例是
  高吞吐量的分布式数据的从各种输入源为大数据存储诸如HDFS或splunk收集
  在收集时进行实时分析,例如采集数据和计算值
  通过批处理进行工作流程管理。 这些工作将通过标准企业系统(RDBMS)和Hadoop操作(MapReduce,HDFS,Pig,Hive or Cascading(流注)整合在一起。
   High throughput data export, e.g. from HDFS to a RDBMS or NoSQL database.

The Spring XD project aims to provide a one stop shop solution for these use-cases.

Getting Started
Requirements

To get started, make sure your system has as a minimum Java JDK 6 or newer installed. Java JDK 7 is recommended.

Download Spring XD

http://repo.spring.io/simple/libs-milestone-local/org/springframework/xd/spring-xd/1.0.0.M4/spring-xd-1.0.0.M4-dist.zip
解压,这将产生的安装目录spring-xd-1.0.0.m2。

All the commands below are executed from this directory, so change into it before proceeding(进行,进程;行动)。

cp spring-xd-1.0.0.M4-dist.zip /opt/
cd /opt/
unzip spring-xd-1.0.0.M4-dist.zip

drwxr-xr-x  7 root   root        4096 Nov 12 13:39 spring-xd-1.0.0.M4/

$ cd spring-xd-1.0.0.M2
设置环境变量
Set the environment variable XD_HOME to the installation directory <root-install-dir>\spring-xd\xd

vi /etc/profile
export XD_HOME=/opt/spring-xd-1.0.0.M4/xd

source /etc/profile
root@Master:/etc# echo $XD_HOME
/opt/spring-xd-1.0.0.M4/xd

安装 Spring XD


Spring XD can be run in two different modes.There’s a single-node runtime option for testing and development, and there’s a distributed runtime which supports distribution of processing tasks across multiple nodes.

This document will get you up and running quickly with a single-node runtime.

See Running Distributed Mode for details on setting up a distributed runtime.


Start the Runtime and the XD Shell

The single node option is the easiest to get started with.

It runs everything you need in a single process. To start it, you just need to cd to the xd directory and run the following command
启动命令
chmod -R 777 spring-xd-1.0.0.M4

xd/bin>$ ./xd-singlenode

启动后会看的
INFO: Starting Servlet Engine: Apache Tomcat/7.0.35
XD Configuration:
        XD_HOME=/opt/spring-xd-1.0.0.M4/xd
        XD_TRANSPORT=local
        XD_STORE=memory
        XD_ANALYTICS=memory
        XD_HADOOP_DISTRO=hadoop12

在一个单独的终端 cd into the shell directory and start the XD shell, which you can use to issue commands.

cd /opt/spring-xd-1.0.0.M4/shell/bin
shell/bin>$ ./xd-shell


The shell is a more user-friendly front end to the REST API which Spring XD exposes to clients. The URL of the currently targeted Spring XD server is shown at startup.

You should now be able to start using Spring XD.

Create a Stream
在spring XD中,基本流定义了事件驱动的源数据到一个接收器的摄取过程通过任意数量的处理器 
You can create a new stream by issuing(发布) a stream create command from the XD shell。Stream defintions are built from a simple DSL. For example, execute:

xd:>stream create --definition "time | log" --name ticktock
Created new stream 'ticktock

This defines a stream named ticktock based off the DSL expression time | log. The DSL uses the "pipe" symbol |, to connect a source to a sink.

在xd窗口返回
01:47:30,823  WARN task-scheduler-6 logger.ticktock:145 - 2013-12-27 01:47:30
01:47:31,825  WARN task-scheduler-9 logger.ticktock:145 - 2013-12-27 01:47:31
01:47:32,827  WARN task-scheduler-6 logger.ticktock:145 - 2013-12-27 01:47:32
01:47:33,830  WARN task-scheduler-9 logger.ticktock:145 - 2013-12-27 01:47:33
01:47:34,845  WARN task-scheduler-6 logger.ticktock:145 - 2013-12-27 01:47:34
01:47:35,849  WARN task-scheduler-4 logger.ticktock:145 - 2013-12-27 01:47:35
01:47:36,852  WARN task-scheduler-7 logger.ticktock:145 - 2013-12-27 01:47:36
01:47:37,854  WARN task-scheduler-4 logger.ticktock:145 - 2013-12-27 01:47:37
01:47:38,856  WARN task-scheduler-7 logger.ticktock:145 - 2013-12-27 01:47:38
01:47:39,858  WARN task-scheduler-4 logger.ticktock:145 - 2013-12-27 01:47:39
01:47:40,881  WARN task-scheduler-7 logger.ticktock:145 - 2013-12-27 01:47:40

time | log

In this simple example, the time source simply sends the current time as a message each second, and the log sink outputs it using the logging framework at the WARN logging level.


To stop the stream, and remove the definition completely, you can use the stream destroy command:

xd:>stream destroy --name ticktock
Destroyed stream 'ticktock'

It is also possibly to stop and restart the stream instead, using the undeploy and deploy commands. The shell supports command completion so you can hit the TAB key to see which commands and options are available.

Command 'tab' not found (for assistance press TAB)
xd:>

!                    //                   admin               
aggregatecounter     cls                  counter             
date                 exit                 fieldvaluecounter   
gauge                hadoop               help                
http                 job                  module              
richgauge            runtime              script              
stream               system               version             

xd:>


探索spring xd

Learn about the modules available in Spring XD in the Sources(源), Processors(处理器), and Sinks(接收器) sections of the documentation.



Running in Distributed Mode
Introduction

The Spring XD distributed runtime (DIRT) supports distribution of processing tasks across multiple nodes.

Spring XD can use several middlewares(中间软件) when running in distributed mode.
At the time of writing, Redis and RabbitMQ are available options.
在写的时候,Redis and RabbitMQ 是可用选项。

curl -d "multihttp --port=9001 --rulepath=passport | file --dir=/home/focusstat/log/passport --name=passport.log" http://127.0.0.1:8080/streams/passport



http://www.open-open.com/news/view/154055d

root@Master:/opt/spring-xd-1.0.0.M4/shell/bin# netstat -antup
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      673/sshd       
tcp        0     52 10.1.78.49:22           10.1.77.40:57969        ESTABLISHED 1586/1         
tcp        0      0 10.1.78.49:22           10.1.77.40:56054        ESTABLISHED 1025/0         
tcp6       0      0 :::22                   :::*                    LISTEN      673/sshd       
tcp6       0      0 :::9101                 :::*                    LISTEN      1677/java      
tcp6       0      0 :::9393                 :::*                    LISTEN      1677/java      
tcp6       0      0 127.0.0.1:9101          127.0.0.1:45686         ESTABLISHED 1677/java      
tcp6       0      0 127.0.0.1:9101          127.0.0.1:45687         ESTABLISHED 1677/java      
tcp6       0      0 127.0.0.1:45686         127.0.0.1:9101          ESTABLISHED 1677/java      
tcp6       0      0 127.0.0.1:45687         127.0.0.1:9101          ESTABLISHED 1677/java      
udp        0      0 0.0.0.0:68              0.0.0.0:*                           640/dhclient3

xd:>stream create --name httptest --definition "http | file"
Created new stream 'httptest'
xd:> http post --target http://localhost:9000 --data "hello world"
> POST (text/plain;Charset=UTF-8) http://localhost:9000 hello world
> 200 OK

root@Master:/tmp/xd/output# tail -f httptest.out
hello world

root@Master:/tmp/xd/output# curl -d "test" http://localhost:9000
root@Master:/tmp/xd/output# tail -f httptest.out






    
最新技术文章:
▪Android开发之登录验证实例教程
▪Android开发之注册登录方法示例
▪Android获取手机SIM卡运营商信息的方法
▪Android获取手机SIM卡运营商信息的方法 iis7站长之家
▪Android发送短信功能代码
▪Android根据电话号码获得联系人头像实例代码
▪Android中GPS定位的用法实例
▪Android实现退出时关闭所有Activity的方法
▪Android实现文件的分割和组装
▪Android录音应用实例教程
▪Android双击返回键退出程序的实现方法
▪Android实现侦听电池状态显示、电量及充电动...
▪Android获取当前已连接的wifi信号强度的方法
▪Android实现动态显示或隐藏密码输入框的内容
▪根据USER-AGENT判断手机类型并跳转到相应的app...
▪Android Touch事件分发过程详解
▪Android中实现为TextView添加多个可点击的文本
▪Android程序设计之AIDL实例详解
▪Android显式启动与隐式启动Activity的区别介绍
▪Android按钮单击事件的四种常用写法总结
▪Android消息处理机制Looper和Handler详解
▪Android实现Back功能代码片段总结
▪Android实用的代码片段 常用代码总结
▪Android实现弹出键盘的方法
▪Android中通过view方式获取当前Activity的屏幕截...
▪Android提高之自定义Menu(TabMenu)实现方法
▪Android提高之多方向抽屉实现方法
▪Android提高之MediaPlayer播放网络音频的实现方法...
▪Android提高之MediaPlayer播放网络视频的实现方法...
▪Android提高之手游转电视游戏的模拟操控
 


站内导航:


特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!

©2012-2021,,E-mail:www_#163.com(请将#改为@)

浙ICP备11055608号-3