Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
chenenyu committed Dec 28, 2016
0 parents commit b5dc5fa
Show file tree
Hide file tree
Showing 58 changed files with 1,499 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.DS_Store
.gradle
local.properties
.idea
build
*.iml
/captures
.externalNativeBuild
1 change: 1 addition & 0 deletions annotation/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
4 changes: 4 additions & 0 deletions annotation/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
apply plugin: 'java'

sourceCompatibility = "1.7"
targetCompatibility = "1.7"
17 changes: 17 additions & 0 deletions annotation/src/main/java/com/chenenyu/router/annotation/Route.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.chenenyu.router.annotation;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* Annotation for route.
* <p>
* Created by Cheney on 2016/12/20.
*/
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.CLASS)
public @interface Route {
String[] value();
}
1 change: 1 addition & 0 deletions app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
33 changes: 33 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
apply plugin: 'com.android.application'
apply plugin: 'com.neenbedankt.android-apt'

android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "com.chenenyu.router.demo"
minSdkVersion 14
targetSdkVersion 25
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(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
apt project(':compiler')
compile project(':library')
compile 'com.android.support:appcompat-v7:25.1.0'
compile 'com.android.support.constraint:constraint-layout:1.0.0-beta4'
testCompile 'junit:junit:4.12'
}
25 changes: 25 additions & 0 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /Users/Cheney/workspace/AndroidSDK/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 *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.chenenyu.router.demo;

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.assertEquals;

/**
* 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.chenenyu.router.demo", appContext.getPackageName());
}
}
33 changes: 33 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest package="com.chenenyu.router.demo"
xmlns:android="http://schemas.android.com/apk/res/android">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
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>
<activity
android:name=".TestActivity"
android:label="TestActivity">
</activity>
<activity
android:name=".DynamicActivity"
android:label="DynamicActivity">
</activity>
<activity
android:name=".ForResultActivity"
android:label="ForResultActivity">
</activity>
</application>

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

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

public class DynamicActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_not_annotated);
}
}
33 changes: 33 additions & 0 deletions app/src/main/java/com/chenenyu/router/demo/ForResultActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.chenenyu.router.demo;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.chenenyu.router.annotation.Route;

@Route("result")
public class ForResultActivity extends AppCompatActivity {

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

String extra = getIntent().getStringExtra("extra");
TextView textExtra = (TextView) findViewById(R.id.text_extra);
textExtra.setText(extra);

Button result = (Button) findViewById(R.id.btn_result);
result.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
setResult(RESULT_OK, new Intent().putExtra("extra", "Result from ForResultActivity"));
finish();
}
});
}
}
106 changes: 106 additions & 0 deletions app/src/main/java/com/chenenyu/router/demo/MainActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
package com.chenenyu.router.demo;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.chenenyu.router.RouteCallBack;
import com.chenenyu.router.RouteTable;
import com.chenenyu.router.Router;

import java.util.Map;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {
private final String TAG = "RouterDemo";
private EditText editRoute;
private String uri;
private Button btn0, btn1, btn2, btn3, btn4, btn5;

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

editRoute = (EditText) findViewById(R.id.edit_route);
btn0 = (Button) findViewById(R.id.btn0);
btn1 = (Button) findViewById(R.id.btn1);
btn2 = (Button) findViewById(R.id.btn2);
btn3 = (Button) findViewById(R.id.btn3);
btn4 = (Button) findViewById(R.id.btn4);
btn5 = (Button) findViewById(R.id.btn5);

btn0.setOnClickListener(this);
btn1.setOnClickListener(this);
btn2.setOnClickListener(this);
btn3.setOnClickListener(this);
btn4.setOnClickListener(this);
btn5.setOnClickListener(this);
editRoute.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {

}

@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {

}

@Override
public void afterTextChanged(Editable s) {
uri = s.toString();
btn0.setText(getString(R.string.go_to, s));
}
});

// 动态添加路由表
Router.addRouteTable(new RouteTable() {
@Override
public void initActivityTable(Map<String, Class<? extends Activity>> map) {
map.put("dynamic", DynamicActivity.class);
}
});
}

@Override
public void onClick(View v) {
if (v == btn0) {
Router.build(uri).callback(new RouteCallBack() { // 添加结果回调
@Override
public void succeed(Uri uri) {
Log.i(TAG, "succeed: " + uri.toString());
}

@Override
public void error(Uri uri, String message) {
Log.w(TAG, "error: " + uri + ", " + message);
}
}).go(this);
} else if (v == btn1) {
Router.build(btn1.getText().toString()).go(this);
} else if (v == btn2) {
Router.build("dynamic").go(this);
} else if (v == btn3) {
Bundle bundle = new Bundle();
bundle.putString("extra", "Bundle from MainActivity.");
Router.build("result").requestCode(0).extras(bundle).go(this);
}
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == 0 && resultCode == RESULT_OK) {
String result = data.getStringExtra("extra");
Toast.makeText(this, result, Toast.LENGTH_SHORT).show();
}
}
}
16 changes: 16 additions & 0 deletions app/src/main/java/com/chenenyu/router/demo/TestActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.chenenyu.router.demo;

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

import com.chenenyu.router.annotation.Route;

@Route("test")
public class TestActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test);
}
}
23 changes: 23 additions & 0 deletions app/src/main/res/layout/activity_for_result.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
android:id="@+id/activity_for_result"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.chenenyu.router.demo.ForResultActivity">

<TextView
android:id="@+id/text_extra"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="extra"/>

<Button
android:id="@+id/btn_result"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="setResult"/>

</FrameLayout>
Loading

0 comments on commit b5dc5fa

Please sign in to comment.