• 【阿炬Android笔记】01、调用VitamioBundle播放窗口


    1、调用VitamioBundle播放窗口

                    
                    Intent intent = new Intent(getApplicationContext(), VideoActivity.class);
                    intent.setData(Uri.parse(path));
                    // intent.putExtra("path", f.path);
                    intent.putExtra("displayName", "企建教育");
                    startActivity(intent);
                    
                    

     2、AndBase对话框

                    AbDialogUtil.showAlertDialog(MainActivity.this, "这里是标题",
                            "这里写一些描述", new AbDialogOnClickListener() {
    
                                @Override
                                public void onPositiveClick() {
                                    // TODO Auto-generated method stub
    
                                }
    
                                @Override
                                public void onNegativeClick() {
                                    // TODO Auto-generated method stub
    
                                }
                            });

     3、AndBase框架异步获取json数据,并解析的过程

            mAbHttpUtil = AbHttpUtil.getInstance(this);
            mAbHttpUtil.setTimeout(10000);
            String urlString = "http://ke.cpmqa.com/";
            mAbHttpUtil.get(urlString, new AbStringHttpResponseListener() {
    
                @Override
                public void onSuccess(int statusCode, String content) {
                    Log.d(TAG, "onSuccess");
    
                    try {
                        JSONObject jsonObject = new JSONObject(content);
    
                        int total = jsonObject.getInt("total");
                        Boolean success = jsonObject.getBoolean("success");
                        Log.d(TAG, "total:" + total + " | success:" + success);
    
                        JSONArray jsonArray = jsonObject.getJSONArray("rows");// 里面有一个数组数据,可以用getJSONArray获取数组
                        for (int i = 0; i < jsonArray.length(); i++) {
                            JSONObject item = jsonArray.getJSONObject(i); // 得到每个对象
    
                            TttVideo t = new TttVideo();
                            t.Id = item.getInt("Id");
                            t.VideoName = item.getString("VideoName");
                            t.Flag = item.getInt("Flag");
                            t.VideoUrl = item.getString("VideoUrl");
                            t.OrderFlag = item.getInt("OrderFlag");
    
                            list.add(t);
    
                        }
    
                    } catch (JSONException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
    
                }
    
                // 失败,调用
                @Override
                public void onFailure(int statusCode, String content,
                        Throwable error) {
    
                    Log.d(TAG, "onFailure");
                    AbToastUtil.showToast(MainActivity.this, error.getMessage());
                }
    
                // 开始执行前
                @Override
                public void onStart() {
                    Log.d(TAG, "onStart");
                    // 显示进度框
                    AbDialogUtil
                            .showProgressDialog(MainActivity.this, 0, "正在查询...");
                }
    
                // 完成后调用,失败,成功
                @Override
                public void onFinish() {
                    Log.d(TAG, "onFinish");
                    // 移除进度框
                    AbDialogUtil.removeDialog(MainActivity.this);
                };
    
            });

    4、动态添加控件,并设置控件属性

                    TableLayout table1 = (TableLayout) findViewById(R.id.table1);
    
                    if (list != null) {
                        for (TttVideo t : list) {
    
                            TextView tv = new TextView(MainActivity.this);
                            tv.setId(t.Id);
                            tv.setText(Html.fromHtml(t.VideoName));
    
                            TableRow.LayoutParams lp = new TableRow.LayoutParams(
                                    TableRow.LayoutParams.MATCH_PARENT,
                                    TableRow.LayoutParams.WRAP_CONTENT);
    
                            if (t.Flag == 0) {
                                lp.setMargins(
                                        DensityUtil.dip2px(MainActivity.this, 20),
                                        DensityUtil.dip2px(MainActivity.this, 20),
                                        DensityUtil.dip2px(MainActivity.this, 15),
                                        DensityUtil.dip2px(MainActivity.this, 20));
                                tv.setTextColor(Color.BLACK);
                            } else {
                                lp.setMargins(
                                        DensityUtil.dip2px(MainActivity.this, 40),
                                        DensityUtil.dip2px(MainActivity.this, 15),
                                        DensityUtil.dip2px(MainActivity.this, 15),
                                        DensityUtil.dip2px(MainActivity.this, 15));
    
                                if (MediaUtils.isVideo(t.VideoUrl)) {
                                    tv.setTextColor(Color.rgb(53, 53, 53));
                                    
                                }
                                
                                tv.setOnClickListener(MainActivity.this);
    
                            }
    
                            TableRow tr = new TableRow(MainActivity.this);
                            tr.addView(tv, lp);
    
                            if (t.Flag == 0) {
    
                            } else {
                                tr.setBackgroundColor(Color.WHITE);
                            }
    
                            TableLayout.LayoutParams tablelp = new TableLayout.LayoutParams(
                                    TableLayout.LayoutParams.MATCH_PARENT,
                                    TableLayout.LayoutParams.WRAP_CONTENT);
    
                            tablelp.setMargins(0, 0, 0,
                                    DensityUtil.dip2px(MainActivity.this, 1));
    
                            table1.addView(tr, tablelp);
    
                        }
    
                    }

    5、代码中的单位转换类:

    public class DensityUtil {
        /** 
         * 根据手机的分辨率从 dp 的单位 转成为 px(像素) 
         */  
        public static int dip2px(Context context, float dpValue) {  
            final float scale = context.getResources().getDisplayMetrics().density;  
            return (int) (dpValue * scale + 0.5f);  
        }  
      
        /** 
         * 根据手机的分辨率从 px(像素) 的单位 转成为 dp 
         */  
        public static int px2dip(Context context, float pxValue) {  
            final float scale = context.getResources().getDisplayMetrics().density;  
            return (int) (pxValue / scale + 0.5f);  
        }  
    }
  • 相关阅读:
    Spring警告: Could not load driverClass com.mysql.jdbc.Driver(待解决)
    马士兵_JAVA自学之路(为那些目标模糊的码农们)
    Spring报错:java.io.FileNotFoundException: class path resource [applicationContext.xml] cannot be opened because it does not exist
    安装spring报错:Cannot complete the install because of a conflicting dependency.
    MYSQL外键(Foreign Key)的使用
    MongoDB(Roboit3T)中导出集合数据
    Express安装
    ES6学习
    C#中添加log4net(日志文件)
    登录MES系统后台服务的操作
  • 原文地址:https://www.cnblogs.com/quejuwen/p/4139283.html
Copyright © 2020-2023  润新知