记得在eoe上有人发过,但代码质量不好。我重写了一下,抽成了控件。但没有经过各种控件的相容性测试,如果和其他控件的相容性不好,就直接在activity中写代码吧,应该差不多的。
我用的是平板,所以效果还行,不知道手机如何。
代码:
package com.ql.view;
import android.R.anim;
import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.RotateAnimation;
import android.view.animation.ScaleAnimation;
import android.view.animation.TranslateAnimation;
import android.view.animation.Animation.AnimationListener;
import android.widget.Button;
import android.widget.RelativeLayout;
import com.ql.app.R;
public class AnimButtons extends RelativeLayout{
private Context context;
private int leftMargin=0,bottomMargin=0;
private final int buttonWidth=58;//图片宽高
private final int r=180;//半径
private final int maxTimeSpent=200;//最长动画耗时
private final int minTimeSpent=80;//最短动画耗时
private int intervalTimeSpent;//每相邻2个的时间间隔
private Button[] btns;
private Button btn_menu;
private RelativeLayout.LayoutParams params;
private boolean isOpen = false;//是否菜单打开状态
private float angle;//每个按钮之间的夹角
public AnimButtons(Context context) {
super(context);
// TODO Auto-generated constructor stub
this.context=context;
}
public AnimButtons(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
this.context=context;
}
@Override
protected void onFinishInflate() {
// TODO Auto-generated method stub
super.onFinishInflate();
View view=LayoutInflater.from(context).inflate(R.layout.anim_buttons, this);
initButtons(view);
}
private void initButtons(View view){
// TODO Auto-generated method stub
//6个按钮,具体视情况而定
btns=new Button[6];
btns[0] = (Button) view.findViewById(R.id.btn_camera);
btns[1] = (Button) view.findViewById(R.id.btn_with);
btns[2] = (Button) view.findViewById(R.id.btn_place);
btns[3] = (Button) view.findViewById(R.id.btn_music);
btns[4] = (Button) view.findViewById(R.id.btn_thought);
btns[5] = (Button) view.findViewById(R.id.btn_sleep);
btn_menu = (Button) view.findViewById(R.id.btn_menu);
leftMargin=((RelativeLayout.LayoutParams)(btn_menu.getLayoutParams())).leftMargin;
bottomMargin=((RelativeLayout.LayoutParams)(btn_menu.getLayoutParams())).bottomMargin;
for(int i=0;i<btns.length;i++){
btns[i].setLayoutParams(btn_menu.getLayoutParams());//初始化的时候按钮都重合
btns[i].setTag(String.valueOf(i));
btns[i].setOnClickListener(clickListener);
}
intervalTimeSpent=(maxTimeSpent-minTimeSpent)/btns.length;//20
angle=(float)Math.PI/(2*(btns.length-1));
}
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
// TODO Auto-generated method stub
super.onSizeChanged(w, h, oldw, oldh);
final int bottomMargins=this.getMeasuredHeight()-buttonWidth-bottomMargin;
// Log.i("tag", "bottomMargins====="+bottomMargins);
btn_menu.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(!isOpen){
isOpen = true;
// btn_menu.startAnimation(animRotate(-45.0f, 0.5f, 0.45f));
for(int i=0;i<btns.length;i++){
float xLenth=(float)(r*Math.sin(i*angle));
float yLenth=(float)(r*Math.cos(i*angle));
// Log.i("tag", "xLenth======"+xLenth+",yLenth======"+yLenth);
btns[i].startAnimation(animTranslate(xLenth, -yLenth, leftMargin+(int)xLenth, bottomMargins - (int)yLenth, btns[i], minTimeSpent+i*intervalTimeSpent));
}
}
else{
isOpen = false;
// btn_menu.startAnimation(animRotate(90.0f, 0.5f, 0.45f));
for(int i=0;i<btns.length;i++){
float xLenth=(float)(r*Math.sin(i*angle));
float yLenth=(float)(r*Math.cos(i*angle));
// Log.i("tag", "xLenth======"+xLenth+",yLenth======"+yLenth);
btns[i].startAnimation(animTranslate(-xLenth, yLenth, leftMargin, bottomMargins, btns[i], maxTimeSpent-i*intervalTimeSpent));
}
}
}
});
}
private Animation animScale(float toX, float toY){
// TODO Auto-generated method stub
Animation animation = new ScaleAnimation(1.0f, toX, 1.0f, toY, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
animation.setInterpolator(context, anim.accelerate_decelerate_interpolator);
animation.setDuration(400);
animation.setFillAfter(false);
return animation;
}
private Animation animRotate(float toDegrees, float pivotXValue, float pivotYValue){
// TODO Auto-generated method stub
final Animation animation = new RotateAnimation(0, toDegrees, Animation.RELATIVE_TO_SELF, pivotXValue, Animation.RELATIVE_TO_SELF, pivotYValue);
animation.setAnimationListener(new AnimationListener(){
@Override
public void onAnimationStart(Animation animation){
// TODO Auto-generated method stub
}
@Override
public void onAnimationRepeat(Animation animation){
// TODO Auto-generated method stub
}
@Override
public void onAnimationEnd(Animation animation){
// TODO Auto-generated method stub
animation.setFillAfter(true);
}
});
return animation;
}
private Animation animTranslate(float toX, float toY, final int lastX, final int lastY,
final Button button, long durationMillis){
// TODO Auto-generated method stub
Animation animation = new TranslateAnimation(0, toX, 0, toY);
animation.setAnimationListener(new AnimationListener(){
@Override
public void onAnimationStart(Animation animation){
// TODO Auto-generated method stub
}
@Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationEnd(Animation animation){
// TODO Auto-generated method stub
params = new RelativeLayout.LayoutParams(0, 0);
params.height = buttonWidth;
params.width = buttonWidth;
params.setMargins(lastX, lastY, 0, 0);
button.setLayoutParams(params);
button.clearAnimation();
}
});
animation.setDuration(durationMillis);
return animation;
}
View.OnClickListener clickListener=new View.OnClickListener(){
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
int selectedItem=Integer.parseInt((String)v.getTag());
for(int i=0;i<btns.length;i++){
if(i==selectedItem){
btns[i].startAnimation(animScale(2.0f, 2.0f));
}else{
btns[i].startAnimation(animScale(0.0f, 0.0f));
}
}
if(onButtonClickListener!=null){
onButtonClickListener.onButtonClick(v, selectedItem);
}
}
};
public boolean isOpen(){
return isOpen;
}
private OnButtonClickListener onButtonClickListener;
public interface OnButtonClickListener{
void onButtonClick(View v,int id);
}
public void setOnButtonClickListener(OnButtonClickListener onButtonClickListener){
this.onButtonClickListener=onButtonClickListener;
}
}
布局anim_buttons.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFF"
>
<Button android:id="@+id/btn_sleep"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/composer_sleep"
android:layout_alignParentLeft="true"
android:layout_alignParentBottom="true"
/>
<Button android:id="@+id/btn_thought"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/composer_thought"
android:layout_alignParentLeft="true"
android:layout_alignParentBottom="true"
/>
<Button android:id="@+id/btn_music"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/composer_music"
android:layout_alignParentLeft="true"
android:layout_alignParentBottom="true"
/>
<Button android:id="@+id/btn_place"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/composer_place"
android:layout_alignParentLeft="true"
android:layout_alignParentBottom="true"
/>
<Button android:id="@+id/btn_with"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/composer_with"
android:layout_alignParentLeft="true"
android:layout_alignParentBottom="true"
/>
<Button android:id="@+id/btn_camera"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/composer_camera"
android:layout_alignParentLeft="true"
android:layout_alignParentBottom="true"
/>
<Button android:id="@+id/btn_menu"
android:layout_width="58dip"
android:layout_height="58dip"
android:background="@drawable/friends_delete"
android:layout_alignParentLeft="true"
android:layout_alignParentBottom="true"
android:layout_marginLeft="10dip"
android:layout_marginBottom="10dip"
/>
</RelativeLayout>
用法:
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
AnimButtons animButtons=(AnimButtons)findViewById(R.id.animButtons);
animButtons.setOnButtonClickListener(new AnimButtons.OnButtonClickListener() {
@Override
public void onButtonClick(View v, int id) {
// TODO Auto-generated method stub
Log.i("tag", "id============="+id);
}
});
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
<!-- layout_width,layout_height最好是fill_parent参数 -->
<com.ql.view.AnimButtons
android:id="@+id/animButtons"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
</LinearLayout>
网上又找到一个相同效果的。呵呵。
http://www.cnblogs.com/mudoot/archive/2012/01/19/path_composer_menu.html
已更新。你看到的是老版本,相容性不好。
部分银行项目有用到mq队列管理器用于消息的处理下发,该项目是通过webservice进行连接,下面是具体cxf+spring配置文件:调用只需要把相关的jar包与对应的属性进行修改即可
客户端配置如下:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:cxf="http://cxf.apache.org/core"
xmlns:soap="http://cxf.apache.org/bindings/soap"
xmlns:jaxws="http://cxf.apache.org/jaxws"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:jms="http://cxf.apache.org/transports/jms"
xmlns:wsa="http://cxf.apache.org/ws/addressing"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd
http://cxf.apache.org/transports/jms http://cxf.apache.org/schemas/configuration/jms.xsd" default-lazy-init="true" default-autowire="byName">
<!--p:targetDestination="queue://MQCCC/LOCALQ.SMS.SMSMTSOAP.REQ"
p:replyDestination="queue://MQCCC/LOCALQ.GSP.RSP"-->
<bean id="jmsSmsOutputConfig"
p:receiveTimeout="5000000"
p:connectionFactory-ref="jmsConnectionFactory"
p:targetDestination="queue://MQCCC/REMOTEQ.GSP.SMSMTSOAP.REQ"
p:replyDestination="queue://MQCCC/LOCALQ.GSP.RSP"
p:concurrentConsumers="1"
p:maxConcurrentConsumers="1000"
p:wrapInSingleConnectionFactory="true"
p:useJms11="true" />
<!--MQ 客户端配置连接信息-->
<bean id="jmsConnectionFactory"
>
<property name="targetConnectionFactory">
<bean >
<property name="channel" value="SYSTEM.DEF.SVRCONN"></property>
<property name="queueManager" value="MQCCC"></property>
<property name="hostName" value="182.119.171.65"></property>
<property name="port" value="1415"></property>
<property name="CCSID" value="1208"></property>
<property name="transportType" value="1"></property>
</bean>
</property>
<property name="sessionCacheSize" value="4"></property>
</bean>
<jaxws:client id="smsMtService" xmlns:o="http://sms.service.bankcomm.com/Abstraction/Atomic/business.smsmt.SmsMtSOAP"
service serviceName="o:SmsMt" endpointName="o:SmsMtSOAP" address="jms://" >
<!--设置拦截器-->
<jaxws:inInterceptors>
<bean />
</jaxws:inInterceptors>
<jaxws:outInterceptors>
<bean />
</jaxws:outInterceptors>
<!--<property name="endpointAddress" value=""/>-->
<jaxws:features>
<bean />
<bean xmlns="http://www.springframework.org/schema/beans"
p:jmsConfig-ref="jmsSmsOutputConfig" />
<wsa:addressing/>
</jaxws:features>
</jaxws:client>
</beans>
服务器端配置如下:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:cxf="http://cxf.apache.org/core"
xmlns:soap="http://cxf.apache.org/bindings/soap"
xmlns:jaxws="http://cxf.apache.org/jaxws"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:jms="http://cxf.apache.org/transports/jms"
xmlns:wsa="http://cxf.apache.org/ws/addressing"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd
http://cxf.apache.org/transports/jms http://cxf.apache.org/schemas/configuration/jms.xsd"
default-lazy-init="true" default-autowire="byName">
<import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-local.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-jms.xml" />
<!-- targetDestination服务端监听的队列属性 -->
<bean id="jmsSmsSendConfig"
p:receiveTimeout="50000"
p:connectionFactory-ref="jmsSmsSendConnectionFactory"
p:targetDestination="queue://MQCCC/LOCALQ.GSP.SMSSENDSERVICE.REQ"
p:concurrentConsumers="5" p:maxConcurrentConsumers="1000"
p:wrapInSingleConnectionFactory="true" p:useJms11="true" />
<!-- 服务器端连接配置方式连接 port:1208 UTF8 ,1380 GBK-->
<bean id="jmsSmsSendConnectionFactory"
>
<property name="targetConnectionFactory">
<bean >
<property name="channel" value="SYSTEM.DEF.SVRCONN"></property>
<property name="queueManager" value="MQCCC"></property>
<property name="hostName" value="182.119.171.65"></property>
<property name="port" value="1415"></property>
<property name="CCSID" value="1208"></property>
<property name="transportType" value="1"></property>
</bean>
</property>
<property name="sessionCacheSize" value="5"></property>
</bean>
<bean name="smsSend"
>
<property name="robotInputservice">
<ref bean="robotInputservice" />
</property>
</bean>
<jaxws:endpoint id="smsSendService"
xmlns:customer="http://ccc.service.bankcomm.com/abstraction/atomic/business.SmsSendService/1_0"
implementor="#smsSend" address="jms://">
<jaxws:features>
<wsa:addressing
xmlns:wsa="http://cxf.apache.org/ws/addressing" />
<bean xmlns="http://www.springframework.org/schema/beans"
p:jmsConfig-ref="jmsSmsSendConfig" />
</jaxws:features>
</jaxws:endpoint>
</beans>
mq相关jar包过大,无法上传
在iOS里,程序之间都是相互隔离的,目前并没有一个有效的方式来做程序间通信,幸好iOS程序可以很方便的注册自己的URL Scheme,这样就可以通过打开特定URL的方式来传递参数给另外一个程序。
至于,如何注册自己的URL Scheme,可以参考:自定义URL Scheme。
下面,看一个具体的示例。
假设有两个应用:A和B,A应用有两个UITableView,一个是字母类型的,另一个是数字类型的,B应用有两个按钮,一个用来打开A应用的字母列表,另一个用来打开A应用的数字列表,其中,A应用的Info.plist信息如下:
A应用的所有代码如下:
NavigationAppDelegate.h
#import <UIKit/UIKit.h>
@class NavigationViewController;
@interface NavigationAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
UINavigationController *viewController;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UINavigationController *viewController;
@end
NavigationAppDelegate.m
#import "NavigationAppDelegate.h"
#import "NavigationViewController.h"
#import "NumberViewController.h"
@implementation NavigationAppDelegate
@synthesize window;
@synthesize viewController;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
NavigationViewController *nav = [[NavigationViewController alloc] init];
viewController = [[UINavigationController alloc] initWithRootViewController:nav];
[self.window addSubview:viewController.view];
[self.window makeKeyAndVisible];
[nav release];
return YES;
}
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
if ([[url host] isEqualToString:@"com.aurora.nav"]) {
NSString *viewId = [[url query] substringFromIndex:[[url query] rangeOfString:@"viewId="].location + 7];
if ([viewId isEqualToString:@"letters"]){
NavigationViewController *nav = [[NavigationViewController alloc] init];
[self.viewController pushViewController:nav animated:YES];
[nav release];
} else {
NumberViewController *nav = [[NumberViewController alloc] init];
[self.viewController pushViewController:nav animated:YES];
[nav release];
}
}
return YES;
}
- (void)dealloc {
[viewController release];
[window release];
[super dealloc];
}
@end
NavigationViewController.h
#import <UIKit/UIKit.h>
@interface NavigationViewController : UIViewController <UITableViewDelegate, UITableViewDataSource> {
NSArray *array;
}
@property(nonatomic, retain) NSArray *array;
@end
NavigationViewController.m
#import "NavigationViewController.h"
@implementation NavigationViewController
@synthesize array;
- (void)viewDidLoad {
[super viewDidLoad];
self.title = @"Letters";
NSArray *letters = [[NSArray alloc] initWithObjects:@"A", @"B", @"C", @"D", @"E", @"F", @"G", nil];
self.array = letters;
[letters release];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [array count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
cell.textLabel.text = [array objectAtIndex:[indexPath row]];
return cell;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
- (void)viewDidUnload {
array = nil;
}
- (void)dealloc {
[array release];
array = nil;
[super dealloc];
}
@end
NumberViewController.h
#import <UIKit/UIKit.h>
@interface NumberViewController : UIViewController <UITableViewDelegate, UITableViewDataSource> {
NSArray *array;
}
@property(nonatomic, retain) NSArray *array;
@end
NumberViewController.m
#import "NumberViewController.h"
@implementation NumberViewController
@synthesize array;
- (void)viewDidLoad {
[super viewDidLoad];
self.title = @"Numbers";
NSArray *numbers = [[NSArray alloc] initWithObjects:@"1", @"2", @"3", @"4", @"5", @"6", @"7", nil];
self.array = numbers;
[numbers release];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [array count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
cell.textLabel.text = [array objectAtIndex:[indexPath row]];
return cell;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
- (void)viewDidUnload {
array = nil;
}
- (void)dealloc {
[array release];
array = nil;
[super dealloc];
}
@end
B应用的所有代码如下:
RequestViewController.h
#import <UIKit/UIKit.h>
@interface RequestViewController : UIViewController {
}
- (IBAction) goToLetters;
- (IBAction) goToNumbers;
@end
RequestViewController.m
#import "RequestViewController.h"
@implementation RequestViewController
- (IBAction) goToLetters{
NSString *str = @"nav://com.aurora.nav?viewId=%@";
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:str, @"letters"]];
[[UIApplication sharedApplication] openURL:url];
}
- (IBAction) goToNumbers{
NSString *str = @"nav://com.aurora.nav?viewId=%@";
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:str, @"numbers"]];
[[UIApplication sharedApplication] openURL:url];
}
@end