FANGLH 8 years ago
parent
commit
a73e154b12

+ 146 - 0
WeiChat/META-INF/JavaUtil/ChannelUtil.java

@@ -0,0 +1,146 @@
+package com.czt.util;
+
+import java.io.IOException;
+import java.util.Enumeration;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipFile;
+
+import android.content.Context;
+import android.content.SharedPreferences;
+import android.content.SharedPreferences.Editor;
+import android.content.pm.ApplicationInfo;
+import android.content.pm.PackageManager.NameNotFoundException;
+import android.preference.PreferenceManager;
+import android.text.TextUtils;
+
+public class ChannelUtil {
+	
+	private static final String CHANNEL_KEY = "cztchannel";
+	private static final String CHANNEL_VERSION_KEY = "cztchannel_version";
+	private static String mChannel;
+	/**
+	 * 返回市场。  如果获取失败返回""
+	 * @param context
+	 * @return
+	 */
+	public static String getChannel(Context context){
+		return getChannel(context, "");
+	}
+	/**
+	 * 返回市场。  如果获取失败返回defaultChannel
+	 * @param context
+	 * @param defaultChannel
+	 * @return
+	 */
+	public static String getChannel(Context context, String defaultChannel) {
+		//内存中获取
+		if(!TextUtils.isEmpty(mChannel)){
+			return mChannel;
+		}
+		//sp中获取
+		mChannel = getChannelBySharedPreferences(context);
+		if(!TextUtils.isEmpty(mChannel)){
+			return mChannel;
+		}
+		//从apk中获取
+		mChannel = getChannelFromApk(context, CHANNEL_KEY);
+		if(!TextUtils.isEmpty(mChannel)){
+			//保存sp中备用
+			saveChannelBySharedPreferences(context, mChannel);
+			return mChannel;
+		}
+		//全部获取失败
+		return defaultChannel;
+    }
+	/**
+	 * 从apk中获取版本信息
+	 * @param context
+	 * @param channelKey
+	 * @return
+	 */
+	private static String getChannelFromApk(Context context, String channelKey) {
+		//从apk包中获取
+        ApplicationInfo appinfo = context.getApplicationInfo();
+        String sourceDir = appinfo.sourceDir;
+        //默认放在meta-inf/里, 所以需要再拼接一下
+        String key = "META-INF/" + channelKey;
+        String ret = "";
+        ZipFile zipfile = null;
+        try {
+            zipfile = new ZipFile(sourceDir);
+            Enumeration<?> entries = zipfile.entries();
+            while (entries.hasMoreElements()) {
+                ZipEntry entry = ((ZipEntry) entries.nextElement());
+                String entryName = entry.getName();
+                if (entryName.startsWith(key)) {
+                    ret = entryName;
+                    break;
+                }
+            }
+        } catch (IOException e) {
+            e.printStackTrace();
+        } finally {
+            if (zipfile != null) {
+                try {
+                    zipfile.close();
+                } catch (IOException e) {
+                    e.printStackTrace();
+                }
+            }
+        }
+        String[] split = ret.split("_");
+        String channel = "";
+        if (split != null && split.length >= 2) {
+        	channel = ret.substring(split[0].length() + 1);
+        }
+        return channel;
+	}
+	/**
+	 * 本地保存channel & 对应版本号
+	 * @param context
+	 * @param channel
+	 */
+	private static void saveChannelBySharedPreferences(Context context, String channel){
+		SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
+		Editor editor = sp.edit();
+		editor.putString(CHANNEL_KEY, channel);
+		editor.putInt(CHANNEL_VERSION_KEY, getVersionCode(context));
+		editor.commit();
+	}
+	/**
+	 * 从sp中获取channel
+	 * @param context
+	 * @return 为空表示获取异常、sp中的值已经失效、sp中没有此值
+	 */
+	private static String getChannelBySharedPreferences(Context context){
+		SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
+		int currentVersionCode = getVersionCode(context);
+		if(currentVersionCode == -1){
+			//获取错误
+			return "";
+		}
+		int versionCodeSaved = sp.getInt(CHANNEL_VERSION_KEY, -1);
+		if(versionCodeSaved == -1){
+			//本地没有存储的channel对应的版本号
+			//第一次使用  或者 原先存储版本号异常
+			return "";
+		}
+		if(currentVersionCode != versionCodeSaved){
+			return "";
+		}
+		return sp.getString(CHANNEL_KEY, "");
+	}
+	/**
+	 * 从包信息中获取版本号
+	 * @param context
+	 * @return
+	 */
+	private static int getVersionCode(Context context){
+		try{
+			return context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionCode;
+		}catch(NameNotFoundException e) {
+			e.printStackTrace();
+		}
+		return -1;
+	}
+}

