Skip to content

Commit 13de1f9

Browse files
author
[chengxinping]
committed
完成项目框架
1 parent eea3989 commit 13de1f9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+959
-0
lines changed

Diff for: .gitignore

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
*.iml
2+
.gradle
3+
/local.properties
4+
/.idea/workspace.xml
5+
/.idea/libraries
6+
.DS_Store
7+
/build
8+
/captures
9+
.externalNativeBuild

Diff for: .idea/compiler.xml

+22
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: .idea/copyright/profiles_settings.xml

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: .idea/gradle.xml

+19
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: .idea/misc.xml

+46
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: .idea/modules.xml

+9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: .idea/runConfigurations.xml

+12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: .idea/vcs.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: app/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

Diff for: app/build.gradle

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
apply plugin: 'com.android.application'
2+
3+
android {
4+
compileSdkVersion 25
5+
buildToolsVersion "25.0.2"
6+
defaultConfig {
7+
applicationId "com.cxp.jokes"
8+
minSdkVersion 19
9+
targetSdkVersion 25
10+
versionCode 1
11+
versionName "1.0"
12+
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
13+
}
14+
buildTypes {
15+
release {
16+
minifyEnabled false
17+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18+
}
19+
}
20+
}
21+
22+
dependencies {
23+
compile fileTree(dir: 'libs', include: ['*.jar'])
24+
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
25+
exclude group: 'com.android.support', module: 'support-annotations'
26+
})
27+
compile 'com.android.support:appcompat-v7:25.1.0'
28+
compile 'com.android.support:design:25.1.0'
29+
compile 'com.android.support:support-v4:25.1.0'
30+
testCompile 'junit:junit:4.12'
31+
}

Diff for: app/proguard-rules.pro

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Add project specific ProGuard rules here.
2+
# By default, the flags in this file are appended to flags specified
3+
# in /home/cxp/Android/Sdk/tools/proguard/proguard-android.txt
4+
# You can edit the include path and order by changing the proguardFiles
5+
# directive in build.gradle.
6+
#
7+
# For more details, see
8+
# http://developer.android.com/guide/developing/tools/proguard.html
9+
10+
# Add any project specific keep options here:
11+
12+
# If your project uses WebView with JS, uncomment the following
13+
# and specify the fully qualified class name to the JavaScript interface
14+
# class:
15+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16+
# public *;
17+
#}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.cxp.jokes;
2+
3+
import android.content.Context;
4+
import android.support.test.InstrumentationRegistry;
5+
import android.support.test.runner.AndroidJUnit4;
6+
7+
import org.junit.Test;
8+
import org.junit.runner.RunWith;
9+
10+
import static org.junit.Assert.*;
11+
12+
/**
13+
* Instrumentation test, which will execute on an Android device.
14+
*
15+
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
16+
*/
17+
@RunWith(AndroidJUnit4.class)
18+
public class ExampleInstrumentedTest {
19+
@Test
20+
public void useAppContext() throws Exception {
21+
// Context of the app under test.
22+
Context appContext = InstrumentationRegistry.getTargetContext();
23+
24+
assertEquals("com.cxp.jokes", appContext.getPackageName());
25+
}
26+
}

Diff for: app/src/main/AndroidManifest.xml

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="com.cxp.jokes">
4+
5+
<application
6+
android:allowBackup="true"
7+
android:icon="@mipmap/icon"
8+
android:label="@string/app_name"
9+
android:supportsRtl="true"
10+
android:theme="@style/AppTheme">
11+
<activity
12+
android:name=".MainActivity"
13+
android:label="@string/app_name"
14+
android:theme="@style/AppTheme.NoActionBar">
15+
<intent-filter>
16+
<action android:name="android.intent.action.MAIN" />
17+
<category android:name="android.intent.category.LAUNCHER" />
18+
</intent-filter>
19+
</activity>
20+
</application>
21+
22+
</manifest>

