Skip to content

Commit

Permalink
feat: init product
Browse files Browse the repository at this point in the history
  • Loading branch information
guangli.lgl committed Apr 5, 2017
0 parents commit 820af9d
Show file tree
Hide file tree
Showing 33 changed files with 739 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
*.iml
.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
/build
/captures
.externalNativeBuild
23 changes: 23 additions & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions .idea/copyright/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

84 changes: 84 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/runConfigurations.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

113 changes: 113 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
# 1 代码规范
## 1.1 Class 命名
任何类名都应该使用 UpperCamelCase (驼峰法)命名, 例如:

AndroidActivity, NetworkHelper, UserFragment, PerActivity

## 1.2 变量名。

- 变量名:静态常量使用大写字母,使用下划线“_”分词。
- 非静态成员变量、局部变量、首字母小写,驼峰式分词。
- Activity、Fragment、Adapter、View 的子类的成员变量:m开头、驼峰式分词。
- 方法名:首字母小写,驼峰式分词。

# 1.3 成员变量定义顺序(建议)

- 公用静态常量
- 公用静态变量
- 私用静态常量
- 私用静态变量
- 私有非静态变量

## 1.4 禁止”魔术数”:

switch(i) {
case 1:
mManager.updloadTag();
break;
mManager.uploadTabMore();
case 2:
// do something
break;
// ...
case 3:
// ....
break;
}

代码中的 case 后的数字即为魔术数,应该使用有明示意义的常量代替。

## 1.5 禁止忽略异常:

public void setUserId(String id) {
try {
mUserId = Integer.parseInt(id);
} catch (NumberFormatException e) { }
}


## 1.6 避免UI线程IO:

不要在主线程执行IO或网络的操作 ( 卡顿工具检查主线程的方法时间设置阀值,超过用子线程去执行 )。

# 1.7 非静态匿名内部类请用WeakReference 方式持有外部对象的引用

Runnable timeCallback = new Runnable () {
if(mRef ! = null) {
Activity activity = mRef.get();
if(activity != null) {
// do stuff
}
}

}


# 1.8 长度限制

- 一行代码的长度:不要超过160个字符。
- 一个方法的长度:不要超过:80行。
- 一个文件的长度不超过:1000行。
- 一个方法的参数列表不要超过:7个。
- if 嵌套层次:不要超过4层。
- 无用代码
- 禁止无用的import。
- 禁止import *。
- 禁止无用变量。

# 2 Resource 命名

## 2.1 Activity、Fragment、Dialog的布局命名:activity/fragment/dialog+模块,小写字母使用下划线 ”_ ”分词。
例如:

activity_main, fragment_user,dialog_login_input.xml


## 2.2 控件布局命名:模块名+布局类型,小写字母使用下划线 ”_ ”分词。例如:goods_list_item。

## 2.3 图片资源

不再使用的布局资源及时删除。

## 2.2 图片

图片以ic_为前缀,与功能、状态一起命名。例如:

ic_accept

其他 drawable 文件应该使用相应的前缀,例如:

|类型 | 前缀 |例如 |
|----- |---- |---- |
|Selector |selector_ |selector_button_cancel|
|Background |bg_ |bg_rounded_button|
|Circle |circle_ |circle_white|
|Progress |progress_ |progress_circle_purple|
|Divider |divider_ |divider_grey|

## 2.3 字符串命名

相同英文含义,小写字母使用下划线 ”_ ”分词。

## 2.4 其他
避免使用"px"作为单位。
1 change: 1 addition & 0 deletions app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
29 changes: 29 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 24
buildToolsVersion "25.0.0"
defaultConfig {
applicationId "com.dalimao.mytaxi"
minSdkVersion 15
targetSdkVersion 24
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:24.2.1'
testCompile 'junit:junit:4.12'
}
17 changes: 17 additions & 0 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /Users/liuguangli/Library/Android/sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# Add any project specific keep options here:

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.dalimao.mytaxi;

import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;

import org.junit.Test;
import org.junit.runner.RunWith;

import static org.junit.Assert.*;

/**
* Instrumentation test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() throws Exception {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getTargetContext();

assertEquals("com.dalimao.mytaxi", appContext.getPackageName());
}
}
20 changes: 20 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.dalimao.mytaxi">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>
13 changes: 13 additions & 0 deletions app/src/main/java/com/dalimao/mytaxi/MainActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.dalimao.mytaxi;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
Loading

0 comments on commit 820af9d

Please sign in to comment.