-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Bubbleinpit
committed
May 27, 2017
0 parents
commit 6c66605
Showing
50 changed files
with
1,710 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# Built application files | ||
*.apk | ||
*.ap_ | ||
|
||
# Files for the ART/Dalvik VM | ||
*.dex | ||
|
||
# Java class files | ||
*.class | ||
|
||
# Generated files | ||
bin/ | ||
gen/ | ||
out/ | ||
|
||
# Gradle files | ||
.gradle/ | ||
build/ | ||
|
||
# Local configuration file (sdk path, etc) | ||
local.properties | ||
|
||
# Proguard folder generated by Eclipse | ||
proguard/ | ||
|
||
# Log Files | ||
*.log | ||
|
||
# Android Studio Navigation editor temp files | ||
.navigation/ | ||
|
||
# Android Studio captures folder | ||
captures/ | ||
|
||
# Intellij | ||
*.iml | ||
.idea | ||
|
||
# Keystore files | ||
*.jks | ||
|
||
# External native build folder generated in Android Studio 2.2 and later | ||
.externalNativeBuild | ||
|
||
# Google Services (e.g. APIs or Firebase) | ||
google-services.json | ||
|
||
# Freeline | ||
freeline.py | ||
freeline/ | ||
freeline_project_description.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
apply plugin: 'com.android.application' | ||
|
||
android { | ||
compileSdkVersion 25 | ||
buildToolsVersion "25.0.2" | ||
defaultConfig { | ||
applicationId "me.lijpeng.one_layout" | ||
minSdkVersion 21 | ||
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(dir: 'libs', include: ['*.jar']) | ||
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { | ||
exclude group: 'com.android.support', module: 'support-annotations' | ||
}) | ||
compile 'com.android.support:appcompat-v7:25.3.1' | ||
compile 'com.android.support:design:25.3.1' | ||
compile 'com.cpiz.bubbleview:bubbleview:1.0.2' | ||
compile files('libs/okio-1.13.0.jar') | ||
compile files('libs/jsoup-1.10.2.jar') | ||
compile files('libs/gson-2.8.0.jar') | ||
compile files('libs/okhttp-2.5.0.jar') | ||
testCompile 'junit:junit:4.12' | ||
} |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 D:\programs_for_production\android_studio\sdk/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 |
26 changes: 26 additions & 0 deletions
26
app/src/androidTest/java/me/lijpeng/one/ExampleInstrumentedTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package me.lijpeng.one; | ||
|
||
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.*; | ||
|
||
/** | ||
* 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("me.lijpeng.one_layout", appContext.getPackageName()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="me.lijpeng.one"> | ||
<uses-permission android:name="android.permission.INTERNET" /> | ||
<application | ||
android:allowBackup="true" | ||
android:icon="@mipmap/app_logo" | ||
android:label="@string/app_name" | ||
android:roundIcon="@mipmap/app_logo" | ||
android:supportsRtl="true" | ||
android:theme="@style/AppTheme"> | ||
<activity | ||
android:name=".MainActivity" | ||
android:label="@string/app_name"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
|
||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
</application> | ||
|
||
</manifest> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package me.lijpeng.one; | ||
|
||
import android.os.Bundle; | ||
import android.support.annotation.NonNull; | ||
import android.support.design.widget.BottomNavigationView; | ||
import android.support.v4.app.Fragment; | ||
import android.support.v4.app.FragmentPagerAdapter; | ||
import android.support.v4.view.ViewPager; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.view.MenuItem; | ||
import android.view.View; | ||
|
||
import com.squareup.okhttp.OkHttpClient; | ||
|
||
import me.lijpeng.one.fragments.*; | ||
import me.lijpeng.one.thirdparty.viewpager.NoSlidingPageTransformer; | ||
import me.lijpeng.one.thirdparty.viewpager.NoSlidingViewPaper; | ||
|
||
import java.util.ArrayList; | ||
|
||
public class MainActivity extends AppCompatActivity { | ||
|
||
//private TextView mTextMessage; | ||
private ViewPager mViewPager; | ||
private View articleContainer; | ||
public static OkHttpClient client = new OkHttpClient(); | ||
|
||
private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener | ||
= new BottomNavigationView.OnNavigationItemSelectedListener() { | ||
|
||
@Override | ||
public boolean onNavigationItemSelected(@NonNull MenuItem item) { | ||
|
||
articleContainer = findViewById(R.id.article_container); | ||
switch (item.getItemId()) { | ||
case R.id.navigation_home: | ||
if (mViewPager.getCurrentItem() == 2) | ||
articleContainer.setVisibility(View.INVISIBLE); | ||
mViewPager.setCurrentItem(0); | ||
return true; | ||
case R.id.navigation_dashboard: | ||
articleContainer.setVisibility(View.VISIBLE); | ||
mViewPager.setCurrentItem(1); | ||
return true; | ||
case R.id.navigation_notifications: | ||
if (mViewPager.getCurrentItem() == 0) | ||
articleContainer.setVisibility(View.INVISIBLE); | ||
mViewPager.setCurrentItem(2); | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
}; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_main); | ||
mViewPager = (NoSlidingViewPaper) findViewById(R.id.viewpager); | ||
final ArrayList<Fragment> fgLists = new ArrayList<>(3); | ||
fgLists.add(new FragmentOne()); | ||
fgLists.add(new FragmentArticle()); | ||
fgLists.add(new FragmentQuestion()); | ||
NoSlidingPageTransformer pageTransformer = new NoSlidingPageTransformer(); | ||
pageTransformer.setCurrentItem(this, 0, fgLists); | ||
mViewPager.setPageTransformer(true, pageTransformer); | ||
FragmentPagerAdapter mAdapter = new FragmentPagerAdapter(getSupportFragmentManager()) { | ||
@Override | ||
public Fragment getItem(int position) { | ||
return fgLists.get(position); | ||
} | ||
|
||
@Override | ||
public int getCount() { | ||
return fgLists.size(); | ||
} | ||
}; | ||
mViewPager.setAdapter(mAdapter); | ||
mViewPager.setOffscreenPageLimit(2); //预加载剩下两页 | ||
articleContainer = findViewById(R.id.article_container); | ||
|
||
BottomNavigationView navigation = (BottomNavigationView) findViewById(R.id.navigation); | ||
navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener); | ||
} | ||
|
||
} |
82 changes: 82 additions & 0 deletions
82
app/src/main/java/me/lijpeng/one/fragments/BaseFragment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package me.lijpeng.one.fragments; | ||
|
||
import android.content.Context; | ||
import android.os.Bundle; | ||
import android.support.annotation.Nullable; | ||
import android.support.v4.app.Fragment; | ||
import android.support.v4.widget.SwipeRefreshLayout; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.view.animation.Animation; | ||
import android.view.animation.AnimationUtils; | ||
|
||
import me.lijpeng.one.R; | ||
|
||
/** | ||
* Created by ljp on 2017/5/25. | ||
*/ | ||
|
||
public abstract class BaseFragment extends Fragment implements SwipeRefreshLayout.OnRefreshListener{ | ||
protected View mView; | ||
protected boolean isViewInitiated; //当前页面是否初始化 | ||
protected boolean isVisibleToUser; //当前页面是否显示 | ||
protected boolean isDataRequested; //是否已经请求了数据 | ||
protected Context mContext; | ||
Animation appearAnimation; | ||
Animation disappearAnimation; | ||
|
||
@Nullable | ||
@Override | ||
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { | ||
|
||
mContext = getContext(); | ||
mView = inflater.inflate(getLayoutId(), null); | ||
isViewInitiated = true; | ||
appearAnimation = AnimationUtils.loadAnimation(mContext, R.anim.appear_anim); | ||
disappearAnimation = AnimationUtils.loadAnimation(mContext, R.anim.disappear_anim); | ||
initView(); | ||
prepareGetData(); | ||
return mView; | ||
} | ||
|
||
/*初始化页面布局和数据*/ | ||
protected abstract void initView(); | ||
/*布局*/ | ||
public abstract int getLayoutId(); | ||
/*从服务器获取数据*/ | ||
protected abstract void getDataFromServer(); | ||
|
||
/** | ||
* 当前页面是否展示 | ||
* @param isVisibleToUser 显示为true, 不显示为false | ||
*/ | ||
@Override | ||
public void setUserVisibleHint(boolean isVisibleToUser) { | ||
super.setUserVisibleHint(isVisibleToUser); | ||
this.isVisibleToUser = isVisibleToUser; | ||
prepareGetData(); | ||
} | ||
|
||
/** | ||
* 如果只想第一次进入该页面请求数据,return prepareGetData(false) | ||
* 如果想每次进入该页面就请求数据,return prepareGetData(true) | ||
*/ | ||
private boolean prepareGetData(){ | ||
return prepareGetData(false); | ||
} | ||
|
||
/** | ||
* 判断是否从服务器器获取数据 | ||
* @param isforceUpdate 强制更新的标记 | ||
*/ | ||
protected boolean prepareGetData(boolean isforceUpdate) { | ||
if(isVisibleToUser && isViewInitiated && (!isDataRequested || isforceUpdate)){ | ||
/*从服务器获取数据*/ | ||
getDataFromServer(); | ||
isDataRequested = true; | ||
return true; | ||
} | ||
return false; | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
app/src/main/java/me/lijpeng/one/fragments/FragmentArticle.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package me.lijpeng.one.fragments; | ||
|
||
import android.app.Fragment; | ||
import android.view.View; | ||
|
||
import me.lijpeng.one.R; | ||
|
||
/** | ||
* Created by ljp on 2017/5/25. | ||
*/ | ||
|
||
public class FragmentArticle extends BaseFragment { | ||
|
||
@Override | ||
protected void initView() { | ||
|
||
} | ||
@Override | ||
public int getLayoutId() { | ||
return R.layout.article_layout; | ||
} | ||
@Override | ||
protected void getDataFromServer() { | ||
/* | ||
* 请求url:http://v3.wufazhuce.com:8000/api/essay/${id} | ||
*/ | ||
} | ||
|
||
@Override | ||
public void onRefresh() { | ||
|
||
} | ||
} |
Oops, something went wrong.