Diff for: app/src/main/java/com/cxp/jokes/MainActivity.java

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
package com.cxp.jokes;
2+
3+
import android.os.Bundle;
4+
import android.support.design.widget.NavigationView;
5+
import android.support.v4.app.Fragment;
6+
import android.support.v4.app.FragmentTransaction;
7+
import android.support.v4.view.GravityCompat;
8+
import android.support.v4.widget.DrawerLayout;
9+
import android.support.v7.app.ActionBarDrawerToggle;
10+
import android.support.v7.app.AppCompatActivity;
11+
import android.support.v7.widget.Toolbar;
12+
import android.view.MenuItem;
13+
import android.widget.Toast;
14+
15+
import com.cxp.jokes.fragment.GifFragment;
16+
import com.cxp.jokes.fragment.PicFragment;
17+
import com.cxp.jokes.fragment.TxtFragment;
18+
19+
public class MainActivity extends AppCompatActivity
20+
implements NavigationView.OnNavigationItemSelectedListener {
21+
22+
@Override
23+
protected void onCreate(Bundle savedInstanceState) {
24+
super.onCreate(savedInstanceState);
25+
setContentView(R.layout.activity_main);
26+
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
27+
setSupportActionBar(toolbar);
28+
29+
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
30+
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
31+
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
32+
drawer.setDrawerListener(toggle);
33+
setFragment(new PicFragment());
34+
toggle.syncState();
35+
36+
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
37+
navigationView.setNavigationItemSelectedListener(this);
38+
navigationView.setCheckedItem(R.id.nav_pic);
39+
}
40+
41+
private void setFragment(Fragment mFragment) {
42+
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
43+
ft.replace(R.id.content_main, mFragment);
44+
ft.commit();
45+
}
46+
47+
@Override
48+
public void onBackPressed() {
49+
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
50+
if (drawer.isDrawerOpen(GravityCompat.START)) {
51+
drawer.closeDrawer(GravityCompat.START);
52+
} else {
53+
super.onBackPressed();
54+
}
55+
}
56+
57+
@SuppressWarnings("StatementWithEmptyBody")
58+
@Override
59+
public boolean onNavigationItemSelected(MenuItem item) {
60+
// Handle navigation view item clicks here.
61+
int id = item.getItemId();
62+
if (id == R.id.nav_pic) {
63+
setFragment(new PicFragment());
64+
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
65+
drawer.closeDrawer(GravityCompat.START);
66+
} else if (id == R.id.nav_txt) {
67+
setFragment(new TxtFragment());
68+
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
69+
drawer.closeDrawer(GravityCompat.START);
70+
} else if (id == R.id.nav_gif) {
71+
setFragment(new GifFragment());
72+
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
73+
drawer.closeDrawer(GravityCompat.START);
74+
} else if (id == R.id.nav_about) {
75+
Toast.makeText(this, "about", Toast.LENGTH_SHORT).show();
76+
}
77+
return true;
78+
}
79+
}
+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package com.cxp.jokes.base;
2+
3+
import android.app.Activity;
4+
import android.os.Bundle;
5+
import android.support.annotation.Nullable;
6+
import android.support.v4.app.Fragment;
7+
import android.view.LayoutInflater;
8+
import android.view.View;
9+
import android.view.ViewGroup;
10+
11+
/**
12+
* Created by cxp on 17-1-13.
13+
*/
14+
15+
public abstract class BaseFragment extends Fragment {
16+
public Activity mActivity;
17+
18+
@Override
19+
public void onCreate(@Nullable Bundle savedInstanceState) {
20+
super.onCreate(savedInstanceState);
21+
mActivity = getActivity();
22+
}
23+
24+
@Nullable
25+
@Override
26+
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
27+
View view = initView();
28+
return view;
29+
}
30+
31+
@Override
32+
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
33+
super.onViewCreated(view, savedInstanceState);
34+
initData();
35+
}
36+
37+
public abstract void initData();
38+
39+
public abstract View initView();
40+
}
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.cxp.jokes.fragment;
2+
3+
import android.view.View;
4+
5+
import com.cxp.jokes.R;
6+
import com.cxp.jokes.base.BaseFragment;
7+
8+
/**
9+
* Created by cxp on 17-1-13.
10+
*/
11+
12+
public class PicFragment extends BaseFragment {
13+
@Override
14+
public void initData() {
15+
16+
}
17+
18+
@Override
19+
public View initView() {
20+
View view = View.inflate(mActivity, R.layout.fragment_content, null);
21+
return view;
22+
}
23+
}

0 commit comments

Comments
 (0)