首页 文章 精选 留言 我的

精选列表

搜索[鸿蒙开发],共10000篇文章
优秀的个人博客,低调大师

Android -- NDK开发入门

第一步,建立一个普通的Android项目HelloNDK,然后在与src同一级的目录下新建一个jni目录; 第二步,在jni目录下新建一个hello_ndk.c文件,代码如下: #include <string.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <sys/ioctl.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <jni.h> #include <android/log.h> /********获取字符串************* */ jstring Java_com_example_hellondk_MainActivity_readJNIString( JNIEnv* env, jobject obj) { return (*env)->NewStringUTF(env, "Hello from JNI --- 22222 !"); } 说明如下: Java_com_example_hellondk_MainActivity_readJNIString // 方法名,由三部分组成,Java + [com_example_hellondk_HelloNDKActivity](包名+activity名) + [readJNIString](在java代码中调用的方法名) (*env)->NewStringUTF(env, "Hello from JNI --- 22222 !"); //在java中接收的返回值,不能直接return,一定要调用(*env)->NewStringUTF()这个方法返回 第三步,在jni目录下新建一个Android.mk文件,代码如下: LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) LOCAL_MODULE := hello_ndk LOCAL_SRC_FILES := hello_ndk.c LOCAL_LDLIBS := -llog include $(BUILD_SHARED_LIBRARY) 说明如下: LOCAL_MODULE := hello_ndk //这个与生成.so文件名有关,和导入Native Support的.so文件有关 LOCAL_SRC_FILES := hello_ndk.c //这个是读取相关的C文件名 第四步,配置android项目的native support,选中项目右键Android Tools--Add Native Support, 打开Add Android Native Support对话框,输入第三步中配置的LOACL_MODULE的值,如下图: 第五步,修改MainActivity.java文件,代码如下: package com.example.hellondk; import android.os.Bundle; import android.app.Activity; import android.view.Menu; import android.widget.TextView; public class MainActivity extends Activity { TextView mTestTv; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mTestTv = (TextView)findViewById(R.id.test_tv); mTestTv.setText(readJNIString()); } private native String readJNIString(); static { System.loadLibrary("hello_ndk");//引入hello_ndk.so } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } } 说明如下: 项目运行的时候首先会执行static里面的方法,引入hello_ndk.so,然后执行onCreate里的方法,读取C文件里的方法获取返回值并显示在TextView控件上。 第六步,运行Android Application项目,程序会首先生成.so文件,成功后继续运行android项目,生成.so的过程如下: 我是天王盖地虎的分割线 本文转自我爱物联网博客园博客,原文链接:http://www.cnblogs.com/yydcdut/p/3908734.html,如需转载请自行联系原作者

优秀的个人博客,低调大师

IOS开发博客学习

M了个J :http://www.cnblogs.com/mjios/tag/objective-c/ http://www.cnblogs.com/tianjian/p/3358602.html Cocos2d-x VS环境配置 泰然论坛:http://www.ityran.com/archives/category/cocos2d-iphone 1.http://www.cnblogs.com/zilongshanren/archive/2011/09/19/2181558.html 非常适用的入门教程 2.http://www.cnblogs.com/BigPolarBear/tag/iOS/ 3.一些相应的环境配置,以及简单语法介绍,适合入门 http://blog.csdn.net/xiaominghimi/article/details/6937685 http://blog.csdn.net/sdhjob/article/details/8173176 沈大海 4.Cocos2d-x的使用 http://cocos2d.cocoachina.com/ http://cocos2d.cocoachina.com/resource 重要的博客http://blog.csdn.net/honghaier/article/details/7887873 Cocos2d-x视频教程 http://www.tudou.com/plcover/Yofz8yOj62c/ 5.http://www.cnblogs.com/zilongshanren/archive/2012/02/17/2356516.htm http://www.cnblogs.com/zilongshanren/tag/cocos2d/ 8.http://blog.csdn.net/honghaier/article/details/7887873重点 OC知识点 1.http://rzchina.blog.163.com/blog/#m=0&t=1&c=fks_084069084082083074087082094095085094080066084083087074083 本文转自夏雪冬日博客园博客,原文链接:http://www.cnblogs.com/heyonggang/p/3351269.html,如需转载请自行联系原作者

