Просмотр исходного кода

添加定位、aplication添加 task 常量

liujiangyao лет назад: 8
Родитель
Сommit
8647b6d3d4

+ 18 - 0
app/src/main/java/com/sheep/gamegroup/util/CommonUtil.java

@@ -18,9 +18,11 @@ import com.arialyy.aria.core.inf.IEntity;
 import com.kfzs.duanduan.datashare.provider.download.DownLoadInfo;
 import com.sheep.gamegroup.absBase.BaseActivity;
 import com.sheep.gamegroup.model.entity.HomeListEntity;
+import com.sheep.gamegroup.model.entity.TaskEty;
 import com.sheep.gamegroup.model.entity.WebviewEntity;
 import com.sheep.gamegroup.model.entity.WithdrawalEty;
 import com.sheep.jiuyan.samllsheep.R;
+import com.sheep.jiuyan.samllsheep.SheepApp;
 import com.sheep.jiuyan.samllsheep.utils.ClassFileHelper;
 import com.sheep.jiuyan.samllsheep.utils.G;
 import com.sheep.jiuyan.samllsheep.utils.SpUtils;
@@ -433,4 +435,20 @@ public class CommonUtil {
 
         activity.finish();
     }
+
+    /**
+     * 设置时长
+     SheepApp.getInstance().setTaskEty(taskEty);
+     */
+    public void setTAskEnty(TaskEty tAskEnty){
+        try {
+            if(tAskEnty.getInspect_type() == 1){
+                SheepApp.getInstance().setTaskEty(tAskEnty);
+            }else {
+                SheepApp.getInstance().setTaskEty(null);
+            }
+        }catch (Exception e){
+            SheepApp.getInstance().setTaskEty(null);
+        }
+    }
 }

+ 246 - 0
app/src/main/java/com/sheep/gamegroup/util/LocationUtils.java

