zoukankan      html  css  js  c++  java
  • 开发冲刺七

    今天是真的吐了,本以为昨天已经成功吧文件导入了as,但是在今天运行是才暴露出了问题,刚开始一直报缺少某个NDK,从setting中下载与当前SDK符合的NDK后报找不到NDK,在网页上查找了无数的答案,就是解决不了,卸载后重新下载了一个3.52版本的还是不行,但是这次暴露出了真正的问题,是因为AS版本不够高,运行这个工程需要3.6及以上的版本,下载好最新版本之后终于可以运行了,

    补:

    冲刺内容:生成二维码并且可以保存在本地相册

    冲刺结果:

    1:

     

    2:

    源代码:

    ShareImgActivity.java

    package com.example.meet.UI;
    
    import android.content.ContentValues;
    import android.content.Intent;
    import android.graphics.Bitmap;
    import android.graphics.BitmapFactory;
    import android.net.Uri;
    import android.os.Bundle;
    import android.os.Environment;
    import android.provider.MediaStore;
    import android.view.View;
    import android.widget.ImageView;
    import android.widget.LinearLayout;
    import android.widget.TextView;
    import android.widget.Toast;
    
    import androidx.cardview.widget.CardView;
    
    import com.example.framework.base.BaseBackActivity;
    import com.example.framework.bmob.BmobManager;
    import com.example.framework.bmob.MyMeetUser;
    import com.example.framework.helper.GlideHelper;
    import com.example.framework.view.LoadingView;
    import com.example.meet.R;
    
    import com.uuzuche.lib_zxing.activity.CodeUtils;
    
    import java.io.File;
    import java.io.FileNotFoundException;
    import java.io.FileOutputStream;
    import java.io.IOException;
    
    
    public class ShareImgActivity extends BaseBackActivity implements View.OnClickListener {
    
        //头像
        private ImageView iv_photo;
        //昵称
        private TextView tv_name;
        //性别
        private TextView tv_sex;
        //年龄
        private TextView tv_age;
        //电话
        private TextView tv_phone;
        //简介
        private TextView tv_desc;
        //二维码
        private ImageView iv_qrcode;
        //根布局
        private LinearLayout ll_content;
        //下载
        private LinearLayout ll_download;
    
        private LoadingView mLodingView;
    
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_share_img);
    
            initView();
        }
    
        private void initView() {
    
            mLodingView =new LoadingView(this);
            mLodingView.setText("正在保存");
    
            iv_photo = (ImageView) findViewById(R.id.iv_photo);
            tv_name = (TextView) findViewById(R.id.tv_name);
            tv_sex = (TextView) findViewById(R.id.tv_sex);
            tv_age = (TextView) findViewById(R.id.tv_age);
            tv_phone = (TextView) findViewById(R.id.tv_phone);
            tv_desc = (TextView) findViewById(R.id.tv_desc);
            iv_qrcode = (ImageView) findViewById(R.id.iv_qrcode);
            ll_content = (LinearLayout) findViewById(R.id.ll_content);
            ll_download = (LinearLayout) findViewById(R.id.ll_download);
    
            ll_download.setOnClickListener(new View.OnClickListener() {
    
                @Override
                public void onClick(View v) {
                    /*
                    *
                    * */
                    mLodingView.show();
                    //绘制时保存缓存
                    ll_content.setDrawingCacheEnabled(true);
                    ll_content.measure(
                            View.MeasureSpec.makeMeasureSpec(0,View.MeasureSpec.UNSPECIFIED),
                            View.MeasureSpec.makeMeasureSpec(0,View.MeasureSpec.UNSPECIFIED));
                    ll_content.layout(0,0,ll_content.getMeasuredWidth(),
                            ll_content.getMeasuredHeight());
                    Bitmap mBitmap=ll_content.getDrawingCache();
                    if(mBitmap!=null)
                    {
                        saveBitmapToAlbum(mBitmap);
                    }
                }
            });
            loadInfo();
            
    
    
        }
            //保存Bitmap到相册
        private void saveBitmapToAlbum( Bitmap mBitmap) {
            File rootPath = new File(Environment.getExternalStorageDirectory()+"/Meet/");
    
            if(!rootPath.exists())
            {
                rootPath.mkdirs();
            }
    
            File file=new File(rootPath,System.currentTimeMillis()+".png");
            try {
                FileOutputStream out = new FileOutputStream(file);
                //自带保存方法
                mBitmap.compress(Bitmap.CompressFormat.PNG,90,out);
                    out.flush();
                    out.close();
    
                    mLodingView.hide();
                    Toast.makeText(this,"保存成功",Toast.LENGTH_SHORT).show();
                    //刷新图库,同步到手机相册
                sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE,Uri.fromFile(file)));
                    //updateAlnum(file.getPath());
    
    
            } catch (IOException e) {
                mLodingView.hide();
                Toast.makeText(this,"保存失败",Toast.LENGTH_SHORT).show();
    
    
            }
        }
    
    
        //创建二维码
        private void createQRCode(final String userId) {
            //必须先绘制View否则宽高回事0,而参数不可为零
            iv_qrcode.post(new Runnable() {
                @Override
                public void run() {
                    String textContent = "Meet#"+userId;
                    Bitmap mBitmap = CodeUtils.createImage(textContent,iv_qrcode.getWidth(),iv_qrcode.getHeight(), null);
                    iv_qrcode.setImageBitmap(mBitmap);
                }
            });
    
    
        }
    
        //加载个人信息
        private void loadInfo() {
            MyMeetUser myMeetUser=BmobManager.getInstance().getCurrentUser();
            GlideHelper.loadUrl(this, myMeetUser.getPhoto(), iv_photo);
            tv_name.setText(myMeetUser.getNickName());
            tv_sex.setText(myMeetUser.isSex() ? R.string.text_me_info_boy : R.string.text_me_info_girl);
            tv_age.setText(myMeetUser.getAge() + " " + getString(R.string.text_search_age));
            tv_phone.setText(myMeetUser.getMobilePhoneNumber());
            tv_desc.setText(myMeetUser.getDesc());
    
            createQRCode(myMeetUser.getObjectId());
        }
    
    
        @Override
        public void onClick(View v) {
    
        }
    }

    MeFragment.java

    package com.example.meet.fragment;
    
    import android.content.Intent;
    import android.os.Bundle;
    import android.view.LayoutInflater;
    import android.view.View;
    import android.view.ViewGroup;
    import android.widget.LinearLayout;
    import android.widget.TextView;
    
    import androidx.fragment.app.Fragment;
    
    import com.example.framework.bmob.BmobManager;
    import com.example.framework.bmob.MyMeetUser;
    import com.example.framework.helper.GlideHelper;
    import com.example.meet.R;
    import com.example.meet.UI.NewFriendActivity;
    import com.example.meet.UI.PrivateSetActivity;
    import com.example.meet.UI.ShareImgActivity;
    
    import de.hdodenhof.circleimageview.CircleImageView;
    
    /**
     * A simple {@link Fragment} subclass.
     */
    public class MeFragment extends Fragment {
    
        private CircleImageView ivMePhoto;
        private TextView tvNickname;
        private TextView tvServerStatus;
        private LinearLayout llMeInfo;
        private LinearLayout llNewFriend;
        private LinearLayout llPrivateSet;
        private LinearLayout llShare;
        private LinearLayout llNotice;
        private LinearLayout llSetting;
    
        public MeFragment() {
    
        }
    
    
        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                                 Bundle savedInstanceState) {
            // Inflate the layout for this fragment
    
            View view = inflater.inflate(R.layout.fragment_me, container, false);
            initView(view);
            return view;
        }
    
        private void initView(View view){
            ivMePhoto = (CircleImageView) view.findViewById(R.id.iv_me_photo);
            tvNickname = (TextView) view.findViewById(R.id.tv_nickname);
            tvServerStatus = (TextView) view.findViewById(R.id.tv_server_status);
            llMeInfo = (LinearLayout) view.findViewById(R.id.ll_me_info);
            llNewFriend = (LinearLayout) view.findViewById(R.id.ll_new_friend);
            llPrivateSet = (LinearLayout) view.findViewById(R.id.ll_private_set);
            llShare = (LinearLayout) view.findViewById(R.id.ll_share);
            llNotice = (LinearLayout) view.findViewById(R.id.ll_notice);
            llSetting = (LinearLayout) view.findViewById(R.id.ll_setting);
            loadMeInfo();
            llNewFriend.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    startActivity(new Intent(getActivity(), NewFriendActivity.class));
                }
            });
            llShare.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    startActivity(new Intent(getActivity(),ShareImgActivity.class));
                }
            });
            llPrivateSet.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    startActivity(new Intent(getActivity(), PrivateSetActivity.class));
                }
            });
        }
    
        /**
         * 加载我的信息
         */
        private void loadMeInfo() {
            MyMeetUser user = BmobManager.getInstance().getCurrentUser();
            GlideHelper.loadUrl(getActivity(),user.getPhoto(),ivMePhoto);
            tvNickname.setText(user.getTokenNickName());
        }
    }

    FileHelper.java

    package com.example.framework.helper;
    
    import android.app.Activity;
    import android.content.ContentValues;
    import android.content.Context;
    import android.content.Intent;
    import android.database.Cursor;
    import android.graphics.Bitmap;
    import android.graphics.BitmapFactory;
    import android.net.Uri;
    import android.os.Build;
    import android.os.Environment;
    import android.os.ParcelFileDescriptor;
    import android.provider.MediaStore;
    import android.text.TextUtils;
    import android.widget.Toast;
    
    import androidx.core.content.FileProvider;
    import androidx.core.os.EnvironmentCompat;
    import androidx.loader.content.CursorLoader;
    
    
    import com.example.framework.utils.LogUtils;
    
    import java.io.BufferedInputStream;
    import java.io.BufferedOutputStream;
    import java.io.File;
    import java.io.FileDescriptor;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.OutputStream;
    import java.text.SimpleDateFormat;
    import java.util.Date;
    import java.util.Locale;
    
    public class FileHelper {
    
    
    
        private static volatile FileHelper mInstnce = null;
        private SimpleDateFormat simpleDateFormat;
        private File tempFile = null;
        private Uri imageUri;
        //相机
        public static final int CAMERA_REQUEST_CODE = 1004;
        //相册
        public static final int ABLUM_REQUEST_CODE = 1005;
    
    
        public FileHelper(){
            simpleDateFormat = new SimpleDateFormat("yyyy_MM_dd_HH_mm_ss");
        }
    
    
        public static FileHelper getInstance() {
            if (mInstnce == null) {
                synchronized (FileHelper.class) {
                    if (mInstnce == null) {
                        mInstnce = new FileHelper();
                    }
                }
            }
            return mInstnce;
        }
    
    
        /**
         * 使用相机
         * @param activity
         */
        public void toCamera(Activity activity){
            try {
                Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                String fileName = simpleDateFormat.format(new Date());
                tempFile = new File(Environment.getExternalStorageDirectory(), fileName + ".jpg");
                //兼容Android N
                if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
                    imageUri = Uri.fromFile(tempFile);
                } else {
                    //利用FileProvider
                    imageUri = FileProvider.getUriForFile(activity,
                            activity.getPackageName() + ".fileprovider", tempFile);
                    //添加权限
                    intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION |
                            Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
                }
                intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
                activity.startActivityForResult(intent,CAMERA_REQUEST_CODE);
            } catch (Exception e) {
                Toast.makeText(activity, "无法打开相机", Toast.LENGTH_SHORT).show();
                e.printStackTrace();
            }
        }
    
    
        /**
         * 跳转到相册
         * @return
         */
        public void toAblum(Activity activity){
            Intent intent = new Intent(Intent.ACTION_PICK);
            intent.setType("image/*");
            activity.startActivityForResult(intent,ABLUM_REQUEST_CODE);
        }
    
    
        public File getTempFile() {
            return tempFile;
        }
    
        public Uri getImageUri() {
            return imageUri;
        }
    
    
        //获取拍照和选取的图片的绝对路径
        public String getRealPathFromURI(Activity activity, Uri contentUri) {
            Context context = activity.getApplicationContext();
            File rootDataDir = context.getExternalFilesDir(null);
    //        MyApplication.getMyContext().getExternalFilesDir(null).getPath();
            String fileName = getFileName(contentUri);
            if (!TextUtils.isEmpty(fileName)) {
                File copyFile = new File(rootDataDir + File.separator + fileName);
                copyFile(context, contentUri, copyFile);
                return copyFile.getAbsolutePath();
            }
            return null;
        }
        public String getFileName(Uri uri) {
            if (uri == null) return null;
            String fileName = null;
            String path = uri.getPath();
            int cut = path.lastIndexOf('/');
            if (cut != -1) {
                fileName = path.substring(cut + 1);
            }
            return fileName;
        }
    
        public void copyFile(Context context, Uri srcUri, File dstFile) {
            try {
                InputStream inputStream = context.getContentResolver().openInputStream(srcUri);
                if (inputStream == null) return;
                OutputStream outputStream = new FileOutputStream(dstFile);
                copyStream(inputStream, outputStream);
                inputStream.close();
                outputStream.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    
        public int copyStream(InputStream input, OutputStream output) throws Exception, IOException {
            final int BUFFER_SIZE = 1024 * 2;
            byte[] buffer = new byte[BUFFER_SIZE];
            BufferedInputStream in = new BufferedInputStream(input, BUFFER_SIZE);
            BufferedOutputStream out = new BufferedOutputStream(output, BUFFER_SIZE);
            int count = 0, n = 0;
            try {
                while ((n = in.read(buffer, 0, BUFFER_SIZE)) != -1) {
                    out.write(buffer, 0, n);
                    count += n;
                }
                out.flush();
            } finally {
                try {
                    out.close();
                } catch (IOException e) {
                }
                try {
                    in.close();
                } catch (IOException e) {
                }
            }
            return count;
        }
    
    
    
    
    
    }
  • 相关阅读:
    [洛谷][P1503][鬼子进村][Treap]
    [noi 2004] 郁闷的出纳员
    bzoj 3224,tyvj 1728普通平衡树
    Treap
    [模拟赛]棘手的操作
    bzoj 4551[Tjoi2016&Heoi2016]树
    bzoj2527 [Poi2011]Meteors
    bzoj4152 [AMPPZ2014]The Captain
    bzoj4516 [Sdoi2016]生成魔咒
    bzoj4547 小奇的集合
  • 原文地址:https://www.cnblogs.com/yizhixiaozhu/p/12770373.html
Copyright © 2011-2022 走看看