优秀的个人博客,低调大师

iOS开发-状态模式

状态模式允许对象内部状态改变时改变它的行为,对象看起来好像修改了它的类。状态模式看起来和策略模式比较相像,策略模式是将可以互换的行为封装起来,然后通过使用委托的方式,决定使用哪一个行为,状态也是封装行为,不同的是可以将行为委托到当前状态。一个需要从外部设置,一个是内部通过状态变更达到行为变成的目的。 基础知识 状态模式的UML类图: State封装基本的状态行为,我们通过Cotext上下文持有状态子类的实例,外部发起请求,我们就可以委托状态进行处理。地铁里面一般都有自动饮料售卖机,我们将所有的饮料都当做商品来看,我们如果需要买饮料需要两步,投币,取货,如果没有商品还可以退钱三种行为,关于自动售卖机的存在无钱状态,有钱状态,售卖中状态,已售罄状态四种状态,稍微思考一下,可以看下面的具体实现。 设计实战 状态行为基类: @protocol StateProtocol <NSObject> @optional -(void)putMoney; @optional -(void)ejectMoney; @optional -(void)pressButton; @optional -(void)distribute; @end @interface State : NSObject<StateProtocol> @end 售卖机处于无钱状态(NoMoneyState): @protocol NoMoneyDelegate <NSObject> -(void)setCurrentState:(State *)currentState; -(State *)geHasMoneyState; @end //没钱状态 @interface NoMoneyState : State @property (weak,nonatomic) id<NoMoneyDelegate> delegate; @end @implementation NoMoneyState -(void)putMoney{ NSLog(@"NoMoneyState-putMoney:投放钱币"); [self.delegate setCurrentState:[self.delegate geHasMoneyState]]; } -(void)ejectMoney{ NSLog(@"NoMoneyState-ejectMoney:没有投入钱币,无法退钱"); } -(void)pressButton{ NSLog(@"NoMoneyState-pressButton:请先投币"); } -(void)distribute{ NSLog(@"NoMoneyState-pressButton:请投币"); } @end 售卖机处于有钱状态(HasMoneyState): @protocol HasMoneyDelegate <NSObject> -(void)setCurrentState:(State *)currentState; -(State *)getNoMoneyState; -(State *)getSoldState; @end //有钱状态 @interface HasMoneyState : State @property (weak,nonatomic) id<HasMoneyDelegate> delegate; @end @implementation HasMoneyState -(void)putMoney{ NSLog(@"HasMoneyState-putMoney:已经投入了钱,暂不支持投入"); } -(void)ejectMoney{ NSLog(@"HasMoneyState-ejectMoney:退钱,重新设置售卖机为无前状态"); [self.delegate setCurrentState:[self.delegate getNoMoneyState]]; } -(void)pressButton{ NSLog(@"HasMoneyState-pressButton:按钮按下,取货"); [self.delegate setCurrentState:[self.delegate getSoldState]]; } -(void)distribute{ NSLog(@"HasMoneyState-distribute:无法进行取出商品"); } @end 售卖机处于售卖状态: @protocol SoldDelegate <NSObject> -(void)setCurrentState:(State *)currentState; -(void)realseProduct; -(NSInteger)getCurrentCount; -(State *)getNoMoneyState; -(State *)getSoldOutState; @end //售出状态 @interface SoldState : State @property (weak,nonatomic) id<SoldDelegate> delegate; @end @implementation SoldState -(void)putMoney{ NSLog(@"SoldState-putMoney:请稍后,正在进行商品出售"); } -(void)ejectMoney{ NSLog(@"SoldState-putMoney:请稍后,正在进行商品出售,无法退钱"); } -(void)pressButton{ NSLog(@"SoldState-putMoney:请在取出物品之后重新投币"); } -(void)distribute{ [self.delegate realseProduct]; if ([self.delegate getCurrentCount]) { [self.delegate setCurrentState:[self.delegate getNoMoneyState]]; }else{ [self.delegate setCurrentState:[self.delegate getSoldOutState]]; } } @end 售罄状态(SoldOutState): @protocol SoldOutDelegate <NSObject> -(void)setCurrentState:(State *)currentState; @end //售罄状态 @interface SoldOutState : State @property (weak,nonatomic) id<SoldOutDelegate> delegate; @end @implementation SoldOutState -(void)putMoney{ NSLog(@"SoldOutState-PutMoney:已售罄"); } -(void)ejectMoney{ NSLog(@"SoldOutState-ejectMoney:无法退钱"); } -(void)pressButton{ NSLog(@"SoldOutState-pressButton:无法售出"); } -(void)distribute{ NSLog(@"SoldOutState-distribute:无法分发"); } @end 售卖机(SaleMachine): @interface SaleMachine : NSObject<NoMoneyDelegate,HasMoneyDelegate,SoldOutDelegate,SoldDelegate> @property (strong,nonatomic) NoMoneyState *noMoneyState; @property (strong,nonatomic) HasMoneyState *hasMoneyState; @property (strong,nonatomic) SoldOutState *soldOutState; @property (strong,nonatomic) SoldState *soldState; -(instancetype)initWithCount:(NSInteger)count; -(void)setCurrentState:(State *)currentState; -(void)putMoney; -(void)ejectMoney; -(void)pressButton; @end @interface SaleMachine() @property (strong,nonatomic) State *state; @property (assign,nonatomic) NSInteger productCount; @end @implementation SaleMachine -(instancetype)initWithCount:(NSInteger)count{ self=[super init]; if (self) { self.noMoneyState=[[NoMoneyState alloc]init]; self.noMoneyState.delegate=self; self.hasMoneyState=[[HasMoneyState alloc]init]; self.hasMoneyState.delegate=self; self.soldState=[[SoldState alloc]init]; self.soldState.delegate=self; self.soldOutState=[[SoldOutState alloc]init]; self.soldOutState.delegate=self; self.productCount=count; if (count) { self.state=self.noMoneyState; } } return self; } -(void)putMoney{ [self.state putMoney]; } -(void)ejectMoney{ [self.state ejectMoney]; } -(void)pressButton{ [self.state pressButton]; [self.state distribute]; } -(void)setCurrentState:(State *)currentState{ self.state=currentState; } #pragma mark - NoMoenyDelegate -(State *)geHasMoneyState{ return self.hasMoneyState; } #pragma mark - HasMoneyDelegate -(State *)getNoMoneyState{ return self.noMoneyState; } -(State *)getSoldState{ return self.soldState; } #pragma mark - SoldDelegate -(void)realseProduct{ NSLog(@"SoldDelegate-realseProduct:商品售出"); if (self.productCount) { self.productCount-=1; } } -(State *)getSoldOutState{ return self.soldOutState; } -(NSInteger)getCurrentCount{ return self.productCount; } @end 测试: SaleMachine *machine=[[SaleMachine alloc]initWithCount:1]; [machine putMoney]; [machine ejectMoney]; [machine putMoney]; [machine pressButton]; SaleMachine *next=[[SaleMachine alloc]initWithCount:1]; [next putMoney]; [next ejectMoney]; 测试效果: 状态模式的优缺点: 优点:状态模式允许一个对象基于内部状态有不同的行为,将行为委托给状态对象执行,状态转化可以由Context也可以由状态行为控制,比较灵活; 缺点:状态模式的使用必然会增加系统类和对象的个数。状态模式的结构与实现都较为复杂,如果使用不当将导致程序结构和代码的混乱。 本文转自Fly_Elephant博客园博客,原文链接:http://www.cnblogs.com/xiaofeixiang/p/5135479.html,如需转载请自行联系原作者

