From 6242026fdad2397130199608f9787daf61abf380 Mon Sep 17 00:00:00 2001 From: zengfantian Date: Sun, 29 Mar 2015 01:44:57 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=A0=E5=85=A5=E6=AD=A3=E6=96=B9=E5=BD=A2It?= =?UTF-8?q?em=E7=9A=84=E7=BD=91=E6=A0=BC=E7=A4=BA=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AndroidManifest.xml | 14 ++ res/layout/activity_block_gridview.xml | 19 +++ res/layout/activity_block_gridview_item.xml | 34 ++++ res/values-sw600dp/dimens.xml | 4 + res/values-w570dp-land/dimens.xml | 4 + res/values/colors_common.xml | 1 + res/values/dimens_views.xml | 2 + res/values/strings_sample.xml | 1 + .../sample/basic/BasicTestActivity.java | 31 +++- .../SquareAutoFitGridviewActivity.java | 155 ++++++++++++++++++ 10 files changed, 263 insertions(+), 2 deletions(-) create mode 100644 res/layout/activity_block_gridview.xml create mode 100644 res/layout/activity_block_gridview_item.xml create mode 100644 res/values-sw600dp/dimens.xml create mode 100644 res/values-w570dp-land/dimens.xml create mode 100644 src/com/zftlive/android/sample/gridview/SquareAutoFitGridviewActivity.java diff --git a/AndroidManifest.xml b/AndroidManifest.xml index bfa7d8f..6b77f1d 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -577,6 +577,20 @@ android:screenOrientation="portrait" android:windowSoftInputMode="stateAlwaysHidden|adjustResize" /> + + + + + + + + + diff --git a/res/layout/activity_block_gridview.xml b/res/layout/activity_block_gridview.xml new file mode 100644 index 0000000..8ca7654 --- /dev/null +++ b/res/layout/activity_block_gridview.xml @@ -0,0 +1,19 @@ + + + + \ No newline at end of file diff --git a/res/layout/activity_block_gridview_item.xml b/res/layout/activity_block_gridview_item.xml new file mode 100644 index 0000000..bd20f65 --- /dev/null +++ b/res/layout/activity_block_gridview_item.xml @@ -0,0 +1,34 @@ + + + + + + + + + + \ No newline at end of file diff --git a/res/values-sw600dp/dimens.xml b/res/values-sw600dp/dimens.xml new file mode 100644 index 0000000..d29c64c --- /dev/null +++ b/res/values-sw600dp/dimens.xml @@ -0,0 +1,4 @@ + + + 140dp + \ No newline at end of file diff --git a/res/values-w570dp-land/dimens.xml b/res/values-w570dp-land/dimens.xml new file mode 100644 index 0000000..d29c64c --- /dev/null +++ b/res/values-w570dp-land/dimens.xml @@ -0,0 +1,4 @@ + + + 140dp + \ No newline at end of file diff --git a/res/values/colors_common.xml b/res/values/colors_common.xml index a454da2..e70ee0d 100644 --- a/res/values/colors_common.xml +++ b/res/values/colors_common.xml @@ -148,4 +148,5 @@ #00008B #000080 #000000 + #70000000 diff --git a/res/values/dimens_views.xml b/res/values/dimens_views.xml index 75904e3..912901d 100644 --- a/res/values/dimens_views.xml +++ b/res/values/dimens_views.xml @@ -13,4 +13,6 @@ 135dp 40dp + + 140dp \ No newline at end of file diff --git a/res/values/strings_sample.xml b/res/values/strings_sample.xml index 2ab3dbc..55ced1a 100644 --- a/res/values/strings_sample.xml +++ b/res/values/strings_sample.xml @@ -23,6 +23,7 @@ 下拉ScrollView背景回弹效果 FadingActionBar官方DEMO PullToReresh官方DEMO + 正方形Item的网格 diff --git a/src/com/zftlive/android/sample/basic/BasicTestActivity.java b/src/com/zftlive/android/sample/basic/BasicTestActivity.java index 4c55817..3d1473b 100644 --- a/src/com/zftlive/android/sample/basic/BasicTestActivity.java +++ b/src/com/zftlive/android/sample/basic/BasicTestActivity.java @@ -1,12 +1,14 @@ package com.zftlive.android.sample.basic; import android.content.Context; +import android.util.Log; import android.view.View; import android.widget.Button; import com.zftlive.android.R; import com.zftlive.android.base.BaseActivity; import com.zftlive.android.common.ActionBarManager; +import com.zftlive.android.tools.ToolDateTime; import com.zftlive.android.tools.ToolLocation; import com.zftlive.android.tools.ToolPhone; @@ -19,6 +21,8 @@ import com.zftlive.android.tools.ToolPhone; public class BasicTestActivity extends BaseActivity implements View.OnClickListener{ private Button btn_opengps, btn_call,btn_contact,btn_setting,btn_carema,btn_photo; + private boolean flag = true; + private Thread task = null; @Override public int bindLayout() { @@ -48,7 +52,13 @@ public class BasicTestActivity extends BaseActivity implements View.OnClickListe @Override public void doBusiness(Context mContext) { - + + + + task = new Thread(new ThreadTask()); + task.start(); + + } @Override @@ -80,11 +90,28 @@ public class BasicTestActivity extends BaseActivity implements View.OnClickListe ToolPhone.toCameraActivity(getContext(), 88); break; case R.id.btn_photo: - ToolPhone.toImagePickerActivity(getContext(), 77); +// ToolPhone.toImagePickerActivity(getContext(), 77); + flag = false; + task.interrupt(); break; default: break; } } + + public class ThreadTask implements Runnable{ + + @Override + public void run() { + while(flag){ + Log.e(TAG, "Thread ID "+Thread.currentThread().getId() + "-->"+ToolDateTime.gainCurrentDate("yyyy-MM-dd HH:mm:ss")); + try { + Thread.sleep(3 * 1000); + } catch (InterruptedException e) { + Log.e(TAG, "线程被打断!"); + } + } + } + } } diff --git a/src/com/zftlive/android/sample/gridview/SquareAutoFitGridviewActivity.java b/src/com/zftlive/android/sample/gridview/SquareAutoFitGridviewActivity.java new file mode 100644 index 0000000..d5c4d76 --- /dev/null +++ b/src/com/zftlive/android/sample/gridview/SquareAutoFitGridviewActivity.java @@ -0,0 +1,155 @@ +package com.zftlive.android.sample.gridview; + +import java.util.LinkedHashMap; +import java.util.Map; + +import android.content.Context; +import android.view.View; +import android.view.ViewGroup; +import android.widget.AdapterView; +import android.widget.AdapterView.OnItemClickListener; +import android.widget.GridView; +import android.widget.ImageView; +import android.widget.TextView; + +import com.zftlive.android.R; +import com.zftlive.android.base.BaseActivity; +import com.zftlive.android.base.BaseAdapter; +import com.zftlive.android.common.ActionBarManager; +import com.zftlive.android.tools.ToolAlert; +import com.zftlive.android.tools.ToolImage; + +/** + * 正方形Item的gridview样例 + * @author 曾繁添 + * @version 1.0 + * + */ +public class SquareAutoFitGridviewActivity extends BaseActivity { + + private GridView gv_square; + private MyGridAdapter mAdapter; + private String imageURLs[] = new String[]{ + "http://www.daqianduan.com/wp-content/uploads/2014/12/kanjian.jpg", + "http://www.daqianduan.com/wp-content/uploads/2014/11/capinfo.jpg", + "http://www.daqianduan.com/wp-content/uploads/2014/11/mi-2.jpg", + "http://www.daqianduan.com/wp-content/uploads/2014/10/dxy.cn_.png", + "http://www.daqianduan.com/wp-content/uploads/2014/10/xinhua.jpg", + "http://www.daqianduan.com/wp-content/uploads/2014/09/job.jpg", + "http://www.daqianduan.com/wp-content/uploads/2013/06/ctrip.png", + "http://www.daqianduan.com/wp-content/uploads/2014/09/ideabinder.png", + "http://www.daqianduan.com/wp-content/uploads/2014/05/ymatou.png", + "http://www.daqianduan.com/wp-content/uploads/2014/03/west_house.jpg", + "http://www.daqianduan.com/wp-content/uploads/2014/03/youanxianpin.jpg", + "http://www.daqianduan.com/wp-content/uploads/2014/02/jd.jpg", + "http://www.daqianduan.com/wp-content/uploads/2013/11/wealink.png", + "http://www.daqianduan.com/wp-content/uploads/2013/09/exmail.jpg", + "http://www.daqianduan.com/wp-content/uploads/2013/09/alipay.png", + "http://www.daqianduan.com/wp-content/uploads/2013/08/huaqiangbei.png", + "http://www.daqianduan.com/wp-content/uploads/2013/06/ctrip.png", + "http://www.daqianduan.com/static/img/thumbnail.png", + "http://www.daqianduan.com/wp-content/uploads/2013/06/bingdian.png", + "http://www.daqianduan.com/wp-content/uploads/2013/04/ctrip-wireless.png" + }; + private String titles[] = new String[]{ + "前端开发工程师", + "Web前端工程师(北京-海淀)", + "更关注用户前端体验(北京)", + "丁香园求多枚Web", + "新华网招中高级", + "好声音母公司梦响强音文化", + "携程网国际业务部", + "ideabinder", + "海外购物公司洋码头", + "金山软件-西山居", + "优安鲜品招Web前端", + "京东招聘Web前端开", + "若邻网(上海)急聘程师", + "腾讯广州研发线邮箱部)", + "支付宝招募资深交互设计师", + "华强北商城招聘前端开发工程师", + "携程(上海)框架研发部", + "阿里巴巴中文站招聘前端开发", + "多途网络科端开发工程师", + "携程无线前端团队招聘 直接" + }; + + @Override + public int bindLayout() { + return R.layout.activity_block_gridview; + } + + @Override + public void initView(View view) { + gv_square = (GridView) findViewById(R.id.gv_square); + gv_square.setOnItemClickListener(new OnItemClickListener() { + + @Override + public void onItemClick(AdapterView parent, View view, + int position, long id) { + Map itemData = (Map)parent.getItemAtPosition(position); + ToolAlert.toastShort(getContext(), itemData.get("title")+""); + } + }); + mAdapter = new MyGridAdapter(); + ToolImage.initImageLoader(getContext()); + + //初始化带返回按钮的标题栏 + String strCenterTitle = getResources().getString(R.string.SquareAutoFitGridviewActivity); + ActionBarManager.initBackTitle(getContext(), getActionBar(), strCenterTitle); + } + + @Override + public void doBusiness(Context mContext) { + //构造数据 + for (int i = 0; i < 20; i++) { + Map rowData = new LinkedHashMap(); + rowData.put("imageUrl", imageURLs[i]); + rowData.put("title", titles[i]); + mAdapter.addItem(rowData); + } + gv_square.setAdapter(mAdapter); + mAdapter.notifyDataSetChanged(); + } + + @Override + public void resume() { + + } + + @Override + public void destroy() { + ToolImage.clearCache(); + } + + /** + * 网格适配器 + * + */ + protected class MyGridAdapter extends BaseAdapter{ + + @Override + public View getView(int position, View convertView, ViewGroup parent) { + ViewHolder mViewHolder; + if(null == convertView){ + convertView = getLayoutInflater().inflate(R.layout.activity_block_gridview_item, null); + mViewHolder = new ViewHolder(); + mViewHolder.iv_icon = (ImageView)convertView.findViewById(R.id.iv_icon); + mViewHolder.tv_title = (TextView)convertView.findViewById(R.id.tv_title); + convertView.setTag(mViewHolder); + }else{ + mViewHolder = (ViewHolder)convertView.getTag(); + } + //设置数据 + Map rowData = (Map)getItem(position); + ToolImage.getImageLoader().displayImage((String)rowData.get("imageUrl"), mViewHolder.iv_icon); + mViewHolder.tv_title.setText((String)rowData.get("title")); + return convertView; + } + + class ViewHolder{ + ImageView iv_icon; + TextView tv_title; + } + } +}