Ray Zhang %!s(int64=12) %!d(string=hai) anos
pai
achega
ef6c0b8348

BIN=BIN
Apex/res/drawable-hdpi/bg_3.png


BIN=BIN
Apex/res/drawable-hdpi/bg_4.png


+ 1 - 1
Apex/res/layout/activity_apex.xml

@@ -13,7 +13,7 @@
             android:layout_height="wrap_content"
             android:layout_alignParentTop="true"
             android:scaleType="fitXY"
-            android:src="@drawable/bg_2" 
+            android:src="@drawable/bg_4" 
             
             />
 

+ 187 - 138
Apex/src/com/usai/apex/DetailFragment.java

@@ -11,8 +11,15 @@ import com.usai.util.commonUtil;
 import android.R.integer;
 import android.animation.Animator;
 import android.animation.AnimatorListenerAdapter;
+import android.app.AlertDialog;
+import android.app.Dialog;
+import android.app.DownloadManager;
+import android.app.AlertDialog.Builder;
+import android.app.DownloadManager.Request;
 import android.content.Context;
+import android.content.DialogInterface;
 import android.content.Intent;
+import android.graphics.Bitmap;
 import android.net.Uri;
 import android.os.AsyncTask;
 import android.os.Build;
@@ -28,7 +35,9 @@ import android.view.View;
 import android.view.View.OnClickListener;
 import android.view.ViewGroup;
 import android.webkit.DownloadListener;
+import android.webkit.WebChromeClient;
 import android.webkit.WebView;
+import android.webkit.WebViewClient;
 import android.widget.Button;
 import android.widget.LinearLayout;
 import android.widget.RelativeLayout;
@@ -45,16 +54,14 @@ public class DetailFragment extends Fragment implements OnClickListener /*
 
 	/* private GestureDetector mGestureDetector; */
 	@Override