优秀的个人博客,低调大师

iOS开发-automaticallyAdjustsScrollViewInsets属性

最近遇到一个问题是这样的,App一般自己都会有一个UINavigationController,顶部TableView如果有tableHeaderView如果设置起始位置是(0,0)是在导航栏的下面的,为了更好地UI希望从屏幕的(0,0)开始,就遇到了上面的这个问题,简单的看一下效果: 主要代码如下: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 - (UITableView *)tableView { if (!_tableView) { _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth( self .view.bounds), CGRectGetHeight( self .view.bounds)) style:UITableViewStylePlain]; // _tableView.tableFooterView = [[UIView alloc] init]; _tableView.rowHeight =40.0; _tableView.sectionHeaderHeight = 0.0; _tableView.sectionFooterHeight = 0.0; _tableView.dataSource = self ; _tableView.delegate = self ; } return _tableView; } -( NSInteger )tableView:(UITableView *)tableView numberOfRowsInSection:( NSInteger )section{ return 5; } //http://www.cnblogs.com/xiaofeixiang 技术交流:228407086 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:( NSIndexPath *)indexPath{ UITableViewCell *cell=[[UITableViewCell alloc]init]; cell.textLabel.text=@ "博客园-FlyElephant" ; return cell; } 这个时候设置automaticallyAdjustsScrollViewInsets效果如下: 官方文档解释如下: 1 2 3 4 5 6 7 8 9 10 11 12 A Boolean value that indicates whether the view controller should automatically adjust its scroll view insets. Declaration SWIFT var automaticallyAdjustsScrollViewInsets: Bool OBJECTIVE-C @property ( nonatomic , assign) BOOL automaticallyAdjustsScrollViewInsets Discussion The default value of this property is YES , which allows the view controller to adjust its scroll view insets in response to the screen areas consumed by the status bar, navigation bar, and toolbar or tab bar. Set to NO if you want to manage scroll view inset adjustments yourself, such as when there is more than one scroll view in the view hierarchy. Availability Available in iOS 7.0 and later. 简单点说就是automaticallyAdjustsScrollViewInsets根据按所在界面的status bar,navigationbar,与tabbar的高度,自动调整scrollview的 inset,设置为no,不让viewController调整,我们自己修改布局即可~ 本文转自Fly_Elephant博客园博客,原文链接:http://www.cnblogs.com/xiaofeixiang/p/4655932.html,如需转载请自行联系原作者

