本文的合集已經(jīng)編著成書荣茫,高級(jí)Android開發(fā)強(qiáng)化實(shí)戰(zhàn)侧戴,歡迎各位讀友的建議和指導(dǎo)故源。在京東即可購(gòu)買:https://item.jd.com/12385680.html
我會(huì)介紹關(guān)于Android的一些有趣的小知識(shí)點(diǎn). 上一篇. 第三篇.
1. Dagger2的開發(fā)順序
Module -> Component -> Application
首先模塊(Module)創(chuàng)建需要提供的類實(shí)例, 其次把模塊添加到組件(Component)中并提供需要注入的類, 最后把組件添加到應(yīng)用(Application)中并提供接口.
// 模塊
@Module
public class TestAppModule {
private final Context mContext;
public TestAppModule(Context context) {
mContext = context.getApplicationContext();
}
// 提供類實(shí)例
@AppScope
@Provides
public Context provideAppContext() {
return mContext;
}
@Provides
public WeatherApiClient provideWeatherApiClient() {
return new MockWeatherApiClient();
}
}
// 組件
@AppScope
@Component(modules = TestAppModule.class) // 注冊(cè)模塊
public interface TestAppComponent extends AppComponent {
void inject(MainActivityTest test);
}
// 應(yīng)用
public class TestWeatherApplication extends WeatherApplication {
private TestAppComponent mTestAppComponent;
@Override public void onCreate() {
super.onCreate();
mTestAppComponent = DaggerTestAppComponent.builder()
.testAppModule(new TestAppModule(this))
.build();
}
// 提供組件
@Override
public TestAppComponent getAppComponent() {
return mTestAppComponent;
}
}
2. JRebel
Android調(diào)試工具, 不用編譯, 就可以刷新一些項(xiàng)目修改. 不過(guò)功能已經(jīng)被Android Studio 2.0 代替, 等待2.0正式發(fā)版.
3. 數(shù)據(jù)綁定(DataBinding)
DataBinding實(shí)現(xiàn)數(shù)據(jù)與頁(yè)面的分離, 更符合面向?qū)ο蟮木幊棠J?
布局設(shè)置
<data>
<variable
name="weatherData"
type="clwang.chunyu.me.wcl_espresso_dagger_demo.data.WeatherData"/>
</data>
<TextView
android:id="@+id/temperature"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_marginBottom="@dimen/margin_large"
android:layout_marginTop="@dimen/margin_xlarge"
android:text="@{weatherData.temperatureCelsius}"
android:textAppearance="@style/TextAppearance.AppCompat.Display3"
tools:text="10°"/>
邏輯設(shè)置
private ActivityMainBinding mBinding; // 頁(yè)面綁定類
mBinding = DataBindingUtil.setContentView(this, R.layout.activity_main); // 綁定頁(yè)面
mBinding.weatherLayout.setVisibility(View.VISIBLE); // 使用Id
mBinding.setWeatherData(weatherData); // 綁定數(shù)據(jù)
4. ClassyShark
查看Apk信息的軟件, 功能非常強(qiáng)大, 省去反編譯的步驟, 主要功能:
(1) 在MultiDex中dex的詳細(xì)信息.
(2) 使用NativeLibrary的詳細(xì)信息.
(3) 類的詳細(xì)信息.
(4) 數(shù)量統(tǒng)計(jì).
5. CocoaPod安裝
升級(jí)Mac系統(tǒng), 可能會(huì)導(dǎo)致Pod命令消失, 需要重新安裝Pod.
sudo gem install -n /usr/local/bin cocoapods
6. LaunchMode
LaunchMode包含四種模式,
(1) standard, 標(biāo)準(zhǔn)模式, 啟動(dòng)重新創(chuàng)建示例, 默認(rèn).
(2) singleTop, 棧頂復(fù)用模式, 位于棧頂, 啟動(dòng)不會(huì)被創(chuàng)建, 調(diào)用onNewIntent.
(3) singleTask, 棧內(nèi)復(fù)用模式, 存在不會(huì)被創(chuàng)建, 調(diào)用onNewIntent.
(4) singleInstance, 單實(shí)例模式, 單獨(dú)位于一個(gè)任務(wù)棧內(nèi), 復(fù)用.
7. TextView的標(biāo)準(zhǔn)字體
樣式
style="@style/TextAppearance.AppCompat.Display4"
style="@style/TextAppearance.AppCompat.Display3"
style="@style/TextAppearance.AppCompat.Display2"
style="@style/TextAppearance.AppCompat.Display1"
style="@style/TextAppearance.AppCompat.Headline"
style="@style/TextAppearance.AppCompat.Title"
style="@style/TextAppearance.AppCompat.Subhead"
style="@style/TextAppearance.AppCompat.Body2"
style="@style/TextAppearance.AppCompat.Body1"
style="@style/TextAppearance.AppCompat.Caption"
style="@style/TextAppearance.AppCompat.Button"
顯示
8. 自動(dòng)生成DbHelper的腳本
下載地址
安裝Jinja2.
pip install Jinja2
設(shè)置數(shù)據(jù)
CLASS Repo
String Id
String Name
String Description
String Owner
ENDCLASS
下載代碼庫(kù). 生成代碼.
python sql_lite_helper.py -f ~/Desktop/Repo -n SampleGenerate -p me.chunyu -a clwang
9. Gson的序列化參數(shù)
有些情況下, Json名稱與變量不同, 需要指定.
@SerializedName("avatar_url") private String avatarUrl;
10. Proguard保留庫(kù)
最簡(jiǎn)潔的方式是全部保留. 去除警告dontwarn, 保留類keep class.
# 在線更新
-dontwarn clwang.chunyu.me.**
-keep class clwang.chunyu.me.**{*;}
OK, That's all! Enjoy It!