groovy寫安卓代碼注意事項:
下載sdk:http://groovy-lang.org/download.html
需要配置:
apply plugin: 'com.android.application'
buildscript { repositories { jcenter() }
dependencies { classpath 'com.android.tools.build:gradle:1.3.0' classpath 'org.codehaus.groovy:gradle-groovy-android-plugin:0.3.6' }
}
apply plugin: 'groovyx.grooid.groovy-android'
dependencies { compile 'org.codehaus.groovy:groovy:2.4.3:grooid' compile('org.codehaus.groovy:groovy-json:2.4.3') { transitive = false }
}
一個groovy寫的遵循Google Material Design设计原则安卓源代碼
https://github.com/zzhoujay/Gank4Android
參考:
http://m.blog.csdn.net/blog/zhjali123/45128187
Gradle: 错误:编码 GBK 的不可映射字符的解決方案:
tasks.withType(Compile) {
options.encoding = “UTF-8”
}
Gradle2.0+环境下需将Compile改为JavaCompile
tasks.withType(JavaCompile) {
options.encoding = “UTF-8”
}
Mac下批量将GBK转换UTF-8编码
http://weijun.me/post/develop/2015-07-29
原理:
mac shell
iconv -f GBK -t UTF8 “
中文文字感情分享,java開源庫
https://www.jb51.cc/semanticanalysis
http://git.oschina.net/www.feit.com/SemanticAnalysis
使用方式:
1.自行编译src 或者直接下载dist中的zg-sa.jar
2.需要引用的第三方的包位于lib文件夹中
DEMO:
?
1
2
3
Analysis analysis = new Analysis();
System.out.println(“1: ” + analysis.parse(“这是一个普通评论”).getCode());
System.out.println(“2: ” + analysis.parse(“中国加油!”).getdisplay());
输出:
1: 0
2: 正面
正面:1
负面:-1
中性:0
android 6.0 ssl3_get_server_key_exchange:BAD_DH_P_LENGTH
http://bbs.csdn.net/topics/391843187
出現這個原因是因為:
android自家寫的BoringSSL不在支持openssl的漏洞導致logjam attack
保存fragment狀態
activity裡面這樣寫:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.contentContainer,MainFragment.newInstance())
.commit();
}
}
fragment里面这样写:
Bundle savedState;
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
// Restore State Here
if (!restoreStateFromArguments()) {
// First Time running,Initialize something here
}
}
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
// Save State Here
// 這裡是防止旋轉屏幕是出現的狀態丟失問題
saveStatetoArguments();
}
@Override
public void onDestroyView() {
super.onDestroyView();
// Save State Here
saveStatetoArguments();
}
private void saveStatetoArguments() {
savedState = saveState();
if (savedState != null) {
Bundle b = getArguments();
b.putBundle(“internalSavedViewState8954201239547”,savedState);
}
}
private boolean restoreStateFromArguments() {
Bundle b = getArguments();
savedState = b.getBundle(“internalSavedViewState8954201239547”);
if (savedState != null) {
restoreState();
return true;
}
return false;
}
/////////////////////////////////
// 取出状态数据
/////////////////////////////////
private void restoreState() {
if (savedState != null) {
//比如
//tv1.setText(savedState.getString(“text”));
}
}
//////////////////////////////
// 保存状态数据
//////////////////////////////
private Bundle saveState() {
Bundle state = new Bundle();
// 比如
//state.putString(“text”,tv1.getText().toString());
return state;
}
參考:
http://www.jcodecraeer.com/a/anzhuokaifa/androidkaifa/2015/0327/2648.html
http://inthecheesefactory.com/blog/fragment-state-saving-best-practices/en
一個有demo的開源地址:
https://github.com/nuuneoi/StatedFragment