-
Notifications
You must be signed in to change notification settings - Fork 745
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
0 parents
commit 27f58df
Showing
71 changed files
with
2,611 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 | ||
|
||
|
||
*.iml | ||
.gradle | ||
/local.properties | ||
/.idea/workspace.xml | ||
/.idea/libraries | ||
.DS_Store | ||
/build | ||
/captures | ||
.externalNativeBuild |
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,37 @@ | ||
apply plugin: 'com.android.application' | ||
|
||
android { | ||
compileSdkVersion 25 | ||
buildToolsVersion "25.0.3" | ||
defaultConfig { | ||
applicationId "com.vector.appupdatedemo" | ||
minSdkVersion 14 | ||
targetSdkVersion 25 | ||
versionCode 1 | ||
versionName "0.1.0" | ||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" | ||
} | ||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
compile fileTree(include: ['*.jar'], dir: 'libs') | ||
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.constraint:constraint-layout:1.0.2' | ||
compile 'com.qianwen:okhttp-utils:3.7.0' | ||
//rxjava 1 | ||
compile 'io.reactivex:rxjava:1.2.9' | ||
compile 'io.reactivex:rxandroid:1.2.0' | ||
//权限引导 | ||
compile 'com.tbruyelle.rxpermissions:rxpermissions:0.9.4@aar' | ||
testCompile 'junit:junit:4.12' | ||
compile project(':update-app') | ||
} |
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:\code\AndroidStudio\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/com/vector/appupdatedemo/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 com.vector.appupdatedemo; | ||
|
||
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("com.vector.appupdatedemo", 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,34 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.vector.appupdatedemo"> | ||
|
||
<uses-permission android:name="android.permission.INTERNET"/> | ||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> | ||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> | ||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/> | ||
<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"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN"/> | ||
|
||
<category android:name="android.intent.category.LAUNCHER"/> | ||
</intent-filter> | ||
</activity> | ||
<provider | ||
android:name="android.support.v4.content.FileProvider" | ||
android:authorities="${applicationId}.fileProvider" | ||
android:exported="false" | ||
android:grantUriPermissions="true"> | ||
<meta-data | ||
android:name="android.support.FILE_PROVIDER_PATHS" | ||
android:resource="@xml/file_paths"/> | ||
</provider> | ||
</application> | ||
|
||
</manifest> |
101 changes: 101 additions & 0 deletions
101
app/src/main/java/com/vector/appupdatedemo/CProgressDialogUtils.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,101 @@ | ||
package com.vector.appupdatedemo; | ||
|
||
import android.app.Activity; | ||
import android.app.ProgressDialog; | ||
import android.content.DialogInterface; | ||
|
||
/** | ||
* Created by Vector on 2016/8/12 0012. | ||
*/ | ||
public class CProgressDialogUtils { | ||
private static final String TAG = CProgressDialogUtils.class.getSimpleName(); | ||
|
||
private CProgressDialogUtils() { | ||
throw new UnsupportedOperationException("cannot be instantiated"); | ||
} | ||
|
||
private static ProgressDialog sCircleProgressDialog; | ||
|
||
public static void showProgressDialog(Activity activity) { | ||
showProgressDialog(activity, "加载中", false, null); | ||
} | ||
|
||
public static void showProgressDialog(Activity activity, DialogInterface.OnCancelListener listener) { | ||
showProgressDialog(activity, "加载中", true, listener); | ||
} | ||
|
||
public static void showProgressDialog(Activity activity, String msg) { | ||
showProgressDialog(activity, msg, false, null); | ||
} | ||
|
||
public static void showProgressDialog(Activity activity, String msg, DialogInterface.OnCancelListener listener) { | ||
showProgressDialog(activity, msg, true, listener); | ||
} | ||
|
||
public static void showProgressDialog(final Activity activity, String msg, boolean cancelable, DialogInterface.OnCancelListener listener) { | ||
if (activity == null || activity.isFinishing()) { | ||
return; | ||
} | ||
|
||
|
||
if (sCircleProgressDialog == null) { | ||
sCircleProgressDialog = new ProgressDialog(activity); | ||
sCircleProgressDialog.setMessage(msg); | ||
sCircleProgressDialog.setOwnerActivity(activity); | ||
sCircleProgressDialog.setOnCancelListener(listener); | ||
sCircleProgressDialog.setCancelable(cancelable); | ||
} else { | ||
if (activity.equals(sCircleProgressDialog.getOwnerActivity())) { | ||
sCircleProgressDialog.setMessage(msg); | ||
sCircleProgressDialog.setCancelable(cancelable); | ||
sCircleProgressDialog.setOnCancelListener(listener); | ||
} else { | ||
//不相等,所以取消任何ProgressDialog | ||
cancelProgressDialog(); | ||
sCircleProgressDialog = new ProgressDialog(activity); | ||
sCircleProgressDialog.setMessage(msg); | ||
sCircleProgressDialog.setCancelable(cancelable); | ||
sCircleProgressDialog.setOwnerActivity(activity); | ||
sCircleProgressDialog.setOnCancelListener(listener); | ||
} | ||
} | ||
|
||
if (!sCircleProgressDialog.isShowing()) { | ||
sCircleProgressDialog.show(); | ||
} | ||
|
||
// sCircleProgressDialog.setOnKeyListener(new DialogInterface.OnKeyListener() { | ||
// @Override | ||
// public boolean onKey(DialogInterface dialogInterface, int i, KeyEvent keyEvent) { | ||
// if (KeyEvent.KEYCODE_BACK == keyEvent.getKeyCode()) { | ||
// if (!activity.isFinishing()) { | ||
// cancelProgressDialog(); | ||
// activity.finish(); | ||
// return true; | ||
// } | ||
// } | ||
// return false; | ||
// } | ||
// }); | ||
|
||
|
||
} | ||
|
||
|
||
public static void cancelProgressDialog(Activity activity) { | ||
if (sCircleProgressDialog != null && sCircleProgressDialog.isShowing()) { | ||
if (sCircleProgressDialog.getOwnerActivity() == activity) { | ||
sCircleProgressDialog.cancel(); | ||
sCircleProgressDialog = null; | ||
} | ||
} | ||
} | ||
|
||
public static void cancelProgressDialog() { | ||
if (sCircleProgressDialog != null && sCircleProgressDialog.isShowing()) { | ||
sCircleProgressDialog.cancel(); | ||
sCircleProgressDialog = null; | ||
} | ||
} | ||
|
||
} |
91 changes: 91 additions & 0 deletions
91
app/src/main/java/com/vector/appupdatedemo/MainActivity.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,91 @@ | ||
package com.vector.appupdatedemo; | ||
|
||
import android.os.Bundle; | ||
import android.os.Environment; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.util.Log; | ||
import android.view.View; | ||
import android.widget.Toast; | ||
|
||
import com.tbruyelle.rxpermissions.RxPermissions; | ||
import com.vector.update_app.UpdateAppBean; | ||
import com.vector.update_app.UpdateAppManager; | ||
import com.vector.update_app.UpdateCallback; | ||
import com.zhy.http.okhttp.OkHttpUtils; | ||
|
||
import rx.functions.Action1; | ||
|
||
import static android.Manifest.permission.WRITE_EXTERNAL_STORAGE; | ||
|
||
public class MainActivity extends AppCompatActivity { | ||
|
||
private static final String TAG = MainActivity.class.getSimpleName(); | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_main); | ||
OkHttpUtils.getInstance() | ||
.init(this) | ||
.debug(true, "vetor") | ||
.timeout(20 * 1000); | ||
|
||
} | ||
|
||
public void updateApp(View view) { | ||
//http://47.94.102.201/mobileCard/com/mobile/updateVersion.html?version=0.2.0&appKey=ab55ce55Ac4bcP408cPb8c1Aaeac179c5f6f | ||
//http://47.94.102.201/mobileCard/com/mobile/updateVersion.html?appKey=ab55ce55Ac4bcP408cPb8c1Aaeac179c5f6f&version=0.1.0 | ||
|
||
String url = "http://47.94.102.201/mobileCard/com/mobile/updateVersion.html"; | ||
String appKey = "ab55ce55Ac4bcP408cPb8c1Aaeac179c5f6f"; | ||
|
||
final String targetPath = Environment.getExternalStorageState(); | ||
|
||
final MyHttpUtil httpManager = new MyHttpUtil(); | ||
|
||
final UpdateAppManager updateAppManager = UpdateAppManager.getInstance(); | ||
|
||
updateAppManager.updateApp(this, httpManager, url, appKey, new UpdateCallback() { | ||
@Override | ||
public void isHasNewApp(boolean hasNewApp, UpdateAppBean updateApp) { | ||
Log.d(TAG, "isHasNewApp() called with: hasNewApp = [" + hasNewApp + "], updateApp = [" + updateApp + "]"); | ||
if (hasNewApp) { | ||
updateAppManager.showUpdatedDialog(httpManager, MainActivity.this, targetPath, updateApp); | ||
} else { | ||
Toast.makeText(MainActivity.this, "没有新版本", Toast.LENGTH_SHORT).show(); | ||
} | ||
|
||
} | ||
|
||
@Override | ||
public void onAfter() { | ||
Log.d(TAG, "onAfter() called"); | ||
CProgressDialogUtils.cancelProgressDialog(MainActivity.this); | ||
} | ||
|
||
@Override | ||
public void onBefore() { | ||
Log.d(TAG, "onBefore() called"); | ||
CProgressDialogUtils.showProgressDialog(MainActivity.this); | ||
} | ||
|
||
}); | ||
} | ||
|
||
public void getPermission(View view) { | ||
RxPermissions rxPermissions = new RxPermissions(this); | ||
rxPermissions.request(WRITE_EXTERNAL_STORAGE) | ||
.subscribe(new Action1<Boolean>() { | ||
@Override | ||
public void call(Boolean aBoolean) { | ||
if (aBoolean) { | ||
Toast.makeText(MainActivity.this, "已授权", Toast.LENGTH_SHORT).show(); | ||
} else { | ||
Toast.makeText(MainActivity.this, "未授权", Toast.LENGTH_SHORT).show(); | ||
} | ||
|
||
} | ||
}); | ||
|
||
} | ||
} |
Oops, something went wrong.