wenwenwen888 / ListDemo

所有Demo仅用于个人测试

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ListDemo

所有Demo仅用于个人测试

一个伟大的项目, 都是源自于一个个小小的demo~

1,Socket Demo

一个socket通信的简单demo,支持断开重连
此demo引用了这里的Socket封装库并作了自己的业务修改

####--------------------------主要文件或代码--------------------------

2,Unfile Demo

用于解压文件(内含删除整个文件夹的功能)

####--------------------------主要文件或代码--------------------------


  • 解压文件代码如下:
    /**
     * 解压缩一个文件
     *
     * @param zipFile    压缩文件
     * @param folderPath 解压缩的目标目录
     * @return 返回解压根目录
     * @throws IOException 当解压缩过程出错时抛出
     */
    public static String upZipFile(File zipFile, String folderPath) throws IOException {
        String FolderPath = null;
        File desDir = new File(folderPath);
        if (!desDir.exists()) {
            desDir.mkdirs();
        }
        ZipFile zf = new ZipFile(zipFile, "GBK");
        for (Enumeration<?> entries = zf.getEntries(); entries.hasMoreElements(); ) {
            ZipEntry entry = ((ZipEntry) entries.nextElement());
            if (entry.isDirectory()) {
                continue;
            }
            InputStream in = zf.getInputStream((com.file.zip.ZipEntry) entry);
            String str = folderPath + File.separator + entry.getName();
            FolderPath = folderPath + File.separator + entry.getName().substring(0, entry.getName().indexOf("/"));//返回的根目录
            Log.e("upZipFileToTFcard", "FolderPath:" + entry.getName());
            str = new String(str.getBytes(), "utf-8");
            File desFile = new File(str);
            if (!desFile.exists()) {
                File fileParentDir = desFile.getParentFile();
                if (!fileParentDir.exists()) {
                    Log.e("upZipFileToTFcard", "fileParentDir:" + fileParentDir.getPath());
                    fileParentDir.mkdirs();
                }
                Log.e("upZipFileToTFcard" , "desFile:"+desFile.getPath());
                desFile.createNewFile();
            }
            OutputStream out = new FileOutputStream(desFile);
            byte buffer[] = new byte[BUFF_SIZE];
            int realLength;
            while ((realLength = in.read(buffer)) > 0) {
                out.write(buffer, 0, realLength);
            }
            in.close();
            out.close();
        }
        return FolderPath;
    }
  • 删除整个文件夹文件代码如下
    /**
     * 递归删除文件和文件夹
     * @param file    要删除的根目录
     */
    public static void RecursionDeleteFile(File file){
        if(file.isFile()){
            file.delete();
            return;
        }
        if(file.isDirectory()){
            File[] childFile = file.listFiles();
            if(childFile == null || childFile.length == 0){
                file.delete();
                return;
            }
            for(File f : childFile){
                RecursionDeleteFile(f);
            }
            file.delete();
        }
    }

3,Timer Demo

一个简单的倒计时demo

####--------------------------主要文件或代码--------------------------

4,MultiMedia Demo

有关多媒体Demo(暂时有拍照与从相册选照片)

####--------------------------主要文件或代码--------------------------

5,DrawerLayout Demo

官方控件DrawerLayout的简单使用

####--------------------------主要文件或代码--------------------------

6,CustomProgressBar Demo

一个自定义进度条

  • 示例图 :

####--------------------------主要文件或代码--------------------------


