Browse Source

UU运动移植到设置里,解决UAS部门日报详情界面报错bug

FANGLH 9 years ago
parent
commit
99c05716d5

+ 11 - 60
WeiChat/src/main/java/basepedo/ui/MyPedometerActivity.java

@@ -13,13 +13,9 @@ import android.os.Messenger;
 import android.os.RemoteException;
 import android.view.Menu;
 import android.view.MenuItem;
-import android.view.View;
-import android.widget.Button;
 import android.widget.TextView;
-import android.widget.Toast;
 
 import com.xzjmyk.pm.activity.R;
-import com.xzjmyk.pm.activity.ui.MainActivity;
 import com.xzjmyk.pm.activity.ui.base.BaseActivity;
 
 import basepedo.config.Constant;
@@ -35,7 +31,7 @@ public class MyPedometerActivity extends BaseActivity implements Handler.Callbac
     private Messenger messenger;
     private Messenger mGetReplyMessenger = new Messenger(new Handler(this));
     private Handler delayHandler;
-
+    private String uustep_service_name = "basepedo.service.StepService";
     ServiceConnection conn = new ServiceConnection() {
         @Override
         public void onServiceConnected(ComponentName name, IBinder service) {
@@ -54,9 +50,6 @@ public class MyPedometerActivity extends BaseActivity implements Handler.Callbac
 
         }
     };
-    private Button close_step;
-    private Button open_step;
-
     @Override
     public boolean handleMessage(Message msg) {
         switch (msg.what) {
@@ -88,6 +81,7 @@ public class MyPedometerActivity extends BaseActivity implements Handler.Callbac
         return false;
     }
 
+
     @Override
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
@@ -97,41 +91,8 @@ public class MyPedometerActivity extends BaseActivity implements Handler.Callbac
     }
     private void init() {
         text_step = (TextView) findViewById(R.id.text_step);
-        close_step = (Button) findViewById(R.id.close_uu_step_bt);
-        open_step = (Button) findViewById(R.id.open_uu_step_bt);
-
-        if (isServiceRunning() == true){
-            setupService();
-            open_step.setVisibility(View.GONE);
-            close_step.setVisibility(View.VISIBLE);
-        }else {
-            open_step.setVisibility(View.VISIBLE);
-            close_step.setVisibility(View.GONE);
-        }
-        open_step.setOnClickListener(new View.OnClickListener() {
-            @Override
-            public void onClick(View v) {
-                setupService();
-                Toast.makeText(MyPedometerActivity.this, "您已开启UU运动,UU将记录您的运动步数并显示在通知栏", Toast.LENGTH_LONG).show();
-                open_step.setVisibility(View.GONE);
-                close_step.setVisibility(View.VISIBLE);
-            }
-        });
-
-        close_step.setOnClickListener(new View.OnClickListener() {
-            @Override
-            public void onClick(View v) {
-//                setoffService();
-//                Toast.makeText(MyPedometerActivity.this, "您已关闭UU运动,通知栏将不再显示您的运动步数", Toast.LENGTH_LONG).show();
-                ToastMessage("该功能未完善");
-//                open_step.setVisibility(View.VISIBLE);
-//                close_step.setVisibility(View.GONE);
-
-            }
-        });
-
         delayHandler = new Handler(this);
-
+        setupService();
     }
 
 
@@ -140,18 +101,6 @@ public class MyPedometerActivity extends BaseActivity implements Handler.Callbac
         bindService(intent, conn, Context.BIND_AUTO_CREATE);
         startService(intent);
     }
