|
| 1 | +#### MyActivity |
| 2 | + |
| 3 | +> 所有的 Activity 必须继承至 MyActivity,如果使用 MVP 请继承至 MvpActivity,已经处理了 Activity 多重启动的问题,[详情可点击此处查看](https://www.jianshu.com/p/579f1f118161) |
| 4 | +
|
| 5 | +> 获取 Context 或者 Activity |
| 6 | +
|
| 7 | + public Context getContext() |
| 8 | + |
| 9 | + public <A extends BaseActivity> A getActivity() |
| 10 | + |
| 11 | +> startActivity 方法优化 |
| 12 | +
|
| 13 | + public void startActivity(Class<? extends Activity> cls) |
| 14 | + |
| 15 | + public void startActivityFinish(Class<? extends Activity> cls) |
| 16 | + |
| 17 | + public void startActivityFinish(Intent intent) |
| 18 | + |
| 19 | +> startActivityForResult 方法优化 |
| 20 | +
|
| 21 | + public void startActivityForResult(Intent intent, ActivityCallback callback) |
| 22 | + |
| 23 | + public void startActivityForResult(Intent intent, @Nullable Bundle options, ActivityCallback callback) |
| 24 | + |
| 25 | +> setResult 方法优化 |
| 26 | +
|
| 27 | + public void finishResult(int resultCode) |
| 28 | + |
| 29 | + public void finishResult(int resultCode, Intent data) |
| 30 | + |
| 31 | +> Activity 标题 |
| 32 | +
|
| 33 | + public void setTitle(int titleId) |
| 34 | + |
| 35 | + public void setTitle(CharSequence title) |
| 36 | + |
| 37 | + public CharSequence getTitle() |
| 38 | + |
| 39 | +> Toast 方法 |
| 40 | +
|
| 41 | + public void toast(CharSequence s) |
| 42 | + |
| 43 | + public void toast(int id) |
| 44 | + |
| 45 | + public void toast(Object object) |
| 46 | + |
| 47 | +> Handler 方法 |
| 48 | +
|
| 49 | + public static Handler getHandler() |
| 50 | + |
| 51 | +> TitleBar 方法 |
| 52 | +
|
| 53 | + public TitleBar getTitleBar() |
| 54 | + |
| 55 | +> TitleBar 监听方法(需要被重写) |
| 56 | +
|
| 57 | + // 标题栏左项被点击了,默认返回 |
| 58 | + public void onLeftClick(View v) |
| 59 | + |
| 60 | + // 标题栏中间项被点击了 |
| 61 | + public void onTitleClick(View v) |
| 62 | + |
| 63 | + // 标题栏右项被点击了 |
| 64 | + public void onRightClick(View v) |
| 65 | + |
| 66 | +#### MyFragment |
| 67 | + |
| 68 | +> 获取Activity,防止出现 getActivity() 为空 |
| 69 | +
|
| 70 | + public FragmentActivity getFragmentActivity() |
| 71 | + |
| 72 | +> 是否进行了懒加载 |
| 73 | +
|
| 74 | + protected boolean isLazyLoad() |
| 75 | + |
| 76 | +> 当前 Fragment 是否可见 |
| 77 | +
|
| 78 | + public boolean isFragmentVisible() |
| 79 | + |
| 80 | +> 跟 Activity 的同名方法效果一样 |
| 81 | +
|
| 82 | + protected void onRestart() |
| 83 | + |
| 84 | +> 根据资源 id 获取一个 View 对象 |
| 85 | +
|
| 86 | + protected <T extends View> T findViewById(@IdRes int id) |
| 87 | + |
| 88 | + protected <T extends View> T findActivityViewById(@IdRes int id) |
| 89 | + |
| 90 | +> 跳转到其他Activity |
| 91 | +
|
| 92 | + public void startActivity(Class<? extends Activity> cls) |
| 93 | + |
| 94 | +> 销毁当前 Fragment 所在的 Activity |
| 95 | +
|
| 96 | + public void finish() |
| 97 | + |
| 98 | +> 获取系统服务 |
| 99 | +
|
| 100 | + public Object getSystemService(@NonNull String name) |
| 101 | + |
| 102 | +> Fragment返回键被按下时回调(只做预留方法,没有效果) |
| 103 | +
|
| 104 | + public boolean onKeyDown(int keyCode, KeyEvent event) |
| 105 | + |
| 106 | +> Toast 方法 |
| 107 | +
|
| 108 | + public void toast(CharSequence s) |
| 109 | + |
| 110 | + public void toast(int id) |
| 111 | + |
| 112 | + public void toast(Object object) |
| 113 | + |
| 114 | +##### MyRecyclerViewAdapter |
| 115 | + |
| 116 | +> 获取 RecyclerView 或者 Context |
| 117 | +
|
| 118 | + public RecyclerView getRecyclerView() |
| 119 | + |
| 120 | + public Context getContext() |
| 121 | + |
| 122 | +> 布局摆放器(可以被重载,由于 RecyclerView 不能没有设置 LayoutManager,这里设置了默认的) |
| 123 | +
|
| 124 | + protected RecyclerView.LayoutManager getDefaultLayoutManager(Context context) { |
| 125 | + return new LinearLayoutManager(context); |
| 126 | + } |
| 127 | + |
| 128 | +> 分页逻辑预留方法 |
| 129 | +
|
| 130 | + public int getPageNumber() |
| 131 | + |
| 132 | + public void setPageNumber(int pageNumber) |
| 133 | + |
| 134 | + public boolean isLastPage() |
| 135 | + |
| 136 | + public void setLastPage(boolean lastPage) |
| 137 | + |
| 138 | +> 标记方法 |
| 139 | +
|
| 140 | + public Object getTag() |
| 141 | + |
| 142 | + public void setTag(Object tag) |
| 143 | + |
| 144 | +> 操作数据集合 |
| 145 | +
|
| 146 | + public void setData(List<T> data) |
| 147 | + |
| 148 | + public List<T> getData() |
| 149 | + |
| 150 | + public void addData(List<T> data) |
| 151 | + |
| 152 | + public void clearData() |
| 153 | + |
| 154 | +> 操作单个数据 |
| 155 | +
|
| 156 | + public T getItem(int position) |
| 157 | + |
| 158 | + public void setItem(int position, T item) |
| 159 | + |
| 160 | + public void addItem(T item) |
| 161 | + |
| 162 | + public void addItem(int position, T item) |
| 163 | + |
| 164 | + public void removeItem(T item) |
| 165 | + |
| 166 | + public void removeItem(int position) |
| 167 | + |
| 168 | +> MyRecyclerViewAdapter.ViewHolder 方法 |
| 169 | +
|
| 170 | + public final View getItemView() |
| 171 | + |
| 172 | + public final <V extends View> V findViewById(@IdRes int viewId) |
| 173 | + |
| 174 | + public final ViewHolder setText(@IdRes int viewId, @StringRes int resId) |
| 175 | + |
| 176 | + public final ViewHolder setText(@IdRes int viewId, String text) |
| 177 | + |
| 178 | + public final ViewHolder setVisibility(@IdRes int viewId, int visibility) |
| 179 | + |
| 180 | + public final ViewHolder setColor(@IdRes int viewId, @ColorInt int color) |
| 181 | + |
| 182 | + public final ViewHolder setImage(@IdRes int viewId, @DrawableRes int resId) |
| 183 | + |
| 184 | +> 监听方法(必须在 RecyclerView.setAdapter 之前调用) |
| 185 | +
|
| 186 | + public void setOnItemClickListener(OnItemClickListener l) |
| 187 | + |
| 188 | + public void setOnChildClickListener(@IdRes int childId, OnChildClickListener l) |
| 189 | + |
| 190 | + public void setOnItemLongClickListener(OnItemLongClickListener l) |
| 191 | + |
| 192 | + public void setOnChildLongClickListener(@IdRes int childId, OnChildLongClickListener l) |
| 193 | + |
| 194 | + public void setOnScrollingListener(OnScrollingListener l) |
| 195 | + |
| 196 | +> MyListViewAdapter 和 MyRecyclerViewAdapter 差不多,只不过没有上面这些监听方法,因为 ListView 本身已经自带这些了 |
| 197 | +
|
0 commit comments