Android开源:Meepo-类似 Retrofit 的跳转路由
<p style="text-align:center"><img src="https://simg.open-open.com/show/5123262d1b3c76b32c02bcd810eb43b8.jpg"></p> <h2>Meepo</h2> <p>Meepo is a <strong> <a href="/misc/goto?guid=4958964956869128717" rel="nofollow,noindex">retrofit</a> </strong> -like router generator for Android. You can use it to create routers for Activities, Fragments and even any things.</p> <h3>Install</h3> <pre> <code class="language-java">repositories { maven { url "https://jitpack.io" } } dependencies { compile 'com.github.nekocode:Meepo:{lastest-version}' }</code></pre> <h2>Usage</h2> <p>Declare the router interface firstly. Meepo turns your navigation methods into a Java interface.</p> <pre> <code class="language-java">public interface Router { @TargetPath("user/{user_id}/detail") boolean gotoUserDetail(Context context, @Path("user_id") String userId, @Query("show_title") boolean showTitle); @TargetClass(StoreActivity.class) @TargetFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP) void gotoB(Context context, @Bundle("title") String title); }</code></pre> <p>If you want to use URI to open your Activity, you need to add an <intent-filter> element in your manifest file for the corresponding <activity> element.</p> <pre> <code class="language-java"><activity android:name=".UserDetailActivity"> <intent-filter> <action android:name="android.intent.action.VIEW"/> <category android:name="android.intent.category.DEFAULT"/> <data android:host="meepo.com" android:pathPattern="/user/.*/detail" android:scheme="meepo"/> </intent-filter> </activity></code></pre> <p>Use the Meepo class to generate an implementation of your router interface.</p> <pre> <code class="language-java">final Meepo meepo = new Meepo.Builder() .config(new UriConfig().scheme("meepo").host("meepo.com")) .build(); final Router router = meepo.create(Router.class);</code></pre> <p>Now, you can use the router 's methods to navigate activity instead of startActivity() directly.</p> <pre> <code class="language-java">boolean isSucess = router.gotoUserDetail(this, "123", true);</code></pre> <h2>Router Annonation</h2> <p>Meepo supports below router annonations currently:</p> <table> <thead> <tr> <th>Annonation</th> <th>Description</th> </tr> </thead> <tbody> <tr> <td>@TargetClass</td> <td>Declare the target Class (Such as target Activity or Fragment)</td> </tr> <tr> <td>@TargetPath</td> <td>Declare the path of URI path (and MimeType)</td> </tr> <tr> <td>@TargetAction</td> <td>Declare the Intent action</td> </tr> <tr> <td>@TargetFlags</td> <td>Declare the Intent flags</td> </tr> <tr> <td>@Bundle</td> <td>Put data into the Intent's Bundle</td> </tr> <tr> <td>@Path</td> <td>Replace the URI path's corresponding replacement block with string parameter</td> </tr> <tr> <td>@Query</td> <td>Query parameter of the URI</td> </tr> <tr> <td>@QueryMap</td> <td>Map of Query parameters</td> </tr> <tr> <td>@RequestCode</td> <td>Request code for startActivityForResult()</td> </tr> </tbody> </table> <h2>Custom Parser and GotoAdapter</h2> <p>You can create custom Parser and GotoAdapter for Meepo. See the <strong> <a href="/misc/goto?guid=4959747706619448765" rel="nofollow,noindex">sample</a> </strong> for more detail. It means that you have the ability to make router for anything.</p> <pre> <code class="language-java">final ModuleRouter moduleRouter = new Meepo.Builder() .config(new ModuleConfig("TEST")) .parser(new ModuleParser()) .adapter(new GotoModuleAdapter()) .build() .create(ModuleRouter.class);</code></pre> <p> </p> <p>项目主页:<a href="http://www.open-open.com/lib/view/home/1492653726254">http://www.open-open.com/lib/view/home/1492653726254</a></p> <p> </p>
本文由用户 fugees 自行上传分享,仅供网友学习交流。所有权归原作者,若您的权利被侵害,请联系管理员。
转载本站原创文章,请注明出处,并保留原始链接、图片水印。
本站是一个以用户分享为主的开源技术平台,欢迎各类分享!