android应用市场源码发布【第二天】 【第一小节】
2012-10-11 16:17
211 查看
废话不多说 下面是【第一天】和【第二天】 这次代码比较多 所以用小节来标识
【第一天】:http://blog.csdn.net/zxciop110/article/details/8048645
【第二天】:http://blog.csdn.net/zxciop110/article/details/8061010
产品下载地址 :http://download.csdn.net/detail/zxciop110/4625423
这次是进入首页了:
先看图:
看图讲
这个是类似TAB一样 用ActivityGroup实现 中间图是一个ViewFlipper 下面就是用gridView
先看首页布局:
布局没什么可讲的 主要是ViewFlipper动态加载VIEW
现在看首页代码:
那些定义不用多讲 大家一看就明白
重点:ViewPager
定义一些标识
arrayList 这里BannerBitmap封装好了
这里GamesBanner = WebHelper.getBanner(context)请求服务器 来得到图片
监听开始轮播 :
定义 这里就是gridview 当我们点击某一个ITEM的时候跳转到详细页 下面一些方法做了封装 你们会的 我就不发那一部分了 无非就是GET SET
先发到这里后面还会继续 因为还有700多行 首页我就大概一下吧 因为要讲到明天也讲不完 我要顺一下这里 有点乱!
【第一天】:http://blog.csdn.net/zxciop110/article/details/8048645
【第二天】:http://blog.csdn.net/zxciop110/article/details/8061010
产品下载地址 :http://download.csdn.net/detail/zxciop110/4625423
这次是进入首页了:
先看图:
看图讲
这个是类似TAB一样 用ActivityGroup实现 中间图是一个ViewFlipper 下面就是用gridView
先看首页布局:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="@drawable/bg_index" android:orientation="vertical" android:weightSum="1"> <RelativeLayout android:layout_width="fill_parent" android:background="@drawable/home_top" android:layout_height="wrap_content"> <ImageView android:id="@+id/iv_n" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/logo_one"> </ImageView> <ImageButton android:id="@+id/imageButton1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_marginRight="50dp" android:background="@drawable/button_style" > </ImageButton> <ImageButton android:id="@+id/imdownload" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBottom="@+id/ion1" android:layout_alignParentRight="true" android:background="@drawable/share_one" /> </RelativeLayout> <RelativeLayout android:layout_width="fill_parent" android:layout_height="35dp"> <Button android:id="@+id/btn_sorting" android:layout_width="80dip" android:layout_height="fill_parent" android:layout_alignBottom="@+id/classification" android:background="@drawable/wei" android:text="@string/classification" android:textColor="#FFFFFF" android:textSize="15dp"> </Button> <Button android:id="@+id/btn_date" android:layout_width="80dip" android:layout_height="fill_parent" android:layout_alignParentRight="true" android:background="@drawable/wei" android:text="@string/update" android:textColor="#FFFFFF" android:textSize="15dp"> </Button> <Button android:id="@+id/btn_groom" android:layout_width="80dip" android:layout_height="fill_parent" android:layout_toRightOf="@+id/btn_sorting" android:background="@drawable/wei" android:text="@string/recommend" android:textColor="#FFFFFF" android:textSize="15dp"> </Button> <Button android:id="@+id/btn_hot" android:layout_width="80dip" android:layout_height="fill_parent" android:layout_toRightOf="@+id/btn_groom" android:background="@drawable/wei" android:text="@string/hot" android:textColor="#FFFFFF" android:textSize="15dp" android:layout_toLeftOf="@+id/btn_date"> </Button> </RelativeLayout> <!-- 中间动态加载View --> <ViewFlipper android:id="@+id/body" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical"> </ViewFlipper> <FrameLayout android:layout_width="fill_parent" android:layout_height="140dip"> <android.support.v4.view.ViewPager android:id="@+id/vp" android:layout_width="fill_parent" android:layout_height="fill_parent" /> <LinearLayout android:layout_width="fill_parent" android:layout_height="35dip" android:layout_gravity="bottom" android:background="#33000000" android:gravity="center" android:orientation="vertical"> <TextView android:id="@+id/tv_title" android:layout_gravity="left" android:layout_marginTop="6dip" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="最近超过亿万下载量游戏推荐" android:textColor="#ffffff" /> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="100dip" > <View android:id="@+id/v_dot0" style="@style/dot_style" android:background="@drawable/dot_focused" /> <View android:id="@+id/v_dot1" style="@style/dot_style" /> <View android:id="@+id/v_dot2" style="@style/dot_style" /> <!-- <View android:id="@+id/v_dot3" style="@style/dot_style" /> <View android:id="@+id/v_dot4" style="@style/dot_style" /> --> </LinearLayout> </LinearLayout> </FrameLayout> <GridView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/gridview" android:layout_width="fill_parent" android:background="@drawable/home_backdrops" android:columnWidth="90dp" android:scrollbars="none" android:listSelector="#00000000" android:gravity="center" android:horizontalSpacing="10dp" android:numColumns="2" android:stretchMode="columnWidth" android:verticalSpacing="10dp" android:layout_height="fill_parent"/> </LinearLayout>
布局没什么可讲的 主要是ViewFlipper动态加载VIEW
现在看首页代码:
* MyTab.java * com.yzz.twan * * Function: TODO * * ver date author * ────────────────────────────────── * 2012-6-25 HP * * Copyright (c) 2012, TNT All Rights Reserved. */ package com.yzz.twan; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.Timer; import java.util.TimerTask; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; import android.app.ActivityGroup; import android.app.AlertDialog; import android.app.AlertDialog.Builder; import android.app.LocalActivityManager; import android.app.ProgressDialog; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.ServiceConnection; import android.content.SharedPreferences; import android.content.SharedPreferences.Editor; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.net.Uri; import android.net.wifi.WifiInfo; import android.net.wifi.WifiManager; import android.os.Bundle; import android.os.Environment; import android.os.Handler; import android.os.IBinder; import android.os.Message; import android.os.Parcelable; import android.support.v4.view.PagerAdapter; import android.support.v4.view.ViewPager; import android.support.v4.view.ViewPager.OnPageChangeListener; import android.telephony.TelephonyManager; import android.util.Log; import android.view.GestureDetector; import android.view.GestureDetector.OnGestureListener; import android.view.KeyEvent; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuItem; import android.view.MotionEvent; import android.view.View; import android.view.View.OnClickListener; import android.view.View.OnTouchListener; import android.view.Window; import android.widget.AbsListView; import android.widget.AbsListView.OnScrollListener; import android.widget.AdapterView; import android.widget.Button; import android.widget.GridView; import android.widget.ImageButton; import android.widget.ImageView; import android.widget.ImageView.ScaleType; import android.widget.LinearLayout; import android.widget.ProgressBar; import android.widget.TextView; import android.widget.Toast; import android.widget.ViewFlipper; import com.yzz.twan.adapter.GamesInfoListAdapter; import com.yzz.twan.bo.BannerBitmap; import com.yzz.twan.bo.GameInfo; import com.yzz.twan.log.Logger; import com.yzz.twan.util.WebHelper; /** * ClassName:MyTab Function: TODO ADD FUNCTION Reason: TODO ADD REASON * * @author weijinpeng * @version * @since Ver 1.1 * @see */ public class MyTab extends ActivityGroup implements OnClickListener, OnGestureListener, OnTouchListener, OnScrollListener { private DownloadService.DownloadBinder binder;// 后台下载 private boolean binded; private ViewPager viewPager;// 滑动组 private List<ImageView> imageViews;// 集合 // private int[] imageResId;// ID private List<View> dots;// z正文 private TextView tv_title; public ArrayList<Bitmap> imageList = new ArrayList<Bitmap>(); private int currentItem = 0;// 索引 private ScheduledExecutorService scheduledExecutorService; private Button btn_sorting, btn_groom, btn_hot, btn_date;// 按钮 private ImageButton imdownload,imageButton1; private ImageView appraise_a, appraise_b, appraise_c, appraise_d; public static ViewFlipper linearLayout;// 加载布局 GestureDetector mGestureDetector;// shoushi public static LocalActivityManager m_ActivityManager;// 消息 private static final String TAG = "IndexActivity"; private ProgressBar pb;// 进度条 private Thread mThread; public Logger logger; private String url = "http://61.155.165.32/shuixiyue/pic/item/f141247490d0e96fb251b963.jpg"; MyAutoUpdate mMyAutoUpdate;// 新版本 private File cache; // 缓存目录 private static final int MSG_SUCCESS = 0;//获取图片成功的标识 private static final int MSG_FAILURE = 1;//获取图片失败的标识 private ProgressDialog progressDialog; int str_id = 0; private int imgFlag = 0; public Context context; private static Boolean isExit = false; private static Boolean hasTask = false; public static final int ITEM0=Menu.FIRST;//系统值 public static final int ITEM1=Menu.FIRST+1; public static final int ITEM2=Menu.FIRST+2; public static final int ITEM3=Menu.FIRST+3; ArrayList<BannerBitmap> GamesBanner = new ArrayList<BannerBitmap>(); BannerBitmap bannerbitmap; int[] imageResId = new int[3];// ID // titles; // 标题 private String[] titles = new String[imageResId.length]; // titles[0] = "最新游戏推荐给各位"; // titles[1] = "愤怒的小鸟现在很火"; // titles[2] = "切西瓜目前下载量X"; // WeDialog wd; Timer iExit = new Timer(); TimerTask task = new TimerTask(){ @Override public void run() { isExit = false; hasTask = true; // TODO Auto-generated method stub } }; // 切换当前图片 private Handler handler = new Handler() { public void handleMessage(android.os.Message msg) { viewPager.setCurrentItem(currentItem);// 切换当前显示的图片 }; }; private Handler mHandler = new Handler(){ @Override public void handleMessage(Message msg) { switch (msg.what){ case MSG_SUCCESS: //成功返回 adapter.setList(list); if(page == "1"){ gridview.setAdapter(adapter); } else { adapter.notifyDataSetChanged(); } progressDialog.dismiss(); // mMediaPlayer.isPlaying(); // mMediaPlayer = MediaPlayer.create(MyTab.this, R.raw.music); // mMediaPlayer = MediaPlayer.create(MyTab.this, R.raw.music); break; case MSG_FAILURE: //无法连接服务器 progressDialog.dismiss(); AlertDialog.Builder builder = new Builder(MyTab.this); builder.setTitle("失败"); builder.setPositiveButton("确定",null); builder.setIcon(R.drawable.icon); builder.setMessage("无法连接服务器,请检查网络设置"); builder.show(); break; } } }; private Handler handlers = new Handler() { public void handleMessage(android.os.Message msg) { int progress = msg.arg1; // TextVAIEW }; }; private ServiceConnection conn = new ServiceConnection() { @Override public void onServiceConnected(ComponentName name, IBinder service) { binder = (DownloadService.DownloadBinder) service; binded = true; // 开始下载 binder.start(); listenProgress(); } @Override public void onServiceDisconnected(ComponentName name) { // TODO Auto-generated method stub } }; // -----------------ccf private GridView gridview; private ArrayList<GameInfo> list; private GamesInfoListAdapter adapter; // --------------------- @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); this.requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.home_tab); progressDialog = ProgressDialog.show(MyTab.this, "请稍等...", "获取数据中...", true); progressDialog.setIcon(R.drawable.icon); // notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); progressDialog.setCancelable(true);//来控制和返回键关闭对框框,主要的目的在多线程的应用 progressDialog.setCanceledOnTouchOutside(false);//防止提示框运行期间点击别的地方消失提示框 if(mThread == null|| mThread != null){ mThread = new Thread(runnable); mThread.start(); }else{ } // cache = new File(Environment.getExternalStorageDirectory(),"test"); // "/mnt/sdcard/test/" if(!cache.exists()){ cache.mkdirs(); } list = new ArrayList<GameInfo>(); imageResId = new int[] { R.drawable.banner1, R.drawable.banner2, R.drawable.banner3, }; // titles[3] = "目前看到的是热门游戏"; // titles[4] = "96盒子特别推荐"; imageViews = new ArrayList<ImageView>(); // 初始化图片资源 for (int i = 0; i < imageResId.length; i++) { ImageView imageView = new ImageView(this); imageView.setImageResource(imageResId<i>); // imageView.setImageBitmap(imageResId<i>); imageView.setScaleType(ScaleType.CENTER_CROP); imageViews.add(imageView); } dots = new ArrayList<View>(); dots.add(findViewById(R.id.v_dot0)); dots.add(findViewById(R.id.v_dot1)); dots.add(findViewById(R.id.v_dot2)); // dots.add(findViewById(R.id.v_dot3)); // dots.add(findViewById(R.id.v_dot4)); tv_title = (TextView) findViewById(R.id.tv_title); tv_title.setText(titles[0]);// 设置 viewPager = (ViewPager) findViewById(R.id.vp); viewPager.setAdapter(new MyAdapter());// 设置填充页面 // 设置监听 viewPager.setOnPageChangeListener(new MyPageChangeListener()); // 得到需要加载的布局 linearLayout = (ViewFlipper) findViewById(R.id.body); m_ActivityManager = getLocalActivityManager(); // 得到对象 btn_sorting = (Button) findViewById(R.id.btn_sorting); btn_groom = (Button) findViewById(R.id.btn_groom); btn_hot = (Button) findViewById(R.id.btn_hot); btn_date = (Button) findViewById(R.id.btn_date); imdownload = (ImageButton) findViewById(R.id.imdownload); imageButton1 = (ImageButton) findViewById(R.id.imageButton1); // 监听 btn_sorting.setOnClickListener(this); imageButton1.setOnClickListener(this);//搜索 btn_groom.setOnClickListener(this); btn_hot.setOnClickListener(this); btn_date.setOnClickListener(this); imdownload.setOnClickListener(this); btn_groom.setBackgroundResource(R.drawable.weione); btn_groom.setTextColor(this.getResources().getColor(R.color.black)); mGestureDetector = new GestureDetector((OnGestureListener) this); linearLayout.setOnTouchListener(this); linearLayout.setLongClickable(true); // 暂时注释 // 窗体创建之后, 查询数据库是否有未完成任务, 如果有, 创建进度条等组件, 继续下载 // List<String> lists = new InfoDao(this).queryUndone(); // Log.i("TAG", "InfoDao"+lists); // for(String path : lists) // createDownload(path); // mGestureDetector = new GestureDetector(new MyGestureListener()); // 事件监听 // install_a.setOnClickListener(this); // 安装新版本暂时注销 // mMyAutoUpdate.getCurrentVersion(); mMyAutoUpdate = new MyAutoUpdate(MyTab.this); mMyAutoUpdate.check(); gridview = (GridView) findViewById(R.id.gridview); gridview.setOnScrollListener(this); adapter = new GamesInfoListAdapter(this); // Log.i("TAG", "adapter"+adapter); gridview.setOnItemClickListener(new GridView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { // int index = position + 1;// id是从0开始的,所以需要+1 // Intent intent = new Intent(); // intent.setClass(MyTab.this, GalleryActivity.class); // intent.putExtra("position", index); // startActivity(intent); // Toast.makeText(getApplicationContext(), "你按下了选项:" + index, 0).show(); // Log.v("wjp", "124234"); GameInfo info = null; info = list.get(position); Intent intent = new Intent(); intent.setClass(MyTab.this, GamesInfoDetail.class); Bundle mBundle = new Bundle(); mBundle.putString("ID", info.getGameid()); mBundle.putString("gameName", info.getName()); mBundle.putString("typeName", info.getTypeName()); mBundle.putString("authorName", info.getAuthor()); mBundle.putString("score", info.getSourceScore()); mBundle.putString("logo_url", info.getLogo_url()); mBundle.putString("size", info.getSize()); mBundle.putString("desc", info.getDescription()); mBundle.putString("download_url", info.getDownLoadFileUrl()); intent.putExtras(mBundle); startActivity(intent); // Toast.makeText(getApplicationContext(), "你按下了选项:" + position, 0).show(); // Log.v(TAG, "onItemClick() gameInfo:" +info); } }); // wd = new WeDialog(this); // adapter.setList(list); //// Log.v("wjpp", "list"+list); // gridview.setAdapter(adapter); // list = WebHelper.getGameList(MyTab.this, "recommend", "1", "8", null, null); }</i></i>
那些定义不用多讲 大家一看就明白
重点:ViewPager
定义一些标识
private String[] titles; // 图片标题 private List<ImageView> imageViews; // private int[] imageResId; // 图片ID private List<View> dots; // 图片标题正文的那些点 private TextView tv_title; private int currentItem = 0; // 当前图片的索引号
arrayList 这里BannerBitmap封装好了
ArrayList<BannerBitmap> GamesBanner = new ArrayList<BannerBitmap>(); BannerBitmap bannerbitmap; Bitmap [] imageResId = new Bitmap[3];// ID/ ID
这里GamesBanner = WebHelper.getBanner(context)请求服务器 来得到图片
GamesBanner = WebHelper.getBanner(context); if(GamesBanner !=null){ for(int i=0;i<GamesBanner.size();i++){ bannerbitmap = new BannerBitmap(); bannerbitmap = GamesBanner.get(i); // Log.d(TAG,"bannerbitmap-------" +bannerbitmap.toString()); titles<i> = bannerbitmap.getSortNum(); // imageResId<i> = WebHelper.getHttpBitmap(bannerbitmap.getKeyWord()); // } }else { Log.i("TAG", ""); // return; }</i></i>
监听开始轮播 :
viewPager.setAdapter(new MyAdapter());// 设置填充ViewPager页面的适配器 // 设置一个监听器,当ViewPager中的页面改变时调用 viewPager.setOnPageChangeListener(new MyPageChangeListener()); } @Override protected void onStart() { scheduledExecutorService = Executors.newSingleThreadScheduledExecutor(); // 当Activity显示出来后,每两秒钟切换一次图片显示 scheduledExecutorService.scheduleAtFixedRate(new ScrollTask(), 1, 2, TimeUnit.SECONDS); super.onStart(); } @Override protected void onStop() { // 当Activity不可见的时候停止切换 scheduledExecutorService.shutdown(); super.onStop(); } /** * 换行切换任务 * * @author Administrator * */ private class ScrollTask implements Runnable { public void run() { synchronized (viewPager) { System.out.println("currentItem: " + currentItem); currentItem = (currentItem + 1) % imageViews.size(); handler.obtainMessage().sendToTarget(); // 通过Handler切换图片 } } } /** * 当ViewPager中页面的状态发生改变时调用 * * @author Administrator * */ private class MyPageChangeListener implements OnPageChangeListener { private int oldPosition = 0; /** * This method will be invoked when a new page becomes selected. * position: Position index of the new selected page. */ public void onPageSelected(int position) { currentItem = position; // tv_title.setText(titles[position]); dots.get(oldPosition).setBackgroundResource(R.drawable.dot_normal); dots.get(position).setBackgroundResource(R.drawable.dot_focused); oldPosition = position; } public void onPageScrollStateChanged(int arg0) { } public void onPageScrolled(int arg0, float arg1, int arg2) { } } /** * 填充ViewPager页面的适配器 * * @author Administrator * */ private class MyAdapter extends PagerAdapter { @Override public int getCount() { Log.i("TAG","imageResId.length"); return imageResId.length; } @Override public Object instantiateItem(View arg0, int arg1) { ((ViewPager) arg0).addView(imageViews.get(arg1)); return imageViews.get(arg1); } @Override public void destroyItem(View arg0, int arg1, Object arg2) { ((ViewPager) arg0).removeView((View) arg2); } @Override public boolean isViewFromObject(View arg0, Object arg1) { return arg0 == arg1; } @Override public void restoreState(Parcelable arg0, ClassLoader arg1) { } @Override public Parcelable saveState() { return null; } @Override public void startUpdate(View arg0) { } @Override public void finishUpdate(View arg0) { } }
定义 这里就是gridview 当我们点击某一个ITEM的时候跳转到详细页 下面一些方法做了封装 你们会的 我就不发那一部分了 无非就是GET SET
gridview = (GridView) findViewById(R.id.gridview); gridview.setOnScrollListener(this); adapter = new GamesInfoListAdapter(this); // Log.i("TAG", "adapter"+adapter); gridview.setOnItemClickListener(new GridView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { // int index = position + 1;// id是从0开始的,所以需要+1 // Intent intent = new Intent(); // intent.setClass(MyTab.this, GalleryActivity.class); // intent.putExtra("position", index); // startActivity(intent); // Toast.makeText(getApplicationContext(), "你按下了选项:" + index, 0).show(); // Log.v("wjp", "124234"); GameInfo info = null; info = list.get(position); Intent intent = new Intent(); intent.setClass(MyTab.this, GamesInfoDetail.class); Bundle mBundle = new Bundle(); mBundle.putString("ID", info.getGameid()); mBundle.putString("gameName", info.getName()); mBundle.putString("typeName", info.getTypeName()); mBundle.putString("authorName", info.getAuthor()); mBundle.putString("score", info.getSourceScore()); mBundle.putString("logo_url", info.getLogo_url()); mBundle.putString("size", info.getSize()); mBundle.putString("desc", info.getDescription()); mBundle.putString("download_url", info.getDownLoadFileUrl()); intent.putExtras(mBundle); startActivity(intent); // Toast.makeText(getApplicationContext(), "你按下了选项:" + position, 0).show(); // Log.v(TAG, "onItemClick() gameInfo:" +info); } });
先发到这里后面还会继续 因为还有700多行 首页我就大概一下吧 因为要讲到明天也讲不完 我要顺一下这里 有点乱!
相关文章推荐
- android应用市场源码发布【第二天】
- 如何发布一款Android应用到安卓市场
- Android应用发布市场平台
- Android应用市场和发布流程参考
- Android 发布应用到市场
- Android应用市场发布经验总结
- Android开发如果要发布到应用市场需要哪些条件呢
- android应用如何在发布市场时关掉所有的Log日志输出
- android签名打包发布到应用市场
- 如何将Android应用发布到Google Play(Android Market)官方市场
- 上传发布Android应用到各大开放平台市场上去
- andriod应用市场源码发布【第一天】
- ionic 热更新-不发布应用市场动态更新APP源码
- Android应用市场发布
- 发布应用到Android市场 -- Android Essentials: Submitting Your Application to the Android Market
- Android 发布应用到市场
- android 需要发布的应用市场
- Android应用市场发布经验总结
- Android应用市场发布经验总结
- Android应用市场App发布