-	public void onCreate(Bundle savedInstanceState)
-	{
+	public void onCreate(Bundle savedInstanceState) {
 		// TODO Auto-generated method stub
 		super.onCreate(savedInstanceState);
 
 	}
 
 	@Override
-	public void onDestroyView()
-	{
+	public void onDestroyView() {
 		Log.d("DetailFragment", "onDestroyView()");
 		super.onDestroyView();
 	}
@@ -74,15 +81,12 @@ public class DetailFragment extends Fragment implements OnClickListener /*
 
 	// String fragment_content = null;
 
-	public void requestdata()
-	{
+	public void requestdata() {
 
-		if (m_task != null)
-		{
+		if (m_task != null) {
 			return;
 		}
-		if (mdataFragment.get_result() != null)
-		{
+		if (mdataFragment.get_result() != null) {
 			LayoutInflater inflater = (LayoutInflater) ApexTrackingApplication
 					.get_instance().getSystemService(
 							Context.LAYOUT_INFLATER_SERVICE);
@@ -97,13 +101,11 @@ public class DetailFragment extends Fragment implements OnClickListener /*
 
 	}
 
-	private void showProgress(final boolean show)
-	{
+	private void showProgress(final boolean show) {
 		// On Honeycomb MR2 we have the ViewPropertyAnimator APIs, which allow
 		// for very easy animations. If available, use these APIs to fade-in
 		// the progress spinner.
-		if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2)
-		{
+		if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
 			int shortAnimTime = ApexTrackingApplication.get_instance()
 					.getResources()
 					.getInteger(android.R.integer.config_shortAnimTime);
@@ -111,11 +113,9 @@ public class DetailFragment extends Fragment implements OnClickListener /*
 			mStatusView.setVisibility(View.VISIBLE);
 			mStatusView.animate().setDuration(shortAnimTime)
 					.alpha(show ? 1 : 0)
-					.setListener(new AnimatorListenerAdapter()
-					{
+					.setListener(new AnimatorListenerAdapter() {
 						@Override
-						public void onAnimationEnd(Animator animation)
-						{
+						public void onAnimationEnd(Animator animation) {
 							mStatusView.setVisibility(show ? View.VISIBLE
 									: View.INVISIBLE);
 						}
@@ -123,18 +123,14 @@ public class DetailFragment extends Fragment implements OnClickListener /*
 
 			ll_root.setVisibility(View.VISIBLE);
 			ll_root.animate().setDuration(shortAnimTime).alpha(show ? 0 : 1)
-					.setListener(new AnimatorListenerAdapter()
-					{
+					.setListener(new AnimatorListenerAdapter() {
 						@Override
-						public void onAnimationEnd(Animator animation)
-						{
+						public void onAnimationEnd(Animator animation) {
 							ll_root.setVisibility(show ? View.INVISIBLE
 									: View.VISIBLE);
 						}
 					});
-		}
-		else
-		{
+		} else {
 			// The ViewPropertyAnimator APIs are not available, so simply show
 			// and hide the relevant UI components.
 			mStatusView.setVisibility(show ? View.VISIBLE : View.INVISIBLE);
@@ -162,8 +158,7 @@ public class DetailFragment extends Fragment implements OnClickListener /*
 
 	@Override
 	public View onCreateView(LayoutInflater inflater, ViewGroup container,
-			Bundle savedInstanceState)
-	{
+			Bundle savedInstanceState) {
 		/* mGestureDetector = new GestureDetector(this); */
 		View view = inflater.inflate(R.layout.detail_fragment, null);
 		sl_root = (ScrollView) view.findViewById(R.id.sl_root);
@@ -177,12 +172,10 @@ public class DetailFragment extends Fragment implements OnClickListener /*
 		mStatusView = view.findViewById(R.id.status);
 		LinearLayout ll = (LinearLayout) view.findViewById(R.id.ll_refresh);
 		Button btn_refresh = (Button) ll.findViewById(R.id.btn_refresh);
-		btn_refresh.setOnClickListener(new View.OnClickListener()
-		{
+		btn_refresh.setOnClickListener(new View.OnClickListener() {
 
 			@Override
-			public void onClick(View v)
-			{
+			public void onClick(View v) {
 				LinearLayout ll = (LinearLayout) ll_root
 						.findViewById(R.id.ll_refresh);
 				ll.setVisibility(View.GONE);
@@ -193,8 +186,7 @@ public class DetailFragment extends Fragment implements OnClickListener /*
 		});
 		FragmentManager fm = getActivity().getSupportFragmentManager();
 		List<Fragment> fragments = fm.getFragments();
-		if (fragments != null)
-		{
+		if (fragments != null) {
 			Log.e("DetailFragment", "fragments count=" + fragments.size());
 			for (int i = 0; i < fragments.size(); i++)
 				Log.e("DetailFragment", "fragments name=" + fragments.size());
@@ -205,8 +197,7 @@ public class DetailFragment extends Fragment implements OnClickListener /*
 		mdataFragment = (DataFragment) fm.findFragmentByTag("data_" + tag);
 
 		// If not retained (or first time running), we need to create it.
-		if (mdataFragment == null)
-		{
+		if (mdataFragment == null) {
 			Log.e("dataFragment creaded ", "tag=data_" + tag);
 			mdataFragment = new DataFragment();
 			// Tell it who it is working with.
@@ -217,23 +208,19 @@ public class DetailFragment extends Fragment implements OnClickListener /*
 		return view;
 	}
 
-	void init(String jstr, LayoutInflater inflater)
-	{
+	void init(String jstr, LayoutInflater inflater) {
 		String TAG = "init@DetailFragment";
 		Log.d(TAG, jstr);
-		try
-		{
+		try {
 			JSONObject jsonObj = new JSONObject(jstr);
 			int group_count = jsonObj.getInt("count");
-			if (group_count == 0)
-			{
+			if (group_count == 0) {
 
 				TextView tv_empty = (TextView) ll_root
 						.findViewById(R.id.tv_empty);
 				tv_empty.setVisibility(View.VISIBLE);
 			}
-			for (int i = 0; i < group_count; i++)
-			{
+			for (int i = 0; i < group_count; i++) {
 				// String key = (String) it.next();
 				// if (key.equals("result"))
 				// continue;
@@ -248,8 +235,7 @@ public class DetailFragment extends Fragment implements OnClickListener /*
 				ll_root.addView(v);
 				String grouptype = groupobj.getString("_type");
 				// groupobj.remove("_type");
-				if (grouptype.equals("mapping"))
-				{
+				if (grouptype.equals("mapping")) {
 					LinearLayout mappingview = (LinearLayout) inflater.inflate(
 							R.layout.key_mapping, null);
 					mappingview.setId(commonUtil.generateViewId());
@@ -257,8 +243,7 @@ public class DetailFragment extends Fragment implements OnClickListener /*
 					ll_root.addView(mappingview);
 
 					int map_count = groupobj.getInt("count");
-					for (int j = 0; j < map_count; j++)
-					{
+					for (int j = 0; j < map_count; j++) {
 						// String keygroup = (String) itgroup.next();
 						JSONObject itemobj = groupobj.getJSONObject("item" + j);
 						String key = (String) itemobj.keys().next();
@@ -281,70 +266,125 @@ public class DetailFragment extends Fragment implements OnClickListener /*
 					//
 					//
 					// }
-				}
-				else
-					if (grouptype.equals("table"))
-					{
-						String content = groupobj.getString("content");
-						WebView wv;
-
-						wv = (WebView) inflater.inflate(R.layout.web_content,
-								null);
-
-						wv.getSettings().setDefaultTextEncodingName("UTF-8");
-						wv.setId(commonUtil.generateViewId());
-						
-						wv.setDownloadListener(new DownloadListener()
-						{
-
-							@Override
-							public void onDownloadStart(String url,
-									String userAgent,
-									String contentDisposition, String mimetype,
-									long contentLength) {
-								Log.d("WebView","Download Action");
-					            Log.i("tag", "url="+url);             
-					            Log.i("tag", "userAgent="+userAgent);  
-					            Log.i("tag", "contentDisposition="+contentDisposition);           
-					            Log.i("tag", "mimetype="+mimetype);  
-					            Log.i("tag", "contentLength="+contentLength);  
-					            Uri uri = Uri.parse(url);  
-					            Intent intent = new Intent(Intent.ACTION_VIEW, uri);  
-					            startActivity(intent); 		
-							}
-							
-						});
-						control.put(v.getId(), wv.getId());
-						wv.loadData(content, mimeType, null);
-
-						// wv.setOnTouchListener(new OnTouchListener()
-						// {
-						// @Override
-						// public boolean onTouch(View v, MotionEvent event)
-						// {
-						//
-						// if (event.getAction() == MotionEvent.ACTION_UP)
-						// sl_root.requestDisallowInterceptTouchEvent(false);
-						// else
-						// sl_root.requestDisallowInterceptTouchEvent(true);
-						//
-						// return false;
-						// }
-						// });
-						ll_root.addView(wv);
-						Log.d("table content", content);
+				} else if (grouptype.equals("table")) {
+					String content = groupobj.getString("content");
+					WebView wv;
 
-					}
-				if (grouptype.equals("list"))
-				{
+					wv = (WebView) inflater.inflate(R.layout.web_content, null);
+
+					wv.getSettings().setDefaultTextEncodingName("UTF-8");
+					wv.setId(commonUtil.generateViewId());
+					wv.setWebViewClient(new MyWebViewClient());
+					wv.setDownloadListener(new DownloadListener() {
+
+						@Override
+						public void onDownloadStart(String url,
+								String userAgent, String contentDisposition,
+								String mimetype, long contentLength) {
+							Log.d("WebView", "Download Action");
+							Log.i("tag", "url=" + url);
+							// Log.i("tag", "userAgent="+userAgent);
+							// Log.i("tag",
+							// "contentDisposition="+contentDisposition);
+							// Log.i("tag", "mimetype="+mimetype);
+							// Log.i("tag", "contentLength="+contentLength);
+							// Uri uri = Uri.parse(url);
+							// Intent intent = new Intent(Intent.ACTION_VIEW,
+							// uri);
+							// startActivity(intent);
+
+							final DownloadManager downloadManager = (DownloadManager) ApexTrackingApplication
+									.get_instance().getSystemService(
+											Context.DOWNLOAD_SERVICE);
+
+							Uri uri = Uri.parse(url);
+							final Request request = new Request(uri);
+
+							// 设置允许使用的网络类型,这里是移动网络和wifi都可以
+							request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_MOBILE
+									| DownloadManager.Request.NETWORK_WIFI);
+
+							// 禁止发出通知,既后台下载,如果要使用这一句必须声明一个权限:android.permission.DOWNLOAD_WITHOUT_NOTIFICATION
+							// request.setShowRunningNotification(false);
+
+							// 不显示下载界面
+							request.setVisibleInDownloadsUi(false);
+							request.setNotificationVisibility(Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
+
+							/*
+							 * 设置下载后文件存放的位置,如果sdcard不可用,那么设置这个将报错,
+							 * 因此最好不设置如果sdcard可用,下载后的文件 在/mnt/sdcard/Android/
+							 * data/packageName/files目录下面
+							 * ,如果sdcard不可用,设置了下面这个将报错,不设置,下载后的文件在/cache这个 目录下面
+							 */
+							// request.setDestinationInExternalFilesDir(this,
+							// null, "tar.apk");
+
+							getActivity();
+							AlertDialog.Builder builder = new Builder(
+									getActivity());
+							builder.setMessage("Click start button to begin download");
+
+							builder.setTitle("Confirm download");
+
+							builder.setPositiveButton("Start",
+									new Dialog.OnClickListener() {
+
+										@Override
+										public void onClick(
+												DialogInterface dialog,
+												int which) {
+											long id = downloadManager
+													.enqueue(request);
+											dialog.dismiss();
+
+										}
+									});
+
+							builder.setNegativeButton("Cancel",
+									new Dialog.OnClickListener() {
+
+										@Override
+										public void onClick(
+												DialogInterface dialog,
+												int which) {
+											dialog.dismiss();
+										}
+									});
+
+							builder.create().show();
+						}
+
+					});
+					control.put(v.getId(), wv.getId());
+					wv.loadData(content, mimeType, null);
+
+					// wv.setOnTouchListener(new OnTouchListener()
+					// {
+					// @Override
+					// public boolean onTouch(View v, MotionEvent event)
+					// {
+					//
+					// if (event.getAction() == MotionEvent.ACTION_UP)
+					// sl_root.requestDisallowInterceptTouchEvent(false);
+					// else
+					// sl_root.requestDisallowInterceptTouchEvent(true);
+					//
+					// return false;
+					// }
+					// });
+					ll_root.addView(wv);
+					Log.d("table content", content);
+
+				}
+				if (grouptype.equals("list")) {
 					LinearLayout listview = (LinearLayout) inflater.inflate(
 							R.layout.list_content, null);
 					listview.setId(commonUtil.generateViewId());
 					control.put(v.getId(), listview.getId());
 					ll_root.addView(listview);
 					long list_count = groupobj.getInt("count");
-					for (int j = 0; j < list_count; j++)
-					{
+					for (int j = 0; j < list_count; j++) {
 						RelativeLayout listitem = (RelativeLayout) inflater
 								.inflate(R.layout.list_item, null);
 
@@ -378,17 +418,14 @@ public class DetailFragment extends Fragment implements OnClickListener /*
 			// {
 			//
 			// }
-		}
-		catch (JSONException e)
-		{
+		} catch (JSONException e) {
 			// TODO Auto-generated catch block
 			e.printStackTrace();
 		}
 	}
 
 	@Override
-	public void onClick(View v)
-	{
+	public void onClick(View v) {
 		View view = ll_root.findViewById(control.get(v.getId()));
 		if (view.getVisibility() == View.VISIBLE)
 			view.setVisibility(View.GONE);
@@ -397,13 +434,11 @@ public class DetailFragment extends Fragment implements OnClickListener /*
 
 	}
 
-	class SearchTask extends AsyncTask<Void, Void, Boolean>
-	{
+	class SearchTask extends AsyncTask<Void, Void, Boolean> {
 		int errorcode;
 
 		@Override
-		protected Boolean doInBackground(Void... params)
-		{
+		protected Boolean doInBackground(Void... params) {
 			Log.e("SearchTask", "doInBackground");
 			if (!Network.NetworkIsAvailable())
 
@@ -412,8 +447,7 @@ public class DetailFragment extends Fragment implements OnClickListener /*
 				return false;
 			}
 			String jstr = Network.get_detail(getArguments());
-			if (jstr == null || jstr.length() <= 0)
-			{
+			if (jstr == null || jstr.length() <= 0) {
 				// Log.d(TAG, "json is wrong");
 
 				errorcode = Network.RESULT_NET_ERROR;
@@ -427,16 +461,13 @@ public class DetailFragment extends Fragment implements OnClickListener /*
 		}
 
 		@Override
-		protected void onPostExecute(Boolean success)
-		{
+		protected void onPostExecute(Boolean success) {
 			Log.i("onPostExecute", "entry");
 			m_task = null;
 			showProgress(false);
 
-			switch (errorcode)
-			{
-			case Network.RESULT_NET_NOTAVAILABLE:
-			{
+			switch (errorcode) {
+			case Network.RESULT_NET_NOTAVAILABLE: {
 				Toast toast = Toast.makeText(
 						ApexTrackingApplication.get_instance(),
 						getText(R.string.msg_connection_none),
@@ -445,8 +476,7 @@ public class DetailFragment extends Fragment implements OnClickListener /*
 				toast.show();
 				break;
 			}
-			case Network.RESULT_NET_ERROR:
-			{
+			case Network.RESULT_NET_ERROR: {
 				Toast toast = Toast.makeText(
 						ApexTrackingApplication.get_instance(),
 						getText(R.string.msg_net_error), Toast.LENGTH_LONG);
@@ -470,8 +500,7 @@ public class DetailFragment extends Fragment implements OnClickListener /*
 				break;
 			}
 
-			if (success)
-			{
+			if (success) {
 				LayoutInflater inflater = (LayoutInflater) ApexTrackingApplication
 						.get_instance().getSystemService(
 								Context.LAYOUT_INFLATER_SERVICE);
@@ -480,9 +509,7 @@ public class DetailFragment extends Fragment implements OnClickListener /*
 														 * getActivity().
 														 * getLayoutInflater()
 														 */);
-			}
-			else
-			{
+			} else {
 				LinearLayout ll = (LinearLayout) ll_root
 						.findViewById(R.id.ll_refresh);
 				ll.setVisibility(View.VISIBLE);
@@ -491,35 +518,57 @@ public class DetailFragment extends Fragment implements OnClickListener /*
 		}
 
 		@Override
-		protected void onCancelled()
-		{
+		protected void onCancelled() {
 			m_task = null;
 			showProgress(false);
 		}
 	}
 
-	public class DataFragment extends Fragment
-	{
+	public class DataFragment extends Fragment {
 
 		String result = null;
 
 		@Override
-		public void onCreate(Bundle savedInstanceState)
-		{
+		public void onCreate(Bundle savedInstanceState) {
 			setRetainInstance(true);
 			super.onCreate(savedInstanceState);
 		}
 
-		public String get_result()
-		{
+		public String get_result() {
 			return result;
 
 		}
 
-		public void put_result(String s)
-		{
+		public void put_result(String s) {
 			result = s;
 		}
 
 	}
+
+	public class MyWebViewClient extends WebViewClient {
+		// 如果页面中链接,如果希望点击链接继续在当前browser中响应,
+		// 而不是新开Android的系统browser中响应该链接,必须覆盖 webview的WebViewClient对象。
+		public boolean shouldOverviewUrlLoading(WebView view, String url) {
+			// L.i("shouldOverviewUrlLoading");
+			view.loadUrl(url);
+			return true;
+		}
+
+		public void onPageStarted(WebView view, String url, Bitmap favicon) {
+			// L.i("onPageStarted");
+			// showProgress();
+		}
+
+		public void onPageFinished(WebView view, String url) {
+			// L.i("onPageFinished");
+			// closeProgress();
+		}
+
+		public void onReceivedError(WebView view, int errorCode,
+				String description, String failingUrl) {
+			// L.i("onReceivedError");
+			// closeProgress();
+		}
+	}
+
 }

+ 3 - 3
Apex/src/com/usai/apex/ServiceLocationFragment.java

@@ -178,9 +178,9 @@ public class ServiceLocationFragment extends Fragment implements
 			marker_detail.put(markertext, detail);
 //			BitmapDescriptor bd=BitmapDescriptorFactory.fromResource(R.drawable.ic_launcher);
 //			Drawable da=getResources().getDrawable(R.drawable.ic_launcher);
-			Bitmap bmp=BitmapFactory.decodeResource(getResources(), R.drawable.ic_map);
-			Log.d("markersize",bmp.getWidth()+","+bmp.getHeight());
-			map.addMarker(new MarkerOptions().icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_launcher))
+//			Bitmap bmp=BitmapFactory.decodeResource(getResources(), R.drawable.ic_map);
+//			Log.d("markersize",bmp.getWidth()+","+bmp.getHeight());
+			map.addMarker(new MarkerOptions().icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_map))
 					.position(
 							new LatLng(Double.parseDouble(point[0]), Double
 									.parseDouble(point[1]))).title(markertext)