浏览代码

数据缓存框架

316044749 7 年之前
父节点
当前提交
634e12c780

+ 18 - 0
app/build.gradle

@@ -10,10 +10,27 @@ android {
         versionName "1.0"
         javaCompileOptions { annotationProcessorOptions { includeCompileClasspath = true } }
     }
+
+    signingConfigs {
+        myconfig {
+            keyAlias 'shitunet'
+            keyPassword 'key_shitu'
+            storePassword 'key_shitu'
+            storeFile file('src\\main\\doc\\shitunet.jks')
+        }
+    }
+
     buildTypes {
         release {
             minifyEnabled false
             proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
+            signingConfig signingConfigs.myconfig
+        }
+        debug {
+            debuggable true
+            minifyEnabled false
+            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
+            signingConfig signingConfigs.myconfig
         }
     }
 }
@@ -24,4 +41,5 @@ dependencies {
     compile 'com.android.support:design:26.1.0'
     compile 'com.jakewharton:butterknife:7.0.1'
     compile 'com.github.bumptech.glide:glide:3.7.0'
+    compile 'com.muddzdev:styleabletoast:2.0.1'
 }

二进制
app/release/app-release.apk


+ 1 - 0
app/release/output.json

@@ -0,0 +1 @@
+[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":1},"path":"app-release.apk","properties":{"packageId":"com.ynstkz.shitu.android","split":"","minSdkVersion":"16"}}]

+ 7 - 0
app/src/main/AndroidManifest.xml

@@ -17,6 +17,13 @@
                 <category android:name="android.intent.category.LAUNCHER" />
             </intent-filter>
         </activity>
+
+        <activity android:name=".activity.LoginActivity"
+            android:screenOrientation="portrait"/>
+
+        <activity android:name=".activity.RegisterActivity"
+            android:screenOrientation="portrait"/>
+
     </application>
 
 </manifest>

app/doc/shitunet.jks → app/src/main/doc/shitunet.jks


+ 90 - 3
app/src/main/java/com/ynstkz/shitu/android/activity/HomeActivity.java

@@ -1,9 +1,14 @@
 package com.ynstkz.shitu.android.activity;
 
+import android.content.Intent;
 import android.os.Bundle;
+import android.support.v4.app.Fragment;
+import android.view.View;
+import android.widget.ImageView;
+import android.widget.LinearLayout;
+import android.widget.RelativeLayout;
 import android.widget.TextView;
 
-import com.common.library.okhttp.OkHttpUtils;
 import com.ynstkz.shitu.android.R;
 import com.ynstkz.shitu.android.base.TitleBarActivity;
 
@@ -12,17 +17,99 @@ import butterknife.ButterKnife;
 
 public class HomeActivity extends TitleBarActivity {
 
-    @Bind(R.id.tv_barTitle)
-    TextView tvBarTitle;
+    @Bind(R.id.tv_title)
+    TextView tvTitle;
+    @Bind(R.id.view_title)
+    RelativeLayout viewTitle;
+    @Bind(R.id.rl_lab_home)
+    RelativeLayout rlLabHome;
+    @Bind(R.id.rl_lab_nearby)
+    RelativeLayout rlLabNearby;
+    @Bind(R.id.rl_lab_usercenter)
+    RelativeLayout rlLabUsercenter;
+    @Bind(R.id.ll_bottom_lab)
+    LinearLayout llBottomLab;
+
+    private Fragment[] mFragments;
+    private int tabIndex;
 
     @Override
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         ButterKnife.bind(this);
+        initView();
+        initData();
+        setListener();
     }
 
     @Override
     protected int getLayoutId() {
         return R.layout.activity_home;
     }
+
+    private void initView(){
+        mFragments = new Fragment[3];
+        mFragments[0] = getSupportFragmentManager().findFragmentById(R.id.fm_home);
+        mFragments[1] = getSupportFragmentManager().findFragmentById(R.id.fm_nearby);
+        mFragments[2] = getSupportFragmentManager().findFragmentById(R.id.fm_usercent);
+        changleLayout(0);
+    }
+
+    private void initData(){
+
+    }
+
+    private void setListener(){
+        //首页
+        rlLabHome.setOnClickListener(new View.OnClickListener() {
+            @Override
+            public void onClick(View view) {
+                changleLayout(0);
+            }
+        });
+        //附近
+        rlLabNearby.setOnClickListener(new View.OnClickListener() {
+            @Override
+            public void onClick(View view) {
+                changleLayout(1);
+            }
+        });
+        //个人中心
+        rlLabUsercenter.setOnClickListener(new View.OnClickListener() {
+            @Override
+            public void onClick(View view) {
+                if(isLogin()){
+                    changleLayout(2);
+                } else {
+                    startActivityForResult(new Intent(HomeActivity.this, LoginActivity.class), 10);
+                }
+            }
+        });
+    }
+
+    /**
+     * 切换fragment
+     *
+     * @param tabIndex
+     */
+    private void changleLayout(int tabIndex) {
+        this.tabIndex = tabIndex;
+        getSupportFragmentManager().beginTransaction().hide(mFragments[0]).hide(mFragments[1])
+                .hide(mFragments[2]).show(mFragments[tabIndex]).commitAllowingStateLoss();
+        switch (tabIndex) {
+
+        }
+    }
+
+    @Override
+    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
+        switch (requestCode) {
+            case 10:
+                if(resultCode == RESULT_OK) { //登陆成功
+                    changleLayout(2);
+                }
+                break;
+        }
+    }
+
 }

