From ce4ea39afd14301dd1df0501a657fa6de97d576a Mon Sep 17 00:00:00 2001
From: 陈奇 <1650699704@qq.com>
Date: Tue, 27 Nov 2018 17:11:35 +0800
Subject: [PATCH] [*]修改主页指针跳转动画
---
app/src/main/java/com/moral/yunfushao/MainActivity.java | 99 ++++++++++++++++++++++++++++++++-----------------
1 files changed, 64 insertions(+), 35 deletions(-)
diff --git a/app/src/main/java/com/moral/yunfushao/MainActivity.java b/app/src/main/java/com/moral/yunfushao/MainActivity.java
index 024aa65..ccc4547 100644
--- a/app/src/main/java/com/moral/yunfushao/MainActivity.java
+++ b/app/src/main/java/com/moral/yunfushao/MainActivity.java
@@ -6,6 +6,7 @@
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
+import android.content.pm.PackageManager;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.AsyncTask;
@@ -43,6 +44,7 @@
import com.moral.yunfushao.model.EventMessage;
import com.moral.yunfushao.model.User;
import com.moral.yunfushao.update.UpdateManager;
+import com.moral.yunfushao.utils.PermissionUtil;
import org.greenrobot.eventbus.EventBus;
import org.json.JSONException;
@@ -64,13 +66,14 @@
//������fragments
private Class fragments[] = {FragmentMonitor.class, FragmentShoppongMall.class, FragmentSettings.class};
//������������������������������
- private int mIcons[] = {R.drawable.menu1, R.drawable.menu2,R.drawable.menu3};
+ private int mIcons[] = {R.drawable.menu1, R.drawable.menu2, R.drawable.menu3};
//Tab���������������
- private String mTextArray[] = {"������������", "������","������"};
+ private String mTextArray[] = {"������������", "������", "������"};
private int index = 0;
private boolean islogin = false;
- private BluetoothService mBluetoothService;
+ public static BluetoothService mBluetoothService;
+
@Override
protected void getBundleExtras(Bundle extras) {
islogin = extras.getBoolean("islogin", false);
@@ -82,9 +85,15 @@
}
@Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
+ protected void onStart() {
+ super.onStart();
bindService();
+ PermissionUtil.verifyStoragePermissions(this);
+ }
+
+ @Override
+ protected void onStop() {
+ super.onStop();
}
@Override
@@ -134,13 +143,13 @@
@Override
protected void initData() {
prepare();
- if(MainApp.theApp.bleManager!=null){
- if(MainApp.theApp.bleManager.isSupportBle()){
+ if (MainApp.theApp.bleManager != null) {
+ if (MainApp.theApp.bleManager.isSupportBle()) {
MainApp.theApp.bleManager.enableBluetooth();
- }else{
+ } else {
mToatUtils.showSingletonToast("���������������������������������BLE���");
}
- }else{
+ } else {
mToatUtils.showSingletonToast("���������������������������������BLE���");
}
getAd();
@@ -212,6 +221,20 @@
}
}
+ @Override
+ public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
+ super.onRequestPermissionsResult(requestCode, permissions, grantResults);
+
+ if (requestCode == 1) {
+ for (int i = 0; i < permissions.length; i++) {
+ if (grantResults[i] != PackageManager.PERMISSION_GRANTED) {
+ //������������
+ PermissionUtil.verifyStoragePermissions(this);
+ }
+ }
+ }
+ }
+
UpdateManager manager = new UpdateManager(MainActivity.this);
private class checkUpdateTask extends AsyncTask<String, Void, String> {
@@ -254,7 +277,7 @@
return;
String url = API.GET_INFO;
Map<String, String> params = new HashMap<>();
- params.put("phone",MainApp.theApp.sharedPreferencesUtil.getLoginInfo().getPhone());
+ params.put("phone", MainApp.theApp.sharedPreferencesUtil.getLoginInfo().getPhone());
HttpUtils.doPost(url, params, CacheMode.DEFAULT, false, new HttpCallBack() {
@Override
public void onSuccess(String res, String msg) {
@@ -271,12 +294,13 @@
}
@Override
- public void onFail(int errno,String s) {
+ public void onFail(int errno, String s) {
}
});
}
}
+
public BluetoothService getBluetoothService() {
return mBluetoothService;
}
@@ -296,45 +320,47 @@
mBluetoothService = ((BluetoothService.BluetoothBinder) service).getService();
mBluetoothService.setScanCallback(callback);
String mac = MainApp.theApp.sharedPreferencesUtil.getBLE();
- if(!TextUtils.isEmpty(mac)){
+ System.out.println("BleGattCallback init");
+ if (!TextUtils.isEmpty(mac)) {
mBluetoothService.scanAndConnect5(mac);
}
}
@Override
public void onServiceDisconnected(ComponentName name) {
+ System.out.println("BleGattCallback onServiceDisconnected");
mBluetoothService = null;
}
-
-
};
private BluetoothService.Callback callback = new BluetoothService.Callback() {
@Override
public void onStartScan() {
-
+ System.out.println("MainActivity onStartScan");
}
@Override
public void onScanning(ScanResult result) {
-
+ System.out.println("MainActivity onScanning");
}
@Override
public void onScanComplete() {
-
+ System.out.println("MainActivity onScanComplete");
}
@Override
public void onConnecting() {
+ System.out.println("MainActivity onConnecting");
progressDialog.setTitleText("������������...");
progressDialog.show();
}
@Override
public void onConnectFail() {
+ System.out.println("MainActivity onConnectFail");
progressDialog.dismiss();
- mToatUtils.showSingletonToast("������������");
+ mBluetoothService.closeConnect();
EventMessage msg = new EventMessage();
msg.setType(AppConfig.GET_BLE_DISCONNECT);
EventBus.getDefault().postSticky(msg);
@@ -342,6 +368,7 @@
@Override
public void onDisConnected() {
+ System.out.println("MainActivity onDisConnected");
progressDialog.dismiss();
mToatUtils.showSingletonToast("���������������������");
EventMessage msg = new EventMessage();
@@ -351,6 +378,7 @@
@Override
public void onServicesDiscovered() {
+ System.out.println("MainActivity onServicesDiscovered");
progressDialog.dismiss();
EventMessage msg = new EventMessage();
msg.setType(AppConfig.GET_BLE_SERVICE);
@@ -360,11 +388,12 @@
private AlertDialog adDialog;
private View adView;
- private TextView tv_content,tv_name;
+ private TextView tv_content, tv_name;
private ImageView iv_logo;
- private Button bt_cancel,bt_ok;
- private void showAd(String content,String logo,String name){
- adView = LayoutInflater.from(this).inflate(R.layout.dialog_ad_layout,null);
+ private Button bt_cancel, bt_ok;
+
+ private void showAd(String content, String logo, String name) {
+ adView = LayoutInflater.from(this).inflate(R.layout.dialog_ad_layout, null);
tv_content = (TextView) adView.findViewById(R.id.tv_content);
tv_name = (TextView) adView.findViewById(R.id.tv_name);
bt_cancel = (Button) adView.findViewById(R.id.bt_cancel);
@@ -372,7 +401,7 @@
iv_logo = (ImageView) adView.findViewById(R.id.iv_logo);
tv_content.setText(content);
tv_name.setText(name);
- ImageLoader.setCircleImageView(this,logo,iv_logo,R.mipmap.circle);
+ ImageLoader.setCircleImageView(this, logo, iv_logo, R.mipmap.circle);
bt_cancel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
@@ -380,30 +409,30 @@
}
});
adDialog = new AlertDialog.Builder(this).setView(adView).create();
- Window window=adDialog.getWindow();
+ Window window = adDialog.getWindow();
window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
adDialog.show();
}
- private void getAd(){
+ private void getAd() {
HttpUtils.doPost(API.GETAD, null, CacheMode.DEFAULT, false, new HttpCallBack() {
@Override
public void onSuccess(String res, String msg) {
- if(TextUtils.isEmpty(res)){
+ if (TextUtils.isEmpty(res)) {
return;
}
try {
JSONObject json = new JSONObject(res);
- String time = MainApp.theApp.sharedPreferencesUtil.getShowAd();
- if(TextUtils.isEmpty(time)){
- showAd(json.optString("content"),json.optString("logo"),json.optString("name"));
+ String time = MainApp.theApp.sharedPreferencesUtil.getShowAd();
+ if (TextUtils.isEmpty(time)) {
+ showAd(json.optString("content"), json.optString("logo"), json.optString("name"));
MainApp.theApp.sharedPreferencesUtil.saveShowAd(TimeUtil.getCurrentDate("yyyy-MM-dd"));
- }else{
- if(time.equals(TimeUtil.getCurrentDate("yyyy-MM-dd"))){
+ } else {
+ if (time.equals(TimeUtil.getCurrentDate("yyyy-MM-dd"))) {
return;
- }else{
- showAd(json.optString("content"),json.optString("logo"),json.optString("name"));
+ } else {
+ showAd(json.optString("content"), json.optString("logo"), json.optString("name"));
MainApp.theApp.sharedPreferencesUtil.saveShowAd(TimeUtil.getCurrentDate("yyyy-MM-dd"));
}
}
@@ -425,8 +454,8 @@
});
}
- public void resetBLECallBack(){
- if(mBluetoothService!=null){
+ public void resetBLECallBack() {
+ if (mBluetoothService != null) {
mBluetoothService.setScanCallback(callback);
}
}
--
Gitblit v1.8.0