首先:如果我们在xml里面定义了一个listener,又在代码里面动态的注册了一个listener.当我们调用时会使用xml里面的.
1.xml代码添加:
<Button
android:id="@+id/hd_test"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="硬解码测试"
android:onClick="doNothing"/>
donothing方法放到使用这个layout的代码里面去实现:
public void doNothing(View view){
}
2.java层添加:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_native);
Button button = (Button)findViewById(R.id.hd_test);
ButtonListener b = new ButtonListener();
button.setOnTouchListener(b);
textView = (TextView)findViewById(R.id.hd_result);
}
class ButtonListener implements View.OnClickListener, View.OnTouchListener{
@Override
public void onClick(View v) {
if(v.getId() == R.id.hd_test){
testHdTranscode(v);
}
}
@Override
public boolean onTouch(View v, MotionEvent event) {
if(v.getId() == R.id.hd_test){
if(event.getAction() == MotionEvent.ACTION_DOWN){
textView.setText("");
}
}
return false;
}
}
public void hdecode(View view){
AHVideoLog.d("wlz", "native Test, hdecode start");
FFmpegUtil util = new FFmpegUtil();
LvCmdResult result = util.hdecode("", "");
}
public void testHdTranscode(View view){
if(true){
textView.setText("");
glTranscode(view);
textView.setText("success !!");
return;
}
if (false) {
cmdHdTranacode(view);
return;
}
//TextView text ;
Expect expect = new Expect();
NativeTest test = new NativeTest();
test.testHdTranscode(in, out, 1280, 720, 1.0f, expect);
String relust ="width: " + expect.width + " height: " + expect.height + " rotation: " + expect.rotation +
" pps: " + expect.pps_ok + " sps: " + expect.sps_ok + " mediacodec" + expect.mediacodec_ok;
Log.e(TAG, "testHdTranscode, width: " + relust);
textView.setText(relust);
}