当前位置: 编程技术>移动开发
本页文章导读:
▪播发图片的类 播放图片的类
public class GGView extends View {
int COMPONENT_WIDTH; //该控件宽度
int COMPONENT_HEIGHT; //该控件高度
boolean initflag=false; //是否要获取控件的高度和宽度标志
static Bitmap[] bma; .........
▪ Objective-C中协媾和委托 Objective-C中协议和委托
Objective-C中的协议(Protocol)类似于常用的接口,协议(Protocols)中定义的方法,在类中实现。@protocol MyFirstProtocol- (void)myFirstProtocolMethod;@end在iPhone OS中,协议(Protoco.........
▪ speech recognition中施用PendingIntent speech recognition中使用PendingIntent
http://stackoverflow.com/questions/4530472/widget-that-calls-speech-recognition-app
http://stackoverflow.com/questions/6466328/recognizerintent-how-to-add-a-bundle-to-a-pending-intent
// this intent points.........
[1]播发图片的类
来源: 互联网 发布时间: 2014-02-18
播放图片的类
public class GGView extends View {
int COMPONENT_WIDTH; //该控件宽度
int COMPONENT_HEIGHT; //该控件高度
boolean initflag=false; //是否要获取控件的高度和宽度标志
static Bitmap[] bma; //需要播放的图片的数组
Paint paint; //画笔
int[] drawablesId; //图片ID数组
int currIndex=0; //图片ID数组下标,根据此变量画图片
boolean workFlag=true; //播放图片线程标志位
public GGView(Context father,AttributeSet as) { //构造器
super(father,as);
drawablesId=new int[]{ //初始化图片ID数组
R.drawable.adv1, //将需要播放的图片ID放于此处即可
R.drawable.adv2,
R.drawable.adv3,
};
bma=new Bitmap[drawablesId.length]; //创建存放图片的数组
initBitmaps(); //调用初始化图片函数,初始化图片数组
paint=new Paint(); //创建画笔
paint.setFlags(Paint.ANTI_ALIAS_FLAG); //消除锯齿
new Thread(){ //创建播放图片线程
public void run(){
while(workFlag){
currIndex=(currIndex+1)%drawablesId.length;//改变ID数组下标值
GGView.this.postInvalidate(); //绘制
try {
Thread.sleep(3000); //休息三秒
} catch (InterruptedException e) {
e.printStackTrace();
}}}}.start(); //启动线程
}
public void initBitmaps(){ //初始化图片函数
Resources res=this.getResources(); //获取Resources对象
for(int i=0;i<drawablesId.length;i++){
bma[i]=BitmapFactory.decodeResource(res, drawablesId[i]);
}}
public void onDraw(Canvas canvas){ //绘制函数
if(!initflag) { //第一次绘制时需要获取宽度和高度
COMPONENT_WIDTH=this.getWidth(); //获取view的宽度
COMPONENT_HEIGHT=this.getHeight(); //获取view的高度
initflag=true;
}
int picWidth=bma[currIndex].getWidth(); //获取当前绘制图片的宽度
int picHeight=bma[currIndex].getHeight(); //获取当前绘制图片的高度
int startX=(COMPONENT_WIDTH-picWidth)/2; //得到绘制图片的左上角X坐标
int startY=(COMPONENT_HEIGHT-picHeight)/2; //得到绘制图片的左上角Y坐标
canvas.drawARGB(255, 200, 128, 128); //设置背景色
canvas.drawBitmap(bma[currIndex], startX,startY, paint); //绘制图片
}}
[2] Objective-C中协媾和委托
来源: 互联网 发布时间: 2014-02-18
Objective-C中协议和委托
Objective-C中的协议(Protocol)类似于常用的接口,协议(Protocols)中定义的方法,在类中实现。
@protocol MyFirstProtocol
- (void)myFirstProtocolMethod;
@end
在iPhone OS中,协议(Protocol)通常用来实现委托对象(Delegate Object)。委托对象(Delegate Object)一般用来自己定义行为或者动作,也就是调用自己定义方法,但自己不实现该方法,委托其它的类来实现该方法。
UIApplication类就是一个典型的例子。UIApplication类中定义了一个应用程序应有的行为或者动作。而不是强制让你的UIApplication子类去接受当前应用程序的状态消息并做出相应处理。UIApplication类通过调用特殊的方法,来传递这些消息给它的委托对象。这个委托对象通过实现名为UIApplicationDelegate的协议(Protocol),之后就可以接受到当前应用程序的状态消息并做出相应处理。比如内存不够的错误,应用程序被中断等重要消息。
下面是一个HelloWorld代码:
main.m
Objective-C中的协议(Protocol)类似于常用的接口,协议(Protocols)中定义的方法,在类中实现。
@protocol MyFirstProtocol
- (void)myFirstProtocolMethod;
@end
在iPhone OS中,协议(Protocol)通常用来实现委托对象(Delegate Object)。委托对象(Delegate Object)一般用来自己定义行为或者动作,也就是调用自己定义方法,但自己不实现该方法,委托其它的类来实现该方法。
UIApplication类就是一个典型的例子。UIApplication类中定义了一个应用程序应有的行为或者动作。而不是强制让你的UIApplication子类去接受当前应用程序的状态消息并做出相应处理。UIApplication类通过调用特殊的方法,来传递这些消息给它的委托对象。这个委托对象通过实现名为UIApplicationDelegate的协议(Protocol),之后就可以接受到当前应用程序的状态消息并做出相应处理。比如内存不够的错误,应用程序被中断等重要消息。
下面是一个HelloWorld代码:
main.m
#import
int main(int argc, char *argv[])
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
int retVal = UIApplicationMain(argc, argv, nil, nil);
[pool release];
return retVal;
}
[3] speech recognition中施用PendingIntent
来源: 互联网 发布时间: 2014-02-18
speech recognition中使用PendingIntent
http://stackoverflow.com/questions/4530472/widget-that-calls-speech-recognition-app
http://stackoverflow.com/questions/6466328/recognizerintent-how-to-add-a-bundle-to-a-pending-intent
// this intent points to activity that should handle results Intent activityIntent = new Intent(context, ResultsActivity.class); // this intent wraps results activity intent PendingIntent resultsPendingIntent = PendingIntent.getActivity(context, 0, activityIntent, 0); // this intent calls the speech recognition Intent voiceIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); voiceIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM); voiceIntent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Speech recognition demo"); voiceIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); voiceIntent.putExtra(RecognizerIntent.EXTRA_RESULTS_PENDINGINTENT, resultsPendingIntent); // this intent wraps voice recognition intent PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, voiceIntent, 0); rv.setOnClickPendingIntent(R.id.btn, pendingIntent);
最新技术文章: