优化代码

This commit is contained in:
linglongxin24
2016-08-24 10:24:04 +08:00
parent c1b509b4f7
commit 2cba51761c
12 changed files with 204 additions and 73 deletions

3
.idea/gradle.xml generated
View File

@@ -3,8 +3,9 @@
<component name="GradleSettings">
<option name="linkedExternalProjectsSettings">
<GradleProjectSettings>
<option name="distributionType" value="DEFAULT_WRAPPED" />
<option name="distributionType" value="LOCAL" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="gradleHome" value="E:\kejiang\Android\Android Studio\gradle\gradle-2.14.1" />
<option name="modules">
<set>
<option value="$PROJECT_DIR$" />

2
.idea/misc.xml generated
View File

@@ -27,5 +27,5 @@
</value>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK" />
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK" />
</project>

View File

@@ -34,4 +34,37 @@
android:layout_width="match_parent"
android:layout_height="match_parent" />
</com.ldd.pullview.AbPullToRefreshView>
<RadioGroup
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:orientation="horizontal"
android:layout_alignParentStart="true">
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1"
android:id="@+id/radioButton" />
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="2"
android:id="@+id/radioButton2" />
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="3"
android:id="@+id/radioButton3" />
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="4"
android:id="@+id/radioButton4" />
</RadioGroup>
</RelativeLayout>

View File

@@ -5,7 +5,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.2'
classpath 'com.android.tools.build:gradle:2.1.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files

View File

@@ -1,6 +1,6 @@
#Mon Dec 28 10:00:20 PST 2015
#Tue Aug 16 10:13:25 CST 2016
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip

View File

@@ -27,10 +27,8 @@ dependencies {
compile 'org.xutils:xutils:3.3.34'
compile 'com.android.support:recyclerview-v7:23.3.0'
compile 'com.linglongxin24:UncaughtExceptionSendEmail:1.0.0'
debugCompile 'com.squareup.leakcanary:leakcanary-android:1.3.1'
// or 1.4-beta1
releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.3.1'
// or 1.4-beta1
testCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.3.1'
// debugCompile 'com.squareup.leakcanary:leakcanary-android:1.4-beta2'
// releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.4-beta2'
// testCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.4-beta2'
compile 'com.android.support:design:23.4.0'
}

View File

@@ -1,49 +1,41 @@
package com.kejiang.yuandl.app;
import android.app.Application;
import android.app.admin.SystemUpdatePolicy;
import android.content.Context;
import android.os.Vibrator;
import com.squareup.leakcanary.LeakCanary;
import com.kejiang.yuandl.mylibrary.CustomActivityOnCrash;
import com.orhanobut.logger.Logger;
import com.squareup.leakcanary.RefWatcher;
import org.xutils.x;
/**
* Created by yuandl on 2016/5/23 0023.
*/
public class MyApplication extends Application {
private RefWatcher refWatcher;
@Override
public void onCreate() {
super.onCreate();
CustomActivityOnCrash.install(this);
CustomActivityOnCrash.setDebugMode(true);
String[] emialTo = {"yuandl@Bluemobi.cn", "kangfh@Bluemobi.cn"};
CustomActivityOnCrash.setEmailTo(emialTo);
Logger.init("law");
x.Ext.init(this);
// refWatcher = LeakCanary.install(this);
refWatcher = installLeakCanary();
}
@Override
public void onLowMemory() {
super.onLowMemory();
System.gc();
}
public static RefWatcher getRefWatcher(Context context) {
MyApplication application = (MyApplication) context.getApplicationContext();
return application.refWatcher;
}
protected RefWatcher installLeakCanary() {
return RefWatcher.DISABLED;
}
}
//package com.kejiang.yuandl.app;
//
//import android.app.Application;
//import android.content.Context;
//
//import com.kejiang.yuandl.mylibrary.CustomActivityOnCrash;
//import com.orhanobut.logger.Logger;
//import org.xutils.x;
//
///**
// * Created by yuandl on 2016/5/23 0023.
// */
//public class MyApplication extends Application {
// @Override
// public void onCreate() {
// super.onCreate();
//// CustomActivityOnCrash.install(this);
//// CustomActivityOnCrash.setDebugMode(true);
//// String[] emialTo = {"yuandl@Bluemobi.cn", "kangfh@Bluemobi.cn"};
//// CustomActivityOnCrash.setEmailTo(emialTo);
//// Logger.init("law");
//// x.Ext.init(this);
//// refWatcher = LeakCanary.install(this);
//// refWatcher = installLeakCanary();
// }
//
// @Override
// public void onLowMemory() {
// super.onLowMemory();
// System.gc();
// }
//
//// public static RefWatcher getRefWatcher(Context context) {
//// MyApplication application = (MyApplication) context.getApplicationContext();
//// return application.refWatcher;
//// }
////
//// protected RefWatcher installLeakCanary() {
//// return RefWatcher.DISABLED;
//// }
//}

