当前位置:  编程技术>移动开发
本页文章导读:
    ▪属性定义研究-很浅        属性定义研究--很浅     在attrs.xml文件中如下定义:<?xml version="1.0" encoding="utf-8"?> <resources> <declare-styleable name="MyView"> <attr name="textColor" format="color" /> <attr name="textSize" fo.........
    ▪ openGL简例二        openGL简例2 public class VortexRenderer implements GLSurfaceView.Renderer{ private float _red = 0.9f; private float _green = 0.8f; private float _blue = 0.8f; // new object variables we need // a raw buffer to hold indices private ShortBuffer _i.........
    ▪ (转)获取全部安装的应用       (转)获取所有安装的应用 class PInfo { private String appname = ""; private String pname = ""; private String versionName = ""; private int versionCode = 0; private Drawable icon; private void pret.........

[1]属性定义研究-很浅
    来源: 互联网  发布时间: 2014-02-18
属性定义研究--很浅
    在attrs.xml文件中如下定义:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="MyView">
<attr name="textColor" format="color" />
<attr name="textSize" format="dimension" />
<attr name="imgBackground" format="integer" />
<attr name="textPaddingLeft" format="dimension"/>
<attr name="textPaddingRight" format="dimension"/>
<!-- Default TestView style. -->  
<attr name="testViewStyle" format="reference" /> 
</declare-styleable>
</resources>
[color=blue][/color]
   theme.xml 中如下声明:
<resources>  
    <style name="ddd.OMS" parent="@android:style/Theme">  
        <item name="testViewStyle">@style/widget.motiontextview</item>
    </style>     
</resources> 

layout/xxxx.xml下使用,
android:layout_marginRight="15px"
android:layout_marginLeft="15px"

android:layout_marginBottom="10px"


这部分代码中要是要使用到自己定义的属性需要如下解析:

TypedArray params = context.obtainStyledAttributes(attrs,
                 R.styleable.MyView);
TypedArray appearance = null;
         int ap = params.getResourceId(R.styleable.MyView_testViewStyle, -1);
if (ap != -1) {
             appearance = context.obtainStyledAttributes(ap,
                                 R.styleable.MyView
                                 );
         }
float textSize = appearance.getDimension(R.styleable.MyView_textSize, 24);
不过以上属性需要都是自己定义的,才可以在第二次产生的appearance中获取到

改为如下代码  需要请教:
暂时不知道如何获取!但是可以通过 int resourceId=attrs.getStyleAttribute()获取testViewStyle 的resource ID,但是现在我还不知道如何获取 testViewStyle 的值!

如果哪位仁兄有办法,请予以回复!谢谢!

    
[2] openGL简例二
    来源: 互联网  发布时间: 2014-02-18
openGL简例2
public class VortexRenderer implements GLSurfaceView.Renderer{

private float _red = 0.9f;
private float _green = 0.8f;
private float _blue = 0.8f;
// new object variables we need
// a raw buffer to hold indices
private ShortBuffer _indexBuffer;
private ShortBuffer _indexBufferStatic;
// a raw buffer to hold the vertices
private FloatBuffer _vertexBuffer;
private FloatBuffer _vertexBufferStatic;
private short[] _indicesArray = {0, 1, 2};
private int _nrOfVertices = 3;
// code snipped
private float _angle;
private FloatBuffer _colorBuffer;
private float _xAngle;
private float _yAngle;
private float _width = 320f;
private float _height = 480f;
public void setAngle(float angle) {
_angle = angle;
}
private void initTriangle() {
    // float has 4 bytes
    ByteBuffer vbb = ByteBuffer.allocateDirect(_nrOfVertices * 3 * 4);
    vbb.order(ByteOrder.nativeOrder());
    _vertexBuffer = vbb.asFloatBuffer();
    // short has 2 bytes
    ByteBuffer ibb = ByteBuffer.allocateDirect(_nrOfVertices * 2);
    ibb.order(ByteOrder.nativeOrder());
    _indexBuffer = ibb.asShortBuffer();
    // float has 4 bytes, 4 colors (RGBA) * number of vertices * 4 bytes
    ByteBuffer cbb = ByteBuffer.allocateDirect(4 * _nrOfVertices * 4);
    cbb.order(ByteOrder.nativeOrder());
    _colorBuffer = cbb.asFloatBuffer();
    float[] coords = {
        -0.5f, -0.5f, 0f, // (x1, y1, z1)
        0.5f, -0.5f, 0f, // (x2, y2, z2)
        0f, 0.5f, 0f // (x3, y3, z3)
    };
    float[] colors = {
            1f, 0f, 0f, 1f, // point 1
            0f, 1f, 0f, 1f, // point 2
            0f, 0f, 1f, 1f, // point 3
        };
    _vertexBuffer.put(coords);
    _indexBuffer.put(_indicesArray);
    _colorBuffer.put(colors);
    _vertexBuffer.position(0);
    _indexBuffer.position(0);
    _colorBuffer.position(0);
}

    public void setColor(float r, float g, float b) {
        _red = r;
        _green = g;
        _blue = b;
    }

@Override
public void onDrawFrame(GL10 gl) {

gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
for (int i = 1; i <= 10; i++)
{
gl.glLoadIdentity();
    gl.glTranslatef(0.0f, -1f, -1.0f + -1.5f * i);
// set rotation
gl.glRotatef(_xAngle, 1f, 0f, 0f);
gl.glRotatef(_yAngle, 0f, 1f, 0f);
        // set rotation for the non-static triangle
        gl.glVertexPointer(3, GL10.GL_FLOAT, 0, _vertexBuffer);
        gl.glColorPointer(4, GL10.GL_FLOAT, 0, _colorBuffer);
        gl.glDrawElements(GL10.GL_TRIANGLES, _nrOfVertices, GL10.GL_UNSIGNED_SHORT, _indexBuffer);
}
}
@Override
public void onSurfaceChanged(GL10 gl, int w, int h) {
// TODO Auto-generated method stub
_width = w;
_height = h;
gl.glViewport(0, 0, w, h);
}
@Override
public void onSurfaceCreated(GL10 gl, EGLConfig arg1) {
// TODO Auto-generated method stub
    gl.glMatrixMode(GL10.GL_PROJECTION);
    float size = .01f * (float) Math.tan(Math.toRadians(45.0) / 2);
    float ratio = _width / _height;
    // perspective:
    gl.glFrustumf(-size, size, -size / ratio, size / ratio, 0.01f, 100.0f);
    // orthographic:
    //gl.glOrthof(-1, 1, -1 / ratio, 1 / ratio, 0.01f, 100.0f);
    gl.glViewport(0, 0, (int) _width, (int) _height);
    gl.glMatrixMode(GL10.GL_MODELVIEW);
    gl.glEnable(GL10.GL_DEPTH_TEST);

// define the color we want to be displayed as the "clipping wall"
gl.glClearColor(_red, _green, _blue, 1.0f);
    // enable the differentiation of which side may be visible
    gl.glEnable(GL10.GL_CULL_FACE);
    // which is the front? the one which is drawn counter clockwise
    gl.glFrontFace(GL10.GL_CCW);
    // which one should NOT be drawn
    gl.glCullFace(GL10.GL_BACK);
gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
    gl.glEnableClientState(GL10.GL_COLOR_ARRAY);
    initJZT();
}
}

    
[3] (转)获取全部安装的应用
    来源: 互联网  发布时间: 2014-02-18
(转)获取所有安装的应用
class PInfo {   
    private String appname = "";   
    private String pname = "";   
    private String versionName = "";   
    private int versionCode = 0;   
    private Drawable icon;   
    private void prettyPrint() {   
        log(appname + "\t" + pname + "\t" + versionName + "\t" + versionCode + "\t");   
    }   
}   
  
private void listPackages() {   
    ArrayList<PInfo> apps = getInstalledApps(false); /* false = no system packages */  
    final int max = apps.size();   
    for (int i=0; i<max; i++) {   
        apps.get(i).prettyPrint();   
    }   
}   
  
private ArrayList<PInfo> getInstalledApps(boolean getSysPackages) {   
    ArrayList<PInfo> res = new ArrayList<PInfo>();           
    List<PackageInfo> packs = getPackageManager().getInstalledPackages(0);   
    for(int i=0;i<packs.size();i++) {   
        PackageInfo p = packs.get(i);   
        if ((!getSysPackages) && (p.versionName == null)) {   
            continue ;   
        }   
        PInfo newInfo = new PInfo();   
        newInfo.appname = p.applicationInfo.loadLabel(getPackageManager()).toString();   
        newInfo.pname = p.packageName;   
        newInfo.versionName = p.versionName;   
        newInfo.versionCode = p.versionCode;   
        newInfo.icon = p.applicationInfo.loadIcon(getPackageManager());   
        res.add(newInfo);   
    }   
    return res;    
}  

 


    
最新技术文章:
▪Android开发之登录验证实例教程
▪Android开发之注册登录方法示例
▪Android获取手机SIM卡运营商信息的方法
▪Android实现将已发送的短信写入短信数据库的...
▪Android发送短信功能代码
▪Android根据电话号码获得联系人头像实例代码
▪Android中GPS定位的用法实例
▪Android实现退出时关闭所有Activity的方法
▪Android实现文件的分割和组装
▪Android录音应用实例教程
▪Android双击返回键退出程序的实现方法
▪Android实现侦听电池状态显示、电量及充电动...
▪Android获取当前已连接的wifi信号强度的方法
▪Android实现动态显示或隐藏密码输入框的内容
▪根据USER-AGENT判断手机类型并跳转到相应的app...
▪Android Touch事件分发过程详解
▪Android中实现为TextView添加多个可点击的文本
▪Android程序设计之AIDL实例详解
▪Android显式启动与隐式启动Activity的区别介绍
▪Android按钮单击事件的四种常用写法总结
▪Android消息处理机制Looper和Handler详解
▪Android实现Back功能代码片段总结
▪Android实用的代码片段 常用代码总结
▪Android实现弹出键盘的方法
▪Android中通过view方式获取当前Activity的屏幕截...
▪Android提高之自定义Menu(TabMenu)实现方法
▪Android提高之多方向抽屉实现方法
▪Android提高之MediaPlayer播放网络音频的实现方法...
▪Android提高之MediaPlayer播放网络视频的实现方法...
▪Android提高之手游转电视游戏的模拟操控
 


站内导航:


特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!

©2012-2021,,E-mail:www_#163.com(请将#改为@)

浙ICP备11055608号-3