Skip to content

Commit

Permalink
提交test
Browse files Browse the repository at this point in the history
  • Loading branch information
zengmanyan committed Jul 2, 2018
0 parents commit fc2cd49
Show file tree
Hide file tree
Showing 43 changed files with 1,107 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
*.iml
.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
/build
/captures
.externalNativeBuild
18 changes: 18 additions & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

64 changes: 64 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/runConfigurations.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
32 changes: 32 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
apply plugin: 'com.android.application'
//apply plugin: 'com.jakewharton.butterknife'

android {
compileSdkVersion 27
defaultConfig {
applicationId "com.zmy.broadcasttest"
minSdkVersion 15
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}

dependencies {
// implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
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'

compile 'com.jakewharton:butterknife:8.8.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
}
21 changes: 21 additions & 0 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.zmy.broadcasttest;

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.*;

/**
* Instrumented 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("com.zmy.broadcasttest", appContext.getPackageName());
}
}
25 changes: 25 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.zmy.broadcasttest">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">

</activity>
<activity android:name=".LoginActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>

</activity>
</application>

</manifest>
35 changes: 35 additions & 0 deletions app/src/main/java/com/zmy/broadcasttest/ActivitController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.zmy.broadcasttest;

import java.util.ArrayList;
import java.util.List;

/**
* Created by zengmanyan on 2018/7/1.
*/

public class ActivitController {

private static List<BaseActivity> activities = new ArrayList<>();

public static void addActivity(BaseActivity activity) {
if (activity != null && !activity.isFinishing()) {
activities.add(activity);
}
}

public static void removeActivity(BaseActivity activity) {
// if (activity!=null && !activity.isFinishing()){
activities.remove(activity);
// }
}

public static void existAcftivit() {
for (BaseActivity activity : activities) {
if (activity != null && !activity.isFinishing()) {
activity.finish();
}
}
activities.clear();
}

}
91 changes: 91 additions & 0 deletions app/src/main/java/com/zmy/broadcasttest/BaseActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package com.zmy.broadcasttest;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.os.PersistableBundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;

/**
* Created by zengmanyan on 2018/7/1.
* 基类Activity ,可以不必每个Activity 注册广播及取消广播 并出现强制下线提示框
* <p>
* 在onResume注册和onPuase取消注册是为了保证只有在栈顶的Activity才接收到这条广播
*/

public class BaseActivity extends AppCompatActivity {

private OfflineReceiver offlineReceiver;

private BaseActivity mActivity;

@Override
public void onCreate(@Nullable Bundle savedInstanceState, @Nullable PersistableBundle persistentState) {
super.onCreate(savedInstanceState, persistentState);
mActivity = this;
ActivitController.addActivity(this);

}

@Override
protected void onResume() {
super.onResume();
IntentFilter intentFilter = new IntentFilter("com.zmy.broadcasttest.OFFLINE");
offlineReceiver = new OfflineReceiver();
registerReceiver(offlineReceiver, intentFilter);
}

@Override
protected void onPause() {
super.onPause();
if (offlineReceiver != null) {
unregisterReceiver(offlineReceiver);
}

}

@Override
protected void onDestroy() {
super.onDestroy();
ActivitController.removeActivity(this);
}

class OfflineReceiver extends BroadcastReceiver {

@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
Utils.showToast(mActivity, "action: " + action);
// if ("com.zmy.broadcasttest.OFFLINE".equals(action)) {
// showDialog();
AlertDialog.Builder dialog = new AlertDialog.Builder(mActivity);
dialog.setTitle("提示")
.setMessage("您确定要退出登录吗?")
.setPositiveButton("确定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
//1.退出登录
//2.关闭Activity
ActivitController.existAcftivit();
//3.重新启动登录页
LoginActivity.actionStartLoginAc(mActivity);
}
})
.setNegativeButton("取消", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
}).create().show();

// }

}
}
}
Loading

0 comments on commit fc2cd49

Please sign in to comment.