1.啟動圖功能開發與封裝(倒計時效果)
【添加依賴】Banner依賴;fastjson庫;
2. 持久化
【持久化】包含三種:sp;file;sqlit;
【sp封裝源碼】com.flj.latte.util.storage.LattePreference
1 package com.flj.latte.util.storage; 2 3 import android.content.SharedPreferences; 4 import android.preference.PreferenceManager; 5 6 import com.alibaba.fastjson.JSON; 7 import com.alibaba.fastjson.JSONObject; 8 import com.flj.latte.app.Latte; 9 10 /** 11 * Created by 傅令傑 on 2017/4/22 12 */ 13 14 public final class LattePreference { 15 16 /** 17 * 提示: 18 * 【用於Activity內部存儲】Activity.getPreferences(int mode)生成 Activity名.xml 19 * 【用於數據的保存】PreferenceManager.getDefaultSharedPreferences(Context)生成 “包名_preferences.xml” 20 * 【自定義名稱】Context.getSharedPreferences(String name,int mode)生成name.xml 21 */ 22 private static final SharedPreferences PREFERENCES = 23 PreferenceManager.getDefaultSharedPreferences(Latte.getApplicationContext()); 24 25 private static final String APP_PREFERENCES_KEY = "profile";//定義一個key值; 26 27 private static SharedPreferences getAppPreference() { 28 return PREFERENCES; 29 } 30 31 public static void setAppProfile(String val) { 32 getAppPreference() 33 .edit() 34 .putString(APP_PREFERENCES_KEY, val) 35 .apply(); 36 } 37 38 public static String getAppProfile() { 39 return getAppPreference().getString(APP_PREFERENCES_KEY, null); 40 } 41 42 public static JSONObject getAppProfileJson() { 43 final String profile = getAppProfile(); 44 return JSON.parseObject(profile); 45 } 46 47 public static void removeAppProfile() { 48 getAppPreference() 49 .edit() 50 .remove(APP_PREFERENCES_KEY) 51 .apply(); 52 } 53 54 public static void clearAppPreferences() { 55 getAppPreference() 56 .edit() 57 .clear() 58 .apply(); 59 } 60 61 /** 62 * flag:true:第一次存儲數據;fasle:非第一次存儲數據 63 * @param key 64 * @param flag 65 */ 66 public static void setAppFlag(String key, boolean flag) { 67 getAppPreference() 68 .edit() 69 .putBoolean(key, flag) 70 .apply(); 71 } 72 73 public static boolean getAppFlag(String key) { 74 return getAppPreference() 75 .getBoolean(key, false); 76 } 77 78 public static void addCustomAppProfile(String key, String val) { 79 getAppPreference() 80 .edit() 81 .putString(key, val) 82 .apply(); 83 } 84 85 public static String getCustomAppProfile(String key) { 86 return getAppPreference().getString(key, ""); 87 } 88 89 }
3.倒計時工具庫封裝
【說明】需要實現一個接口,然后回調;
4.第一個啟動頁面的倒計時
【說明】繼承與封裝好的fragment;
【使用drawable控制形狀】現在的textView是正方形,與實際的使用不符合,現在使用drawable控制;
【布局文件的完善】
【布局的的增加】
【增加插件和依賴】
【初始化timer】
【基類增加返回activity】
【定時任務的設置】
【測試】
5.啟動圖功能開發與封裝(輪播效果)
5.1 輪播圖片的添加
【需要使用到的依賴】
【類泛型的源碼的查看】
【圖片的加入】需要新建類,添加輪播的圖片;
【新建CB類】
【新建holder】ImageView的設置
【完善啟動頁】
5.2 指示器的添加
【設置指示器】新建兩個顏色的選中與未選中的指示器;
【原則】業務中可以使用圖片代替代碼的就是用圖片;框架中可以使用代碼就使用代碼,不要使用圖片;
【指示器設置位置】
【指示器加入到APP中並且item響應點擊事件】
【測試效果】
6.啟動圖功能優化與完善
【設計】如果是第一次啟動,則需要顯示滾動輪播圖,如果不是第一次啟動,則需要顯示單張圖片5s;
【新建枚舉類】標記是否為第一次開啟登錄;
【說明】由於目前沒有書寫登錄的邏輯,現在只是設置了標記;
【檢查是否顯示啟動頁】第一次進入APP的時候需要展示滾動畫面,非第一次,漸變圖進入到主頁面;
【非第一次漸變頁的跳轉事件按鈕的點擊】
【測試應用】
[去除titleBar]
【效果】經過第一次的點擊之后,直接進入到倒計時,過了5s時間然后停止了