▍1. android 自定义radiogroup实现源码下载-listview+radiobutton实现
listview radiobutton 实现 浅显易懂
listview radiobutton 实现 浅显易懂
Android版视频会议是Web版视频会议系统的移动版,它构建在Android手机上,主要提供Web版视频会议系统中的一系列的提醒功能,如站内短信、视频会议提醒以及待办事宜等。
android动态壁纸中的水波纹效果,采用opengl中的shader实现
[实例简介]开发mp4 [实例截图] [核心代码]package com.example.mp4;import java.io.File;import java.util.Vector;import android.app.Activity;import android.content.Intent;import android.os.Bundle;import android.view.KeyEvent;import android.view.View;import android.view.View.OnClickListener;import android.view.ViewGroup;import android.widget.AdapterView;import android.widget.AdapterView.OnItemClickListener;import android.widget.BaseAdapter;import android.widget.Button;import android.widget.EditText;import android.widget.ImageView;import android.widget.ListView;import android.widget.TextView;import android.widget.Toast;public class MyFileActivity extends Activity { private final String[] FILE_MapTable = { ".3gp", ".mov", ".avi", ".rmvb", ".wmv", ".mp3", ".mp4" }; private Vector items = null;// 存放显示的名称 private Vector paths = null;// 存放文件路径 private Vector sizes = null;// 存放文件大小 private String rootPath = "/mnt/sdcard";// 起始文件夹 private EditText pathEditText;// 路径 private Button queryButton;// 查询按钮 private ListView fileListView;// 文件列表 @Override protected void onCreate(Bundle icicle) { // TODO Auto-generated method stub super.onCreate(icicle); setContentView(R.layout.myfile); this.setTitle("多媒体文件浏览"); pathEditText = (EditText) findViewById(R.id.path_edit); queryButton = (Button) findViewById(R.id.qry_button); fileListView = (ListView) findViewById(R.id.file_listview); // 单击按钮事件 queryButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub File file = new File(pathEditText.getText().toString()); if (file.exists()) { if (file.isFile()) { // 如果是媒体文件直接打开 openFile(pathEditText.getText().toString()); } else { // 打开目录下的文件 getFileDir(pathEditText.getText().toString()); } } else { Toast.makeText(MyFileActivity.this, "找不到位置,请确定位置是否正确!", Toast.LENGTH_SHORT).show(); } } }); //设置listitem中的文件被单击时要做的动作 fileListView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView arg0, View arg1, int position, long arg3) { // TODO Auto-generated method stub fileOrDir(paths.get(position)); } }); //打开默认文件夹 getFileDir(rootPath); } //重写返回键功能是否为back public boolean onKeyDown(int keyCode,KeyEvent event){ //判断触发键是否为back键 if(keyCode == KeyEvent.KEYCODE_BACK){ pathEditText = (EditText)findViewById(R.id.path_edit); File file = new File(pathEditText.getText().toString()); if(rootPath.equals(pathEditText.getText().toString().trim())){ return super.onKeyDown(keyCode, event); }else{ getFileDir(file.getParent()); return true; } }else{ return super.onKeyDown(keyCode, event); } } //处理文件或目录的方法 private void fileOrDir(String path){ File file = new File(path); if(file.isDirectory()){ getFileDir(file.getPath()); }else{ openFile(path); } }//获取文件结构的方法 private void getFileDir(String filePath) { // TODO Auto-generated method stub pathEditText.setText(filePath); items = new Vector(); paths = new Vector(); sizes = new Vector(); File f = new File(filePath); File[] files = f.listFiles(); if (files != null) { /* 将所有文件添加到ArrayList中 */ for (int i = 0; i < files.length; i ) { if (files[i].isDirectory()) { items.add(files[i].getName()); paths.add(files[i].getPath()); sizes.add(""); } } for (int i = 0; i < files.length; i ) { if (files[i].isFile()) { String fileName = files[i].getName(); int index = fileName.lastIndexOf("."); if (index > 0) { String endName = fileName.substring(index, fileName.length()).toLowerCase(); String type = null; for(int x=0;i< FILE_MapTable.length;x ){ //符合预先定义的多媒体格式的文件才会在界面中显示 if(endName.equals(FILE_MapTable[x])){ type = FILE_MapTable[x]; break; } } if(type !=null){ items.add(files[i].getName()); paths.add(files[i].getPath()); sizes.add(files[i].length() ""); } } } } } fileListView.setAdapter(new FileListAdapter(this,items)); } private void openFile(String path) { // TODO Auto-generated method stub Intent intent = new Intent(MyFileActivity.this,MediaPlayerActivity.class); intent.putExtra("path", path); startActivity(intent); finish(); } //列表适配器 class FileListAdapter extends BaseAdapter{ private Vector items =null;//存放显示的名称 private MyFileActivity myFile; public FileListAdapter(MyFileActivity myFile,Vector items){ this.items = items; this.myFile = myFile; } @Override public int getCount() { // TODO Auto-generated method stub return items.size(); } @Override public Object getItem(int position) { // TODO Auto-generated method stub return items.elementAt(position); } @Override public long getItemId(int position) { // TODO Auto-generated method stub return items.size(); } @Override public View getView(int position, View convertView, ViewGroup parent) { // TODO Auto-generated method stub if(convertView==null){ //加载列表布局文件 convertView = myFile.getLayoutInflater().inflate(R.layout.file_item, null); } //文件名称 TextView name = (TextView)convertView.findViewById(R.id.name); //媒体文件类型 ImageView music = (ImageView)convertView.findViewById(R.id.music); //文件夹类型 ImageView folder = (ImageView)convertView.findViewById(R.id.folder); name.setText(items.elementAt(position)); if(sizes.elementAt(position).equals("")){ //隐藏媒体文件图标,显示文件夹图标 music.setVisibility(View.GONE); folder.setVisibility(View.VISIBLE); }else{ music.setVisibility(View.VISIBLE); folder.setVisibility(View.GONE); } return convertView; } }}
[实例简介]android音乐播放器 实现了 播放音乐 扫描本地音乐 音乐列表 收藏等功能 ,扫描本地歌曲的时候 出现乱码现象,其它的参考还不错,有参考价值 [实例截图] [核心代码]
[实例简介] 仿微信浏览相册图片, 相册浏览 [实例截图] [核心代码]import java.io.File;import java.io.FilenameFilter;import java.util.ArrayList;import java.util.Arrays;import java.util.HashSet;import java.util.List;import android.app.Activity;import android.app.ProgressDialog;import android.content.ContentResolver;import android.database.Cursor;import android.net.Uri;import android.os.Bundle;import android.os.Environment;import android.os.Handler;import android.provider.MediaStore;import android.util.DisplayMetrics;import android.util.Log;import android.view.LayoutInflater;import android.view.View;import android.view.View.OnClickListener;import android.view.ViewGroup.LayoutParams;import android.view.WindowManager;import android.widget.GridView;import android.widget.PopupWindow.OnDismissListener;import android.widget.RelativeLayout;import android.widget.TextView;import android.widget.Toast;import com.zhy.bean.ImageFloder;import com.zhy.imageloader.ListImageDirPopupWindow.OnImageDirSelected;public class MainActivity extends Activity implements OnImageDirSelected{ private ProgressDialog mProgressDialog; /** * 存储文件夹中的图片数量 */ private int mPicsSize; /** * 图片数量最多的文件夹 */ private File mImgDir; /** * 所有的图片 */ private List mImgs; private GridView mGirdView; private MyAdapter mAdapter; /** * 临时的辅助类,用于防止同一个文件夹的多次扫描 */ private HashSet mDirPaths = new HashSet(); /** * 扫描拿到所有的图片文件夹 */ private List mImageFloders = new ArrayList(); private RelativeLayout mBottomLy; private TextView mChooseDir; private TextView mImageCount; int totalCount = 0; private int mScreenHeight; private ListImageDirPopupWindow mListImageDirPopupWindow; private Handler mHandler = new Handler() { public void handleMessage(android.os.Message msg) { mProgressDialog.dismiss(); // 为View绑定数据 data2View(); // 初始化展示文件夹的popupWindw initListDirPopupWindw(); } }; /** * 为View绑定数据 */ private void data2View() { if (mImgDir == null) { Toast.makeText(getApplicationContext(), "擦,一张图片没扫描到", Toast.LENGTH_SHORT).show(); return; } mImgs = Arrays.asList(mImgDir.list()); /** * 可以看到文件夹的路径和图片的路径分开保存,极大的减少了内存的消耗; */ mAdapter = new MyAdapter(getApplicationContext(), mImgs, R.layout.grid_item, mImgDir.getAbsolutePath()); mGirdView.setAdapter(mAdapter); mImageCount.setText(totalCount "张"); }; /** * 初始化展示文件夹的popupWindw */ private void initListDirPopupWindw() { mListImageDirPopupWindow = new ListImageDirPopupWindow( LayoutParams.MATCH_PARENT, (int) (mScreenHeight * 0.7), mImageFloders, LayoutInflater.from(getApplicationContext()) .inflate(R.layout.list_dir, null)); mListImageDirPopupWindow.setOnDismissListener(new OnDismissListener() { @Override public void onDismiss() { // 设置背景颜色变暗 WindowManager.LayoutParams lp = getWindow().getAttributes(); lp.alpha = 1.0f; getWindow().setAttributes(lp); } }); // 设置选择文件夹的回调 mListImageDirPopupWindow.setOnImageDirSelected(this); } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); DisplayMetrics outMetrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(outMetrics); mScreenHeight = outMetrics.heightPixels; initView(); getImages(); initEvent(); } /** * 利用ContentProvider扫描手机中的图片,此方法在运行在子线程中 完成图片的扫描,最终获得jpg最多的那个文件夹 */ private void getImages() { if (!Environment.getExternalStorageState().equals( Environment.MEDIA_MOUNTED)) { Toast.makeText(this, "暂无外部存储", Toast.LENGTH_SHORT).show(); return; } // 显示进度条 mProgressDialog = ProgressDialog.show(this, null, "正在加载..."); new Thread(new Runnable() { @Override public void run() { String firstImage = null; Uri mImageUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI; ContentResolver mContentResolver = MainActivity.this .getContentResolver(); // 只查询jpeg和png的图片 Cursor mCursor = mContentResolver.query(mImageUri, null, MediaStore.Images.Media.MIME_TYPE "=? or " MediaStore.Images.Media.MIME_TYPE "=?", new String[] { "image/jpeg", "image/png" }, MediaStore.Images.Media.DATE_MODIFIED); Log.e("TAG", mCursor.getCount() ""); while (mCursor.moveToNext()) { // 获取图片的路径 String path = mCursor.getString(mCursor .getColumnIndex(MediaStore.Images.Media.DATA)); Log.e("TAG", path); // 拿到第一张图片的路径 if (firstImage == null) firstImage = path; // 获取该图片的父路径名 File parentFile = new File(path).getParentFile(); if (parentFile == null) continue; String dirPath = parentFile.getAbsolutePath(); ImageFloder imageFloder = null; // 利用一个HashSet防止多次扫描同一个文件夹(不加这个判断,图片多起来还是相当恐怖的~~) if (mDirPaths.contains(dirPath)) { continue; } else { mDirPaths.add(dirPath); // 初始化imageFloder imageFloder = new ImageFloder(); imageFloder.setDir(dirPath); imageFloder.setFirstImagePath(path); } int picSize = parentFile.list(new FilenameFilter() { @Override public boolean accept(File dir, String filename) { if (filename.endsWith(".jpg") || filename.endsWith(".png") || filename.endsWith(".jpeg")) return true; return false; } }).length; totalCount = picSize; imageFloder.setCount(picSize); mImageFloders.add(imageFloder); if (picSize > mPicsSize) { mPicsSize = picSize; mImgDir = parentFile; } } mCursor.close(); // 扫描完成,辅助的HashSet也就可以释放内存了 mDirPaths = null; // 通知Handler扫描图片完成 mHandler.sendEmptyMessage(0x110); } }).start(); } /** * 初始化View */ private void initView() { mGirdView = (GridView) findViewById(R.id.id_gridView); mChooseDir = (TextView) findViewById(R.id.id_choose_dir); mImageCount = (TextView) findViewById(R.id.id_total_count); mBottomLy = (RelativeLayout) findViewById(R.id.id_bottom_ly); } private void initEvent() { /** * 为底部的布局设置点击事件,弹出popupWindow */ mBottomLy.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { mListImageDirPopupWindow .setAnimationStyle(R.style.anim_popup_dir); mListImageDirPopupWindow.showAsDropDown(mBottomLy, 0, 0); // 设置背景颜色变暗 WindowManager.LayoutParams lp = getWindow().getAttributes(); lp.alpha = .3f; getWindow().setAttributes(lp); } }); } @Override public void selected(ImageFloder floder) { mImgDir = new File(floder.getDir()); mImgs = Arrays.asList(mImgDir.list(new FilenameFilter() { @Override public boolean accept(File dir, String filename) { if (filename.endsWith(".jpg") || filename.endsWith(".png") || filename.endsWith(".jpeg")) return true; return false; } })); /** * 可以看到文件夹的路径和图片的路径分开保存,极大的减少了内存的消耗; */ mAdapter = new MyAdapter(getApplicationContext(), mImgs, R.layout.grid_item, mImgDir.getAbsolutePath()); mGirdView.setAdapter(mAdapter); // mAdapter.notifyDataSetChanged(); mImageCount.setText(floder.getCount() "张"); mChooseDir.setText(floder.getName()); mListImageDirPopupWindow.dismiss(); }}
Android应用源码可以按音乐视频图片分类浏览的安卓文件浏览器
[实例简介]android 多线程下载文件例子 [实例截图] [核心代码]
[实例简介]Open GL 入门级示例 [实例截图] [核心代码]package com.china.gltry;import javax.microedition.khronos.egl.EGL10;import javax.microedition.khronos.egl.EGL11;import javax.microedition.khronos.egl.EGLConfig;import javax.microedition.khronos.egl.EGLContext;import javax.microedition.khronos.egl.EGLDisplay;import javax.microedition.khronos.egl.EGLSurface;import javax.microedition.khronos.opengles.GL;import android.view.SurfaceHolder;/** * An EGL helper class. */public class EGLHelper{ public EGLHelper() { } /** * Initialize EGL for a given configuration spec. * @param configSpec */ public void start(int[] configSpec){ /* * Get an EGL instance */ mEgl = (EGL10) EGLContext.getEGL(); /* * Get to the default display. */ mEglDisplay = mEgl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY); /* * We can now initialize EGL for that display */ int[] version = new int[2]; mEgl.eglInitialize(mEglDisplay, version); EGLConfig[] configs = new EGLConfig[1]; int[] num_config = new int[1]; mEgl.eglChooseConfig(mEglDisplay, configSpec, configs, 1, num_config); mEglConfig = configs[0]; /* * Create an OpenGL ES context. This must be done only once, an * OpenGL context is a somewhat heavy object. */ mEglContext = mEgl.eglCreateContext(mEglDisplay, mEglConfig, EGL10.EGL_NO_CONTEXT, null); mEglSurface = null; } /* * Create and return an OpenGL surface */ public GL createSurface(SurfaceHolder holder) { /* * The window size has changed, so we need to create a new * surface. */ if (mEglSurface != null) { /* * Unbind and destroy the old EGL surface, if * there is one. */ mEgl.eglMakeCurrent(mEglDisplay, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_CONTEXT); mEgl.eglDestroySurface(mEglDisplay, mEglSurface); } /* * Create an EGL surface we can render into. */ mEglSurface = mEgl.eglCreateWindowSurface(mEglDisplay, mEglConfig, holder, null); /* * Before we can issue GL commands, we need to make sure * the context is current and bound to a surface. */ mEgl.eglMakeCurrent(mEglDisplay, mEglSurface, mEglSurface, mEglContext); GL gl = mEglContext.getGL(); return gl; } /** * Display the current render surface. * @return false if the context has been lost. */ public boolean swap() { mEgl.eglSwapBuffers(mEglDisplay, mEglSurface); /* * Always check for EGL_CONTEXT_LOST, which means the context * and all associated data were lost (For instance because * the device went to sleep). We need to sleep until we * get a new surface. */ return mEgl.eglGetError() != EGL11.EGL_CONTEXT_LOST; } public void finish() { if (mEglSurface != null) { mEgl.eglMakeCurrent(mEglDisplay, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_CONTEXT); mEgl.eglDestroySurface(mEglDisplay, mEglSurface); mEglSurface = null; } if (mEglContext != null) { mEgl.eglDestroyContext(mEglDisplay, mEglContext); mEglContext = null; } if (mEglDisplay != null) { mEgl.eglTerminate(mEglDisplay); mEglDisplay = null; } } EGL10 mEgl; EGLDisplay mEglDisplay; EGLSurface mEglSurface; EGLConfig mEglConfig; EGLContext mEglContext;}
Android开源小说阅读器CoolReader源码