+ 24 - 0
app/src/main/java/com/ynstkz/shitu/android/activity/LoginActivity.java

@@ -0,0 +1,24 @@
+package com.ynstkz.shitu.android.activity;
+
+import android.os.Bundle;
+import android.support.annotation.Nullable;
+
+import com.ynstkz.shitu.android.R;
+import com.ynstkz.shitu.android.base.TitleBarActivity;
+
+/**
+ * 作者:fuchangle on 2018/1/31 16:29
+ */
+
+public class LoginActivity extends TitleBarActivity{
+
+    @Override
+    protected void onCreate(@Nullable Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+    }
+
+    @Override
+    protected int getLayoutId() {
+        return R.layout.activity_login;
+    }
+}

+ 26 - 0
app/src/main/java/com/ynstkz/shitu/android/activity/RegisterActivity.java

@@ -0,0 +1,26 @@
+package com.ynstkz.shitu.android.activity;
+
+import android.os.Bundle;
+import android.support.annotation.Nullable;
+
+import com.ynstkz.shitu.android.R;
+import com.ynstkz.shitu.android.base.TitleBarActivity;
+
+/**
+ * 作者:fuchangle on 2018/1/31 16:29
+ */
+
+public class RegisterActivity extends TitleBarActivity{
+
+    @Override
+    protected void onCreate(@Nullable Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+
+    }
+
+    @Override
+    protected int getLayoutId() {
+        return R.layout.activity_register;
+    }
+
+}

+ 17 - 0
app/src/main/java/com/ynstkz/shitu/android/base/BaseActivity.java

@@ -1,9 +1,13 @@
 package com.ynstkz.shitu.android.base;
 
+import android.content.SharedPreferences;
+import android.graphics.Color;
 import android.os.Bundle;
 import android.support.annotation.Nullable;
 
 import com.common.library.base.LibBaseActivity;
