├── libs
├── asmack.jar
├── mialab-pushlib.jar
└── android-support-v4.jar
├── ic_launcher-web.png
├── res
├── drawable
│ ├── empty.png
│ ├── loading.png
│ ├── notification.png
│ ├── logo_background.jpg
│ ├── main_icon_sel.xml
│ └── base_anim_loading.xml
├── drawable-hdpi
│ ├── icon.png
│ ├── clarend2.jpg
│ ├── icon_hot.png
│ ├── icon_new.png
│ ├── photobg.9.png
│ ├── ic_launcher.png
│ ├── living_bk.9.png
│ ├── base_drawable_horse1.png
│ ├── base_drawable_horse2.png
│ ├── base_drawable_horse3.png
│ ├── base_drawable_horse4.png
│ ├── base_drawable_horse5.png
│ ├── life_home_blue_circle.png
│ ├── life_home_white_circle.png
│ └── base_drawable_progressdialog_bg.png
├── drawable-xhdpi
│ ├── icon.png
│ └── ic_launcher.png
├── drawable-mdpi
│ ├── ic_launcher.png
│ ├── maintitle_bar.png
│ ├── main_bottombar_a.png
│ └── d_alert_dialog_icon.png
├── raw
│ └── pushclient.properties
├── drawable-xxhdpi
│ └── ic_launcher.png
├── values
│ ├── dimens.xml
│ ├── strings.xml
│ ├── styles.xml
│ └── color.xml
├── anim
│ ├── rotate.xml
│ ├── push_up_in.xml
│ └── push_up_out.xml
├── values-v11
│ └── styles.xml
├── menu
│ └── splash.xml
├── values-w820dp
│ └── dimens.xml
├── values-v14
│ └── styles.xml
└── layout
│ ├── user_info.xml
│ ├── main_gridview.xml
│ ├── base_progress_dialog.xml
│ ├── splash.xml
│ ├── grid_icon_item.xml
│ └── palm_main.xml
├── README.md
├── src
└── com
│ └── mialab
│ └── palmsuda
│ ├── tools
│ ├── ivache
│ │ ├── OnHandleCacheListener.java
│ │ ├── DiskCache.java
│ │ ├── ImageCache.java
│ │ └── ImageWorker.java
│ └── util
│ │ ├── FunctionUtil.java
│ │ └── FileUtils.java
│ ├── syncauth
│ ├── NPersoncenterAvtivity.java
│ ├── AuthenticationService.java
│ ├── PalmAccount.java
│ ├── Authenticator.java
│ └── AuthenticationUtil.java
│ ├── views
│ ├── AlwaysMarqueeTextView.java
│ ├── TitleAdItem.java
│ ├── MyHScrollView.java
│ ├── VScrollTextView.java
│ └── MyScrollView.java
│ ├── base
│ ├── MyProgressDialog.java
│ ├── CustomProgressDialog.java
│ └── BaseActivity.java
│ ├── service
│ ├── StartServiceRecevier.java
│ ├── BackService.java
│ └── ServiceManager.java
│ ├── common
│ ├── Constants.java
│ ├── Command.java
│ └── Params.java
│ ├── modules
│ ├── ModuleKey.java
│ ├── ContentItem.java
│ ├── ModuleConfigOptions.java
│ └── ModuleItem.java
│ └── main
│ ├── Splash.java
│ ├── GdvAdapter.java
│ ├── CrashHandler.java
│ ├── MainViewHelper.java
│ ├── PalmSudaApp.java
│ ├── MaintainMgr.java
│ └── PalmSudaHome.java
├── .gitignore
├── .classpath
├── project.properties
├── proguard-project.txt
├── .project
├── AndroidManifest.xml
├── assets
└── datas
│ └── 10285.txt
└── LICENSE
/libs/asmack.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kuaijibird/palmsuda/HEAD/libs/asmack.jar
--------------------------------------------------------------------------------
/ic_launcher-web.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kuaijibird/palmsuda/HEAD/ic_launcher-web.png
--------------------------------------------------------------------------------
/libs/mialab-pushlib.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kuaijibird/palmsuda/HEAD/libs/mialab-pushlib.jar
--------------------------------------------------------------------------------
/res/drawable/empty.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kuaijibird/palmsuda/HEAD/res/drawable/empty.png
--------------------------------------------------------------------------------
/res/drawable/loading.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kuaijibird/palmsuda/HEAD/res/drawable/loading.png
--------------------------------------------------------------------------------
/res/drawable-hdpi/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kuaijibird/palmsuda/HEAD/res/drawable-hdpi/icon.png
--------------------------------------------------------------------------------
/libs/android-support-v4.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kuaijibird/palmsuda/HEAD/libs/android-support-v4.jar
--------------------------------------------------------------------------------
/res/drawable-xhdpi/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kuaijibird/palmsuda/HEAD/res/drawable-xhdpi/icon.png
--------------------------------------------------------------------------------
/res/drawable/notification.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kuaijibird/palmsuda/HEAD/res/drawable/notification.png
--------------------------------------------------------------------------------
/res/drawable-hdpi/clarend2.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kuaijibird/palmsuda/HEAD/res/drawable-hdpi/clarend2.jpg
--------------------------------------------------------------------------------
/res/drawable-hdpi/icon_hot.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kuaijibird/palmsuda/HEAD/res/drawable-hdpi/icon_hot.png
--------------------------------------------------------------------------------
/res/drawable-hdpi/icon_new.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kuaijibird/palmsuda/HEAD/res/drawable-hdpi/icon_new.png
--------------------------------------------------------------------------------
/res/drawable-hdpi/photobg.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kuaijibird/palmsuda/HEAD/res/drawable-hdpi/photobg.9.png
--------------------------------------------------------------------------------
/res/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kuaijibird/palmsuda/HEAD/res/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/res/drawable-hdpi/living_bk.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kuaijibird/palmsuda/HEAD/res/drawable-hdpi/living_bk.9.png
--------------------------------------------------------------------------------
/res/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kuaijibird/palmsuda/HEAD/res/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/res/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kuaijibird/palmsuda/HEAD/res/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/res/drawable/logo_background.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kuaijibird/palmsuda/HEAD/res/drawable/logo_background.jpg
--------------------------------------------------------------------------------
/res/raw/pushclient.properties:
--------------------------------------------------------------------------------
1 | apiKey=1234567890
2 | xmppHost=10.0.2.2
3 | #xmppHost=192.168.1.108
4 | xmppPort=5222
5 |
--------------------------------------------------------------------------------
/res/drawable-mdpi/maintitle_bar.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kuaijibird/palmsuda/HEAD/res/drawable-mdpi/maintitle_bar.png
--------------------------------------------------------------------------------
/res/drawable-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kuaijibird/palmsuda/HEAD/res/drawable-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/res/drawable-mdpi/main_bottombar_a.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kuaijibird/palmsuda/HEAD/res/drawable-mdpi/main_bottombar_a.png
--------------------------------------------------------------------------------
/res/drawable-mdpi/d_alert_dialog_icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kuaijibird/palmsuda/HEAD/res/drawable-mdpi/d_alert_dialog_icon.png
--------------------------------------------------------------------------------
/res/drawable-hdpi/base_drawable_horse1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kuaijibird/palmsuda/HEAD/res/drawable-hdpi/base_drawable_horse1.png
--------------------------------------------------------------------------------
/res/drawable-hdpi/base_drawable_horse2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kuaijibird/palmsuda/HEAD/res/drawable-hdpi/base_drawable_horse2.png
--------------------------------------------------------------------------------
/res/drawable-hdpi/base_drawable_horse3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kuaijibird/palmsuda/HEAD/res/drawable-hdpi/base_drawable_horse3.png
--------------------------------------------------------------------------------
/res/drawable-hdpi/base_drawable_horse4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kuaijibird/palmsuda/HEAD/res/drawable-hdpi/base_drawable_horse4.png
--------------------------------------------------------------------------------
/res/drawable-hdpi/base_drawable_horse5.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kuaijibird/palmsuda/HEAD/res/drawable-hdpi/base_drawable_horse5.png
--------------------------------------------------------------------------------
/res/drawable-hdpi/life_home_blue_circle.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kuaijibird/palmsuda/HEAD/res/drawable-hdpi/life_home_blue_circle.png
--------------------------------------------------------------------------------
/res/drawable-hdpi/life_home_white_circle.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kuaijibird/palmsuda/HEAD/res/drawable-hdpi/life_home_white_circle.png
--------------------------------------------------------------------------------
/res/drawable-hdpi/base_drawable_progressdialog_bg.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kuaijibird/palmsuda/HEAD/res/drawable-hdpi/base_drawable_progressdialog_bg.png
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # palmsuda
2 | “掌上苏大”是一款校园客户端应用,致力于服务苏州大学的师生,它的特点是贴近校园生活,包含消息中心、跳蚤市场、勤工俭学、校园新闻、苏大周边、交通查询、时事经纬、视频教程、真题库、考研信息、自考助学、课程表、个人中心、网站导航、音乐天地、流量查询、软件管理、设置中心等若干模块,以及二维码扫描功能。
3 |
--------------------------------------------------------------------------------
/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 16dp
5 | 16dp
6 |
7 |
8 |
--------------------------------------------------------------------------------
/res/anim/rotate.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/src/com/mialab/palmsuda/tools/ivache/OnHandleCacheListener.java:
--------------------------------------------------------------------------------
1 | package com.mialab.palmsuda.tools.ivache;
2 |
3 | import android.graphics.Bitmap;
4 | import android.widget.ImageView;
5 |
6 | public interface OnHandleCacheListener {
7 |
8 | void onSetImage(final ImageView imageView, final Bitmap bitmap);
9 |
10 | void onError(final ImageView imageView);
11 |
12 | }
13 |
14 |
--------------------------------------------------------------------------------
/res/values-v11/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/res/menu/splash.xml:
--------------------------------------------------------------------------------
1 |
12 |
--------------------------------------------------------------------------------
/res/drawable/main_icon_sel.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
5 |
7 |
8 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Built application files
2 | *.apk
3 | *.ap_
4 |
5 | # Files for the Dalvik VM
6 | *.dex
7 |
8 | # Java class files
9 | *.class
10 |
11 | # Generated files
12 | bin/
13 | gen/
14 |
15 | # Gradle files
16 | .gradle/
17 | build/
18 | /*/build/
19 |
20 | # Local configuration file (sdk path, etc)
21 | local.properties
22 |
23 | # Proguard folder generated by Eclipse
24 | proguard/
25 |
26 | # Log Files
27 | *.log
28 |
--------------------------------------------------------------------------------
/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
8 | 64dp
9 |
10 |
11 |
--------------------------------------------------------------------------------
/res/values-v14/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
8 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/res/layout/user_info.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
12 |
13 |
--------------------------------------------------------------------------------
/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/res/layout/main_gridview.xml:
--------------------------------------------------------------------------------
1 |
2 |
12 |
--------------------------------------------------------------------------------
/project.properties:
--------------------------------------------------------------------------------
1 | # This file is automatically generated by Android Tools.
2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3 | #
4 | # This file must be checked in Version Control Systems.
5 | #
6 | # To customize properties used by the Ant build system edit
7 | # "ant.properties", and override values to adapt the script to your
8 | # project structure.
9 | #
10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
12 |
13 | # Project target.
14 | target=android-19
15 |
--------------------------------------------------------------------------------
/src/com/mialab/palmsuda/syncauth/NPersoncenterAvtivity.java:
--------------------------------------------------------------------------------
1 | package com.mialab.palmsuda.syncauth;
2 |
3 | import com.mialab.palmsuda.main.R;
4 |
5 | import android.accounts.AccountAuthenticatorActivity;
6 | import android.os.Bundle;
7 |
8 | public class NPersoncenterAvtivity extends AccountAuthenticatorActivity {
9 | public static final String PARAM_CONFIRMCREDENTIALS = "confirmCredentials";
10 | public static final String PARAM_AUTHTOKEN_TYPE = "authtokenType";
11 |
12 | @Override
13 | protected void onCreate(Bundle savedInstanceState) {
14 | super.onCreate(savedInstanceState);
15 | setContentView(R.layout.user_info);
16 | }
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/src/com/mialab/palmsuda/syncauth/AuthenticationService.java:
--------------------------------------------------------------------------------
1 | package com.mialab.palmsuda.syncauth;
2 |
3 | import android.app.Service;
4 | import android.content.Intent;
5 | import android.os.IBinder;
6 |
7 | public class AuthenticationService extends Service {
8 |
9 | private static final String TAG = "AuthenticationService";
10 |
11 | private Authenticator mAuthenticator;
12 |
13 | @Override
14 | public void onCreate() {
15 | mAuthenticator = new Authenticator(this);
16 | }
17 |
18 | @Override
19 | public void onDestroy() {
20 | }
21 |
22 | @Override
23 | public IBinder onBind(Intent intent) {
24 | return mAuthenticator.getIBinder();
25 | }
26 |
27 | }
28 |
--------------------------------------------------------------------------------
/src/com/mialab/palmsuda/views/AlwaysMarqueeTextView.java:
--------------------------------------------------------------------------------
1 | package com.mialab.palmsuda.views;
2 |
3 | import android.content.Context;
4 | import android.util.AttributeSet;
5 | import android.widget.TextView;
6 |
7 | public class AlwaysMarqueeTextView extends TextView {
8 |
9 | public AlwaysMarqueeTextView(Context context){
10 | super(context);
11 | }
12 |
13 | public AlwaysMarqueeTextView(Context context,AttributeSet attrs){
14 | super(context,attrs);
15 | }
16 |
17 | public AlwaysMarqueeTextView(Context context,AttributeSet attrs,int defStyle){
18 | super(context,attrs,defStyle);
19 | }
20 | @Override
21 | public boolean isFocused(){
22 | return true;
23 | }
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/res/drawable/base_anim_loading.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
8 |
11 |
14 |
17 |
20 |
21 |
--------------------------------------------------------------------------------
/proguard-project.txt:
--------------------------------------------------------------------------------
1 | # To enable ProGuard in your project, edit project.properties
2 | # to define the proguard.config property as described in that file.
3 | #
4 | # Add project specific ProGuard rules here.
5 | # By default, the flags in this file are appended to flags specified
6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt
7 | # You can edit the include path and order by changing the ProGuard
8 | # include property in project.properties.
9 | #
10 | # For more details, see
11 | # http://developer.android.com/guide/developing/tools/proguard.html
12 |
13 | # Add any project specific keep options here:
14 |
15 | # If your project uses WebView with JS, uncomment the following
16 | # and specify the fully qualified class name to the JavaScript interface
17 | # class:
18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
19 | # public *;
20 | #}
21 |
--------------------------------------------------------------------------------
/src/com/mialab/palmsuda/base/MyProgressDialog.java:
--------------------------------------------------------------------------------
1 | package com.mialab.palmsuda.base;
2 |
3 | import android.content.Context;
4 |
5 | public class MyProgressDialog {
6 | private static CustomProgressDialog customProgressDialog;
7 |
8 | public static void show(Context context, String str) {
9 | if (customProgressDialog == null||customProgressDialog.getOwnerActivity()==null
10 | ||customProgressDialog.getOwnerActivity().isFinishing()) {
11 | customProgressDialog = new CustomProgressDialog(context);
12 | }
13 | customProgressDialog.setTitle(str);
14 | if (!customProgressDialog.isShowing())
15 | customProgressDialog.show();
16 |
17 | }
18 |
19 | public static void hide() {
20 | if (customProgressDialog != null && customProgressDialog.isShowing()) {
21 | customProgressDialog.dismiss();
22 | customProgressDialog.cancel();
23 | }
24 | customProgressDialog=null;
25 | }
26 |
27 | }
28 |
--------------------------------------------------------------------------------
/src/com/mialab/palmsuda/views/TitleAdItem.java:
--------------------------------------------------------------------------------
1 | package com.mialab.palmsuda.views;
2 |
3 | public class TitleAdItem {
4 |
5 | private String id;
6 | private String param;
7 | private String url;
8 | private String msg;
9 | private String mdkey;
10 |
11 | public String getId() {
12 | return id;
13 | }
14 | public void setId(String id) {
15 | this.id = id;
16 | }
17 | public String getParam() {
18 | return param;
19 | }
20 | public void setParam(String param) {
21 | this.param = param;
22 | }
23 | public String getUrl() {
24 | return url;
25 | }
26 | public void setUrl(String url) {
27 | this.url = url;
28 | }
29 | public String getMsg() {
30 | return msg;
31 | }
32 | public void setMsg(String msg) {
33 | this.msg = msg;
34 | }
35 | public String getMdkey() {
36 | return mdkey;
37 | }
38 | public void setMdkey(String mdkey) {
39 | this.mdkey = mdkey;
40 | }
41 |
42 | }
43 |
--------------------------------------------------------------------------------
/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | palmsuda_demo3
4 |
5 |
6 |
7 |
8 |
9 | com.android.ide.eclipse.adt.ResourceManagerBuilder
10 |
11 |
12 |
13 |
14 | com.android.ide.eclipse.adt.PreCompilerBuilder
15 |
16 |
17 |
18 |
19 | org.eclipse.jdt.core.javabuilder
20 |
21 |
22 |
23 |
24 | com.android.ide.eclipse.adt.ApkBuilder
25 |
26 |
27 |
28 |
29 |
30 | com.android.ide.eclipse.adt.AndroidNature
31 | org.eclipse.jdt.core.javanature
32 |
33 |
34 |
--------------------------------------------------------------------------------
/res/anim/push_up_in.xml:
--------------------------------------------------------------------------------
1 |
2 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/res/anim/push_up_out.xml:
--------------------------------------------------------------------------------
1 |
2 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/res/layout/base_progress_dialog.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
13 |
14 |
19 |
20 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/src/com/mialab/palmsuda/base/CustomProgressDialog.java:
--------------------------------------------------------------------------------
1 | package com.mialab.palmsuda.base;
2 |
3 | import com.mialab.palmsuda.main.R;
4 |
5 | import android.app.Activity;
6 | import android.app.Dialog;
7 | import android.content.Context;
8 | import android.graphics.drawable.AnimationDrawable;
9 | import android.os.Bundle;
10 | import android.text.TextUtils;
11 | import android.widget.ImageView;
12 | import android.widget.TextView;
13 |
14 | public class CustomProgressDialog extends Dialog {
15 | private TextView tv_tips;
16 | private ImageView img;
17 | private String title;
18 | private AnimationDrawable animationDrawable;
19 |
20 | public CustomProgressDialog(Context context) {
21 | super(context, R.style.successDialog);
22 | setOwnerActivity((Activity) context);
23 | setCanceledOnTouchOutside(true);
24 | }
25 |
26 | public void setTitle(String title) {
27 | this.title = title;
28 | }
29 |
30 | @Override
31 | public void show() {
32 | super.show();
33 | animationDrawable = (AnimationDrawable) img.getDrawable();
34 | animationDrawable.start();
35 | }
36 |
37 | @Override
38 | protected void onCreate(Bundle savedInstanceState) {
39 | super.onCreate(savedInstanceState);
40 | setContentView(R.layout.base_progress_dialog);
41 | tv_tips = (TextView) findViewById(R.id.tv_dialog_text);
42 | img = (ImageView) findViewById(R.id.img_loading);
43 | if (!TextUtils.isEmpty(title)) {
44 | tv_tips.setText(title);
45 | }
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/src/com/mialab/palmsuda/service/StartServiceRecevier.java:
--------------------------------------------------------------------------------
1 | package com.mialab.palmsuda.service;
2 |
3 | import java.util.Calendar;
4 |
5 | import com.mialab.palmsuda.common.Constants;
6 |
7 | import android.content.BroadcastReceiver;
8 | import android.content.Context;
9 | import android.content.Intent;
10 | import android.util.Log;
11 |
12 | /**
13 | * @author mialab
14 | * @date 创建时间:2015-9-3 下午11:26:43
15 | *
16 | */
17 | public class StartServiceRecevier extends BroadcastReceiver {
18 | public String TAG = Constants.APP_TAG;
19 |
20 | @Override
21 | public void onReceive(Context context, Intent intent) {
22 | try {
23 | Log.d(TAG, "StartServiceRecevier:onReceive:[" + intent.getAction()
24 | + "]");
25 |
26 | // 设置Action封装到Intent对象中,启动BackService,
27 | // 由BackService根据不同的Action,做相应的处理。
28 |
29 | int hour = Calendar.getInstance().get(Calendar.HOUR_OF_DAY);
30 | if (intent.getAction().equals("start.service.receiver.action")
31 | && hour > 7 && hour < 22) {
32 | Intent it = new Intent(context, BackService.class);
33 | it.setAction("PULLDATA_WEATHER");
34 | context.startService(it);
35 | }
36 |
37 | /*
38 | * if (intent.getAction().equals("start.service.receiver.action") &&
39 | * hour > 7 && hour < 22) { Intent it = new Intent(context,
40 | * BackService.class); it.setAction("PULLDATA");
41 | * context.startService(it); }
42 | */
43 | } catch (Exception e) {
44 | }
45 |
46 | }
47 |
48 | }
49 |
--------------------------------------------------------------------------------
/src/com/mialab/palmsuda/common/Constants.java:
--------------------------------------------------------------------------------
1 | package com.mialab.palmsuda.common;
2 | /**
3 | * @author mialab
4 | * @date 创建时间:2015-8-22 下午6:04:22
5 | *
6 | */
7 | public class Constants {
8 | public static boolean TEST_MODE = false;
9 | public static boolean DEBUG_MODE =true;
10 | public static final String APP_TAG = "PalmSuda";
11 | public static final String APP_DIR = "PalmSuda";
12 | public static final String APP_CACHE = "/cache";
13 |
14 | public static final boolean MARKET_VERSION = false;
15 |
16 | public static final String ACCOUNT_TYPE = "com.mialab.palmsuda_demo3.sync";
17 |
18 | public static final String HTTP_SCHEME = "http";
19 | //public static final String HTTP_HOST = "res.51wcity.com";
20 | //public static final String HTTP_HOST = "mialab.suda.edu.cn";
21 |
22 | public static final String HTTP_HOST = "192.168.0.119:8080";
23 |
24 | public static final String HTTP_PATH = "/city-service/service";
25 | //public static final String HTTP_PATH = "/palm-service/service";
26 |
27 | public static final String HTTP_PALM_DATA_ROOT = HTTP_SCHEME + "://"
28 | + HTTP_HOST;
29 | public static final String SERVER_URL = HTTP_PALM_DATA_ROOT + HTTP_PATH;
30 |
31 | public static final String APP_UNAME = "palmsuda";
32 |
33 | public static final String SAVE_SELECT_AREA = "CityName";
34 | public static final String SAVE_AREA_ID = "CityID";
35 |
36 | public static final String SAVE_MOBILE_NUM = "mobile_number";
37 |
38 | public static final String MODULE_URL = "module_url";
39 |
40 | //public static final String HTTP_MODULE_LIST = "http://res.51wcity.com/WirelessSZ/city/100_%1$s.html";
41 |
42 | }
43 |
--------------------------------------------------------------------------------
/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 掌上苏大
5 | Hello world!
6 | Settings
7 | 正在加载数据,请稍等...
8 |
9 | 是
10 | 否
11 | 退出确认
12 | 您真的要退出 [掌上苏大] ?
13 | 升级确认
14 | 您确定要升级到最新版本 [掌上苏大] 吗?
15 | 设置
16 | 退出
17 | 正在升级....
18 | © 2014 掌上苏大 版权所有
19 | 异常
20 | SD卡无法访问,无法正常工作!
21 | 网络不可用
22 | 您的设备未连接网络。请连接到网络并重试。
23 | 您SD卡空间不足,请先清理SD卡。
24 |
25 | 关于
26 | 确定
27 | 取消
28 | 刷新
29 | 已更新到最新数据
30 | 已经是最新版本
31 | 当前版本:
32 | 友情提醒
33 | 温馨提示
34 | 新消息
35 | 不好意思,该功能只有升级后可以使用,赶紧更新试试吧!
36 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/res/layout/splash.xml:
--------------------------------------------------------------------------------
1 |
5 |
10 |
11 |
20 |
21 |
22 |
32 |
33 |
34 |
42 |
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
14 |
15 |
16 |
19 |
20 |
29 |
30 |
40 |
41 |
--------------------------------------------------------------------------------
/res/layout/grid_icon_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
12 |
13 |
17 |
18 |
24 |
25 |
26 |
34 |
35 |
36 |
37 |
38 |
46 |
47 |
--------------------------------------------------------------------------------
/src/com/mialab/palmsuda/modules/ModuleKey.java:
--------------------------------------------------------------------------------
1 | package com.mialab.palmsuda.modules;
2 |
3 | public class ModuleKey {
4 | public static final String MODULE_KEY_NOTICEMSG = "noticemsg";
5 |
6 | public static final String MODULE_KEY_WEATHER = "weather";
7 | public static final String MODULE_KEY_NEWS = "suda_news";
8 | public static final String MODULE_KEY_CURRENT = "current";
9 | public static final String MODULE_KEY_PHONE_GUARD = "phoneguard";
10 |
11 | public static final String MODULE_KEY_TRAVEL = "travel";
12 |
13 | public static final String MODULE_KEY_AROUND = "suda_around";
14 | public static final String MODULE_KEY_FLEA = "flea";
15 | public static final String MODULE_KEY_TRAFFIC = "traffic";
16 | public static final String MODULE_KEY_SEARCH = "search";
17 | public static final String MODULE_KEY_PT_JOB = "pt_job";
18 | public static final String MODULE_KEY_QR_CODE = "qr_code";
19 | public static final String MODULE_KEY_OPTIMIZE = "optimize";
20 | public static final String MODULE_KEY_NETFLOW = "netflow";
21 | public static final String MODULE_KEY_PROCESS = "process";
22 | public static final String MODULE_KEY_MYSETTING = "mysetting";
23 |
24 | public static final String MODULE_KEY_SOFTWARE_MANAGE = "software_manage";
25 | public static final String MODULE_KEY_COMMUNICATE = "communicate";
26 | public static final String MODULE_KEY_CONNECT_US = "connect_us";
27 |
28 | public static final String MODULE_KEY_HOTLINE = "hotline";
29 | public static final String NOTICEMSG_TYPE_DIALOG = "dialog";
30 | public static final String NOTICEMSG_TYPE_PERSON = "person";
31 | public static final String NOTICEMSG_TYPE_RECHARGE = "rechargecenter";
32 |
33 | public static final String MODULE_KEY_MESSAGE_CENTER = "messagecenter";
34 | public static final String MODULE_KEY_PERSONCENTER = "personalcenter";
35 | // public static final String MODULE_KEY_PERSONCENTER = "personalcenter";
36 |
37 | public static final String MODULE_KEY_APPFLOW = "appflow";
38 | public static final String MODULE_KEY_CHARGECENTER = "chargecenter";
39 | public static final String MODULE_KEY_MAINPAGE = "mainpage";
40 |
41 | public static final String MODULE_KEY_FLOWPACKET = "flowpacket";
42 | // public static final String MODULE_KEY_GAMEDOWN = "gamedown";
43 | }
44 |
--------------------------------------------------------------------------------
/src/com/mialab/palmsuda/base/BaseActivity.java:
--------------------------------------------------------------------------------
1 | package com.mialab.palmsuda.base;
2 |
3 | import android.app.Activity;
4 | import android.app.ActivityManager;
5 | import android.app.AlertDialog;
6 | import android.content.Context;
7 | import android.os.Bundle;
8 |
9 | import com.mialab.palmsuda.common.Constants;
10 | import com.mialab.palmsuda.main.PalmSudaApp;
11 | import com.mialab.palmsuda.main.R;
12 | import com.mialab.palmsuda.tools.ivache.ImageCache;
13 | import com.mialab.palmsuda.tools.ivache.ImageWorker;
14 |
15 | /**
16 | * @author mialab
17 | * @date 创建时间:2015-8-22 上午9:46:32
18 | *
19 | */
20 | public class BaseActivity extends Activity {
21 | @Override
22 | protected void onCreate(Bundle savedInstanceState) {
23 | PalmSudaApp.SCREEN_WEIDTH = getResources().getDisplayMetrics().widthPixels;
24 | PalmSudaApp.SCREEN_HEIGTH = getResources().getDisplayMetrics().heightPixels;
25 | super.onCreate(savedInstanceState);
26 | }
27 | @Override
28 | protected void onResume() {
29 | super.onResume();
30 | //MobclickAgent.onResume(this);
31 | }
32 |
33 | @Override
34 | protected void onPause() {
35 | super.onPause();
36 | //MobclickAgent.onPause(this);
37 | }
38 |
39 | public ImageWorker mImageWorker = null;
40 | public ImageWorker getImageWorker() {
41 | if (mImageWorker == null) {
42 | ImageCache.ImageCacheParams cacheParams = new ImageCache.ImageCacheParams();
43 | ImageWorker.ScreenWeith = getResources().getDisplayMetrics().widthPixels;
44 | cacheParams.memCacheSize = (1024 * 1024 * getMemoryClass(getApplicationContext())) / 4;
45 | // cacheParams.clearDiskCacheOnStart = true;
46 | mImageWorker = ImageWorker.newInstance();
47 | mImageWorker.setCommonResID(R.drawable.photobg, R.drawable.photobg);
48 | mImageWorker.addParams(Constants.APP_TAG, cacheParams);
49 | }
50 | return mImageWorker;
51 | }
52 | public int getMemoryClass(Context context) {
53 | return ((ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE)).getMemoryClass();
54 | }
55 |
56 | public void showWaitDialog(String msg) {
57 | MyProgressDialog.show(this, msg);
58 | }
59 |
60 | public void dismissDlg() {
61 | MyProgressDialog.hide();
62 | }
63 |
64 |
65 | public void showInfoDlg(String msg) {
66 | if (!this.isFinishing()) {
67 | new AlertDialog.Builder(this).setIcon(android.R.drawable.ic_dialog_info).setTitle("友情提示")
68 | .setMessage("" + msg).setPositiveButton(android.R.string.ok, null).create().show();
69 | }
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/src/com/mialab/palmsuda/tools/ivache/DiskCache.java:
--------------------------------------------------------------------------------
1 | package com.mialab.palmsuda.tools.ivache;
2 |
3 | import java.io.File;
4 |
5 | import com.mialab.palmsuda.tools.util.FileUtils;
6 | import com.mialab.palmsuda.tools.util.FunctionUtil;
7 |
8 | import android.util.Log;
9 |
10 | /**
11 | * @author mialab
12 | * @date 创建时间:2015-8-4 下午12:48:50
13 | *
14 | */
15 | public class DiskCache {
16 | public static final String DISK_CACHE_DIR = "ivcache";
17 |
18 | private final File mCacheDir;
19 |
20 | private DiskCache(File cacheDir) {
21 | mCacheDir = cacheDir;
22 | }
23 |
24 | public static DiskCache openCache() {
25 | File cacheDir = getDiskCacheDir(DISK_CACHE_DIR);
26 |
27 | if (!cacheDir.exists()) {
28 | cacheDir.mkdirs();
29 | }
30 |
31 | Log.d("hand", "cacheDir.isDirectory()的值为:" + cacheDir.isDirectory());
32 | Log.d("hand", "cacheDir.canWrite()的值为:" + cacheDir.canWrite());
33 |
34 | if (cacheDir.isDirectory() && cacheDir.canWrite()) {
35 | return new DiskCache(cacheDir);
36 | }
37 |
38 | return null;
39 | }
40 |
41 | public static File getDiskCacheDir(String uniqueName) {
42 | final String cachePath = FileUtils.getSDPath();
43 | return new File(cachePath + File.separator + uniqueName);
44 |
45 | }
46 |
47 | /**
48 | * Checks if a specific key exist in the cache.
49 | *
50 | * @param key
51 | * The unique identifier for the bitmap
52 | * @return true if found, false otherwise
53 | */
54 | public boolean containsKey(String key) {
55 | final String existingFile = createFilePath(mCacheDir, key);
56 | File file = new File(existingFile);
57 | if (file != null && file.exists()) {
58 | return true;
59 | }
60 | return false;
61 | }
62 |
63 | /**
64 | * Removes all disk cache entries from this instance cache dir
65 | */
66 | public void clearCache() {
67 | DiskCache.clearCache(mCacheDir);
68 | }
69 |
70 | private static void clearCache(File cacheDir) {
71 | final File[] files = cacheDir.listFiles();
72 | for (int i = 0; i < files.length; i++) {
73 | files[i].delete();
74 | }
75 | }
76 |
77 | public static String getFilePath(String url) {
78 | return FunctionUtil.EncoderByMd5(url) + ".cac";
79 | }
80 |
81 | public String createFilePath(File cacheDir, String key) {
82 | return cacheDir.getAbsolutePath() + File.separator + getFilePath(key);
83 |
84 | }
85 |
86 | /**
87 | * Create a constant cache file path using the current cache directory and
88 | * an image key.
89 | *
90 | * @param key
91 | * @return
92 | */
93 | public String createFilePath(String key) {
94 | return createFilePath(mCacheDir, key);
95 | }
96 |
97 | }
98 |
--------------------------------------------------------------------------------
/src/com/mialab/palmsuda/modules/ContentItem.java:
--------------------------------------------------------------------------------
1 | package com.mialab.palmsuda.modules;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | public class ContentItem {
7 | private String contentId;
8 | private String parentId;
9 | private String contentName;
10 | private int level;
11 | private int backgroundVersion;
12 | private String backgroundUrl;
13 | private List mItems;
14 | private String mobileNum;
15 | private boolean isBgUpdate;
16 |
17 | public ContentItem() {
18 | mItems = new ArrayList();
19 | }
20 |
21 | public String getContentId() {
22 | return contentId;
23 | }
24 |
25 | public void setContentId(String contentId) {
26 | this.contentId = contentId;
27 | }
28 |
29 | public String getParentId() {
30 | return parentId;
31 | }
32 |
33 | public void setParentId(String parentId) {
34 | this.parentId = parentId;
35 | }
36 |
37 | public String getContentName() {
38 | return contentName;
39 | }
40 |
41 | public void setContentName(String contentName) {
42 | this.contentName = contentName;
43 | }
44 |
45 | public int getLevel() {
46 | return level;
47 | }
48 |
49 | public void setLevel(int level) {
50 | this.level = level;
51 | }
52 |
53 | public int getBackgroundVersion() {
54 | return backgroundVersion;
55 | }
56 |
57 | public void setBackgroundVersion(int backgroundVersion) {
58 | this.backgroundVersion = backgroundVersion;
59 | }
60 |
61 | public String getBackgroundUrl() {
62 | return backgroundUrl;
63 | }
64 |
65 | public void setBackgroundUrl(String backgroundUrl) {
66 | this.backgroundUrl = backgroundUrl;
67 | }
68 |
69 | public String getMobileNum() {
70 | return mobileNum;
71 | }
72 |
73 | public void setMobileNum(String mobileNum) {
74 | this.mobileNum = mobileNum;
75 | }
76 |
77 | public List getmItems() {
78 | return mItems;
79 | }
80 |
81 | public void setmItems(List mItems) {
82 | this.mItems = mItems;
83 | }
84 |
85 | public void addModuleItem(ModuleItem mItem) {
86 | mItems.add(mItem);
87 | }
88 |
89 | public ModuleItem getModuleItemByMdKey(String moduleKey) {
90 | ModuleItem mItem = null;
91 | if (mItems != null) {
92 | for (ModuleItem item : mItems) {
93 | if (moduleKey.equals(item.getModuleKey())) {
94 | mItem = item;
95 | break;
96 | }
97 | }
98 | }
99 | return mItem;
100 | }
101 |
102 | public boolean isBgUpdate() {
103 | return isBgUpdate;
104 | }
105 |
106 | public void setBgUpdate(boolean isBgUpdate) {
107 | this.isBgUpdate = isBgUpdate;
108 | }
109 |
110 | }
111 |
--------------------------------------------------------------------------------
/src/com/mialab/palmsuda/modules/ModuleConfigOptions.java:
--------------------------------------------------------------------------------
1 | package com.mialab.palmsuda.modules;
2 |
3 | public class ModuleConfigOptions {
4 | private boolean needNetwork = true; // Bit0 1
5 | private boolean needSdCard = true; // Bit1 2
6 | private boolean needLogin = true; // Bit2 4
7 | private boolean needModuleLog = false; // Bit3 8
8 | private boolean marketVersion = false; // Bit4 16
9 | private boolean hotModule = false; // Bit5 32
10 | private boolean newModule = false; // Bit6 64
11 |
12 | public ModuleConfigOptions() {
13 | // Default constructor
14 | }
15 |
16 | /**
17 | * Construct ModuleConfigOptions with specified options
18 | *
19 | * @param value
20 | * The Module options value
21 | */
22 | public ModuleConfigOptions(long value) {
23 | setLongValue(value);
24 | }
25 |
26 | public long longValue() {
27 | long value = 0L;
28 | value = this.needNetwork ? value | 1 : value;
29 | value = this.needSdCard ? value | 1 << 1 : value;
30 | value = this.needLogin ? value | 1 << 2 : value;
31 | value = this.needModuleLog ? value | 1 << 3 : value;
32 | value = this.marketVersion ? value | 1 << 4 : value;
33 | value = this.hotModule ? value | 1 << 5 : value;
34 | value = this.newModule ? value | 1 << 6 : value;
35 |
36 | return value;
37 | }
38 |
39 | public long getLongValue() {
40 | return longValue();
41 | }
42 |
43 | public void setLongValue(long value) {
44 | this.needNetwork = (value >> 0 & 1) == 1;
45 | this.needSdCard = (value >> 1 & 1) == 1;
46 | this.needLogin = (value >> 2 & 1) == 1;
47 | this.needModuleLog = (value >> 3 & 1) == 1;
48 | this.marketVersion = (value >> 4 & 1) == 1;
49 | this.hotModule = (value >> 5 & 1) == 1;
50 | this.newModule = (value >> 6 & 1) == 1;
51 | }
52 |
53 | public boolean isNeedNetwork() {
54 | return needNetwork;
55 | }
56 |
57 | public void setNeedNetwork(boolean needNetwork) {
58 | this.needNetwork = needNetwork;
59 | }
60 |
61 | public boolean isNeedSdCard() {
62 | return needSdCard;
63 | }
64 |
65 | public void setNeedSdCard(boolean needSdCard) {
66 | this.needSdCard = needSdCard;
67 | }
68 |
69 | public boolean isNeedLogin() {
70 | return needLogin;
71 | }
72 |
73 | public boolean isMarketVersion() {
74 | return marketVersion;
75 | }
76 |
77 | public void setNeedLogin(boolean needLogin) {
78 | this.needLogin = needLogin;
79 | }
80 |
81 | public boolean isNeedModuleLog() {
82 | return needModuleLog;
83 | }
84 |
85 | public void setNeedModuleLog(boolean needModuleLog) {
86 | this.needModuleLog = needModuleLog;
87 | }
88 |
89 | public boolean isHotModule() {
90 | return hotModule;
91 | }
92 |
93 | public boolean isNewModule() {
94 | return newModule;
95 | }
96 | }
97 |
--------------------------------------------------------------------------------
/res/layout/palm_main.xml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
12 |
13 |
20 |
21 |
22 |
27 |
28 |
33 |
34 |
39 |
40 |
46 |
47 |
48 |
56 |
57 |
63 |
64 |
65 |
66 |
67 |
--------------------------------------------------------------------------------
/src/com/mialab/palmsuda/main/Splash.java:
--------------------------------------------------------------------------------
1 | package com.mialab.palmsuda.main;
2 |
3 | import com.mialab.palmsuda.main.R;
4 |
5 | import android.app.Activity;
6 | import android.content.Intent;
7 | import android.content.pm.PackageInfo;
8 | import android.content.pm.PackageManager.NameNotFoundException;
9 | import android.os.Bundle;
10 | import android.os.Handler;
11 | import android.util.Log;
12 | import android.view.Menu;
13 | import android.view.MenuItem;
14 | import android.view.Window;
15 | import android.view.WindowManager;
16 | import android.view.animation.AlphaAnimation;
17 | import android.view.animation.Animation;
18 | import android.widget.RelativeLayout;
19 | import android.widget.TextView;
20 |
21 | public class Splash extends Activity {
22 | private static final String TAG = "Splash";
23 | private RelativeLayout cover_page;
24 | public String versionName = "";
25 | private Handler handler = new Handler();
26 |
27 | @Override
28 | protected void onCreate(Bundle savedInstanceState) {
29 | super.onCreate(savedInstanceState);
30 | // 设置为无标题栏
31 | requestWindowFeature(Window.FEATURE_NO_TITLE);
32 | // 设置为全屏模式
33 | getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
34 | WindowManager.LayoutParams.FLAG_FULLSCREEN);
35 | setContentView(R.layout.splash);
36 |
37 | // 获取当前版本,并设置在启动界面的TextView
38 | this.getCurrentVersion();
39 |
40 | cover_page = (RelativeLayout) findViewById(R.id.cover_page);
41 | AlphaAnimation aa = new AlphaAnimation(0.1f, 1.0f);
42 | aa.setDuration(5000);
43 | cover_page.startAnimation(aa);
44 |
45 | Animation anim = android.view.animation.AnimationUtils.loadAnimation(
46 | this, R.anim.rotate);
47 | android.view.animation.LinearInterpolator lir = new android.view.animation.LinearInterpolator();
48 | anim.setInterpolator(lir);
49 | findViewById(R.id.progressBar1).startAnimation(anim);
50 |
51 | handler.postDelayed(new SplashHandler(), 8000);
52 | // 延迟8秒,再运行SplashHandler的run()方法
53 | }
54 |
55 | class SplashHandler implements Runnable {
56 | @Override
57 | public void run() {
58 | gotoPalmHome();
59 | }
60 | }
61 |
62 | /**
63 | * 加载主界面
64 | */
65 | private void gotoPalmHome() {
66 | Intent intent = new Intent(this, PalmSudaHome.class);
67 | startActivity(intent);
68 | finish();// 把当前的Activity从任务栈里面移除
69 | }
70 |
71 | public void getCurrentVersion() {
72 | try {
73 | PackageInfo info = this.getPackageManager().getPackageInfo(
74 | this.getPackageName(), 0);
75 | this.versionName = info.versionName;
76 | PalmSudaApp.versionName = this.versionName;
77 |
78 | Log.d(TAG, "Current version_name is " + versionName);
79 |
80 | TextView textVersion = (TextView) findViewById(R.id.textVersion);
81 | textVersion.setText(versionName);
82 |
83 | } catch (NameNotFoundException e) {
84 | e.printStackTrace();
85 | }
86 | }
87 | }
88 |
--------------------------------------------------------------------------------
/res/values/color.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | #FFFFFF
5 | #000000
6 | #ee0000
7 | #AA00003D
8 | #084356
9 | #6E6E6E
10 | #6E6E6E
11 | #6E6E6E
12 | #E0E0E0
13 | #B88B24
14 | #184655
15 | #FF9118
16 | #D8D8D8
17 | #BABABA
18 | #408080
19 | #53D0FE
20 | #F98D20
21 | #C49402
22 | #FF00FF
23 | #ffff0000
24 | #ff0000ff
25 | #ff00ff00
26 | #ffffff00
27 | #414246
28 | #C3C8CB
29 | #FF6D00
30 | #854E00
31 | #2085A4
32 | #314D7D
33 | #EFF6Fc
34 | #b6b6b6
35 | #FFFFE4CA
36 | #FFE0E0E0
37 | #6CA6CD
38 | #f2f9ff
39 | #FFFACD
40 | #EEEEEE
41 | #D3D3D3
42 | #00FFFFFF
43 | #E2C8C5
44 | #bcd1e2
45 | #EBEBEB
46 | #00000000
47 | #007cad
48 | #969696
49 | #ff4a4a4a
50 | #FFA500
51 | #ff666666
52 | #ffff0033
53 | #ff228B22
54 | #525252
55 | #525252
56 |
57 |
--------------------------------------------------------------------------------
/src/com/mialab/palmsuda/service/BackService.java:
--------------------------------------------------------------------------------
1 | package com.mialab.palmsuda.service;
2 |
3 | import java.util.Timer;
4 | import java.util.TimerTask;
5 |
6 | import android.app.Service;
7 | import android.content.Intent;
8 | import android.content.SharedPreferences;
9 | import android.os.Binder;
10 | import android.os.Handler;
11 | import android.os.IBinder;
12 | import android.text.TextUtils;
13 | import android.util.Log;
14 |
15 | import com.mialab.palmsuda.main.PalmSudaApp;
16 |
17 | /**
18 | * @author mialab
19 | * @date 创建时间:2015-8-23 上午5:49:43
20 | *
21 | */
22 | public class BackService extends Service {
23 | public String TAG = "BackService";
24 |
25 | private Timer timer;
26 |
27 | boolean ischeck = false;
28 |
29 | private Handler mHandler = new Handler();
30 | SharedPreferences spsetting;
31 |
32 | @Override
33 | public void onCreate() {
34 | Log.d(TAG, "BackService onCreate................");
35 |
36 | spsetting = PalmSudaApp.getInstance().getSettings();
37 | try {
38 | mHandler.postDelayed(new Runnable() {
39 | @Override
40 | public void run() {
41 | checkVersionChange();
42 | }
43 | }, 15000);
44 | } catch (Exception e) {
45 | }
46 | }
47 |
48 | @Override
49 | public int onStartCommand(Intent intent, int flags, int startId) {
50 | Log.d("hand", "BackService onStartCommand................");
51 | flags = START_STICKY;
52 | handleCommand(intent);
53 | return super.onStartCommand(intent, flags, startId);
54 | }
55 |
56 | private void handleCommand(Intent intent) {
57 | try {
58 | if (intent == null) {
59 | return;
60 | }
61 | String action = "" + intent.getAction();
62 | if (!TextUtils.isEmpty(action)) {
63 | // 根据intent中的不同action处理各种不同事务
64 | }
65 | } catch (Exception e) {
66 | return;
67 | }
68 | }
69 |
70 | public void checkVersionChange() {
71 | }
72 |
73 | @Override
74 | public void onDestroy() {
75 | Log.d(TAG, "BackService onDestroy................");
76 | if (timer != null) {
77 | timer.cancel();
78 | }
79 | timer = null;
80 | }
81 |
82 | public class BackServiceBinder extends Binder {
83 | public BackService getService() {
84 | return BackService.this;
85 | }
86 | }
87 |
88 | private BackServiceBinder mBinder = new BackServiceBinder();
89 |
90 | @Override
91 | public IBinder onBind(Intent intent) {
92 | Log.d(TAG, "BackService onBind................");
93 | return mBinder;
94 | }
95 |
96 | public void getNetFlow() {
97 | }
98 |
99 | public void pullWeatherDataFromCloud() {
100 | }
101 |
102 | public void pullDataFromCloud() {
103 | }
104 |
105 | private void startFloatNotice() {
106 | }
107 |
108 | private void updateFloatCircleInfo() {
109 | }
110 |
111 | class RefreshTask extends TimerTask {
112 | @Override
113 | public void run() {
114 | }
115 | }
116 | }
117 |
--------------------------------------------------------------------------------
/src/com/mialab/palmsuda/syncauth/PalmAccount.java:
--------------------------------------------------------------------------------
1 | package com.mialab.palmsuda.syncauth;
2 |
3 | import android.accounts.Account;
4 | import android.accounts.AccountManager;
5 |
6 | /**
7 | * @author mialab
8 | * @date 创建时间:2015-8-23 上午6:29:44
9 | *
10 | */
11 | public class PalmAccount {
12 | private String accountName = "";
13 | private String password = "";
14 | private String nickname = "";
15 | private String authcode = "";
16 | private String birthDate = "";
17 | private String cityName = "";
18 | private int sex = 0;//0 男,1 女
19 | private String email = "";
20 | private String mkeywords = "";
21 | public int type;
22 | private String imsi = "";
23 | private String newNum = "";
24 |
25 | public PalmAccount() {
26 |
27 | }
28 |
29 | public PalmAccount(Account account, AccountManager mAccountManager) {
30 | accountName = account.name;
31 | password = mAccountManager.getPassword(account);
32 | }
33 |
34 | public String getAccountName() {
35 | return accountName;
36 | }
37 |
38 | public void setAccountName(String accountName) {
39 | this.accountName = accountName;
40 | }
41 |
42 | public String getPassword() {
43 | return password;
44 | }
45 |
46 | public void setPassword(String password) {
47 | this.password = password;
48 | }
49 |
50 | public String getNickname() {
51 | return nickname;
52 | }
53 |
54 | public void setNickname(String nickname) {
55 | this.nickname = nickname;
56 | }
57 |
58 | public String getAuthcode() {
59 | return authcode;
60 | }
61 |
62 | public void setAuthcode(String authcode) {
63 | this.authcode = authcode;
64 | }
65 |
66 | public String getBirthDate() {
67 | return birthDate;
68 | }
69 |
70 | public void setBirthDate(String birthDate) {
71 | this.birthDate = birthDate;
72 | }
73 |
74 | public String getCityName() {
75 | return cityName;
76 | }
77 |
78 | public void setCityName(String cityName) {
79 | this.cityName = cityName;
80 | }
81 |
82 | public int getSex() {
83 | return sex;
84 | }
85 |
86 | public void setSex(int sex) {
87 | this.sex = sex;
88 | }
89 |
90 | public String getEmail() {
91 | return email;
92 | }
93 |
94 | public void setEmail(String email) {
95 | this.email = email;
96 | }
97 |
98 | public String getMkeywords() {
99 | return mkeywords;
100 | }
101 |
102 | public void setMkeywords(String mkeywords) {
103 | this.mkeywords = mkeywords;
104 | }
105 |
106 | public int getType() {
107 | return type;
108 | }
109 |
110 | public void setType(int type) {
111 | this.type = type;
112 | }
113 |
114 | public String toString() {
115 | StringBuffer sb = new StringBuffer();
116 | sb.append("\taccountName=" + accountName);
117 | return sb.toString();
118 | }
119 |
120 | public String getImsi() {
121 | return imsi;
122 | }
123 |
124 | public void setImsi(String imsi) {
125 | this.imsi = imsi;
126 | }
127 |
128 | public String getNewNum() {
129 | return newNum;
130 | }
131 |
132 | public void setNewNum(String newNum) {
133 | this.newNum = newNum;
134 | }
135 |
136 |
137 | }
138 |
--------------------------------------------------------------------------------
/src/com/mialab/palmsuda/main/GdvAdapter.java:
--------------------------------------------------------------------------------
1 | package com.mialab.palmsuda.main;
2 |
3 | import java.util.List;
4 |
5 | import android.content.Context;
6 | import android.view.LayoutInflater;
7 | import android.view.View;
8 | import android.view.ViewGroup;
9 | import android.widget.BaseAdapter;
10 | import android.widget.GridView;
11 | import android.widget.ImageView;
12 | import android.widget.ImageView.ScaleType;
13 | import android.widget.RelativeLayout;
14 | import android.widget.RelativeLayout.LayoutParams;
15 | import android.widget.TextView;
16 |
17 | import com.mialab.palmsuda.modules.ModuleItem;
18 | import com.mialab.palmsuda.tools.ivache.ImageWorker;
19 |
20 | public class GdvAdapter extends BaseAdapter {
21 |
22 | private LayoutInflater mInflater = null;
23 | private Context mContext = null;
24 | private List mThumbIds;
25 | private ImageWorker imgeWorker;
26 |
27 | public GdvAdapter(Context c, ImageWorker loader, GridView gv) {
28 | mContext = c;
29 | mInflater = LayoutInflater.from(mContext);
30 | imgeWorker = loader;
31 | }
32 |
33 | public void setData(List items) {
34 | mThumbIds = items;
35 | this.notifyDataSetChanged();
36 | }
37 |
38 | public int getCount() {
39 | return (mThumbIds != null) ? mThumbIds.size() : 0;
40 | }
41 |
42 | public ModuleItem getItem(int position) {
43 | return (mThumbIds != null) ? mThumbIds.get(position) : null;
44 | }
45 |
46 | public long getItemId(int position) {
47 | return position;
48 | }
49 |
50 | public View getView(int position, View convertView, ViewGroup parent) {
51 | ViewHolder holder = new ViewHolder();
52 | convertView = this.mInflater.inflate(R.layout.grid_icon_item, null);
53 | holder.tvItem = (TextView) convertView.findViewById(R.id.wap_item_name);
54 | holder.iView = (ImageView) convertView
55 | .findViewById(R.id.wap_item_image);
56 | holder.icView = (ImageView) convertView.findViewById(R.id.wap_ic_image);
57 |
58 | ModuleItem item = this.getItem(position);
59 | holder.tvItem.setText("" + item.getModuleName());
60 |
61 | if (item.getOptions().isHotModule()) {
62 | holder.icView.setVisibility(View.VISIBLE);
63 | holder.icView.setImageResource(R.drawable.icon_hot);
64 | } else if (item.getOptions().isNewModule()) {
65 | holder.icView.setVisibility(View.VISIBLE);
66 | holder.icView.setImageResource(R.drawable.icon_new);
67 | } else {
68 | holder.icView.setVisibility(View.GONE);
69 | holder.icView.setImageResource(0);
70 | }
71 |
72 | RelativeLayout.LayoutParams paLayoutParams = (LayoutParams) holder.iView
73 | .getLayoutParams();
74 | paLayoutParams.width = PalmSudaApp.SCREEN_WEIDTH * 3 / 16;
75 | paLayoutParams.height = paLayoutParams.width * 100 / 96;
76 | holder.iView.setLayoutParams(paLayoutParams);
77 | holder.iView.setScaleType(ScaleType.FIT_XY);
78 | imgeWorker.loadBitmap(item.getIconUrl(), holder.iView,
79 | PalmSudaApp.SCREEN_WEIDTH / 4, PalmSudaApp.SCREEN_WEIDTH / 4);
80 |
81 | GridView.LayoutParams lparams = new GridView.LayoutParams(
82 | PalmSudaApp.SCREEN_WEIDTH * 3 / 16 + 5,
83 | PalmSudaApp.SCREEN_WEIDTH / 4 + 10);
84 | convertView.setLayoutParams(lparams);
85 | return convertView;
86 | }
87 |
88 | class ViewHolder {
89 | TextView tvItem;
90 | ImageView iView;
91 | ImageView icView;
92 | }
93 | }
94 |
--------------------------------------------------------------------------------
/src/com/mialab/palmsuda/tools/util/FunctionUtil.java:
--------------------------------------------------------------------------------
1 | package com.mialab.palmsuda.tools.util;
2 |
3 | import java.security.MessageDigest;
4 | import java.security.NoSuchAlgorithmException;
5 |
6 | import com.mialab.palmsuda.common.Constants;
7 | import com.mialab.palmsuda.main.PalmSudaApp;
8 |
9 | import android.content.Context;
10 | import android.net.ConnectivityManager;
11 | import android.net.NetworkInfo;
12 | import android.text.TextUtils;
13 |
14 | /**
15 | * @author mialab
16 | * @date 创建时间:2015-8-4 下午11:35:59
17 | *
18 | */
19 | public class FunctionUtil {
20 | public static String EncoderByMd5(String str) {
21 | if (TextUtils.isEmpty(str)) {
22 | return "";
23 | }
24 | MessageDigest md5 = null;
25 | try {
26 | md5 = MessageDigest.getInstance("MD5");
27 | } catch (NoSuchAlgorithmException e) {
28 | e.printStackTrace();
29 | }
30 | md5.update(str.getBytes());
31 | String strDes = bytes2Hex(md5.digest()); // to HexString
32 | return strDes;
33 | }
34 |
35 | private static String bytes2Hex(byte[] bts) {
36 | String des = "";
37 | String tmp = null;
38 |
39 | for (int i = 0; i < bts.length; i++) {
40 | tmp = (Integer.toHexString(bts[i] & 0xFF));
41 | if (tmp.length() == 1) {
42 | des += "0";
43 | }
44 | des += tmp;
45 | }
46 | return des;
47 | }
48 |
49 | public static boolean isNetworkConnected() {
50 | ConnectivityManager cManager = (ConnectivityManager) PalmSudaApp.getInstance().getSystemService(
51 | Context.CONNECTIVITY_SERVICE);
52 |
53 | if (cManager != null) {
54 | NetworkInfo localNetworkInfo = cManager.getActiveNetworkInfo();
55 | if (localNetworkInfo != null)
56 | return localNetworkInfo.isConnectedOrConnecting();
57 | }
58 | return false;
59 | }
60 |
61 | public static String[] getUrlSchemeHostPath(String moduleUrl) {
62 | String[] retu = new String[3];
63 | if (TextUtils.isEmpty(moduleUrl)) {
64 | retu[0] = Constants.HTTP_SCHEME;
65 | retu[1] = Constants.HTTP_HOST;
66 | retu[2] = Constants.HTTP_PATH;
67 | return retu;
68 | }
69 |
70 | String[] splits = moduleUrl.split("/");
71 |
72 | retu[0] = splits[0].replace(":", "");
73 | retu[1] = splits[2];
74 | retu[2] = "";
75 | for (int i = 3; i < splits.length - 1; i++) {
76 | retu[2] += splits[i] + "/";
77 | }
78 | retu[2] += splits[splits.length - 1];
79 | return retu;
80 | }
81 |
82 | /**
83 | *
84 | * @param localVersion
85 | * String
86 | * @param serverVersion
87 | * String
88 | * @return 0 = same, -1 = local version newer than server, 1 = local version
89 | * old than server, -2 unknown
90 | */
91 | public static int checkVersion(String localVersion, String serverVersion) {
92 | try {
93 | if (TextUtils.isEmpty(localVersion) || TextUtils.isEmpty(serverVersion)) {
94 | return -2;
95 | }
96 | String[] localVs = localVersion.split("\\.");
97 | String[] serverVs = serverVersion.split("\\.");
98 |
99 | int index = Math.min(localVs.length, serverVs.length);
100 | for (int i = 0; i < index; i++) {
101 | if (getInt(localVs[i]) == getInt(serverVs[i])) {
102 | continue;
103 | } else if (getInt(localVs[i]) < getInt(serverVs[i])) {
104 | return 1;
105 | } else {
106 | return -1;
107 | }
108 | }
109 | } catch (Exception e) {
110 | return 1;
111 | }
112 | return 0;
113 | }
114 |
115 | public static int getInt(String str) {
116 | try {
117 | return Integer.parseInt(str);
118 | } catch (Exception e) {
119 | return 0;
120 | }
121 | }
122 |
123 | }
124 |
--------------------------------------------------------------------------------
/src/com/mialab/palmsuda/modules/ModuleItem.java:
--------------------------------------------------------------------------------
1 | package com.mialab.palmsuda.modules;
2 |
3 | public class ModuleItem {
4 | private int moduleId;
5 | private String moduleVersion;
6 | private String moduleName;
7 | private String moduleKey;
8 | private int options;
9 | private int iconVersion;
10 | private String iconUrl;
11 | private String moduleUrl;
12 | private int type;
13 | private int level;// 4 表示运营商
14 | private String needClientVersion;
15 | private String dispClientVersion;
16 |
17 | // private int index;
18 | // private String parameter_a;
19 | // private String parameter_b;
20 | // private String parameter_c;
21 | private String description;
22 | private boolean isIconUpdate;
23 | // private String workCityId;
24 | private int hasAd;
25 |
26 | private ModuleConfigOptions mOptions;
27 |
28 | public ModuleItem() {
29 | }
30 |
31 | public int getModuleId() {
32 | return moduleId;
33 | }
34 |
35 | public String getDispClientVersion() {
36 | return dispClientVersion;
37 | }
38 |
39 | public void setDispClientVersion(String dispClientVersion) {
40 | this.dispClientVersion = dispClientVersion;
41 | }
42 |
43 | public ModuleConfigOptions getmOptions() {
44 | return mOptions;
45 | }
46 |
47 | public void setmOptions(ModuleConfigOptions mOptions) {
48 | this.mOptions = mOptions;
49 | }
50 |
51 | public void setModuleId(int moduleId) {
52 | this.moduleId = moduleId;
53 | }
54 |
55 | public String getModuleVersion() {
56 | return moduleVersion;
57 | }
58 |
59 | public void setModuleVersion(String moduleVersion) {
60 | this.moduleVersion = moduleVersion;
61 | }
62 |
63 | public String getModuleName() {
64 | return moduleName;
65 | }
66 |
67 | public void setModuleName(String moduleName) {
68 | this.moduleName = moduleName;
69 | }
70 |
71 | public String getModuleKey() {
72 | return moduleKey;
73 | }
74 |
75 | public void setModuleKey(String moduleKey) {
76 | this.moduleKey = moduleKey;
77 | }
78 |
79 | public ModuleConfigOptions getOptions() {
80 | return mOptions;
81 | }
82 |
83 | public void setOptions(int options) {
84 | this.options = options;
85 | this.mOptions = new ModuleConfigOptions(options);
86 | }
87 |
88 | public int getIconVersion() {
89 | return iconVersion;
90 | }
91 |
92 | public void setIconVersion(int iconVersion) {
93 | this.iconVersion = iconVersion;
94 | }
95 |
96 | public String getIconUrl() {
97 | return iconUrl;
98 | }
99 |
100 | public void setIconUrl(String iconUrl) {
101 | this.iconUrl = iconUrl;
102 | }
103 |
104 | public String getModuleUrl() {
105 | return moduleUrl;
106 | }
107 |
108 | public void setModuleUrl(String moduleUrl) {
109 | this.moduleUrl = moduleUrl;
110 | }
111 |
112 | public String getNeedClientVersion() {
113 | return needClientVersion;
114 | }
115 |
116 | public void setNeedClientVersion(String needClientVersion) {
117 | this.needClientVersion = needClientVersion;
118 | }
119 |
120 | public String getDescription() {
121 | return description;
122 | }
123 |
124 | public void setDescription(String description) {
125 | this.description = description;
126 | }
127 |
128 | public int getLevel() {
129 | return level;
130 | }
131 |
132 | public void setLevel(int level) {
133 | this.level = level;
134 | }
135 |
136 | public int getType() {
137 | return type;
138 | }
139 |
140 | public void setType(int type) {
141 | this.type = type;
142 | }
143 |
144 | public boolean isIconUpdate() {
145 | return isIconUpdate;
146 | }
147 |
148 | public void setIconUpdate(boolean isIconUpdate) {
149 | this.isIconUpdate = isIconUpdate;
150 | }
151 |
152 | public int getHasAd() {
153 | return hasAd;
154 | }
155 |
156 | public void setHasAd(int hasAd) {
157 | this.hasAd = hasAd;
158 | }
159 |
160 | }
161 |
--------------------------------------------------------------------------------
/src/com/mialab/palmsuda/views/MyHScrollView.java:
--------------------------------------------------------------------------------
1 | package com.mialab.palmsuda.views;
2 |
3 | import android.content.Context;
4 | import android.graphics.Rect;
5 | import android.util.AttributeSet;
6 | import android.view.MotionEvent;
7 | import android.view.View;
8 | import android.view.ViewConfiguration;
9 | import android.view.animation.TranslateAnimation;
10 | import android.widget.HorizontalScrollView;
11 | import android.widget.Scroller;
12 |
13 | public class MyHScrollView extends HorizontalScrollView {
14 |
15 | private final static int TOUCH_STATE_REST = 0;
16 | private final static int TOUCH_STATE_SCROLLING = 1;
17 | private View inner;
18 | private Rect normal = new Rect();
19 | private int mTouchSlop;
20 | private int mTouchState = TOUCH_STATE_REST;
21 | private float mLastMotionX;
22 | private Scroller mScroller;
23 |
24 | public MyHScrollView(Context context, AttributeSet attrs) {
25 | super(context, attrs);
26 | mScroller = new Scroller(context);
27 | mTouchSlop = ViewConfiguration.get(getContext()).getScaledTouchSlop();
28 | }
29 |
30 | @Override
31 | protected void onFinishInflate() {
32 | if (getChildCount() > 0) {
33 | inner = getChildAt(0);
34 | }
35 | }
36 |
37 | @Override
38 | public void computeScroll() {
39 | mScroller.getCurrX();
40 | if (mScroller.computeScrollOffset()) {
41 | scrollTo(mScroller.getCurrX(), mScroller.getCurrY());
42 | postInvalidate();
43 | }
44 | }
45 |
46 | @Override
47 | public boolean onTouchEvent(MotionEvent event) {
48 | final int action = event.getAction();
49 | final float x = event.getX();
50 | switch (action) {
51 | case MotionEvent.ACTION_DOWN :
52 | if (!mScroller.isFinished()) {
53 | mScroller.abortAnimation();
54 | }
55 | mLastMotionX = x;
56 | break;
57 | case MotionEvent.ACTION_MOVE :
58 | int deltaX = (int) (mLastMotionX - x);
59 | mLastMotionX = x;
60 | scrollBy(deltaX, 0);
61 | if (isNeedMove()) {
62 | if (normal.isEmpty()) {
63 | normal.set(inner.getLeft(), inner.getTop(), inner.getRight(), inner.getBottom());
64 | }
65 | inner.layout(inner.getLeft() - deltaX / 2, inner.getTop(), inner.getRight() - deltaX / 2,
66 | inner.getBottom());
67 | }
68 | break;
69 | case MotionEvent.ACTION_UP :
70 | if (isNeedAnimation()) {
71 | animation();
72 | }
73 | mTouchState = TOUCH_STATE_REST;
74 | break;
75 | case MotionEvent.ACTION_CANCEL :
76 | mTouchState = TOUCH_STATE_REST;
77 | break;
78 | }
79 | return true;
80 | }
81 |
82 | @Override
83 | public boolean onInterceptTouchEvent(MotionEvent ev) {
84 | final int action = ev.getAction();
85 | if ((action == MotionEvent.ACTION_MOVE) && (mTouchState != TOUCH_STATE_REST)) {
86 | return true;
87 | }
88 | final float x = ev.getX();
89 | switch (action) {
90 | case MotionEvent.ACTION_MOVE :
91 | final int xDiff = (int) Math.abs(mLastMotionX - x);
92 | if (xDiff > mTouchSlop) {
93 | mTouchState = TOUCH_STATE_SCROLLING;
94 | }
95 | break;
96 | case MotionEvent.ACTION_DOWN :
97 | mLastMotionX = x;
98 | mTouchState = mScroller.isFinished() ? TOUCH_STATE_REST : TOUCH_STATE_SCROLLING;
99 | break;
100 | case MotionEvent.ACTION_CANCEL :
101 | case MotionEvent.ACTION_UP :
102 | mTouchState = TOUCH_STATE_REST;
103 | break;
104 | }
105 | return mTouchState != TOUCH_STATE_REST;
106 |
107 | }
108 |
109 | // 开启动画移动
110 | public void animation() {
111 | TranslateAnimation ta = new TranslateAnimation(inner.getLeft(), normal.left, 0, 0);
112 | ta.setDuration(200);
113 | inner.startAnimation(ta);
114 | inner.layout(normal.left, normal.top, normal.right, normal.bottom);
115 | normal.setEmpty();
116 | }
117 | public boolean isNeedAnimation() {
118 | return !normal.isEmpty();
119 | }
120 | public boolean isNeedMove() {
121 | int offset = inner.getMeasuredWidth() - getWidth();
122 | int scrollX = getScrollX();
123 | if (scrollX == 0 || scrollX == offset) {
124 | return true;
125 | }
126 | return false;
127 | }
128 |
129 | }
130 |
--------------------------------------------------------------------------------
/src/com/mialab/palmsuda/syncauth/Authenticator.java:
--------------------------------------------------------------------------------
1 | package com.mialab.palmsuda.syncauth;
2 |
3 | import com.mialab.palmsuda.common.Params;
4 |
5 | import android.accounts.AbstractAccountAuthenticator;
6 | import android.accounts.Account;
7 | import android.accounts.AccountAuthenticatorResponse;
8 | import android.accounts.AccountManager;
9 | import android.accounts.NetworkErrorException;
10 | import android.content.Context;
11 | import android.content.Intent;
12 | import android.os.Bundle;
13 | import android.util.Log;
14 |
15 | /**
16 | * This class is an implementation of AbstractAccountAuthenticator for
17 | * authenticating accounts in the com.openpeak.cius.sync domain.
18 | */
19 | public class Authenticator extends AbstractAccountAuthenticator {
20 |
21 | private static final String TAG = "Authenticator";
22 |
23 | private final Context mContext;
24 |
25 | public Authenticator(Context context) {
26 | super(context);
27 | mContext = context;
28 | }
29 |
30 | /**
31 | * {@inheritDoc}
32 | */
33 | @Override
34 | public Bundle addAccount(AccountAuthenticatorResponse response, String accountType, String authTokenType,
35 | String[] requiredFeatures, Bundle options) {
36 | final Intent intent = new Intent(mContext, NPersoncenterAvtivity.class);
37 | intent.putExtra(NPersoncenterAvtivity.PARAM_AUTHTOKEN_TYPE, authTokenType);
38 | intent.putExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE, response);
39 | final Bundle bundle = new Bundle();
40 | bundle.putParcelable(AccountManager.KEY_INTENT, intent);
41 | return bundle;
42 | }
43 |
44 | /**
45 | * {@inheritDoc}
46 | */
47 | @Override
48 | public Bundle confirmCredentials(AccountAuthenticatorResponse response, Account account, Bundle options) {
49 | final Intent intent = new Intent(mContext, NPersoncenterAvtivity.class);
50 | final AccountManager am = AccountManager.get(mContext);
51 | intent.putExtra(Params.PARAMS_LOGIN_ID, am.getUserData(account, Params.PARAMS_LOGIN_ID));
52 | intent.putExtra(NPersoncenterAvtivity.PARAM_CONFIRMCREDENTIALS, true);
53 | intent.putExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE, response);
54 | final Bundle bundle = new Bundle();
55 | bundle.putParcelable(AccountManager.KEY_INTENT, intent);
56 | return bundle;
57 | }
58 |
59 | /**
60 | * {@inheritDoc}
61 | */
62 | @Override
63 | public Bundle editProperties(AccountAuthenticatorResponse response, String accountType) {
64 | throw new UnsupportedOperationException();
65 | }
66 |
67 | /**
68 | * {@inheritDoc}
69 | */
70 | @Override
71 | public Bundle getAuthToken(AccountAuthenticatorResponse response, Account account, String authTokenType,
72 | Bundle loginOptions) {
73 | Log.i(TAG, "getAuthToken:");
74 |
75 | final Bundle result = new Bundle();
76 | return result;
77 | }
78 |
79 | /**
80 | * {@inheritDoc}
81 | */
82 | @Override
83 | public String getAuthTokenLabel(String authTokenType) {
84 | Log.i(TAG, "getAuthTokenLabel:");
85 |
86 | return null;
87 | }
88 |
89 | /**
90 | * {@inheritDoc}
91 | */
92 | @Override
93 | public Bundle hasFeatures(AccountAuthenticatorResponse response, Account account, String[] features) {
94 | final Bundle result = new Bundle();
95 | result.putBoolean(AccountManager.KEY_BOOLEAN_RESULT, false);
96 | return result;
97 | }
98 |
99 | /**
100 | * {@inheritDoc}
101 | */
102 | @Override
103 | public Bundle updateCredentials(AccountAuthenticatorResponse response, Account account, String authTokenType,
104 | Bundle loginOptions) {
105 | Log.i(TAG, "updateCredentials:");
106 | final Intent intent = new Intent(mContext, NPersoncenterAvtivity.class);
107 | AccountManager am = AccountManager.get(mContext);
108 | intent.putExtra(Params.PARAMS_LOGIN_ID, am.getUserData(account, Params.PARAMS_LOGIN_ID));
109 | intent.setAction("android.intent.action.VIEW");
110 | intent.putExtra("account", account);
111 | intent.putExtra(NPersoncenterAvtivity.PARAM_AUTHTOKEN_TYPE, authTokenType);
112 | intent.putExtra(NPersoncenterAvtivity.PARAM_CONFIRMCREDENTIALS, false);
113 | final Bundle bundle = new Bundle();
114 | bundle.putParcelable(AccountManager.KEY_INTENT, intent);
115 | return bundle;
116 | }
117 |
118 | }
119 |
--------------------------------------------------------------------------------
/src/com/mialab/palmsuda/views/VScrollTextView.java:
--------------------------------------------------------------------------------
1 | package com.mialab.palmsuda.views;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | import android.content.Context;
7 | import android.graphics.Color;
8 | import android.text.TextUtils.TruncateAt;
9 | import android.util.AttributeSet;
10 | import android.view.Gravity;
11 | import android.view.View;
12 | import android.view.animation.Animation;
13 | import android.widget.TextView;
14 | import android.widget.ViewFlipper;
15 |
16 | import com.mialab.palmsuda.main.R;
17 |
18 | public class VScrollTextView extends ViewFlipper {
19 | private TextView tView;
20 | private List vInfos;
21 | private int currentIndex = 0;
22 |
23 | int scrollTime = 9000;
24 | private int type = 0; // 0 横向滚动,1 竖直滚动
25 |
26 | private TextClickListener ilistener;
27 |
28 | public VScrollTextView(Context context) {
29 | super(context);
30 | init();
31 | }
32 |
33 | public VScrollTextView(Context context, AttributeSet attr) {
34 | super(context, attr);
35 | init();
36 | }
37 |
38 | private void init() {
39 | setFlipInterval(scrollTime);
40 | setInAnimation(getContext(), R.anim.push_up_in);
41 | setOutAnimation(getContext(), R.anim.push_up_out);
42 | tView = new TextView(getContext());
43 | LayoutParams params = new LayoutParams(LayoutParams.FILL_PARENT,
44 | LayoutParams.FILL_PARENT);
45 | tView.setLayoutParams(params);
46 | tView.setGravity(Gravity.CENTER);
47 | tView.setTextColor(Color.WHITE);
48 | tView.setOnClickListener(new OnClickListener() {
49 | public void onClick(View v) {
50 | if (ilistener != null) {
51 | if (vInfos != null&&vInfos.size()>0)
52 | ilistener.onTextClick(vInfos.get(currentIndex), currentIndex);
53 | }
54 | }
55 | });
56 | this.addView(tView);
57 | }
58 |
59 | public void setOnTextClickListener(TextClickListener i) {
60 | ilistener = i;
61 | }
62 |
63 | public void setTxtInfos(List infos) {
64 | if (infos != null && infos.size() > 0) {
65 | vInfos = infos;
66 | if(vInfos.size()==1){
67 | type = 0;
68 | }else {
69 | type = 1;
70 | }
71 | notifyDataSetChange();
72 | }
73 | }
74 |
75 | public void setTxtInfo(String msg) {
76 | if (msg != null) {
77 | TitleAdItem titleAdItem=new TitleAdItem();
78 | titleAdItem.setMsg(""+msg);
79 | titleAdItem.setParam("");
80 | titleAdItem.setUrl("");
81 | vInfos =new ArrayList();
82 | vInfos.add(titleAdItem);
83 | type = 0;
84 | notifyDataSetChange();
85 | }
86 | }
87 |
88 | public void notifyDataSetChange() {
89 | currentIndex = 0;
90 | if (type == 0) {
91 | setAutoStart(false);
92 | stopFlipping();
93 | clearAnimation();
94 | TitleAdItem item=vInfos.get(currentIndex);
95 | tView.setText(item.getMsg());
96 | } else if (type == 1) {
97 | tView.setText(vInfos.get(currentIndex).getMsg());
98 | Animation animation = getInAnimation();
99 | if (animation != null) {
100 | animation.setAnimationListener(new Animation.AnimationListener() {
101 | public void onAnimationStart(Animation animation) {
102 | if (currentIndex < (vInfos.size() - 1)) {
103 | currentIndex++;
104 | } else {
105 | currentIndex = 0;
106 | }
107 | tView.setText(vInfos.get(currentIndex).getMsg());
108 | }
109 |
110 | public void onAnimationRepeat(Animation animation) {
111 | }
112 |
113 | public void onAnimationEnd(Animation animation) {
114 | }
115 | });
116 | }
117 | this.startFlipping();
118 | setAutoStart(true);
119 | }
120 | tView.setSingleLine(true);
121 | tView.setFocusableInTouchMode(true);
122 | tView.setHorizontallyScrolling(true);
123 | tView.setEllipsize(TruncateAt.MARQUEE);
124 | tView.setMarqueeRepeatLimit(-1);
125 | tView.setFocusable(true);
126 | tView.requestFocus();
127 | }
128 |
129 | public void setTextSize(Context ct, float size) {
130 | tView.setTextSize(size);//DisplayUtil.getInstance((Activity) ct).sp2px(size));
131 | }
132 |
133 | public void setTextColor(int color) {
134 | tView.setTextColor(color);
135 | }
136 |
137 | public TextView getTextView() {
138 | return tView;
139 | }
140 |
141 | public void setScrollDTime(int mSec) {
142 | scrollTime = mSec;
143 | }
144 |
145 | public interface TextClickListener {
146 | public void onTextClick(TitleAdItem titem, int index);
147 | }
148 |
149 | }
150 |
--------------------------------------------------------------------------------
/src/com/mialab/palmsuda/tools/util/FileUtils.java:
--------------------------------------------------------------------------------
1 | package com.mialab.palmsuda.tools.util;
2 |
3 | import java.io.BufferedReader;
4 | import java.io.File;
5 | import java.io.FileOutputStream;
6 | import java.io.IOException;
7 | import java.io.InputStream;
8 | import java.io.InputStreamReader;
9 | import java.io.OutputStream;
10 |
11 | import com.mialab.palmsuda.common.Constants;
12 |
13 | import android.content.Context;
14 | import android.os.Environment;
15 | import android.util.Log;
16 |
17 | /**
18 | * @author mialab
19 | * @date 创建时间:2015-8-4 下午8:18:30
20 | *
21 | */
22 | public class FileUtils {
23 | private static int FILESIZE = 4 * 1024;
24 |
25 | public FileUtils() {
26 | }
27 |
28 | /**
29 | * 在SD卡上创建文件
30 | *
31 | * @param fileName
32 | * @return
33 | * @throws IOException
34 | */
35 | public static File createSDFile(String fileName) throws IOException {
36 | File file = new File(fileName);
37 | file.createNewFile();
38 | return file;
39 | }
40 |
41 | /**
42 | * 在SD卡上创建目录
43 | *
44 | * @param dirName
45 | * @return
46 | */
47 | public static File createSDDir(String dirName) {
48 | File dir = new File(dirName);
49 | dir.mkdirs();
50 | return dir;
51 | }
52 |
53 | /**
54 | * 判断SD卡上的文件夹是否存在
55 | *
56 | * @param fileName
57 | * @return
58 | */
59 | public boolean isFileExist(String fileName) {
60 | File file = new File(FileUtils.getSDPath() + fileName);
61 | return file.exists();
62 | }
63 |
64 | public boolean delExistFile(String fileName) {
65 | File file = new File(FileUtils.getSDPath() + fileName);
66 | if (file.exists()) {
67 | return file.delete();
68 | }
69 | return false;
70 | }
71 |
72 | public static boolean delFile(String fileName) {
73 | File file = new File(fileName);
74 | if (file.exists()) {
75 | return file.delete();
76 | }
77 | return false;
78 | }
79 |
80 | public static String getSDPath() {
81 | String path = "";
82 | boolean sdCardExist = Environment.getExternalStorageState().equals(
83 | android.os.Environment.MEDIA_MOUNTED); // 判断sd卡是否存在
84 | if (sdCardExist) {
85 | path = Environment.getExternalStorageDirectory().getAbsolutePath()
86 | + "/" + Constants.APP_DIR;// 获取根目录
87 | } else {
88 | path = "D:/" + Constants.APP_DIR;
89 | }
90 | FileUtils.createSDDir(path);
91 | return path;
92 | }
93 |
94 | public static File write2SDFromByte(String fileName, byte[] buffer) {
95 |
96 | File file = null;
97 | OutputStream output = null;
98 | try {
99 | File dir = (new File(fileName)).getParentFile();
100 | createSDDir(dir.getAbsolutePath());
101 | file = createSDFile(fileName);
102 | output = new FileOutputStream(file);
103 | output.write(buffer);
104 | output.flush();
105 | } catch (Exception e) {
106 | } finally {
107 | try {
108 | if (output != null) {
109 | output.close();
110 | }
111 | } catch (IOException e) {
112 |
113 | }
114 | }
115 | return file;
116 | }
117 |
118 | //用户文件是否存在
119 | public static boolean isFileExist(Context ct,String fileName) {
120 | File file = new File(ct.getFilesDir() + "/" + fileName);
121 | return file.exists();
122 | }
123 |
124 | public static String getNativeFile(Context ctx, String filename) {
125 | String src = "";
126 | if (isFileExist(ctx, filename)) {
127 | InputStream in = null;
128 | BufferedReader reader = null;
129 | try {
130 | in = ctx.openFileInput(filename);
131 | reader = new BufferedReader(new InputStreamReader(in));
132 | String line = "";
133 | StringBuffer buffer = new StringBuffer();
134 | while ((line = reader.readLine()) != null) {
135 | buffer.append(line);
136 | }
137 | src = buffer.toString();
138 | } catch (Exception e) {
139 | Log.e(Constants.APP_TAG, "getNativeFile", e);
140 | } finally {
141 | try {
142 | if (reader != null)
143 | reader.close();
144 | if (in != null)
145 | in.close();
146 | } catch (Exception e) {
147 | }
148 | }
149 | }
150 | return src;
151 | }
152 |
153 | //保存文件到 应用本地
154 | public static void saveData2Native(Context ctx,String filename, byte[] bt) {
155 | FileOutputStream fout = null;
156 | try {
157 | fout = ctx.openFileOutput(filename, 0);
158 | fout.write(bt);
159 | fout.flush();
160 | } catch (Exception e) {
161 | e.printStackTrace();
162 | } finally {
163 | try {
164 | if (fout != null) {
165 | fout.close();
166 | }
167 | } catch (IOException e) {
168 | e.printStackTrace();
169 | }
170 | }
171 | }
172 |
173 | }
174 |
--------------------------------------------------------------------------------
/src/com/mialab/palmsuda/main/CrashHandler.java:
--------------------------------------------------------------------------------
1 | package com.mialab.palmsuda.main;
2 |
3 | import java.io.File;
4 | import java.io.FileOutputStream;
5 | import java.io.PrintWriter;
6 | import java.io.StringWriter;
7 | import java.io.Writer;
8 | import java.lang.Thread.UncaughtExceptionHandler;
9 | import java.text.DateFormat;
10 | import java.text.SimpleDateFormat;
11 | import java.util.Date;
12 |
13 | import com.mialab.palmsuda.common.Constants;
14 |
15 | import android.content.Context;
16 | import android.os.Environment;
17 | import android.os.Looper;
18 | import android.text.TextUtils;
19 | import android.util.Log;
20 |
21 |
22 |
23 | /**
24 | * @author mialab
25 | * @date 创建时间:2015-9-3 下午7:53:37
26 | *
27 | */
28 | public class CrashHandler implements UncaughtExceptionHandler {
29 | public static final String TAG = Constants.APP_TAG;
30 | private Thread.UncaughtExceptionHandler mDefaultHandler;
31 | // CrashHandler实例
32 | private static CrashHandler INSTANCE = new CrashHandler();
33 |
34 | // 用于格式化日期,作为日志文件名的一部分
35 | private DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
36 |
37 | private CrashHandler() {
38 | }
39 |
40 | public static CrashHandler getInstance() {
41 | return INSTANCE;
42 | }
43 |
44 | public void init(Context context) {
45 | mDefaultHandler = Thread.getDefaultUncaughtExceptionHandler();
46 | Thread.setDefaultUncaughtExceptionHandler(this);
47 | }
48 |
49 | @Override
50 | public void uncaughtException(Thread thread, Throwable ex) {
51 | android.util.Log.e(Constants.APP_TAG, "uncaughtException", ex);
52 | try {
53 | String oldexp = PalmSudaApp.getInstance().getSaveString("EXPECTIONAPP");
54 | String exp = getExceptionStr(ex);
55 | String subExp="";
56 | if(TextUtils.isEmpty(oldexp)){
57 | oldexp="";
58 | }
59 | if(!TextUtils.isEmpty(exp)&&exp.length()>30){
60 | subExp=exp.substring(0,30);
61 | }else {
62 | subExp="";
63 | }
64 | if (oldexp.equals(subExp)) {
65 | android.os.Process.killProcess(android.os.Process.myPid());
66 | System.exit(1);
67 | } else {
68 | PalmSudaApp.getInstance().setSaveString("EXPECTIONAPP", subExp);
69 | if (!handleException(exp) && mDefaultHandler != null) {
70 | mDefaultHandler.uncaughtException(thread, ex);
71 | } else {
72 | android.os.Process.killProcess(android.os.Process.myPid());
73 | System.exit(1);
74 | }
75 | }
76 | } catch (Exception e) {
77 | android.util.Log.e(Constants.APP_TAG, "uncaughtException",e);
78 | android.os.Process.killProcess(android.os.Process.myPid());
79 | System.exit(1);
80 | }
81 | }
82 |
83 | /**
84 | * 自定义错误处理,收集错误信息 发送错误报告等操作均在此完成.
85 | *
86 | * @param ex
87 | * @return true:如果处理了该异常信息;否则返回false.
88 | */
89 | private boolean handleException(final String ex) {
90 | if (ex == null) {
91 | return false;
92 | }
93 | new Thread() {
94 | @Override
95 | public void run() {
96 | saveCrashInfo2File(ex);
97 | if (Constants.DEBUG_MODE) {
98 | Looper.prepare();
99 | PalmSudaApp.getInstance().showToast("程序遇到问题,我们将会尽快处理。");
100 | Looper.loop();
101 | }
102 | }
103 | }.start();
104 | return true;
105 | }
106 |
107 | private String getExceptionStr(Throwable ex) {
108 | StringBuffer sb = new StringBuffer();
109 | Writer writer = new StringWriter();
110 | PrintWriter printWriter = new PrintWriter(writer);
111 | ex.printStackTrace(printWriter);
112 | Throwable cause = ex.getCause();
113 | while (cause != null) {
114 | cause.printStackTrace(printWriter);
115 | cause = cause.getCause();
116 | }
117 | printWriter.close();
118 | String result = writer.toString();
119 | sb.append(result);
120 | return sb.toString();
121 | }
122 |
123 | /**
124 | * 保存错误信息到文件中
125 | *
126 | * @param ex
127 | * @return 返回文件名称
128 | */
129 | private String saveCrashInfo2File(String ex) {
130 | FileOutputStream fos = null;
131 | try {
132 | StringBuffer sb = new StringBuffer();
133 | sb.append(formatter.format(new Date())).append("\n");
134 |
135 | sb.append("" + ex).append("\n");
136 | String fileName = "WCitycrash.log";
137 | String path = Environment.getExternalStorageDirectory().getAbsolutePath() + "/" + Constants.APP_DIR + "/"
138 | + fileName;
139 | File file = new File(path);
140 | file.getParentFile().mkdirs();
141 | fos = new FileOutputStream(file, false);
142 | fos.write(sb.toString().getBytes());
143 | return path;
144 | } catch (Exception e) {
145 | Log.e(TAG, "saveCrashInfo2File...", e);
146 | } finally {
147 | try {
148 | if (fos != null) {
149 | fos.close();
150 | }
151 | } catch (Exception e) {
152 | }
153 | }
154 | return null;
155 | }
156 |
157 |
158 | }
159 |
--------------------------------------------------------------------------------
/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
10 |
11 |
16 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
33 |
34 |
37 |
38 |
42 |
43 |
44 |
45 |
46 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
--------------------------------------------------------------------------------
/src/com/mialab/palmsuda/tools/ivache/ImageCache.java:
--------------------------------------------------------------------------------
1 | package com.mialab.palmsuda.tools.ivache;
2 |
3 | import java.io.File;
4 |
5 | import android.graphics.Bitmap;
6 | import android.graphics.BitmapFactory;
7 | import android.support.v4.util.LruCache;
8 |
9 | /**
10 | * @author mialab
11 | * @date 创建时间:2015-8-4 下午12:45:10
12 | *
13 | */
14 | public enum ImageCache {
15 | INSTANCE;
16 |
17 | // 默认内存缓存大小
18 | private static final int DEFAULT_MEM_CACHE_SIZE = 1024 * 1024 * 2; // 4MB
19 |
20 | // 是否使用内存缓存
21 | private static final boolean DEFAULT_MEM_CACHE_ENABLED = true;
22 | // 是否使用SD卡缓存
23 | private static final boolean DEFAULT_DISK_CACHE_ENABLED = true;
24 | // 是否在使用缓存前清理SD卡
25 | private static final boolean DEFAULT_CLEAR_DISK_CACHE_ON_START = false;
26 |
27 | private ImageCacheParams mImageCacheParams;
28 |
29 | // sd卡
30 | private DiskCache mDiskCache;
31 |
32 | // 内存
33 | private LruCache mMemoryCache;
34 |
35 | // private HashMap maps = new HashMap();
37 |
38 | public static ImageCache createCache() {
39 | return INSTANCE;
40 | }
41 |
42 | private ImageCache() {
43 | }
44 |
45 | public void setCacheParams(ImageCacheParams cacheParams) {
46 | init(cacheParams);
47 | }
48 |
49 | private void init(ImageCacheParams cacheParams) {
50 | mImageCacheParams = cacheParams;
51 | // Set up disk cache
52 | if (cacheParams.diskCacheEnabled) {
53 | mDiskCache = DiskCache.openCache();
54 | if (mDiskCache != null && cacheParams.clearDiskCacheOnStart) {
55 | mDiskCache.clearCache();
56 | }
57 | }
58 |
59 | // Set up memory cache
60 | if (cacheParams.memoryCacheEnabled) {
61 | mMemoryCache = new LruCache(
62 | cacheParams.memCacheSize) {
63 | /**
64 | * Measure item size in bytes rather than units which is more
65 | * practical for a bitmap cache
66 | */
67 | @Override
68 | protected int sizeOf(String key, Bitmap bitmap) {
69 | return getBitmapSize(bitmap);
70 | }
71 |
72 | };
73 | }
74 |
75 | }
76 |
77 | public int getBitmapSize(Bitmap bitmap) {
78 | // if (Build.VERSION.SDK_INT >= 12) {
79 | // return bitmap.getByteCount();
80 | // }
81 | // Pre HC-MR1
82 | return bitmap.getRowBytes() * bitmap.getHeight();
83 | }
84 |
85 | /**
86 | * 将图片添加到缓存
87 | */
88 | public void addBitmapToCache(String data, Bitmap bitmap) {
89 | if (data == null || bitmap == null) {
90 | return;
91 | }
92 |
93 | // Add to memory cache
94 | if (mMemoryCache != null && mMemoryCache.get(data) == null) {
95 | mMemoryCache.put(data, bitmap);
96 | }
97 |
98 | }
99 |
100 | /**
101 | * 从 内存取得图片
102 | *
103 | * @return
104 | */
105 | public Bitmap getBitmapFromMem(String path) {
106 | if (mMemoryCache != null) {
107 | final Bitmap memBitmap = mMemoryCache.get(path);
108 | if (memBitmap != null) {
109 | return memBitmap;
110 | }
111 | }
112 | return null;
113 | }
114 |
115 | /**
116 | * 从 sd取得图片
117 | *
118 | * @return
119 | */
120 | public Bitmap getBitmapFromDiskCache(String path, int reqWidth,
121 | int reqHeight) {
122 | if (mDiskCache != null) {
123 | final File cacheFile = new File(mDiskCache.createFilePath(path));
124 | if (mDiskCache.containsKey(path)) {
125 | cacheFile.setLastModified(System.currentTimeMillis());
126 | return decodeBitmap(cacheFile, reqWidth, reqHeight);
127 | }
128 | }
129 | return null;
130 | }
131 |
132 | /**
133 | * 从 sd取得图片
134 | *
135 | * @return
136 | */
137 | public Bitmap getBitmapFromDiskCache(File file, int reqWidth, int reqHeight) {
138 | if (file != null && file.exists()) {
139 | file.setLastModified(System.currentTimeMillis());
140 | return decodeBitmap(file, reqWidth, reqHeight);
141 | }
142 | return null;
143 | }
144 |
145 | /**
146 | * 清理缓存
147 | */
148 | public void clearCaches() {
149 | if (mMemoryCache != null) {
150 | mMemoryCache.evictAll();
151 | }
152 | }
153 |
154 | public synchronized Bitmap decodeBitmap(File file, int reqWidth,
155 | int reqHeight) {
156 | return decodeBitmap(file.getAbsolutePath(), reqWidth, reqHeight);
157 | }
158 |
159 | public synchronized Bitmap decodeBitmap(String fileName, int width,
160 | int height) {
161 |
162 | // First decode with inJustDecodeBounds=true to check dimensions
163 | final BitmapFactory.Options options = new BitmapFactory.Options();
164 | options.inJustDecodeBounds = true;
165 | BitmapFactory.decodeFile(fileName, options);
166 | if (options.outWidth < 1 || options.outHeight < 1) {
167 | String fn = fileName;
168 | File ft = new File(fn);
169 | if (ft.exists()) {
170 | ft.delete();
171 | return null;
172 | }
173 | }
174 | // Calculate inSampleSize
175 | options.inSampleSize = calculateOriginal(options, width, height);
176 |
177 | // Decode bitmap with inSampleSize set
178 | options.inJustDecodeBounds = false;
179 | return BitmapFactory.decodeFile(fileName, options);
180 | }
181 |
182 | private int calculateOriginal(BitmapFactory.Options options, int reqWidth,
183 | int reqHeight) {
184 | int inSampleSize = 1;
185 | final int height = options.outHeight;
186 | final int width = options.outWidth;
187 |
188 | if (height > reqHeight || width > reqWidth) {
189 | if (width > height) {
190 | inSampleSize = Math.round((float) height / (float) reqHeight);
191 | } else {
192 | inSampleSize = Math.round((float) width / (float) reqWidth);
193 | }
194 | final float totalPixels = width * height;
195 | final float totalReqPixelsCap = reqWidth * reqHeight * 3;
196 |
197 | while (totalPixels / (inSampleSize * inSampleSize) > totalReqPixelsCap) {
198 | inSampleSize++;
199 | }
200 | }
201 | return inSampleSize;
202 | }
203 |
204 | /**
205 | * A holder class that contains cache parameters.
206 | */
207 | public static class ImageCacheParams {
208 | public boolean memoryCacheEnabled = DEFAULT_MEM_CACHE_ENABLED;
209 | public boolean diskCacheEnabled = DEFAULT_DISK_CACHE_ENABLED;
210 | public int memCacheSize = DEFAULT_MEM_CACHE_SIZE;
211 | public boolean clearDiskCacheOnStart = DEFAULT_CLEAR_DISK_CACHE_ON_START;
212 | }
213 |
214 | }
215 |
--------------------------------------------------------------------------------
/assets/datas/10285.txt:
--------------------------------------------------------------------------------
1 | {"ContentConfig":{"id":"10285","parentId":"320500","name":"苏州大学","level":"211","bgVer":"1","bgUrl":"http://192.168.0.101:8080/palmsuda/images/bk/bksz.jpg","moduleList":[{"ModuleInfo":{"id":"1501","version":"1.0","name":"校园新闻","key":"suda_news","options":"9","iconVer":"21","iconUrl":"http://192.168.0.101:8080/palmsuda/images/icons/suda_news.png","type":"0","level":"1","url":"http://192.168.0.102:8080/palm-service/service","dispClientVer":"1.0.0","needClientVer":"1.0.0","isSupportAdv":"0"}},{"ModuleInfo":{"id":"1502","version":"1.0","name":"苏大周边","key":"suda_around","options":"9","iconVer":"21","iconUrl":"http://192.168.0.101:8080/palmsuda/images/icons/suda_around.png","type":"0","level":"1","url":"http://192.168.0.101:8080/palm-service/service","dispClientVer":"1.0.0","needClientVer":"1.0.0","isSupportAdv":"0"}},{"ModuleInfo":{"id":"1503","version":"1.0","name":"跳蚤市场","key":"flea","options":"41","iconVer":"21","iconUrl":"http://192.168.0.101:8080/palmsuda/images/icons/flea_market.png","type":"0","level":"1","url":"http://192.168.0.101:8080/palm-service/service","dispClientVer":"1.0.0","needClientVer":"1.0.0","isSupportAdv":"1"}},{"ModuleInfo":{"id":"1504","version":"1.0","name":"交通查询","key":"traffic","options":"9","iconVer":"21","iconUrl":"http://192.168.0.101:8080/palmsuda/images/icons/traffic.png","type":"0","level":"1","url":"http://192.168.0.101:8080/palm-service/service","dispClientVer":"1.0.0","needClientVer":"1.0.0","isSupportAdv":"0"}},{"ModuleInfo":{"id":"1505","version":"1.0","name":"勤工俭学","key":"pt_job","options":"27","iconVer":"21","iconUrl":"http://192.168.0.101:8080/palmsuda/images/icons/pt_job.png","type":"0","level":"1","url":"http://192.168.0.101:8080/palm-service/service","dispClientVer":"1.0.0","needClientVer":"1.0.0","isSupportAdv":"0","desc":"勤工俭学模块"}},{"ModuleInfo":{"id":"1506","version":"1.0","name":"时事经纬","key":"current","options":"9","iconVer":"21","iconUrl":"http://192.168.0.101:8080/palmsuda/images/icons/current.png","type":"0","level":"1","url":"http://192.168.0.102:8080/palm-service/service","dispClientVer":"1.0.0","needClientVer":"1.0.0","isSupportAdv":"0"}},{"ModuleInfo":{"id":"1507","version":"1.0","name":"真题库","key":"old_exam","options":"41","iconVer":"21","iconUrl":"http://192.168.0.101:8080/palmsuda/images/icons/old_exam.png","type":"0","level":"1","url":"http://192.168.0.101:8080/palm-service/service","dispClientVer":"1.0.0","needClientVer":"1.0.0","isSupportAdv":"0"}},{"ModuleInfo":{"id":"1508","version":"1.0","name":"视频教程","key":"video_course","options":"9","iconVer":"21","iconUrl":"http://192.168.0.101:8080/palmsuda/images/icons/video_course.png","type":"0","level":"1","url":"http://192.168.0.101:8080/palm-service/service","dispClientVer":"1.0.0","needClientVer":"1.0.0","isSupportAdv":"0"}},{"ModuleInfo":{"id":"1509","version":"1.0","name":"考研信息","key":"qr_code","options":"77","iconVer":"21","iconUrl":"http://192.168.0.101:8080/palmsuda/images/icons/master.png","type":"0","level":"1","url":"http://192.168.0.101:8080/","dispClientVer":"1.0.0","needClientVer":"1.0.0","isSupportAdv":"0"}},{"ModuleInfo":{"id":"1510","version":"1.0","name":"自考助学","key":"self_taught","options":"9","iconVer":"21","iconUrl":"http://192.168.0.101:8080/palmsuda/images/icons/self_taught.png","type":"0","level":"1","dispClientVer":"1.0.0","needClientVer":"1.0.0","isSupportAdv":"0"}},{"ModuleInfo":{"id":"1511","version":"1.0","name":"课程表","key":"schedule","options":"9","iconVer":"21","iconUrl":"http://192.168.0.101:8080/palmsuda/images/icons/schedule.png","type":"0","level":"1","url":"http://192.168.0.101:8080/palm-service/service","dispClientVer":"1.0.0","needClientVer":"1.0.0","isSupportAdv":"0"}},{"ModuleInfo":{"id":"1512","version":"1.0","name":"扫二维码","key":"qr_code","options":"9","iconVer":"21","iconUrl":"http://192.168.0.101:8080/palmsuda/images/icons/qr_code.png","type":"0","level":"1","url":"http://192.168.0.102:8080/palm-service/service","dispClientVer":"1.0.0","needClientVer":"1.0.0","isSupportAdv":"0"}},{"ModuleInfo":{"id":"1513","version":"1.0","name":"消息中心","key":"messagecenter","options":"9","iconVer":"1","iconUrl":"http://192.168.0.101:8080/palmsuda/images/icons/messagecenter.png","type":"0","level":"1","url":"http://192.168.0.101:8080/palm-service/service","dispClientVer":"1.0.0","needClientVer":"1.0.0","isSupportAdv":"0"}},{"ModuleInfo":{"id":"1514","version":"1.0","name":"个人中心","key":"personalcenter","options":"11","iconVer":"21","iconUrl":"http://192.168.0.101:8080/palmsuda/images/icons/person_center.png","type":"0","level":"1","url":"http://192.168.0.101:8080/palm-service/service","dispClientVer":"1.0.0","needClientVer":"1.0.0","isSupportAdv":"0"}},{"ModuleInfo":{"id":"2801","version":"1.0","name":"网站导航","key":"site","options":"9","iconVer":"21","iconUrl":"http://192.168.0.101:8080/palmsuda/images/icons/site.png","type":"1","level":"4","url":"http://192.168.0.101:8080/palm-service/service","dispClientVer":"1.0.0","needClientVer":"1.0.0","isSupportAdv":"0"}},{"ModuleInfo":{"id":"2802","version":"1.0","name":"音乐天地","key":"music","options":"9","iconVer":"21","iconUrl":"http://192.168.0.101:8080/palmsuda/images/icons/music.png","type":"1","level":"4","url":"http://192.168.0.101:8080/palm-service/service","dispClientVer":"1.0.0","needClientVer":"1.0.0","isSupportAdv":"0"}},{"ModuleInfo":{"id":"4001","version":"1.0","name":"流量查询","key":"netflow","options":"9","iconVer":"21","iconUrl":"http://192.168.0.101:8080/palmsuda/images/icons/netflow.png","type":"9","level":"4","url":"http://192.168.0.101:8080/palm-service/service","dispClientVer":"1.0.0","needClientVer":"1.0.0","isSupportAdv":"0"}},{"ModuleInfo":{"id":"4002","version":"1.0","name":"设置中心","key":"mysetting","options":"9","iconVer":"21","iconUrl":"http://192.168.0.101:8080/palmsuda/images/icons/mysetting.png","type":"9","level":"4","url":"http://192.168.0.101:8080/palm-service/service","dispClientVer":"1.0.0","needClientVer":"1.0.0","isSupportAdv":"0"}},{"ModuleInfo":{"id":"4003","version":"1.0","name":"软件管理","key":"software_manage","options":"9","iconVer":"21","iconUrl":"http://192.168.0.101:8080/palmsuda/images/icons/software_manage.png","type":"9","level":"4","url":"http://192.168.0.101:8080/palm-service/service","dispClientVer":"1.0.0","needClientVer":"1.0.0","isSupportAdv":"0"}},{"ModuleInfo":{"id":"4005","version":"1.0","name":"联系我们","key":"connect_us","options":"9","iconVer":"21","iconUrl":"http://192.168.0.101:8080/palmsuda/images/icons/connect_us.png","type":"9","level":"4","url":"http://192.168.0.102:8080/","dispClientVer":"1.0.0","needClientVer":"1.0.0","isSupportAdv":"0","desc":"联系我们模块"}}]}}
2 |
3 |
--------------------------------------------------------------------------------
/src/com/mialab/palmsuda/service/ServiceManager.java:
--------------------------------------------------------------------------------
1 | package com.mialab.palmsuda.service;
2 |
3 | import java.util.Properties;
4 |
5 | import android.app.Activity;
6 | import android.content.ComponentName;
7 | import android.content.Context;
8 | import android.content.Intent;
9 | import android.content.ServiceConnection;
10 | import android.content.SharedPreferences;
11 | import android.content.SharedPreferences.Editor;
12 | import android.os.IBinder;
13 | import android.util.Log;
14 |
15 | import com.mialab.push_client.Constants;
16 | import com.mialab.push_client.LogUtil;
17 | import com.mialab.push_client.NotificationService;
18 | import com.mialab.push_client.NotificationSettingsActivity;
19 |
20 | /**
21 | * @author mialab
22 | * @date 创建时间:2015-9-3 下午9:26:35
23 | *
24 | */
25 | public final class ServiceManager {
26 | private static final String LOGTAG = LogUtil
27 | .makeLogTag(ServiceManager.class);
28 |
29 | private Context context;
30 | private SharedPreferences sharedPrefs;
31 | private Properties props;
32 | private String version = "1.0.0";
33 | private String apiKey;
34 | private String xmppHost;
35 | private String xmppPort;
36 | private String callbackActivityPackageName;
37 | private String callbackActivityClassName;
38 |
39 | public ServiceManager(Context context) {
40 | this.context = context;
41 |
42 | if (context instanceof Activity) {
43 | Log.i(LOGTAG, "Callback Activity...");
44 | Activity callbackActivity = (Activity) context;
45 | callbackActivityPackageName = callbackActivity.getPackageName();
46 | callbackActivityClassName = callbackActivity.getClass().getName();
47 | }
48 |
49 | props = loadProperties();
50 | apiKey = props.getProperty("apiKey", "");
51 | xmppHost = props.getProperty("xmppHost", "127.0.0.1");
52 | xmppPort = props.getProperty("xmppPort", "5222");
53 | Log.i(LOGTAG, "apiKey=" + apiKey);
54 | Log.i(LOGTAG, "xmppHost=" + xmppHost);
55 | Log.i(LOGTAG, "xmppPort=" + xmppPort);
56 |
57 | sharedPrefs = context.getSharedPreferences(
58 | Constants.SHARED_PREFERENCE_NAME, Context.MODE_PRIVATE);
59 | Editor editor = sharedPrefs.edit();
60 | editor.putString(Constants.API_KEY, apiKey);
61 | editor.putString(Constants.VERSION, version);
62 | editor.putString(Constants.XMPP_HOST, xmppHost);
63 | editor.putInt(Constants.XMPP_PORT, Integer.parseInt(xmppPort));
64 | editor.putString(Constants.CALLBACK_ACTIVITY_PACKAGE_NAME,
65 | callbackActivityPackageName);
66 | editor.putString(Constants.CALLBACK_ACTIVITY_CLASS_NAME,
67 | callbackActivityClassName);
68 | editor.commit();
69 | // Log.i(LOGTAG, "sharedPrefs=" + sharedPrefs.toString());
70 | }
71 |
72 | public void startService() {
73 | startNotificationService();
74 | startBackService();
75 | }
76 |
77 | public void startNotificationService(){
78 | Thread serviceThread = new Thread(new Runnable() {
79 | @Override
80 | public void run() {
81 | Intent intent = NotificationService.getIntent();
82 | context.startService(intent);
83 | }
84 | });
85 | serviceThread.start();
86 | }
87 |
88 | public void startBackService() {
89 | Log.d(LOGTAG, "startBackService.....");
90 | Intent intent = new Intent("com.mialab.palmsuda.service.BackService");
91 | context.startService(intent);
92 | context.bindService(intent, connection, Context.BIND_AUTO_CREATE);
93 | }
94 |
95 | private BackService backService;
96 | private ServiceConnection connection = new ServiceConnection() {
97 | @Override
98 | public void onServiceDisconnected(ComponentName name) {
99 | backService = null;
100 | Log.d(LOGTAG, "onServiceDisconnected...");
101 | }
102 | @Override
103 | public void onServiceConnected(ComponentName name, IBinder service) {
104 | backService = ((BackService.BackServiceBinder) (service)).getService();
105 | if (backService != null) {
106 | }
107 | Log.d(LOGTAG, "onServiceConnected...");
108 | }
109 | };
110 |
111 | public void stopService() {
112 | stopNotificationService();
113 | stopBackService();
114 | }
115 |
116 | public void stopNotificationService() {
117 | Intent intent = NotificationService.getIntent();
118 | context.stopService(intent);
119 | }
120 |
121 | public void stopBackService() {
122 | Intent intent = new Intent("com.mialab.palmsuda.service.BackService");
123 | context.stopService(intent);
124 | }
125 |
126 | // private String getMetaDataValue(String name, String def) {
127 | // String value = getMetaDataValue(name);
128 | // return (value == null) ? def : value;
129 | // }
130 | //
131 | // private String getMetaDataValue(String name) {
132 | // Object value = null;
133 | // PackageManager packageManager = context.getPackageManager();
134 | // ApplicationInfo applicationInfo;
135 | // try {
136 | // applicationInfo = packageManager.getApplicationInfo(context
137 | // .getPackageName(), 128);
138 | // if (applicationInfo != null && applicationInfo.metaData != null) {
139 | // value = applicationInfo.metaData.get(name);
140 | // }
141 | // } catch (NameNotFoundException e) {
142 | // throw new RuntimeException(
143 | // "Could not read the name in the manifest file.", e);
144 | // }
145 | // if (value == null) {
146 | // throw new RuntimeException("The name '" + name
147 | // + "' is not defined in the manifest file's meta data.");
148 | // }
149 | // return value.toString();
150 | // }
151 |
152 | private Properties loadProperties() {
153 | // InputStream in = null;
154 | // Properties props = null;
155 | // try {
156 | // in = getClass().getResourceAsStream(
157 | // "/org/androidpn/client/client.properties");
158 | // if (in != null) {
159 | // props = new Properties();
160 | // props.load(in);
161 | // } else {
162 | // Log.e(LOGTAG, "Could not find the properties file.");
163 | // }
164 | // } catch (IOException e) {
165 | // Log.e(LOGTAG, "Could not find the properties file.", e);
166 | // } finally {
167 | // if (in != null)
168 | // try {
169 | // in.close();
170 | // } catch (Throwable ignore) {
171 | // }
172 | // }
173 | // return props;
174 |
175 | Properties props = new Properties();
176 | try {
177 | int id = context.getResources().getIdentifier("pushclient", "raw",
178 | context.getPackageName());
179 | props.load(context.getResources().openRawResource(id));
180 | } catch (Exception e) {
181 | Log.e(LOGTAG, "Could not find the properties file.", e);
182 | }
183 | return props;
184 | }
185 |
186 | public void setNotificationIcon(int iconId) {
187 | Editor editor = sharedPrefs.edit();
188 | editor.putInt(Constants.NOTIFICATION_ICON, iconId);
189 | editor.commit();
190 | }
191 |
192 | public static void viewNotificationSettings(Context context) {
193 | Intent intent = new Intent().setClass(context,
194 | NotificationSettingsActivity.class);
195 | context.startActivity(intent);
196 | }
197 |
198 | }
199 |
--------------------------------------------------------------------------------
/src/com/mialab/palmsuda/syncauth/AuthenticationUtil.java:
--------------------------------------------------------------------------------
1 | package com.mialab.palmsuda.syncauth;
2 |
3 | import android.accounts.Account;
4 | import android.accounts.AccountManager;
5 | import android.content.Context;
6 | import android.os.Bundle;
7 | import android.util.Log;
8 |
9 | import com.mialab.palmsuda.common.Constants;
10 | import com.mialab.palmsuda.common.Params;
11 | import com.mialab.palmsuda.main.R;
12 |
13 | public class AuthenticationUtil {
14 |
15 | public static String TAG = "AuthenticationUtil";
16 |
17 | public static PalmAccount mAccount;
18 |
19 | public synchronized static void saveNewAccount(Context context) {
20 |
21 | if (mAccount == null) {
22 | Log.e(TAG, "saveNewAccount: mAccount is empty!");
23 | return;
24 | }
25 | AccountManager mAccountManager = AccountManager.get(context);
26 | Account[] mAccounts = mAccountManager
27 | .getAccountsByType(Constants.ACCOUNT_TYPE);
28 |
29 | Log.d("hand", "-----mAccounts.length is: " + mAccounts.length
30 | + "------------");
31 |
32 | if (mAccounts.length > 0) {
33 | Log.d(
34 | "hand",
35 | "saveNewAccount: account exist:"
36 | + mAccount.getAccountName());
37 | return;
38 | }
39 | final Account account = new Account(
40 | context.getString(R.string.app_name), Constants.ACCOUNT_TYPE);
41 | Bundle userData = new Bundle();
42 | //userData.putInt(Params.PARAMS_ACCOUNT_TYPE, mAccount.type);
43 | userData.putString(Params.PARAMS_ACCOUNT_TYPE, "" + mAccount.type);
44 |
45 | userData.putString(Params.PARAMS_LOGIN_ID, mAccount.getAccountName());
46 | userData.putString(Params.PARAMS_LOGIN_PW, mAccount.getPassword());
47 |
48 | userData.putString(Params.PARAMS_USER_NICK_NAME, mAccount.getNickname());
49 | userData.putString(Params.PARAMS_USER_BIRTHDAY, mAccount.getBirthDate());
50 | userData.putString(Params.PARAMS_USER_CITY, mAccount.getCityName());
51 | userData.putString(Params.PARAMS_USER_DESC, mAccount.getMkeywords());
52 | //userData.putInt(Params.PARAMS_USER_SEX, mAccount.getSex());
53 | userData.putString(Params.PARAMS_USER_SEX, "" + mAccount.getSex());
54 |
55 | userData.putString(Params.PARAMS_USER_EMAIL, mAccount.getEmail());
56 | userData.putString(Params.PARAMS_NEW_MOBILE_NUMBER,
57 | mAccount.getNewNum());
58 | userData.putString(Params.PARAMS_LOGIN_IMSI, mAccount.getImsi());
59 |
60 | boolean addAccountSuccess = mAccountManager.addAccountExplicitly(
61 | account, mAccount.getAccountName(), userData);
62 |
63 | Log.d("hand", "--------addAccountSuccess is: " + addAccountSuccess + "-----------");
64 | }
65 |
66 | public static Account getAccount(Context context) {
67 | AccountManager mAccountManager = AccountManager.get(context);
68 |
69 | Account[] mAccounts = mAccountManager
70 | .getAccountsByType(Constants.ACCOUNT_TYPE);
71 | if (mAccounts.length > 0) {
72 | return mAccounts[0];
73 | }
74 | return null;
75 | }
76 |
77 | public static PalmAccount getAccountData(Context context) {
78 | AccountManager mAccountManager = AccountManager.get(context);
79 |
80 | Account[] mAccounts = mAccountManager
81 | .getAccountsByType(Constants.ACCOUNT_TYPE);
82 | if (mAccounts.length > 0) {
83 | PalmAccount cityAccount = new PalmAccount();
84 | cityAccount.setAccountName(mAccountManager.getUserData(
85 | mAccounts[0], Params.PARAMS_LOGIN_ID));
86 | cityAccount.setPassword(mAccountManager.getUserData(mAccounts[0],
87 | Params.PARAMS_LOGIN_PW));
88 |
89 | cityAccount.setBirthDate(mAccountManager.getUserData(mAccounts[0],
90 | Params.PARAMS_USER_BIRTHDAY));
91 | cityAccount.setCityName(mAccountManager.getUserData(mAccounts[0],
92 | Params.PARAMS_USER_CITY));
93 | cityAccount.setEmail(mAccountManager.getUserData(mAccounts[0],
94 | Params.PARAMS_USER_EMAIL));
95 | cityAccount.setNickname(mAccountManager.getUserData(mAccounts[0],
96 | Params.PARAMS_USER_NICK_NAME));
97 | cityAccount.setMkeywords(mAccountManager.getUserData(mAccounts[0],
98 | Params.PARAMS_USER_DESC));
99 | cityAccount.setImsi(mAccountManager.getUserData(mAccounts[0],
100 | Params.PARAMS_LOGIN_IMSI));
101 | cityAccount.setNewNum(mAccountManager.getUserData(mAccounts[0],
102 | Params.PARAMS_NEW_MOBILE_NUMBER));
103 |
104 | String sex = mAccountManager.getUserData(mAccounts[0],
105 | Params.PARAMS_USER_SEX);
106 | if (sex != null) {
107 | int i = 0;
108 | if (sex.equals("0")) {
109 | i = 0;
110 | } else {
111 | i = 1;
112 | }
113 | cityAccount.setSex(i);
114 | }
115 | return cityAccount;
116 | }
117 | return null;
118 | }
119 |
120 | public static void setAccountData(PalmAccount mAccount) {
121 | AuthenticationUtil.mAccount = mAccount;
122 | }
123 |
124 | public synchronized static void saveEditAccount(Context context,
125 | Account account) {
126 | if (mAccount == null) {
127 | Log.e(TAG, "saveEditAccount: mAccount is empty!");
128 | return;
129 | }
130 | AccountManager mAccountManager = AccountManager.get(context);
131 | mAccountManager.setPassword(account, mAccount.getAccountName());
132 |
133 | mAccountManager.setUserData(account, Params.PARAMS_LOGIN_PW,
134 | mAccount.getPassword());
135 | mAccountManager.setUserData(account, Params.PARAMS_LOGIN_ID,
136 | mAccount.getAccountName());
137 | mAccountManager.setUserData(account, Params.PARAMS_LOGIN_IMSI,
138 | mAccount.getImsi());
139 | mAccountManager.setUserData(account, Params.PARAMS_USER_BIRTHDAY,
140 | mAccount.getBirthDate());
141 | mAccountManager.setUserData(account, Params.PARAMS_USER_CITY,
142 | mAccount.getCityName());
143 | mAccountManager.setUserData(account, Params.PARAMS_USER_EMAIL,
144 | mAccount.getEmail());
145 | mAccountManager.setUserData(account, Params.PARAMS_USER_NICK_NAME,
146 | mAccount.getNickname());
147 | mAccountManager.setUserData(account, Params.PARAMS_USER_DESC,
148 | mAccount.getMkeywords());
149 | mAccountManager.setUserData(account, Params.PARAMS_USER_SEX,
150 | String.valueOf(mAccount.getSex()));
151 | mAccountManager.setUserData(account, Params.PARAMS_NEW_MOBILE_NUMBER,
152 | mAccount.getNewNum());
153 |
154 | }
155 |
156 | public synchronized static void updateAccountParameter(Context context,
157 | String key, String value) {
158 | AccountManager mAccountManager = AccountManager.get(context);
159 | Account[] mAccounts = mAccountManager
160 | .getAccountsByType(Constants.ACCOUNT_TYPE);
161 |
162 | mAccountManager.setUserData(mAccounts[0], key, value);
163 | }
164 |
165 | public synchronized static void deleteAccount(Context context) {
166 | AccountManager mAccountManager = AccountManager.get(context);
167 | Account[] mAccounts = mAccountManager
168 | .getAccountsByType(Constants.ACCOUNT_TYPE);
169 | if (mAccounts != null && mAccounts.length > 0) {
170 | for (Account account2 : mAccounts) {
171 | Log.d(TAG, "account2 name=" + account2.name);
172 | mAccountManager.removeAccount(account2, null, null);
173 | }
174 | }
175 | }
176 |
177 | }
178 |
--------------------------------------------------------------------------------
/src/com/mialab/palmsuda/common/Command.java:
--------------------------------------------------------------------------------
1 | package com.mialab.palmsuda.common;
2 |
3 | import java.io.UnsupportedEncodingException;
4 | import java.net.URI;
5 | import java.net.URISyntaxException;
6 | import java.util.ArrayList;
7 | import java.util.List;
8 |
9 | import org.apache.http.NameValuePair;
10 | import org.apache.http.client.entity.UrlEncodedFormEntity;
11 | import org.apache.http.client.methods.HttpGet;
12 | import org.apache.http.client.methods.HttpPost;
13 | import org.apache.http.client.utils.URIUtils;
14 | import org.apache.http.client.utils.URLEncodedUtils;
15 | import org.apache.http.message.BasicNameValuePair;
16 | import org.apache.http.params.CoreConnectionPNames;
17 | import org.apache.http.protocol.HTTP;
18 |
19 | import com.mialab.palmsuda.common.Constants;
20 | import com.mialab.palmsuda.main.PalmSudaApp;
21 | import com.mialab.palmsuda.tools.util.FunctionUtil;
22 |
23 | import android.text.TextUtils;
24 | import android.util.Log;
25 |
26 | public class Command {
27 | public static final String PARAMS_CMD = "cmd";
28 |
29 |
30 |
31 | /*
32 | private static final String SERVER_URL = Constants.SERVER_URL;
33 |
34 | public static final String PARAMS_CMD = "cmd";
35 |
36 | // login
37 | public static final String CMD_USER_LOGIN = "user.login";
38 | // logout
39 | public static final String CMD_USER_LOGOUT = "user.logout";
40 |
41 | public static final String TOKEN = "WANGYAN-FREY-19740714";
42 |
43 | // Register sms
44 | public static final String CMD_USER_SMS_REG = "user.sms.send";
45 |
46 | public static final String CMD_USER_REGISTER = "user.reg";
47 | public static final String CMD_USER_CHANGE_PW = "user.password.change";
48 | public static final String CMD_USER_PW_RESET = "user.password.reset";
49 | public static final String CMD_USER_STATUS = "user.login.status";
50 |
51 | public static final String CMD_USER_CUMULATION = "user.used.cumulation";
52 | public static final String CMD_USER_CUMULATION2 = "flowcenter.list.item";
53 |
54 | public static final String CMD_COLLECT_REFERRER = "collect.referrer";
55 |
56 | // Common
57 | public static final String COMMON = "common.";
58 | public static final String CMD_COMMON_LIST_HOT_CITY = "common.hot.city";
59 | public static final String CMD_COMMON_LIST_CITY_BY_NAME = "common.list.city";
60 | public static final String CMD_COMMON_GET_MY_AWARD = "common.my.award";
61 | public static final String CMD_COMMON_LIST_SUPPORT_CITY = "common.support.city";
62 | public static final String CMD_COMMON_LOCATION_INFO = "common.location.info";
63 | public static final String CMD_COMMON_LIST_MY_MSG = "common.my.msg";
64 | public static final String CMD_COMMON_GET_MSG_BY_ID = "common.msg.by.id";
65 | public static final String CMD_COMMON_CRASH_LOG = "common.crash.log";
66 | public static final String CMD_COMMON_PULL_CLICK_LOG = "common.pull.click.log";
67 |
68 | // Weather
69 | public static final String WEATHER = "weather.";
70 | public static final String CMD_WEATHER_CURRENT_INFO = "weather.current.info";
71 | public static final String CMD_WEATHER_INFO = "weather.info";
72 | public static final String CMD_WEATHER_CALENDAR_MONTH = "weather.calendar.month";
73 | public static final String CMD_WEATHER_CALENDAR_DATE = "weather.calendar.date";
74 |
75 | // Collect
76 | public static final String COLLECT = "collect.";
77 | public static final String CMD_COLLECT_MOBILE_INFO = "collect.mobile.info";
78 | public static final String CMD_COLLECT_CUSTOMER_RESPONSE = "collect.customer.response";
79 | public static final String CMD_COLLECT_WEB_DOWNLOAD = "collect.web.download";
80 | public static final String CMD_COLLECT_FUNCTION_USED = "collect.function.used";
81 | public static final String CMD_COLLECT_MARKET_INSTALL = "collect.market.install";
82 |
83 | public static final String CMD_COLLECT_MOBILE_PARAMETER = "collect.mobile.parameter";
84 |
85 | // Control
86 | public static final String CONTROL = "control.";
87 | public static final String CMD_CONTROL_GET_CITY_CONFIG = "control.city.config";
88 | public static final String CMD_CONTROL_GET_MOBILE_NUMBER = "control.mobile.number";
89 | public static final String CMD_CONTROL_GET_SUPER_CONFIG = "control.super.config";
90 | public static final String CMD_CONTROL_SAVE_ACCESS_LOG = "control.accesslog.save";
91 |
92 | // Software
93 | public static final String SOFTWARE = "software.";
94 | public static final String CMD_SOFTWARE_LIST_TOP = "software.top";
95 | public static final String CMD_SOFTWARE_LIST_HOT = "software.hot";
96 | public static final String CMD_SOFTWARE_LIST_TYPE = "software.type";
97 | public static final String CMD_SOFTWARE_LIST_BY_TYPE = "software.by.type";
98 | public static final String CMD_SOFTWARE_SEARCH = "software.search";
99 |
100 | // Pull
101 | public static final String CMD_PULL_DATA_NORMAL = "pull.data.normal";
102 | public static final String CMD_PULL_DATA_WEATHER = "pull.data.weather";
103 |
104 | // Goods
105 | public static final String ALIPAY_GOODS_LIST = "alipay.goods.list";
106 | public static final String ALIPAY_GET_ORDER = "alipay.get.order";
107 | public static final String ALIPAY_GOODS_LIST_WITH_TYPE = "alipay.goods.with.sub.type.list";
108 | public static final String ALIPAY_ORDER_LIST = "alipay.order.list";
109 | public static final String ALIPAY_ORDER_DETAIL = "alipay.order.detail";
110 | public static final String ALIPAY_ORDER_DELETE = "alipay.order.delete";
111 |
112 | public static final String CMD_BIND_MOBILE = "control.bind.mobile";
113 |
114 | public static final String CMD_USER_TITLE_INTEGRAL = "user.title.integral";
115 | public static final String CMD_CONTROL_MOBILE_INFO = "control.mobile.info";
116 | public static final String CMD_CONTROL_MODULES_ADVERT = "control.city.modules.advert";
117 |
118 | // Account
119 | public static final String ACCOUNT = "account.";
120 | public static final String CMD_ACCOUNT_LIVING_LIST = "account.living.list";
121 | public static final String CMD_ACCOUNT_LIVING_DEL = "account.living.del";
122 | public static final String CMD_ACCOUNT_LIVING_BIND = "account.living.bind";
123 | public static final String CMD_ACCOUNT_BIND = "account.bind";
124 |
125 | public static final String CMD_USER_EXT_INFO = "user.ext.info";
126 | public static final String CMD_USER_NUM_UPDATE = "user.mobilenum.update";
127 |
128 | // Travel
129 | public static final String CMD_TRAVEL_LIST_LINE = "travel.line";
130 | public static final String CMD_TRAVEL_LINE_DETAIL = "travel.line.detail";
131 | public static final String CMD_TRAVEL_BOOK_LINE = "travel.book.line";
132 | public static final String CMD_TRAVEL_RECOMMAND_LINE = "travel.recommand.line";
133 | public static final String CMD_TRAVEL_RECOMMAND_AGENCY = "travel.recommand.agency";
134 | public static final String CMD_TRAVEL_LIST_TYPE = "travel.type";
135 | public static final String CMD_TRAVEL_ADVERT = "travel.advert";
136 | public static final String CMD_TRAVEL_CALL_LOG = "travel.call.log";
137 |
138 | public static final String CMD_CALL_LOAG_ADD = "activity.call.log.add";
139 |
140 |
141 | public static String getCommandT1(String para) {
142 | if (para == null) {
143 | return null;
144 | }
145 | return FunctionUtil.EncoderByMd5(TOKEN + para);
146 | }
147 | */
148 |
149 | }
150 |
--------------------------------------------------------------------------------
/src/com/mialab/palmsuda/common/Params.java:
--------------------------------------------------------------------------------
1 | package com.mialab.palmsuda.common;
2 |
3 | public class Params {
4 | public static final String PARAMS_ACCOUNT_ID = "accountid";
5 | public static final String PARAMS_ACCOUNT_TYPE = "accounttype";
6 | public static final String PARAMS_LOGIN_ID = "loginid";
7 | public static final String PARAMS_LOGIN_PW = "loginpw";
8 | public static final String PARAMS_LOGIN_IMSI = "loginimsi";
9 | public static final String PARAMS_USER_NAME = "username";
10 | public static final String PARAMS_USER_PWD = "password";
11 | //public static final String PARAMS_USER_PWD_NEW = "newpassword";
12 | //public static final String PARAMS_USER_REG_CODE = "regcode";
13 | public static final String PARAMS_USER_NICK_NAME = "nickname";
14 | //public static final String PARAMS_USER_ADDRESS = "address";
15 | public static final String PARAMS_USER_BIRTHDAY = "birthday";
16 | public static final String PARAMS_USER_EMAIL = "email";
17 | public static final String PARAMS_USER_CITY = "city";
18 | public static final String PARAMS_USER_DESC = "desc";
19 | public static final String PARAMS_USER_SEX = "sex";
20 | public static final String PARAMS_NEW_MOBILE_NUMBER = "newmobilenum";
21 | public static final String PARAMS_MOBILE_TOKEN = "token";
22 |
23 | /*
24 | // Login
25 | public static final String PARAMS_LOGIN_ID = "loginid";
26 | public static final String PARAMS_LOGIN_PW = "loginpw";
27 | public static final String PARAMS_LOGIN_IMSI = "loginimsi";
28 | public static final String PARAMS_DISPLAY_NAME = "displauname";
29 | public static final String PARAMS_LOGIN_TOKEN = "logintoken";
30 | public static final String PARAMS_LOGIN_ISSAVE = "loginsavepw";
31 | public static final String PARAM_SAVE_LOGIN = "saveaccount";
32 | public static final String PARAMS_SMS_SEND_ID = "sendid";
33 | public static final String PARAMS_SMS_SEND_MESSAGE = "message";
34 | public static final String PARAMS_USER_NAME = "username";
35 | public static final String PARAMS_USER_PWD = "password";
36 | public static final String PARAMS_USER_PWD_NEW = "newpassword";
37 | public static final String PARAMS_USER_REG_CODE = "regcode";
38 | public static final String PARAMS_USER_NICK_NAME = "nickname";
39 | public static final String PARAMS_USER_ADDRESS = "address";
40 | public static final String PARAMS_USER_BIRTHDAY = "birthday";
41 | public static final String PARAMS_USER_EMAIL = "email";
42 | public static final String PARAMS_USER_CITY = "city";
43 | public static final String PARAMS_USER_DESC = "desc";
44 | public static final String PARAMS_USER_SEX = "sex";
45 | public static final String PARAMS_USER_NEWPWD = "newpassword";
46 |
47 | public static final String PARAMS_REFERRER = "referrer";
48 |
49 | // Account
50 | public static final String PARAMS_ACCOUNT_ID = "accountid";
51 | public static final String PARAMS_ACCOUNT_NAME = "username";
52 | public static final String PARAMS_ACCOUNT_IDCARD = "idcard";
53 | public static final String PARAMS_ACCOUNT_AREA = "area";
54 | public static final String PARAMS_ACCOUNT_PASSWD = "passwd";
55 | public static final String PARAMS_ACCOUNT_TYPE = "accounttype";
56 | public static final String PARAMS_ACCOUNT_SUB_TYPE = "accountsubtype";
57 | public static final String PARAM_ACCOUNT_PASSWORD = "password";
58 |
59 | public static final String PARAM_ACCOUNT_OPTIONS = "account_options";
60 | public static final String PARAM_ACCOUNT_PULL_START = "pullStartHour";
61 | public static final String PARAM_ACCOUNT_PULL_END = "pullEndHour";
62 |
63 | // Common
64 | public static final String PARAMS_PAGE_NUM = "page";
65 | public static final String PARAMS_PAGE_SIZE = "size";
66 | public static final String PARAMS_SEARCH_TYPE = "type";
67 | public static final String PARAMS_SEARCH_SRC = "src";
68 | public static final String PARAMS_SEARCH_KEY = "searchkey";
69 | public static final String PARAMS_SEARCH_SIFT = "sift";
70 | public static final String PARAMS_CITY = "city";
71 | public static final String PARAMS_MOBILE_TOKEN = "token";
72 | public static final String PARAMS_PRODUCT_ID = "productid";
73 | public static final String PARAMS_CITY_ID = "cityid";
74 | public static final String PARAMS_WORK_CITY_ID = "workcityid";
75 | public static final String PARAMS_CITY_ADDRESS = "cityaddress";
76 | public static final String PARAMS_TICKET = "ticket";
77 | public static final String PARAMS_CHECK_UPDATE = "checkupdate";
78 | public static final String PARAMS_LANGUAGE = "language";
79 | public static final String PARAMS_3G_TYPE = "3gtype";
80 | public static final String PARAMS_MODULE_KEY = "modulekey";
81 | public static final String PARAMS_LOCATION_INFO = "locationinfo";
82 | public static final String PARAMS_TODAY = "today";
83 | public static final String PARAMS_SWITCH = "switch";
84 | public static final String PARAMS_CDMA_LOCATION = "cdmaloc";
85 | public static final String PARAMS_PULL_CLICK_TYPE = "pullclicktype";// 1=open,
86 | // 2=close
87 | public static final String PARAMS_T1 = "t1";
88 |
89 | // Pull
90 | public static final String PARAMS_BELONE_CITY = "belonecity";
91 | public static final String PARAMS_BELONE_GROUPS = "belonegroups";
92 | public static final String PARAMS_BELONE_LEVEL = "belonelevel";
93 | public static final String PARAMS_PULL_OPTIONS = "pulloptions";
94 | public static final String PARAMS_RECEIVED_MSGS = "receivedmsgs";
95 |
96 | // Mobile
97 | public static final String PARAMS_NEW_MOBILE_NUMBER = "newmobilenum";
98 | public static final String PARAMS_MOBILE_NUMBER = "mobilenum";
99 | public static final String PARAMS_MOBILE_DEVICEID = "deviceid";
100 | public static final String PARAMS_MOBILE_MODEL = "model";
101 | public static final String PARAMS_MOBILE_SDK = "sdk";
102 | public static final String PARAMS_VERSION_NAME = "version";
103 | public static final String PARAMS_IP = "ip";
104 | public static final String PARAMS_IMSI = "imsi";
105 | public static final String PARAMS_CUSTOMER_RESPONSE = "customresponse";
106 | public static final String PARAMS_CUSTOMER_CONTACTS = "customcontacts";
107 | public static final String PARAMS_USE_FUNCTIONS = "usefunctions";
108 | public static final String PARAMS_INSTALL_APPS = "installapps";
109 |
110 | public static final String PARAMS_APP_UPDATE = "appupdate";
111 |
112 | // weather
113 | public static final String PARAMS_CITY_WEATHER_ID = "weatherid";
114 |
115 | public static final String PARAMS_MOBILE_PARAMETERS = "parameters";
116 |
117 | // Travel
118 | public static final String PARAMS_PRICE = "price";
119 | public static final String PARAMS_DAYS = "days";
120 | public static final String PARAMS_PLACE = "place";
121 | public static final String PARAMS_LINE_ID = "lineid";
122 | public static final String PARAMS_LINE_TYPE = "type";
123 | public static final String PARAMS_USER_ID = "userid";
124 | public static final String PARAMS_BOOKER_NAME = "bookername";
125 | public static final String PARAMS_BOOKER_PHONE = "bookerphone";
126 | public static final String PARAMS_BOOKER_NUMBER = "bookernum";
127 | public static final String PARAMS_BOOK_DESC = "bookdesc";
128 | public static final String PARAMS_LINE_NAME = "linename";
129 | public static final String PARAMS_AGENCY_ID = "agencyid";
130 | public static final String PARAMS_AGENCY_NAME = "agencyname";
131 | public static final String PARAMS_AGENCY_DEPT = "agencydept";
132 | public static final String PARAMS_CALL_PHONE = "phone";
133 | */
134 |
135 | }
136 |
--------------------------------------------------------------------------------
/src/com/mialab/palmsuda/views/MyScrollView.java:
--------------------------------------------------------------------------------
1 | package com.mialab.palmsuda.views;
2 |
3 | import android.app.WallpaperManager;
4 | import android.content.Context;
5 | import android.os.IBinder;
6 | import android.util.AttributeSet;
7 | import android.view.MotionEvent;
8 | import android.view.VelocityTracker;
9 | import android.view.View;
10 | import android.view.ViewConfiguration;
11 | import android.view.ViewGroup;
12 | import android.view.View.MeasureSpec;
13 | import android.widget.Scroller;
14 |
15 | public class MyScrollView extends ViewGroup {
16 |
17 | private Scroller mScroller;
18 | private VelocityTracker mVelocityTracker;
19 | private int mCurScreen;
20 | private int mDefaultScreen = 0;
21 | private static final int TOUCH_STATE_REST = 0;
22 | private static final int TOUCH_STATE_SCROLLING = 1;
23 | private static final int SNAP_VELOCITY = 600;
24 | private int mTouchState = TOUCH_STATE_REST;
25 | private int mTouchSlop;
26 | private float mLastMotionX;
27 | private WallpaperManager mWallpaperManager;
28 | private OnViewChanged listen;
29 |
30 | public MyScrollView(Context context, AttributeSet attrs) {
31 | this(context, attrs, 0);
32 | }
33 |
34 | public MyScrollView(Context context, AttributeSet attrs, int defStyle) {
35 |
36 | super(context, attrs, defStyle);
37 | mWallpaperManager = WallpaperManager.getInstance(context);
38 | mScroller = new Scroller(context);
39 | mCurScreen = mDefaultScreen;
40 | mTouchSlop = ViewConfiguration.get(getContext()).getScaledTouchSlop();
41 | }
42 |
43 | @Override
44 | protected void onLayout(boolean changed, int l, int t, int r, int b) {
45 | int childLeft = 0;
46 | final int childCount = getChildCount();
47 | for (int i = 0; i < childCount; i++) {
48 | final View childView = getChildAt(i);
49 | if (childView.getVisibility() != View.GONE) {
50 | final int childWidth = childView.getMeasuredWidth();
51 | childView.layout(childLeft, 0, childLeft + childWidth, childView.getMeasuredHeight());
52 | childLeft += childWidth;
53 | }
54 | }
55 | updateWallpaperOffset();
56 | }
57 |
58 | @Override
59 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
60 | super.onMeasure(widthMeasureSpec, heightMeasureSpec);
61 | final int width = MeasureSpec.getSize(widthMeasureSpec);
62 | final int widthMode = MeasureSpec.getMode(widthMeasureSpec);
63 | if (widthMode != MeasureSpec.EXACTLY) {
64 | throw new IllegalStateException("ScrollLayout only canmCurScreen run at EXACTLY mode!");
65 | }
66 | final int heightMode = MeasureSpec.getMode(heightMeasureSpec);
67 | if (heightMode != MeasureSpec.EXACTLY) {
68 | throw new IllegalStateException("ScrollLayout only can run at EXACTLY mode!");
69 | }
70 | final int count = getChildCount();
71 | for (int i = 0; i < count; i++) {
72 | getChildAt(i).measure(widthMeasureSpec, heightMeasureSpec);
73 | }
74 | scrollTo(mCurScreen * width, 0);
75 | }
76 |
77 | public void setOnViewChangedListener(OnViewChanged l) {
78 | listen = l;
79 | }
80 |
81 | /**
82 | * According to the position of current layout scroll to the destination
83 | * page.
84 | */
85 | public void snapToDestination() {
86 | final int screenWidth = getWidth();
87 | final int destScreen = (getScrollX() + screenWidth / 2) / screenWidth;
88 | snapToScreen(destScreen);
89 | }
90 |
91 | public void snapToScreen(int whichScreen) {
92 | whichScreen = Math.max(0, Math.min(whichScreen, getChildCount() - 1));
93 | if (getScrollX() != (whichScreen * getWidth())) {
94 | final int delta = whichScreen * getWidth() - getScrollX();
95 | mScroller.startScroll(getScrollX(), 0, delta, 0, Math.abs(delta) * 2);
96 | mCurScreen = whichScreen;
97 | invalidate();
98 | if (listen != null) {
99 | listen.onViewChange(mCurScreen, getChildCount());
100 | }
101 | }
102 | }
103 |
104 | public void setToScreen(int whichScreen) {
105 | whichScreen = Math.max(0, Math.min(whichScreen, getChildCount() - 1));
106 | mCurScreen = whichScreen;
107 | scrollTo(whichScreen * getWidth(), 0);
108 | }
109 |
110 | public int getCurScreen() {
111 | return mCurScreen;
112 | }
113 |
114 | @Override
115 | public void computeScroll() {
116 | mScroller.getCurrX();
117 | if (mScroller.computeScrollOffset()) {
118 | scrollTo(mScroller.getCurrX(), mScroller.getCurrY());
119 | updateWallpaperOffset();
120 | postInvalidate();
121 | }
122 | }
123 |
124 | @Override
125 | public boolean onTouchEvent(MotionEvent event) {
126 | if (mVelocityTracker == null) {
127 | mVelocityTracker = VelocityTracker.obtain();
128 | }
129 | mVelocityTracker.addMovement(event);
130 | final int action = event.getAction();
131 | final float x = event.getX();
132 | // final float y = event.getY();
133 | switch (action) {
134 | case MotionEvent.ACTION_DOWN :
135 | if (!mScroller.isFinished()) {
136 | mScroller.abortAnimation();
137 | }
138 | mLastMotionX = x;
139 | break;
140 | case MotionEvent.ACTION_MOVE :
141 | int deltaX = (int) (mLastMotionX - x);
142 | mLastMotionX = x;
143 | scrollBy(deltaX, 0);
144 | updateWallpaperOffset();
145 | break;
146 | case MotionEvent.ACTION_UP :
147 | final VelocityTracker velocityTracker = mVelocityTracker;
148 | velocityTracker.computeCurrentVelocity(1000);
149 | int velocityX = (int) velocityTracker.getXVelocity();
150 | if (velocityX > SNAP_VELOCITY && mCurScreen > 0) {
151 | snapToScreen(mCurScreen - 1);
152 | } else if (velocityX < -SNAP_VELOCITY && mCurScreen < getChildCount() - 1) {
153 | snapToScreen(mCurScreen + 1);
154 | } else {
155 | snapToDestination();
156 | }
157 | if (mVelocityTracker != null) {
158 | mVelocityTracker.recycle();
159 | mVelocityTracker = null;
160 | }
161 | mTouchState = TOUCH_STATE_REST;
162 | break;
163 | case MotionEvent.ACTION_CANCEL :
164 | mTouchState = TOUCH_STATE_REST;
165 | break;
166 | }
167 | return true;
168 | }
169 |
170 | @Override
171 | public boolean onInterceptTouchEvent(MotionEvent ev) {
172 | final int action = ev.getAction();
173 | if ((action == MotionEvent.ACTION_MOVE) && (mTouchState != TOUCH_STATE_REST)) {
174 | return true;
175 | }
176 | final float x = ev.getX();
177 | // final float y = ev.getY();
178 | switch (action) {
179 | case MotionEvent.ACTION_MOVE :
180 | final int xDiff = (int) Math.abs(mLastMotionX - x);
181 | if (xDiff > mTouchSlop) {
182 | mTouchState = TOUCH_STATE_SCROLLING;
183 | }
184 | break;
185 | case MotionEvent.ACTION_DOWN :
186 | mLastMotionX = x;
187 | mTouchState = mScroller.isFinished() ? TOUCH_STATE_REST : TOUCH_STATE_SCROLLING;
188 | break;
189 | case MotionEvent.ACTION_CANCEL :
190 | case MotionEvent.ACTION_UP :
191 | mTouchState = TOUCH_STATE_REST;
192 | break;
193 | }
194 | return mTouchState != TOUCH_STATE_REST;
195 | }
196 |
197 | private void updateWallpaperOffset() {
198 | if (getChildCount() > 0) {
199 | int scrollRange = getChildAt(getChildCount() - 1).getRight() - getWidth();
200 | IBinder token = getWindowToken();
201 | if (token != null) {
202 | mWallpaperManager.setWallpaperOffsetSteps(1.0f / (getChildCount() - 1), 0);
203 | mWallpaperManager.setWallpaperOffsets(getWindowToken(),
204 | Math.max(0.f, Math.min(getScrollX() / (float) scrollRange, 1.f)), 0);
205 | }
206 | }
207 | }
208 |
209 | public interface OnViewChanged {
210 | public void onViewChange(int position, int count);
211 | }
212 |
213 | }
214 |
--------------------------------------------------------------------------------
/src/com/mialab/palmsuda/main/MainViewHelper.java:
--------------------------------------------------------------------------------
1 | package com.mialab.palmsuda.main;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | import android.view.LayoutInflater;
7 | import android.view.View;
8 | import android.view.ViewGroup;
9 | import android.view.ViewGroup.LayoutParams;
10 | import android.widget.AdapterView;
11 | import android.widget.GridView;
12 | import android.widget.ImageView;
13 | import android.widget.LinearLayout;
14 | import android.widget.RelativeLayout;
15 | import android.widget.TextView;
16 |
17 | import com.mialab.palmsuda.modules.ContentItem;
18 | import com.mialab.palmsuda.modules.ModuleItem;
19 | import com.mialab.palmsuda.views.MyScrollView;
20 |
21 | /**
22 | * @author mialab
23 | * @date 创建时间:2015-8-22 下午7:06:05
24 | *
25 | */
26 | public class MainViewHelper {
27 | private PalmSudaHome mActivity;
28 | private LinearLayout barDots, bottomBar;
29 | private MyScrollView scrollView;
30 | private ContentItem mAItem;
31 | private LayoutInflater mInflater = null;
32 |
33 | private List gridItems, barItems;
34 | private int PAGENUM = 16;
35 | private int vspace = 0, hspace = 0;
36 | float oldX = 0;
37 |
38 | MainViewHelper(PalmSudaHome maty) {
39 | mActivity = maty;
40 | // 找到相应的View
41 | scrollView = (MyScrollView) mActivity.findViewById(R.id.vflipper);
42 | bottomBar = (LinearLayout) mActivity.findViewById(R.id.bar_item_holder);
43 | barDots = (LinearLayout) mActivity.findViewById(R.id.bar_item_dot);
44 |
45 | mInflater = LayoutInflater.from(mActivity);
46 |
47 | gridItems = new ArrayList();
48 | barItems = new ArrayList();
49 |
50 | scrollView.setOnViewChangedListener(new MyScrollView.OnViewChanged() {
51 | @Override
52 | public void onViewChange(int position, int count) {
53 | setFlipperDots(position, count);
54 | }
55 | });
56 | }
57 |
58 | public void setContentItem(ContentItem aItem) {
59 | mAItem = aItem;
60 | notifyDataChange();
61 | }
62 |
63 | public void onDestroy() {
64 | scrollView.removeAllViews();
65 | barDots.removeAllViews();
66 | if (gridItems != null)
67 | gridItems.clear();
68 | if (barItems != null)
69 | barItems.clear();
70 | }
71 |
72 | public void notifyDataChange() {
73 | bottomBar.removeAllViews();
74 | scrollView.removeAllViews();
75 | barDots.removeAllViews();
76 | setSomeData();
77 | if (gridItems != null)
78 | gridItems.clear();
79 | if (barItems != null)
80 | barItems.clear();
81 | if (mAItem != null) {
82 | List ms = mAItem.getmItems();
83 | for (int i = 0; i < ms.size(); i++) {
84 | ModuleItem item = ms.get(i);
85 | if (item != null) {
86 | if (item.getLevel() == 4) {
87 | barItems.add(item);
88 | } else {
89 | gridItems.add(item);
90 | }
91 | }
92 | }
93 | setFlipperView(gridItems);
94 | setBarView(barItems);
95 | }
96 | }
97 |
98 | private void setSomeData() {
99 | float sh = PalmSudaApp.SCREEN_HEIGTH;
100 | float wh = PalmSudaApp.SCREEN_WEIDTH;
101 | int ih = (int) (wh / 4 + 10);
102 | int iw = (int) (wh / 4 - 15);
103 | int col = (int) ((sh - ih * 2) / ih);
104 |
105 | if (col < 4) {
106 | PAGENUM = 12;
107 | vspace = (int) ((sh - (col + 2) * ih) / 4);
108 | } else if (col == 4) {
109 | PAGENUM = 16;
110 | vspace = (int) ((sh - 6 * ih) / 4);
111 | // vspace = 0;
112 | } else if (col == 5) {
113 | PAGENUM = 16;
114 | vspace = (int) ((sh - 6 * ih) / 4);
115 | // vspace = 0;
116 | } else if (col == 6) {
117 | PAGENUM = 20;
118 | vspace = (int) ((sh - 7 * ih) / 5);
119 | } else if (col > 6) {
120 | PAGENUM = 24;
121 | vspace = (int) ((sh - 8 * ih) / 6);
122 | }
123 | hspace = (int) ((wh - 4 * iw) / 4);
124 | }
125 |
126 | private void setFlipperView(List gridItems) {
127 | int size = gridItems.size();
128 | int count = size / PAGENUM + (size % PAGENUM == 0 ? 0 : 1);
129 | for (int i = 0; i < count; i++) {
130 | List tmp = null;
131 | GridView gView = null;
132 | if (i == (count - 1)) {
133 | tmp = gridItems.subList((count - 1) * PAGENUM, size);
134 | gView = createGridView(tmp);
135 | } else {
136 | tmp = gridItems.subList(i * PAGENUM, i * PAGENUM + PAGENUM);
137 | gView = createGridView(tmp);
138 | }
139 |
140 | ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(
141 | ViewGroup.LayoutParams.FILL_PARENT,
142 | ViewGroup.LayoutParams.FILL_PARENT);
143 | scrollView.addView(gView, params);
144 | }
145 | scrollView.setToScreen(0);
146 | setFlipperDots(0, scrollView.getChildCount());
147 | }
148 |
149 | private void setFlipperDots(int index, int count) {
150 | int num = barDots.getChildCount();
151 | if (num == 0) {
152 | for (int i = 0; i < count; i++) {
153 | ImageView dot = new ImageView(mActivity);
154 | dot.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
155 | LayoutParams.WRAP_CONTENT));
156 | dot.setPadding(5, 1, 5, 1);
157 | dot.setImageResource(R.drawable.life_home_blue_circle);
158 | barDots.addView(dot);
159 | }
160 | }
161 | if (count > 0) {
162 | for (int i = 0; i < count; i++) {
163 | ImageView dot = (ImageView) barDots.getChildAt(i);
164 | if (i == index) {
165 | dot.setImageResource(R.drawable.life_home_blue_circle);
166 | } else {
167 | dot.setImageResource(R.drawable.life_home_white_circle);
168 | }
169 | }
170 | }
171 | }
172 |
173 | private void setBarView(List barItems) {
174 | if (barItems == null || barItems.size() == 0) {
175 | mActivity.findViewById(R.id.bar_scroll_view).setVisibility(
176 | View.GONE);
177 | } else {
178 | mActivity.findViewById(R.id.bar_scroll_view).setVisibility(
179 | View.VISIBLE);
180 | }
181 | for (final ModuleItem item : barItems) {
182 | View baritem = createBarItem(item);
183 | baritem.setOnClickListener(new View.OnClickListener() {
184 | @Override
185 | public void onClick(View v) {
186 | mActivity.gridViewClick(mAItem, item);
187 | }
188 | });
189 | LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
190 | PalmSudaApp.SCREEN_WEIDTH / 4,
191 | PalmSudaApp.SCREEN_WEIDTH / 4 + 10);
192 | bottomBar.addView(baritem, params);
193 | }
194 | }
195 |
196 | private View createBarItem(final ModuleItem item) {
197 | View convertView = this.mInflater
198 | .inflate(R.layout.grid_icon_item, null);
199 | TextView tvItem = (TextView) convertView
200 | .findViewById(R.id.wap_item_name);
201 | ImageView iView = (ImageView) convertView
202 | .findViewById(R.id.wap_item_image);
203 | ImageView icView = (ImageView) convertView
204 | .findViewById(R.id.wap_ic_image);
205 | icView.setVisibility(View.GONE);
206 | tvItem.setText("" + item.getModuleName());
207 | RelativeLayout.LayoutParams paLayoutParams = (android.widget.RelativeLayout.LayoutParams) iView
208 | .getLayoutParams();
209 | paLayoutParams.width = PalmSudaApp.SCREEN_WEIDTH * 3 / 16;
210 | paLayoutParams.height = paLayoutParams.width * 100 / 96;
211 | iView.setLayoutParams(paLayoutParams);
212 | mActivity.getImageWorker().loadBitmap(item.getIconUrl(), iView,
213 | PalmSudaApp.SCREEN_WEIDTH / 4, PalmSudaApp.SCREEN_WEIDTH / 4);
214 | return convertView;
215 | }
216 |
217 | private GridView createGridView(List items) {
218 | GridView gView = (GridView) mInflater.inflate(R.layout.main_gridview,
219 | null);
220 | gView.setVerticalSpacing(vspace);
221 | gView.setPadding(0, vspace / 2, 0, 0);
222 | GdvAdapter adapter = new GdvAdapter(mActivity,
223 | mActivity.getImageWorker(), gView);
224 | adapter.setData(items);
225 | gView.setAdapter(adapter);
226 | gView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
227 | @Override
228 | public void onItemClick(AdapterView> arg0, View arg1, int arg2,
229 | long arg3) {
230 | ModuleItem item = (ModuleItem) arg0.getAdapter().getItem(arg2);
231 | mActivity.gridViewClick(mAItem, item);
232 | }
233 | });
234 | return gView;
235 | }
236 | }
237 |
--------------------------------------------------------------------------------
/src/com/mialab/palmsuda/main/PalmSudaApp.java:
--------------------------------------------------------------------------------
1 | package com.mialab.palmsuda.main;
2 |
3 | import android.app.AlarmManager;
4 | import android.app.Application;
5 | import android.app.PendingIntent;
6 | import android.content.Context;
7 | import android.content.Intent;
8 | import android.content.SharedPreferences;
9 | import android.content.SharedPreferences.Editor;
10 | import android.content.pm.ApplicationInfo;
11 | import android.content.pm.PackageInfo;
12 | import android.content.pm.PackageManager;
13 | import android.content.pm.PackageManager.NameNotFoundException;
14 | import android.net.wifi.WifiInfo;
15 | import android.net.wifi.WifiManager;
16 | import android.telephony.TelephonyManager;
17 | import android.text.TextUtils;
18 | import android.util.Log;
19 | import android.widget.Toast;
20 |
21 | import com.mialab.palmsuda.common.Constants;
22 | import com.mialab.palmsuda.common.Params;
23 | import com.mialab.palmsuda.service.ServiceManager;
24 | import com.mialab.palmsuda.service.StartServiceRecevier;
25 | import com.mialab.palmsuda.syncauth.AuthenticationUtil;
26 | import com.mialab.palmsuda.syncauth.PalmAccount;
27 |
28 | //import com.mialab.push_client.ServiceManager;
29 |
30 | /**
31 | * @author mialab
32 | * @date 创建时间:2015-8-22 上午9:40:48
33 | *
34 | */
35 | public class PalmSudaApp extends Application {
36 | private static final String TAG = Constants.APP_TAG;
37 | private static PalmSudaApp app = null;
38 | private SharedPreferences settings;
39 | private ServiceManager serviceManager;
40 |
41 | public static String versionName = "";
42 |
43 | // public static final int PRODUCT_ID = 100;
44 | // public static final int WORK_PRODUCT_ID = 100;
45 | // private BatteryReceiver mbreceiver;
46 | // public static final int appid = PRODUCT_ID;
47 | private PendingIntent sender;
48 | public static String contentId = "";
49 |
50 | public static int SCREEN_WEIDTH = 0;
51 | public static int SCREEN_HEIGTH = 0;
52 |
53 | public static PalmSudaApp getInstance() {
54 | return app;
55 | }
56 |
57 | @Override
58 | public void onCreate() {
59 | super.onCreate();
60 | app = this;
61 | Log.d(TAG, "This is PalmSuda App.....");
62 | Log.d(TAG, "Git查看文件修改内容99999.....");
63 |
64 | CrashHandler crashHandler = CrashHandler.getInstance();
65 | crashHandler.init(getApplicationContext());
66 | settings = getSharedPreferences("APP_SETTING", Application.MODE_PRIVATE);
67 |
68 | SCREEN_WEIDTH = getResources().getDisplayMetrics().widthPixels;
69 | SCREEN_HEIGTH = getResources().getDisplayMetrics().heightPixels;
70 |
71 | serviceManager = new ServiceManager(this);
72 | serviceManager.setNotificationIcon(R.drawable.notification);
73 | serviceManager.startService();
74 | bindReceiver(20);
75 | }
76 |
77 | public SharedPreferences getSettings() {
78 | if (settings == null) {
79 | settings = getSharedPreferences("APP_SETTING",
80 | Application.MODE_PRIVATE);
81 | }
82 | return settings;
83 | }
84 |
85 | public void setSaveString(String key, String value) {
86 | if (settings == null) {
87 | settings = getSharedPreferences("APP_SETTING",
88 | Application.MODE_PRIVATE);
89 | }
90 | settings.edit().putString(key, value).commit();
91 | }
92 |
93 | public String getSaveString(String key) {
94 | if (settings == null) {
95 | settings = getSharedPreferences("APP_SETTING",
96 | Application.MODE_PRIVATE);
97 | }
98 | return settings.getString(key, "");
99 | }
100 |
101 | public void bindReceiver(int minutes) {
102 | Log.d("bindReceiver", "##bindReceiver: repeat minutes=" + minutes);
103 | Intent intent = new Intent(PalmSudaApp.getInstance(),
104 | StartServiceRecevier.class);
105 | intent.setAction("start.service.receiver.action");
106 | AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
107 | if (sender != null) {
108 | am.cancel(sender);
109 | } else {
110 | sender = PendingIntent.getBroadcast(PalmSudaApp.getInstance(), 0,
111 | intent, PendingIntent.FLAG_UPDATE_CURRENT);
112 | }
113 | long trigerTime = System.currentTimeMillis() + 300000
114 | + (long) (300000 * Math.random());
115 | if (Constants.TEST_MODE || Constants.DEBUG_MODE) {
116 | minutes = 3;
117 | trigerTime = System.currentTimeMillis() + 90000;
118 | }
119 | am.setRepeating(AlarmManager.RTC_WAKEUP, trigerTime, minutes * 60000,
120 | sender);
121 | }
122 |
123 | @Override
124 | public void onLowMemory() {
125 | super.onLowMemory();
126 | try {
127 | System.gc();
128 | } catch (Exception e) {
129 | }
130 | }
131 |
132 | public void onTerminate() {
133 | Log.d(TAG, "PalmSuda App is Stoped.....");
134 | super.onTerminate();
135 | }
136 |
137 | /**
138 | * 获取渠道信息
139 | */
140 | public String getMetaData() {
141 | try {
142 | ApplicationInfo appInfo = this.getPackageManager()
143 | .getApplicationInfo(getPackageName(),
144 | PackageManager.GET_META_DATA);
145 | return appInfo.metaData.getString("UMENG_CHANNEL");
146 | } catch (Exception e) {
147 | }
148 | return "";
149 | }
150 |
151 | public String getDeviceID() {
152 | TelephonyManager teleMgr = (TelephonyManager) getBaseContext()
153 | .getSystemService(Context.TELEPHONY_SERVICE);
154 | String deviceId = teleMgr.getDeviceId();
155 | return deviceId;
156 | }
157 |
158 | public String getMacAddress() {
159 | WifiManager wManager = (WifiManager) this
160 | .getSystemService(Context.WIFI_SERVICE);
161 | WifiInfo wInfo = wManager.getConnectionInfo();
162 | return "MAC:" + wInfo.getMacAddress();
163 | }
164 |
165 | public String getSubscriberID() {
166 | String imsi = "";
167 | try {
168 | TelephonyManager teleMgr = (TelephonyManager) getBaseContext()
169 | .getSystemService(Context.TELEPHONY_SERVICE);
170 | imsi = teleMgr.getSubscriberId();
171 | } catch (Exception e) {
172 | imsi = "";
173 | }
174 | return imsi;
175 | }
176 |
177 | public String getCurrentVersion() {
178 | try {
179 | if (TextUtils.isEmpty(this.versionName)) {
180 | PackageInfo info = this.getPackageManager().getPackageInfo(
181 | this.getPackageName(), 0);
182 | // this.versionCode = info.versionCode;
183 | this.versionName = info.versionName;
184 | }
185 | } catch (NameNotFoundException e) {
186 | }
187 | return this.versionName;
188 | }
189 |
190 | public String getMobileNumber() {
191 | String mobileNum = settings.getString(Constants.SAVE_MOBILE_NUM, "");
192 | if (TextUtils.isEmpty(mobileNum)) {
193 | PalmAccount cAccount = AuthenticationUtil.getAccountData(this);
194 | if (cAccount != null && cAccount.type == 0) {
195 | settings.edit()
196 | .putString(Constants.SAVE_MOBILE_NUM,
197 | cAccount.getAccountName()).commit();
198 | mobileNum = cAccount.getAccountName();
199 | }
200 | }
201 | return mobileNum;
202 | }
203 |
204 | public void saveMobileNumber(String mobileNumber) {
205 | if (TextUtils.isEmpty(mobileNumber)) {
206 | return;
207 | }
208 | Log.d("hand", "----------para mobileNumber is: " + mobileNumber
209 | + "--------------");
210 |
211 | PalmAccount cAccount = AuthenticationUtil.getAccountData(this);
212 |
213 | Log.d("hand", "-----getAccountData(this) is:" + cAccount + "---------");
214 |
215 | if (cAccount == null) {
216 | cAccount = new PalmAccount();
217 | cAccount.setAccountName(mobileNumber);
218 | cAccount.setImsi(getSubscriberID());
219 | AuthenticationUtil.setAccountData(cAccount);
220 |
221 | Log.d("hand", "-----para mobileNumber is:" + mobileNumber
222 | + "---------");
223 | Log.d("hand", "-----getSubscriberID() is:" + getSubscriberID()
224 | + "---------");
225 | Log.d("hand", "-----saveNewAccount:" + cAccount + "---------");
226 |
227 | AuthenticationUtil.saveNewAccount(app);
228 |
229 | } else {
230 | AuthenticationUtil.updateAccountParameter(app,
231 | Params.PARAMS_LOGIN_ID, mobileNumber);
232 | AuthenticationUtil.updateAccountParameter(app,
233 | Params.PARAMS_LOGIN_IMSI, getSubscriberID());
234 | }
235 | if (settings != null) {
236 | Editor editor = settings.edit();
237 | editor.putString(Constants.SAVE_MOBILE_NUM, mobileNumber)
238 | .putString("CURRENTTAOCAN", "");
239 | editor.commit();
240 | }
241 | }
242 |
243 | public void showToast(CharSequence msg) {
244 | Toast.makeText(this, msg, Toast.LENGTH_LONG).show();
245 | }
246 | }
247 |
--------------------------------------------------------------------------------
/src/com/mialab/palmsuda/tools/ivache/ImageWorker.java:
--------------------------------------------------------------------------------
1 | package com.mialab.palmsuda.tools.ivache;
2 |
3 | import java.io.BufferedInputStream;
4 | import java.io.BufferedOutputStream;
5 | import java.io.File;
6 | import java.io.FileOutputStream;
7 | import java.io.IOException;
8 | import java.io.InputStream;
9 | import java.lang.ref.WeakReference;
10 | import java.net.HttpURLConnection;
11 | import java.net.URL;
12 | import java.util.HashMap;
13 | import java.util.concurrent.ExecutorService;
14 | import java.util.concurrent.Executors;
15 |
16 | import com.mialab.palmsuda.tools.ivache.ImageCache.ImageCacheParams;
17 |
18 | import android.graphics.Bitmap;
19 | import android.os.Build;
20 | import android.os.Handler;
21 | import android.text.TextUtils;
22 | import android.util.Log;
23 | import android.widget.ImageView;
24 |
25 | /**
26 | * @author mialab
27 | * @date 创建时间:2015-8-4 下午12:07:24
28 | *
29 | */
30 | public enum ImageWorker {
31 | INSTANCE;
32 | private ImageCache mImageCache;
33 |
34 | private int loadingResId = 0, errorResId = 0, bgResId = 0;
35 |
36 | private volatile boolean onScreen = true;
37 | public static int ScreenWeith = 480;
38 | private ExecutorService searchThreadPool;
39 | private HashMap params;
40 | private Handler mHandler;
41 | public static final int IO_BUFFER_SIZE = 8 * 1024;
42 | private OnHandleCacheListener mIHandleCache;
43 |
44 | public static ImageWorker newInstance() {
45 | return INSTANCE;
46 | }
47 |
48 | private ImageWorker() {
49 | mHandler = new Handler();
50 | mImageCache = ImageCache.createCache();
51 | searchThreadPool = Executors.newFixedThreadPool(8);
52 | mIHandleCache = new OnHandleCacheListener() {
53 | @Override
54 | public void onSetImage(final ImageView imageView,
55 | final Bitmap bitmap) {
56 | mHandler.post(new Runnable() {
57 | @Override
58 | public void run() {
59 | imageView.setImageBitmap(bitmap);
60 | // imageView.setBackgroundResource(0);
61 | AsyncDrawable aDrawable = (AsyncDrawable) imageView
62 | .getTag();
63 | if (aDrawable != null) {
64 | imageView.setBackgroundResource(aDrawable
65 | .getBgResID());
66 | }
67 | }
68 | });
69 | }
70 |
71 | @Override
72 | public void onError(final ImageView imageView) {
73 | mHandler.post(new Runnable() {
74 | @Override
75 | public void run() {
76 | if (imageView != null) {
77 | AsyncDrawable aDrawable = (AsyncDrawable) imageView
78 | .getTag();
79 | imageView
80 | .setImageResource(aDrawable != null ? aDrawable
81 | .getErrorResID() : errorResId);
82 | }
83 | }
84 | });
85 | }
86 | };
87 | }
88 |
89 | public void setCommonResID(int loadId, int errId) {
90 | loadingResId = loadId;
91 | errorResId = errId;
92 | }
93 |
94 | public void loadBitmap(final String path, final ImageView imageView,
95 | int loadingRes) {
96 | loadBitmap(path, imageView, ScreenWeith / 3, ScreenWeith / 3,
97 | loadingRes, errorResId, bgResId);
98 | }
99 |
100 | public void loadBitmap(final String path, final ImageView imageView, int w, int h) {
101 | loadBitmap(path, imageView, w, h, loadingResId, errorResId, bgResId);
102 | }
103 |
104 | public void loadBitmap(final String path, final ImageView imageView, int w,
105 | int h, int loadingRes, int errRes, int bgRes) {
106 | Bitmap result = mImageCache.getBitmapFromMem(path);
107 | imageView.setImageResource(0);
108 | imageView.setBackgroundResource(bgRes > 0 ? bgRes : 0);
109 | if (result != null && !result.isRecycled()) {
110 | mIHandleCache.onSetImage(imageView, result);
111 | } else if (cancelWork(imageView, path)) {
112 | final SearchTask task = new SearchTask(path, imageView, w, h,
113 | mIHandleCache);
114 | final AsyncDrawable asyncDrawable = new AsyncDrawable(loadingRes,
115 | errRes, bgRes, task);
116 | imageView.setTag(asyncDrawable);
117 | imageView.setBackgroundResource(asyncDrawable.getDefaultResID());
118 | if (!searchThreadPool.isTerminated()
119 | && !searchThreadPool.isShutdown()) {
120 | searchThreadPool.execute(task);
121 | }
122 | }
123 | }
124 |
125 | protected boolean cancelWork(final ImageView view, final String path) {
126 | SearchTask task = getSearchTask(view);
127 | if (task != null) {
128 | final String taskPath = task.getPath();
129 | if (TextUtils.isEmpty(taskPath) || !taskPath.equals(path)) {
130 | task.cancelWork();
131 | } else {
132 | return false;
133 | }
134 | }
135 | return true;
136 | }
137 |
138 | public static void cancelWork(final ImageView imageView) {
139 | final SearchTask bitmapWorkerTask = getSearchTask(imageView);
140 | if (bitmapWorkerTask != null) {
141 | bitmapWorkerTask.cancelWork();
142 | }
143 | }
144 |
145 | public static SearchTask getSearchTask(final ImageView imageView) {
146 | if (imageView != null) {
147 | AsyncDrawable asyncDrawable = (AsyncDrawable) imageView.getTag();
148 | if (asyncDrawable != null) {
149 | return asyncDrawable.getTask();
150 | }
151 | }
152 | return null;
153 | }
154 |
155 | /**
156 | * Set a new CacheParams.
157 | */
158 | public void addParams(String tag, ImageCacheParams cacheParams) {
159 | if (params == null) {
160 | params = new HashMap();
161 | }
162 | params.put(tag, cacheParams);
163 | mImageCache.setCacheParams(cacheParams);
164 | }
165 |
166 | /**
167 | * Get a CacheParams by flag.
168 | */
169 | public ImageCacheParams getParams(String tag) {
170 | return params.get(tag);
171 | }
172 |
173 | public class AsyncDrawable {
174 | private final WeakReference task;
175 | private int defaultId = 0;
176 | private int errorResId = 0;
177 | private int bgresId = 0;
178 |
179 | public AsyncDrawable(int loadingRes, int errResId, int bgResid,
180 | SearchTask searchTask) {
181 | task = new WeakReference(searchTask);
182 | defaultId = loadingRes;
183 | errorResId = errResId;
184 | bgresId = bgResid;
185 | }
186 |
187 | public int getDefaultResID() {
188 | return defaultId;
189 | }
190 |
191 | public int getErrorResID() {
192 | return errorResId;
193 | }
194 |
195 | public int getBgResID() {
196 | return bgresId;
197 | }
198 |
199 | public SearchTask getTask() {
200 | return task.get();
201 | }
202 | }
203 |
204 | public class SearchTask implements Runnable {
205 |
206 | String path;
207 | volatile boolean stop = false;
208 | OnHandleCacheListener mIHandleCache;
209 | int reqW = 0;
210 | int reqH = 0;
211 | private WeakReference mImageViewReference;
212 |
213 | // 停止掉任务
214 | public void cancelWork() {
215 | stop = true;
216 | }
217 |
218 | public SearchTask(final String path, final ImageView imageView, int w,
219 | int h, final OnHandleCacheListener mIHandleCache) {
220 | this.path = path;
221 | reqW = w;
222 | reqH = h;
223 | mImageViewReference = new WeakReference(imageView);
224 | this.mIHandleCache = mIHandleCache;
225 | }
226 |
227 | public String getPath() {
228 | return path;
229 | }
230 |
231 | @Override
232 | public void run() {
233 | Bitmap bitmap = null;
234 | if (mImageCache != null && !stop && getAttachedImageView() != null
235 | && onScreen) {
236 | bitmap = mImageCache.getBitmapFromDiskCache(path, reqW, reqH);
237 | }
238 | if (bitmap == null && mImageCache != null && !stop
239 | && getAttachedImageView() != null && onScreen) {
240 | try {
241 | File file = downloadBitmap(path);
242 | bitmap = mImageCache.getBitmapFromDiskCache(file, reqW,
243 | reqH);
244 | if (bitmap == null) {
245 | mIHandleCache.onError(getAttachedImageView());
246 | }
247 | } catch (IOException e) {
248 | mIHandleCache.onError(getAttachedImageView());
249 | e.printStackTrace();
250 | }
251 |
252 | }
253 |
254 | if (bitmap != null && mImageCache != null && !stop && onScreen) {
255 | ImageView imageView = getAttachedImageView();
256 | mImageCache.addBitmapToCache(path, bitmap);
257 | if (imageView != null && !stop) {
258 | mIHandleCache.onSetImage(imageView, bitmap);
259 | } else {
260 | bitmap.recycle();
261 | bitmap = null;
262 |
263 | }
264 | }
265 |
266 | }
267 |
268 | /**
269 | * Returns the ImageView associated with this task as long as the
270 | * ImageView's task still points to this task as well. Returns null
271 | * otherwise.
272 | */
273 | private ImageView getAttachedImageView() {
274 | final ImageView imageView = mImageViewReference.get();
275 | final SearchTask bitmapWorkerTask = ImageWorker
276 | .getSearchTask(imageView);
277 |
278 | if (this == bitmapWorkerTask) {
279 | return imageView;
280 | }
281 |
282 | return null;
283 | }
284 | }
285 |
286 | public void setOnScreen(String tag, boolean onScreen) {
287 | this.onScreen = onScreen;
288 | if (!onScreen) {
289 | mImageCache.clearCaches();
290 | shutdownThreadPool();
291 | } else {
292 | restartThreadPool();
293 | mImageCache.setCacheParams(getParams(tag));
294 | }
295 | }
296 |
297 | private void restartThreadPool() {
298 | synchronized (searchThreadPool) {
299 | if (searchThreadPool.isTerminated()
300 | || searchThreadPool.isShutdown()) {
301 | searchThreadPool = null;
302 | searchThreadPool = Executors.newFixedThreadPool(8);
303 | }
304 | }
305 | }
306 |
307 | private void shutdownThreadPool() {
308 | searchThreadPool.shutdown();
309 | }
310 |
311 | private File downloadBitmap(String urlString) throws IOException {
312 | DiskCache cache = DiskCache.openCache();
313 |
314 | Log.d("hand", "打印cache值为:" + cache);
315 | Log.d("hand", "打印urlString值为:" + urlString);
316 |
317 | final File cacheFile = new File(cache.createFilePath(urlString));
318 |
319 | if (cache.containsKey(urlString)) {
320 | return cacheFile;
321 | }
322 |
323 | HttpURLConnection urlConnection = null;
324 | BufferedOutputStream out = null;
325 | try {
326 | final URL url = new URL(urlString);
327 | urlConnection = (HttpURLConnection) url.openConnection();
328 | urlConnection.setReadTimeout(6 * 1000);
329 | urlConnection.setConnectTimeout(6 * 1000);
330 | InputStream in = new BufferedInputStream(
331 | urlConnection.getInputStream(), IO_BUFFER_SIZE);
332 | out = new BufferedOutputStream(new FileOutputStream(cacheFile),
333 | IO_BUFFER_SIZE);
334 | int b;
335 | while ((b = in.read()) != -1) {
336 | out.write(b);
337 | }
338 | cacheFile.setLastModified(System.currentTimeMillis());
339 | } catch (IOException e) {
340 | throw e;
341 | } finally {
342 | if (urlConnection != null) {
343 | urlConnection.disconnect();
344 | }
345 | if (out != null) {
346 | out.flush();
347 | out.close();
348 | }
349 | }
350 | return cacheFile;
351 | }
352 | }
353 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "{}"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright {yyyy} {name of copyright owner}
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
203 |
--------------------------------------------------------------------------------
/src/com/mialab/palmsuda/main/MaintainMgr.java:
--------------------------------------------------------------------------------
1 | package com.mialab.palmsuda.main;
2 |
3 | import java.io.IOException;
4 | import java.io.InputStream;
5 | import java.util.ArrayList;
6 | import java.util.List;
7 | import java.util.concurrent.ExecutorService;
8 | import java.util.concurrent.Executors;
9 |
10 | import org.json.JSONArray;
11 | import org.json.JSONObject;
12 |
13 | import android.content.Context;
14 | import android.content.Intent;
15 | import android.os.Handler;
16 | import android.os.Message;
17 | import android.text.TextUtils;
18 | import android.util.Log;
19 |
20 | import com.mialab.palmsuda.common.Constants;
21 | import com.mialab.palmsuda.modules.ContentItem;
22 | import com.mialab.palmsuda.modules.ModuleConfigOptions;
23 | import com.mialab.palmsuda.modules.ModuleItem;
24 | import com.mialab.palmsuda.modules.ModuleKey;
25 | import com.mialab.palmsuda.tools.util.FunctionUtil;
26 |
27 | /**
28 | * @author mialab
29 | * @date 创建时间:2015-8-22 下午10:37:14
30 | *
31 | */
32 | public class MaintainMgr {
33 | private static final String TAG = "MaintainMgr";
34 | private static MaintainMgr mgr;
35 |
36 | private ContentItem mContentItem;
37 |
38 | private PalmSudaApp app = PalmSudaApp.getInstance();
39 |
40 | private ExecutorService executorService = null;
41 |
42 | private MaintainMgr() {
43 | executorService = Executors.newFixedThreadPool(6);
44 | }
45 |
46 | public static MaintainMgr getInstance() {
47 | if (mgr == null) {
48 | mgr = new MaintainMgr();
49 | }
50 | return mgr;
51 | }
52 |
53 | private String getAssetModuleList(String contentId) throws IOException {
54 | Log.d("hand", "-------参数app为: " + app + "-------");
55 | return getFromAsset(app, "datas/" + contentId + ".txt");
56 | }
57 |
58 | public void getModuleList(final String contentId,
59 | final String contentAddress, final String version,
60 | final boolean isfirst, final ContentReadyCallback aCallback) {
61 | final Handler handler = new Handler() {
62 | public void handleMessage(Message message) {
63 | aCallback.dataReady(message.obj);
64 | }
65 | };
66 | executorService.execute(new Runnable() {
67 | @Override
68 | public void run() {
69 | try {
70 | String src = null;
71 | ContentItem contentItem = null;
72 |
73 | if (contentItem == null) {
74 | src = getAssetModuleList(contentId);
75 |
76 | Log.d("hand", "-----------contentId is: " + contentId
77 | + "---------");
78 | Log.d("hand", "-----------src is: " + src + "---------");
79 |
80 | contentItem = getContentItem(src, false, "");
81 |
82 | Log.d("hand", "-----------contentItem is: "
83 | + contentItem + "---------");
84 | Log.d("hand",
85 | "---------------"
86 | + contentItem.getContentName()
87 | + "------------");
88 | Log.d("hand",
89 | "---------------" + contentItem.getMobileNum()
90 | + "-----------");
91 | Log.d("hand",
92 | "---------------" + contentItem.getmItems()
93 | + "---------");
94 | Log.d("hand",
95 | "---------------"
96 | + contentItem.getBackgroundUrl()
97 | + "---------");
98 | }
99 |
100 | if (contentItem != null) {
101 | mContentItem = contentItem;
102 | }
103 |
104 | handler.sendMessage(Message.obtain(handler, 0, contentItem));
105 | } catch (Exception e) {
106 | handler.sendMessage(Message
107 | .obtain(handler, 0, mContentItem));
108 | android.util.Log.e("hand", "content item---", e);
109 | }
110 | }
111 | });
112 | }
113 |
114 | private ContentItem getContentItem(String src, boolean isSave,
115 | String filename) {
116 | ContentItem aItem = null;
117 | Log.d("hand",
118 | "-------!TextUtils.isEmpty(src) is: " + !TextUtils.isEmpty(src)
119 | + "----------------");
120 |
121 | if (!TextUtils.isEmpty(src)) {
122 | try {
123 | Log.d("hand", "------This way: " + "----------------");
124 |
125 | JSONObject object = new JSONObject(src.trim())
126 | .getJSONObject("ContentConfig");
127 | Log.d("hand", "-------JSONObject object is: " + object
128 | + "----------------");
129 |
130 | aItem = new ContentItem();
131 |
132 | if (!object.isNull("id"))
133 | aItem.setContentId(object.getString("id"));
134 | if (!object.isNull("parentId"))
135 | aItem.setParentId(object.getString("parentId"));
136 | if (!object.isNull("name"))
137 | aItem.setContentName(object.getString("name"));
138 | if (!object.isNull("level"))
139 | aItem.setLevel(object.getInt("level"));
140 | if (!object.isNull("bgVer")) {
141 | int bgver = object.getInt("bgVer");
142 | aItem.setBackgroundVersion(bgver);
143 | }
144 | if (!object.isNull("bgUrl"))
145 | aItem.setBackgroundUrl(object.getString("bgUrl"));
146 | if (!object.isNull("moduleList")) {
147 | JSONArray jArray = object.getJSONArray("moduleList");
148 | int len = jArray.length();
149 | List mList = new ArrayList();
150 | Log.d("hand", "-------ArrayList is: " + mList
151 | + "----------------");
152 |
153 | for (int i = 0; i < len; i++) {
154 | JSONObject jbo = jArray.getJSONObject(i);
155 | Log.d("hand", "-------ModuleInfo is: " + jbo
156 | + "----------------");
157 |
158 | if (!jbo.isNull("ModuleInfo")) {
159 | ModuleItem mItem = new ModuleItem();
160 | JSONObject jo = jbo.getJSONObject("ModuleInfo");
161 |
162 | Log.d("hand", "-------ModuleItem mItem is: "
163 | + mItem + "----------------");
164 |
165 | if (!jo.isNull("id"))
166 | mItem.setModuleId(jo.getInt("id"));
167 | if (!jo.isNull("version"))
168 | mItem.setModuleVersion(jo.getString("version"));
169 | if (!jo.isNull("name"))
170 | mItem.setModuleName(jo.getString("name"));
171 | if (!jo.isNull("key")) {
172 | mItem.setModuleKey(jo.getString("key"));
173 | }
174 | if (!jo.isNull("options"))
175 | mItem.setOptions(jo.getInt("options"));
176 | if (!jo.isNull("iconVer")) {
177 | int iconVer = jo.getInt("iconVer");
178 | mItem.setIconVersion(iconVer);
179 | }
180 | if (!jo.isNull("iconUrl"))
181 | mItem.setIconUrl(jo.getString("iconUrl"));
182 | if (!jo.isNull("type"))
183 | mItem.setType(jo.getInt("type"));
184 | if (!jo.isNull("level"))
185 | mItem.setLevel(jo.getInt("level"));
186 | if (!jo.isNull("url"))
187 | mItem.setModuleUrl(jo.getString("url"));
188 | if (!jo.isNull("needClientVer"))
189 | mItem.setNeedClientVersion(jo
190 | .getString("needClientVer"));
191 | if (!jo.isNull("desc"))
192 | mItem.setDescription(jo.getString("desc"));
193 |
194 | if (!jo.isNull("dispClientVer")) {
195 | mItem.setDispClientVersion(jo
196 | .getString("dispClientVer"));
197 | }
198 |
199 | if (jo.has("isSupportAdv")) {
200 | mItem.setHasAd(jo.getInt("isSupportAdv"));
201 | }
202 |
203 | String dispClientVersion = mItem
204 | .getDispClientVersion();
205 | ModuleConfigOptions options = mItem.getmOptions();
206 |
207 | Log.d("hand", "------PalmSudaApp.versionName is:"
208 | + PalmSudaApp.versionName + "----------");
209 |
210 | int retu = FunctionUtil.checkVersion(
211 | PalmSudaApp.versionName, dispClientVersion);
212 |
213 | Log.d("hand", "------retu:" + retu + "----------");
214 | Log.d("hand", "------mItem.getDispClientVersion():"
215 | + mItem.getDispClientVersion()
216 | + "----------");
217 | Log.d("hand", "------options.isMarketVersion():"
218 | + options.isMarketVersion() + "----------");
219 | Log.d("hand", "------retu:" + mItem.getModuleName()
220 | + "----------");
221 | Log.d("hand", "------retu:" + mItem.getIconUrl()
222 | + "----------");
223 |
224 | retu = -1; // 仅作调试用
225 |
226 | if (retu < 0) {
227 | if (Constants.MARKET_VERSION
228 | && options.isMarketVersion()) {
229 | continue;
230 | } else {
231 | Log.d("hand",
232 | "ModuleName---"
233 | + mItem.getModuleName());
234 | mList.add(mItem);
235 | }
236 | }
237 | }
238 | }
239 | aItem.setmItems(mList);
240 | }
241 | } catch (Exception e) {
242 | Log.d("hand", "------Exception e:" + e + "----------");
243 | }
244 | }
245 | return aItem;
246 | }
247 |
248 | public String getFromAsset(Context context, String fileName)
249 | throws IOException {
250 | try {
251 | InputStream in = context.getResources().getAssets().open(fileName);
252 | Log.d("handong", "------------filename是 : " + fileName);
253 | Log.d("handong", "------------打印 InputStream : " + in);
254 | if (in != null) {
255 | int length = in.available();
256 | byte[] buffer = new byte[length];
257 | in.read(buffer);
258 | in.close();
259 | return new String(buffer, "UTF-8");
260 | }
261 | } catch (Exception e) {
262 | Log.d("handong", "------------发生Exception: " + e);
263 | return null;
264 | }
265 | return null;
266 | }
267 |
268 | public String getMobileNumber() {
269 | String mobileNum = "";
270 | return mobileNum;
271 | }
272 |
273 | public Class getStartClass(String mdKey, Intent it) {
274 | if (mContentItem == null) {
275 | return null;
276 | }
277 | Class startClass = null;
278 | ModuleItem item = mContentItem.getModuleItemByMdKey(mdKey);
279 | if (mdKey.contains("weather")) {
280 | // it.putExtra("cityId", item.getWorkCityId());
281 | // startClass = WeatherActivity.class;
282 | } else if (mdKey.equals("suda_news")) {
283 | // startClass = com.suda.ui.campus_news.NewsActivity.class;
284 | } else if (mdKey.equals("suda_around")) {
285 | // startClass = com.suda.ui.around.AroundActivity.class;
286 | } else if (mdKey.equals("current")) {
287 | // startClass = com.suda.ui.current.CurrentNewsActivity.class;
288 | } else if (mdKey.equals("flea")) {
289 | // startClass = com.suda.ui.flea.FleaActivity.class;
290 | } else if (mdKey.contains("traffic")) {
291 | // startClass = com.suda.ui.traffic.TrafficActivity.class;
292 | } else if (mdKey.contains("pt_job")) {
293 | // startClass = com.suda.ui.pt_job.Pt_Job_Activity.class;
294 | } else if (mdKey.equals("qr_code")) {
295 | // startClass = com.suda.framework.zxing.CaptureActivity.class;
296 | } else if (mdKey.equals(ModuleKey.MODULE_KEY_PERSONCENTER)) {
297 | // startClass = PersoncenterActivity2.class;
298 | } else if (mdKey.equals(ModuleKey.MODULE_KEY_PHONE_GUARD)) {
299 | // startClass =
300 | // com.suda.ui.website_development.Website_Develop_Activity.class;
301 |
302 | } else if (mdKey.equals(ModuleKey.MODULE_KEY_OPTIMIZE)) {
303 | // startClass = com.suda.ui.enterprise.EnterpriseActivity.class;
304 | } else if (mdKey.equals(ModuleKey.MODULE_KEY_NETFLOW)) {
305 | // startClass = com.suda.ui.sike.SikeActivity.class;
306 | } else if (mdKey.equals(ModuleKey.MODULE_KEY_PROCESS)) {
307 | // startClass = com.suda.ui.cad.CadActivity.class;
308 | } else if (mdKey.equals(ModuleKey.NOTICEMSG_TYPE_RECHARGE)) {
309 | // startClass = com.suda.ui.video.VideoActivity.class;
310 | } else if (mdKey.equals(ModuleKey.MODULE_KEY_MYSETTING)) {
311 | // startClass = com.suda.ui.child.ChildActivity.class;
312 | } else if (mdKey.equals(ModuleKey.MODULE_KEY_MESSAGE_CENTER)) {
313 | // startClass = MsgCenterActivity.class;
314 | } else if (mdKey.equals(ModuleKey.MODULE_KEY_SOFTWARE_MANAGE)) {
315 | // startClass = com.suda.ui.training.TrainingActivity.class;
316 | } else if (mdKey.equals(ModuleKey.MODULE_KEY_COMMUNICATE)) {
317 | // startClass = com.suda.ui.common.WordActivity.class;
318 | } else if (mdKey.equals(ModuleKey.MODULE_KEY_CONNECT_US)) {
319 | // startClass = com.suda.ui.connect.ConnectActivity.class;
320 | } else if (mdKey.equals(ModuleKey.MODULE_KEY_FLOWPACKET)) {
321 | // startClass = com.suda.ui.telmgr.FlowMainActivity.class;
322 | }
323 | return startClass;
324 | }
325 |
326 | public boolean isContainsKey(String key) {
327 | if (mContentItem != null) {
328 | return mContentItem.getModuleItemByMdKey(key) != null;
329 | }
330 | return false;
331 | }
332 |
333 | public ModuleItem getModuleItemByMdKey(String key) {
334 | if (mContentItem != null) {
335 | return mContentItem.getModuleItemByMdKey(key);
336 | }
337 | return null;
338 | }
339 |
340 | public void runBackground(Runnable command) {
341 | executorService.execute(command);
342 | }
343 |
344 | public interface ContentReadyCallback {
345 | public void dataReady(Object data);
346 | }
347 |
348 | public void cleardata() {
349 | }
350 | }
351 |
--------------------------------------------------------------------------------
/src/com/mialab/palmsuda/main/PalmSudaHome.java:
--------------------------------------------------------------------------------
1 | package com.mialab.palmsuda.main;
2 |
3 | //import com.app.palmsuda.main.WapPageActivity;
4 |
5 | import java.util.Collections;
6 |
7 | import com.mialab.palmsuda.base.BaseActivity;
8 | import com.mialab.palmsuda.common.Constants;
9 | import com.mialab.palmsuda.modules.ContentItem;
10 | import com.mialab.palmsuda.modules.ModuleItem;
11 | import com.mialab.palmsuda.service.BackService;
12 | import com.mialab.palmsuda.tools.util.FunctionUtil;
13 | import com.mialab.palmsuda.views.VScrollTextView;
14 | import com.mialab.palmsuda.main.R;
15 |
16 | import android.app.Activity;
17 | import android.app.AlertDialog;
18 | import android.app.Dialog;
19 | import android.content.DialogInterface;
20 | import android.content.Intent;
21 | import android.content.SharedPreferences;
22 | import android.graphics.Color;
23 | import android.os.Bundle;
24 | import android.os.Handler;
25 | import android.os.Message;
26 | import android.provider.Settings;
27 | import android.text.TextUtils;
28 | import android.util.Log;
29 | import android.view.View;
30 | import android.widget.Toast;
31 |
32 | /**
33 | * @author mialab
34 | * @date 创建时间:2015-8-22 上午9:42:14
35 | *
36 | */
37 | public class PalmSudaHome extends BaseActivity {
38 | private static final String TAG = Constants.APP_TAG;
39 | private static final int DIALOG_CONFIRM_QUIT = 1;
40 | private static final int DIALOG_CONFIRM_UPDATE = 2;
41 | private static final int DIALOG_ABOUT = 3;
42 | private static final int DIALOG_SD_ERROR = 4;
43 | private static final int DIALOG_NETWORK_ERROR = 5;
44 | private static final int DIALOG_FUNCTION_ERROR = 6;
45 | private static final int DIALOG_NOMORE_SPACE = 7;
46 |
47 | private MainViewHelper mViewHelper;
48 | private SharedPreferences settings;
49 | private VScrollTextView tvName;
50 | private ContentItem aItem;
51 | private String contentName = "";
52 | public String versionName = "";
53 |
54 | @Override
55 | protected void onCreate(Bundle savedInstanceState) {
56 | super.onCreate(savedInstanceState);
57 | setContentView(R.layout.palm_main);
58 |
59 | getImageWorker().setOnScreen(Constants.APP_TAG, true);
60 | // 获取本地设置文件
61 | settings = PalmSudaApp.getInstance().getSettings();
62 |
63 | mViewHelper = new MainViewHelper(this);
64 | tvName = (VScrollTextView) findViewById(R.id.grid_title_name);
65 |
66 | tvName.setTextSize(this, 20);
67 | tvName.setTextColor(Color.WHITE);
68 | tvName.setTxtInfo(getString(R.string.app_name));
69 |
70 | loadData();
71 |
72 | }
73 |
74 | /**
75 | * 加载本地程序
76 | */
77 | private void loadData() {
78 | PalmSudaApp.contentId = "";
79 |
80 | if (TextUtils.isEmpty(PalmSudaApp.contentId)) {
81 | Log.d("hand", "-------------------walk this way------------------");
82 | handleMainView("10285", "苏州大学", true, false);
83 | }
84 | }
85 |
86 | private void handleMainView(final String contentid, final String addr,
87 | final boolean isfirst, final boolean isSwitch) {
88 | if (!isfirst) {
89 | showWaitDialog(getString(R.string.weather_flush_content));
90 | }
91 | MaintainMgr.getInstance().getModuleList(contentid, addr, versionName,
92 | isfirst, new MaintainMgr.ContentReadyCallback() {
93 | @Override
94 | public void dataReady(Object data) {
95 | if (data != null) {
96 | aItem = (ContentItem) data;
97 | setMainView(aItem, isSwitch);
98 | } else {
99 | dismissDlg();
100 | showToast("没有获得数据,请查看网络是否通畅!");
101 | }
102 | }
103 | });
104 | }
105 |
106 | private void setMainView(ContentItem aItem, boolean isSwitch) {
107 | mViewHelper.setContentItem(aItem);
108 | contentName = aItem.getContentName();
109 | // dismissDlg();
110 |
111 | Log.d("hand",
112 | "----------aItem.getContentName(): " + aItem.getContentName()
113 | + "-----------");
114 | Log.d("hand",
115 | "----------aItem.getMobileNum() is: " + aItem.getMobileNum()
116 | + "-----------");
117 | Log.d("hand",
118 | "----------aItem.getBackgroundUrl() is: "
119 | + aItem.getBackgroundUrl() + "-----------");
120 | Log.d("hand", "----------aItem.getmItems() is: " + aItem.getmItems()
121 | + "-----------");
122 |
123 | PalmSudaApp.contentId = aItem.getContentId();
124 | settings.edit().putString(Constants.SAVE_SELECT_AREA, contentName)
125 | .putString(Constants.SAVE_AREA_ID, PalmSudaApp.contentId)
126 | .commit();
127 |
128 | }
129 |
130 | Handler handler = new Handler() {
131 | public void handleMessage(Message msg) {
132 | Log.i(TAG, "handleMessage:msg.what=" + msg.what);
133 | switch (msg.what) {
134 | case 0:
135 | break;
136 | case 1:
137 | break;
138 | case 2:
139 | showDialog(DIALOG_SD_ERROR);
140 | break;
141 | case 3:
142 | break;
143 | case 4:
144 | break;
145 | case 5: // Menu updated
146 | showDialog(DIALOG_CONFIRM_UPDATE);
147 | break;
148 | case 6:
149 | showToast((String) msg.obj);
150 | break;
151 | }
152 | }
153 | };
154 |
155 | /**
156 | * GridView各item的点击跳转事件-TTT
157 | *
158 | * @param area
159 | * @param item
160 | */
161 | public void gridViewClick(ContentItem area, final ModuleItem item) {
162 | String mdKey = item.getModuleKey();
163 | int type = item.getType();
164 |
165 | Log.d("hand",
166 | "-----------item.getModuleKey() is: " + item.getModuleKey()
167 | + "---------");
168 | Log.d("hand", "-----------item.getType() is: " + item.getType()
169 | + "---------");
170 |
171 | if (TextUtils.isEmpty(mdKey)) {
172 | this.showToast(R.string.dialog_net_error_msg);
173 | return;
174 | }
175 |
176 | if (item.getOptions().isNeedNetwork()
177 | && !FunctionUtil.isNetworkConnected()) {
178 | this.showDialog(DIALOG_NETWORK_ERROR);
179 | return;
180 | }
181 |
182 | Log.d("hand", "-----------versionName is: " + versionName + "---------");
183 | Log.d("hand",
184 | "-----------item.getNeedClientVersion() is: "
185 | + item.getNeedClientVersion() + "---------");
186 |
187 | if (FunctionUtil.checkVersion(versionName, item.getNeedClientVersion()) > 0) {
188 | Log.d("hand",
189 | "-----------被拦截了: "
190 | + FunctionUtil.checkVersion(versionName,
191 | item.getNeedClientVersion()) + "---------");
192 | showDialog(DIALOG_FUNCTION_ERROR);
193 | return;
194 | }
195 |
196 | if (type == 1) {
197 | // String wapUrl = MaintainMgr.getInstance().formatWapUrl(item);
198 | // String proxy = item.getParameter_b();
199 | // Intent intent1 = new Intent();
200 | // intent1.putExtra(Constants.PARAM_WAP_URL, wapUrl);
201 | // intent1.putExtra(Constants.PARAM_WAP_TITLE,
202 | // item.getModuleName());
203 | // if (!TextUtils.isEmpty(proxy)) {
204 | // intent1.putExtra(Constants.PARAM_WAP_PROXY, proxy);
205 | // }
206 | // intent1.setClass(PalmSudaHome.this, WapPageActivity.class);
207 | // startActivity(intent1);
208 | } else if (type == 0) {
209 | Intent it = new Intent();
210 | it.putExtra(Constants.MODULE_URL, item.getModuleUrl());
211 | // it.putExtra(Constants.CITYID, area.getCityId());
212 | // it.putExtra(Constants.CITYNAME, area.getCityName());
213 | // it.putExtra(Constants.WORK_CITYID, item.getWorkCityId());
214 | // it.putExtra(Constants.MODULE_ID, item.getModuleId());
215 | // it.putExtra(Constants.MODULE_NAME, item.getModuleName());
216 | // it.putExtra(Constants.PARAM_A, item.getParameter_a());
217 | // it.putExtra(Constants.PARAM_B, item.getParameter_b());
218 | // it.putExtra(Constants.PARAM_C, item.getParameter_c());
219 | int hasad = item.getHasAd();
220 | if (1 == hasad) {
221 | it.putExtra("HASAD", hasad);
222 | }
223 |
224 | @SuppressWarnings("rawtypes")
225 | Class startClass = MaintainMgr.getInstance().getStartClass(mdKey,
226 | it);
227 | if (startClass != null && isClassAvailable(startClass.getName())) {
228 | it.setClass(PalmSudaHome.this, startClass);
229 | startActivity(it);
230 | } else {
231 | showDialog(DIALOG_FUNCTION_ERROR);
232 | }
233 | } else if (type == 2) {
234 | // String pkgname = item.getParameter_a();
235 | } else if (type == 9) {
236 | Toast.makeText(this, "对不起,该功能模块暂时尚未上线!", Toast.LENGTH_SHORT).show();
237 | }
238 | }
239 |
240 | void showToast(CharSequence msg) {
241 | Toast.makeText(this, msg, Toast.LENGTH_LONG).show();
242 | }
243 |
244 | public void showToast(int id) {
245 | Toast.makeText(this, id, Toast.LENGTH_LONG).show();
246 | }
247 |
248 | public void onBackPressed() {
249 | this.showDialog(DIALOG_CONFIRM_QUIT);
250 | }
251 |
252 | private boolean isClassAvailable(String classname) {
253 | boolean isava = true;
254 | try {
255 | if (Class.forName(classname) != null) {
256 | isava = true;
257 | }
258 | } catch (Exception e) {
259 | Log.d(Constants.APP_TAG, "isClassAvailable", e);
260 | isava = false;
261 | }
262 | return isava;
263 | }
264 |
265 | @Override
266 | public void onPause() {
267 | super.onPause();
268 | if (mImageWorker != null)
269 | mImageWorker.setOnScreen(Constants.APP_TAG, false);
270 |
271 | }
272 |
273 | @Override
274 | protected void onResume() {
275 | super.onResume();
276 | if (mImageWorker != null)
277 | mImageWorker.setOnScreen(Constants.APP_TAG, true);
278 | if (mViewHelper != null) {
279 | mViewHelper.notifyDataChange();
280 | }
281 | }
282 |
283 | public void onDestroy() {
284 | Log.d(TAG, "============PalmSuda onDestroy=============");
285 | super.onDestroy();
286 | try {
287 | if (mViewHelper != null) {
288 | mViewHelper.onDestroy();
289 | }
290 |
291 | MaintainMgr.getInstance().runBackground(new Runnable() {
292 | @Override
293 | public void run() {
294 | MaintainMgr.getInstance().cleardata();
295 | // NetworkUtilities.shutDown();
296 | }
297 | });
298 | System.exit(0);
299 | } catch (Exception e) {
300 | }
301 | }
302 |
303 | protected Dialog onCreateDialog(int id) {
304 | switch (id) {
305 | case DIALOG_CONFIRM_QUIT:
306 | return new AlertDialog.Builder(PalmSudaHome.this)
307 | .setIcon(R.drawable.d_alert_dialog_icon)
308 | .setTitle(R.string.alert_dialog_quit_title)
309 | .setMessage(R.string.alert_dialog_quit_msg)
310 | .setPositiveButton(R.string.alert_dialog_yes,
311 | new DialogInterface.OnClickListener() {
312 | public void onClick(DialogInterface dialog,
313 | int whichButton) {
314 | dialog.cancel();
315 | finish();
316 | }
317 | })
318 | .setNegativeButton(R.string.alert_dialog_no,
319 | new DialogInterface.OnClickListener() {
320 | public void onClick(DialogInterface dialog,
321 | int whichButton) {
322 | /* User clicked Cancel so do some stuff */
323 | dialog.cancel();
324 | }
325 | }).create();
326 | case DIALOG_ABOUT:
327 | int iconid = android.R.drawable.ic_dialog_alert;
328 | String msg = this.getResources().getString(
329 | R.string.dialog_about_msg);
330 | return new AlertDialog.Builder(this)
331 | .setIcon(iconid)
332 | .setTitle(R.string.menu_about)
333 | .setMessage(msg)
334 | .setPositiveButton(android.R.string.ok,
335 | new DialogInterface.OnClickListener() {
336 | public void onClick(DialogInterface dialog,
337 | int whichButton) {
338 | dialog.cancel();
339 | }
340 | }).create();
341 | case DIALOG_SD_ERROR:
342 | return new AlertDialog.Builder(this)
343 | .setIcon(android.R.drawable.ic_dialog_alert)
344 | .setTitle(R.string.dialog_error_title)
345 | .setMessage(R.string.dialog_sd_error_msg)
346 | .setPositiveButton(android.R.string.ok,
347 | new DialogInterface.OnClickListener() {
348 | public void onClick(DialogInterface dialog,
349 | int whichButton) {
350 | dialog.cancel();
351 | }
352 | }).create();
353 | case DIALOG_NOMORE_SPACE:
354 | return new AlertDialog.Builder(this)
355 | .setIcon(android.R.drawable.ic_dialog_alert)
356 | .setTitle(R.string.kind_tips)
357 | .setMessage(R.string.dialog_sd_nospace_msg)
358 | .setPositiveButton(android.R.string.ok,
359 | new DialogInterface.OnClickListener() {
360 | public void onClick(DialogInterface dialog,
361 | int whichButton) {
362 | dialog.cancel();
363 | }
364 | }).create();
365 | case DIALOG_NETWORK_ERROR:
366 | return new AlertDialog.Builder(this)
367 | .setIcon(android.R.drawable.ic_dialog_alert)
368 | .setTitle(R.string.dialog_error_title)
369 | .setMessage(R.string.dialog_net_error_msg)
370 | .setPositiveButton(R.string.common_setting,
371 | new DialogInterface.OnClickListener() {
372 | public void onClick(DialogInterface dialog,
373 | int whichButton) {
374 | startActivity(new Intent(
375 | Settings.ACTION_WIRELESS_SETTINGS));
376 | dialog.cancel();
377 | finish();
378 | }
379 | })
380 | .setNegativeButton(R.string.common_cancel,
381 | new DialogInterface.OnClickListener() {
382 | public void onClick(DialogInterface dialog,
383 | int whichButton) {
384 | dialog.dismiss();
385 | finish();
386 | }
387 | }).create();
388 | }
389 | return null;
390 | }
391 | }
392 |
--------------------------------------------------------------------------------