优秀的个人博客,低调大师

iOS开发-装饰模式

装饰模式是指在不必改变原类文件和使用继承的情况下,动态地扩展一个对象的功能。通过创建一个包装对象,也就是装饰来包裹真实的对象。装饰模式中的装饰对象和真实对象有相同的接口。这样客户端对象就能以和真实对象相同的方式和装饰对象交互,同时装饰对象包含一个真实对象的引用(reference),装饰对象接受所有来自客户端的请求。它把这些请求转发给真实的对象。 装饰模式与继承都可以要扩展对象的功能,但是装饰模式可以提供比继承更多的灵活性。通过使用不同的具体装饰类以及这些装饰类的排列组合,可以创造出很多不同行为的组合。 基础设计 单纯的看概念有点单调,看一张经典的装饰模式的UML类图: Component:定义ConcreteComponent和Decorator类要实现的方法,装饰对象和真实对象的之间的通信就是通过Component实现; ConcreteComponent:真实对象,使用ConcreteComponent的派生类提供核心功能,与Decorator是同一级别; Decorator:具有特定装饰功能的类,用来装饰ConcreteComponent类,具体的装饰子类通过继承Decorator实现; 关于整体的轮廓有了一个大概的了解,我们可以通过生活的例子来模拟装饰模式,关于房子,有商业住宅和民用住宅,买了房子我们需要装修,桌子,椅子必不可少,我们最终需要算一下总费用,思考几秒可以看下面具体实现; 功能实现 设计基础类House和协议: 1 2 3 4 5 6 7 8 9 10 11 12 @protocol HouseDelegate <NSObject> @optional -( double )totalMoney; @end @ interface House : NSObject<HouseDelegate> -(NSString *)detialInfo; @end House的子类CommercialHouse,被装饰对象: 1 2 3 4 5 6 7 8 9 10 11 @implementation CommercialHouse -( double )totalMoney{ return 360000.89; } -(NSString *)detialInfo{ return [NSString stringWithFormat: @"商业住宅" ]; } @end 装饰对象的基类HouseDecorator,这里需要保持一个对被装饰对象的引用: 1 2 3 4 5 6 7 @ interface HouseDecorator : House -(instancetype)initWithHouse:(House *)house; @property (strong,nonatomic) House *house; @end 1 2 3 4 5 6 7 8 9 10 @implementation HouseDecorator -(instancetype)initWithHouse:(House *)house{ self=[super init]; if (self) { self.house=house; } return self; } @end 装饰对象TableDecorator: 1 2 3 4 5 6 7 8 9 10 11 @implementation TableDecorator -( double )totalMoney{ return self.house.totalMoney+10; } -(NSString *)detialInfo{ return [NSString stringWithFormat: @"%@--桌子" ,self.house.detialInfo]; } @end 装饰对象ChairDecorator: 1 2 3 4 5 6 7 8 9 10 11 @implementation ChairDecorator -( double )totalMoney{ return self.house.totalMoney+100; } -(NSString *)detialInfo{ return [NSString stringWithFormat: @"%@--椅子" ,self.house.detialInfo]; } @end 回到最初的总费用问题,我们看下结果: 1 2 3 4 5 6 7 House *house=[[CommercialHouse alloc]init]; house=[[TableDecorator alloc]initWithHouse:house]; house=[[ChairDecorator alloc]initWithHouse:house]; NSLog( @"房子价格:%f" , [house totalMoney]); NSLog( @"房子详情:%@" ,[house detialInfo]); NSLog( @"博客园-FlyElephant" ); NSLog( @"http://www.cnblogs.com/xiaofeixiang/" ); 桌子椅子的价格是可以动态变化的,桌子椅子的数量的也是不确定的,从这些角度看例子稍微有点勉强,不过大概功能设计实现大同小异,万变不离其宗,相信大家会对装饰模式有自己独到的见解~ 本文转自Fly_Elephant博客园博客,原文链接:http://www.cnblogs.com/xiaofeixiang/p/5097972.html,如需转载请自行联系原作者

