init
This commit is contained in:
@@ -1,8 +1,12 @@
|
||||
apply plugin: 'com.android.application'
|
||||
|
||||
android {
|
||||
|
||||
compileSdkVersion 26
|
||||
buildToolsVersion "26.0.3"
|
||||
|
||||
defaultConfig {
|
||||
|
||||
applicationId "com.example.ninefourone.nutritionmaster"
|
||||
minSdkVersion 19
|
||||
targetSdkVersion 26
|
||||
@@ -10,12 +14,14 @@ android {
|
||||
versionName "1.0"
|
||||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
release {
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
dependencies {
|
||||
@@ -25,4 +31,9 @@ dependencies {
|
||||
testImplementation 'junit:junit:4.12'
|
||||
androidTestImplementation 'com.android.support.test:runner:1.0.2'
|
||||
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
|
||||
//butterknife
|
||||
implementation 'com.jakewharton:butterknife:8.8.1'
|
||||
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
|
||||
//logger
|
||||
implementation 'com.orhanobut:logger:2.2.0'
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
package="com.example.ninefourone.nutritionmaster">
|
||||
|
||||
<application
|
||||
android:name="com.example.ninefourone.nutritionmaster.NutritionMaster"
|
||||
android:allowBackup="true"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
|
||||
@@ -9,6 +9,5 @@ public class MainActivity extends AppCompatActivity {
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_main);
|
||||
//11111
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.example.ninefourone.nutritionmaster;
|
||||
|
||||
import android.app.Application;
|
||||
|
||||
import com.orhanobut.logger.AndroidLogAdapter;
|
||||
import com.orhanobut.logger.Logger;
|
||||
|
||||
|
||||
/**
|
||||
* Created by ScorpioMiku on 2018/8/26.
|
||||
*/
|
||||
|
||||
public class NutritionMaster extends Application {
|
||||
public static NutritionMaster mInstance;
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
mInstance = this;
|
||||
init();
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化所有基础的东西
|
||||
*/
|
||||
private void init() {
|
||||
Logger.addLogAdapter(new AndroidLogAdapter());
|
||||
Logger.d("Logger初始化成功");
|
||||
}
|
||||
|
||||
public static NutritionMaster getInstance() {
|
||||
return mInstance;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
package com.example.ninefourone.nutritionmaster.base;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
|
||||
import butterknife.ButterKnife;
|
||||
import butterknife.Unbinder;
|
||||
|
||||
/**
|
||||
* Created by ScorpioMiku on 2018/8/26.
|
||||
*/
|
||||
|
||||
public abstract class BaseActivity extends AppCompatActivity {
|
||||
private Unbinder unbinder;
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(getLayoutId());
|
||||
unbinder = ButterKnife.bind(this);
|
||||
initViews(savedInstanceState);
|
||||
initToolBar();
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置布局layout
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public abstract int getLayoutId();
|
||||
|
||||
/**
|
||||
* 初始化views
|
||||
*
|
||||
* @param savedInstanceState
|
||||
*/
|
||||
public abstract void initViews(Bundle savedInstanceState);
|
||||
|
||||
/**
|
||||
* 初始化toolbar
|
||||
*/
|
||||
public abstract void initToolBar();
|
||||
|
||||
/**
|
||||
* 加载数据
|
||||
*/
|
||||
public void loadData() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示进度条
|
||||
*/
|
||||
public void showProgressBar() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 隐藏进度条
|
||||
*/
|
||||
public void hideProgressBar() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化recyclerView
|
||||
*/
|
||||
public void initRecyclerView() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化refreshLayout
|
||||
*/
|
||||
public void initRefreshLayout() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置数据显示
|
||||
*/
|
||||
public void finishTask() {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
unbinder.unbind();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,153 @@
|
||||
package com.example.ninefourone.nutritionmaster.base;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.LayoutRes;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import butterknife.ButterKnife;
|
||||
import butterknife.Unbinder;
|
||||
|
||||
/**
|
||||
* Created by ScorpioMiku on 2018/8/26.
|
||||
*/
|
||||
|
||||
public abstract class BaseFragment extends Fragment {
|
||||
private View parentView;
|
||||
private FragmentActivity activity;
|
||||
protected boolean isPrepared;
|
||||
protected boolean isVisible;
|
||||
private Unbinder unbinder;
|
||||
|
||||
public abstract
|
||||
@LayoutRes
|
||||
int getLayoutResId();
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle state) {
|
||||
parentView = inflater.inflate(getLayoutResId(), container, false);
|
||||
activity = getSupportActivity();
|
||||
return parentView;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(View view, Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
unbinder = ButterKnife.bind(this, view);
|
||||
initView(savedInstanceState);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 初始化自己的ui
|
||||
*
|
||||
* @param state
|
||||
*/
|
||||
public abstract void initView(Bundle state);
|
||||
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
unbinder.unbind();
|
||||
}
|
||||
|
||||
|
||||
public FragmentActivity getSupportActivity() {
|
||||
return super.getActivity();
|
||||
}
|
||||
|
||||
|
||||
public android.app.ActionBar getSupportActionBar() {
|
||||
return getSupportActivity().getActionBar();
|
||||
}
|
||||
|
||||
|
||||
public Context getApplicationContext() {
|
||||
return this.activity == null ? (getActivity() == null ?
|
||||
null : getActivity().getApplicationContext()) : this.activity.getApplicationContext();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Fragment数据的懒加载
|
||||
*/
|
||||
@Override
|
||||
public void setUserVisibleHint(boolean isVisibleToUser) {
|
||||
super.setUserVisibleHint(isVisibleToUser);
|
||||
if (getUserVisibleHint()) {
|
||||
isVisible = true;
|
||||
onVisible();
|
||||
} else {
|
||||
isVisible = false;
|
||||
onInvisible();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* fragment显示时才加载数据
|
||||
*/
|
||||
protected void onVisible() {
|
||||
lazyLoad();
|
||||
}
|
||||
|
||||
/**
|
||||
* fragment懒加载方法
|
||||
*/
|
||||
protected void lazyLoad() {
|
||||
}
|
||||
|
||||
/**
|
||||
* fragment隐藏
|
||||
*/
|
||||
protected void onInvisible() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载数据
|
||||
*/
|
||||
protected void loadData() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示进度条
|
||||
*/
|
||||
protected void showProgressBar() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 隐藏进度条
|
||||
*/
|
||||
protected void hideProgressBar() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化recyclerView
|
||||
*/
|
||||
protected void initRecyclerView() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化refreshLayout
|
||||
*/
|
||||
protected void initRefreshLayout() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置数据显示
|
||||
*/
|
||||
protected void finishTask() {
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.example.ninefourone.nutritionmaster.utils;
|
||||
|
||||
/**
|
||||
* Created by ScorpioMiku on 2018/8/26.
|
||||
*/
|
||||
|
||||
public class ConstantUtils {
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.example.ninefourone.nutritionmaster.utils;
|
||||
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.example.ninefourone.nutritionmaster.NutritionMaster;
|
||||
|
||||
/**
|
||||
* Created by ScorpioMiku on 2018/8/26.
|
||||
*/
|
||||
|
||||
public class MessageUtils {
|
||||
|
||||
public static void MakeToast(String message) {
|
||||
Toast.makeText(NutritionMaster.getInstance(), message, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
@@ -5,14 +5,16 @@ buildscript {
|
||||
repositories {
|
||||
google()
|
||||
jcenter()
|
||||
mavenCentral()
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:3.0.1'
|
||||
|
||||
|
||||
classpath 'com.jakewharton:butterknife-gradle-plugin:8.8.1'
|
||||
// NOTE: Do not place your application dependencies here; they belong
|
||||
// in the individual module build.gradle files
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
allprojects {
|
||||
@@ -20,8 +22,6 @@ allprojects {
|
||||
google()
|
||||
jcenter()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
task clean(type: Delete) {
|
||||
delete rootProject.buildDir
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user