+import com.muddzdev.styleabletoastlibrary.StyleableToast;
+import com.ynstkz.shitu.android.data.SharedPreferencesUtils;
 
 /**
  * 作者:fuchangle on 2018/1/27 21:50
@@ -15,4 +19,17 @@ public class BaseActivity extends LibBaseActivity{
     protected void onCreate(@Nullable Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
     }
+
+    protected void showToast(String content){
+        new StyleableToast
+                .Builder(this)
+                .text(content)
+                .textColor(Color.WHITE)
+                .backgroundColor(Color.BLACK)
+                .show();
+    }
+
+    protected boolean isLogin(){
+        return SharedPreferencesUtils.isLogin();
+    }
 }

+ 0 - 3
app/src/main/java/com/ynstkz/shitu/android/base/TitleBarActivity.java

@@ -62,7 +62,4 @@ public abstract class TitleBarActivity extends BaseActivity{
 
     protected abstract int getLayoutId();
 
-    protected void showToast(View view, String msg){
-        Snackbar.make(view, msg, Snackbar.LENGTH_LONG).show();
-    }
 }

+ 90 - 0
app/src/main/java/com/ynstkz/shitu/android/data/SharedPreferencesDao.java

@@ -0,0 +1,90 @@
+package com.ynstkz.shitu.android.data;
+
+import android.content.Context;
+import android.content.SharedPreferences;
+import android.content.pm.PackageManager;
+
+import com.common.library.utils.AppInfoUtil;
+import com.ynstkz.shitu.android.application.STApplication;
+import com.ynstkz.shitu.android.common.Constants;
+
+/**
+ * Created by fucl on 2016/4/6.
+ */
+public class SharedPreferencesDao {
+
+    private static final String FILE_NAME = Constants.ST_SHAREPREFREENCE;
+    private static final String PACK_NAME = AppInfoUtil.getAppPackageName(STApplication.getContext());
+
+    /**
+     * 保存数据的方法,我们需要拿到保存数据的具体类型,然后根据类型调用不同的保存方法
+     * @param key			键名
+     * @param object		值
+     */
+    public static boolean set(String key, Object object) {
+        try {
+            Context otherAppsContext = STApplication.getContext().createPackageContext(PACK_NAME, Context.CONTEXT_IGNORE_SECURITY);
+            String type = object.getClass().getSimpleName();
+            SharedPreferences sp = otherAppsContext.getSharedPreferences(FILE_NAME, Context.MODE_MULTI_PROCESS);
+            SharedPreferences.Editor editor = sp.edit();
+
+            if ("String".equals(type)) {
+                editor.putString(key, (String) object);
+            } else if ("Integer".equals(type)) {
+                editor.putInt(key, (Integer) object);
+            } else if ("Boolean".equals(type)) {
+                editor.putBoolean(key, (Boolean) object);
+            } else if ("Float".equals(type)) {
+                editor.putFloat(key, (Float) object);
+            } else if ("Long".equals(type)) {
+                editor.putLong(key, (Long) object);
+            }
+            return editor.commit();
+        } catch (PackageManager.NameNotFoundException e) {
+            e.printStackTrace();
+        }
+        return false;
+    }
+
+    public static boolean remove(String key){
+        Context otherAppsContext;
+        try {
+            otherAppsContext = STApplication.getContext().createPackageContext(PACK_NAME, Context.CONTEXT_IGNORE_SECURITY);
+            SharedPreferences sp = otherAppsContext.getSharedPreferences(FILE_NAME, Context.MODE_MULTI_PROCESS);
+            SharedPreferences.Editor editor = sp.edit();
+            editor.remove(key);
+            return editor.commit();
+        } catch (PackageManager.NameNotFoundException e) {
+            e.printStackTrace();
+            return false;
+        }
+    }
+    /**
+     * 得到保存数据的方法,我们根据默认值得到保存的数据的具体类型,然后调用相对于的方法获取值
+     * @param key
+     * @param defaultObject
+     * @return
+     */
+    public static Object get(String key, Object defaultObject) {
+        try {
+            String type = defaultObject.getClass().getSimpleName();
+            Context otherAppsContext = STApplication.getContext().createPackageContext(PACK_NAME, Context.CONTEXT_IGNORE_SECURITY);
+            SharedPreferences sp = otherAppsContext.getSharedPreferences(FILE_NAME, Context.MODE_MULTI_PROCESS);
+            if ("String".equals(type)) {
+                return sp.getString(key, (String) defaultObject);
+            } else if ("Integer".equals(type)) {
+                return sp.getInt(key, (Integer) defaultObject);
+            } else if ("Boolean".equals(type)) {
+                return sp.getBoolean(key, (Boolean) defaultObject);
+            } else if ("Float".equals(type)) {
+                return sp.getFloat(key, (Float) defaultObject);
+            } else if ("Long".equals(type)) {
+                return sp.getLong(key, (Long) defaultObject);
+            }
+            return defaultObject;
+        } catch (Exception e) {
+            e.printStackTrace();
+            return defaultObject;
+        }
+    }
+}

+ 6 - 78
app/src/main/java/com/ynstkz/shitu/android/data/SharedPreferencesUtils.java

@@ -1,90 +1,18 @@
 package com.ynstkz.shitu.android.data;
 
-import android.content.Context;
-import android.content.SharedPreferences;
-import android.content.pm.PackageManager;
-
-import com.common.library.utils.AppInfoUtil;
-import com.ynstkz.shitu.android.application.STApplication;
-import com.ynstkz.shitu.android.common.Constants;
-
 /**
- * Created by fucl on 2016/4/6.
+ * 作者:fuchangle on 2018/2/5 10:42
  */
