Android开发的一些记录

2017-06-27  本文已影响48人  让我爱胡蝶

概览




    /**
     * 根据包名判断应用是否已经安装。
     *
     * @param context     上下文
     * @param packageName 包名
     * @return 如果应用已经安装,则返回true,否则返回false.
     */
    public static boolean isPackageExist(Context context, String packageName) {
        boolean isExist = false;
        try {
            isExist = (null != context.getPackageManager().getApplicationInfo(packageName, PackageManager.GET_UNINSTALLED_PACKAGES))
                    && (null != context.getPackageManager().getPackageInfo(packageName, 0));
        } catch (NameNotFoundException e) {
        } finally {
            return isExist;
        }
    }

Android 编码URL中文字符串;
我能想到的问题:中文字符和空格。重复编码也没问题。

public static String encodeUrl(String url) {
        return Uri.encode(url, "-![.:/,%?&=]");
    }

    /***
     * 测量的默认处理
     * 1. EXACTLY返回定值
     * 2. UNSPECIFIED返回默认值
     * 3.AT_MOST返回最小值
     * @param measureSpace 值
     * @param default 默认值
     * @return 大小
     */
    private fun getMeasureSize(measureSpace: Int, default: Int): Int {
        var retuSize = 0
        val model = MeasureSpec.getMode(measureSpace)
        val size = MeasureSpec.getSize(measureSpace)
        when (model) {
            MeasureSpec.UNSPECIFIED -> retuSize = default
            MeasureSpec.AT_MOST -> retuSize = Math.min(default, size)
            MeasureSpec.EXACTLY -> retuSize = size
        }
        return retuSize
    }

主要问题是滑动一会后,停住不滑动,过一会松手。就会出现onFling不回调。


引用初探Kotlin和anko进行Android开发

//anko
    compile "org.jetbrains.anko:anko-sdk15:+" // So here it's 15 too
    compile "org.jetbrains.anko:anko-appcompat-v7:+"
    compile "org.jetbrains.anko:anko-design:+"
    compile "org.jetbrains.anko:anko-recyclerview-v7:+"
 @NonNull
    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        BottomSheetDialog dialog = (BottomSheetDialog) super.onCreateDialog(savedInstanceState);
        rootView = View.inflate(getContext(), R.layout.work_comment_fragment, null);
        initView();
        initData();
        dialog.setContentView(rootView, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, (int) (getContext().getResources().getDisplayMetrics().heightPixels * 0.5)));
        mBehavior = BottomSheetBehavior.from((View) rootView.getParent());
        return dialog;
    }
上一篇下一篇

猜你喜欢

热点阅读