@@ -0,0 +1,246 @@
+package com.sheep.gamegroup.util;
+
+import android.Manifest;
+import android.content.Context;
+import android.content.pm.PackageManager;
+import android.location.Criteria;
+import android.location.Location;
+import android.location.LocationListener;
+import android.location.LocationManager;
+import android.os.Bundle;
+import android.support.annotation.NonNull;
+import android.support.v4.app.ActivityCompat;
+import android.text.TextUtils;
+import android.widget.Toast;
+
+import com.sheep.jiuyan.samllsheep.SheepApp;
+
+import java.util.HashMap;
+
+/**
+ * Created by ljy on 2018/5/11.
+ */
+
+public class LocationUtils {
+
+    private static final long REFRESH_TIME = 5000L;
+    private static final float METER_POSITION = 0.0f;
+    private static ILocationListener mLocationListener;
+    String logitudeLStr;
+    private static LocationUtils locationUtils;
+
+    public static LocationUtils getInstance(){
+        if(locationUtils == null){
+            locationUtils = new LocationUtils();
+        }
+        return locationUtils;
+    }
+    private static LocationListener listener = new MyLocationListener();
+
+    private static class MyLocationListener implements LocationListener {
+        @Override
+        public void onLocationChanged(Location location) {//定位改变监听
+            if (mLocationListener != null) {
+                mLocationListener.onSuccessLocation(location);
+            }
+        }
+
+        @Override
+        public void onStatusChanged(String provider, int status, Bundle extras) {//定位状态监听
+
+        }
+
+        @Override
+        public void onProviderEnabled(String provider) {//定位状态可用监听
+
+        }
+
+        @Override
+        public void onProviderDisabled(String provider) {//定位状态不可用监听
+
+        }
+    }
+    /**
+     * GPS获取定位方式
+     */
+    public static Location getGPSLocation(@NonNull Context context) {
+        Location location = null;
+        LocationManager manager = getLocationManager(context);
+        //高版本的权限检查
+        if (ActivityCompat.checkSelfPermission(context, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
+            return null;
+        }
+        if (manager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {//是否支持GPS定位
+            //获取最后的GPS定位信息,如果是第一次打开,一般会拿不到定位信息,一般可以请求监听,在有效的时间范围可以获取定位信息
+            location = manager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
+        }
+        return location;
+    }
+    /**
+     * network获取定位方式
+     */
+    public static Location getNetWorkLocation(Context context) {
+        Location location = null;
+        LocationManager manager = getLocationManager(context);
+        //高版本的权限检查
+        if (ActivityCompat.checkSelfPermission(context, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
+            return null;
+        }
+        if (manager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {//是否支持Network定位
+            //获取最后的network定位信息
+            location = manager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
+        }
+        return location;
+    }
+
+    /**
+     * 获取最好的定位方式
+     */
+    public static Location getBestLocation(Context context, Criteria criteria) {
+        Location location;
+        LocationManager manager = getLocationManager(context);
+        if (criteria == null) {
+            criteria = new Criteria();
+        }
+        String provider = manager.getBestProvider(criteria, true);
+        if (TextUtils.isEmpty(provider)) {
+            //如果找不到最适合的定位,使用network定位
+            location = getNetWorkLocation(context);
+        } else {
+            //高版本的权限检查
+            if (ActivityCompat.checkSelfPermission(context, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED
+                    && ActivityCompat.checkSelfPermission(context, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
+                return null;
+            }
+            //获取最适合的定位方式的最后的定位权限
+            location = manager.getLastKnownLocation(provider);
+        }
+        return location;
+    }
+
+    /**
+     * 定位监听
+     */
+    public static void addLocationListener(Context context, String provider, ILocationListener locationListener) {
+
+        addLocationListener(context, provider, REFRESH_TIME, METER_POSITION, locationListener);
+    }
+
+    /**
+     * 定位监听
+     */
+    public static void addLocationListener(Context context, String provider, long time, float meter, ILocationListener locationListener) {
+        if (locationListener != null) {
+            mLocationListener = locationListener;
+        }
+        if (listener == null) {
+            listener = new MyLocationListener();
+        }
+        LocationManager manager = getLocationManager(context);
+        if (ActivityCompat.checkSelfPermission(context, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED
+                && ActivityCompat.checkSelfPermission(context, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
+            return;
+        }
+        manager.requestLocationUpdates(provider, time, meter, listener);
+    }
+
+    /**
+     * 取消定位监听
+     */
+    public static void unRegisterListener(Context context) {
+        if (listener != null) {
+            LocationManager manager = getLocationManager(context);
+            if (ActivityCompat.checkSelfPermission(context, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED
+                    && ActivityCompat.checkSelfPermission(context, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
+                return;
+            }
+            //移除定位监听
+            manager.removeUpdates(listener);
+        }
+    }
+
+    private static LocationManager getLocationManager(@NonNull Context context) {
+        return (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
+    }
+
+    /**
+     * 自定义接口
+     */
+    public interface ILocationListener {
+        void onSuccessLocation(Location location);
+    }
+
+
+    /**
+     * Longitude:经度
+     * Latitude:纬度
+     * 通过GPS获取定位信息
+     */
+    public String getGPSLocations(final Context context) {
+        logitudeLStr = null;
+        Location gps = getGPSLocation(SheepApp.mContext);
+        if (gps == null) {
+            //设置定位监听,因为GPS定位,第一次进来可能获取不到,通过设置监听,可以在有效的时间范围内获取定位信息
+            LocationUtils.addLocationListener(context, LocationManager.GPS_PROVIDER, new LocationUtils.ILocationListener() {
+                @Override
+                public void onSuccessLocation(Location location) {
+                    if (location != null) {
+                        logitudeLStr = location.getLongitude() + "," +location.getLatitude();
+                        Toast.makeText(context, "gps onSuccessLocation location:  lat==" + location.getLatitude() + "     lng==" + location.getLongitude(), Toast.LENGTH_SHORT).show();
+                    } else {
+//                        Toast.makeText(context, "gps location is null", Toast.LENGTH_SHORT).show();
+                    }
+                }
+            });
+        } else {
+            Toast.makeText(context, "gps location: lat==" + gps.getLatitude() + "  lng==" + gps.getLongitude(), Toast.LENGTH_SHORT).show();
+        }
+        return logitudeLStr;
+    }
+
+    /**
+     * 通过网络等获取定位信息
+     */
+    private String getNetworkLocations() {
+        logitudeLStr = null;
+        Location net = LocationUtils.getNetWorkLocation(SheepApp.mContext);
+        if (net == null) {
+        } else {
+            logitudeLStr = net.getLongitude() + "," +net.getLatitude();
+        }
+        return logitudeLStr;
+    }
+
+    /**
+     * 采用最好的方式获取定位信息
+     */
+    private String getBestLocations() {
+        logitudeLStr = null;
+        Criteria c = new Criteria();//Criteria类是设置定位的标准信息(系统会根据你的要求,匹配最适合你的定位供应商),一个定位的辅助信息的类
+        c.setPowerRequirement(Criteria.POWER_LOW);//设置低耗电
+        c.setAltitudeRequired(true);//设置需要海拔
+        c.setBearingAccuracy(Criteria.ACCURACY_COARSE);//设置COARSE精度标准
+        c.setAccuracy(Criteria.ACCURACY_LOW);//设置低精度
+        //... Criteria 还有其他属性,就不一一介绍了
+        Location best = LocationUtils.getBestLocation(SheepApp.mContext, c);
+        if (best == null) {
+
+        } else {
+            logitudeLStr = best.getLongitude() + "," +best.getLatitude();
+        }
+        return logitudeLStr;
+    }
+
+    /**
+     * Longitude:经度
+     * Latitude:纬度
+     * 获取经纬度
+     */
+    public String getLongitudeLatitude(Context context){
+        logitudeLStr = getGPSLocations(context);
+        if(TextUtils.isEmpty(logitudeLStr) && logitudeLStr.length() > 3){
+            logitudeLStr = getNetworkLocations();
+        }
+        return logitudeLStr;
+    }
+}

+ 2 - 1
app/src/main/java/com/sheep/gamegroup/view/activity/ActMyMoney.java

@@ -16,6 +16,7 @@ import com.kfzs.duanduan.fragment.FgtMyMoney2;
 import com.kfzs.duanduan.fragment.FgtMyMoney3;
 import com.kfzs.duanduan.mine.GiftpackListAdapter;
 import com.kfzs.duanduan.utils.StatusBarUtils;
+import com.kfzs.duanduan.utils.dlg.FormatAny;
 import com.sheep.gamegroup.absBase.BaseActivity;
 import com.sheep.gamegroup.model.entity.BaseMessage;
 import com.sheep.gamegroup.model.entity.UserAssets;
@@ -151,7 +152,7 @@ public class ActMyMoney extends BaseActivity {
         my_money_task_reward.setText(getString(R.string.task_reward, userAssets.getTask_reward()));
         my_money_agent_extract.setText(getString(R.string.agent_extract, userAssets.getProxy_commission()));
         my_money_recharge_amount.setText(getString(R.string.recharge_amount, userAssets.getRecharge_amount()));
-        my_money_available_amount.setText(getString(R.string.available_amount, userAssets.getCash_withdrawal()));
+        my_money_available_amount.setText(getString(R.string.available_amount, FormatAny.getInstance().formatString(userAssets.getCash_withdrawal())));
     }
     private void resetData() {
         my_money_total_money.setText(getString(R.string.total_money, "0.00"));

+ 1 - 0
app/src/main/java/com/sheep/gamegroup/view/activity/DialogActivity.java

@@ -373,6 +373,7 @@ public class DialogActivity extends Activity implements TaskDialogContract.View
                 taskEty.setRunTask(1);
                 setBtnState();
                 G.showToast("接收任务成功");
+                CommonUtil.getInstance().setTAskEnty(taskEty);
             }
             EventBus.getDefault().post(new BigEvent().setEventTypes(EventTypes.ONFRESH_TRYMAKEMANY_PAGE));
         }catch (Exception e){

+ 2 - 0
app/src/main/java/com/sheep/gamegroup/view/activity/TaskDetailAct.java

@@ -645,6 +645,8 @@ public class TaskDetailAct extends AbsChooseImageActivity implements TaskDetailC
                     public void onNext(BaseMessage baseMessage) {
                         hideProgress();
                         initData();
+
+                        CommonUtil.getInstance().setTAskEnty(taskReleaseEty.getTask());
 //                        EventBus.getDefault().post(new BigEvent().setEventTypes(EventTypes.ONFRESH_TRYMAKEMANY_PAGE));
                     }
                 });

+ 10 - 0
app/src/main/java/com/sheep/jiuyan/samllsheep/SheepApp.java

@@ -10,6 +10,7 @@ import com.kfzs.duanduan.react.SharedPreferences;
 import com.sheep.gamegroup.di.components.DaggerNetComponent;
 import com.sheep.gamegroup.di.components.NetComponent;
 import com.sheep.gamegroup.di.modules.NetModule;
+import com.sheep.gamegroup.model.entity.TaskEty;
 import com.sheep.gamegroup.util.ConnectAddress;
 import com.sheep.gamegroup.util.UMConfigUtils;
 import com.sheep.jiuyan.samllsheep.utils.G;
@@ -28,6 +29,15 @@ public class SheepApp extends BaseApplication {
 
 
     private NetComponent netComponent;
+    private TaskEty taskEty;
+
+    public TaskEty getTaskEty() {
+        return taskEty;
+    }
+
+    public void setTaskEty(TaskEty taskEty) {
+        this.taskEty = taskEty;
+    }
 
     public static SheepApp get(Context context) {