+ 59 - 0
WeiChat/META-INF/MultiChannelBuildTool.py

@@ -0,0 +1,59 @@
+#!/usr/bin/python
+# coding=utf-8
+import zipfile
+import shutil
+import os
+
+# 空文件 便于写入此空文件到apk包中作为channel文件
+src_empty_file = 'info/czt.txt'
+# 创建一个空文件(不存在则创建)
+f = open(src_empty_file, 'w') 
+f.close()
+
+# 获取当前目录中所有的apk源包
+src_apks = []
+# python3 : os.listdir()即可,这里使用兼容Python2的os.listdir('.')
+for file in os.listdir('.'):
+    if os.path.isfile(file):
+        extension = os.path.splitext(file)[1][1:]
+        if extension in 'apk':
+            src_apks.append(file)
+
+# 获取渠道列表
+channel_file = 'info/channel.txt'
+f = open(channel_file)
+lines = f.readlines()
+f.close()
+
+for src_apk in src_apks:
+    # file name (with extension)
+    src_apk_file_name = os.path.basename(src_apk)
+    # 分割文件名与后缀
+    temp_list = os.path.splitext(src_apk_file_name)
+    # name without extension
+    src_apk_name = temp_list[0]
+    # 后缀名,包含.   例如: ".apk "
+    src_apk_extension = temp_list[1]
+    
+    # 创建生成目录,与文件名相关
+    output_dir = 'output_' + src_apk_name + '/'
+    # 目录不存在则创建
+    if not os.path.exists(output_dir):
+        os.mkdir(output_dir)
+        
+    # 遍历渠道号并创建对应渠道号的apk文件
+    for line in lines:
+        # 获取当前渠道号,因为从渠道文件中获得带有\n,所有strip一下
+        target_channel = line.strip()
+        # 拼接对应渠道号的apk
+        target_apk = output_dir + src_apk_name + "-" + target_channel + src_apk_extension  
+        # 拷贝建立新apk
+        shutil.copy(src_apk,  target_apk)
+        # zip获取新建立的apk文件
+        zipped = zipfile.ZipFile(target_apk, 'a', zipfile.ZIP_DEFLATED)
+        # 初始化渠道信息
+        empty_channel_file = "META-INF/cztchannel_{channel}".format(channel = target_channel)
+        # 写入渠道信息
+        zipped.write(src_empty_file, empty_channel_file)
+        # 关闭zip流
+        zipped.close()

+ 21 - 0
WeiChat/META-INF/info/channel.txt

@@ -0,0 +1,21 @@
+samsungapps
+hiapk
+anzhi
+360cn
+xiaomi
+myapp
+91com
+gfan
+appchina
+nduoa
+3gcn
+mumayi
+10086com
+wostore
+189store
+lenovomm
+hicloud
+meizu
+baidu
+googleplay
+wandou

+ 0 - 0
WeiChat/META-INF/info/czt.txt


+ 12 - 0
WeiChat/src/main/java/com/xzjmyk/pm/activity/ui/erp/activity/oa/ExpenseReimbursementActivity.java

@@ -1167,6 +1167,18 @@ public class ExpenseReimbursementActivity extends BaseActivity implements View.O
     }
     private void initAddDatas() {
         if (ListUtils.isEmpty(mAddCost_list)) return;
+        if (!ListUtils.isEmpty(costFormModel_list) && ListUtils.isEmpty(selected_detailsData)){
+            for (int i = 0; i < costFormModel_list.size(); i++) {
+                selected_detailsData.add(costFormModel_list.get(i).getCost_type());
+                if (i == (costFormModel_list.size() - 1)){
+                    gAdapter.setSelected_data(selected_detailsData);
+                    gAdapter.notifyDataSetChanged();
+                }
+            }
+        }
+        gAdapter.setSelected_data(selected_detailsData);
+        gAdapter.notifyDataSetChanged();
+
         gAdapter.setmAddCostBean_list(mAddCost_list);
         gAdapter.notifyDataSetChanged();