View File

@@ -61,6 +61,7 @@ import java.net.SocketTimeoutException;
import java.net.URLEncoder;
import java.util.List;
import java.util.Map;
import java.util.Observer;
import java.util.Set;
/**
@@ -452,7 +453,7 @@ public abstract class BaseActivity extends AutoLayoutActivity implements View.On
@Override
public void onStarted() {
netOnStart();
netOnStart(requestCode);
}
@Override
@@ -546,7 +547,12 @@ public abstract class BaseActivity extends AutoLayoutActivity implements View.On
return jsonBean;
}
/**
* 开始访问网络
*/
protected void netOnStart(int requestCode) {
netOnStart();
}
/**
* 开始访问网络
*/
@@ -622,7 +628,7 @@ public abstract class BaseActivity extends AutoLayoutActivity implements View.On
int responseCode = httpEx.getCode();
String responseMsg = httpEx.getMessage();
String errorResult = httpEx.getResult();
Toast.makeText(x.app(), "网络错误:" + ex.getMessage(), Toast.LENGTH_LONG).show();
Toast.makeText(x.app(), "网络繁忙", Toast.LENGTH_LONG).show();
// ...
} else if (ex instanceof SocketTimeoutException) {
Toast.makeText(x.app(), "连接服务器超时", Toast.LENGTH_LONG).show();
@@ -706,6 +712,7 @@ public abstract class BaseActivity extends AutoLayoutActivity implements View.On
protected void onDestroy() {
// fixFocusedViewLeak(x.app());
// fixInputMethodManager();
// fixInputMethodManagerLeak(this);
mContentLayout.removeAllViews();
mContentLayout = null;
if (cancelable != null && !cancelable.isCancelled()) {
@@ -790,6 +797,48 @@ public abstract class BaseActivity extends AutoLayoutActivity implements View.On
Reflector.invokeMethodExceptionSafe(imm, "startGettingWindowFocus", view);
}
public static void fixInputMethodManagerLeak(Context context) {
if (context == null) {
return;
}
try {
// 对 mCurRootView mServedView mNextServedView 进行置空...
InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
if (imm == null) {
return;
}// author:sodino mail:sodino@qq.com
Object obj_get = null;
Field f_mCurRootView = imm.getClass().getDeclaredField("mCurRootView");
Field f_mServedView = imm.getClass().getDeclaredField("mServedView");
Field f_mNextServedView = imm.getClass().getDeclaredField("mNextServedView");
if (f_mCurRootView.isAccessible() == false) {
f_mCurRootView.setAccessible(true);
}
obj_get = f_mCurRootView.get(imm);
if (obj_get != null) { // 不为null则置为空
f_mCurRootView.set(imm, null);
}
if (f_mServedView.isAccessible() == false) {
f_mServedView.setAccessible(true);
}
obj_get = f_mServedView.get(imm);
if (obj_get != null) { // 不为null则置为空
f_mServedView.set(imm, null);
}
if (f_mNextServedView.isAccessible() == false) {
f_mNextServedView.setAccessible(true);
}
obj_get = f_mNextServedView.get(imm);
if (obj_get != null) { // 不为null则置为空
f_mNextServedView.set(imm, null);
}
} catch (Throwable t) {
t.printStackTrace();
}
}
}

View File

@@ -18,18 +18,15 @@ import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONException;
import com.alibaba.fastjson.TypeReference;
import com.kejiang.yuandl.app.MyApplication;
import com.kejiang.yuandl.bean.JsonBean;
import com.kejiang.yuandl.utils.CheckNetwork;
import com.kejiang.yuandl.utils.SharedPreferencesUtils;
import com.kejiang.yuandl.utils.Tools;
import com.kejiang.yuandl.view.LoadingDialog;
import com.orhanobut.logger.Logger;
import com.squareup.leakcanary.RefWatcher;
import org.xutils.common.Callback;
import org.xutils.common.util.KeyValue;
import org.xutils.common.util.MD5;
import org.xutils.ex.HttpException;
import org.xutils.http.RequestParams;
import org.xutils.x;
@@ -120,7 +117,7 @@ public class BaseFragment extends Fragment {
@Override
public void onStarted() {
netOnStart();
netOnStart(requestCode);
}
@Override
@@ -220,6 +217,12 @@ public class BaseFragment extends Fragment {
protected void netOnStart() {
loadingDialog.show("Loading...");
}
/**
* 开始访问网络
*/
protected void netOnStart(int requestCode) {
netOnStart();
}
/**
* 访问网络的进程
@@ -282,7 +285,7 @@ public class BaseFragment extends Fragment {
int responseCode = httpEx.getCode();
String responseMsg = httpEx.getMessage();
String errorResult = httpEx.getResult();
Toast.makeText(x.app(), "网络错误:" + ex.getMessage(), Toast.LENGTH_LONG).show();
Toast.makeText(x.app(), "网络繁忙", Toast.LENGTH_LONG).show();
// ...
} else if (ex instanceof SocketTimeoutException) {
Toast.makeText(x.app(), "连接服务器超时", Toast.LENGTH_LONG).show();
@@ -426,8 +429,8 @@ public class BaseFragment extends Fragment {
if (cancelable != null && !cancelable.isCancelled()) {
cancelable.cancel();
}
RefWatcher refWatcher = MyApplication.getRefWatcher(getActivity());
refWatcher.watch(this);
// RefWatcher refWatcher = MyApplication.getRefWatcher(getActivity());
// refWatcher.watch(this);
}
}

View File

@@ -0,0 +1,56 @@
package com.kejiang.yuandl.base;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
/**
* Created by yuandl on 2016/8/8 0008.
*/
public abstract class LazyLoadFragment extends Fragment {
/**
* 控件是否初始化完成
*/
private boolean isViewCreated;
/**
* 数据是否已加载完毕
*/
private boolean isLoadDataCompleted;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(getLayout(), container, false);
initViews(view);
isViewCreated = true;
return view;
}
public abstract int getLayout();
public abstract void initViews(View view);
@Override
public void setUserVisibleHint(boolean isVisibleToUser) {
super.setUserVisibleHint(isVisibleToUser);
if (isVisibleToUser && isViewCreated && !isLoadDataCompleted) {
loadData();
}
}
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
if (getUserVisibleHint()) {
loadData();
}
}
public void loadData() {
isLoadDataCompleted = true;
}
}

View File

@@ -1,12 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
style="@style/immersion_status"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF"
android:id="@+id/llRoot"
android:orientation="vertical">
<!-- style="@style/immersion_status"-->
<!-- Title -->
<include layout="@layout/public_titlebar" />

View File

@@ -4,9 +4,9 @@
android:layout_width="match_parent"
android:layout_height="160px"
android:background="#FFFFFF"
android:fitsSystemWindows="true"
android:orientation="horizontal">
<!--
android:fitsSystemWindows="true"-->
<ImageView
android:id="@+id/button_backward"