* activity_customprogressbar.xml: ```java ``` * style.xml: ```java <style name="StyleProgressBarMini" parent="@android:style/Widget.ProgressBar.Horizontal"> 50dip 10dip false @android:drawable/progress_indeterminate_horizontal @drawable/shape_progressbar_mini </style> ``` * [shape_progressbar_mini.xml](https://github.com/wenwenwen888/ListDemo/blob/master/app/src/main/res/drawable/shape_progressbar_mini.xml)
* [shape_progressbar_bg.xml](https://github.com/wenwenwen888/ListDemo/blob/master/app/src/main/res/drawable/shape_progressbar_bg.xml)

7,MPAndroidLineChart Demo

基于MPAndroidChart的一个折线图

  • 示例图 :

这里是MPAndroidChart的地址

####--------------------------主要文件或代码--------------------------

8,EventBus Demo

EventBus的简单使用
这里是EventBus的地址

####--------------------------主要文件或代码--------------------------

9,Realm Demo

Realm数据库的简单使用
Realm for Android详细教程

####--------------------------主要文件或代码--------------------------

10,ScreenShot Demo

一个简单的截屏工具
这里是截屏库的地址

####--------------------------主要文件或代码--------------------------

11,Drawing Demo

一个画板(可以弹出颜色选择器选择画笔颜色)
这里是画板的地址
这里是颜色选择器的地址

####--------------------------主要文件或代码--------------------------

12,Notification Demo

Notification广播简单使用
这里是引用notification库的地址

####--------------------------主要文件或代码--------------------------

PugNotification.with(context)
                .load()
                .title(title)       //title
                .message(message)   //content
                .smallIcon(R.drawable.ic_notifications)     //smallicon
                .largeIcon(R.drawable.ic_notifications)     //largeicon
                .flags(Notification.DEFAULT_ALL)
                .autoCancel(true)           //点击取消
                .simple()
                .build();

13,CustomSearchEditText Demo

一个自定义搜索框
这里是自定义搜索框的地址

14,Spinner Demo(nice-spinner)

一个自定义的spinner
这里是nice_spinner的开源地址

####--------------------------主要文件或代码--------------------------

<org.angmarch.views.NiceSpinner
        android:id="@+id/nicespinner"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="10dp"
        app:backgroundSelector="@drawable/gray_border_bg"
        app:textTint="@color/colorBlack" />

15,AssetsApk Demo

从Assets文件夹安装APK
原理:把要安装的APK文件放在assets文件夹,然后要安装的时候是先复制到本地内存,然后再安装「为什么会有如此流氓的软件」

####--------------------------主要文件或代码--------------------------

public boolean copyApkFromAssets(Context context, String fileName, String path) {
        boolean copyIsFinish = false;
        try {
            InputStream is = context.getAssets().open(fileName);
            File file = new File(path);
            file.createNewFile();
            FileOutputStream fos = new FileOutputStream(file);
            byte[] temp = new byte[1024];
            int i;
            while ((i = is.read(temp)) > 0) {
                fos.write(temp, 0, i);
            }
            fos.close();
            is.close();
            copyIsFinish = true;
        } catch (IOException e) {
            e.printStackTrace();
        }
        return copyIsFinish;
    }
  • 安装APK
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setDataAndType(Uri.parse("file://" + FILEPATH), "application/vnd.android.package-archive");
startActivity(intent);

16,ProgressDialog Demo

自定义ProgressDialog

示例图 :

####--------------------------主要文件或代码--------------------------

<style name="CustomDialog" parent="Theme.AppCompat.Dialog">
        <item name="android:backgroundDimEnabled">true</item>       //true-背景变暗,false-背景不变暗
        <item name="colorAccent">@color/colorAccent</item>          //加载图标颜色
        <item name="android:windowBackground">@android:color/transparent</item>    //背景透明
</style>

17,QRCode Demo

二维码demo
这里是zxing的开源地址
这里是基于zxing二次开发的一个开源库地址

示例图 :

####--------------------------主要文件或代码--------------------------

18,WatchActivity Demo

观察者模式demo

####--------------------------主要文件或代码--------------------------

19,AnimationActivity Demo

动画animation的初认识demo

####--------------------------主要文件或代码--------------------------

20,ToolBarActivity Demo

Toolbar与NavigationView、DrawerLayout的使用

预览图 :

21,DoubleRecyclerViewActivity Demo

RecyclerView嵌套RecyclerView

About

所有Demo仅用于个人测试


Languages

Language:Java 100.0%