资源下载

更多资源
腾讯云软件源

腾讯云软件源

为解决软件依赖安装时官方源访问速度慢的问题,腾讯云为一些软件搭建了缓存服务。您可以通过使用腾讯云软件源站来提升依赖包的安装速度。为了方便用户自由搭建服务架构,目前腾讯云软件源站支持公网访问和内网访问。

Nacos

Nacos

Nacos /nɑ:kəʊs/ 是 Dynamic Naming and Configuration Service 的首字母简称,一个易于构建 AI Agent 应用的动态服务发现、配置管理和AI智能体管理平台。Nacos 致力于帮助您发现、配置和管理微服务及AI智能体应用。Nacos 提供了一组简单易用的特性集,帮助您快速实现动态服务发现、服务配置、服务元数据、流量管理。Nacos 帮助您更敏捷和容易地构建、交付和管理微服务平台。

Rocky Linux

Rocky Linux

Rocky Linux(中文名:洛基)是由Gregory Kurtzer于2020年12月发起的企业级Linux发行版,作为CentOS稳定版停止维护后与RHEL(Red Hat Enterprise Linux)完全兼容的开源替代方案,由社区拥有并管理,支持x86_64、aarch64等架构。其通过重新编译RHEL源代码提供长期稳定性,采用模块化包装和SELinux安全架构,默认包含GNOME桌面环境及XFS文件系统,支持十年生命周期更新。

Sublime Text

Sublime Text

Sublime Text具有漂亮的用户界面和强大的功能,例如代码缩略图,Python的插件,代码段等。还可自定义键绑定,菜单和工具栏。Sublime Text 的主要功能包括:拼写检查,书签,完整的 Python API , Goto 功能,即时项目切换,多选择,多窗口等等。Sublime Text 是一个跨平台的编辑器,同时支持Windows、Linux、Mac OS X等操作系统。

用户登录
用户注册