-public class SharedPreferencesUtils {
 
-    private static final String FILE_NAME = Constants.ST_SHAREPREFREENCE;
-    private static final String PACK_NAME = AppInfoUtil.getAppPackageName(STApplication.getContext());
-
-    /**
-     * 保存数据的方法,我们需要拿到保存数据的具体类型,然后根据类型调用不同的保存方法
-     * @param key			键名
-     * @param object		值
-     */
-    public static boolean set(String key, Object object) {
-        try {
-            Context otherAppsContext = STApplication.getContext().createPackageContext(PACK_NAME, Context.CONTEXT_IGNORE_SECURITY);
-            String type = object.getClass().getSimpleName();
-            SharedPreferences sp = otherAppsContext.getSharedPreferences(FILE_NAME, Context.MODE_MULTI_PROCESS);
-            SharedPreferences.Editor editor = sp.edit();
+public class SharedPreferencesUtils {
 
-            if ("String".equals(type)) {
-                editor.putString(key, (String) object);
-            } else if ("Integer".equals(type)) {
-                editor.putInt(key, (Integer) object);
-            } else if ("Boolean".equals(type)) {
-                editor.putBoolean(key, (Boolean) object);
-            } else if ("Float".equals(type)) {
-                editor.putFloat(key, (Float) object);
-            } else if ("Long".equals(type)) {
-                editor.putLong(key, (Long) object);
-            }
-            return editor.commit();
-        } catch (PackageManager.NameNotFoundException e) {
-            e.printStackTrace();
-        }
-        return false;
-    }
+    private static final String IS_LOGIN = "isLogin";
 
-    public static boolean remove(String key){
-        Context otherAppsContext;
-        try {
-            otherAppsContext = STApplication.getContext().createPackageContext(PACK_NAME, Context.CONTEXT_IGNORE_SECURITY);
-            SharedPreferences sp = otherAppsContext.getSharedPreferences(FILE_NAME, Context.MODE_MULTI_PROCESS);
-            SharedPreferences.Editor editor = sp.edit();
-            editor.remove(key);
-            return editor.commit();
-        } catch (PackageManager.NameNotFoundException e) {
-            e.printStackTrace();
-            return false;
-        }
-    }
     /**
-     * 得到保存数据的方法,我们根据默认值得到保存的数据的具体类型,然后调用相对于的方法获取值
-     * @param key
-     * @param defaultObject
+     * 是否登录
      * @return
      */
-    public static Object get(String key, Object defaultObject) {
-        try {
-            String type = defaultObject.getClass().getSimpleName();
-            Context otherAppsContext = STApplication.getContext().createPackageContext(PACK_NAME, Context.CONTEXT_IGNORE_SECURITY);
-            SharedPreferences sp = otherAppsContext.getSharedPreferences(FILE_NAME, Context.MODE_MULTI_PROCESS);
-            if ("String".equals(type)) {
-                return sp.getString(key, (String) defaultObject);
-            } else if ("Integer".equals(type)) {
-                return sp.getInt(key, (Integer) defaultObject);
-            } else if ("Boolean".equals(type)) {
-                return sp.getBoolean(key, (Boolean) defaultObject);
-            } else if ("Float".equals(type)) {
-                return sp.getFloat(key, (Float) defaultObject);
-            } else if ("Long".equals(type)) {
-                return sp.getLong(key, (Long) defaultObject);
-            }
-            return defaultObject;
-        } catch (Exception e) {
-            e.printStackTrace();
-            return defaultObject;
-        }
+    public static boolean isLogin(){
+        return (Boolean)SharedPreferencesDao.get(IS_LOGIN, false);
     }
 }

+ 3 - 2
app/src/main/java/com/ynstkz/shitu/android/fragment/HomeFragment.java

@@ -5,6 +5,7 @@ import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
 
+import com.ynstkz.shitu.android.R;
 import com.ynstkz.shitu.android.base.BaseFragment;
 
 /**
@@ -15,8 +16,8 @@ public class HomeFragment extends BaseFragment{
 
     @Override
     public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
-        return super.onCreateView(inflater, container, savedInstanceState);
+        View view = inflater.inflate(R.layout.fm_home, null);
+        return view;
     }
 
-
 }

+ 3 - 1
app/src/main/java/com/ynstkz/shitu/android/fragment/NearbyFragment.java

@@ -6,6 +6,7 @@ import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
 
+import com.ynstkz.shitu.android.R;
 import com.ynstkz.shitu.android.base.BaseFragment;
 
 /**
@@ -17,7 +18,8 @@ public class NearbyFragment extends BaseFragment{
 
     @Override
     public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
-        return super.onCreateView(inflater, container, savedInstanceState);
+        View view = inflater.inflate(R.layout.fm_nearby, null);
+        return view;
     }
 
 }

+ 3 - 1
app/src/main/java/com/ynstkz/shitu/android/fragment/UserCenterFragment.java

@@ -5,6 +5,7 @@ import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
 
+import com.ynstkz.shitu.android.R;
 import com.ynstkz.shitu.android.base.BaseFragment;
 
 /**
@@ -16,7 +17,8 @@ public class UserCenterFragment extends BaseFragment{
 
     @Override
     public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
-        return super.onCreateView(inflater, container, savedInstanceState);
+        View view = inflater.inflate(R.layout.fm_usercenter, null);
+        return view;
     }
 
 }

+ 18 - 6
app/src/main/res/layout/activity_home.xml

@@ -12,11 +12,23 @@
 
         <include layout="@layout/view_title"/>
 
-        <TextView
-            android:id="@+id/tv_barTitle"
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            android:text="Hello World!"/>
+        <fragment
+            android:id="@+id/fm_home"
+            android:name="com.ynstkz.shitu.android.fragment.HomeFragment"
+            android:layout_width="match_parent"
+            android:layout_height="match_parent"/>
+
+        <fragment
+            android:id="@+id/fm_nearby"
+            android:name="com.ynstkz.shitu.android.fragment.NearbyFragment"
+            android:layout_width="match_parent"
+            android:layout_height="match_parent"/>
+
+        <fragment
+            android:id="@+id/fm_usercent"
+            android:name="com.ynstkz.shitu.android.fragment.UserCenterFragment"
+            android:layout_width="match_parent"
+            android:layout_height="match_parent"/>
 
     </LinearLayout>
 
@@ -27,7 +39,7 @@
         android:layout_alignParentBottom="true"
         android:orientation="horizontal">
 
-
+        <include layout="@layout/view_main_bottom"/>
 
     </LinearLayout>
 

+ 6 - 0
app/src/main/res/layout/activity_login.xml

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:orientation="vertical" android:layout_width="match_parent"
+    android:layout_height="match_parent">
+
+</LinearLayout>

+ 6 - 0
app/src/main/res/layout/activity_register.xml

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:orientation="vertical" android:layout_width="match_parent"
+    android:layout_height="match_parent">
+
+</LinearLayout>

+ 79 - 0
app/src/main/res/layout/view_main_bottom.xml

@@ -0,0 +1,79 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    android:background="@color/white"
+    android:orientation="horizontal">
+
+    <RelativeLayout
+        android:id="@+id/rl_lab_home"
+        android:layout_width="0dp"
+        android:layout_height="wrap_content"
+        android:layout_gravity="bottom"
+        android:layout_weight="1"
+        android:padding="@dimen/company_5dp">
+
+        <LinearLayout
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_centerInParent="true"
+            android:orientation="vertical">
+
+            <ImageView
+                android:layout_width="@dimen/lab_size"
+                android:layout_height="@dimen/lab_size"
+                android:layout_centerInParent="true"
+                android:layout_gravity="center_horizontal"
+                android:src="@mipmap/ic_launcher" />
+
+        </LinearLayout>
+
+    </RelativeLayout>
+
+    <RelativeLayout
+        android:id="@+id/rl_lab_nearby"
+        android:layout_width="0dp"
+        android:layout_height="wrap_content"
+        android:layout_gravity="bottom"
+        android:layout_weight="1"
+        android:padding="@dimen/company_5dp">
+
+        <LinearLayout
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_centerInParent="true"
+            android:orientation="vertical">
+
+            <ImageView
+                android:layout_width="@dimen/lab_size"
+                android:layout_height="@dimen/lab_size"
+                android:src="@mipmap/ic_launcher" />
+
+        </LinearLayout>
+
+    </RelativeLayout>
+
+    <RelativeLayout
+        android:id="@+id/rl_lab_usercenter"
+        android:layout_width="0dp"
+        android:layout_height="wrap_content"
+        android:layout_gravity="bottom"
+        android:layout_weight="1"
+        android:padding="@dimen/company_5dp">
+
+        <LinearLayout
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_centerInParent="true"
+            android:orientation="vertical">
+
+            <ImageView
+                android:layout_width="@dimen/lab_size"
+                android:layout_height="@dimen/lab_size"
+                android:src="@mipmap/ic_launcher" />
+
+        </LinearLayout>
+
+    </RelativeLayout>
+
+</LinearLayout>

+ 1 - 0
app/src/main/res/values/dimens.xml

@@ -1,4 +1,5 @@
 <?xml version="1.0" encoding="utf-8"?>
 <resources>
     <dimen name="titlebar_height">50dp</dimen>
+    <dimen name="lab_size">40dp</dimen>
 </resources>