-    private void setoffService() {
-        Intent intent = new Intent(mContext, StepService.class);
-        unbindService(conn);
-        stopService(intent);
-    }
-
-    @Override
-    protected void onDestroy() {
-        unbindService(conn);
-        super.onDestroy();
-    }
-
     @Override
     protected void onResume() {
         super.onResume();
@@ -165,22 +114,24 @@ public class MyPedometerActivity extends BaseActivity implements Handler.Callbac
     @Override
     public boolean onOptionsItemSelected(MenuItem item) {
         if (item.getItemId() == android.R.id.home) {
-           startActivity(new Intent(this, MainActivity.class));
-            finish();
+            if (isServiceRunning(uustep_service_name)){
+                unbindService(conn);
+            }
         }
         return super.onOptionsItemSelected(item);
     }
 
     @Override
     public void onBackPressed() {
-        startActivity(new Intent(mContext, MainActivity.class));
+        if (isServiceRunning(uustep_service_name)){
+            unbindService(conn);
+        }
         super.onBackPressed();
-        finish();
     }
-    private boolean isServiceRunning() { //判断UU运动服务是否已经运行
+    private boolean isServiceRunning(String servicename) { //判断UU运动服务是否已经运行
         ActivityManager manager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
         for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
-            if ("basepedo.service.StepService".equals(service.service.getClassName())) {
+            if (servicename.equals(service.service.getClassName())) {
                 return true;
             }
         }

+ 31 - 5
WeiChat/src/main/java/com/xzjmyk/pm/activity/adapter/CommonDocApprovalFlowAdapter.java

@@ -12,11 +12,7 @@ import android.widget.TextView;
 import com.xzjmyk.pm.activity.R;
 import com.xzjmyk.pm.activity.bean.oa.CommonApprovalFlowBean;
 import com.xzjmyk.pm.activity.helper.AvatarHelper;
-import com.xzjmyk.pm.activity.ui.erp.db.DBManager;
-import com.xzjmyk.pm.activity.ui.erp.entity.EmployeesEntity;
-import com.xzjmyk.pm.activity.ui.erp.util.CommonUtil;
 import com.xzjmyk.pm.activity.ui.erp.util.ListUtils;
-import com.xzjmyk.pm.activity.ui.erp.util.StringUtils;
 
 import java.util.List;
 
@@ -126,7 +122,7 @@ public class CommonDocApprovalFlowAdapter extends BaseAdapter {
                 viewHolder.AppFlowStatus.setText("");
                 viewHolder.AppFlowNode.setImageResource(R.drawable.node_none3);
             }
-        } else {
+        } else if (datanum !=0 && nodesnum != 0){
             if (position > (datanum - nodesnum - 1)) { //已走过审批流的节点
                 if (mCommonApprovalFlowBean.getNodes().get(datanum - position - 1).getJn_dealResult().equals("同意")) {
                     viewHolder.AppFlowStatus.setTextColor(mContext.getResources().getColor(R.color.done_approval));
@@ -182,6 +178,36 @@ public class CommonDocApprovalFlowAdapter extends BaseAdapter {
                 viewHolder.AppFlowTime.setText("");
                 viewHolder.AppFlowDescriptionll.setVisibility(View.GONE);
             }
+        }else if (datanum == 0 && nodesnum != 0){  // 兼容data 为空情况
+            if (mCommonApprovalFlowBean.getNodes().get(nodesnum - position - 1).getJn_dealResult().equals("同意")) {
+                viewHolder.AppFlowStatus.setTextColor(mContext.getResources().getColor(R.color.done_approval));
+                viewHolder.AppFlowStatus.setText("已审批");
+                viewHolder.AppFlowNode.setImageResource(R.drawable.node_finished3);
+                viewHolder.AppFlowTime.setText(mCommonApprovalFlowBean.getNodes().get(nodesnum - position - 1).getJn_dealTime());
+
+                //当已审批时判断有没有审批语
+                if (mCommonApprovalFlowBean.getNodes().get(nodesnum - position - 1).getJn_nodeDescription() != null) {
+                    viewHolder.AppFlowDescriptionll.setVisibility(View.VISIBLE);
+                    viewHolder.AppFlowDescriptiontv.setTextColor(mContext.getResources().getColor(R.color.done_approval));
+                    viewHolder.AppFlowDescriptiontv.setText("( " + mCommonApprovalFlowBean.getNodes().get(nodesnum - position - 1).getJn_nodeDescription().toString() + " )");
+                    final String des_msg = mCommonApprovalFlowBean.getNodes().get(nodesnum - position - 1).getJn_nodeDescription().toString();
+                    viewHolder.AppFlowDescriptionll.setOnClickListener(new View.OnClickListener() {
+                        //点击查看详细批语
+                        @Override
+                        public void onClick(View v) {
+                            new AlertDialog
+                                    .Builder(mContext)
+                                    .setTitle("审批语详情")
+                                    .setMessage("\t" + des_msg)
+                                    .setPositiveButton("确定", null)
+                                    .show();
+                        }
+                    });
+                } else {
+                    viewHolder.AppFlowDescriptionll.setVisibility(View.GONE);
+                    viewHolder.AppFlowDescriptiontv.setText("");
+                }
+            }
         }
 
 

+ 31 - 1
WeiChat/src/main/java/com/xzjmyk/pm/activity/adapter/DailyDetailsApprovalFlowAdapter.java

@@ -128,7 +128,7 @@ public class DailyDetailsApprovalFlowAdapter extends BaseAdapter {
                 viewHolder.AppFlowStatus.setText("");
                 viewHolder.AppFlowNode.setImageResource(R.drawable.node_none3);
             }
-        } else {
+        } else if (datanum !=0 && nodesnum != 0){
             if (position > (datanum - nodesnum - 1)) { //已走过审批流的节点
                 if (mCommonApprovalFlowBean.getNodes().get(datanum - position - 1).getJn_dealResult().equals("同意")) {
                     viewHolder.AppFlowStatus.setTextColor(mContext.getResources().getColor(R.color.done_approval));
@@ -184,6 +184,36 @@ public class DailyDetailsApprovalFlowAdapter extends BaseAdapter {
                 viewHolder.AppFlowTime.setText("");
                 viewHolder.AppFlowDescriptionll.setVisibility(View.GONE);
             }
+        }else if (datanum == 0 && nodesnum != 0){  // 兼容data 为空情况
+            if (mCommonApprovalFlowBean.getNodes().get(nodesnum - position - 1).getJn_dealResult().equals("同意")) {
+                viewHolder.AppFlowStatus.setTextColor(mContext.getResources().getColor(R.color.done_approval));
+                viewHolder.AppFlowStatus.setText("已审批");
+                viewHolder.AppFlowNode.setImageResource(R.drawable.node_finished3);
+                viewHolder.AppFlowTime.setText(mCommonApprovalFlowBean.getNodes().get(nodesnum - position - 1).getJn_dealTime());
+
+                //当已审批时判断有没有审批语
+                if (mCommonApprovalFlowBean.getNodes().get(nodesnum - position - 1).getJn_nodeDescription() != null) {
+                    viewHolder.AppFlowDescriptionll.setVisibility(View.VISIBLE);
+                    viewHolder.AppFlowDescriptiontv.setTextColor(mContext.getResources().getColor(R.color.done_approval));
+                    viewHolder.AppFlowDescriptiontv.setText("( " + mCommonApprovalFlowBean.getNodes().get(nodesnum - position - 1).getJn_nodeDescription().toString() + " )");
+                    final String des_msg = mCommonApprovalFlowBean.getNodes().get(nodesnum - position - 1).getJn_nodeDescription().toString();
+                    viewHolder.AppFlowDescriptionll.setOnClickListener(new View.OnClickListener() {
+                        //点击查看详细批语
+                        @Override
+                        public void onClick(View v) {
+                            new AlertDialog
+                                    .Builder(mContext)
+                                    .setTitle("审批语详情")
+                                    .setMessage("\t" + des_msg)
+                                    .setPositiveButton("确定", null)
+                                    .show();
+                        }
+                    });
+                } else {
+                    viewHolder.AppFlowDescriptionll.setVisibility(View.GONE);
+                    viewHolder.AppFlowDescriptiontv.setText("");
+                }
+            }
         }
         return convertView;
     }

+ 1 - 0
WeiChat/src/main/java/com/xzjmyk/pm/activity/ui/MainActivity.java

@@ -118,6 +118,7 @@ public class MainActivity extends BaseActivity implements NetWorkObservable.NetW
     private MeFragment mMeFragment;//我
     private ContactFragment mBusinessCircleFragment;
     public static String BAIDU_PUSH = "BAIDUPUSH";
+    public static String UU_STEP = "UUSTEP";
     private boolean mXmppBind;
     private CoreService mCoreService;
     private boolean isPause = true;// 界面是否暂停

+ 1 - 0
WeiChat/src/main/java/com/xzjmyk/pm/activity/ui/erp/util/CommonUtil.java

@@ -1370,4 +1370,5 @@ public class CommonUtil {
         context.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.parse("file://" + "uu/myqzonepic")));
         com.xzjmyk.pm.activity.ui.erp.net.ViewUtil.ToastMessage(context, "图片已保存至:sdcard/uu/myqzonepic");
     }
+
 }

+ 62 - 0
WeiChat/src/main/java/com/xzjmyk/pm/activity/ui/me/SettingActivity.java

@@ -1,6 +1,7 @@
 package com.xzjmyk.pm.activity.ui.me;
 
 import android.annotation.TargetApi;
+import android.app.ActivityManager;
 import android.app.AlertDialog;
 import android.app.ProgressDialog;
 import android.content.DialogInterface;
@@ -15,6 +16,7 @@ import android.view.View;
 import android.widget.Button;
 import android.widget.RelativeLayout;
 import android.widget.TextView;
+import android.widget.Toast;
 
 import com.baidu.android.pushservice.PushManager;
 import com.baidu.autoupdatesdk.AppUpdateInfo;
@@ -42,6 +44,8 @@ import com.xzjmyk.pm.activity.util.ToastUtil;
 
 import java.io.File;
 
+import basepedo.ui.MyPedometerActivity;
+
 /**
  * 设置
  */
@@ -54,6 +58,12 @@ public class SettingActivity extends ActionBackActivity implements View.OnClickL
     @ViewInject(R.id.cb_task_reply)
     private SwitchView cb_task_reply;
 
+    @ViewInject(R.id.uu_step_rl)
+    private RelativeLayout uu_step_rl;
+
+    @ViewInject(R.id.uu_step_reply)
+    private  SwitchView uu_step_reply;
+
     @ViewInject(R.id.rl_app_update)
     private RelativeLayout rl_app_update;
     @ViewInject(R.id.version_value)
@@ -62,6 +72,7 @@ public class SettingActivity extends ActionBackActivity implements View.OnClickL
     private RelativeLayout close_push_rl;
     private ProgressDialog dialog;
     private RelativeLayout share_rl;
+    private String uustep_service_name = "basepedo.service.StepService";
 
     @Override
     protected void onCreate(Bundle savedInstanceState) {
@@ -80,6 +91,7 @@ public class SettingActivity extends ActionBackActivity implements View.OnClickL
         mExitBtn = (Button) findViewById(R.id.exit_btn);
         //share_rl.setVisibility(View.GONE);
         int isPush = PreferenceUtils.getInt(MyApplication.getInstance(), MainActivity.BAIDU_PUSH);
+
         if (isPush == -1) {//第一次进入没有配置
             cb_task_reply.setChecked(true);
         } else if (isPush == 0) {//选择不推送
@@ -119,8 +131,58 @@ public class SettingActivity extends ActionBackActivity implements View.OnClickL
         long cacheSize = GetFileSizeUtil.getFileSize(new File(MyApplication.getInstance().mAppDir));
         mCacheTv.setText(GetFileSizeUtil.formatFileSize(cacheSize));
         uas_website_tv.setText(CommonUtil.getSharedPreferences(this, "erp_baseurl"));
+
+
+        //UU开关的根据StepService是否开启显示状态
+        int isStep = PreferenceUtils.getInt(MyApplication.getInstance(), MainActivity.UU_STEP);
+
+        if (isServiceRunning(uustep_service_name)){
+            uu_step_reply.setChecked(true);
+            uu_step_reply.setFocusable(false);
+            uu_step_reply.setClickable(false);
+        }else {
+            uu_step_reply.setChecked(false);
+        }
+
+        uu_step_reply.setOnCheckedChangeListener(new SwitchView.OnCheckedChangeListener() {
+            @Override
+            public void onCheckedChanged(View view, boolean isChecked) {
+                if (isChecked) {
+                    PreferenceUtils.putInt(MainActivity.UU_STEP, 1);
+                    PushManager.resumeWork(MyApplication.getInstance());
+                    uu_step_reply.setFocusable(false);
+                    uu_step_reply.setClickable(false);
+                    startActivity(new Intent(mContext, MyPedometerActivity.class));
+                } else {
+                    PushManager.stopWork(MyApplication.getInstance());
+                    PreferenceUtils.putInt(MainActivity.UU_STEP, 0);
+//                    stopService(intent);
+                    Toast.makeText(mContext, "您已关闭UU运动", Toast.LENGTH_LONG).show();
+                }
+            }
+        });
+        uu_step_rl.setOnClickListener(new View.OnClickListener() {
+            @Override
+            public void onClick(View v) {
+                int last_isStep = PreferenceUtils.getInt(MyApplication.getInstance(), MainActivity.UU_STEP);
+                if (isServiceRunning(uustep_service_name) && last_isStep == 1){
+                    startActivity(new Intent(mContext, MyPedometerActivity.class));
+                }else {
+                    Toast.makeText(mContext, "尚未开启UU运动", Toast.LENGTH_SHORT).show();
+                }
+            }
+        });
     }
 
+    private boolean isServiceRunning(String servicename) { //判断某个服务是否已经运行
+        ActivityManager manager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
+        for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
+            if (servicename.equals(service.service.getClassName())) {
+                return true;
+            }
+        }
+        return false;
+    }
     private void showExitDialog() {
         new AlertDialog.Builder(mContext).setTitle(R.string.app_name).setMessage(R.string.exit_tips).setNegativeButton(R.string.cancel, null)
                 .setPositiveButton(R.string.sure, new DialogInterface.OnClickListener() {

+ 2 - 9
WeiChat/src/main/res/layout/activity_pedometer.xml

@@ -62,21 +62,14 @@
             android:layout_marginTop="100dp"
             android:text="暂未开启UU运动"
             />
-        <Button
-            android:id="@+id/open_uu_step_bt"
-            style="@style/from_button_base_bule"
-            android:layout_marginTop="5dp"
-            android:layout_marginLeft="40dp"
-            android:layout_marginRight="40dp"
-            android:text="开启UU运动"
-            android:visibility="visible"/>
         <Button
             android:id="@+id/close_uu_step_bt"
             style="@style/from_button_base_bule"
             android:layout_marginTop="5dp"
             android:layout_marginLeft="40dp"
             android:layout_marginRight="40dp"
-            android:text="关闭UU运动" />
+            android:text="关闭UU运动"
+            android:visibility="gone"/>
 
     </LinearLayout>
 </ScrollView>

+ 22 - 0
WeiChat/src/main/res/layout/activity_setting.xml

@@ -52,7 +52,29 @@
                     android:background="@drawable/oa_next"
                     android:contentDescription="@string/app_name" />
             </RelativeLayout>
+            <RelativeLayout
+                android:id="@+id/uu_step_rl"
+                style="@style/IMTbleLine1"
+                android:background="@drawable/selector_me_menu_item_bg">
 
+                <TextView
+                    android:id="@+id/uu_step_text"
+                    android:layout_width="wrap_content"
+                    android:layout_height="wrap_content"
+                    android:layout_centerVertical="true"
+                    android:gravity="center"
+                    android:text=" UU 运动"
+                    android:textColor="@color/black"
+                    android:textSize="14sp" />
+
+                <com.xzjmyk.pm.activity.ui.erp.view.SwitchView
+                    android:id="@+id/uu_step_reply"
+                    android:layout_width="40dp"
+                    android:layout_height="25dp"
+                    android:layout_alignParentRight="true"
+                    android:layout_centerVertical="true"
+                    />
+            </RelativeLayout>
             <View
                 android:layout_width="match_parent"
                 android:layout_height="@dimen/line"

+ 1 - 0
WeiChat/src/main/res/layout/fragment_me.xml

@@ -235,6 +235,7 @@
             style="@style/IMTbleLine_UP_Me"
             android:layout_marginTop="7dp"
             android:background="@drawable/selector_me_menu_item_bg"
+            android:visibility="gone"
             >
             <TextView
                 android:layout_width="wrap_content"