diff --git a/AudioRoute/src/com/example/audioroute/AudioRoute.java b/AudioRoute/src/com/example/audioroute/AudioRoute.java index c0d0e3a..7be2b26 100644 --- a/AudioRoute/src/com/example/audioroute/AudioRoute.java +++ b/AudioRoute/src/com/example/audioroute/AudioRoute.java @@ -17,27 +17,23 @@ package com.example.audioroute; -import java.io.File; import android.app.Activity; import android.content.Context; +import android.media.AudioManager; +import android.media.AudioSystem; import android.os.Bundle; -import android.os.Handler; -import android.os.Message; -import android.util.Log; +import android.os.SystemProperties; import android.util.Log; import android.view.View; import android.view.View.OnClickListener; import android.widget.CheckBox; -import android.widget.Button; -import android.widget.RadioButton; import android.widget.TextView; -import android.media.AudioManager; -import android.media.AudioSystem; -import android.os.SystemProperties; + +import java.io.File; public class AudioRoute extends Activity { - private final static String TAG = "AudioRoute"; + private static final String TAG = "AudioRoute"; private TextView mCommand; private CheckBox mSpdifIn; @@ -46,130 +42,109 @@ public class AudioRoute extends Activity { private AudioManager mAudioManager; - /** Called when the activity is first created. */ + /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Create and attach the view that is responsible for painting. mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); - File fileHdmi=new File("proc/asound/imxhdmisoc"); - File fileSpdif=new File("proc/asound/imxspdif"); - if(fileHdmi.exists()&&!fileSpdif.exists()) - { - setContentView(R.layout.passthrough); - mCheckBoxPassthrough = (CheckBox)findViewById(R.id.CheckPassthrough); - mTextViewOutputChoose = (TextView) findViewById(R.id.AudioOutputText); + File fileHdmi = new File("proc/asound/imxhdmisoc"); + File fileSpdif = new File("proc/asound/imxspdif"); + if (fileHdmi.exists() && !fileSpdif.exists()) { + setContentView(R.layout.passthrough); + mCheckBoxPassthrough = (CheckBox) findViewById(R.id.CheckPassthrough); + mTextViewOutputChoose = (TextView) findViewById(R.id.AudioOutputText); + } else if (!fileHdmi.exists() && fileSpdif.exists()) { + setContentView(R.layout.spdifin); + mSpdifIn = (CheckBox) findViewById(R.id.spdif_in); + mCommand = (TextView) findViewById(R.id.commandText); + } else if (fileHdmi.exists() && fileSpdif.exists()) { + setContentView(R.layout.main); + mCheckBoxPassthrough = (CheckBox) findViewById(R.id.CheckPassthrough); + mSpdifIn = (CheckBox) findViewById(R.id.spdif_in); + mCommand = (TextView) findViewById(R.id.commandText); + mTextViewOutputChoose = (TextView) findViewById(R.id.AudioOutputText); + } else { + setContentView(R.layout.nodevice); + Log.d(TAG, "no device connected"); } - else if(!fileHdmi.exists()&&fileSpdif.exists()) - { - setContentView(R.layout.spdifin); - mSpdifIn = (CheckBox)findViewById(R.id.spdif_in); - mCommand = (TextView) findViewById(R.id.commandText); - } - else if(fileHdmi.exists()&&fileSpdif.exists()) - { - setContentView(R.layout.main); - mCheckBoxPassthrough = (CheckBox)findViewById(R.id.CheckPassthrough); - mSpdifIn = (CheckBox)findViewById(R.id.spdif_in); - mCommand = (TextView) findViewById(R.id.commandText); - mTextViewOutputChoose = (TextView) findViewById(R.id.AudioOutputText); - } - else - { - setContentView(R.layout.nodevice); - Log.d(TAG,"no device connected"); - } - - if(fileHdmi.exists()&&!fileSpdif.exists()) - { - mTextViewOutputChoose.setText(getResources().getString(R.string.output_choose)); - mCheckBoxPassthrough.setText(getResources().getString(R.string.Enable_Passthrough)); - } - else if(!fileHdmi.exists()&&fileSpdif.exists()) - { - mCommand.setText(getResources().getString(R.string.device_choose)); - mSpdifIn.setText(getResources().getString(R.string.Enable_SPDIF_In)); - } - else if(fileHdmi.exists()&&fileSpdif.exists()) - { - mTextViewOutputChoose.setText(getResources().getString(R.string.output_choose)); - mCheckBoxPassthrough.setText(getResources().getString(R.string.Enable_Passthrough)); - mCommand.setText(getResources().getString(R.string.device_choose)); - mSpdifIn.setText(getResources().getString(R.string.Enable_SPDIF_In)); - } - else - Log.d(TAG,"no device connected"); - - if(fileHdmi.exists()&&!fileSpdif.exists()) - { - String value = SystemProperties.get("vendor.persist.audio.pass.through"); - Log.d(TAG,"property vendor.persist.audio.pass.through is " + value); - if(value.equals("2000")) - mCheckBoxPassthrough.setChecked(true); - else - mCheckBoxPassthrough.setChecked(false); - - mCheckBoxPassthrough.setOnClickListener(new OnClickListener() { - public void onClick(View v) { - Log.d(TAG, "CheckBox Passthrough is clicked"); - SystemProperties.set("vendor.persist.audio.pass.through",mCheckBoxPassthrough.isChecked() ? "2000" : "0" ); - } - }); - } - else if (!fileHdmi.exists()&&fileSpdif.exists()) - { - if (AudioSystem.getDeviceConnectionState(AudioSystem.DEVICE_IN_AUX_DIGITAL, "") == AudioSystem.DEVICE_STATE_AVAILABLE) - mSpdifIn.setChecked(true); - else - mSpdifIn.setChecked(false); - - mSpdifIn.setOnClickListener(new OnClickListener() { - public void onClick(View v) { - Log.d(TAG, "SPDIF IN is clicked"); - - setupAudioRoute(); - } - }); - } - else if(fileHdmi.exists()&&fileSpdif.exists()) - { - if (AudioSystem.getDeviceConnectionState(AudioSystem.DEVICE_IN_AUX_DIGITAL, "") == AudioSystem.DEVICE_STATE_AVAILABLE) - mSpdifIn.setChecked(true); - else - mSpdifIn.setChecked(false); - - mSpdifIn.setOnClickListener(new OnClickListener() { - public void onClick(View v) { - Log.d(TAG, "SPDIF IN is clicked"); - - setupAudioRoute(); - } - }); - - String value = SystemProperties.get("vendor.persist.audio.pass.through"); - Log.d(TAG,"property vendor.persist.audio.pass.through is " + value); - if(value.equals("2000")) - mCheckBoxPassthrough.setChecked(true); - else - mCheckBoxPassthrough.setChecked(false); - - mCheckBoxPassthrough.setOnClickListener(new OnClickListener() { - public void onClick(View v) { - Log.d(TAG, "CheckBox Passthrough is clicked"); - SystemProperties.set("vendor.persist.audio.pass.through",mCheckBoxPassthrough.isChecked() ? "2000" : "0" ); - } - }); - } - else - Log.d(TAG, "no device connected and can't do some operation"); - + if (fileHdmi.exists() && !fileSpdif.exists()) { + mTextViewOutputChoose.setText(getResources().getString(R.string.output_choose)); + mCheckBoxPassthrough.setText(getResources().getString(R.string.Enable_Passthrough)); + } else if (!fileHdmi.exists() && fileSpdif.exists()) { + mCommand.setText(getResources().getString(R.string.device_choose)); + mSpdifIn.setText(getResources().getString(R.string.Enable_SPDIF_In)); + } else if (fileHdmi.exists() && fileSpdif.exists()) { + mTextViewOutputChoose.setText(getResources().getString(R.string.output_choose)); + mCheckBoxPassthrough.setText(getResources().getString(R.string.Enable_Passthrough)); + mCommand.setText(getResources().getString(R.string.device_choose)); + mSpdifIn.setText(getResources().getString(R.string.Enable_SPDIF_In)); + } else Log.d(TAG, "no device connected"); + + if (fileHdmi.exists() && !fileSpdif.exists()) { + String value = SystemProperties.get("vendor.persist.audio.pass.through"); + Log.d(TAG, "property vendor.persist.audio.pass.through is " + value); + if (value.equals("2000")) mCheckBoxPassthrough.setChecked(true); + else mCheckBoxPassthrough.setChecked(false); + + mCheckBoxPassthrough.setOnClickListener( + new OnClickListener() { + public void onClick(View v) { + Log.d(TAG, "CheckBox Passthrough is clicked"); + SystemProperties.set( + "vendor.persist.audio.pass.through", + mCheckBoxPassthrough.isChecked() ? "2000" : "0"); + } + }); + } else if (!fileHdmi.exists() && fileSpdif.exists()) { + if (AudioSystem.getDeviceConnectionState(AudioSystem.DEVICE_IN_AUX_DIGITAL, "") + == AudioSystem.DEVICE_STATE_AVAILABLE) mSpdifIn.setChecked(true); + else mSpdifIn.setChecked(false); + + mSpdifIn.setOnClickListener( + new OnClickListener() { + public void onClick(View v) { + Log.d(TAG, "SPDIF IN is clicked"); + + setupAudioRoute(); + } + }); + } else if (fileHdmi.exists() && fileSpdif.exists()) { + if (AudioSystem.getDeviceConnectionState(AudioSystem.DEVICE_IN_AUX_DIGITAL, "") + == AudioSystem.DEVICE_STATE_AVAILABLE) mSpdifIn.setChecked(true); + else mSpdifIn.setChecked(false); + + mSpdifIn.setOnClickListener( + new OnClickListener() { + public void onClick(View v) { + Log.d(TAG, "SPDIF IN is clicked"); + + setupAudioRoute(); + } + }); + + String value = SystemProperties.get("vendor.persist.audio.pass.through"); + Log.d(TAG, "property vendor.persist.audio.pass.through is " + value); + if (value.equals("2000")) mCheckBoxPassthrough.setChecked(true); + else mCheckBoxPassthrough.setChecked(false); + + mCheckBoxPassthrough.setOnClickListener( + new OnClickListener() { + public void onClick(View v) { + Log.d(TAG, "CheckBox Passthrough is clicked"); + SystemProperties.set( + "vendor.persist.audio.pass.through", + mCheckBoxPassthrough.isChecked() ? "2000" : "0"); + } + }); + } else Log.d(TAG, "no device connected and can't do some operation"); } private void setupAudioRoute() { - Log.d(TAG, "SPDIF IN "+ mSpdifIn.isChecked()); - mAudioManager.setWiredDeviceConnectionState(AudioSystem.DEVICE_IN_AUX_DIGITAL, mSpdifIn.isChecked() ? 1 : 0, "", ""); + Log.d(TAG, "SPDIF IN " + mSpdifIn.isChecked()); + mAudioManager.setWiredDeviceConnectionState( + AudioSystem.DEVICE_IN_AUX_DIGITAL, mSpdifIn.isChecked() ? 1 : 0, "", ""); } - } diff --git a/AudioTimeStampTest/com/fsl/AudioTimeStampTest/AudioPlayThread.java b/AudioTimeStampTest/com/fsl/AudioTimeStampTest/AudioPlayThread.java index 61d7ac4..603bd65 100755 --- a/AudioTimeStampTest/com/fsl/AudioTimeStampTest/AudioPlayThread.java +++ b/AudioTimeStampTest/com/fsl/AudioTimeStampTest/AudioPlayThread.java @@ -2,102 +2,97 @@ * Copyright (C) 2014 Freescale Semiconductor, Inc. */ - package com.genius.audio.track; -import java.util.Timer; import android.media.AudioFormat; -import android.media.AudioManager; -import android.media.AudioTrack; import android.os.Handler; import android.os.Message; -import android.text.format.Time; import android.util.Log; -public class AudioPlayThread implements Runnable{ - final int EVENT_PLAY_OVER = 0x100; - final int EVENT_PLAY_STOP = 0x200; - final int EVENT_AVETIME=0x300; - final int EVENT_MINTIME=0x400; - final int EVENT_MAXTIME=0x500; - long my_aveTime; - long my_minTime; - long my_maxTime; - byte []data; - Handler mHandler; - int mFrequency,mChannel,mSampbit; - int mChannel_macro = 0; - int mSampbit_macro=0; - - public AudioPlayThread(byte []data, Handler handler,int frequency, int channel, int sampbit) { - // TODO Auto-generated constructor stub - this.data = data; - mHandler = handler; - mFrequency=frequency; - mChannel=channel; - mSampbit=sampbit; - } - - public void run() { - Log.i("MyThread", "run.."); - if (data == null || data.length == 0){ - return ; - } - - if(mChannel==1) - mChannel_macro=AudioFormat.CHANNEL_CONFIGURATION_MONO; - else if(mChannel==2) - mChannel_macro=AudioFormat.CHANNEL_CONFIGURATION_STEREO; - if(mSampbit==1) - mSampbit_macro=AudioFormat.ENCODING_PCM_8BIT; - else if(mSampbit==2) - mSampbit_macro=AudioFormat.ENCODING_PCM_16BIT; - AudioTrackWrapper myAudioTrack = new AudioTrackWrapper(mFrequency, mChannel_macro, mSampbit_macro); - myAudioTrack.init(); - int playSize = myAudioTrack.getPrimePlaySize(); - Log.i("MyThread", "total data size = " + data.length + ", playSize = " + playSize); - int index = 0; - int offset = 0; - Message msg = null; - while(true){ - try { - Thread.sleep(0); - offset = index * playSize; - if(offset>=data.length){ - System.out.println("finish3"); - msg = Message.obtain(mHandler, EVENT_PLAY_OVER); - mHandler.sendMessage(msg); - break; - } - myAudioTrack.playAudioTrack(data, offset, playSize); - } catch (Exception e) { - // TODO: handle exception - break; - } - index++; - if (index >= data.length){ - break; - } - } - my_aveTime=myAudioTrack.ave_TiemMs(); - my_minTime=myAudioTrack.min_TimeMs(); - my_maxTime=myAudioTrack.max_TimeMs(); - if (msg==null){ - msg=Message.obtain(mHandler,EVENT_PLAY_STOP) ; - mHandler.sendMessage(msg); - } - for(int i=0;i<=100;i++); - msg=Message.obtain(mHandler,EVENT_AVETIME,my_aveTime); - System.out.println("----thread-my_aveTime-----"+msg.obj); - mHandler.sendMessage(msg); - for(int i=0;i<=100;i++); - msg=Message.obtain(mHandler,EVENT_MINTIME,my_minTime); - System.out.println("----thread-my_minTime-----"+my_minTime); - mHandler.sendMessage(msg); - for(int i=0;i<=100;i++); - msg=Message.obtain(mHandler,EVENT_MAXTIME,my_maxTime); - System.out.println("----thread-my_maxTime-----"+my_maxTime); - mHandler.sendMessage(msg); - myAudioTrack.release(); - } +public class AudioPlayThread implements Runnable { + final int EVENT_PLAY_OVER = 0x100; + final int EVENT_PLAY_STOP = 0x200; + final int EVENT_AVETIME = 0x300; + final int EVENT_MINTIME = 0x400; + final int EVENT_MAXTIME = 0x500; + long my_aveTime; + long my_minTime; + long my_maxTime; + byte[] data; + Handler mHandler; + int mFrequency, mChannel, mSampbit; + int mChannel_macro = 0; + int mSampbit_macro = 0; + + public AudioPlayThread(byte[] data, Handler handler, int frequency, int channel, int sampbit) { + // TODO Auto-generated constructor stub + this.data = data; + mHandler = handler; + mFrequency = frequency; + mChannel = channel; + mSampbit = sampbit; + } + + public void run() { + Log.i("MyThread", "run.."); + if (data == null || data.length == 0) { + return; + } + + if (mChannel == 1) mChannel_macro = AudioFormat.CHANNEL_CONFIGURATION_MONO; + else if (mChannel == 2) mChannel_macro = AudioFormat.CHANNEL_CONFIGURATION_STEREO; + if (mSampbit == 1) mSampbit_macro = AudioFormat.ENCODING_PCM_8BIT; + else if (mSampbit == 2) mSampbit_macro = AudioFormat.ENCODING_PCM_16BIT; + AudioTrackWrapper myAudioTrack = + new AudioTrackWrapper(mFrequency, mChannel_macro, mSampbit_macro); + myAudioTrack.init(); + int playSize = myAudioTrack.getPrimePlaySize(); + Log.i("MyThread", "total data size = " + data.length + ", playSize = " + playSize); + int index = 0; + int offset = 0; + Message msg = null; + while (true) { + try { + Thread.sleep(0); + offset = index * playSize; + if (offset >= data.length) { + System.out.println("finish3"); + msg = Message.obtain(mHandler, EVENT_PLAY_OVER); + mHandler.sendMessage(msg); + break; + } + myAudioTrack.playAudioTrack(data, offset, playSize); + } catch (Exception e) { + // TODO: handle exception + break; + } + index++; + if (index >= data.length) { + break; + } + } + my_aveTime = myAudioTrack.ave_TiemMs(); + my_minTime = myAudioTrack.min_TimeMs(); + my_maxTime = myAudioTrack.max_TimeMs(); + if (msg == null) { + msg = Message.obtain(mHandler, EVENT_PLAY_STOP); + mHandler.sendMessage(msg); + } + for (int i = 0; i <= 100; i++) + ; + msg = Message.obtain(mHandler, EVENT_AVETIME, my_aveTime); + System.out.println("----thread-my_aveTime-----" + msg.obj); + mHandler.sendMessage(msg); + for (int i = 0; i <= 100; i++) + ; + msg = Message.obtain(mHandler, EVENT_MINTIME, my_minTime); + System.out.println("----thread-my_minTime-----" + my_minTime); + mHandler.sendMessage(msg); + for (int i = 0; i <= 100; i++) + ; + msg = Message.obtain(mHandler, EVENT_MAXTIME, my_maxTime); + System.out.println("----thread-my_maxTime-----" + my_maxTime); + mHandler.sendMessage(msg); + myAudioTrack.release(); + } } diff --git a/AudioTimeStampTest/com/fsl/AudioTimeStampTest/AudioTimeStampActivity.java b/AudioTimeStampTest/com/fsl/AudioTimeStampTest/AudioTimeStampActivity.java index a1ee255..b68d8e9 100755 --- a/AudioTimeStampTest/com/fsl/AudioTimeStampTest/AudioTimeStampActivity.java +++ b/AudioTimeStampTest/com/fsl/AudioTimeStampTest/AudioTimeStampActivity.java @@ -4,20 +4,14 @@ package com.genius.audio.track; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; import android.app.Activity; import android.os.Bundle; import android.os.Environment; import android.os.Handler; import android.os.Message; import android.view.View; -import android.view.ViewGroup; import android.view.View.OnClickListener; +import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.BaseAdapter; import android.widget.Button; @@ -27,327 +21,347 @@ import android.widget.TextView; import android.widget.Toast; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; public class AudioTimeStampActivity extends Activity { protected static final String REGEX = null; /** Called when the activity is first created. */ final int EVENT_PLAY_OVER = 0x100; - final int EVENT_PLAY_STOP = 0x200; - final int EVENT_AVETIME=0x300; - final int EVENT_MINTIME=0x400; - final int EVENT_MAXTIME=0x500; - Thread mThread = null; - byte []data = null; - Handler mHandler; - int frequency,channel,sampbit; - long my_avetime,my_mintime,my_maxtime; - Button btnPlay, btnStopButton,btnExit; - TextView textView; - TextView resultView1,resultView2,resultView3; - String filePath=null; - + + final int EVENT_PLAY_STOP = 0x200; + final int EVENT_AVETIME = 0x300; + final int EVENT_MINTIME = 0x400; + final int EVENT_MAXTIME = 0x500; + Thread mThread = null; + byte[] data = null; + Handler mHandler; + int frequency, channel, sampbit; + long my_avetime, my_mintime, my_maxtime; + Button btnPlay, btnStopButton, btnExit; + TextView textView; + TextView resultView1, resultView2, resultView3; + String filePath = null; + public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); - textView = (TextView)findViewById(R.id.textview01); - resultView1=(TextView)findViewById(R.id.textview03); - resultView2=(TextView)findViewById(R.id.textview04); - resultView3=(TextView)findViewById(R.id.textview05); + textView = (TextView) findViewById(R.id.textview01); + resultView1 = (TextView) findViewById(R.id.textview03); + resultView2 = (TextView) findViewById(R.id.textview04); + resultView3 = (TextView) findViewById(R.id.textview05); final File[] files = Environment.getExternalStorageDirectory().listFiles(); - -//*******************************files_wav browse******************** - final List fileList = new ArrayList(); - int b=0; - String wav="wav"; - for(int a=0; a fileList = new ArrayList(); + int b = 0; + String wav = "wav"; + for (int a = 0; a < files.length; a++) { + int start = files[a].getName().lastIndexOf("."); + int end = files[a].getName().length(); + String indexName = files[a].getName().substring(start + 1, end); + if (indexName.equals(wav)) { + fileList.add(files[a]); + } + } + // *********************handler deliver message*********************** + mHandler = + new Handler() { + public void handleMessage(Message message) { + if (message.what == EVENT_PLAY_OVER) { + mThread = null; + textView.setText("Finish..."); + } else if (message.what == EVENT_AVETIME) { + my_avetime = (Long) message.obj; + } else if (message.what == EVENT_MINTIME) { + my_mintime = (Long) message.obj; + } else if (message.what == EVENT_MAXTIME) { + my_maxtime = (Long) message.obj; + resultView1.setText("ave_LatencyTimeMs: " + my_avetime); + resultView2.setText("min_LatencyTimeMs: " + my_mintime); + resultView3.setText("max_LatencyTimeMs: " + my_maxtime); + } else if (message.what == EVENT_PLAY_STOP) { + mThread = null; + textView.setText("Stop..."); + } + } + }; + // ********************************spinner***************************** + Spinner spinner = (Spinner) findViewById(R.id.Spinner); + BaseAdapter ba = + new BaseAdapter() { + @Override + public int getCount() { + return fileList.size(); + } - @Override - public long getItemId(int position) - { - // TODO Auto-generated method stub - return 0; - } - @Override - public View getView(int position, View convertView, ViewGroup parent) - { - LinearLayout line = new LinearLayout(AudioTimeStampActivity.this); - line.setOrientation(0); - ImageView image = new ImageView(AudioTimeStampActivity.this); - image.setImageResource(R.drawable.icon); - TextView text = new TextView(AudioTimeStampActivity.this); - text.setText(fileList.get(position).getName()); - text.setTextSize(30); - text.setTextColor(R.color.blue); - line.addView(image); - line.addView(text); - return line; - } - }; - spinner.setAdapter(ba); - spinner.setOnItemSelectedListener(new Spinner.OnItemSelectedListener(){ - @Override - public void onItemSelected(AdapterView arg0, View arg1, int arg2,long arg3) { - filePath="/sdcard/"+fileList.get(arg2).getName(); - // TODO Auto-generated method stub - if(filePath!=null){ - data=null; - data = getPCMData(); - init(); - } - } - @Override - public void onNothingSelected(AdapterView arg0) { - // TODO Auto-generated method stub - } - } - ); - } - public byte[] getPCMData(){ - File file = new File(filePath); - if (file == null|file.length()<=44){ - return null; - } - FileInputStream inStream; - try { - inStream = new FileInputStream(file); - } catch (FileNotFoundException e) { - e.printStackTrace(); - return null; - } - byte[] data_pack = null; - if (inStream != null){ - long size = file.length()-44; - data_pack = new byte[(int) size]; - try { + @Override + public Object getItem(int position) { + return null; + } + + @Override + public long getItemId(int position) { + // TODO Auto-generated method stub + return 0; + } + + @Override + public View getView(int position, View convertView, ViewGroup parent) { + LinearLayout line = new LinearLayout(AudioTimeStampActivity.this); + line.setOrientation(0); + ImageView image = new ImageView(AudioTimeStampActivity.this); + image.setImageResource(R.drawable.icon); + TextView text = new TextView(AudioTimeStampActivity.this); + text.setText(fileList.get(position).getName()); + text.setTextSize(30); + text.setTextColor(R.color.blue); + line.addView(image); + line.addView(text); + return line; + } + }; + spinner.setAdapter(ba); + spinner.setOnItemSelectedListener( + new Spinner.OnItemSelectedListener() { + @Override + public void onItemSelected( + AdapterView arg0, View arg1, int arg2, long arg3) { + filePath = "/sdcard/" + fileList.get(arg2).getName(); + // TODO Auto-generated method stub + if (filePath != null) { + data = null; + data = getPCMData(); + init(); + } + } + + @Override + public void onNothingSelected(AdapterView arg0) { + // TODO Auto-generated method stub + } + }); + } + + public byte[] getPCMData() { + File file = new File(filePath); + if (file == null | file.length() <= 44) { + return null; + } + FileInputStream inStream; + try { + inStream = new FileInputStream(file); + } catch (FileNotFoundException e) { + e.printStackTrace(); + return null; + } + byte[] data_pack = null; + if (inStream != null) { + long size = file.length() - 44; + data_pack = new byte[(int) size]; + try { byte[] tmp = new byte[4]; - System.out.println(""+tmp.length); - byte[] tmp2= new byte[2]; -//************************RIFF******************************* - inStream.read(tmp); - String id = new String(tmp); - -//***********the total numbers of bytes from the next address to the file tail************* - inStream.read(tmp); - int value2 = 0; - int temp2=0; - for (int i = 3; i >= 0; i--) { - value2<<=8; - temp2=tmp[i]&0xff; - value2|=temp2; - } - -//************************WAVE****************************** - inStream.read(tmp); - String type3 = new String(tmp); - System.out.println("type3="+type3); -//************************fmt******************************* - inStream.read(tmp); - String type4 = new String(tmp); - System.out.println("type4="+type4); -//****************filtering bytes(generally 00000010h)************************ - inStream.read(tmp); - int value5 = 0; - int temp5=0; - for (int i = 3; i >=0; i--) { - value5<<=8; - temp5=tmp[i]&0xff; - value5|=temp5; - } - -//****************format type(if the value is 1, it means PCM)******************** - inStream.read(tmp2); - int value6 = 0; - int temp6=0; - for (int i = 1; i >=0; i--) { - value6<<=8; - temp6=tmp2[i]&0xff; - value6|=temp6; - } - -//*************************Channel***************************** - inStream.read(tmp2); - int value7= 0; - int temp7; - for (int i = 1; i >=0; i--) { - value7<<=8; - temp7=tmp2[i]&0xff; - value7|=temp7; - } - channel=value7; - -//************************frequency******************************* - inStream.read(tmp); - int value8= 0; - int temp8; - for (int i = 3; i >=0; i--) { - value8<<=8; - temp8=tmp[i]&0xff; - value8|=temp8; - } - frequency=value8; - -//************************data transfer rate**************************** - inStream.read(tmp); - int value9= 0; - int temp9; - for (int i = 3; i >=0; i--) { - value9<<=8; - temp9=tmp[i]&0xff; - value9|=temp9; - } - -//************************the length of data block ************************ - inStream.read(tmp2); - int value10= 0; - int temp10; - for (int i = 1; i >=0; i--) { - value10<<=8; - temp10=tmp2[i]&0xff; - value10|=temp10; - } - -//************************sample bits******************************* - inStream.read(tmp2); - int value11= 0; - int temp11; - for (int i = 1; i >=0; i--) { - value11<<=8; - temp11=tmp2[i]&0xff; - value11|=temp11; - } - sampbit=value11/8; - -//************************fact******************************* - inStream.read(tmp); - int value12= 0; - int temp12; - for (int i = 3; i >=0; i--) { - value12<<=8; - temp12=tmp[i]&0xff; - value12|=temp12; - } - -//************************size, the value is 4************************** - inStream.read(tmp); - int value13= 0; - int temp13; - for (int i = 3; i >=0; i--) { - value13<<=8; - temp13=tmp[i]&0xff; - value13|=temp13; - } - -//************************data area****************************** - inStream.read(data_pack); - - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - return null; - } - } - - return data_pack; + System.out.println("" + tmp.length); + byte[] tmp2 = new byte[2]; + // ************************RIFF******************************* + inStream.read(tmp); + String id = new String(tmp); + + // ***********the total numbers of bytes from the next address to the file + // tail************* + inStream.read(tmp); + int value2 = 0; + int temp2 = 0; + for (int i = 3; i >= 0; i--) { + value2 <<= 8; + temp2 = tmp[i] & 0xff; + value2 |= temp2; + } + + // ************************WAVE****************************** + inStream.read(tmp); + String type3 = new String(tmp); + System.out.println("type3=" + type3); + // ************************fmt******************************* + inStream.read(tmp); + String type4 = new String(tmp); + System.out.println("type4=" + type4); + // ****************filtering bytes(generally 00000010h)************************ + inStream.read(tmp); + int value5 = 0; + int temp5 = 0; + for (int i = 3; i >= 0; i--) { + value5 <<= 8; + temp5 = tmp[i] & 0xff; + value5 |= temp5; + } + + // ****************format type(if the value is 1, it means PCM)******************** + inStream.read(tmp2); + int value6 = 0; + int temp6 = 0; + for (int i = 1; i >= 0; i--) { + value6 <<= 8; + temp6 = tmp2[i] & 0xff; + value6 |= temp6; + } + + // *************************Channel***************************** + inStream.read(tmp2); + int value7 = 0; + int temp7; + for (int i = 1; i >= 0; i--) { + value7 <<= 8; + temp7 = tmp2[i] & 0xff; + value7 |= temp7; + } + channel = value7; + + // ************************frequency******************************* + inStream.read(tmp); + int value8 = 0; + int temp8; + for (int i = 3; i >= 0; i--) { + value8 <<= 8; + temp8 = tmp[i] & 0xff; + value8 |= temp8; + } + frequency = value8; + + // ************************data transfer rate**************************** + inStream.read(tmp); + int value9 = 0; + int temp9; + for (int i = 3; i >= 0; i--) { + value9 <<= 8; + temp9 = tmp[i] & 0xff; + value9 |= temp9; + } + + // ************************the length of data block ************************ + inStream.read(tmp2); + int value10 = 0; + int temp10; + for (int i = 1; i >= 0; i--) { + value10 <<= 8; + temp10 = tmp2[i] & 0xff; + value10 |= temp10; + } + + // ************************sample bits******************************* + inStream.read(tmp2); + int value11 = 0; + int temp11; + for (int i = 1; i >= 0; i--) { + value11 <<= 8; + temp11 = tmp2[i] & 0xff; + value11 |= temp11; + } + sampbit = value11 / 8; + + // ************************fact******************************* + inStream.read(tmp); + int value12 = 0; + int temp12; + for (int i = 3; i >= 0; i--) { + value12 <<= 8; + temp12 = tmp[i] & 0xff; + value12 |= temp12; + } + + // ************************size, the value is 4************************** + inStream.read(tmp); + int value13 = 0; + int temp13; + for (int i = 3; i >= 0; i--) { + value13 <<= 8; + temp13 = tmp[i] & 0xff; + value13 |= temp13; + } + + // ************************data area****************************** + inStream.read(data_pack); + + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + return null; + } + } + + return data_pack; } - - public void play(){ - - resultView1.setText(""); + + public void play() { + + resultView1.setText(""); resultView2.setText(""); resultView3.setText(""); - if (data == null){ - Toast.makeText(this, "No File...", 200).show(); - return ; - } - - if (mThread == null){ - mThread = new Thread(new AudioPlayThread(data, mHandler,frequency,channel,sampbit)); - System.out.println("*************frequency "+frequency+" channel "+channel+" sampbit "+sampbit); - System.out.println("------------my_avetime------- "+my_avetime+"---my_mintime-----"+my_mintime+"----my_maxtime---"+my_maxtime); - mThread.start(); - textView.setText("Playing..."); - } - } - - public void stop(){ - if (data == null){ - return ; - } - if (mThread != null){ - mThread.interrupt(); - mThread = null; - } - if(my_avetime==0)resultView1.setText(""); - else resultView1.setText("ave_LatencyTimeMs: "+my_avetime); - resultView2.setText("min_LatencyTimeMs: "+my_mintime); - resultView3.setText("max_LatencyTimeMs: "+my_maxtime); - } - public void init(){ - btnPlay = (Button)findViewById(R.id.buttonPlay); - btnStopButton = (Button)findViewById(R.id.buttonStop); - btnPlay.setOnClickListener(new OnClickListener() { - public void onClick(View v) { - // TODO Auto-generated method stub - play(); - } - }); - btnStopButton.setOnClickListener(new OnClickListener() { - public void onClick(View v) { - // TODO Auto-generated method stub - stop(); - } - }); - } + if (data == null) { + Toast.makeText(this, "No File...", 200).show(); + return; + } + + if (mThread == null) { + mThread = new Thread(new AudioPlayThread(data, mHandler, frequency, channel, sampbit)); + System.out.println( + "*************frequency " + + frequency + + " channel " + + channel + + " sampbit " + + sampbit); + System.out.println( + "------------my_avetime------- " + + my_avetime + + "---my_mintime-----" + + my_mintime + + "----my_maxtime---" + + my_maxtime); + mThread.start(); + textView.setText("Playing..."); + } + } + + public void stop() { + if (data == null) { + return; + } + if (mThread != null) { + mThread.interrupt(); + mThread = null; + } + if (my_avetime == 0) resultView1.setText(""); + else resultView1.setText("ave_LatencyTimeMs: " + my_avetime); + resultView2.setText("min_LatencyTimeMs: " + my_mintime); + resultView3.setText("max_LatencyTimeMs: " + my_maxtime); + } + + public void init() { + btnPlay = (Button) findViewById(R.id.buttonPlay); + btnStopButton = (Button) findViewById(R.id.buttonStop); + btnPlay.setOnClickListener( + new OnClickListener() { + public void onClick(View v) { + // TODO Auto-generated method stub + play(); + } + }); + btnStopButton.setOnClickListener( + new OnClickListener() { + public void onClick(View v) { + // TODO Auto-generated method stub + stop(); + } + }); + } - public void onDestroy(){ - System.exit(0); - super.onDestroy(); + public void onDestroy() { + System.exit(0); + super.onDestroy(); } } diff --git a/AudioTimeStampTest/com/fsl/AudioTimeStampTest/AudioTrackWrapper.java b/AudioTimeStampTest/com/fsl/AudioTimeStampTest/AudioTrackWrapper.java index 27d3b4e..e65cd29 100755 --- a/AudioTimeStampTest/com/fsl/AudioTimeStampTest/AudioTrackWrapper.java +++ b/AudioTimeStampTest/com/fsl/AudioTimeStampTest/AudioTrackWrapper.java @@ -2,135 +2,132 @@ * Copyright (C) 2014 Freescale Semiconductor, Inc. */ - package com.genius.audio.track; import android.media.AudioFormat; import android.media.AudioManager; +import android.media.AudioTimestamp; import android.media.AudioTrack; import android.util.Log; -import android.media.AudioTimestamp; public class AudioTrackWrapper { - - int mFrequency; // samplerate - int mChannel; // channel - int mSampBit; // samplebit + + int mFrequency; // samplerate + int mChannel; // channel + int mSampBit; // samplebit int mChanCount; - int mSampleBits; - int i=0; - int totalPcmLen; - long preTimeStampNs; - long curFeedTimeStampNs; - long mNanoTime; - long preframePosition = 0; - long deltaframe; - long deltatimeMs; - long min_deltatimeMs; - long max_deltatimeMs; - long sum=0; - AudioTrack mAudioTrack; - - public AudioTrackWrapper(int frequency, int channel, int sampbit){ - mFrequency = frequency; - mChannel = channel; - mSampBit = sampbit; - } - - public void init(){ - if (mAudioTrack != null){ - release(); - } - int minBufSize = AudioTrack.getMinBufferSize(mFrequency, mChannel, mSampBit); - mAudioTrack = new AudioTrack(AudioManager.STREAM_MUSIC, - mFrequency, - mChannel, - mSampBit, - minBufSize, - AudioTrack.MODE_STREAM); - - if(mChannel == AudioFormat.CHANNEL_CONFIGURATION_MONO) - mChanCount = 1; - else if(mChannel == AudioFormat.CHANNEL_CONFIGURATION_STEREO) - mChanCount = 2; - else - System.out.println("mChanCount is wrong"); - - if(mSampBit==AudioFormat.ENCODING_PCM_8BIT) - mSampleBits=1; - else if(mSampBit==AudioFormat.ENCODING_PCM_16BIT) - mSampleBits=2; - else - System.out.println("mSampleBits is wrong"); - - mAudioTrack.play(); - } - - public void release(){ - if (mAudioTrack != null){ - mAudioTrack.stop(); - mAudioTrack.release(); - } - } - - public void playAudioTrack(byte []data, int offset, int length){ - if (data == null || data.length == 0){ - return ; - } - -// AudioTimestamp mAudioTimestamp=new AudioTimestamp(); -// mAudioTrack.getTimestamp(mAudioTimestamp); - //System.out.println("-----------no any data, cur played frams ---------"+mAudioTimestamp.framePosition); - - try { - mAudioTrack.write(data, offset, length); - totalPcmLen=totalPcmLen+length; - AudioTimestamp mAudioTimestamp=new AudioTimestamp(); - mAudioTrack.getTimestamp(mAudioTimestamp); - long curFeedFrames = (long)totalPcmLen/(mChanCount*mSampleBits); - if(preframePosition>mAudioTimestamp.framePosition){ - System.out.println(" stamp increase err "); - } - System.out.println("----------- mAudioTimestamp.framePosition ---------"+mAudioTimestamp.nanoTime); - preframePosition=mAudioTimestamp.framePosition; - if(curFeedFrames < mAudioTimestamp.framePosition) { - System.out.println(" stamp err "); - System.out.println("----------- cur feed frams ---------"+curFeedFrames); - System.out.println("----------- cur played frams ---------"+mAudioTimestamp.framePosition); - } - deltaframe=curFeedFrames-mAudioTimestamp.framePosition; - deltatimeMs=deltaframe*1000/mFrequency; - if (i==0){ - min_deltatimeMs=deltatimeMs; - max_deltatimeMs=deltatimeMs; - } - if(deltatimeMsmax_deltatimeMs) - max_deltatimeMs=deltatimeMs; - sum+=deltatimeMs; - i++; - } catch (Exception e) { - // TODO: handle exceptionS - Log.i("MyAudioTrack", "catch exception..."); - } - } - - public long ave_TiemMs(){ - if(i==0)return 0; - else return sum/i; - } - public long min_TimeMs(){ - return min_deltatimeMs; - } - public long max_TimeMs(){ - return max_deltatimeMs; - } - - public int getPrimePlaySize(){ - int minBufSize = AudioTrack.getMinBufferSize(mFrequency, mChannel, mSampBit); - return minBufSize * 2; - } -} + int mSampleBits; + int i = 0; + int totalPcmLen; + long preTimeStampNs; + long curFeedTimeStampNs; + long mNanoTime; + long preframePosition = 0; + long deltaframe; + long deltatimeMs; + long min_deltatimeMs; + long max_deltatimeMs; + long sum = 0; + AudioTrack mAudioTrack; + + public AudioTrackWrapper(int frequency, int channel, int sampbit) { + mFrequency = frequency; + mChannel = channel; + mSampBit = sampbit; + } + + public void init() { + if (mAudioTrack != null) { + release(); + } + int minBufSize = AudioTrack.getMinBufferSize(mFrequency, mChannel, mSampBit); + mAudioTrack = + new AudioTrack( + AudioManager.STREAM_MUSIC, + mFrequency, + mChannel, + mSampBit, + minBufSize, + AudioTrack.MODE_STREAM); + + if (mChannel == AudioFormat.CHANNEL_CONFIGURATION_MONO) mChanCount = 1; + else if (mChannel == AudioFormat.CHANNEL_CONFIGURATION_STEREO) mChanCount = 2; + else System.out.println("mChanCount is wrong"); + + if (mSampBit == AudioFormat.ENCODING_PCM_8BIT) mSampleBits = 1; + else if (mSampBit == AudioFormat.ENCODING_PCM_16BIT) mSampleBits = 2; + else System.out.println("mSampleBits is wrong"); + mAudioTrack.play(); + } + public void release() { + if (mAudioTrack != null) { + mAudioTrack.stop(); + mAudioTrack.release(); + } + } + + public void playAudioTrack(byte[] data, int offset, int length) { + if (data == null || data.length == 0) { + return; + } + + // AudioTimestamp mAudioTimestamp=new AudioTimestamp(); + // mAudioTrack.getTimestamp(mAudioTimestamp); + // System.out.println("-----------no any data, cur played frams + // ---------"+mAudioTimestamp.framePosition); + + try { + mAudioTrack.write(data, offset, length); + totalPcmLen = totalPcmLen + length; + AudioTimestamp mAudioTimestamp = new AudioTimestamp(); + mAudioTrack.getTimestamp(mAudioTimestamp); + long curFeedFrames = (long) totalPcmLen / (mChanCount * mSampleBits); + if (preframePosition > mAudioTimestamp.framePosition) { + System.out.println(" stamp increase err "); + } + System.out.println( + "----------- mAudioTimestamp.framePosition ---------" + + mAudioTimestamp.nanoTime); + preframePosition = mAudioTimestamp.framePosition; + if (curFeedFrames < mAudioTimestamp.framePosition) { + System.out.println(" stamp err "); + System.out.println("----------- cur feed frams ---------" + curFeedFrames); + System.out.println( + "----------- cur played frams ---------" + mAudioTimestamp.framePosition); + } + deltaframe = curFeedFrames - mAudioTimestamp.framePosition; + deltatimeMs = deltaframe * 1000 / mFrequency; + if (i == 0) { + min_deltatimeMs = deltatimeMs; + max_deltatimeMs = deltatimeMs; + } + if (deltatimeMs < min_deltatimeMs) min_deltatimeMs = deltatimeMs; + if (deltatimeMs > max_deltatimeMs) max_deltatimeMs = deltatimeMs; + sum += deltatimeMs; + i++; + } catch (Exception e) { + // TODO: handle exceptionS + Log.i("MyAudioTrack", "catch exception..."); + } + } + + public long ave_TiemMs() { + if (i == 0) return 0; + else return sum / i; + } + + public long min_TimeMs() { + return min_deltatimeMs; + } + + public long max_TimeMs() { + return max_deltatimeMs; + } + + public int getPrimePlaySize() { + int minBufSize = AudioTrack.getMinBufferSize(mFrequency, mChannel, mSampBit); + return minBufSize * 2; + } +} diff --git a/Camera2Basic/app/build/generated/data_binding_base_class_source_out/debug/out/com/example/android/camera2/basic/databinding/ActivityCameraBinding.java b/Camera2Basic/app/build/generated/data_binding_base_class_source_out/debug/out/com/example/android/camera2/basic/databinding/ActivityCameraBinding.java index a8e11c7..efd9593 100644 --- a/Camera2Basic/app/build/generated/data_binding_base_class_source_out/debug/out/com/example/android/camera2/basic/databinding/ActivityCameraBinding.java +++ b/Camera2Basic/app/build/generated/data_binding_base_class_source_out/debug/out/com/example/android/camera2/basic/databinding/ActivityCameraBinding.java @@ -4,56 +4,55 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; + import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.fragment.app.FragmentContainerView; import androidx.viewbinding.ViewBinding; + import com.example.android.camera2.basic.R; -import java.lang.NullPointerException; -import java.lang.Override; public final class ActivityCameraBinding implements ViewBinding { - @NonNull - private final FragmentContainerView rootView; - - @NonNull - public final FragmentContainerView fragmentContainer; - - private ActivityCameraBinding(@NonNull FragmentContainerView rootView, - @NonNull FragmentContainerView fragmentContainer) { - this.rootView = rootView; - this.fragmentContainer = fragmentContainer; - } - - @Override - @NonNull - public FragmentContainerView getRoot() { - return rootView; - } - - @NonNull - public static ActivityCameraBinding inflate(@NonNull LayoutInflater inflater) { - return inflate(inflater, null, false); - } - - @NonNull - public static ActivityCameraBinding inflate(@NonNull LayoutInflater inflater, - @Nullable ViewGroup parent, boolean attachToParent) { - View root = inflater.inflate(R.layout.activity_camera, parent, false); - if (attachToParent) { - parent.addView(root); + @NonNull private final FragmentContainerView rootView; + + @NonNull public final FragmentContainerView fragmentContainer; + + private ActivityCameraBinding( + @NonNull FragmentContainerView rootView, + @NonNull FragmentContainerView fragmentContainer) { + this.rootView = rootView; + this.fragmentContainer = fragmentContainer; + } + + @Override + @NonNull + public FragmentContainerView getRoot() { + return rootView; + } + + @NonNull + public static ActivityCameraBinding inflate(@NonNull LayoutInflater inflater) { + return inflate(inflater, null, false); } - return bind(root); - } - @NonNull - public static ActivityCameraBinding bind(@NonNull View rootView) { - if (rootView == null) { - throw new NullPointerException("rootView"); + @NonNull + public static ActivityCameraBinding inflate( + @NonNull LayoutInflater inflater, @Nullable ViewGroup parent, boolean attachToParent) { + View root = inflater.inflate(R.layout.activity_camera, parent, false); + if (attachToParent) { + parent.addView(root); + } + return bind(root); } - FragmentContainerView fragmentContainer = (FragmentContainerView) rootView; + @NonNull + public static ActivityCameraBinding bind(@NonNull View rootView) { + if (rootView == null) { + throw new NullPointerException("rootView"); + } - return new ActivityCameraBinding((FragmentContainerView) rootView, fragmentContainer); - } + FragmentContainerView fragmentContainer = (FragmentContainerView) rootView; + + return new ActivityCameraBinding((FragmentContainerView) rootView, fragmentContainer); + } } diff --git a/Camera2Basic/app/build/generated/data_binding_base_class_source_out/debug/out/com/example/android/camera2/basic/databinding/FragmentCameraBinding.java b/Camera2Basic/app/build/generated/data_binding_base_class_source_out/debug/out/com/example/android/camera2/basic/databinding/FragmentCameraBinding.java index 79d8773..f274d7a 100644 --- a/Camera2Basic/app/build/generated/data_binding_base_class_source_out/debug/out/com/example/android/camera2/basic/databinding/FragmentCameraBinding.java +++ b/Camera2Basic/app/build/generated/data_binding_base_class_source_out/debug/out/com/example/android/camera2/basic/databinding/FragmentCameraBinding.java @@ -11,645 +11,704 @@ import android.widget.RadioGroup; import android.widget.SeekBar; import android.widget.TextView; + import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.constraintlayout.widget.ConstraintLayout; import androidx.viewbinding.ViewBinding; + import com.example.android.camera.utils.AutoFitSurfaceView; import com.example.android.camera2.basic.R; -import java.lang.NullPointerException; -import java.lang.Override; -import java.lang.String; public final class FragmentCameraBinding implements ViewBinding { - @NonNull - private final ConstraintLayout rootView; - - @NonNull - public final RadioButton AWB; - - @NonNull - public final RadioButton CLOUDYDAYLIGHT; - - @NonNull - public final RadioButton DAYLIGHT; - - @NonNull - public final RadioButton FLUORESCENT; - - /** - * This binding is not available in all configurations. - *

- * Present: - *

    - *
  • layout-land/
  • - *
- * - * Absent: - *
    - *
  • layout/
  • - *
- */ - @Nullable - public final CheckBox HDR; - - @NonNull - public final RadioButton INCANDESCENT; - - /** - * This binding is not available in all configurations. - *

- * Present: - *

    - *
  • layout-land/
  • - *
- * - * Absent: - *
    - *
  • layout/
  • - *
- */ - @Nullable - public final CheckBox LSC; - - @NonNull - public final RadioButton TWILIGHT; - - @NonNull - public final RadioButton WARMFLUORESCENT; - - /** - * This binding is not available in all configurations. - *

- * Present: - *

    - *
  • layout-land/
  • - *
- * - * Absent: - *
    - *
  • layout/
  • - *
- */ - @Nullable - public final SeekBar brightness; - - @NonNull - public final ImageButton captureButton; - - /** - * This binding is not available in all configurations. - *

- * Present: - *

    - *
  • layout-land/
  • - *
- * - * Absent: - *
    - *
  • layout/
  • - *
- */ - @Nullable - public final SeekBar contrast; - - /** - * This binding is not available in all configurations. - *

- * Present: - *

    - *
  • layout-land/
  • - *
- * - * Absent: - *
    - *
  • layout/
  • - *
- */ - @Nullable - public final TextView currentBrightness; - - /** - * This binding is not available in all configurations. - *

- * Present: - *

    - *
  • layout-land/
  • - *
- * - * Absent: - *
    - *
  • layout/
  • - *
- */ - @Nullable - public final TextView currentContrast; - - @NonNull - public final TextView currentExposureTime; - - /** - * This binding is not available in all configurations. - *

- * Present: - *

    - *
  • layout-land/
  • - *
- * - * Absent: - *
    - *
  • layout/
  • - *
- */ - @Nullable - public final TextView currentGamma; - - /** - * This binding is not available in all configurations. - *

- * Present: - *

    - *
  • layout-land/
  • - *
- * - * Absent: - *
    - *
  • layout/
  • - *
- */ - @Nullable - public final TextView currentHue; - - /** - * This binding is not available in all configurations. - *

- * Present: - *

    - *
  • layout-land/
  • - *
- * - * Absent: - *
    - *
  • layout/
  • - *
- */ - @Nullable - public final TextView currentSaturation; - - /** - * This binding is not available in all configurations. - *

- * Present: - *

    - *
  • layout-land/
  • - *
- * - * Absent: - *
    - *
  • layout/
  • - *
- */ - @Nullable - public final TextView currentSharpLevel; - - @NonNull - public final Button dewarp; - - @NonNull - public final SeekBar exposureGain; - - @NonNull - public final SeekBar exposureTime; - - /** - * This binding is not available in all configurations. - *

- * Present: - *

    - *
  • layout-land/
  • - *
- * - * Absent: - *
    - *
  • layout/
  • - *
- */ - @Nullable - public final SeekBar gamma; - - @NonNull - public final Button hflip; - - /** - * This binding is not available in all configurations. - *

- * Present: - *

    - *
  • layout-land/
  • - *
- * - * Absent: - *
    - *
  • layout/
  • - *
- */ - @Nullable - public final SeekBar hue; - - @NonNull - public final View overlay; - - /** - * This binding is not available in all configurations. - *

- * Present: - *

    - *
  • layout-land/
  • - *
- * - * Absent: - *
    - *
  • layout/
  • - *
- */ - @Nullable - public final SeekBar saturation; - - /** - * This binding is not available in all configurations. - *

- * Present: - *

    - *
  • layout-land/
  • - *
- * - * Absent: - *
    - *
  • layout/
  • - *
- */ - @Nullable - public final SeekBar sharpLevel; - - /** - * This binding is not available in all configurations. - *

- * Present: - *

    - *
  • layout-land/
  • - *
- * - * Absent: - *
    - *
  • layout/
  • - *
- */ - @Nullable - public final TextView textBrightness; - - /** - * This binding is not available in all configurations. - *

- * Present: - *

    - *
  • layout-land/
  • - *
- * - * Absent: - *
    - *
  • layout/
  • - *
- */ - @Nullable - public final TextView textContrast; - - @NonNull - public final TextView textExposureGain; - - @NonNull - public final TextView textExposureTime; - - /** - * This binding is not available in all configurations. - *

- * Present: - *

    - *
  • layout-land/
  • - *
- * - * Absent: - *
    - *
  • layout/
  • - *
- */ - @Nullable - public final TextView textGamma; - - /** - * This binding is not available in all configurations. - *

- * Present: - *

    - *
  • layout-land/
  • - *
- * - * Absent: - *
    - *
  • layout/
  • - *
- */ - @Nullable - public final TextView textHue; - - /** - * This binding is not available in all configurations. - *

- * Present: - *

    - *
  • layout-land/
  • - *
- * - * Absent: - *
    - *
  • layout/
  • - *
- */ - @Nullable - public final TextView textSaturation; - - /** - * This binding is not available in all configurations. - *

- * Present: - *

    - *
  • layout-land/
  • - *
- * - * Absent: - *
    - *
  • layout/
  • - *
- */ - @Nullable - public final TextView textSharpLevel; - - @NonNull - public final Button vflip; - - @NonNull - public final AutoFitSurfaceView viewFinder; - - @NonNull - public final RadioGroup wb; - - private FragmentCameraBinding(@NonNull ConstraintLayout rootView, @NonNull RadioButton AWB, - @NonNull RadioButton CLOUDYDAYLIGHT, @NonNull RadioButton DAYLIGHT, - @NonNull RadioButton FLUORESCENT, @Nullable CheckBox HDR, @NonNull RadioButton INCANDESCENT, - @Nullable CheckBox LSC, @NonNull RadioButton TWILIGHT, @NonNull RadioButton WARMFLUORESCENT, - @Nullable SeekBar brightness, @NonNull ImageButton captureButton, @Nullable SeekBar contrast, - @Nullable TextView currentBrightness, @Nullable TextView currentContrast, - @NonNull TextView currentExposureTime, @Nullable TextView currentGamma, - @Nullable TextView currentHue, @Nullable TextView currentSaturation, - @Nullable TextView currentSharpLevel, @NonNull Button dewarp, @NonNull SeekBar exposureGain, - @NonNull SeekBar exposureTime, @Nullable SeekBar gamma, @NonNull Button hflip, - @Nullable SeekBar hue, @NonNull View overlay, @Nullable SeekBar saturation, - @Nullable SeekBar sharpLevel, @Nullable TextView textBrightness, - @Nullable TextView textContrast, @NonNull TextView textExposureGain, - @NonNull TextView textExposureTime, @Nullable TextView textGamma, @Nullable TextView textHue, - @Nullable TextView textSaturation, @Nullable TextView textSharpLevel, @NonNull Button vflip, - @NonNull AutoFitSurfaceView viewFinder, @NonNull RadioGroup wb) { - this.rootView = rootView; - this.AWB = AWB; - this.CLOUDYDAYLIGHT = CLOUDYDAYLIGHT; - this.DAYLIGHT = DAYLIGHT; - this.FLUORESCENT = FLUORESCENT; - this.HDR = HDR; - this.INCANDESCENT = INCANDESCENT; - this.LSC = LSC; - this.TWILIGHT = TWILIGHT; - this.WARMFLUORESCENT = WARMFLUORESCENT; - this.brightness = brightness; - this.captureButton = captureButton; - this.contrast = contrast; - this.currentBrightness = currentBrightness; - this.currentContrast = currentContrast; - this.currentExposureTime = currentExposureTime; - this.currentGamma = currentGamma; - this.currentHue = currentHue; - this.currentSaturation = currentSaturation; - this.currentSharpLevel = currentSharpLevel; - this.dewarp = dewarp; - this.exposureGain = exposureGain; - this.exposureTime = exposureTime; - this.gamma = gamma; - this.hflip = hflip; - this.hue = hue; - this.overlay = overlay; - this.saturation = saturation; - this.sharpLevel = sharpLevel; - this.textBrightness = textBrightness; - this.textContrast = textContrast; - this.textExposureGain = textExposureGain; - this.textExposureTime = textExposureTime; - this.textGamma = textGamma; - this.textHue = textHue; - this.textSaturation = textSaturation; - this.textSharpLevel = textSharpLevel; - this.vflip = vflip; - this.viewFinder = viewFinder; - this.wb = wb; - } - - @Override - @NonNull - public ConstraintLayout getRoot() { - return rootView; - } - - @NonNull - public static FragmentCameraBinding inflate(@NonNull LayoutInflater inflater) { - return inflate(inflater, null, false); - } - - @NonNull - public static FragmentCameraBinding inflate(@NonNull LayoutInflater inflater, - @Nullable ViewGroup parent, boolean attachToParent) { - View root = inflater.inflate(R.layout.fragment_camera, parent, false); - if (attachToParent) { - parent.addView(root); + @NonNull private final ConstraintLayout rootView; + + @NonNull public final RadioButton AWB; + + @NonNull public final RadioButton CLOUDYDAYLIGHT; + + @NonNull public final RadioButton DAYLIGHT; + + @NonNull public final RadioButton FLUORESCENT; + + /** + * This binding is not available in all configurations. + * + *

Present: + * + *

    + *
  • layout-land/ + *
+ * + * Absent: + * + *
    + *
  • layout/ + *
+ */ + @Nullable public final CheckBox HDR; + + @NonNull public final RadioButton INCANDESCENT; + + /** + * This binding is not available in all configurations. + * + *

Present: + * + *

    + *
  • layout-land/ + *
+ * + * Absent: + * + *
    + *
  • layout/ + *
+ */ + @Nullable public final CheckBox LSC; + + @NonNull public final RadioButton TWILIGHT; + + @NonNull public final RadioButton WARMFLUORESCENT; + + /** + * This binding is not available in all configurations. + * + *

Present: + * + *

    + *
  • layout-land/ + *
+ * + * Absent: + * + *
    + *
  • layout/ + *
+ */ + @Nullable public final SeekBar brightness; + + @NonNull public final ImageButton captureButton; + + /** + * This binding is not available in all configurations. + * + *

Present: + * + *

    + *
  • layout-land/ + *
+ * + * Absent: + * + *
    + *
  • layout/ + *
+ */ + @Nullable public final SeekBar contrast; + + /** + * This binding is not available in all configurations. + * + *

Present: + * + *

    + *
  • layout-land/ + *
+ * + * Absent: + * + *
    + *
  • layout/ + *
+ */ + @Nullable public final TextView currentBrightness; + + /** + * This binding is not available in all configurations. + * + *

Present: + * + *

    + *
  • layout-land/ + *
+ * + * Absent: + * + *
    + *
  • layout/ + *
+ */ + @Nullable public final TextView currentContrast; + + @NonNull public final TextView currentExposureTime; + + /** + * This binding is not available in all configurations. + * + *

Present: + * + *

    + *
  • layout-land/ + *
+ * + * Absent: + * + *
    + *
  • layout/ + *
+ */ + @Nullable public final TextView currentGamma; + + /** + * This binding is not available in all configurations. + * + *

Present: + * + *

    + *
  • layout-land/ + *
+ * + * Absent: + * + *
    + *
  • layout/ + *
+ */ + @Nullable public final TextView currentHue; + + /** + * This binding is not available in all configurations. + * + *

Present: + * + *

    + *
  • layout-land/ + *
+ * + * Absent: + * + *
    + *
  • layout/ + *
+ */ + @Nullable public final TextView currentSaturation; + + /** + * This binding is not available in all configurations. + * + *

Present: + * + *

    + *
  • layout-land/ + *
+ * + * Absent: + * + *
    + *
  • layout/ + *
+ */ + @Nullable public final TextView currentSharpLevel; + + @NonNull public final Button dewarp; + + @NonNull public final SeekBar exposureGain; + + @NonNull public final SeekBar exposureTime; + + /** + * This binding is not available in all configurations. + * + *

Present: + * + *

    + *
  • layout-land/ + *
+ * + * Absent: + * + *
    + *
  • layout/ + *
+ */ + @Nullable public final SeekBar gamma; + + @NonNull public final Button hflip; + + /** + * This binding is not available in all configurations. + * + *

Present: + * + *

    + *
  • layout-land/ + *
+ * + * Absent: + * + *
    + *
  • layout/ + *
+ */ + @Nullable public final SeekBar hue; + + @NonNull public final View overlay; + + /** + * This binding is not available in all configurations. + * + *

Present: + * + *

    + *
  • layout-land/ + *
+ * + * Absent: + * + *
    + *
  • layout/ + *
+ */ + @Nullable public final SeekBar saturation; + + /** + * This binding is not available in all configurations. + * + *

Present: + * + *

    + *
  • layout-land/ + *
+ * + * Absent: + * + *
    + *
  • layout/ + *
+ */ + @Nullable public final SeekBar sharpLevel; + + /** + * This binding is not available in all configurations. + * + *

Present: + * + *

    + *
  • layout-land/ + *
+ * + * Absent: + * + *
    + *
  • layout/ + *
+ */ + @Nullable public final TextView textBrightness; + + /** + * This binding is not available in all configurations. + * + *

Present: + * + *

    + *
  • layout-land/ + *
+ * + * Absent: + * + *
    + *
  • layout/ + *
+ */ + @Nullable public final TextView textContrast; + + @NonNull public final TextView textExposureGain; + + @NonNull public final TextView textExposureTime; + + /** + * This binding is not available in all configurations. + * + *

Present: + * + *

    + *
  • layout-land/ + *
+ * + * Absent: + * + *
    + *
  • layout/ + *
+ */ + @Nullable public final TextView textGamma; + + /** + * This binding is not available in all configurations. + * + *

Present: + * + *

    + *
  • layout-land/ + *
+ * + * Absent: + * + *
    + *
  • layout/ + *
+ */ + @Nullable public final TextView textHue; + + /** + * This binding is not available in all configurations. + * + *

Present: + * + *

    + *
  • layout-land/ + *
+ * + * Absent: + * + *
    + *
  • layout/ + *
+ */ + @Nullable public final TextView textSaturation; + + /** + * This binding is not available in all configurations. + * + *

Present: + * + *

    + *
  • layout-land/ + *
+ * + * Absent: + * + *
    + *
  • layout/ + *
+ */ + @Nullable public final TextView textSharpLevel; + + @NonNull public final Button vflip; + + @NonNull public final AutoFitSurfaceView viewFinder; + + @NonNull public final RadioGroup wb; + + private FragmentCameraBinding( + @NonNull ConstraintLayout rootView, + @NonNull RadioButton AWB, + @NonNull RadioButton CLOUDYDAYLIGHT, + @NonNull RadioButton DAYLIGHT, + @NonNull RadioButton FLUORESCENT, + @Nullable CheckBox HDR, + @NonNull RadioButton INCANDESCENT, + @Nullable CheckBox LSC, + @NonNull RadioButton TWILIGHT, + @NonNull RadioButton WARMFLUORESCENT, + @Nullable SeekBar brightness, + @NonNull ImageButton captureButton, + @Nullable SeekBar contrast, + @Nullable TextView currentBrightness, + @Nullable TextView currentContrast, + @NonNull TextView currentExposureTime, + @Nullable TextView currentGamma, + @Nullable TextView currentHue, + @Nullable TextView currentSaturation, + @Nullable TextView currentSharpLevel, + @NonNull Button dewarp, + @NonNull SeekBar exposureGain, + @NonNull SeekBar exposureTime, + @Nullable SeekBar gamma, + @NonNull Button hflip, + @Nullable SeekBar hue, + @NonNull View overlay, + @Nullable SeekBar saturation, + @Nullable SeekBar sharpLevel, + @Nullable TextView textBrightness, + @Nullable TextView textContrast, + @NonNull TextView textExposureGain, + @NonNull TextView textExposureTime, + @Nullable TextView textGamma, + @Nullable TextView textHue, + @Nullable TextView textSaturation, + @Nullable TextView textSharpLevel, + @NonNull Button vflip, + @NonNull AutoFitSurfaceView viewFinder, + @NonNull RadioGroup wb) { + this.rootView = rootView; + this.AWB = AWB; + this.CLOUDYDAYLIGHT = CLOUDYDAYLIGHT; + this.DAYLIGHT = DAYLIGHT; + this.FLUORESCENT = FLUORESCENT; + this.HDR = HDR; + this.INCANDESCENT = INCANDESCENT; + this.LSC = LSC; + this.TWILIGHT = TWILIGHT; + this.WARMFLUORESCENT = WARMFLUORESCENT; + this.brightness = brightness; + this.captureButton = captureButton; + this.contrast = contrast; + this.currentBrightness = currentBrightness; + this.currentContrast = currentContrast; + this.currentExposureTime = currentExposureTime; + this.currentGamma = currentGamma; + this.currentHue = currentHue; + this.currentSaturation = currentSaturation; + this.currentSharpLevel = currentSharpLevel; + this.dewarp = dewarp; + this.exposureGain = exposureGain; + this.exposureTime = exposureTime; + this.gamma = gamma; + this.hflip = hflip; + this.hue = hue; + this.overlay = overlay; + this.saturation = saturation; + this.sharpLevel = sharpLevel; + this.textBrightness = textBrightness; + this.textContrast = textContrast; + this.textExposureGain = textExposureGain; + this.textExposureTime = textExposureTime; + this.textGamma = textGamma; + this.textHue = textHue; + this.textSaturation = textSaturation; + this.textSharpLevel = textSharpLevel; + this.vflip = vflip; + this.viewFinder = viewFinder; + this.wb = wb; } - return bind(root); - } - - @NonNull - public static FragmentCameraBinding bind(@NonNull View rootView) { - // The body of this method is generated in a way you would not otherwise write. - // This is done to optimize the compiled bytecode for size and performance. - int id; - missingId: { - id = R.id.AWB; - RadioButton AWB = rootView.findViewById(id); - if (AWB == null) { - break missingId; - } - - id = R.id.CLOUDY_DAYLIGHT; - RadioButton CLOUDYDAYLIGHT = rootView.findViewById(id); - if (CLOUDYDAYLIGHT == null) { - break missingId; - } - - id = R.id.DAYLIGHT; - RadioButton DAYLIGHT = rootView.findViewById(id); - if (DAYLIGHT == null) { - break missingId; - } - - id = R.id.FLUORESCENT; - RadioButton FLUORESCENT = rootView.findViewById(id); - if (FLUORESCENT == null) { - break missingId; - } - - CheckBox HDR = rootView.findViewById(R.id.HDR); - - id = R.id.INCANDESCENT; - RadioButton INCANDESCENT = rootView.findViewById(id); - if (INCANDESCENT == null) { - break missingId; - } - - CheckBox LSC = rootView.findViewById(R.id.LSC); - - id = R.id.TWILIGHT; - RadioButton TWILIGHT = rootView.findViewById(id); - if (TWILIGHT == null) { - break missingId; - } - - id = R.id.WARM_FLUORESCENT; - RadioButton WARMFLUORESCENT = rootView.findViewById(id); - if (WARMFLUORESCENT == null) { - break missingId; - } - - SeekBar brightness = rootView.findViewById(R.id.brightness); - - id = R.id.capture_button; - ImageButton captureButton = rootView.findViewById(id); - if (captureButton == null) { - break missingId; - } - SeekBar contrast = rootView.findViewById(R.id.contrast); - - TextView currentBrightness = rootView.findViewById(R.id.current_brightness); - - TextView currentContrast = rootView.findViewById(R.id.current_contrast); - - id = R.id.current_exposure_time; - TextView currentExposureTime = rootView.findViewById(id); - if (currentExposureTime == null) { - break missingId; - } - - TextView currentGamma = rootView.findViewById(R.id.current_gamma); - - TextView currentHue = rootView.findViewById(R.id.current_hue); - - TextView currentSaturation = rootView.findViewById(R.id.current_saturation); - - TextView currentSharpLevel = rootView.findViewById(R.id.current_sharp_level); - - id = R.id.dewarp; - Button dewarp = rootView.findViewById(id); - if (dewarp == null) { - break missingId; - } - - id = R.id.exposure_gain; - SeekBar exposureGain = rootView.findViewById(id); - if (exposureGain == null) { - break missingId; - } - - id = R.id.exposure_time; - SeekBar exposureTime = rootView.findViewById(id); - if (exposureTime == null) { - break missingId; - } - - SeekBar gamma = rootView.findViewById(R.id.gamma); - - id = R.id.hflip; - Button hflip = rootView.findViewById(id); - if (hflip == null) { - break missingId; - } - - SeekBar hue = rootView.findViewById(R.id.hue); - - id = R.id.overlay; - View overlay = rootView.findViewById(id); - if (overlay == null) { - break missingId; - } - - SeekBar saturation = rootView.findViewById(R.id.saturation); - - SeekBar sharpLevel = rootView.findViewById(R.id.sharp_level); - - TextView textBrightness = rootView.findViewById(R.id.text_brightness); - - TextView textContrast = rootView.findViewById(R.id.text_contrast); + @Override + @NonNull + public ConstraintLayout getRoot() { + return rootView; + } - id = R.id.text_exposure_gain; - TextView textExposureGain = rootView.findViewById(id); - if (textExposureGain == null) { - break missingId; - } + @NonNull + public static FragmentCameraBinding inflate(@NonNull LayoutInflater inflater) { + return inflate(inflater, null, false); + } - id = R.id.text_exposure_time; - TextView textExposureTime = rootView.findViewById(id); - if (textExposureTime == null) { - break missingId; - } + @NonNull + public static FragmentCameraBinding inflate( + @NonNull LayoutInflater inflater, @Nullable ViewGroup parent, boolean attachToParent) { + View root = inflater.inflate(R.layout.fragment_camera, parent, false); + if (attachToParent) { + parent.addView(root); + } + return bind(root); + } - TextView textGamma = rootView.findViewById(R.id.text_gamma); + @NonNull + public static FragmentCameraBinding bind(@NonNull View rootView) { + // The body of this method is generated in a way you would not otherwise write. + // This is done to optimize the compiled bytecode for size and performance. + int id; + missingId: + { + id = R.id.AWB; + RadioButton AWB = rootView.findViewById(id); + if (AWB == null) { + break missingId; + } + + id = R.id.CLOUDY_DAYLIGHT; + RadioButton CLOUDYDAYLIGHT = rootView.findViewById(id); + if (CLOUDYDAYLIGHT == null) { + break missingId; + } + + id = R.id.DAYLIGHT; + RadioButton DAYLIGHT = rootView.findViewById(id); + if (DAYLIGHT == null) { + break missingId; + } - TextView textHue = rootView.findViewById(R.id.text_hue); + id = R.id.FLUORESCENT; + RadioButton FLUORESCENT = rootView.findViewById(id); + if (FLUORESCENT == null) { + break missingId; + } + + CheckBox HDR = rootView.findViewById(R.id.HDR); + + id = R.id.INCANDESCENT; + RadioButton INCANDESCENT = rootView.findViewById(id); + if (INCANDESCENT == null) { + break missingId; + } - TextView textSaturation = rootView.findViewById(R.id.text_saturation); + CheckBox LSC = rootView.findViewById(R.id.LSC); - TextView textSharpLevel = rootView.findViewById(R.id.text_sharp_level); + id = R.id.TWILIGHT; + RadioButton TWILIGHT = rootView.findViewById(id); + if (TWILIGHT == null) { + break missingId; + } - id = R.id.vflip; - Button vflip = rootView.findViewById(id); - if (vflip == null) { - break missingId; - } + id = R.id.WARM_FLUORESCENT; + RadioButton WARMFLUORESCENT = rootView.findViewById(id); + if (WARMFLUORESCENT == null) { + break missingId; + } - id = R.id.view_finder; - AutoFitSurfaceView viewFinder = rootView.findViewById(id); - if (viewFinder == null) { - break missingId; - } + SeekBar brightness = rootView.findViewById(R.id.brightness); - id = R.id.wb; - RadioGroup wb = rootView.findViewById(id); - if (wb == null) { - break missingId; - } + id = R.id.capture_button; + ImageButton captureButton = rootView.findViewById(id); + if (captureButton == null) { + break missingId; + } - return new FragmentCameraBinding((ConstraintLayout) rootView, AWB, CLOUDYDAYLIGHT, DAYLIGHT, - FLUORESCENT, HDR, INCANDESCENT, LSC, TWILIGHT, WARMFLUORESCENT, brightness, captureButton, - contrast, currentBrightness, currentContrast, currentExposureTime, currentGamma, - currentHue, currentSaturation, currentSharpLevel, dewarp, exposureGain, exposureTime, - gamma, hflip, hue, overlay, saturation, sharpLevel, textBrightness, textContrast, - textExposureGain, textExposureTime, textGamma, textHue, textSaturation, textSharpLevel, - vflip, viewFinder, wb); + SeekBar contrast = rootView.findViewById(R.id.contrast); + + TextView currentBrightness = rootView.findViewById(R.id.current_brightness); + + TextView currentContrast = rootView.findViewById(R.id.current_contrast); + + id = R.id.current_exposure_time; + TextView currentExposureTime = rootView.findViewById(id); + if (currentExposureTime == null) { + break missingId; + } + + TextView currentGamma = rootView.findViewById(R.id.current_gamma); + + TextView currentHue = rootView.findViewById(R.id.current_hue); + + TextView currentSaturation = rootView.findViewById(R.id.current_saturation); + + TextView currentSharpLevel = rootView.findViewById(R.id.current_sharp_level); + + id = R.id.dewarp; + Button dewarp = rootView.findViewById(id); + if (dewarp == null) { + break missingId; + } + + id = R.id.exposure_gain; + SeekBar exposureGain = rootView.findViewById(id); + if (exposureGain == null) { + break missingId; + } + + id = R.id.exposure_time; + SeekBar exposureTime = rootView.findViewById(id); + if (exposureTime == null) { + break missingId; + } + + SeekBar gamma = rootView.findViewById(R.id.gamma); + + id = R.id.hflip; + Button hflip = rootView.findViewById(id); + if (hflip == null) { + break missingId; + } + + SeekBar hue = rootView.findViewById(R.id.hue); + + id = R.id.overlay; + View overlay = rootView.findViewById(id); + if (overlay == null) { + break missingId; + } + + SeekBar saturation = rootView.findViewById(R.id.saturation); + + SeekBar sharpLevel = rootView.findViewById(R.id.sharp_level); + + TextView textBrightness = rootView.findViewById(R.id.text_brightness); + + TextView textContrast = rootView.findViewById(R.id.text_contrast); + + id = R.id.text_exposure_gain; + TextView textExposureGain = rootView.findViewById(id); + if (textExposureGain == null) { + break missingId; + } + + id = R.id.text_exposure_time; + TextView textExposureTime = rootView.findViewById(id); + if (textExposureTime == null) { + break missingId; + } + + TextView textGamma = rootView.findViewById(R.id.text_gamma); + + TextView textHue = rootView.findViewById(R.id.text_hue); + + TextView textSaturation = rootView.findViewById(R.id.text_saturation); + + TextView textSharpLevel = rootView.findViewById(R.id.text_sharp_level); + + id = R.id.vflip; + Button vflip = rootView.findViewById(id); + if (vflip == null) { + break missingId; + } + + id = R.id.view_finder; + AutoFitSurfaceView viewFinder = rootView.findViewById(id); + if (viewFinder == null) { + break missingId; + } + + id = R.id.wb; + RadioGroup wb = rootView.findViewById(id); + if (wb == null) { + break missingId; + } + + return new FragmentCameraBinding( + (ConstraintLayout) rootView, + AWB, + CLOUDYDAYLIGHT, + DAYLIGHT, + FLUORESCENT, + HDR, + INCANDESCENT, + LSC, + TWILIGHT, + WARMFLUORESCENT, + brightness, + captureButton, + contrast, + currentBrightness, + currentContrast, + currentExposureTime, + currentGamma, + currentHue, + currentSaturation, + currentSharpLevel, + dewarp, + exposureGain, + exposureTime, + gamma, + hflip, + hue, + overlay, + saturation, + sharpLevel, + textBrightness, + textContrast, + textExposureGain, + textExposureTime, + textGamma, + textHue, + textSaturation, + textSharpLevel, + vflip, + viewFinder, + wb); + } + String missingId = rootView.getResources().getResourceName(id); + throw new NullPointerException("Missing required view with ID: ".concat(missingId)); } - String missingId = rootView.getResources().getResourceName(id); - throw new NullPointerException("Missing required view with ID: ".concat(missingId)); - } } diff --git a/Camera2Basic/app/build/generated/data_binding_base_class_source_out/debug/out/com/example/android/camera2/basic/databinding/FragmentVideoBinding.java b/Camera2Basic/app/build/generated/data_binding_base_class_source_out/debug/out/com/example/android/camera2/basic/databinding/FragmentVideoBinding.java index 35e138b..9f5b361 100644 --- a/Camera2Basic/app/build/generated/data_binding_base_class_source_out/debug/out/com/example/android/camera2/basic/databinding/FragmentVideoBinding.java +++ b/Camera2Basic/app/build/generated/data_binding_base_class_source_out/debug/out/com/example/android/camera2/basic/databinding/FragmentVideoBinding.java @@ -11,645 +11,704 @@ import android.widget.RadioGroup; import android.widget.SeekBar; import android.widget.TextView; + import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.constraintlayout.widget.ConstraintLayout; import androidx.viewbinding.ViewBinding; + import com.example.android.camera.utils.AutoFitSurfaceView; import com.example.android.camera2.basic.R; -import java.lang.NullPointerException; -import java.lang.Override; -import java.lang.String; public final class FragmentVideoBinding implements ViewBinding { - @NonNull - private final ConstraintLayout rootView; - - @NonNull - public final RadioButton AWB; - - @NonNull - public final RadioButton CLOUDYDAYLIGHT; - - @NonNull - public final RadioButton DAYLIGHT; - - @NonNull - public final RadioButton FLUORESCENT; - - /** - * This binding is not available in all configurations. - *

- * Present: - *

    - *
  • layout-land/
  • - *
- * - * Absent: - *
    - *
  • layout/
  • - *
- */ - @Nullable - public final CheckBox HDR; - - @NonNull - public final RadioButton INCANDESCENT; - - /** - * This binding is not available in all configurations. - *

- * Present: - *

    - *
  • layout-land/
  • - *
- * - * Absent: - *
    - *
  • layout/
  • - *
- */ - @Nullable - public final CheckBox LSC; - - @NonNull - public final RadioButton TWILIGHT; - - @NonNull - public final RadioButton WARMFLUORESCENT; - - /** - * This binding is not available in all configurations. - *

- * Present: - *

    - *
  • layout-land/
  • - *
- * - * Absent: - *
    - *
  • layout/
  • - *
- */ - @Nullable - public final SeekBar brightness; - - @NonNull - public final ImageButton captureButton; - - /** - * This binding is not available in all configurations. - *

- * Present: - *

    - *
  • layout-land/
  • - *
- * - * Absent: - *
    - *
  • layout/
  • - *
- */ - @Nullable - public final SeekBar contrast; - - /** - * This binding is not available in all configurations. - *

- * Present: - *

    - *
  • layout-land/
  • - *
- * - * Absent: - *
    - *
  • layout/
  • - *
- */ - @Nullable - public final TextView currentBrightness; - - /** - * This binding is not available in all configurations. - *

- * Present: - *

    - *
  • layout-land/
  • - *
- * - * Absent: - *
    - *
  • layout/
  • - *
- */ - @Nullable - public final TextView currentContrast; - - @NonNull - public final TextView currentExposureTime; - - /** - * This binding is not available in all configurations. - *

- * Present: - *

    - *
  • layout-land/
  • - *
- * - * Absent: - *
    - *
  • layout/
  • - *
- */ - @Nullable - public final TextView currentGamma; - - /** - * This binding is not available in all configurations. - *

- * Present: - *

    - *
  • layout-land/
  • - *
- * - * Absent: - *
    - *
  • layout/
  • - *
- */ - @Nullable - public final TextView currentHue; - - /** - * This binding is not available in all configurations. - *

- * Present: - *

    - *
  • layout-land/
  • - *
- * - * Absent: - *
    - *
  • layout/
  • - *
- */ - @Nullable - public final TextView currentSaturation; - - /** - * This binding is not available in all configurations. - *

- * Present: - *

    - *
  • layout-land/
  • - *
- * - * Absent: - *
    - *
  • layout/
  • - *
- */ - @Nullable - public final TextView currentSharpLevel; - - @NonNull - public final Button dewarp; - - @NonNull - public final SeekBar exposureGain; - - @NonNull - public final SeekBar exposureTime; - - /** - * This binding is not available in all configurations. - *

- * Present: - *

    - *
  • layout-land/
  • - *
- * - * Absent: - *
    - *
  • layout/
  • - *
- */ - @Nullable - public final SeekBar gamma; - - @NonNull - public final Button hflip; - - /** - * This binding is not available in all configurations. - *

- * Present: - *

    - *
  • layout-land/
  • - *
- * - * Absent: - *
    - *
  • layout/
  • - *
- */ - @Nullable - public final SeekBar hue; - - @NonNull - public final View overlay; - - /** - * This binding is not available in all configurations. - *

- * Present: - *

    - *
  • layout-land/
  • - *
- * - * Absent: - *
    - *
  • layout/
  • - *
- */ - @Nullable - public final SeekBar saturation; - - /** - * This binding is not available in all configurations. - *

- * Present: - *

    - *
  • layout-land/
  • - *
- * - * Absent: - *
    - *
  • layout/
  • - *
- */ - @Nullable - public final SeekBar sharpLevel; - - /** - * This binding is not available in all configurations. - *

- * Present: - *

    - *
  • layout-land/
  • - *
- * - * Absent: - *
    - *
  • layout/
  • - *
- */ - @Nullable - public final TextView textBrightness; - - /** - * This binding is not available in all configurations. - *

- * Present: - *

    - *
  • layout-land/
  • - *
- * - * Absent: - *
    - *
  • layout/
  • - *
- */ - @Nullable - public final TextView textContrast; - - @NonNull - public final TextView textExposureGain; - - @NonNull - public final TextView textExposureTime; - - /** - * This binding is not available in all configurations. - *

- * Present: - *

    - *
  • layout-land/
  • - *
- * - * Absent: - *
    - *
  • layout/
  • - *
- */ - @Nullable - public final TextView textGamma; - - /** - * This binding is not available in all configurations. - *

- * Present: - *

    - *
  • layout-land/
  • - *
- * - * Absent: - *
    - *
  • layout/
  • - *
- */ - @Nullable - public final TextView textHue; - - /** - * This binding is not available in all configurations. - *

- * Present: - *

    - *
  • layout-land/
  • - *
- * - * Absent: - *
    - *
  • layout/
  • - *
- */ - @Nullable - public final TextView textSaturation; - - /** - * This binding is not available in all configurations. - *

- * Present: - *

    - *
  • layout-land/
  • - *
- * - * Absent: - *
    - *
  • layout/
  • - *
- */ - @Nullable - public final TextView textSharpLevel; - - @NonNull - public final Button vflip; - - @NonNull - public final AutoFitSurfaceView viewFinder; - - @NonNull - public final RadioGroup wb; - - private FragmentVideoBinding(@NonNull ConstraintLayout rootView, @NonNull RadioButton AWB, - @NonNull RadioButton CLOUDYDAYLIGHT, @NonNull RadioButton DAYLIGHT, - @NonNull RadioButton FLUORESCENT, @Nullable CheckBox HDR, @NonNull RadioButton INCANDESCENT, - @Nullable CheckBox LSC, @NonNull RadioButton TWILIGHT, @NonNull RadioButton WARMFLUORESCENT, - @Nullable SeekBar brightness, @NonNull ImageButton captureButton, @Nullable SeekBar contrast, - @Nullable TextView currentBrightness, @Nullable TextView currentContrast, - @NonNull TextView currentExposureTime, @Nullable TextView currentGamma, - @Nullable TextView currentHue, @Nullable TextView currentSaturation, - @Nullable TextView currentSharpLevel, @NonNull Button dewarp, @NonNull SeekBar exposureGain, - @NonNull SeekBar exposureTime, @Nullable SeekBar gamma, @NonNull Button hflip, - @Nullable SeekBar hue, @NonNull View overlay, @Nullable SeekBar saturation, - @Nullable SeekBar sharpLevel, @Nullable TextView textBrightness, - @Nullable TextView textContrast, @NonNull TextView textExposureGain, - @NonNull TextView textExposureTime, @Nullable TextView textGamma, @Nullable TextView textHue, - @Nullable TextView textSaturation, @Nullable TextView textSharpLevel, @NonNull Button vflip, - @NonNull AutoFitSurfaceView viewFinder, @NonNull RadioGroup wb) { - this.rootView = rootView; - this.AWB = AWB; - this.CLOUDYDAYLIGHT = CLOUDYDAYLIGHT; - this.DAYLIGHT = DAYLIGHT; - this.FLUORESCENT = FLUORESCENT; - this.HDR = HDR; - this.INCANDESCENT = INCANDESCENT; - this.LSC = LSC; - this.TWILIGHT = TWILIGHT; - this.WARMFLUORESCENT = WARMFLUORESCENT; - this.brightness = brightness; - this.captureButton = captureButton; - this.contrast = contrast; - this.currentBrightness = currentBrightness; - this.currentContrast = currentContrast; - this.currentExposureTime = currentExposureTime; - this.currentGamma = currentGamma; - this.currentHue = currentHue; - this.currentSaturation = currentSaturation; - this.currentSharpLevel = currentSharpLevel; - this.dewarp = dewarp; - this.exposureGain = exposureGain; - this.exposureTime = exposureTime; - this.gamma = gamma; - this.hflip = hflip; - this.hue = hue; - this.overlay = overlay; - this.saturation = saturation; - this.sharpLevel = sharpLevel; - this.textBrightness = textBrightness; - this.textContrast = textContrast; - this.textExposureGain = textExposureGain; - this.textExposureTime = textExposureTime; - this.textGamma = textGamma; - this.textHue = textHue; - this.textSaturation = textSaturation; - this.textSharpLevel = textSharpLevel; - this.vflip = vflip; - this.viewFinder = viewFinder; - this.wb = wb; - } - - @Override - @NonNull - public ConstraintLayout getRoot() { - return rootView; - } - - @NonNull - public static FragmentVideoBinding inflate(@NonNull LayoutInflater inflater) { - return inflate(inflater, null, false); - } - - @NonNull - public static FragmentVideoBinding inflate(@NonNull LayoutInflater inflater, - @Nullable ViewGroup parent, boolean attachToParent) { - View root = inflater.inflate(R.layout.fragment_camera, parent, false); - if (attachToParent) { - parent.addView(root); + @NonNull private final ConstraintLayout rootView; + + @NonNull public final RadioButton AWB; + + @NonNull public final RadioButton CLOUDYDAYLIGHT; + + @NonNull public final RadioButton DAYLIGHT; + + @NonNull public final RadioButton FLUORESCENT; + + /** + * This binding is not available in all configurations. + * + *

Present: + * + *

    + *
  • layout-land/ + *
+ * + * Absent: + * + *
    + *
  • layout/ + *
+ */ + @Nullable public final CheckBox HDR; + + @NonNull public final RadioButton INCANDESCENT; + + /** + * This binding is not available in all configurations. + * + *

Present: + * + *

    + *
  • layout-land/ + *
+ * + * Absent: + * + *
    + *
  • layout/ + *
+ */ + @Nullable public final CheckBox LSC; + + @NonNull public final RadioButton TWILIGHT; + + @NonNull public final RadioButton WARMFLUORESCENT; + + /** + * This binding is not available in all configurations. + * + *

Present: + * + *

    + *
  • layout-land/ + *
+ * + * Absent: + * + *
    + *
  • layout/ + *
+ */ + @Nullable public final SeekBar brightness; + + @NonNull public final ImageButton captureButton; + + /** + * This binding is not available in all configurations. + * + *

Present: + * + *

    + *
  • layout-land/ + *
+ * + * Absent: + * + *
    + *
  • layout/ + *
+ */ + @Nullable public final SeekBar contrast; + + /** + * This binding is not available in all configurations. + * + *

Present: + * + *

    + *
  • layout-land/ + *
+ * + * Absent: + * + *
    + *
  • layout/ + *
+ */ + @Nullable public final TextView currentBrightness; + + /** + * This binding is not available in all configurations. + * + *

Present: + * + *

    + *
  • layout-land/ + *
+ * + * Absent: + * + *
    + *
  • layout/ + *
+ */ + @Nullable public final TextView currentContrast; + + @NonNull public final TextView currentExposureTime; + + /** + * This binding is not available in all configurations. + * + *

Present: + * + *

    + *
  • layout-land/ + *
+ * + * Absent: + * + *
    + *
  • layout/ + *
+ */ + @Nullable public final TextView currentGamma; + + /** + * This binding is not available in all configurations. + * + *

Present: + * + *

    + *
  • layout-land/ + *
+ * + * Absent: + * + *
    + *
  • layout/ + *
+ */ + @Nullable public final TextView currentHue; + + /** + * This binding is not available in all configurations. + * + *

Present: + * + *

    + *
  • layout-land/ + *
+ * + * Absent: + * + *
    + *
  • layout/ + *
+ */ + @Nullable public final TextView currentSaturation; + + /** + * This binding is not available in all configurations. + * + *

Present: + * + *

    + *
  • layout-land/ + *
+ * + * Absent: + * + *
    + *
  • layout/ + *
+ */ + @Nullable public final TextView currentSharpLevel; + + @NonNull public final Button dewarp; + + @NonNull public final SeekBar exposureGain; + + @NonNull public final SeekBar exposureTime; + + /** + * This binding is not available in all configurations. + * + *

Present: + * + *

    + *
  • layout-land/ + *
+ * + * Absent: + * + *
    + *
  • layout/ + *
+ */ + @Nullable public final SeekBar gamma; + + @NonNull public final Button hflip; + + /** + * This binding is not available in all configurations. + * + *

Present: + * + *

    + *
  • layout-land/ + *
+ * + * Absent: + * + *
    + *
  • layout/ + *
+ */ + @Nullable public final SeekBar hue; + + @NonNull public final View overlay; + + /** + * This binding is not available in all configurations. + * + *

Present: + * + *

    + *
  • layout-land/ + *
+ * + * Absent: + * + *
    + *
  • layout/ + *
+ */ + @Nullable public final SeekBar saturation; + + /** + * This binding is not available in all configurations. + * + *

Present: + * + *

    + *
  • layout-land/ + *
+ * + * Absent: + * + *
    + *
  • layout/ + *
+ */ + @Nullable public final SeekBar sharpLevel; + + /** + * This binding is not available in all configurations. + * + *

Present: + * + *

    + *
  • layout-land/ + *
+ * + * Absent: + * + *
    + *
  • layout/ + *
+ */ + @Nullable public final TextView textBrightness; + + /** + * This binding is not available in all configurations. + * + *

Present: + * + *

    + *
  • layout-land/ + *
+ * + * Absent: + * + *
    + *
  • layout/ + *
+ */ + @Nullable public final TextView textContrast; + + @NonNull public final TextView textExposureGain; + + @NonNull public final TextView textExposureTime; + + /** + * This binding is not available in all configurations. + * + *

Present: + * + *

    + *
  • layout-land/ + *
+ * + * Absent: + * + *
    + *
  • layout/ + *
+ */ + @Nullable public final TextView textGamma; + + /** + * This binding is not available in all configurations. + * + *

Present: + * + *

    + *
  • layout-land/ + *
+ * + * Absent: + * + *
    + *
  • layout/ + *
+ */ + @Nullable public final TextView textHue; + + /** + * This binding is not available in all configurations. + * + *

Present: + * + *

    + *
  • layout-land/ + *
+ * + * Absent: + * + *
    + *
  • layout/ + *
+ */ + @Nullable public final TextView textSaturation; + + /** + * This binding is not available in all configurations. + * + *

Present: + * + *

    + *
  • layout-land/ + *
+ * + * Absent: + * + *
    + *
  • layout/ + *
+ */ + @Nullable public final TextView textSharpLevel; + + @NonNull public final Button vflip; + + @NonNull public final AutoFitSurfaceView viewFinder; + + @NonNull public final RadioGroup wb; + + private FragmentVideoBinding( + @NonNull ConstraintLayout rootView, + @NonNull RadioButton AWB, + @NonNull RadioButton CLOUDYDAYLIGHT, + @NonNull RadioButton DAYLIGHT, + @NonNull RadioButton FLUORESCENT, + @Nullable CheckBox HDR, + @NonNull RadioButton INCANDESCENT, + @Nullable CheckBox LSC, + @NonNull RadioButton TWILIGHT, + @NonNull RadioButton WARMFLUORESCENT, + @Nullable SeekBar brightness, + @NonNull ImageButton captureButton, + @Nullable SeekBar contrast, + @Nullable TextView currentBrightness, + @Nullable TextView currentContrast, + @NonNull TextView currentExposureTime, + @Nullable TextView currentGamma, + @Nullable TextView currentHue, + @Nullable TextView currentSaturation, + @Nullable TextView currentSharpLevel, + @NonNull Button dewarp, + @NonNull SeekBar exposureGain, + @NonNull SeekBar exposureTime, + @Nullable SeekBar gamma, + @NonNull Button hflip, + @Nullable SeekBar hue, + @NonNull View overlay, + @Nullable SeekBar saturation, + @Nullable SeekBar sharpLevel, + @Nullable TextView textBrightness, + @Nullable TextView textContrast, + @NonNull TextView textExposureGain, + @NonNull TextView textExposureTime, + @Nullable TextView textGamma, + @Nullable TextView textHue, + @Nullable TextView textSaturation, + @Nullable TextView textSharpLevel, + @NonNull Button vflip, + @NonNull AutoFitSurfaceView viewFinder, + @NonNull RadioGroup wb) { + this.rootView = rootView; + this.AWB = AWB; + this.CLOUDYDAYLIGHT = CLOUDYDAYLIGHT; + this.DAYLIGHT = DAYLIGHT; + this.FLUORESCENT = FLUORESCENT; + this.HDR = HDR; + this.INCANDESCENT = INCANDESCENT; + this.LSC = LSC; + this.TWILIGHT = TWILIGHT; + this.WARMFLUORESCENT = WARMFLUORESCENT; + this.brightness = brightness; + this.captureButton = captureButton; + this.contrast = contrast; + this.currentBrightness = currentBrightness; + this.currentContrast = currentContrast; + this.currentExposureTime = currentExposureTime; + this.currentGamma = currentGamma; + this.currentHue = currentHue; + this.currentSaturation = currentSaturation; + this.currentSharpLevel = currentSharpLevel; + this.dewarp = dewarp; + this.exposureGain = exposureGain; + this.exposureTime = exposureTime; + this.gamma = gamma; + this.hflip = hflip; + this.hue = hue; + this.overlay = overlay; + this.saturation = saturation; + this.sharpLevel = sharpLevel; + this.textBrightness = textBrightness; + this.textContrast = textContrast; + this.textExposureGain = textExposureGain; + this.textExposureTime = textExposureTime; + this.textGamma = textGamma; + this.textHue = textHue; + this.textSaturation = textSaturation; + this.textSharpLevel = textSharpLevel; + this.vflip = vflip; + this.viewFinder = viewFinder; + this.wb = wb; } - return bind(root); - } - - @NonNull - public static FragmentVideoBinding bind(@NonNull View rootView) { - // The body of this method is generated in a way you would not otherwise write. - // This is done to optimize the compiled bytecode for size and performance. - int id; - missingId: { - id = R.id.AWB; - RadioButton AWB = rootView.findViewById(id); - if (AWB == null) { - break missingId; - } - - id = R.id.CLOUDY_DAYLIGHT; - RadioButton CLOUDYDAYLIGHT = rootView.findViewById(id); - if (CLOUDYDAYLIGHT == null) { - break missingId; - } - - id = R.id.DAYLIGHT; - RadioButton DAYLIGHT = rootView.findViewById(id); - if (DAYLIGHT == null) { - break missingId; - } - - id = R.id.FLUORESCENT; - RadioButton FLUORESCENT = rootView.findViewById(id); - if (FLUORESCENT == null) { - break missingId; - } - - CheckBox HDR = rootView.findViewById(R.id.HDR); - - id = R.id.INCANDESCENT; - RadioButton INCANDESCENT = rootView.findViewById(id); - if (INCANDESCENT == null) { - break missingId; - } - - CheckBox LSC = rootView.findViewById(R.id.LSC); - - id = R.id.TWILIGHT; - RadioButton TWILIGHT = rootView.findViewById(id); - if (TWILIGHT == null) { - break missingId; - } - - id = R.id.WARM_FLUORESCENT; - RadioButton WARMFLUORESCENT = rootView.findViewById(id); - if (WARMFLUORESCENT == null) { - break missingId; - } - - SeekBar brightness = rootView.findViewById(R.id.brightness); - - id = R.id.capture_button; - ImageButton captureButton = rootView.findViewById(id); - if (captureButton == null) { - break missingId; - } - SeekBar contrast = rootView.findViewById(R.id.contrast); - - TextView currentBrightness = rootView.findViewById(R.id.current_brightness); - - TextView currentContrast = rootView.findViewById(R.id.current_contrast); - - id = R.id.current_exposure_time; - TextView currentExposureTime = rootView.findViewById(id); - if (currentExposureTime == null) { - break missingId; - } - - TextView currentGamma = rootView.findViewById(R.id.current_gamma); - - TextView currentHue = rootView.findViewById(R.id.current_hue); - - TextView currentSaturation = rootView.findViewById(R.id.current_saturation); - - TextView currentSharpLevel = rootView.findViewById(R.id.current_sharp_level); - - id = R.id.dewarp; - Button dewarp = rootView.findViewById(id); - if (dewarp == null) { - break missingId; - } - - id = R.id.exposure_gain; - SeekBar exposureGain = rootView.findViewById(id); - if (exposureGain == null) { - break missingId; - } - - id = R.id.exposure_time; - SeekBar exposureTime = rootView.findViewById(id); - if (exposureTime == null) { - break missingId; - } - - SeekBar gamma = rootView.findViewById(R.id.gamma); - - id = R.id.hflip; - Button hflip = rootView.findViewById(id); - if (hflip == null) { - break missingId; - } - - SeekBar hue = rootView.findViewById(R.id.hue); - - id = R.id.overlay; - View overlay = rootView.findViewById(id); - if (overlay == null) { - break missingId; - } - - SeekBar saturation = rootView.findViewById(R.id.saturation); - - SeekBar sharpLevel = rootView.findViewById(R.id.sharp_level); - - TextView textBrightness = rootView.findViewById(R.id.text_brightness); - - TextView textContrast = rootView.findViewById(R.id.text_contrast); + @Override + @NonNull + public ConstraintLayout getRoot() { + return rootView; + } - id = R.id.text_exposure_gain; - TextView textExposureGain = rootView.findViewById(id); - if (textExposureGain == null) { - break missingId; - } + @NonNull + public static FragmentVideoBinding inflate(@NonNull LayoutInflater inflater) { + return inflate(inflater, null, false); + } - id = R.id.text_exposure_time; - TextView textExposureTime = rootView.findViewById(id); - if (textExposureTime == null) { - break missingId; - } + @NonNull + public static FragmentVideoBinding inflate( + @NonNull LayoutInflater inflater, @Nullable ViewGroup parent, boolean attachToParent) { + View root = inflater.inflate(R.layout.fragment_camera, parent, false); + if (attachToParent) { + parent.addView(root); + } + return bind(root); + } - TextView textGamma = rootView.findViewById(R.id.text_gamma); + @NonNull + public static FragmentVideoBinding bind(@NonNull View rootView) { + // The body of this method is generated in a way you would not otherwise write. + // This is done to optimize the compiled bytecode for size and performance. + int id; + missingId: + { + id = R.id.AWB; + RadioButton AWB = rootView.findViewById(id); + if (AWB == null) { + break missingId; + } + + id = R.id.CLOUDY_DAYLIGHT; + RadioButton CLOUDYDAYLIGHT = rootView.findViewById(id); + if (CLOUDYDAYLIGHT == null) { + break missingId; + } + + id = R.id.DAYLIGHT; + RadioButton DAYLIGHT = rootView.findViewById(id); + if (DAYLIGHT == null) { + break missingId; + } - TextView textHue = rootView.findViewById(R.id.text_hue); + id = R.id.FLUORESCENT; + RadioButton FLUORESCENT = rootView.findViewById(id); + if (FLUORESCENT == null) { + break missingId; + } + + CheckBox HDR = rootView.findViewById(R.id.HDR); + + id = R.id.INCANDESCENT; + RadioButton INCANDESCENT = rootView.findViewById(id); + if (INCANDESCENT == null) { + break missingId; + } - TextView textSaturation = rootView.findViewById(R.id.text_saturation); + CheckBox LSC = rootView.findViewById(R.id.LSC); - TextView textSharpLevel = rootView.findViewById(R.id.text_sharp_level); + id = R.id.TWILIGHT; + RadioButton TWILIGHT = rootView.findViewById(id); + if (TWILIGHT == null) { + break missingId; + } - id = R.id.vflip; - Button vflip = rootView.findViewById(id); - if (vflip == null) { - break missingId; - } + id = R.id.WARM_FLUORESCENT; + RadioButton WARMFLUORESCENT = rootView.findViewById(id); + if (WARMFLUORESCENT == null) { + break missingId; + } - id = R.id.view_finder; - AutoFitSurfaceView viewFinder = rootView.findViewById(id); - if (viewFinder == null) { - break missingId; - } + SeekBar brightness = rootView.findViewById(R.id.brightness); - id = R.id.wb; - RadioGroup wb = rootView.findViewById(id); - if (wb == null) { - break missingId; - } + id = R.id.capture_button; + ImageButton captureButton = rootView.findViewById(id); + if (captureButton == null) { + break missingId; + } - return new FragmentVideoBinding((ConstraintLayout) rootView, AWB, CLOUDYDAYLIGHT, DAYLIGHT, - FLUORESCENT, HDR, INCANDESCENT, LSC, TWILIGHT, WARMFLUORESCENT, brightness, captureButton, - contrast, currentBrightness, currentContrast, currentExposureTime, currentGamma, - currentHue, currentSaturation, currentSharpLevel, dewarp, exposureGain, exposureTime, - gamma, hflip, hue, overlay, saturation, sharpLevel, textBrightness, textContrast, - textExposureGain, textExposureTime, textGamma, textHue, textSaturation, textSharpLevel, - vflip, viewFinder, wb); + SeekBar contrast = rootView.findViewById(R.id.contrast); + + TextView currentBrightness = rootView.findViewById(R.id.current_brightness); + + TextView currentContrast = rootView.findViewById(R.id.current_contrast); + + id = R.id.current_exposure_time; + TextView currentExposureTime = rootView.findViewById(id); + if (currentExposureTime == null) { + break missingId; + } + + TextView currentGamma = rootView.findViewById(R.id.current_gamma); + + TextView currentHue = rootView.findViewById(R.id.current_hue); + + TextView currentSaturation = rootView.findViewById(R.id.current_saturation); + + TextView currentSharpLevel = rootView.findViewById(R.id.current_sharp_level); + + id = R.id.dewarp; + Button dewarp = rootView.findViewById(id); + if (dewarp == null) { + break missingId; + } + + id = R.id.exposure_gain; + SeekBar exposureGain = rootView.findViewById(id); + if (exposureGain == null) { + break missingId; + } + + id = R.id.exposure_time; + SeekBar exposureTime = rootView.findViewById(id); + if (exposureTime == null) { + break missingId; + } + + SeekBar gamma = rootView.findViewById(R.id.gamma); + + id = R.id.hflip; + Button hflip = rootView.findViewById(id); + if (hflip == null) { + break missingId; + } + + SeekBar hue = rootView.findViewById(R.id.hue); + + id = R.id.overlay; + View overlay = rootView.findViewById(id); + if (overlay == null) { + break missingId; + } + + SeekBar saturation = rootView.findViewById(R.id.saturation); + + SeekBar sharpLevel = rootView.findViewById(R.id.sharp_level); + + TextView textBrightness = rootView.findViewById(R.id.text_brightness); + + TextView textContrast = rootView.findViewById(R.id.text_contrast); + + id = R.id.text_exposure_gain; + TextView textExposureGain = rootView.findViewById(id); + if (textExposureGain == null) { + break missingId; + } + + id = R.id.text_exposure_time; + TextView textExposureTime = rootView.findViewById(id); + if (textExposureTime == null) { + break missingId; + } + + TextView textGamma = rootView.findViewById(R.id.text_gamma); + + TextView textHue = rootView.findViewById(R.id.text_hue); + + TextView textSaturation = rootView.findViewById(R.id.text_saturation); + + TextView textSharpLevel = rootView.findViewById(R.id.text_sharp_level); + + id = R.id.vflip; + Button vflip = rootView.findViewById(id); + if (vflip == null) { + break missingId; + } + + id = R.id.view_finder; + AutoFitSurfaceView viewFinder = rootView.findViewById(id); + if (viewFinder == null) { + break missingId; + } + + id = R.id.wb; + RadioGroup wb = rootView.findViewById(id); + if (wb == null) { + break missingId; + } + + return new FragmentVideoBinding( + (ConstraintLayout) rootView, + AWB, + CLOUDYDAYLIGHT, + DAYLIGHT, + FLUORESCENT, + HDR, + INCANDESCENT, + LSC, + TWILIGHT, + WARMFLUORESCENT, + brightness, + captureButton, + contrast, + currentBrightness, + currentContrast, + currentExposureTime, + currentGamma, + currentHue, + currentSaturation, + currentSharpLevel, + dewarp, + exposureGain, + exposureTime, + gamma, + hflip, + hue, + overlay, + saturation, + sharpLevel, + textBrightness, + textContrast, + textExposureGain, + textExposureTime, + textGamma, + textHue, + textSaturation, + textSharpLevel, + vflip, + viewFinder, + wb); + } + String missingId = rootView.getResources().getResourceName(id); + throw new NullPointerException("Missing required view with ID: ".concat(missingId)); } - String missingId = rootView.getResources().getResourceName(id); - throw new NullPointerException("Missing required view with ID: ".concat(missingId)); - } } diff --git a/Camera2Basic/app/build/generated/source/buildConfig/debug/com/example/android/camera2/basic/BuildConfig.java b/Camera2Basic/app/build/generated/source/buildConfig/debug/com/example/android/camera2/basic/BuildConfig.java index 48da814..b578160 100644 --- a/Camera2Basic/app/build/generated/source/buildConfig/debug/com/example/android/camera2/basic/BuildConfig.java +++ b/Camera2Basic/app/build/generated/source/buildConfig/debug/com/example/android/camera2/basic/BuildConfig.java @@ -1,12 +1,10 @@ -/** - * Automatically generated file. DO NOT MODIFY - */ +/** Automatically generated file. DO NOT MODIFY */ package com.example.android.camera2.basic; public final class BuildConfig { - public static final boolean DEBUG = Boolean.parseBoolean("true"); - public static final String APPLICATION_ID = "com.android.example.camera2.basic"; - public static final String BUILD_TYPE = "debug"; - public static final int VERSION_CODE = 1; - public static final String VERSION_NAME = "1.0.0"; + public static final boolean DEBUG = Boolean.parseBoolean("true"); + public static final String APPLICATION_ID = "com.android.example.camera2.basic"; + public static final String BUILD_TYPE = "debug"; + public static final int VERSION_CODE = 1; + public static final String VERSION_NAME = "1.0.0"; } diff --git a/Camera2Basic/app/build/generated/source/navigation-args/debug/com/example/android/camera2/basic/fragments/CameraFragmentArgs.java b/Camera2Basic/app/build/generated/source/navigation-args/debug/com/example/android/camera2/basic/fragments/CameraFragmentArgs.java index 9e56a6f..9fe59e6 100644 --- a/Camera2Basic/app/build/generated/source/navigation-args/debug/com/example/android/camera2/basic/fragments/CameraFragmentArgs.java +++ b/Camera2Basic/app/build/generated/source/navigation-args/debug/com/example/android/camera2/basic/fragments/CameraFragmentArgs.java @@ -1,166 +1,176 @@ package com.example.android.camera2.basic.fragments; import android.os.Bundle; + import androidx.annotation.NonNull; import androidx.navigation.NavArgs; -import java.lang.IllegalArgumentException; -import java.lang.Object; -import java.lang.Override; -import java.lang.String; -import java.lang.SuppressWarnings; + import java.util.HashMap; public class CameraFragmentArgs implements NavArgs { - private final HashMap arguments = new HashMap(); - - private CameraFragmentArgs() { - } - - @SuppressWarnings("unchecked") - private CameraFragmentArgs(HashMap argumentsMap) { - this.arguments.putAll(argumentsMap); - } - - @NonNull - @SuppressWarnings("unchecked") - public static CameraFragmentArgs fromBundle(@NonNull Bundle bundle) { - CameraFragmentArgs __result = new CameraFragmentArgs(); - bundle.setClassLoader(CameraFragmentArgs.class.getClassLoader()); - if (bundle.containsKey("camera_id")) { - String cameraId; - cameraId = bundle.getString("camera_id"); - if (cameraId == null) { - throw new IllegalArgumentException("Argument \"camera_id\" is marked as non-null but was passed a null value."); - } - __result.arguments.put("camera_id", cameraId); - } else { - throw new IllegalArgumentException("Required argument \"camera_id\" is missing and does not have an android:defaultValue"); - } - if (bundle.containsKey("pixel_format")) { - int pixelFormat; - pixelFormat = bundle.getInt("pixel_format"); - __result.arguments.put("pixel_format", pixelFormat); - } else { - throw new IllegalArgumentException("Required argument \"pixel_format\" is missing and does not have an android:defaultValue"); - } - return __result; - } - - @SuppressWarnings("unchecked") - @NonNull - public String getCameraId() { - return (String) arguments.get("camera_id"); - } - - @SuppressWarnings("unchecked") - public int getPixelFormat() { - return (int) arguments.get("pixel_format"); - } - - @SuppressWarnings("unchecked") - @NonNull - public Bundle toBundle() { - Bundle __result = new Bundle(); - if (arguments.containsKey("camera_id")) { - String cameraId = (String) arguments.get("camera_id"); - __result.putString("camera_id", cameraId); - } - if (arguments.containsKey("pixel_format")) { - int pixelFormat = (int) arguments.get("pixel_format"); - __result.putInt("pixel_format", pixelFormat); - } - return __result; - } - - @Override - public boolean equals(Object object) { - if (this == object) { - return true; - } - if (object == null || getClass() != object.getClass()) { - return false; - } - CameraFragmentArgs that = (CameraFragmentArgs) object; - if (arguments.containsKey("camera_id") != that.arguments.containsKey("camera_id")) { - return false; - } - if (getCameraId() != null ? !getCameraId().equals(that.getCameraId()) : that.getCameraId() != null) { - return false; - } - if (arguments.containsKey("pixel_format") != that.arguments.containsKey("pixel_format")) { - return false; - } - if (getPixelFormat() != that.getPixelFormat()) { - return false; - } - return true; - } - - @Override - public int hashCode() { - int result = 1; - result = 31 * result + (getCameraId() != null ? getCameraId().hashCode() : 0); - result = 31 * result + getPixelFormat(); - return result; - } - - @Override - public String toString() { - return "CameraFragmentArgs{" - + "cameraId=" + getCameraId() - + ", pixelFormat=" + getPixelFormat() - + "}"; - } - - public static class Builder { private final HashMap arguments = new HashMap(); - @SuppressWarnings("unchecked") - public Builder(CameraFragmentArgs original) { - this.arguments.putAll(original.arguments); - } + private CameraFragmentArgs() {} @SuppressWarnings("unchecked") - public Builder(@NonNull String cameraId, int pixelFormat) { - if (cameraId == null) { - throw new IllegalArgumentException("Argument \"camera_id\" is marked as non-null but was passed a null value."); - } - this.arguments.put("camera_id", cameraId); - this.arguments.put("pixel_format", pixelFormat); + private CameraFragmentArgs(HashMap argumentsMap) { + this.arguments.putAll(argumentsMap); } @NonNull - public CameraFragmentArgs build() { - CameraFragmentArgs result = new CameraFragmentArgs(arguments); - return result; + @SuppressWarnings("unchecked") + public static CameraFragmentArgs fromBundle(@NonNull Bundle bundle) { + CameraFragmentArgs __result = new CameraFragmentArgs(); + bundle.setClassLoader(CameraFragmentArgs.class.getClassLoader()); + if (bundle.containsKey("camera_id")) { + String cameraId; + cameraId = bundle.getString("camera_id"); + if (cameraId == null) { + throw new IllegalArgumentException( + "Argument \"camera_id\" is marked as non-null but was passed a null" + + " value."); + } + __result.arguments.put("camera_id", cameraId); + } else { + throw new IllegalArgumentException( + "Required argument \"camera_id\" is missing and does not have an" + + " android:defaultValue"); + } + if (bundle.containsKey("pixel_format")) { + int pixelFormat; + pixelFormat = bundle.getInt("pixel_format"); + __result.arguments.put("pixel_format", pixelFormat); + } else { + throw new IllegalArgumentException( + "Required argument \"pixel_format\" is missing and does not have an" + + " android:defaultValue"); + } + return __result; } - @NonNull @SuppressWarnings("unchecked") - public Builder setCameraId(@NonNull String cameraId) { - if (cameraId == null) { - throw new IllegalArgumentException("Argument \"camera_id\" is marked as non-null but was passed a null value."); - } - this.arguments.put("camera_id", cameraId); - return this; + @NonNull + public String getCameraId() { + return (String) arguments.get("camera_id"); } - @NonNull @SuppressWarnings("unchecked") - public Builder setPixelFormat(int pixelFormat) { - this.arguments.put("pixel_format", pixelFormat); - return this; + public int getPixelFormat() { + return (int) arguments.get("pixel_format"); } @SuppressWarnings("unchecked") @NonNull - public String getCameraId() { - return (String) arguments.get("camera_id"); + public Bundle toBundle() { + Bundle __result = new Bundle(); + if (arguments.containsKey("camera_id")) { + String cameraId = (String) arguments.get("camera_id"); + __result.putString("camera_id", cameraId); + } + if (arguments.containsKey("pixel_format")) { + int pixelFormat = (int) arguments.get("pixel_format"); + __result.putInt("pixel_format", pixelFormat); + } + return __result; + } + + @Override + public boolean equals(Object object) { + if (this == object) { + return true; + } + if (object == null || getClass() != object.getClass()) { + return false; + } + CameraFragmentArgs that = (CameraFragmentArgs) object; + if (arguments.containsKey("camera_id") != that.arguments.containsKey("camera_id")) { + return false; + } + if (getCameraId() != null + ? !getCameraId().equals(that.getCameraId()) + : that.getCameraId() != null) { + return false; + } + if (arguments.containsKey("pixel_format") != that.arguments.containsKey("pixel_format")) { + return false; + } + if (getPixelFormat() != that.getPixelFormat()) { + return false; + } + return true; } - @SuppressWarnings("unchecked") - public int getPixelFormat() { - return (int) arguments.get("pixel_format"); + @Override + public int hashCode() { + int result = 1; + result = 31 * result + (getCameraId() != null ? getCameraId().hashCode() : 0); + result = 31 * result + getPixelFormat(); + return result; + } + + @Override + public String toString() { + return "CameraFragmentArgs{" + + "cameraId=" + + getCameraId() + + ", pixelFormat=" + + getPixelFormat() + + "}"; + } + + public static class Builder { + private final HashMap arguments = new HashMap(); + + @SuppressWarnings("unchecked") + public Builder(CameraFragmentArgs original) { + this.arguments.putAll(original.arguments); + } + + @SuppressWarnings("unchecked") + public Builder(@NonNull String cameraId, int pixelFormat) { + if (cameraId == null) { + throw new IllegalArgumentException( + "Argument \"camera_id\" is marked as non-null but was passed a null" + + " value."); + } + this.arguments.put("camera_id", cameraId); + this.arguments.put("pixel_format", pixelFormat); + } + + @NonNull + public CameraFragmentArgs build() { + CameraFragmentArgs result = new CameraFragmentArgs(arguments); + return result; + } + + @NonNull + @SuppressWarnings("unchecked") + public Builder setCameraId(@NonNull String cameraId) { + if (cameraId == null) { + throw new IllegalArgumentException( + "Argument \"camera_id\" is marked as non-null but was passed a null" + + " value."); + } + this.arguments.put("camera_id", cameraId); + return this; + } + + @NonNull + @SuppressWarnings("unchecked") + public Builder setPixelFormat(int pixelFormat) { + this.arguments.put("pixel_format", pixelFormat); + return this; + } + + @SuppressWarnings("unchecked") + @NonNull + public String getCameraId() { + return (String) arguments.get("camera_id"); + } + + @SuppressWarnings("unchecked") + public int getPixelFormat() { + return (int) arguments.get("pixel_format"); + } } - } } diff --git a/Camera2Basic/app/build/generated/source/navigation-args/debug/com/example/android/camera2/basic/fragments/CameraFragmentDirections.java b/Camera2Basic/app/build/generated/source/navigation-args/debug/com/example/android/camera2/basic/fragments/CameraFragmentDirections.java index 7f33ce1..fcdbc45 100644 --- a/Camera2Basic/app/build/generated/source/navigation-args/debug/com/example/android/camera2/basic/fragments/CameraFragmentDirections.java +++ b/Camera2Basic/app/build/generated/source/navigation-args/debug/com/example/android/camera2/basic/fragments/CameraFragmentDirections.java @@ -1,161 +1,169 @@ package com.example.android.camera2.basic.fragments; import android.os.Bundle; + import androidx.annotation.NonNull; import androidx.navigation.ActionOnlyNavDirections; import androidx.navigation.NavDirections; + import com.example.android.camera2.basic.R; -import java.lang.IllegalArgumentException; -import java.lang.Object; -import java.lang.Override; -import java.lang.String; -import java.lang.SuppressWarnings; + import java.util.HashMap; public class CameraFragmentDirections { - private CameraFragmentDirections() { - } - - @NonNull - public static NavDirections actionCameraToPermissions() { - return new ActionOnlyNavDirections(R.id.action_camera_to_permissions); - } - - @NonNull - public static ActionCameraToJpegViewer actionCameraToJpegViewer(@NonNull String filePath) { - return new ActionCameraToJpegViewer(filePath); - } - - public static class ActionCameraToJpegViewer implements NavDirections { - private final HashMap arguments = new HashMap(); - - @SuppressWarnings("unchecked") - private ActionCameraToJpegViewer(@NonNull String filePath) { - if (filePath == null) { - throw new IllegalArgumentException("Argument \"file_path\" is marked as non-null but was passed a null value."); - } - this.arguments.put("file_path", filePath); - } - - @NonNull - @SuppressWarnings("unchecked") - public ActionCameraToJpegViewer setFilePath(@NonNull String filePath) { - if (filePath == null) { - throw new IllegalArgumentException("Argument \"file_path\" is marked as non-null but was passed a null value."); - } - this.arguments.put("file_path", filePath); - return this; - } - - @NonNull - @SuppressWarnings("unchecked") - public ActionCameraToJpegViewer setOrientation(int orientation) { - this.arguments.put("orientation", orientation); - return this; - } + private CameraFragmentDirections() {} @NonNull - @SuppressWarnings("unchecked") - public ActionCameraToJpegViewer setDepth(boolean depth) { - this.arguments.put("depth", depth); - return this; + public static NavDirections actionCameraToPermissions() { + return new ActionOnlyNavDirections(R.id.action_camera_to_permissions); } - @Override - @SuppressWarnings("unchecked") @NonNull - public Bundle getArguments() { - Bundle __result = new Bundle(); - if (arguments.containsKey("file_path")) { - String filePath = (String) arguments.get("file_path"); - __result.putString("file_path", filePath); - } - if (arguments.containsKey("orientation")) { - int orientation = (int) arguments.get("orientation"); - __result.putInt("orientation", orientation); - } else { - __result.putInt("orientation", 0); - } - if (arguments.containsKey("depth")) { - boolean depth = (boolean) arguments.get("depth"); - __result.putBoolean("depth", depth); - } else { - __result.putBoolean("depth", false); - } - return __result; - } - - @Override - public int getActionId() { - return R.id.action_camera_to_jpeg_viewer; - } - - @SuppressWarnings("unchecked") - @NonNull - public String getFilePath() { - return (String) arguments.get("file_path"); - } - - @SuppressWarnings("unchecked") - public int getOrientation() { - return (int) arguments.get("orientation"); - } - - @SuppressWarnings("unchecked") - public boolean getDepth() { - return (boolean) arguments.get("depth"); - } - - @Override - public boolean equals(Object object) { - if (this == object) { - return true; - } - if (object == null || getClass() != object.getClass()) { - return false; - } - ActionCameraToJpegViewer that = (ActionCameraToJpegViewer) object; - if (arguments.containsKey("file_path") != that.arguments.containsKey("file_path")) { - return false; - } - if (getFilePath() != null ? !getFilePath().equals(that.getFilePath()) : that.getFilePath() != null) { - return false; - } - if (arguments.containsKey("orientation") != that.arguments.containsKey("orientation")) { - return false; - } - if (getOrientation() != that.getOrientation()) { - return false; - } - if (arguments.containsKey("depth") != that.arguments.containsKey("depth")) { - return false; - } - if (getDepth() != that.getDepth()) { - return false; - } - if (getActionId() != that.getActionId()) { - return false; - } - return true; - } - - @Override - public int hashCode() { - int result = 1; - result = 31 * result + (getFilePath() != null ? getFilePath().hashCode() : 0); - result = 31 * result + getOrientation(); - result = 31 * result + (getDepth() ? 1 : 0); - result = 31 * result + getActionId(); - return result; + public static ActionCameraToJpegViewer actionCameraToJpegViewer(@NonNull String filePath) { + return new ActionCameraToJpegViewer(filePath); } - @Override - public String toString() { - return "ActionCameraToJpegViewer(actionId=" + getActionId() + "){" - + "filePath=" + getFilePath() - + ", orientation=" + getOrientation() - + ", depth=" + getDepth() - + "}"; + public static class ActionCameraToJpegViewer implements NavDirections { + private final HashMap arguments = new HashMap(); + + @SuppressWarnings("unchecked") + private ActionCameraToJpegViewer(@NonNull String filePath) { + if (filePath == null) { + throw new IllegalArgumentException( + "Argument \"file_path\" is marked as non-null but was passed a null" + + " value."); + } + this.arguments.put("file_path", filePath); + } + + @NonNull + @SuppressWarnings("unchecked") + public ActionCameraToJpegViewer setFilePath(@NonNull String filePath) { + if (filePath == null) { + throw new IllegalArgumentException( + "Argument \"file_path\" is marked as non-null but was passed a null" + + " value."); + } + this.arguments.put("file_path", filePath); + return this; + } + + @NonNull + @SuppressWarnings("unchecked") + public ActionCameraToJpegViewer setOrientation(int orientation) { + this.arguments.put("orientation", orientation); + return this; + } + + @NonNull + @SuppressWarnings("unchecked") + public ActionCameraToJpegViewer setDepth(boolean depth) { + this.arguments.put("depth", depth); + return this; + } + + @Override + @SuppressWarnings("unchecked") + @NonNull + public Bundle getArguments() { + Bundle __result = new Bundle(); + if (arguments.containsKey("file_path")) { + String filePath = (String) arguments.get("file_path"); + __result.putString("file_path", filePath); + } + if (arguments.containsKey("orientation")) { + int orientation = (int) arguments.get("orientation"); + __result.putInt("orientation", orientation); + } else { + __result.putInt("orientation", 0); + } + if (arguments.containsKey("depth")) { + boolean depth = (boolean) arguments.get("depth"); + __result.putBoolean("depth", depth); + } else { + __result.putBoolean("depth", false); + } + return __result; + } + + @Override + public int getActionId() { + return R.id.action_camera_to_jpeg_viewer; + } + + @SuppressWarnings("unchecked") + @NonNull + public String getFilePath() { + return (String) arguments.get("file_path"); + } + + @SuppressWarnings("unchecked") + public int getOrientation() { + return (int) arguments.get("orientation"); + } + + @SuppressWarnings("unchecked") + public boolean getDepth() { + return (boolean) arguments.get("depth"); + } + + @Override + public boolean equals(Object object) { + if (this == object) { + return true; + } + if (object == null || getClass() != object.getClass()) { + return false; + } + ActionCameraToJpegViewer that = (ActionCameraToJpegViewer) object; + if (arguments.containsKey("file_path") != that.arguments.containsKey("file_path")) { + return false; + } + if (getFilePath() != null + ? !getFilePath().equals(that.getFilePath()) + : that.getFilePath() != null) { + return false; + } + if (arguments.containsKey("orientation") != that.arguments.containsKey("orientation")) { + return false; + } + if (getOrientation() != that.getOrientation()) { + return false; + } + if (arguments.containsKey("depth") != that.arguments.containsKey("depth")) { + return false; + } + if (getDepth() != that.getDepth()) { + return false; + } + if (getActionId() != that.getActionId()) { + return false; + } + return true; + } + + @Override + public int hashCode() { + int result = 1; + result = 31 * result + (getFilePath() != null ? getFilePath().hashCode() : 0); + result = 31 * result + getOrientation(); + result = 31 * result + (getDepth() ? 1 : 0); + result = 31 * result + getActionId(); + return result; + } + + @Override + public String toString() { + return "ActionCameraToJpegViewer(actionId=" + + getActionId() + + "){" + + "filePath=" + + getFilePath() + + ", orientation=" + + getOrientation() + + ", depth=" + + getDepth() + + "}"; + } } - } } diff --git a/Camera2Basic/app/build/generated/source/navigation-args/debug/com/example/android/camera2/basic/fragments/ImageViewerFragmentArgs.java b/Camera2Basic/app/build/generated/source/navigation-args/debug/com/example/android/camera2/basic/fragments/ImageViewerFragmentArgs.java index f9b2330..96d8856 100644 --- a/Camera2Basic/app/build/generated/source/navigation-args/debug/com/example/android/camera2/basic/fragments/ImageViewerFragmentArgs.java +++ b/Camera2Basic/app/build/generated/source/navigation-args/debug/com/example/android/camera2/basic/fragments/ImageViewerFragmentArgs.java @@ -1,205 +1,214 @@ package com.example.android.camera2.basic.fragments; import android.os.Bundle; + import androidx.annotation.NonNull; import androidx.navigation.NavArgs; -import java.lang.IllegalArgumentException; -import java.lang.Object; -import java.lang.Override; -import java.lang.String; -import java.lang.SuppressWarnings; + import java.util.HashMap; public class ImageViewerFragmentArgs implements NavArgs { - private final HashMap arguments = new HashMap(); - - private ImageViewerFragmentArgs() { - } - - @SuppressWarnings("unchecked") - private ImageViewerFragmentArgs(HashMap argumentsMap) { - this.arguments.putAll(argumentsMap); - } - - @NonNull - @SuppressWarnings("unchecked") - public static ImageViewerFragmentArgs fromBundle(@NonNull Bundle bundle) { - ImageViewerFragmentArgs __result = new ImageViewerFragmentArgs(); - bundle.setClassLoader(ImageViewerFragmentArgs.class.getClassLoader()); - if (bundle.containsKey("file_path")) { - String filePath; - filePath = bundle.getString("file_path"); - if (filePath == null) { - throw new IllegalArgumentException("Argument \"file_path\" is marked as non-null but was passed a null value."); - } - __result.arguments.put("file_path", filePath); - } else { - throw new IllegalArgumentException("Required argument \"file_path\" is missing and does not have an android:defaultValue"); - } - if (bundle.containsKey("orientation")) { - int orientation; - orientation = bundle.getInt("orientation"); - __result.arguments.put("orientation", orientation); - } else { - __result.arguments.put("orientation", 0); - } - if (bundle.containsKey("depth")) { - boolean depth; - depth = bundle.getBoolean("depth"); - __result.arguments.put("depth", depth); - } else { - __result.arguments.put("depth", false); - } - return __result; - } - - @SuppressWarnings("unchecked") - @NonNull - public String getFilePath() { - return (String) arguments.get("file_path"); - } - - @SuppressWarnings("unchecked") - public int getOrientation() { - return (int) arguments.get("orientation"); - } - - @SuppressWarnings("unchecked") - public boolean getDepth() { - return (boolean) arguments.get("depth"); - } - - @SuppressWarnings("unchecked") - @NonNull - public Bundle toBundle() { - Bundle __result = new Bundle(); - if (arguments.containsKey("file_path")) { - String filePath = (String) arguments.get("file_path"); - __result.putString("file_path", filePath); - } - if (arguments.containsKey("orientation")) { - int orientation = (int) arguments.get("orientation"); - __result.putInt("orientation", orientation); - } else { - __result.putInt("orientation", 0); - } - if (arguments.containsKey("depth")) { - boolean depth = (boolean) arguments.get("depth"); - __result.putBoolean("depth", depth); - } else { - __result.putBoolean("depth", false); - } - return __result; - } - - @Override - public boolean equals(Object object) { - if (this == object) { - return true; - } - if (object == null || getClass() != object.getClass()) { - return false; - } - ImageViewerFragmentArgs that = (ImageViewerFragmentArgs) object; - if (arguments.containsKey("file_path") != that.arguments.containsKey("file_path")) { - return false; - } - if (getFilePath() != null ? !getFilePath().equals(that.getFilePath()) : that.getFilePath() != null) { - return false; - } - if (arguments.containsKey("orientation") != that.arguments.containsKey("orientation")) { - return false; - } - if (getOrientation() != that.getOrientation()) { - return false; - } - if (arguments.containsKey("depth") != that.arguments.containsKey("depth")) { - return false; - } - if (getDepth() != that.getDepth()) { - return false; - } - return true; - } - - @Override - public int hashCode() { - int result = 1; - result = 31 * result + (getFilePath() != null ? getFilePath().hashCode() : 0); - result = 31 * result + getOrientation(); - result = 31 * result + (getDepth() ? 1 : 0); - return result; - } - - @Override - public String toString() { - return "ImageViewerFragmentArgs{" - + "filePath=" + getFilePath() - + ", orientation=" + getOrientation() - + ", depth=" + getDepth() - + "}"; - } - - public static class Builder { private final HashMap arguments = new HashMap(); - @SuppressWarnings("unchecked") - public Builder(ImageViewerFragmentArgs original) { - this.arguments.putAll(original.arguments); - } + private ImageViewerFragmentArgs() {} @SuppressWarnings("unchecked") - public Builder(@NonNull String filePath) { - if (filePath == null) { - throw new IllegalArgumentException("Argument \"file_path\" is marked as non-null but was passed a null value."); - } - this.arguments.put("file_path", filePath); - } - - @NonNull - public ImageViewerFragmentArgs build() { - ImageViewerFragmentArgs result = new ImageViewerFragmentArgs(arguments); - return result; + private ImageViewerFragmentArgs(HashMap argumentsMap) { + this.arguments.putAll(argumentsMap); } @NonNull @SuppressWarnings("unchecked") - public Builder setFilePath(@NonNull String filePath) { - if (filePath == null) { - throw new IllegalArgumentException("Argument \"file_path\" is marked as non-null but was passed a null value."); - } - this.arguments.put("file_path", filePath); - return this; + public static ImageViewerFragmentArgs fromBundle(@NonNull Bundle bundle) { + ImageViewerFragmentArgs __result = new ImageViewerFragmentArgs(); + bundle.setClassLoader(ImageViewerFragmentArgs.class.getClassLoader()); + if (bundle.containsKey("file_path")) { + String filePath; + filePath = bundle.getString("file_path"); + if (filePath == null) { + throw new IllegalArgumentException( + "Argument \"file_path\" is marked as non-null but was passed a null" + + " value."); + } + __result.arguments.put("file_path", filePath); + } else { + throw new IllegalArgumentException( + "Required argument \"file_path\" is missing and does not have an" + + " android:defaultValue"); + } + if (bundle.containsKey("orientation")) { + int orientation; + orientation = bundle.getInt("orientation"); + __result.arguments.put("orientation", orientation); + } else { + __result.arguments.put("orientation", 0); + } + if (bundle.containsKey("depth")) { + boolean depth; + depth = bundle.getBoolean("depth"); + __result.arguments.put("depth", depth); + } else { + __result.arguments.put("depth", false); + } + return __result; } - @NonNull @SuppressWarnings("unchecked") - public Builder setOrientation(int orientation) { - this.arguments.put("orientation", orientation); - return this; + @NonNull + public String getFilePath() { + return (String) arguments.get("file_path"); } - @NonNull @SuppressWarnings("unchecked") - public Builder setDepth(boolean depth) { - this.arguments.put("depth", depth); - return this; + public int getOrientation() { + return (int) arguments.get("orientation"); } @SuppressWarnings("unchecked") - @NonNull - public String getFilePath() { - return (String) arguments.get("file_path"); + public boolean getDepth() { + return (boolean) arguments.get("depth"); } @SuppressWarnings("unchecked") - public int getOrientation() { - return (int) arguments.get("orientation"); + @NonNull + public Bundle toBundle() { + Bundle __result = new Bundle(); + if (arguments.containsKey("file_path")) { + String filePath = (String) arguments.get("file_path"); + __result.putString("file_path", filePath); + } + if (arguments.containsKey("orientation")) { + int orientation = (int) arguments.get("orientation"); + __result.putInt("orientation", orientation); + } else { + __result.putInt("orientation", 0); + } + if (arguments.containsKey("depth")) { + boolean depth = (boolean) arguments.get("depth"); + __result.putBoolean("depth", depth); + } else { + __result.putBoolean("depth", false); + } + return __result; + } + + @Override + public boolean equals(Object object) { + if (this == object) { + return true; + } + if (object == null || getClass() != object.getClass()) { + return false; + } + ImageViewerFragmentArgs that = (ImageViewerFragmentArgs) object; + if (arguments.containsKey("file_path") != that.arguments.containsKey("file_path")) { + return false; + } + if (getFilePath() != null + ? !getFilePath().equals(that.getFilePath()) + : that.getFilePath() != null) { + return false; + } + if (arguments.containsKey("orientation") != that.arguments.containsKey("orientation")) { + return false; + } + if (getOrientation() != that.getOrientation()) { + return false; + } + if (arguments.containsKey("depth") != that.arguments.containsKey("depth")) { + return false; + } + if (getDepth() != that.getDepth()) { + return false; + } + return true; } - @SuppressWarnings("unchecked") - public boolean getDepth() { - return (boolean) arguments.get("depth"); + @Override + public int hashCode() { + int result = 1; + result = 31 * result + (getFilePath() != null ? getFilePath().hashCode() : 0); + result = 31 * result + getOrientation(); + result = 31 * result + (getDepth() ? 1 : 0); + return result; + } + + @Override + public String toString() { + return "ImageViewerFragmentArgs{" + + "filePath=" + + getFilePath() + + ", orientation=" + + getOrientation() + + ", depth=" + + getDepth() + + "}"; + } + + public static class Builder { + private final HashMap arguments = new HashMap(); + + @SuppressWarnings("unchecked") + public Builder(ImageViewerFragmentArgs original) { + this.arguments.putAll(original.arguments); + } + + @SuppressWarnings("unchecked") + public Builder(@NonNull String filePath) { + if (filePath == null) { + throw new IllegalArgumentException( + "Argument \"file_path\" is marked as non-null but was passed a null" + + " value."); + } + this.arguments.put("file_path", filePath); + } + + @NonNull + public ImageViewerFragmentArgs build() { + ImageViewerFragmentArgs result = new ImageViewerFragmentArgs(arguments); + return result; + } + + @NonNull + @SuppressWarnings("unchecked") + public Builder setFilePath(@NonNull String filePath) { + if (filePath == null) { + throw new IllegalArgumentException( + "Argument \"file_path\" is marked as non-null but was passed a null" + + " value."); + } + this.arguments.put("file_path", filePath); + return this; + } + + @NonNull + @SuppressWarnings("unchecked") + public Builder setOrientation(int orientation) { + this.arguments.put("orientation", orientation); + return this; + } + + @NonNull + @SuppressWarnings("unchecked") + public Builder setDepth(boolean depth) { + this.arguments.put("depth", depth); + return this; + } + + @SuppressWarnings("unchecked") + @NonNull + public String getFilePath() { + return (String) arguments.get("file_path"); + } + + @SuppressWarnings("unchecked") + public int getOrientation() { + return (int) arguments.get("orientation"); + } + + @SuppressWarnings("unchecked") + public boolean getDepth() { + return (boolean) arguments.get("depth"); + } } - } } diff --git a/Camera2Basic/app/build/generated/source/navigation-args/debug/com/example/android/camera2/basic/fragments/PermissionsFragmentDirections.java b/Camera2Basic/app/build/generated/source/navigation-args/debug/com/example/android/camera2/basic/fragments/PermissionsFragmentDirections.java index 3f758a8..73d8cd9 100644 --- a/Camera2Basic/app/build/generated/source/navigation-args/debug/com/example/android/camera2/basic/fragments/PermissionsFragmentDirections.java +++ b/Camera2Basic/app/build/generated/source/navigation-args/debug/com/example/android/camera2/basic/fragments/PermissionsFragmentDirections.java @@ -3,14 +3,14 @@ import androidx.annotation.NonNull; import androidx.navigation.ActionOnlyNavDirections; import androidx.navigation.NavDirections; + import com.example.android.camera2.basic.R; public class PermissionsFragmentDirections { - private PermissionsFragmentDirections() { - } + private PermissionsFragmentDirections() {} - @NonNull - public static NavDirections actionPermissionsToSelector() { - return new ActionOnlyNavDirections(R.id.action_permissions_to_selector); - } + @NonNull + public static NavDirections actionPermissionsToSelector() { + return new ActionOnlyNavDirections(R.id.action_permissions_to_selector); + } } diff --git a/Camera2Basic/app/build/generated/source/navigation-args/debug/com/example/android/camera2/basic/fragments/SelectorFragmentDirections.java b/Camera2Basic/app/build/generated/source/navigation-args/debug/com/example/android/camera2/basic/fragments/SelectorFragmentDirections.java index ff83b04..4f1e948 100644 --- a/Camera2Basic/app/build/generated/source/navigation-args/debug/com/example/android/camera2/basic/fragments/SelectorFragmentDirections.java +++ b/Camera2Basic/app/build/generated/source/navigation-args/debug/com/example/android/camera2/basic/fragments/SelectorFragmentDirections.java @@ -1,135 +1,143 @@ package com.example.android.camera2.basic.fragments; import android.os.Bundle; + import androidx.annotation.NonNull; import androidx.navigation.ActionOnlyNavDirections; import androidx.navigation.NavDirections; + import com.example.android.camera2.basic.R; -import java.lang.IllegalArgumentException; -import java.lang.Object; -import java.lang.Override; -import java.lang.String; -import java.lang.SuppressWarnings; + import java.util.HashMap; public class SelectorFragmentDirections { - private SelectorFragmentDirections() { - } - - @NonNull - public static ActionSelectorToCamera actionSelectorToCamera(@NonNull String cameraId, - int pixelFormat) { - return new ActionSelectorToCamera(cameraId, pixelFormat); - } - - @NonNull - public static NavDirections actionCameraToVideo() { - return new ActionOnlyNavDirections(R.id.action_camera_to_video); - } - - public static class ActionSelectorToCamera implements NavDirections { - private final HashMap arguments = new HashMap(); - - @SuppressWarnings("unchecked") - private ActionSelectorToCamera(@NonNull String cameraId, int pixelFormat) { - if (cameraId == null) { - throw new IllegalArgumentException("Argument \"camera_id\" is marked as non-null but was passed a null value."); - } - this.arguments.put("camera_id", cameraId); - this.arguments.put("pixel_format", pixelFormat); - } + private SelectorFragmentDirections() {} @NonNull - @SuppressWarnings("unchecked") - public ActionSelectorToCamera setCameraId(@NonNull String cameraId) { - if (cameraId == null) { - throw new IllegalArgumentException("Argument \"camera_id\" is marked as non-null but was passed a null value."); - } - this.arguments.put("camera_id", cameraId); - return this; + public static ActionSelectorToCamera actionSelectorToCamera( + @NonNull String cameraId, int pixelFormat) { + return new ActionSelectorToCamera(cameraId, pixelFormat); } @NonNull - @SuppressWarnings("unchecked") - public ActionSelectorToCamera setPixelFormat(int pixelFormat) { - this.arguments.put("pixel_format", pixelFormat); - return this; + public static NavDirections actionCameraToVideo() { + return new ActionOnlyNavDirections(R.id.action_camera_to_video); } - @Override - @SuppressWarnings("unchecked") - @NonNull - public Bundle getArguments() { - Bundle __result = new Bundle(); - if (arguments.containsKey("camera_id")) { - String cameraId = (String) arguments.get("camera_id"); - __result.putString("camera_id", cameraId); - } - if (arguments.containsKey("pixel_format")) { - int pixelFormat = (int) arguments.get("pixel_format"); - __result.putInt("pixel_format", pixelFormat); - } - return __result; - } + public static class ActionSelectorToCamera implements NavDirections { + private final HashMap arguments = new HashMap(); - @Override - public int getActionId() { - return R.id.action_selector_to_camera; - } + @SuppressWarnings("unchecked") + private ActionSelectorToCamera(@NonNull String cameraId, int pixelFormat) { + if (cameraId == null) { + throw new IllegalArgumentException( + "Argument \"camera_id\" is marked as non-null but was passed a null" + + " value."); + } + this.arguments.put("camera_id", cameraId); + this.arguments.put("pixel_format", pixelFormat); + } - @SuppressWarnings("unchecked") - @NonNull - public String getCameraId() { - return (String) arguments.get("camera_id"); - } + @NonNull + @SuppressWarnings("unchecked") + public ActionSelectorToCamera setCameraId(@NonNull String cameraId) { + if (cameraId == null) { + throw new IllegalArgumentException( + "Argument \"camera_id\" is marked as non-null but was passed a null" + + " value."); + } + this.arguments.put("camera_id", cameraId); + return this; + } - @SuppressWarnings("unchecked") - public int getPixelFormat() { - return (int) arguments.get("pixel_format"); - } + @NonNull + @SuppressWarnings("unchecked") + public ActionSelectorToCamera setPixelFormat(int pixelFormat) { + this.arguments.put("pixel_format", pixelFormat); + return this; + } - @Override - public boolean equals(Object object) { - if (this == object) { - return true; - } - if (object == null || getClass() != object.getClass()) { - return false; - } - ActionSelectorToCamera that = (ActionSelectorToCamera) object; - if (arguments.containsKey("camera_id") != that.arguments.containsKey("camera_id")) { - return false; - } - if (getCameraId() != null ? !getCameraId().equals(that.getCameraId()) : that.getCameraId() != null) { - return false; - } - if (arguments.containsKey("pixel_format") != that.arguments.containsKey("pixel_format")) { - return false; - } - if (getPixelFormat() != that.getPixelFormat()) { - return false; - } - if (getActionId() != that.getActionId()) { - return false; - } - return true; - } + @Override + @SuppressWarnings("unchecked") + @NonNull + public Bundle getArguments() { + Bundle __result = new Bundle(); + if (arguments.containsKey("camera_id")) { + String cameraId = (String) arguments.get("camera_id"); + __result.putString("camera_id", cameraId); + } + if (arguments.containsKey("pixel_format")) { + int pixelFormat = (int) arguments.get("pixel_format"); + __result.putInt("pixel_format", pixelFormat); + } + return __result; + } - @Override - public int hashCode() { - int result = 1; - result = 31 * result + (getCameraId() != null ? getCameraId().hashCode() : 0); - result = 31 * result + getPixelFormat(); - result = 31 * result + getActionId(); - return result; - } + @Override + public int getActionId() { + return R.id.action_selector_to_camera; + } + + @SuppressWarnings("unchecked") + @NonNull + public String getCameraId() { + return (String) arguments.get("camera_id"); + } + + @SuppressWarnings("unchecked") + public int getPixelFormat() { + return (int) arguments.get("pixel_format"); + } + + @Override + public boolean equals(Object object) { + if (this == object) { + return true; + } + if (object == null || getClass() != object.getClass()) { + return false; + } + ActionSelectorToCamera that = (ActionSelectorToCamera) object; + if (arguments.containsKey("camera_id") != that.arguments.containsKey("camera_id")) { + return false; + } + if (getCameraId() != null + ? !getCameraId().equals(that.getCameraId()) + : that.getCameraId() != null) { + return false; + } + if (arguments.containsKey("pixel_format") + != that.arguments.containsKey("pixel_format")) { + return false; + } + if (getPixelFormat() != that.getPixelFormat()) { + return false; + } + if (getActionId() != that.getActionId()) { + return false; + } + return true; + } + + @Override + public int hashCode() { + int result = 1; + result = 31 * result + (getCameraId() != null ? getCameraId().hashCode() : 0); + result = 31 * result + getPixelFormat(); + result = 31 * result + getActionId(); + return result; + } - @Override - public String toString() { - return "ActionSelectorToCamera(actionId=" + getActionId() + "){" - + "cameraId=" + getCameraId() - + ", pixelFormat=" + getPixelFormat() - + "}"; + @Override + public String toString() { + return "ActionSelectorToCamera(actionId=" + + getActionId() + + "){" + + "cameraId=" + + getCameraId() + + ", pixelFormat=" + + getPixelFormat() + + "}"; + } } - } } diff --git a/Camera2Basic/app/build/generated/source/navigation-args/debug/com/example/android/camera2/basic/video/VideoFragmentArgs.java b/Camera2Basic/app/build/generated/source/navigation-args/debug/com/example/android/camera2/basic/video/VideoFragmentArgs.java index e5beb00..6bc7e6c 100644 --- a/Camera2Basic/app/build/generated/source/navigation-args/debug/com/example/android/camera2/basic/video/VideoFragmentArgs.java +++ b/Camera2Basic/app/build/generated/source/navigation-args/debug/com/example/android/camera2/basic/video/VideoFragmentArgs.java @@ -1,240 +1,256 @@ package com.example.android.camera2.basic.video; import android.os.Bundle; + import androidx.annotation.NonNull; import androidx.navigation.NavArgs; -import java.lang.IllegalArgumentException; -import java.lang.Object; -import java.lang.Override; -import java.lang.String; -import java.lang.SuppressWarnings; + import java.util.HashMap; public class VideoFragmentArgs implements NavArgs { - private final HashMap arguments = new HashMap(); - - private VideoFragmentArgs() { - } - - @SuppressWarnings("unchecked") - private VideoFragmentArgs(HashMap argumentsMap) { - this.arguments.putAll(argumentsMap); - } - - @NonNull - @SuppressWarnings("unchecked") - public static VideoFragmentArgs fromBundle(@NonNull Bundle bundle) { - VideoFragmentArgs __result = new VideoFragmentArgs(); - bundle.setClassLoader(VideoFragmentArgs.class.getClassLoader()); - if (bundle.containsKey("camera_id")) { - String cameraId; - cameraId = bundle.getString("camera_id"); - if (cameraId == null) { - throw new IllegalArgumentException("Argument \"camera_id\" is marked as non-null but was passed a null value."); - } - __result.arguments.put("camera_id", cameraId); - } else { - throw new IllegalArgumentException("Required argument \"camera_id\" is missing and does not have an android:defaultValue"); - } - if (bundle.containsKey("width")) { - int width; - width = bundle.getInt("width"); - __result.arguments.put("width", width); - } else { - throw new IllegalArgumentException("Required argument \"width\" is missing and does not have an android:defaultValue"); - } - if (bundle.containsKey("height")) { - int height; - height = bundle.getInt("height"); - __result.arguments.put("height", height); - } else { - throw new IllegalArgumentException("Required argument \"height\" is missing and does not have an android:defaultValue"); - } - if (bundle.containsKey("fps")) { - int fps; - fps = bundle.getInt("fps"); - __result.arguments.put("fps", fps); - } else { - throw new IllegalArgumentException("Required argument \"fps\" is missing and does not have an android:defaultValue"); - } - return __result; - } - - @SuppressWarnings("unchecked") - @NonNull - public String getCameraId() { - return (String) arguments.get("camera_id"); - } - - @SuppressWarnings("unchecked") - public int getWidth() { - return (int) arguments.get("width"); - } - - @SuppressWarnings("unchecked") - public int getHeight() { - return (int) arguments.get("height"); - } - - @SuppressWarnings("unchecked") - public int getFps() { - return (int) arguments.get("fps"); - } - - @SuppressWarnings("unchecked") - @NonNull - public Bundle toBundle() { - Bundle __result = new Bundle(); - if (arguments.containsKey("camera_id")) { - String cameraId = (String) arguments.get("camera_id"); - __result.putString("camera_id", cameraId); - } - if (arguments.containsKey("width")) { - int width = (int) arguments.get("width"); - __result.putInt("width", width); - } - if (arguments.containsKey("height")) { - int height = (int) arguments.get("height"); - __result.putInt("height", height); - } - if (arguments.containsKey("fps")) { - int fps = (int) arguments.get("fps"); - __result.putInt("fps", fps); - } - return __result; - } - - @Override - public boolean equals(Object object) { - if (this == object) { - return true; - } - if (object == null || getClass() != object.getClass()) { - return false; - } - VideoFragmentArgs that = (VideoFragmentArgs) object; - if (arguments.containsKey("camera_id") != that.arguments.containsKey("camera_id")) { - return false; - } - if (getCameraId() != null ? !getCameraId().equals(that.getCameraId()) : that.getCameraId() != null) { - return false; - } - if (arguments.containsKey("width") != that.arguments.containsKey("width")) { - return false; - } - if (getWidth() != that.getWidth()) { - return false; - } - if (arguments.containsKey("height") != that.arguments.containsKey("height")) { - return false; - } - if (getHeight() != that.getHeight()) { - return false; - } - if (arguments.containsKey("fps") != that.arguments.containsKey("fps")) { - return false; - } - if (getFps() != that.getFps()) { - return false; - } - return true; - } - - @Override - public int hashCode() { - int result = 1; - result = 31 * result + (getCameraId() != null ? getCameraId().hashCode() : 0); - result = 31 * result + getWidth(); - result = 31 * result + getHeight(); - result = 31 * result + getFps(); - return result; - } - - @Override - public String toString() { - return "VideoFragmentArgs{" - + "cameraId=" + getCameraId() - + ", width=" + getWidth() - + ", height=" + getHeight() - + ", fps=" + getFps() - + "}"; - } - - public static class Builder { private final HashMap arguments = new HashMap(); - @SuppressWarnings("unchecked") - public Builder(VideoFragmentArgs original) { - this.arguments.putAll(original.arguments); - } + private VideoFragmentArgs() {} @SuppressWarnings("unchecked") - public Builder(@NonNull String cameraId, int width, int height, int fps) { - if (cameraId == null) { - throw new IllegalArgumentException("Argument \"camera_id\" is marked as non-null but was passed a null value."); - } - this.arguments.put("camera_id", cameraId); - this.arguments.put("width", width); - this.arguments.put("height", height); - this.arguments.put("fps", fps); + private VideoFragmentArgs(HashMap argumentsMap) { + this.arguments.putAll(argumentsMap); } @NonNull - public VideoFragmentArgs build() { - VideoFragmentArgs result = new VideoFragmentArgs(arguments); - return result; + @SuppressWarnings("unchecked") + public static VideoFragmentArgs fromBundle(@NonNull Bundle bundle) { + VideoFragmentArgs __result = new VideoFragmentArgs(); + bundle.setClassLoader(VideoFragmentArgs.class.getClassLoader()); + if (bundle.containsKey("camera_id")) { + String cameraId; + cameraId = bundle.getString("camera_id"); + if (cameraId == null) { + throw new IllegalArgumentException( + "Argument \"camera_id\" is marked as non-null but was passed a null" + + " value."); + } + __result.arguments.put("camera_id", cameraId); + } else { + throw new IllegalArgumentException( + "Required argument \"camera_id\" is missing and does not have an" + + " android:defaultValue"); + } + if (bundle.containsKey("width")) { + int width; + width = bundle.getInt("width"); + __result.arguments.put("width", width); + } else { + throw new IllegalArgumentException( + "Required argument \"width\" is missing and does not have an" + + " android:defaultValue"); + } + if (bundle.containsKey("height")) { + int height; + height = bundle.getInt("height"); + __result.arguments.put("height", height); + } else { + throw new IllegalArgumentException( + "Required argument \"height\" is missing and does not have an" + + " android:defaultValue"); + } + if (bundle.containsKey("fps")) { + int fps; + fps = bundle.getInt("fps"); + __result.arguments.put("fps", fps); + } else { + throw new IllegalArgumentException( + "Required argument \"fps\" is missing and does not have an" + + " android:defaultValue"); + } + return __result; } - @NonNull @SuppressWarnings("unchecked") - public Builder setCameraId(@NonNull String cameraId) { - if (cameraId == null) { - throw new IllegalArgumentException("Argument \"camera_id\" is marked as non-null but was passed a null value."); - } - this.arguments.put("camera_id", cameraId); - return this; + @NonNull + public String getCameraId() { + return (String) arguments.get("camera_id"); } - @NonNull @SuppressWarnings("unchecked") - public Builder setWidth(int width) { - this.arguments.put("width", width); - return this; + public int getWidth() { + return (int) arguments.get("width"); } - @NonNull @SuppressWarnings("unchecked") - public Builder setHeight(int height) { - this.arguments.put("height", height); - return this; + public int getHeight() { + return (int) arguments.get("height"); } - @NonNull @SuppressWarnings("unchecked") - public Builder setFps(int fps) { - this.arguments.put("fps", fps); - return this; + public int getFps() { + return (int) arguments.get("fps"); } @SuppressWarnings("unchecked") @NonNull - public String getCameraId() { - return (String) arguments.get("camera_id"); + public Bundle toBundle() { + Bundle __result = new Bundle(); + if (arguments.containsKey("camera_id")) { + String cameraId = (String) arguments.get("camera_id"); + __result.putString("camera_id", cameraId); + } + if (arguments.containsKey("width")) { + int width = (int) arguments.get("width"); + __result.putInt("width", width); + } + if (arguments.containsKey("height")) { + int height = (int) arguments.get("height"); + __result.putInt("height", height); + } + if (arguments.containsKey("fps")) { + int fps = (int) arguments.get("fps"); + __result.putInt("fps", fps); + } + return __result; } - @SuppressWarnings("unchecked") - public int getWidth() { - return (int) arguments.get("width"); + @Override + public boolean equals(Object object) { + if (this == object) { + return true; + } + if (object == null || getClass() != object.getClass()) { + return false; + } + VideoFragmentArgs that = (VideoFragmentArgs) object; + if (arguments.containsKey("camera_id") != that.arguments.containsKey("camera_id")) { + return false; + } + if (getCameraId() != null + ? !getCameraId().equals(that.getCameraId()) + : that.getCameraId() != null) { + return false; + } + if (arguments.containsKey("width") != that.arguments.containsKey("width")) { + return false; + } + if (getWidth() != that.getWidth()) { + return false; + } + if (arguments.containsKey("height") != that.arguments.containsKey("height")) { + return false; + } + if (getHeight() != that.getHeight()) { + return false; + } + if (arguments.containsKey("fps") != that.arguments.containsKey("fps")) { + return false; + } + if (getFps() != that.getFps()) { + return false; + } + return true; } - @SuppressWarnings("unchecked") - public int getHeight() { - return (int) arguments.get("height"); + @Override + public int hashCode() { + int result = 1; + result = 31 * result + (getCameraId() != null ? getCameraId().hashCode() : 0); + result = 31 * result + getWidth(); + result = 31 * result + getHeight(); + result = 31 * result + getFps(); + return result; } - @SuppressWarnings("unchecked") - public int getFps() { - return (int) arguments.get("fps"); + @Override + public String toString() { + return "VideoFragmentArgs{" + + "cameraId=" + + getCameraId() + + ", width=" + + getWidth() + + ", height=" + + getHeight() + + ", fps=" + + getFps() + + "}"; + } + + public static class Builder { + private final HashMap arguments = new HashMap(); + + @SuppressWarnings("unchecked") + public Builder(VideoFragmentArgs original) { + this.arguments.putAll(original.arguments); + } + + @SuppressWarnings("unchecked") + public Builder(@NonNull String cameraId, int width, int height, int fps) { + if (cameraId == null) { + throw new IllegalArgumentException( + "Argument \"camera_id\" is marked as non-null but was passed a null" + + " value."); + } + this.arguments.put("camera_id", cameraId); + this.arguments.put("width", width); + this.arguments.put("height", height); + this.arguments.put("fps", fps); + } + + @NonNull + public VideoFragmentArgs build() { + VideoFragmentArgs result = new VideoFragmentArgs(arguments); + return result; + } + + @NonNull + @SuppressWarnings("unchecked") + public Builder setCameraId(@NonNull String cameraId) { + if (cameraId == null) { + throw new IllegalArgumentException( + "Argument \"camera_id\" is marked as non-null but was passed a null" + + " value."); + } + this.arguments.put("camera_id", cameraId); + return this; + } + + @NonNull + @SuppressWarnings("unchecked") + public Builder setWidth(int width) { + this.arguments.put("width", width); + return this; + } + + @NonNull + @SuppressWarnings("unchecked") + public Builder setHeight(int height) { + this.arguments.put("height", height); + return this; + } + + @NonNull + @SuppressWarnings("unchecked") + public Builder setFps(int fps) { + this.arguments.put("fps", fps); + return this; + } + + @SuppressWarnings("unchecked") + @NonNull + public String getCameraId() { + return (String) arguments.get("camera_id"); + } + + @SuppressWarnings("unchecked") + public int getWidth() { + return (int) arguments.get("width"); + } + + @SuppressWarnings("unchecked") + public int getHeight() { + return (int) arguments.get("height"); + } + + @SuppressWarnings("unchecked") + public int getFps() { + return (int) arguments.get("fps"); + } } - } } diff --git a/Camera2Basic/app/build/generated/source/navigation-args/debug/com/example/android/camera2/basic/video/VideoFragmentDirections.java b/Camera2Basic/app/build/generated/source/navigation-args/debug/com/example/android/camera2/basic/video/VideoFragmentDirections.java index 1fb741a..8c70a5c 100644 --- a/Camera2Basic/app/build/generated/source/navigation-args/debug/com/example/android/camera2/basic/video/VideoFragmentDirections.java +++ b/Camera2Basic/app/build/generated/source/navigation-args/debug/com/example/android/camera2/basic/video/VideoFragmentDirections.java @@ -3,14 +3,14 @@ import androidx.annotation.NonNull; import androidx.navigation.ActionOnlyNavDirections; import androidx.navigation.NavDirections; + import com.example.android.camera2.basic.R; public class VideoFragmentDirections { - private VideoFragmentDirections() { - } + private VideoFragmentDirections() {} - @NonNull - public static NavDirections actionCameraToPermissions() { - return new ActionOnlyNavDirections(R.id.action_camera_to_permissions); - } + @NonNull + public static NavDirections actionCameraToPermissions() { + return new ActionOnlyNavDirections(R.id.action_camera_to_permissions); + } } diff --git a/Camera2Basic/app/build/generated/source/navigation-args/debug/com/example/android/camera2/basic/video/VideoSelectorFragmentDirections.java b/Camera2Basic/app/build/generated/source/navigation-args/debug/com/example/android/camera2/basic/video/VideoSelectorFragmentDirections.java index d7321c3..0228233 100644 --- a/Camera2Basic/app/build/generated/source/navigation-args/debug/com/example/android/camera2/basic/video/VideoSelectorFragmentDirections.java +++ b/Camera2Basic/app/build/generated/source/navigation-args/debug/com/example/android/camera2/basic/video/VideoSelectorFragmentDirections.java @@ -1,185 +1,194 @@ package com.example.android.camera2.basic.video; import android.os.Bundle; + import androidx.annotation.NonNull; import androidx.navigation.ActionOnlyNavDirections; import androidx.navigation.NavDirections; + import com.example.android.camera2.basic.R; -import java.lang.IllegalArgumentException; -import java.lang.Object; -import java.lang.Override; -import java.lang.String; -import java.lang.SuppressWarnings; + import java.util.HashMap; public class VideoSelectorFragmentDirections { - private VideoSelectorFragmentDirections() { - } - - @NonNull - public static ActionSelectorToVideo actionSelectorToVideo(@NonNull String cameraId, int width, - int height, int fps) { - return new ActionSelectorToVideo(cameraId, width, height, fps); - } - - @NonNull - public static NavDirections actionVideoToCamera() { - return new ActionOnlyNavDirections(R.id.action_video_to_camera); - } - - public static class ActionSelectorToVideo implements NavDirections { - private final HashMap arguments = new HashMap(); - - @SuppressWarnings("unchecked") - private ActionSelectorToVideo(@NonNull String cameraId, int width, int height, int fps) { - if (cameraId == null) { - throw new IllegalArgumentException("Argument \"camera_id\" is marked as non-null but was passed a null value."); - } - this.arguments.put("camera_id", cameraId); - this.arguments.put("width", width); - this.arguments.put("height", height); - this.arguments.put("fps", fps); - } - - @NonNull - @SuppressWarnings("unchecked") - public ActionSelectorToVideo setCameraId(@NonNull String cameraId) { - if (cameraId == null) { - throw new IllegalArgumentException("Argument \"camera_id\" is marked as non-null but was passed a null value."); - } - this.arguments.put("camera_id", cameraId); - return this; - } - - @NonNull - @SuppressWarnings("unchecked") - public ActionSelectorToVideo setWidth(int width) { - this.arguments.put("width", width); - return this; - } - - @NonNull - @SuppressWarnings("unchecked") - public ActionSelectorToVideo setHeight(int height) { - this.arguments.put("height", height); - return this; - } - - @NonNull - @SuppressWarnings("unchecked") - public ActionSelectorToVideo setFps(int fps) { - this.arguments.put("fps", fps); - return this; - } + private VideoSelectorFragmentDirections() {} - @Override - @SuppressWarnings("unchecked") @NonNull - public Bundle getArguments() { - Bundle __result = new Bundle(); - if (arguments.containsKey("camera_id")) { - String cameraId = (String) arguments.get("camera_id"); - __result.putString("camera_id", cameraId); - } - if (arguments.containsKey("width")) { - int width = (int) arguments.get("width"); - __result.putInt("width", width); - } - if (arguments.containsKey("height")) { - int height = (int) arguments.get("height"); - __result.putInt("height", height); - } - if (arguments.containsKey("fps")) { - int fps = (int) arguments.get("fps"); - __result.putInt("fps", fps); - } - return __result; - } - - @Override - public int getActionId() { - return R.id.action_selector_to_video; + public static ActionSelectorToVideo actionSelectorToVideo( + @NonNull String cameraId, int width, int height, int fps) { + return new ActionSelectorToVideo(cameraId, width, height, fps); } - @SuppressWarnings("unchecked") @NonNull - public String getCameraId() { - return (String) arguments.get("camera_id"); - } - - @SuppressWarnings("unchecked") - public int getWidth() { - return (int) arguments.get("width"); - } - - @SuppressWarnings("unchecked") - public int getHeight() { - return (int) arguments.get("height"); - } - - @SuppressWarnings("unchecked") - public int getFps() { - return (int) arguments.get("fps"); - } - - @Override - public boolean equals(Object object) { - if (this == object) { - return true; - } - if (object == null || getClass() != object.getClass()) { - return false; - } - ActionSelectorToVideo that = (ActionSelectorToVideo) object; - if (arguments.containsKey("camera_id") != that.arguments.containsKey("camera_id")) { - return false; - } - if (getCameraId() != null ? !getCameraId().equals(that.getCameraId()) : that.getCameraId() != null) { - return false; - } - if (arguments.containsKey("width") != that.arguments.containsKey("width")) { - return false; - } - if (getWidth() != that.getWidth()) { - return false; - } - if (arguments.containsKey("height") != that.arguments.containsKey("height")) { - return false; - } - if (getHeight() != that.getHeight()) { - return false; - } - if (arguments.containsKey("fps") != that.arguments.containsKey("fps")) { - return false; - } - if (getFps() != that.getFps()) { - return false; - } - if (getActionId() != that.getActionId()) { - return false; - } - return true; - } - - @Override - public int hashCode() { - int result = 1; - result = 31 * result + (getCameraId() != null ? getCameraId().hashCode() : 0); - result = 31 * result + getWidth(); - result = 31 * result + getHeight(); - result = 31 * result + getFps(); - result = 31 * result + getActionId(); - return result; + public static NavDirections actionVideoToCamera() { + return new ActionOnlyNavDirections(R.id.action_video_to_camera); } - @Override - public String toString() { - return "ActionSelectorToVideo(actionId=" + getActionId() + "){" - + "cameraId=" + getCameraId() - + ", width=" + getWidth() - + ", height=" + getHeight() - + ", fps=" + getFps() - + "}"; + public static class ActionSelectorToVideo implements NavDirections { + private final HashMap arguments = new HashMap(); + + @SuppressWarnings("unchecked") + private ActionSelectorToVideo(@NonNull String cameraId, int width, int height, int fps) { + if (cameraId == null) { + throw new IllegalArgumentException( + "Argument \"camera_id\" is marked as non-null but was passed a null" + + " value."); + } + this.arguments.put("camera_id", cameraId); + this.arguments.put("width", width); + this.arguments.put("height", height); + this.arguments.put("fps", fps); + } + + @NonNull + @SuppressWarnings("unchecked") + public ActionSelectorToVideo setCameraId(@NonNull String cameraId) { + if (cameraId == null) { + throw new IllegalArgumentException( + "Argument \"camera_id\" is marked as non-null but was passed a null" + + " value."); + } + this.arguments.put("camera_id", cameraId); + return this; + } + + @NonNull + @SuppressWarnings("unchecked") + public ActionSelectorToVideo setWidth(int width) { + this.arguments.put("width", width); + return this; + } + + @NonNull + @SuppressWarnings("unchecked") + public ActionSelectorToVideo setHeight(int height) { + this.arguments.put("height", height); + return this; + } + + @NonNull + @SuppressWarnings("unchecked") + public ActionSelectorToVideo setFps(int fps) { + this.arguments.put("fps", fps); + return this; + } + + @Override + @SuppressWarnings("unchecked") + @NonNull + public Bundle getArguments() { + Bundle __result = new Bundle(); + if (arguments.containsKey("camera_id")) { + String cameraId = (String) arguments.get("camera_id"); + __result.putString("camera_id", cameraId); + } + if (arguments.containsKey("width")) { + int width = (int) arguments.get("width"); + __result.putInt("width", width); + } + if (arguments.containsKey("height")) { + int height = (int) arguments.get("height"); + __result.putInt("height", height); + } + if (arguments.containsKey("fps")) { + int fps = (int) arguments.get("fps"); + __result.putInt("fps", fps); + } + return __result; + } + + @Override + public int getActionId() { + return R.id.action_selector_to_video; + } + + @SuppressWarnings("unchecked") + @NonNull + public String getCameraId() { + return (String) arguments.get("camera_id"); + } + + @SuppressWarnings("unchecked") + public int getWidth() { + return (int) arguments.get("width"); + } + + @SuppressWarnings("unchecked") + public int getHeight() { + return (int) arguments.get("height"); + } + + @SuppressWarnings("unchecked") + public int getFps() { + return (int) arguments.get("fps"); + } + + @Override + public boolean equals(Object object) { + if (this == object) { + return true; + } + if (object == null || getClass() != object.getClass()) { + return false; + } + ActionSelectorToVideo that = (ActionSelectorToVideo) object; + if (arguments.containsKey("camera_id") != that.arguments.containsKey("camera_id")) { + return false; + } + if (getCameraId() != null + ? !getCameraId().equals(that.getCameraId()) + : that.getCameraId() != null) { + return false; + } + if (arguments.containsKey("width") != that.arguments.containsKey("width")) { + return false; + } + if (getWidth() != that.getWidth()) { + return false; + } + if (arguments.containsKey("height") != that.arguments.containsKey("height")) { + return false; + } + if (getHeight() != that.getHeight()) { + return false; + } + if (arguments.containsKey("fps") != that.arguments.containsKey("fps")) { + return false; + } + if (getFps() != that.getFps()) { + return false; + } + if (getActionId() != that.getActionId()) { + return false; + } + return true; + } + + @Override + public int hashCode() { + int result = 1; + result = 31 * result + (getCameraId() != null ? getCameraId().hashCode() : 0); + result = 31 * result + getWidth(); + result = 31 * result + getHeight(); + result = 31 * result + getFps(); + result = 31 * result + getActionId(); + return result; + } + + @Override + public String toString() { + return "ActionSelectorToVideo(actionId=" + + getActionId() + + "){" + + "cameraId=" + + getCameraId() + + ", width=" + + getWidth() + + ", height=" + + getHeight() + + ", fps=" + + getFps() + + "}"; + } } - } } diff --git a/Camera2Basic/app/src/main/java/com/example/android/camera2/basic/utils/SwipeGestureDetector.java b/Camera2Basic/app/src/main/java/com/example/android/camera2/basic/utils/SwipeGestureDetector.java index 21197e5..8ca27dd 100644 --- a/Camera2Basic/app/src/main/java/com/example/android/camera2/basic/utils/SwipeGestureDetector.java +++ b/Camera2Basic/app/src/main/java/com/example/android/camera2/basic/utils/SwipeGestureDetector.java @@ -1,19 +1,22 @@ package com.example.android.camera2.basic; +import android.util.Log; import android.view.GestureDetector; import android.view.MotionEvent; -import javax.annotation.Nullable; -import android.util.Log; -import androidx.navigation.Navigation; import android.view.View; +import androidx.navigation.Navigation; + +import javax.annotation.Nullable; + public class SwipeGestureDetector extends GestureDetector.SimpleOnGestureListener { - private final static int MIN_SWIPE_DISTANCE_X = 100; + private static final int MIN_SWIPE_DISTANCE_X = 100; private static final String TAG = "SwipeGestureDetector"; private View view; @Override - public boolean onFling(@Nullable MotionEvent e1, @Nullable MotionEvent e2, float velocityX, float velocityY) { + public boolean onFling( + @Nullable MotionEvent e1, @Nullable MotionEvent e2, float velocityX, float velocityY) { if (e1 == null || e2 == null) { Log.e(TAG, "e1 or e2 is null!"); return super.onFling(e1, e2, velocityX, velocityY); @@ -34,8 +37,7 @@ public boolean onFling(@Nullable MotionEvent e1, @Nullable MotionEvent e2, float return true; } - public SwipeGestureDetector (View view) { + public SwipeGestureDetector(View view) { this.view = view; } - -} \ No newline at end of file +} diff --git a/CameraXBasic/gen/buildConfig/debug/com/android/example/cameraxbasic/BuildConfig.java b/CameraXBasic/gen/buildConfig/debug/com/android/example/cameraxbasic/BuildConfig.java index 851bf26..51d87d6 100644 --- a/CameraXBasic/gen/buildConfig/debug/com/android/example/cameraxbasic/BuildConfig.java +++ b/CameraXBasic/gen/buildConfig/debug/com/android/example/cameraxbasic/BuildConfig.java @@ -1,12 +1,10 @@ -/** - * Automatically generated file. DO NOT MODIFY - */ +/** Automatically generated file. DO NOT MODIFY */ package com.android.example.cameraxbasic; public final class BuildConfig { - public static final boolean DEBUG = Boolean.parseBoolean("true"); - public static final String APPLICATION_ID = "com.android.example.cameraxbasic"; - public static final String BUILD_TYPE = "debug"; - public static final int VERSION_CODE = 1; - public static final String VERSION_NAME = "1.0.0"; + public static final boolean DEBUG = Boolean.parseBoolean("true"); + public static final String APPLICATION_ID = "com.android.example.cameraxbasic"; + public static final String BUILD_TYPE = "debug"; + public static final int VERSION_CODE = 1; + public static final String VERSION_NAME = "1.0.0"; } diff --git a/CameraXBasic/gen/navigation-args/debug/com/android/example/cameraxbasic/fragments/CameraFragmentDirections.java b/CameraXBasic/gen/navigation-args/debug/com/android/example/cameraxbasic/fragments/CameraFragmentDirections.java index cad9877..c05626f 100644 --- a/CameraXBasic/gen/navigation-args/debug/com/android/example/cameraxbasic/fragments/CameraFragmentDirections.java +++ b/CameraXBasic/gen/navigation-args/debug/com/android/example/cameraxbasic/fragments/CameraFragmentDirections.java @@ -1,112 +1,119 @@ package com.android.example.cameraxbasic.fragments; import android.os.Bundle; + import androidx.annotation.NonNull; import androidx.navigation.ActionOnlyNavDirections; import androidx.navigation.NavDirections; + import com.android.example.cameraxbasic.R; -import java.lang.IllegalArgumentException; -import java.lang.Object; -import java.lang.Override; -import java.lang.String; -import java.lang.SuppressWarnings; + import java.util.HashMap; public class CameraFragmentDirections { - private CameraFragmentDirections() { - } - - @NonNull - public static ActionCameraToGallery actionCameraToGallery(@NonNull String rootDirectory) { - return new ActionCameraToGallery(rootDirectory); - } - - @NonNull - public static NavDirections actionCameraToPermissions() { - return new ActionOnlyNavDirections(R.id.action_camera_to_permissions); - } - - @NonNull - public static NavDirections actionCameraToVideo() { - return new ActionOnlyNavDirections(R.id.action_camera_to_video); - } - - public static class ActionCameraToGallery implements NavDirections { - private final HashMap arguments = new HashMap(); - - private ActionCameraToGallery(@NonNull String rootDirectory) { - if (rootDirectory == null) { - throw new IllegalArgumentException("Argument \"root_directory\" is marked as non-null but was passed a null value."); - } - this.arguments.put("root_directory", rootDirectory); - } + private CameraFragmentDirections() {} @NonNull - public ActionCameraToGallery setRootDirectory(@NonNull String rootDirectory) { - if (rootDirectory == null) { - throw new IllegalArgumentException("Argument \"root_directory\" is marked as non-null but was passed a null value."); - } - this.arguments.put("root_directory", rootDirectory); - return this; + public static ActionCameraToGallery actionCameraToGallery(@NonNull String rootDirectory) { + return new ActionCameraToGallery(rootDirectory); } - @Override - @SuppressWarnings("unchecked") @NonNull - public Bundle getArguments() { - Bundle __result = new Bundle(); - if (arguments.containsKey("root_directory")) { - String rootDirectory = (String) arguments.get("root_directory"); - __result.putString("root_directory", rootDirectory); - } - return __result; + public static NavDirections actionCameraToPermissions() { + return new ActionOnlyNavDirections(R.id.action_camera_to_permissions); } - @Override - public int getActionId() { - return R.id.action_camera_to_gallery; - } - - @SuppressWarnings("unchecked") @NonNull - public String getRootDirectory() { - return (String) arguments.get("root_directory"); + public static NavDirections actionCameraToVideo() { + return new ActionOnlyNavDirections(R.id.action_camera_to_video); } - @Override - public boolean equals(Object object) { - if (this == object) { - return true; - } - if (object == null || getClass() != object.getClass()) { - return false; - } - ActionCameraToGallery that = (ActionCameraToGallery) object; - if (arguments.containsKey("root_directory") != that.arguments.containsKey("root_directory")) { - return false; - } - if (getRootDirectory() != null ? !getRootDirectory().equals(that.getRootDirectory()) : that.getRootDirectory() != null) { - return false; - } - if (getActionId() != that.getActionId()) { - return false; - } - return true; - } + public static class ActionCameraToGallery implements NavDirections { + private final HashMap arguments = new HashMap(); - @Override - public int hashCode() { - int result = 1; - result = 31 * result + (getRootDirectory() != null ? getRootDirectory().hashCode() : 0); - result = 31 * result + getActionId(); - return result; - } + private ActionCameraToGallery(@NonNull String rootDirectory) { + if (rootDirectory == null) { + throw new IllegalArgumentException( + "Argument \"root_directory\" is marked as non-null but was passed a null" + + " value."); + } + this.arguments.put("root_directory", rootDirectory); + } + + @NonNull + public ActionCameraToGallery setRootDirectory(@NonNull String rootDirectory) { + if (rootDirectory == null) { + throw new IllegalArgumentException( + "Argument \"root_directory\" is marked as non-null but was passed a null" + + " value."); + } + this.arguments.put("root_directory", rootDirectory); + return this; + } + + @Override + @SuppressWarnings("unchecked") + @NonNull + public Bundle getArguments() { + Bundle __result = new Bundle(); + if (arguments.containsKey("root_directory")) { + String rootDirectory = (String) arguments.get("root_directory"); + __result.putString("root_directory", rootDirectory); + } + return __result; + } + + @Override + public int getActionId() { + return R.id.action_camera_to_gallery; + } + + @SuppressWarnings("unchecked") + @NonNull + public String getRootDirectory() { + return (String) arguments.get("root_directory"); + } + + @Override + public boolean equals(Object object) { + if (this == object) { + return true; + } + if (object == null || getClass() != object.getClass()) { + return false; + } + ActionCameraToGallery that = (ActionCameraToGallery) object; + if (arguments.containsKey("root_directory") + != that.arguments.containsKey("root_directory")) { + return false; + } + if (getRootDirectory() != null + ? !getRootDirectory().equals(that.getRootDirectory()) + : that.getRootDirectory() != null) { + return false; + } + if (getActionId() != that.getActionId()) { + return false; + } + return true; + } + + @Override + public int hashCode() { + int result = 1; + result = 31 * result + (getRootDirectory() != null ? getRootDirectory().hashCode() : 0); + result = 31 * result + getActionId(); + return result; + } - @Override - public String toString() { - return "ActionCameraToGallery(actionId=" + getActionId() + "){" - + "rootDirectory=" + getRootDirectory() - + "}"; + @Override + public String toString() { + return "ActionCameraToGallery(actionId=" + + getActionId() + + "){" + + "rootDirectory=" + + getRootDirectory() + + "}"; + } } - } } diff --git a/CameraXBasic/gen/navigation-args/debug/com/android/example/cameraxbasic/fragments/GalleryFragmentArgs.java b/CameraXBasic/gen/navigation-args/debug/com/android/example/cameraxbasic/fragments/GalleryFragmentArgs.java index f2d91f2..6661080 100644 --- a/CameraXBasic/gen/navigation-args/debug/com/android/example/cameraxbasic/fragments/GalleryFragmentArgs.java +++ b/CameraXBasic/gen/navigation-args/debug/com/android/example/cameraxbasic/fragments/GalleryFragmentArgs.java @@ -1,125 +1,130 @@ package com.android.example.cameraxbasic.fragments; import android.os.Bundle; + import androidx.annotation.NonNull; import androidx.navigation.NavArgs; -import java.lang.IllegalArgumentException; -import java.lang.Object; -import java.lang.Override; -import java.lang.String; -import java.lang.SuppressWarnings; + import java.util.HashMap; public class GalleryFragmentArgs implements NavArgs { - private final HashMap arguments = new HashMap(); - - private GalleryFragmentArgs() { - } - - private GalleryFragmentArgs(HashMap argumentsMap) { - this.arguments.putAll(argumentsMap); - } - - @NonNull - @SuppressWarnings("unchecked") - public static GalleryFragmentArgs fromBundle(@NonNull Bundle bundle) { - GalleryFragmentArgs __result = new GalleryFragmentArgs(); - bundle.setClassLoader(GalleryFragmentArgs.class.getClassLoader()); - if (bundle.containsKey("root_directory")) { - String rootDirectory; - rootDirectory = bundle.getString("root_directory"); - if (rootDirectory == null) { - throw new IllegalArgumentException("Argument \"root_directory\" is marked as non-null but was passed a null value."); - } - __result.arguments.put("root_directory", rootDirectory); - } else { - throw new IllegalArgumentException("Required argument \"root_directory\" is missing and does not have an android:defaultValue"); - } - return __result; - } - - @SuppressWarnings("unchecked") - @NonNull - public String getRootDirectory() { - return (String) arguments.get("root_directory"); - } - - @SuppressWarnings("unchecked") - @NonNull - public Bundle toBundle() { - Bundle __result = new Bundle(); - if (arguments.containsKey("root_directory")) { - String rootDirectory = (String) arguments.get("root_directory"); - __result.putString("root_directory", rootDirectory); - } - return __result; - } - - @Override - public boolean equals(Object object) { - if (this == object) { - return true; - } - if (object == null || getClass() != object.getClass()) { - return false; - } - GalleryFragmentArgs that = (GalleryFragmentArgs) object; - if (arguments.containsKey("root_directory") != that.arguments.containsKey("root_directory")) { - return false; - } - if (getRootDirectory() != null ? !getRootDirectory().equals(that.getRootDirectory()) : that.getRootDirectory() != null) { - return false; - } - return true; - } - - @Override - public int hashCode() { - int result = 1; - result = 31 * result + (getRootDirectory() != null ? getRootDirectory().hashCode() : 0); - return result; - } - - @Override - public String toString() { - return "GalleryFragmentArgs{" - + "rootDirectory=" + getRootDirectory() - + "}"; - } - - public static class Builder { private final HashMap arguments = new HashMap(); - public Builder(GalleryFragmentArgs original) { - this.arguments.putAll(original.arguments); - } + private GalleryFragmentArgs() {} - public Builder(@NonNull String rootDirectory) { - if (rootDirectory == null) { - throw new IllegalArgumentException("Argument \"root_directory\" is marked as non-null but was passed a null value."); - } - this.arguments.put("root_directory", rootDirectory); + private GalleryFragmentArgs(HashMap argumentsMap) { + this.arguments.putAll(argumentsMap); } @NonNull - public GalleryFragmentArgs build() { - GalleryFragmentArgs result = new GalleryFragmentArgs(arguments); - return result; + @SuppressWarnings("unchecked") + public static GalleryFragmentArgs fromBundle(@NonNull Bundle bundle) { + GalleryFragmentArgs __result = new GalleryFragmentArgs(); + bundle.setClassLoader(GalleryFragmentArgs.class.getClassLoader()); + if (bundle.containsKey("root_directory")) { + String rootDirectory; + rootDirectory = bundle.getString("root_directory"); + if (rootDirectory == null) { + throw new IllegalArgumentException( + "Argument \"root_directory\" is marked as non-null but was passed a null" + + " value."); + } + __result.arguments.put("root_directory", rootDirectory); + } else { + throw new IllegalArgumentException( + "Required argument \"root_directory\" is missing and does not have an" + + " android:defaultValue"); + } + return __result; } + @SuppressWarnings("unchecked") @NonNull - public Builder setRootDirectory(@NonNull String rootDirectory) { - if (rootDirectory == null) { - throw new IllegalArgumentException("Argument \"root_directory\" is marked as non-null but was passed a null value."); - } - this.arguments.put("root_directory", rootDirectory); - return this; + public String getRootDirectory() { + return (String) arguments.get("root_directory"); } @SuppressWarnings("unchecked") @NonNull - public String getRootDirectory() { - return (String) arguments.get("root_directory"); + public Bundle toBundle() { + Bundle __result = new Bundle(); + if (arguments.containsKey("root_directory")) { + String rootDirectory = (String) arguments.get("root_directory"); + __result.putString("root_directory", rootDirectory); + } + return __result; + } + + @Override + public boolean equals(Object object) { + if (this == object) { + return true; + } + if (object == null || getClass() != object.getClass()) { + return false; + } + GalleryFragmentArgs that = (GalleryFragmentArgs) object; + if (arguments.containsKey("root_directory") + != that.arguments.containsKey("root_directory")) { + return false; + } + if (getRootDirectory() != null + ? !getRootDirectory().equals(that.getRootDirectory()) + : that.getRootDirectory() != null) { + return false; + } + return true; + } + + @Override + public int hashCode() { + int result = 1; + result = 31 * result + (getRootDirectory() != null ? getRootDirectory().hashCode() : 0); + return result; + } + + @Override + public String toString() { + return "GalleryFragmentArgs{" + "rootDirectory=" + getRootDirectory() + "}"; + } + + public static class Builder { + private final HashMap arguments = new HashMap(); + + public Builder(GalleryFragmentArgs original) { + this.arguments.putAll(original.arguments); + } + + public Builder(@NonNull String rootDirectory) { + if (rootDirectory == null) { + throw new IllegalArgumentException( + "Argument \"root_directory\" is marked as non-null but was passed a null" + + " value."); + } + this.arguments.put("root_directory", rootDirectory); + } + + @NonNull + public GalleryFragmentArgs build() { + GalleryFragmentArgs result = new GalleryFragmentArgs(arguments); + return result; + } + + @NonNull + public Builder setRootDirectory(@NonNull String rootDirectory) { + if (rootDirectory == null) { + throw new IllegalArgumentException( + "Argument \"root_directory\" is marked as non-null but was passed a null" + + " value."); + } + this.arguments.put("root_directory", rootDirectory); + return this; + } + + @SuppressWarnings("unchecked") + @NonNull + public String getRootDirectory() { + return (String) arguments.get("root_directory"); + } } - } } diff --git a/CameraXBasic/gen/navigation-args/debug/com/android/example/cameraxbasic/fragments/PermissionsFragmentDirections.java b/CameraXBasic/gen/navigation-args/debug/com/android/example/cameraxbasic/fragments/PermissionsFragmentDirections.java index e9300fb..7b0492e 100644 --- a/CameraXBasic/gen/navigation-args/debug/com/android/example/cameraxbasic/fragments/PermissionsFragmentDirections.java +++ b/CameraXBasic/gen/navigation-args/debug/com/android/example/cameraxbasic/fragments/PermissionsFragmentDirections.java @@ -3,14 +3,14 @@ import androidx.annotation.NonNull; import androidx.navigation.ActionOnlyNavDirections; import androidx.navigation.NavDirections; + import com.android.example.cameraxbasic.R; public class PermissionsFragmentDirections { - private PermissionsFragmentDirections() { - } + private PermissionsFragmentDirections() {} - @NonNull - public static NavDirections actionPermissionsToCamera() { - return new ActionOnlyNavDirections(R.id.action_permissions_to_camera); - } + @NonNull + public static NavDirections actionPermissionsToCamera() { + return new ActionOnlyNavDirections(R.id.action_permissions_to_camera); + } } diff --git a/CameraXBasic/gen/navigation-args/debug/com/android/example/cameraxbasic/fragments/VideoFragmentDirections.java b/CameraXBasic/gen/navigation-args/debug/com/android/example/cameraxbasic/fragments/VideoFragmentDirections.java index 7496348..3200859 100644 --- a/CameraXBasic/gen/navigation-args/debug/com/android/example/cameraxbasic/fragments/VideoFragmentDirections.java +++ b/CameraXBasic/gen/navigation-args/debug/com/android/example/cameraxbasic/fragments/VideoFragmentDirections.java @@ -1,112 +1,119 @@ package com.android.example.cameraxbasic.fragments; import android.os.Bundle; + import androidx.annotation.NonNull; import androidx.navigation.ActionOnlyNavDirections; import androidx.navigation.NavDirections; + import com.android.example.cameraxbasic.R; -import java.lang.IllegalArgumentException; -import java.lang.Object; -import java.lang.Override; -import java.lang.String; -import java.lang.SuppressWarnings; + import java.util.HashMap; public class VideoFragmentDirections { - private VideoFragmentDirections() { - } - - @NonNull - public static ActionVideoToPreview actionVideoToPreview(@NonNull String rootDirectory) { - return new ActionVideoToPreview(rootDirectory); - } - - @NonNull - public static NavDirections actionVideoToPermissions() { - return new ActionOnlyNavDirections(R.id.action_video_to_permissions); - } - - @NonNull - public static NavDirections actionVideoToCamera() { - return new ActionOnlyNavDirections(R.id.action_video_to_camera); - } - - public static class ActionVideoToPreview implements NavDirections { - private final HashMap arguments = new HashMap(); - - private ActionVideoToPreview(@NonNull String rootDirectory) { - if (rootDirectory == null) { - throw new IllegalArgumentException("Argument \"root_directory\" is marked as non-null but was passed a null value."); - } - this.arguments.put("root_directory", rootDirectory); - } + private VideoFragmentDirections() {} @NonNull - public ActionVideoToPreview setRootDirectory(@NonNull String rootDirectory) { - if (rootDirectory == null) { - throw new IllegalArgumentException("Argument \"root_directory\" is marked as non-null but was passed a null value."); - } - this.arguments.put("root_directory", rootDirectory); - return this; + public static ActionVideoToPreview actionVideoToPreview(@NonNull String rootDirectory) { + return new ActionVideoToPreview(rootDirectory); } - @Override - @SuppressWarnings("unchecked") @NonNull - public Bundle getArguments() { - Bundle __result = new Bundle(); - if (arguments.containsKey("root_directory")) { - String rootDirectory = (String) arguments.get("root_directory"); - __result.putString("root_directory", rootDirectory); - } - return __result; + public static NavDirections actionVideoToPermissions() { + return new ActionOnlyNavDirections(R.id.action_video_to_permissions); } - @Override - public int getActionId() { - return R.id.action_video_to_preview; - } - - @SuppressWarnings("unchecked") @NonNull - public String getRootDirectory() { - return (String) arguments.get("root_directory"); + public static NavDirections actionVideoToCamera() { + return new ActionOnlyNavDirections(R.id.action_video_to_camera); } - @Override - public boolean equals(Object object) { - if (this == object) { - return true; - } - if (object == null || getClass() != object.getClass()) { - return false; - } - ActionVideoToPreview that = (ActionVideoToPreview) object; - if (arguments.containsKey("root_directory") != that.arguments.containsKey("root_directory")) { - return false; - } - if (getRootDirectory() != null ? !getRootDirectory().equals(that.getRootDirectory()) : that.getRootDirectory() != null) { - return false; - } - if (getActionId() != that.getActionId()) { - return false; - } - return true; - } + public static class ActionVideoToPreview implements NavDirections { + private final HashMap arguments = new HashMap(); - @Override - public int hashCode() { - int result = 1; - result = 31 * result + (getRootDirectory() != null ? getRootDirectory().hashCode() : 0); - result = 31 * result + getActionId(); - return result; - } + private ActionVideoToPreview(@NonNull String rootDirectory) { + if (rootDirectory == null) { + throw new IllegalArgumentException( + "Argument \"root_directory\" is marked as non-null but was passed a null" + + " value."); + } + this.arguments.put("root_directory", rootDirectory); + } + + @NonNull + public ActionVideoToPreview setRootDirectory(@NonNull String rootDirectory) { + if (rootDirectory == null) { + throw new IllegalArgumentException( + "Argument \"root_directory\" is marked as non-null but was passed a null" + + " value."); + } + this.arguments.put("root_directory", rootDirectory); + return this; + } + + @Override + @SuppressWarnings("unchecked") + @NonNull + public Bundle getArguments() { + Bundle __result = new Bundle(); + if (arguments.containsKey("root_directory")) { + String rootDirectory = (String) arguments.get("root_directory"); + __result.putString("root_directory", rootDirectory); + } + return __result; + } + + @Override + public int getActionId() { + return R.id.action_video_to_preview; + } + + @SuppressWarnings("unchecked") + @NonNull + public String getRootDirectory() { + return (String) arguments.get("root_directory"); + } + + @Override + public boolean equals(Object object) { + if (this == object) { + return true; + } + if (object == null || getClass() != object.getClass()) { + return false; + } + ActionVideoToPreview that = (ActionVideoToPreview) object; + if (arguments.containsKey("root_directory") + != that.arguments.containsKey("root_directory")) { + return false; + } + if (getRootDirectory() != null + ? !getRootDirectory().equals(that.getRootDirectory()) + : that.getRootDirectory() != null) { + return false; + } + if (getActionId() != that.getActionId()) { + return false; + } + return true; + } + + @Override + public int hashCode() { + int result = 1; + result = 31 * result + (getRootDirectory() != null ? getRootDirectory().hashCode() : 0); + result = 31 * result + getActionId(); + return result; + } - @Override - public String toString() { - return "ActionVideoToPreview(actionId=" + getActionId() + "){" - + "rootDirectory=" + getRootDirectory() - + "}"; + @Override + public String toString() { + return "ActionVideoToPreview(actionId=" + + getActionId() + + "){" + + "rootDirectory=" + + getRootDirectory() + + "}"; + } } - } } diff --git a/DirectAudioPlayer/java/com/nxp/directaudioplayer/MainActivity.java b/DirectAudioPlayer/java/com/nxp/directaudioplayer/MainActivity.java index 7068a59..ac9de84 100644 --- a/DirectAudioPlayer/java/com/nxp/directaudioplayer/MainActivity.java +++ b/DirectAudioPlayer/java/com/nxp/directaudioplayer/MainActivity.java @@ -3,17 +3,18 @@ */ package com.nxp.directaudioplayer; +import android.Manifest; import android.app.Activity; import android.content.Context; +import android.content.pm.PackageManager; import android.media.AudioAttributes; import android.media.AudioFormat; import android.media.AudioManager; -import android.media.AudioTrack; import android.media.AudioTimestamp; +import android.media.AudioTrack; import android.os.Bundle; import android.os.Environment; -import android.os.Handler; -import android.os.Message; +import android.support.v4.app.ActivityCompat; import android.support.v4.content.ContextCompat; import android.util.Log; import android.view.View; @@ -22,9 +23,10 @@ import android.widget.CheckBox; import android.widget.CompoundButton; import android.widget.ImageButton; -import android.widget.SeekBar; import android.widget.ListView; +import android.widget.SeekBar; import android.widget.TextView; + import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; @@ -39,13 +41,9 @@ import java.util.Timer; import java.util.TimerTask; -import android.Manifest; -import android.content.pm.PackageManager; -import android.support.v4.app.ActivityCompat; - public class MainActivity extends Activity { int mLPA = 0; - int positionTime=0; + int positionTime = 0; ListView mFileList; TextView mSelectedFfileNameText; String mSelectedFileName; @@ -62,8 +60,8 @@ public class MainActivity extends Activity { private boolean isSeekBarChanging; private static String TAG = "PLAYMUSIC"; - public final static int PERMISSION_REQUESTCODE = 1; - public final static String LPA_ENABLE_PROPERTY = "vendor.audio.lpa.enable"; + public static final int PERMISSION_REQUESTCODE = 1; + public static final String LPA_ENABLE_PROPERTY = "vendor.audio.lpa.enable"; private static final int AUTO_UPDATE_TIMER = 1000; // For 48KHz audio, this buffer can hold 30s data private static final int BUFFER_SIZE = 5760000; @@ -84,8 +82,8 @@ public void onResume() { try { initView(); checkLPAMode(); - }catch (Exception e){ - Log.e(TAG,e.toString()); + } catch (Exception e) { + Log.e(TAG, e.toString()); } } @@ -107,16 +105,21 @@ private void checkLPAMode() { } private void permission() { - if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { + if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) + != PackageManager.PERMISSION_GRANTED) { permissionLists.add(Manifest.permission.READ_EXTERNAL_STORAGE); } - if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { + if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) + != PackageManager.PERMISSION_GRANTED) { permissionLists.add(Manifest.permission.WRITE_EXTERNAL_STORAGE); } if (!permissionLists.isEmpty()) { - ActivityCompat.requestPermissions(this, permissionLists.toArray(new String[permissionLists.size()]), PERMISSION_REQUESTCODE); - }else{ - Log.i(TAG,"permission not allowed"); + ActivityCompat.requestPermissions( + this, + permissionLists.toArray(new String[permissionLists.size()]), + PERMISSION_REQUESTCODE); + } else { + Log.i(TAG, "permission not allowed"); } } @@ -130,34 +133,35 @@ private void initView() { initSeekbar(); imageButton = (ImageButton) findViewById(R.id.bt_media); - imageButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - isPlayOrPause(); - } - }); - - final CheckBox mCheckBox = (CheckBox)findViewById(R.id.checkBox); - mCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener(){ - @Override - public void onCheckedChanged(CompoundButton buttonView, - boolean isChecked) { - if (isChecked){ - isLoopPlay = true; - } else { - isLoopPlay = false; - } - Log.i(TAG, "Loop Playback: " + isLoopPlay); - } - }); + imageButton.setOnClickListener( + new View.OnClickListener() { + @Override + public void onClick(View view) { + isPlayOrPause(); + } + }); + + final CheckBox mCheckBox = (CheckBox) findViewById(R.id.checkBox); + mCheckBox.setOnCheckedChangeListener( + new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + if (isChecked) { + isLoopPlay = true; + } else { + isLoopPlay = false; + } + Log.i(TAG, "Loop Playback: " + isLoopPlay); + } + }); } public void isPlayOrPause() { - int playstate =0; - if(threadPlay.mTrack!=null){ + int playstate = 0; + if (threadPlay.mTrack != null) { playstate = threadPlay.mTrack.getPlayState(); } - if(playstate == 0){ + if (playstate == 0) { Log.i(TAG, "play click"); initSeekbar(); threadPlay.start(); @@ -171,53 +175,57 @@ public void isPlayOrPause() { seekbar.setMax(threadPlay.getDuration()); getProgress(); } - if(playstate== 2){ + if (playstate == 2) { Log.i(TAG, "play click"); threadPlay.mTrack.play(); imageButton.setImageResource(android.R.drawable.ic_media_pause); } - if(playstate== 3){ + if (playstate == 3) { Log.i(TAG, "pause click"); threadPlay.mTrack.pause(); imageButton.setImageResource(android.R.drawable.ic_media_play); } } - private void initSeekbar(){ + private void initSeekbar() { tv_start = (TextView) findViewById(R.id.tv_start); tv_end = (TextView) findViewById(R.id.tv_end); seekbar = (SeekBar) findViewById(R.id.seekbar); - seekbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { - @Override - public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { - tv_start.setText(calculateTime(getCurrentPosition())); - tv_end.setText(calculateTime(threadPlay.getDuration())); - } + seekbar.setOnSeekBarChangeListener( + new SeekBar.OnSeekBarChangeListener() { + @Override + public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { + tv_start.setText(calculateTime(getCurrentPosition())); + tv_end.setText(calculateTime(threadPlay.getDuration())); + } - @Override - public void onStartTrackingTouch(SeekBar seekBar) { - isSeekBarChanging = true; - } + @Override + public void onStartTrackingTouch(SeekBar seekBar) { + isSeekBarChanging = true; + } - @Override - public void onStopTrackingTouch(SeekBar seekBar) { - isSeekBarChanging = false; - tv_start.setText(calculateTime(getCurrentPosition())); - } - }); + @Override + public void onStopTrackingTouch(SeekBar seekBar) { + isSeekBarChanging = false; + tv_start.setText(calculateTime(getCurrentPosition())); + } + }); } private void getProgress() { timer = new Timer(); - timer.schedule(new TimerTask() { - @Override - public void run() { - if(!isSeekBarChanging) { - seekbar.setProgress(getCurrentPosition()); - } - } - },0,50); + timer.schedule( + new TimerTask() { + @Override + public void run() { + if (!isSeekBarChanging) { + seekbar.setProgress(getCurrentPosition()); + } + } + }, + 0, + 50); } class Filter implements FilenameFilter { @@ -229,7 +237,8 @@ public boolean accept(File dir, String name) { private void listFiles() { Filter myfilter = new Filter(); String[] children = mRootdDirectory.list(myfilter); - ArrayAdapter spinnerArrayAdapter = new ArrayAdapter(this, R.layout.file_row, children); + ArrayAdapter spinnerArrayAdapter = + new ArrayAdapter(this, R.layout.file_row, children); mFileList.setAdapter(spinnerArrayAdapter); mFileList.setFocusable(true); mFileList.setFocusableInTouchMode(true); @@ -237,33 +246,35 @@ private void listFiles() { mFileList.setOnItemClickListener(listClick); } - AdapterView.OnItemClickListener listClick = new AdapterView.OnItemClickListener() { - - public void onItemClick(AdapterView adapterView, View view, - int arg2, long arg3) { - long selectedPosition = arg3; - mSelectedFileName = (String) mFileList.getItemAtPosition((int) selectedPosition); - mSelectedFfileNameText.setText("File selected: "+mSelectedFileName); - - while (avoid_RedundantClickCrash){ - if(cnt>0){ - threadPlay.isPlaying = false; - synchronized (threadPlay.mTrack){ - if(threadPlay.mTrack.getPlayState() == AudioTrack.PLAYSTATE_STOPPED){ - initView(); - }else{ - threadPlay.mTrack.pause(); - threadPlay.mTrack.flush(); + AdapterView.OnItemClickListener listClick = + new AdapterView.OnItemClickListener() { + + public void onItemClick(AdapterView adapterView, View view, int arg2, long arg3) { + long selectedPosition = arg3; + mSelectedFileName = + (String) mFileList.getItemAtPosition((int) selectedPosition); + mSelectedFfileNameText.setText("File selected: " + mSelectedFileName); + + while (avoid_RedundantClickCrash) { + if (cnt > 0) { + threadPlay.isPlaying = false; + synchronized (threadPlay.mTrack) { + if (threadPlay.mTrack.getPlayState() + == AudioTrack.PLAYSTATE_STOPPED) { + initView(); + } else { + threadPlay.mTrack.pause(); + threadPlay.mTrack.flush(); + } + } + threadPlay = new ThreadPlay(); } + cnt++; + avoid_RedundantClickCrash = false; } - threadPlay = new ThreadPlay(); + threadPlay.setFile(mSelectedFileName); } - cnt++; - avoid_RedundantClickCrash = false; - } - threadPlay.setFile(mSelectedFileName); - } - }; + }; class ThreadPlay extends Thread { private static final String TAG = "PLAYMUSIC"; @@ -284,80 +295,74 @@ class ThreadPlay extends Thread { public void setFile(String filename) { this.mFileName = filename; } + public void run() { android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_AUDIO); try { - mTempFile = new File(Environment.getExternalStorageDirectory().getAbsoluteFile() + "/" + mFileName); + mTempFile = + new File( + Environment.getExternalStorageDirectory().getAbsoluteFile() + + "/" + + mFileName); } catch (Exception ex) { - Log.e(TAG,"Fail to find the file"); + Log.e(TAG, "Fail to find the file"); } try { minputStream = new FileInputStream(mTempFile); } catch (Exception ex) { - Log.e(TAG,"Fail to transform to inputstream"); + Log.e(TAG, "Fail to transform to inputstream"); } paserWAVheader(); int AudioFmtChn; int AudioFmtBits; - if (chans == 1) - AudioFmtChn = AudioFormat.CHANNEL_OUT_MONO; - else if (chans == 2) - AudioFmtChn = AudioFormat.CHANNEL_OUT_STEREO; - else if (chans == 4) - AudioFmtChn = AudioFormat.CHANNEL_OUT_QUAD; - else if (chans == 6) - AudioFmtChn = AudioFormat.CHANNEL_OUT_5POINT1; - else if (chans == 8) - AudioFmtChn = AudioFormat.CHANNEL_OUT_7POINT1_SURROUND; + if (chans == 1) AudioFmtChn = AudioFormat.CHANNEL_OUT_MONO; + else if (chans == 2) AudioFmtChn = AudioFormat.CHANNEL_OUT_STEREO; + else if (chans == 4) AudioFmtChn = AudioFormat.CHANNEL_OUT_QUAD; + else if (chans == 6) AudioFmtChn = AudioFormat.CHANNEL_OUT_5POINT1; + else if (chans == 8) AudioFmtChn = AudioFormat.CHANNEL_OUT_7POINT1_SURROUND; else { Log.e(TAG, "unsupported channel num " + chans + ", treat as stereo"); return; } - if (bits == 8) - AudioFmtBits = AudioFormat.ENCODING_PCM_8BIT; - else if (bits == 16) - AudioFmtBits = AudioFormat.ENCODING_PCM_16BIT; - else if (bits == 24) - AudioFmtBits = AudioFormat.ENCODING_PCM_FLOAT; - else if (bits == 32) - AudioFmtBits = AudioFormat.ENCODING_PCM_FLOAT; + if (bits == 8) AudioFmtBits = AudioFormat.ENCODING_PCM_8BIT; + else if (bits == 16) AudioFmtBits = AudioFormat.ENCODING_PCM_16BIT; + else if (bits == 24) AudioFmtBits = AudioFormat.ENCODING_PCM_FLOAT; + else if (bits == 32) AudioFmtBits = AudioFormat.ENCODING_PCM_FLOAT; else { Log.e(TAG, "unsupported bits " + bits + ", treat as 16 bits"); return; } - AudioManager mAudioManager = (AudioManager)getSystemService(Context.AUDIO_SERVICE); - if (bits == 16) - mAudioManager.setParameters("pcm_bit=16"); - else if (bits == 24) - mAudioManager.setParameters("pcm_bit=24"); - else if (bits == 32) - mAudioManager.setParameters("pcm_bit=32"); - - if (mLPA == 1) - minBufSize = BUFFER_SIZE; - else - minBufSize = AudioTrack.getMinBufferSize(rate, AudioFmtChn, AudioFmtBits); - Log.e(TAG, "Buffer size: " + minBufSize ); + AudioManager mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); + if (bits == 16) mAudioManager.setParameters("pcm_bit=16"); + else if (bits == 24) mAudioManager.setParameters("pcm_bit=24"); + else if (bits == 32) mAudioManager.setParameters("pcm_bit=32"); + + if (mLPA == 1) minBufSize = BUFFER_SIZE; + else minBufSize = AudioTrack.getMinBufferSize(rate, AudioFmtChn, AudioFmtBits); + Log.e(TAG, "Buffer size: " + minBufSize); mediaBuffer = new byte[minBufSize]; - // For stream rate <= 192000, channels <=2, it can obviously be attached to a mixed output, + // For stream rate <= 192000, channels <=2, it can obviously be attached to a mixed + // output, // AudioPolicyManager will use mixer thread(primary thread) to play them. // In App layer, we can use FLAG_HW_AV_SYNC to explicitly request AudioPolicyManager // to use DirectOutput thread. - mTrack = new AudioTrack( - new AudioAttributes.Builder() - .setFlags(AudioAttributes.FLAG_HW_AV_SYNC) - .setUsage(AudioAttributes.USAGE_MEDIA) - .setContentType(AudioAttributes.CONTENT_TYPE_MUSIC).build(), - new AudioFormat.Builder() - .setSampleRate(rate) - .setEncoding(AudioFmtBits) - .setChannelMask(AudioFmtChn).build(), - minBufSize, - AudioTrack.MODE_STREAM, - AudioManager.AUDIO_SESSION_ID_GENERATE - ); + mTrack = + new AudioTrack( + new AudioAttributes.Builder() + .setFlags(AudioAttributes.FLAG_HW_AV_SYNC) + .setUsage(AudioAttributes.USAGE_MEDIA) + .setContentType(AudioAttributes.CONTENT_TYPE_MUSIC) + .build(), + new AudioFormat.Builder() + .setSampleRate(rate) + .setEncoding(AudioFmtBits) + .setChannelMask(AudioFmtChn) + .build(), + minBufSize, + AudioTrack.MODE_STREAM, + AudioManager.AUDIO_SESSION_ID_GENERATE); mTrack.play(); long totalFeedSize = 0; @@ -365,12 +370,12 @@ else if (bits == 32) while (isPlaying) { int state = mTrack.getPlayState(); - if(state == AudioTrack.PLAYSTATE_STOPPED) { + if (state == AudioTrack.PLAYSTATE_STOPPED) { Log.i(TAG, "PLAYSTATE_STOPPED"); break; } - if(state == AudioTrack.PLAYSTATE_PAUSED) { + if (state == AudioTrack.PLAYSTATE_PAUSED) { Log.v(TAG, "PLAYSTATE_PAUSED"); try { Thread.sleep(10); @@ -395,10 +400,15 @@ else if (bits == 32) try { minputStream.close(); - mTempFile = new File(Environment.getExternalStorageDirectory().getAbsoluteFile() + "/" + mFileName); + mTempFile = + new File( + Environment.getExternalStorageDirectory() + .getAbsoluteFile() + + "/" + + mFileName); minputStream = new FileInputStream(mTempFile); } catch (Exception ex) { - Log.e(TAG,"Fail to find the file"); + Log.e(TAG, "Fail to find the file"); } paserWAVheader(); @@ -414,22 +424,27 @@ else if (bits == 32) int toWrite = read; // In pause stae, mTrack.write may exit with written < read. - while(written < read) { + while (written < read) { if (bits == 24 || bits == 32) { mediaBufferFloat = byteArrayToFloatArray(mediaBuffer); - ret = mTrack.write(mediaBufferFloat, written/4, toWrite/4, AudioTrack.WRITE_BLOCKING); - ret = ret*4; // convert float to byte length + ret = + mTrack.write( + mediaBufferFloat, + written / 4, + toWrite / 4, + AudioTrack.WRITE_BLOCKING); + ret = ret * 4; // convert float to byte length } else { ret = mTrack.write(mediaBuffer, written, toWrite); } - if(ret < 0) { + if (ret < 0) { Log.i(TAG, "write " + toWrite + " bytes failed, ret " + ret + ", break"); break; } written += ret; - if(written < read) { + if (written < read) { toWrite = read - written; try { @@ -443,18 +458,28 @@ else if (bits == 32) totalFeedSize += written; } // while (isPlaying) - if(mLPA == 1) { + if (mLPA == 1) { AudioTimestamp timestamp = new AudioTimestamp(); mTrack.getTimestamp(timestamp); long playedFrame = timestamp.framePosition; - long frameSize = chans*bits/8; - long totalFrame = totalFeedSize/frameSize; + long frameSize = chans * bits / 8; + long totalFrame = totalFeedSize / frameSize; long restFrame = totalFrame - playedFrame; - long restTimeMs = restFrame*1000/rate; - - Log.i(TAG, "Done feeding data, total frames " + totalFrame + ", played frames " + playedFrame + - ", rest frames " + restFrame + ", rest ms " + restTimeMs + ", frame size " + frameSize); + long restTimeMs = restFrame * 1000 / rate; + + Log.i( + TAG, + "Done feeding data, total frames " + + totalFrame + + ", played frames " + + playedFrame + + ", rest frames " + + restFrame + + ", rest ms " + + restTimeMs + + ", frame size " + + frameSize); try { Thread.sleep(restTimeMs); @@ -474,7 +499,7 @@ else if (bits == 32) mTrack.stop(); Log.i(TAG, "mtrack stop in play thread"); mTrack.release(); - Log.i(TAG,"mtrack release in play thread"); + Log.i(TAG, "mtrack release in play thread"); } public float[] byteArrayToFloatArray(byte[] bytes) { @@ -491,7 +516,7 @@ public void paserWAVheader() { byte[] head = new byte[44]; try { read = minputStream.read(head); - Log.i(TAG,"read is "+read); + Log.i(TAG, "read is " + read); } catch (Exception ex) { ex.printStackTrace(); } @@ -505,27 +530,30 @@ public void paserWAVheader() { Log.i(TAG, "error WAVE"); return; } - rate = (int) (head[24] & 0x0FF) + - ((int) (head[24 + 1] & 0x0FF) << 8) + - ((int) (head[24 + 2] & 0x0FF) << 16) + - ((int) (head[24 + 3] & 0x0FF) << 24); + rate = + (int) (head[24] & 0x0FF) + + ((int) (head[24 + 1] & 0x0FF) << 8) + + ((int) (head[24 + 2] & 0x0FF) << 16) + + ((int) (head[24 + 3] & 0x0FF) << 24); bits = head[34]; chans = head[22]; - int byteRate = (int) (head[28] & 0x0FF) + - ((int) (head[28 + 1] & 0x0FF) << 8) + - ((int) (head[28 + 2] & 0x0FF) << 16) + - ((int) (head[28 + 3] & 0x0FF) << 24); - int waveSize = (int) (head[40] & 0x0FF) + - ((int) (head[40 + 1] & 0x0FF) << 8) + - ((int) (head[40 + 2] & 0x0FF) << 16) + - ((int) (head[40 + 3] & 0x0FF) << 24); + int byteRate = + (int) (head[28] & 0x0FF) + + ((int) (head[28 + 1] & 0x0FF) << 8) + + ((int) (head[28 + 2] & 0x0FF) << 16) + + ((int) (head[28 + 3] & 0x0FF) << 24); + int waveSize = + (int) (head[40] & 0x0FF) + + ((int) (head[40 + 1] & 0x0FF) << 8) + + ((int) (head[40 + 2] & 0x0FF) << 16) + + ((int) (head[40 + 3] & 0x0FF) << 24); maxSize = waveSize / byteRate; Log.i(TAG, "The time of the music: " + maxSize + "(s)"); Log.i(TAG, "rate " + rate + ", bits " + bits + ", chans " + chans); } - public int getDuration(){ - return maxSize; + public int getDuration() { + return maxSize; } } @@ -537,37 +565,28 @@ public String calculateTime(int time) { minute = time / 60; second = time % 60; - if(minute>=0&&minute<10) - { - if(second>=0&&second<10) - { - return "0"+minute+":"+"0"+second; - }else - { - return "0"+minute+":"+second; + if (minute >= 0 && minute < 10) { + if (second >= 0 && second < 10) { + return "0" + minute + ":" + "0" + second; + } else { + return "0" + minute + ":" + second; } - }else - { - if(second>=0&&second<10) - { - return minute+":"+"0"+second; - }else - { - return minute+":"+second; + } else { + if (second >= 0 && second < 10) { + return minute + ":" + "0" + second; + } else { + return minute + ":" + second; } } } else if (time < 60) { second = time; - if(second>=0&&second<10) - { - return "00:"+"0"+second; - }else - { + if (second >= 0 && second < 10) { + return "00:" + "0" + second; + } else { return "00:" + second; } - } return null; } @@ -577,11 +596,13 @@ public int getCurrentPosition() { if (threadPlay != null) { if (threadPlay.mTrack != null) { synchronized (threadPlay.mTrack) { - if (threadPlay.mTrack.getPlayState() == 0|| threadPlay.mTrack.getPlayState() == 2|| - threadPlay.mTrack.getPlayState() == 3 ) { - CurrentPosition = threadPlay.mTrack.getPlaybackHeadPosition() / threadPlay.rate; + if (threadPlay.mTrack.getPlayState() == 0 + || threadPlay.mTrack.getPlayState() == 2 + || threadPlay.mTrack.getPlayState() == 3) { + CurrentPosition = + threadPlay.mTrack.getPlaybackHeadPosition() / threadPlay.rate; CurrentPosition %= threadPlay.getDuration(); - }else{ + } else { CurrentPosition = 0; } } diff --git a/Ethernet/app/src/main/java/com/nxp/ethernet/EthernetDevInfo.java b/Ethernet/app/src/main/java/com/nxp/ethernet/EthernetDevInfo.java index ab8960b..100bae8 100644 --- a/Ethernet/app/src/main/java/com/nxp/ethernet/EthernetDevInfo.java +++ b/Ethernet/app/src/main/java/com/nxp/ethernet/EthernetDevInfo.java @@ -17,13 +17,9 @@ package com.nxp.ethernet; public class EthernetDevInfo { - /** - * The ethernet interface is configured by dhcp - */ - public static final String ETHERNET_CONN_MODE_DHCP= "dhcp"; - /** - * The ethernet interface is configured manually - */ + /** The ethernet interface is configured by dhcp */ + public static final String ETHERNET_CONN_MODE_DHCP = "dhcp"; + /** The ethernet interface is configured manually */ public static final String ETHERNET_CONN_MODE_MANUAL = "static"; private String dev_name; @@ -36,7 +32,7 @@ public class EthernetDevInfo { private String proxyExclusionList; private String gateway; - public EthernetDevInfo () { + public EthernetDevInfo() { dev_name = null; ipaddr = null; dns = null; @@ -47,15 +43,14 @@ public EthernetDevInfo () { gateway = null; } - /** - * save interface name into the configuration - */ + /** save interface name into the configuration */ public void setIfName(String ifname) { this.dev_name = ifname; } /** * Returns the interface name from the saved configuration + * * @return interface name */ public String getIfName() { @@ -82,7 +77,7 @@ public void setPrefixLength(String ip) { this.prefixlength = ip; } - public String getPrefixLength( ) { + public String getPrefixLength() { return this.prefixlength; } @@ -119,7 +114,9 @@ public void setProxyExclusionList(String proxyExclusionList) { } /** * Set ethernet configuration mode - * @param mode {@code ETHERNET_CONN_MODE_DHCP} for dhcp {@code ETHERNET_CONN_MODE_MANUAL} for manual configure + * + * @param mode {@code ETHERNET_CONN_MODE_DHCP} for dhcp {@code ETHERNET_CONN_MODE_MANUAL} for + * manual configure */ public void setConnectMode(String mode) { if (mode.equals(ETHERNET_CONN_MODE_DHCP) || mode.equals(ETHERNET_CONN_MODE_MANUAL)) { @@ -130,5 +127,4 @@ public void setConnectMode(String mode) { public String getConnectMode() { return this.mode; } - } diff --git a/Ethernet/app/src/main/java/com/nxp/ethernet/EthernetEnabler.java b/Ethernet/app/src/main/java/com/nxp/ethernet/EthernetEnabler.java index 7582c68..017362c 100644 --- a/Ethernet/app/src/main/java/com/nxp/ethernet/EthernetEnabler.java +++ b/Ethernet/app/src/main/java/com/nxp/ethernet/EthernetEnabler.java @@ -23,12 +23,11 @@ public class EthernetEnabler { private final LocalEthernetManager mLocalEthManager; private EthernetIpDialog mEthConfigDialog; - public void setIpDialog (EthernetIpDialog Dialog) { + public void setIpDialog(EthernetIpDialog Dialog) { mEthConfigDialog = Dialog; } - public void setProxyDialog(EthernetProxyDialog Dialog) { - } + public void setProxyDialog(EthernetProxyDialog Dialog) {} public EthernetEnabler(Context context) { mLocalEthManager = new LocalEthernetManager(context); @@ -39,17 +38,16 @@ public LocalEthernetManager getManager() { return mLocalEthManager; } -// public void resume() { -// } -// -// public void pause() { -// } + // public void resume() { + // } + // + // public void pause() { + // } public void setEthEnabled() { if (!mLocalEthManager.isConfigured()) { mEthConfigDialog.show(); - } else - { + } else { mLocalEthManager.resetInterface(); } } diff --git a/Ethernet/app/src/main/java/com/nxp/ethernet/EthernetIpDialog.java b/Ethernet/app/src/main/java/com/nxp/ethernet/EthernetIpDialog.java index d0e6523..dad5c8c 100644 --- a/Ethernet/app/src/main/java/com/nxp/ethernet/EthernetIpDialog.java +++ b/Ethernet/app/src/main/java/com/nxp/ethernet/EthernetIpDialog.java @@ -29,8 +29,10 @@ import android.widget.TextView; import android.widget.Toast; -public class EthernetIpDialog extends AlertDialog implements - DialogInterface.OnClickListener, AdapterView.OnItemSelectedListener, View.OnClickListener { +public class EthernetIpDialog extends AlertDialog + implements DialogInterface.OnClickListener, + AdapterView.OnItemSelectedListener, + View.OnClickListener { private final String TAG = "EthernetIpSetting"; private static final boolean DBG = true; private final EthernetEnabler mEthEnabler; @@ -47,6 +49,7 @@ public EthernetIpDialog(Context context, EthernetEnabler Enabler) { mEthEnabler = Enabler; buildDialogContent(context); } + public void buildDialogContent(Context context) { this.setTitle(R.string.eth_config_title); View mView; @@ -71,10 +74,18 @@ public void buildDialogContent(Context context) { mConTypeDhcp.setChecked(false); mConTypeManual.setChecked(true); ip_dns_setting.setVisibility(View.VISIBLE); - mIpaddr.setText(mEthEnabler.getManager().getSharedPreIpAddress(),TextView.BufferType.EDITABLE); - mDns.setText(mEthEnabler.getManager().getSharedPreDnsAddress(),TextView.BufferType.EDITABLE); - mPrefixLength.setText(mEthEnabler.getManager().getSharedPrefixLength(),TextView.BufferType.EDITABLE); - mGateway.setText(mEthEnabler.getManager().getSharedPreGateway(),TextView.BufferType.EDITABLE); + mIpaddr.setText( + mEthEnabler.getManager().getSharedPreIpAddress(), + TextView.BufferType.EDITABLE); + mDns.setText( + mEthEnabler.getManager().getSharedPreDnsAddress(), + TextView.BufferType.EDITABLE); + mPrefixLength.setText( + mEthEnabler.getManager().getSharedPrefixLength(), + TextView.BufferType.EDITABLE); + mGateway.setText( + mEthEnabler.getManager().getSharedPreGateway(), + TextView.BufferType.EDITABLE); } } else { mConTypeDhcp.setChecked(true); @@ -90,8 +101,7 @@ public void buildDialogContent(Context context) { this.setButton(BUTTON_NEGATIVE, context.getText(R.string.menu_cancel), this); String[] Devs = mEthEnabler.getManager().getDeviceNameList(); if (Devs != null) { - if (DBG) - Log.d(TAG, "found device: " + Devs[0]); + if (DBG) Log.d(TAG, "found device: " + Devs[0]); updateDevNameList(Devs); } } @@ -99,12 +109,13 @@ public void buildDialogContent(Context context) { public void saveconf() { EthernetDevInfo info = new EthernetDevInfo(); info.setIfName(mDevList.getSelectedItem().toString()); - if (DBG) - Log.d(TAG, "Config device for " + mDevList.getSelectedItem().toString()); + if (DBG) Log.d(TAG, "Config device for " + mDevList.getSelectedItem().toString()); if (mConTypeManual.isChecked()) { - if ((mIpaddr.getText().toString().equals("")) || (mPrefixLength.getText().toString().equals("")) || - mGateway.getText().toString().equals("")) { - Toast.makeText(this.getContext(), R.string.show_need_setting,Toast.LENGTH_SHORT).show(); + if ((mIpaddr.getText().toString().equals("")) + || (mPrefixLength.getText().toString().equals("")) + || mGateway.getText().toString().equals("")) { + Toast.makeText(this.getContext(), R.string.show_need_setting, Toast.LENGTH_SHORT) + .show(); return; } else { info.setConnectMode(EthernetDevInfo.ETHERNET_CONN_MODE_MANUAL); @@ -119,27 +130,28 @@ public void saveconf() { info.setDnsAddr(null); } -// info.setProxyAddr(mEthEnabler.getManager().getSharedPreProxyAddress()); -// info.setProxyPort(mEthEnabler.getManager().getSharedPreProxyPort()); -// info.setProxyExclusionList(mEthEnabler.getManager().getSharedPreProxyExclusionList()); + // info.setProxyAddr(mEthEnabler.getManager().getSharedPreProxyAddress()); + // info.setProxyPort(mEthEnabler.getManager().getSharedPreProxyPort()); + // + // info.setProxyExclusionList(mEthEnabler.getManager().getSharedPreProxyExclusionList()); mEthEnabler.getManager().updateDevInfo(info); mEthEnabler.setEthEnabled(); - //configHandler.post(new ConfigHandler(info)); + // configHandler.post(new ConfigHandler(info)); } -// class ConfigHandler implements Runnable { -// EthernetDevInfo info; -// -// public ConfigHandler(EthernetDevInfo info) { -// this.info = info; -// } -// -// public void run() { -// mEthEnabler.getManager().updateDevInfo(info); -// mEthEnabler.setEthEnabled(); -// } -// } + // class ConfigHandler implements Runnable { + // EthernetDevInfo info; + // + // public ConfigHandler(EthernetDevInfo info) { + // this.info = info; + // } + // + // public void run() { + // mEthEnabler.getManager().updateDevInfo(info); + // mEthEnabler.setEthEnabled(); + // } + // } public void onClick(DialogInterface dialog, int which) { switch (which) { @@ -150,27 +162,22 @@ public void onClick(DialogInterface dialog, int which) { dialog.cancel(); break; default: - Log.e(TAG,"Unknown button"); + Log.e(TAG, "Unknown button"); } } - public void onItemSelected(AdapterView parent, View view, int position, long id) { - } + public void onItemSelected(AdapterView parent, View view, int position, long id) {} - public void onNothingSelected(AdapterView parent) { - } + public void onNothingSelected(AdapterView parent) {} - public void onClick(View v) { - } + public void onClick(View v) {} public void updateDevNameList(String[] DevList) { if (DevList != null) { - ArrayAdapter adapter = new ArrayAdapter<>( - getContext(), android.R.layout.simple_spinner_item, DevList); - adapter.setDropDownViewResource( - android.R.layout.simple_spinner_dropdown_item); + ArrayAdapter adapter = + new ArrayAdapter<>(getContext(), android.R.layout.simple_spinner_item, DevList); + adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); mDevList.setAdapter(adapter); } } } - diff --git a/Ethernet/app/src/main/java/com/nxp/ethernet/EthernetProxyDialog.java b/Ethernet/app/src/main/java/com/nxp/ethernet/EthernetProxyDialog.java index ee2eb3d..0e4e4a3 100644 --- a/Ethernet/app/src/main/java/com/nxp/ethernet/EthernetProxyDialog.java +++ b/Ethernet/app/src/main/java/com/nxp/ethernet/EthernetProxyDialog.java @@ -26,7 +26,8 @@ import android.widget.TextView; import android.widget.Toast; -public class EthernetProxyDialog extends AlertDialog implements DialogInterface.OnClickListener, View.OnClickListener { +public class EthernetProxyDialog extends AlertDialog + implements DialogInterface.OnClickListener, View.OnClickListener { private final String TAG = "EthernetProxyDialog"; private final EthernetEnabler mEthEnabler; @@ -52,24 +53,28 @@ public void buildDialogContent(Context context) { mProxyExclusionList = (EditText) mView.findViewById(R.id.proxy_exclusionlist); mProxyEnableCheckBox = (CheckBox) mView.findViewById(R.id.proxy_enable_checkbox); mConfigWindow = (LinearLayout) mView.findViewById(R.id.enterprise_wrapper); - mProxyEnableCheckBox.setOnCheckedChangeListener((buttonView, isChecked) -> { - if (isChecked) { - mConfigWindow.setVisibility(View.VISIBLE); - } else { - mConfigWindow.setVisibility(View.GONE); - } - mProxyIp.setEnabled(isChecked); - mProxyPort.setEnabled(isChecked); - mProxyExclusionList.setEnabled(isChecked); - }); - + mProxyEnableCheckBox.setOnCheckedChangeListener( + (buttonView, isChecked) -> { + if (isChecked) { + mConfigWindow.setVisibility(View.VISIBLE); + } else { + mConfigWindow.setVisibility(View.GONE); + } + mProxyIp.setEnabled(isChecked); + mProxyPort.setEnabled(isChecked); + mProxyExclusionList.setEnabled(isChecked); + }); this.setInverseBackgroundForced(true); this.setButton(BUTTON_POSITIVE, context.getText(R.string.menu_save), this); this.setButton(BUTTON_NEGATIVE, context.getText(R.string.menu_cancel), this); - mProxyIp.setText(mEthEnabler.getManager().getSharedPreProxyAddress(), TextView.BufferType.EDITABLE); - mProxyPort.setText(mEthEnabler.getManager().getSharedPreProxyPort(), TextView.BufferType.EDITABLE); - mProxyExclusionList.setText(mEthEnabler.getManager().getSharedPreProxyExclusionList(), TextView.BufferType.EDITABLE); + mProxyIp.setText( + mEthEnabler.getManager().getSharedPreProxyAddress(), TextView.BufferType.EDITABLE); + mProxyPort.setText( + mEthEnabler.getManager().getSharedPreProxyPort(), TextView.BufferType.EDITABLE); + mProxyExclusionList.setText( + mEthEnabler.getManager().getSharedPreProxyExclusionList(), + TextView.BufferType.EDITABLE); if (mEthEnabler.getManager().getSharedPreProxyAddress() == null) { mProxyEnableCheckBox.setChecked(false); mConfigWindow.setVisibility(View.GONE); @@ -104,7 +109,8 @@ public void saveconf() { mEthEnabler.getManager().updateDevInfo(info); mEthEnabler.getManager().setProxy(); } else { - Toast.makeText(this.getContext(), R.string.show_connect_ethernet, Toast.LENGTH_SHORT).show(); + Toast.makeText(this.getContext(), R.string.show_connect_ethernet, Toast.LENGTH_SHORT) + .show(); } } diff --git a/Ethernet/app/src/main/java/com/nxp/ethernet/LocalEthernetManager.java b/Ethernet/app/src/main/java/com/nxp/ethernet/LocalEthernetManager.java index 54792bd..b67446d 100644 --- a/Ethernet/app/src/main/java/com/nxp/ethernet/LocalEthernetManager.java +++ b/Ethernet/app/src/main/java/com/nxp/ethernet/LocalEthernetManager.java @@ -33,16 +33,15 @@ import android.text.TextUtils; import android.util.Log; import android.widget.Toast; + import com.android.net.module.util.ProxyUtils; import java.net.Inet4Address; import java.net.InetAddress; -import java.net.UnknownHostException; import java.util.ArrayList; import java.util.regex.Matcher; import java.util.regex.Pattern; - public class LocalEthernetManager { public static final String TAG = "LocalEthernetManager"; @@ -77,11 +76,11 @@ public LocalEthernetManager(Context context) { mConnMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); mEthernetManager = (EthernetManager) context.getSystemService(EthernetManager.class); - } /** * check if the ethernet service has been configured. + * * @return {@code true} if configured {@code false} otherwise */ public boolean isConfigured() { @@ -90,11 +89,11 @@ public boolean isConfigured() { /** * Return the saved ethernet configuration + * * @return ethernet interface configuration on success, {@code null} on failure */ public synchronized EthernetDevInfo getSavedConfig() { - if (!isConfigured()) - return null; + if (!isConfigured()) return null; EthernetDevInfo info = new EthernetDevInfo(); info.setConnectMode(getSharedPreMode()); info.setIfName(DevName[0]); @@ -136,7 +135,7 @@ void configureInterface(EthernetDevInfo info) { String ipAddr = info.getIpAddress(); if (TextUtils.isEmpty(ipAddr)) { - Log.d(TAG,"Static IP configuration failed with empty IP address"); + Log.d(TAG, "Static IP configuration failed with empty IP address"); } Log.d(TAG, "---------Static IP address =" + ipAddr); @@ -147,24 +146,25 @@ void configureInterface(EthernetDevInfo info) { inetAddr = (Inet4Address) InetAddresses.parseNumericAddress(ipAddr); // inetAddress = InetAddresses.parseNumericAddress(ipAddr); } catch (IllegalArgumentException | ClassCastException e) { - Log.d(TAG,"Static IP configuration failed with address parse error"); + Log.d(TAG, "Static IP configuration failed with address parse error"); } if (inetAddr == null || inetAddr.equals(Inet4Address.ANY)) { - Log.d(TAG,"Static IP configuration failed with inetAddr error"); + Log.d(TAG, "Static IP configuration failed with inetAddr error"); } try { int networkPrefixLength = Integer.parseInt(info.getPrefixLength()); - Log.d(TAG,"--------networkPrefixLength =" + networkPrefixLength); + Log.d(TAG, "--------networkPrefixLength =" + networkPrefixLength); if (networkPrefixLength < 0 || networkPrefixLength > 32) { - Log.d(TAG,"Static IP configuration failed with PrefixLength parse error"); + Log.d(TAG, "Static IP configuration failed with PrefixLength parse error"); } staticIpBuilder.setIpAddress(new LinkAddress(inetAddr, networkPrefixLength)); - // staticIpBuilder.setIpAddress(new LinkAddress(inetAddress, networkPrefixLength)); + // staticIpBuilder.setIpAddress(new LinkAddress(inetAddress, + // networkPrefixLength)); } catch (NumberFormatException e) { - Log.d(TAG,"Static IP configuration failed with ipaddress set error"); + Log.d(TAG, "Static IP configuration failed with ipaddress set error"); } String gateway = info.getGateway(); @@ -172,7 +172,7 @@ void configureInterface(EthernetDevInfo info) { try { staticIpBuilder.setGateway(InetAddresses.parseNumericAddress(gateway)); } catch (IllegalArgumentException | ClassCastException e) { - Log.d(TAG,"Static IP configuration failed with gateway set error"); + Log.d(TAG, "Static IP configuration failed with gateway set error"); } } @@ -182,22 +182,30 @@ void configureInterface(EthernetDevInfo info) { try { dnsServers.add(InetAddresses.parseNumericAddress(dns1)); } catch (IllegalArgumentException | ClassCastException e) { - Log.d(TAG,"Static IP configuration failed with dns error"); + Log.d(TAG, "Static IP configuration failed with dns error"); } } staticIpBuilder.setDnsServers(dnsServers); mIpConfiguration.setStaticIpConfiguration(staticIpBuilder.build()); mEthernetManager.setConfiguration(DevName[0], mIpConfiguration); - Log.d(TAG,"Static IP configuration succeeded"); + Log.d(TAG, "Static IP configuration succeeded"); } catch (IllegalStateException e) { - Log.e(TAG,"Static IP configuration failed with IllegalStateException: " + e); + Log.e(TAG, "Static IP configuration failed with IllegalStateException: " + e); } catch (IllegalArgumentException e) { - Log.e(TAG,"Wrong Static IP: " + e); - Toast.makeText(mContext, "Illegal address inputted. You can not access the Internet.",Toast.LENGTH_SHORT).show(); + Log.e(TAG, "Wrong Static IP: " + e); + Toast.makeText( + mContext, + "Illegal address inputted. You can not access the Internet.", + Toast.LENGTH_SHORT) + .show(); } catch (Exception err) { Log.e(TAG, "Exception in setting Static IP"); - Toast.makeText(mContext, "We got exception when set the static IP.",Toast.LENGTH_SHORT).show(); + Toast.makeText( + mContext, + "We got exception when set the static IP.", + Toast.LENGTH_SHORT) + .show(); } Log.d(TAG, "set ip manually " + info.toString()); updateDevInfo(info); @@ -206,7 +214,7 @@ void configureInterface(EthernetDevInfo info) { public EthernetDevInfo getDhcpInfo() { EthernetDevInfo ethinfo = new EthernetDevInfo(); - String [] DevName = getDeviceNameList(); + String[] DevName = getDeviceNameList(); ethinfo.setIfName(DevName[0]); ethinfo.setConnectMode(EthernetDevInfo.ETHERNET_CONN_MODE_DHCP); String ip; @@ -217,23 +225,22 @@ public EthernetDevInfo getDhcpInfo() { ip = "[]"; Log.w(TAG, "get Dhcp Info error:" + err.toString()); } - if (!ip.equals("[]")) - ethinfo.setIpAddress(ip.substring(2, ip.length()-1)); + if (!ip.equals("[]")) ethinfo.setIpAddress(ip.substring(2, ip.length() - 1)); String dns = " "; try { Network network = mConnMgr.getActiveNetwork(); - for( InetAddress d : mConnMgr.getLinkProperties(network).getDnsServers()) { + for (InetAddress d : mConnMgr.getLinkProperties(network).getDnsServers()) { String temp = d.toString(); - dns = temp.substring(1, temp.length()-1); + dns = temp.substring(1, temp.length() - 1); break; } } catch (Exception err) { Log.w(TAG, "get Dhcp Info error:" + err.toString()); } - ethinfo.setDnsAddr(dns);// now only use dns1, need optimization later here. + ethinfo.setDnsAddr(dns); // now only use dns1, need optimization later here. String proxyAddress = getSharedPreProxyAddress(); String proxyPort = getSharedPreProxyPort(); - String proxyExclusionList=getSharedPreProxyExclusionList(); + String proxyExclusionList = getSharedPreProxyExclusionList(); ethinfo.setProxyAddr(proxyAddress); ethinfo.setProxyPort(proxyPort); ethinfo.setProxyExclusionList(proxyExclusionList); @@ -248,76 +255,75 @@ public void resetInterface() { if (info != null && isConfigured()) { configureInterface(info); } else { - //First boot using AOSP dhcp + // First boot using AOSP dhcp updateDevInfo(getDhcpInfo()); } } /** * update a ethernet interface information - * @param info the interface infomation + * + * @param info the interface infomation */ public synchronized void updateDevInfo(EthernetDevInfo info) { sharedPreferencesStore(info); } - public SharedPreferences sharedPreferences(){ - return this.mContext.getSharedPreferences("ethernet", - Context.MODE_PRIVATE); + public SharedPreferences sharedPreferences() { + return this.mContext.getSharedPreferences("ethernet", Context.MODE_PRIVATE); } - public void sharedPreferencesStore(EthernetDevInfo info){ + public void sharedPreferencesStore(EthernetDevInfo info) { Editor editor = sharedPreferences().edit(); try { - editor.putString("conn_mode",info.getConnectMode()); - editor.putString("mIpaddr",info.getIpAddress()); - editor.putString("mDns",info.getDnsAddr()); + editor.putString("conn_mode", info.getConnectMode()); + editor.putString("mIpaddr", info.getIpAddress()); + editor.putString("mDns", info.getDnsAddr()); editor.putString("mGateway", info.getGateway()); editor.putString("mPrefixLength", info.getPrefixLength()); - editor.putString("mProxyIp",info.getProxyAddr()); + editor.putString("mProxyIp", info.getProxyAddr()); editor.putString("mProxyPort", info.getProxyPort()); editor.putString("mProxyExclusionList", info.getProxyExclusionList()); } catch (NumberFormatException e) { e.printStackTrace(); } editor.apply(); - } - public String getSharedPreMode(){ + public String getSharedPreMode() { String temp = null; try { - temp = sharedPreferences().getString("conn_mode",null); + temp = sharedPreferences().getString("conn_mode", null); } catch (Exception e) { e.printStackTrace(); } return temp; } - public String getSharedPreIpAddress(){ + public String getSharedPreIpAddress() { String temp = null; try { - temp = sharedPreferences().getString("mIpaddr",null); + temp = sharedPreferences().getString("mIpaddr", null); } catch (Exception e) { e.printStackTrace(); } return temp; } - public String getSharedPreDnsAddress(){ + public String getSharedPreDnsAddress() { String temp = null; try { - temp = sharedPreferences().getString("mDns",null); + temp = sharedPreferences().getString("mDns", null); } catch (Exception e) { e.printStackTrace(); } return temp; } - public String getSharedPreGateway(){ + public String getSharedPreGateway() { String temp = null; try { - temp = sharedPreferences().getString("mGateway",null); + temp = sharedPreferences().getString("mGateway", null); } catch (Exception e) { e.printStackTrace(); } @@ -327,37 +333,37 @@ public String getSharedPreGateway(){ public String getSharedPrefixLength() { String temp = null; try { - temp = sharedPreferences().getString("mPrefixLength",null); + temp = sharedPreferences().getString("mPrefixLength", null); } catch (Exception e) { e.printStackTrace(); } return temp; } - public String getSharedPreProxyAddress(){ + public String getSharedPreProxyAddress() { String temp = null; try { - temp = sharedPreferences().getString("mProxyIp",null); + temp = sharedPreferences().getString("mProxyIp", null); } catch (Exception e) { e.printStackTrace(); } return temp; } - public String getSharedPreProxyPort(){ + public String getSharedPreProxyPort() { String temp = null; try { - temp = sharedPreferences().getString("mProxyPort",null); + temp = sharedPreferences().getString("mProxyPort", null); } catch (Exception e) { e.printStackTrace(); } return temp; } - public String getSharedPreProxyExclusionList(){ + public String getSharedPreProxyExclusionList() { String temp = null; try { - temp = sharedPreferences().getString("mProxyExclusionList",null); + temp = sharedPreferences().getString("mProxyExclusionList", null); } catch (Exception e) { e.printStackTrace(); } @@ -401,7 +407,7 @@ public static int validate(String hostname, String port, String exclList) { return 0; } - public void setProxy(){ + public void setProxy() { IpConfiguration mIpConfiguration = new IpConfiguration(); boolean hasProxySettings = true; @@ -409,14 +415,15 @@ public void setProxy(){ hasProxySettings = false; } - mIpConfiguration.setProxySettings(hasProxySettings - ? IpConfiguration.ProxySettings.STATIC : IpConfiguration.ProxySettings.NONE); + mIpConfiguration.setProxySettings( + hasProxySettings + ? IpConfiguration.ProxySettings.STATIC + : IpConfiguration.ProxySettings.NONE); if (hasProxySettings) { Network network = mConnMgr.getActiveNetwork(); LinkProperties lp = mConnMgr.getLinkProperties(network); - if (lp == null) - return; + if (lp == null) return; int port = 0; String exclusionList = null; @@ -431,15 +438,16 @@ public void setProxy(){ result = -1; } if (result == 0) { - mIpConfiguration.setHttpProxy(ProxyInfo.buildDirectProxy(host, port, - ProxyUtils.exclusionStringAsList(exclusionList))); + mIpConfiguration.setHttpProxy( + ProxyInfo.buildDirectProxy( + host, port, ProxyUtils.exclusionStringAsList(exclusionList))); } } else { mIpConfiguration.setHttpProxy(null); } } - public boolean isEthernetConnect(){ + public boolean isEthernetConnect() { NetworkInfo networkInfo = mConnMgr.getActiveNetworkInfo(); if (networkInfo == null) { return false; diff --git a/Ethernet/app/src/main/java/com/nxp/ethernet/MainActivity.java b/Ethernet/app/src/main/java/com/nxp/ethernet/MainActivity.java index 0e861d8..5b3b186 100644 --- a/Ethernet/app/src/main/java/com/nxp/ethernet/MainActivity.java +++ b/Ethernet/app/src/main/java/com/nxp/ethernet/MainActivity.java @@ -40,7 +40,7 @@ public class MainActivity extends Activity { private final String TAG = "EthernetMainActivity"; - private EthernetDevInfo mSaveConfig; + private EthernetDevInfo mSaveConfig; private EthernetProxyDialog mEthernetProxyDialog; private EthernetEnabler mEthEnabler; private EthernetIpDialog mEthIpConfigDialog; @@ -49,13 +49,14 @@ public class MainActivity extends Activity { private int mNetworkType; private ConnectivityManager mConnectivityManager; - private final BroadcastReceiver mEthernetReceiver = new BroadcastReceiver() { + private final BroadcastReceiver mEthernetReceiver = + new BroadcastReceiver() { - public void onReceive(Context context, Intent intent) { - updateConnectivityStatus(); - updateConnectivity(); - } - }; + public void onReceive(Context context, Intent intent) { + updateConnectivityStatus(); + updateConnectivity(); + } + }; private void updateConnectivityStatus() { NetworkInfo networkInfo = mConnectivityManager.getActiveNetworkInfo(); @@ -70,9 +71,7 @@ private void updateConnectivityStatus() { } } - /** - * Return whether Ethernet port is available. - */ + /** Return whether Ethernet port is available. */ public boolean isEthernetAvailable() { return getPackageManager().hasSystemFeature(PackageManager.FEATURE_ETHERNET) && mEthernetManager.getAvailableInterfaces().length > 0; @@ -107,10 +106,7 @@ private Network getFirstEthernet() { return null; } - /** - * Returns the formatted IP addresses of the Ethernet connection or null - * if none available. - */ + /** Returns the formatted IP addresses of the Ethernet connection or null if none available. */ public String getEthernetIpAddress() { final Network network = getFirstEthernet(); if (network == null) { @@ -144,8 +140,10 @@ private String formatIpAddresses(Network network) { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); - this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, - WindowManager.LayoutParams.FLAG_FULLSCREEN); + this.getWindow() + .setFlags( + WindowManager.LayoutParams.FLAG_FULLSCREEN, + WindowManager.LayoutParams.FLAG_FULLSCREEN); setContentView(R.layout.ethernet_configure); mEthernetManager = (EthernetManager) getSystemService(EthernetManager.class); @@ -163,21 +161,23 @@ protected void onCreate(Bundle savedInstanceState) { mBtnCheck.setOnClickListener(v -> updateConnectivity()); - mBtnIPConfig.setOnClickListener(v -> { - mEthIpConfigDialog = new EthernetIpDialog(MainActivity.this, mEthEnabler); - mEthEnabler.setIpDialog(mEthIpConfigDialog); - mEthIpConfigDialog.show(); - }); - - mBtnProxyConfig.setOnClickListener(v -> { - mSaveConfig = mEthEnabler.getManager().getSavedConfig(); - if (mSaveConfig != null) { - mEthernetProxyDialog = new EthernetProxyDialog(MainActivity.this,mEthEnabler); - mEthEnabler.setProxyDialog(mEthernetProxyDialog); - mEthernetProxyDialog.show(); - } - }); - + mBtnIPConfig.setOnClickListener( + v -> { + mEthIpConfigDialog = new EthernetIpDialog(MainActivity.this, mEthEnabler); + mEthEnabler.setIpDialog(mEthIpConfigDialog); + mEthIpConfigDialog.show(); + }); + + mBtnProxyConfig.setOnClickListener( + v -> { + mSaveConfig = mEthEnabler.getManager().getSavedConfig(); + if (mSaveConfig != null) { + mEthernetProxyDialog = + new EthernetProxyDialog(MainActivity.this, mEthEnabler); + mEthEnabler.setProxyDialog(mEthernetProxyDialog); + mEthernetProxyDialog.show(); + } + }); } @Override diff --git a/FSLOta/src/com/fsl/android/ota/BuildPropParser.java b/FSLOta/src/com/fsl/android/ota/BuildPropParser.java index 4f85d44..564fa8e 100644 --- a/FSLOta/src/com/fsl/android/ota/BuildPropParser.java +++ b/FSLOta/src/com/fsl/android/ota/BuildPropParser.java @@ -16,47 +16,48 @@ package com.fsl.android.ota; -import java.io.*; -import java.util.*; - import android.content.Context; import android.util.Log; +import java.io.*; +import java.util.*; + public class BuildPropParser { private HashMap propHM = null; File tmpFile; Context mContext; - + final String TAG = "OTA"; BuildPropParser(ByteArrayOutputStream out, Context context) { - mContext = context; + mContext = context; propHM = new HashMap(); setByteArrayStream(out); } BuildPropParser(File file, Context context) throws IOException { - mContext = context; + mContext = context; propHM = new HashMap(); setFile(file); } - public HashMap getPropMap() { return propHM;}; - public String getProp(String propname) { - if (propHM != null) - return (String) propHM.get(propname); - else - return null; + public HashMap getPropMap() { + return propHM; + } + ; + + public String getProp(String propname) { + if (propHM != null) return (String) propHM.get(propname); + else return null; } private void setByteArrayStream(ByteArrayOutputStream out) { try { - File tmpDir = null; - if (mContext != null) - tmpDir = mContext.getFilesDir(); - Log.d(TAG, "tmpDir:" + tmpDir.toString() + "\n"); + File tmpDir = null; + if (mContext != null) tmpDir = mContext.getFilesDir(); + Log.d(TAG, "tmpDir:" + tmpDir.toString() + "\n"); tmpFile = File.createTempFile("buildprop", "ss", tmpDir); - + tmpFile.deleteOnExit(); FileOutputStream o2 = new FileOutputStream(tmpFile); out.writeTo(o2); @@ -88,19 +89,14 @@ private void setFile(File file) throws IOException { throw e; } } - - public String getRelease() { - if (propHM != null) - return propHM.get("ro.build.version.release"); - else - return null; - } - public String getNumRelease() { - if (propHM != null) - return propHM.get("ro.build.version.incremental"); - else - return null; - } + public String getRelease() { + if (propHM != null) return propHM.get("ro.build.version.release"); + else return null; + } + public String getNumRelease() { + if (propHM != null) return propHM.get("ro.build.version.incremental"); + else return null; + } } diff --git a/FSLOta/src/com/fsl/android/ota/OTAServerConfig.java b/FSLOta/src/com/fsl/android/ota/OTAServerConfig.java index 2e141d2..68d49b3 100644 --- a/FSLOta/src/com/fsl/android/ota/OTAServerConfig.java +++ b/FSLOta/src/com/fsl/android/ota/OTAServerConfig.java @@ -16,145 +16,140 @@ package com.fsl.android.ota; +import android.os.Build; import android.os.SystemProperties; +import android.util.Log; + import java.io.File; import java.net.MalformedURLException; import java.net.URL; -import java.io.BufferedReader; -import java.io.FileReader; -import java.io.IOException; - -import android.util.Log; -import android.os.Build; // TODO: get the configure from a configure file. public class OTAServerConfig { - - final String default_serveraddr = "10.193.108.180"; - final String default_protocol = "http"; - final int default_port = 10888; - URL updatePackageURL; - URL buildpropURL; - URL diffbuildpropURL; - URL payloadPropertiesURL; - URL payloadURL; - URL diffPayloadPropertiesURL; - URL diffPayloadURL; - boolean ab_slot = false; - boolean is_diff_upgrade = false; - String product; - final String TAG = "OTA"; - final String configFile = "/vendor/etc/ota.conf"; - final String server_ip_config = "server"; - final String port_config_str = "port"; - final String android_nickname = "ota_folder_suffix"; - public OTAServerConfig (String productname) throws MalformedURLException { - if (loadConfigureFromFile(configFile, productname) == false) - defaultConfigure(productname); - } - - boolean loadConfigureFromFile (String configFile, String product) { - try { - BuildPropParser parser = new BuildPropParser(new File(configFile), null); - String server = parser.getProp(server_ip_config); - String port_str = parser.getProp(port_config_str); - String android_name = parser.getProp(android_nickname); - String version_incremental = Build.VERSION.INCREMENTAL; - int port = new Long(port_str).intValue(); - String ota_folder; - String fileaddr; - String buildconfigAddr; - String diffbuildconfigAddr; - String payloadPropertiesAddr; - String payloadAddr; - String diffPayloadPropertiesAddr; - String diffPayloadAddr; - - String version = SystemProperties.get("ro.build.version.release"); - String platform = SystemProperties.get("ro.board.platform"); - ota_folder = new String(product + "_" + android_name + "_" + version + "/"); - fileaddr = new String(ota_folder + product + "-ota-" + version_incremental + ".zip"); - buildconfigAddr = new String(ota_folder + "build.prop"); - diffbuildconfigAddr = new String(ota_folder + "build_diff.prop"); - payloadPropertiesAddr = new String(ota_folder + "payload_properties.txt"); - diffPayloadPropertiesAddr = new String(ota_folder + "payload_properties_diff.txt"); - payloadAddr = new String(ota_folder + "payload.bin"); - diffPayloadAddr = new String(ota_folder + "payload_diff.bin"); - if (platform.indexOf("imx8") != -1) { - ab_slot = true; - } - - buildpropURL = new URL(default_protocol, server, port, buildconfigAddr); - if (!ab_slot) { - updatePackageURL = new URL(default_protocol, server, port, fileaddr); - Log.d(TAG, "ota package: " + updatePackageURL.toString()); - } else { - payloadPropertiesURL = new URL(default_protocol, server, port, payloadPropertiesAddr); - payloadURL = new URL(default_protocol, server, port, payloadAddr); - diffbuildpropURL = new URL(default_protocol, server, port, diffbuildconfigAddr); - diffPayloadPropertiesURL = new URL(default_protocol, server, port, diffPayloadPropertiesAddr); - diffPayloadURL = new URL(default_protocol, server, port, diffPayloadAddr); - Log.d(TAG, "build.prop: " + buildpropURL.toString()); - Log.d(TAG, "payload.bin: " + payloadURL.toString()); - Log.d(TAG, "payload_properties.txt" + payloadPropertiesURL.toString()); - } - } catch (Exception e) { - Log.e(TAG, "wrong format/error of OTA configure file."); - e.printStackTrace(); - return false; - } - - return true; - } - - void defaultConfigure(String productname) throws MalformedURLException - { - product = productname; - String fileaddr = new String(product + "/" + product + ".ota.zip"); - String buildconfigAddr = new String(product + "/" + "build.prop"); - updatePackageURL = new URL(default_protocol, default_serveraddr, default_port, fileaddr ); - buildpropURL = new URL(default_protocol, default_serveraddr, default_port, buildconfigAddr); - Log.d(TAG, "create a new server config: package url " + updatePackageURL.toString() + "port:" + updatePackageURL.getPort()); - Log.d(TAG, "build.prop URL:" + buildpropURL.toString()); - } - - public boolean ab_slot() - { - return ab_slot; - } - - public boolean getDiffUpgrade() - { - return is_diff_upgrade; - } - - public void setDiffUpgrade() - { - is_diff_upgrade = true; - } - - public URL getPackageURL () - { - if (ab_slot) { - if (getDiffUpgrade()) - return diffPayloadURL; - else - return payloadURL; - } - else - return updatePackageURL; - } - - public URL getPayloadPropertiesURL () - { - if (getDiffUpgrade()) - return diffPayloadPropertiesURL; - else - return payloadPropertiesURL; - } - - public URL getBuildPropURL() { return buildpropURL; } - - public URL getBuildPropDiffURL() { return diffbuildpropURL; } + final String default_serveraddr = "10.193.108.180"; + final String default_protocol = "http"; + final int default_port = 10888; + URL updatePackageURL; + URL buildpropURL; + URL diffbuildpropURL; + URL payloadPropertiesURL; + URL payloadURL; + URL diffPayloadPropertiesURL; + URL diffPayloadURL; + boolean ab_slot = false; + boolean is_diff_upgrade = false; + String product; + final String TAG = "OTA"; + final String configFile = "/vendor/etc/ota.conf"; + final String server_ip_config = "server"; + final String port_config_str = "port"; + final String android_nickname = "ota_folder_suffix"; + + public OTAServerConfig(String productname) throws MalformedURLException { + if (loadConfigureFromFile(configFile, productname) == false) defaultConfigure(productname); + } + + boolean loadConfigureFromFile(String configFile, String product) { + try { + BuildPropParser parser = new BuildPropParser(new File(configFile), null); + String server = parser.getProp(server_ip_config); + String port_str = parser.getProp(port_config_str); + String android_name = parser.getProp(android_nickname); + String version_incremental = Build.VERSION.INCREMENTAL; + int port = new Long(port_str).intValue(); + String ota_folder; + String fileaddr; + String buildconfigAddr; + String diffbuildconfigAddr; + String payloadPropertiesAddr; + String payloadAddr; + String diffPayloadPropertiesAddr; + String diffPayloadAddr; + + String version = SystemProperties.get("ro.build.version.release"); + String platform = SystemProperties.get("ro.board.platform"); + ota_folder = new String(product + "_" + android_name + "_" + version + "/"); + fileaddr = new String(ota_folder + product + "-ota-" + version_incremental + ".zip"); + buildconfigAddr = new String(ota_folder + "build.prop"); + diffbuildconfigAddr = new String(ota_folder + "build_diff.prop"); + payloadPropertiesAddr = new String(ota_folder + "payload_properties.txt"); + diffPayloadPropertiesAddr = new String(ota_folder + "payload_properties_diff.txt"); + payloadAddr = new String(ota_folder + "payload.bin"); + diffPayloadAddr = new String(ota_folder + "payload_diff.bin"); + if (platform.indexOf("imx8") != -1) { + ab_slot = true; + } + + buildpropURL = new URL(default_protocol, server, port, buildconfigAddr); + if (!ab_slot) { + updatePackageURL = new URL(default_protocol, server, port, fileaddr); + Log.d(TAG, "ota package: " + updatePackageURL.toString()); + } else { + payloadPropertiesURL = + new URL(default_protocol, server, port, payloadPropertiesAddr); + payloadURL = new URL(default_protocol, server, port, payloadAddr); + diffbuildpropURL = new URL(default_protocol, server, port, diffbuildconfigAddr); + diffPayloadPropertiesURL = + new URL(default_protocol, server, port, diffPayloadPropertiesAddr); + diffPayloadURL = new URL(default_protocol, server, port, diffPayloadAddr); + Log.d(TAG, "build.prop: " + buildpropURL.toString()); + Log.d(TAG, "payload.bin: " + payloadURL.toString()); + Log.d(TAG, "payload_properties.txt" + payloadPropertiesURL.toString()); + } + } catch (Exception e) { + Log.e(TAG, "wrong format/error of OTA configure file."); + e.printStackTrace(); + return false; + } + + return true; + } + + void defaultConfigure(String productname) throws MalformedURLException { + product = productname; + String fileaddr = new String(product + "/" + product + ".ota.zip"); + String buildconfigAddr = new String(product + "/" + "build.prop"); + updatePackageURL = new URL(default_protocol, default_serveraddr, default_port, fileaddr); + buildpropURL = new URL(default_protocol, default_serveraddr, default_port, buildconfigAddr); + Log.d( + TAG, + "create a new server config: package url " + + updatePackageURL.toString() + + "port:" + + updatePackageURL.getPort()); + Log.d(TAG, "build.prop URL:" + buildpropURL.toString()); + } + + public boolean ab_slot() { + return ab_slot; + } + + public boolean getDiffUpgrade() { + return is_diff_upgrade; + } + + public void setDiffUpgrade() { + is_diff_upgrade = true; + } + + public URL getPackageURL() { + if (ab_slot) { + if (getDiffUpgrade()) return diffPayloadURL; + else return payloadURL; + } else return updatePackageURL; + } + + public URL getPayloadPropertiesURL() { + if (getDiffUpgrade()) return diffPayloadPropertiesURL; + else return payloadPropertiesURL; + } + + public URL getBuildPropURL() { + return buildpropURL; + } + + public URL getBuildPropDiffURL() { + return diffbuildpropURL; + } } diff --git a/FSLOta/src/com/fsl/android/ota/OTAServerManager.java b/FSLOta/src/com/fsl/android/ota/OTAServerManager.java index e4aaa1e..1d10f64 100644 --- a/FSLOta/src/com/fsl/android/ota/OTAServerManager.java +++ b/FSLOta/src/com/fsl/android/ota/OTAServerManager.java @@ -16,13 +16,6 @@ package com.fsl.android.ota; -import java.net.*; -import java.security.GeneralSecurityException; -import java.io.*; -import java.util.List; -import java.util.ArrayList; - -import android.os.SystemProperties; import android.content.*; import android.net.ConnectivityManager; import android.os.Build; @@ -35,439 +28,462 @@ import android.os.UpdateEngineCallback; import android.util.Log; +import java.io.*; +import java.net.*; +import java.security.GeneralSecurityException; +import java.util.ArrayList; +import java.util.List; + public class OTAServerManager { - public interface OTAStateChangeListener { - - final int STATE_IN_IDLE = 0; - final int STATE_IN_CHECKED = 1; // state in checking whether new available. - final int STATE_IN_DOWNLOADING = 2; // state in download upgrade package - final int STATE_IN_UPGRADING = 3; // In upgrade state - - final int MESSAGE_DOWNLOAD_PROGRESS = 4; - final int MESSAGE_VERIFY_PROGRESS = 5; - final int MESSAGE_STATE_CHANGE = 6; - final int MESSAGE_ERROR = 7; - final int MESSAGE_WAIT_REBOOT = 8; - - // should be raise exception ? but how to do exception in async mode ? - final int NO_ERROR = 0; - final int ERROR_WIFI_NOT_AVALIBLE = 1; // require wifi network, for OTA app. - final int ERROR_CANNOT_FIND_SERVER = 2; - final int ERROR_PACKAGE_VERIFY_FALIED = 3; - final int ERROR_WRITE_FILE_ERROR = 4; - final int ERROR_NETWORK_ERROR = 5; - final int ERROR_PACKAGE_INSTALL_FAILED = 6; - final int ERROR_PACKAGE_VERIFY_FAILED = 7; - - // results - final int RESULTS_ALREADY_LATEST = 1; - - public void onStateOrProgress(int message, int error, Object info); - - } - - public enum OtaTypeSelect { - NONE, FULL_OTA, DIFF_OTA, BOTH_OTA; - } - - public class OTAUpdateEngineCallback extends UpdateEngineCallback { - private OTAStateChangeListener mListener; - - public OTAUpdateEngineCallback(OTAStateChangeListener listener){ - mListener = listener; - } - - public void onStatusUpdate(int status, float percent) { - if (status == UpdateEngine.UpdateStatusConstants.DOWNLOADING) { - publishDownloadProgress(100, (long)(percent*100)); - } - } - - public void onPayloadApplicationComplete(int errorCode) { - Log.d(TAG, "onPayloadApplicationComplete: errorCode: " + errorCode); - if (errorCode == UpdateEngine.ErrorCodeConstants.SUCCESS) { - if (this.mListener != null && !mStop) - this.mListener.onStateOrProgress(OTAStateChangeListener.MESSAGE_WAIT_REBOOT, 0, null); - } - } - } - - private OTAStateChangeListener mListener; - private OTAServerConfig mConfig; - private BuildPropParser parser = null; - private BuildPropParser parser_diff = null; - long mCacheProgress = -1; - boolean mStop = false; - Context mContext; - String mUpdatePackageLocation = "/cache/update.zip"; - String TAG = "OTA"; - Handler mSelfHandler; - WakeLock mWakelock; - UpdateEngine mUpdateEngine; - String[] mUpdateHeader; - - public OTAServerManager(Context context) throws MalformedURLException { - mConfig = new OTAServerConfig(Build.PRODUCT); - PowerManager pm = (PowerManager)context.getSystemService(Context.POWER_SERVICE); - mWakelock = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, "OTA Wakelock"); - mContext = context; - mUpdateEngine = new UpdateEngine(); - } - - public OTAStateChangeListener getmListener() { - return mListener; - } - - public void setmListener(OTAStateChangeListener mListener) { - this.mListener = mListener; - } - - public boolean checkNetworkOnline() { - ConnectivityManager conMgr = (ConnectivityManager)mContext.getSystemService(Context.CONNECTIVITY_SERVICE); - - if (conMgr.getNetworkInfo(ConnectivityManager.TYPE_ETHERNET).isConnectedOrConnecting()|| - conMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI).isConnectedOrConnecting()) { - return true; - } else { - return false; - } - } - - public void startCheckingVersion() { - - Log.v(TAG, "startCheckingVersion"); - if (checkURLOK(mConfig.getBuildPropURL()) == false) { - if (this.mListener != null) { - if (this.checkNetworkOnline()) { - reportCheckingError(OTAStateChangeListener.ERROR_CANNOT_FIND_SERVER); - Log.v(TAG, "error cannot find server!"); - } - else { - reportCheckingError(OTAStateChangeListener.ERROR_WIFI_NOT_AVALIBLE); - Log.v(TAG, "error wifi or ethernet not avalible"); - } - } - - return; - } - - parser = getTargetPackagePropertyList(mConfig.getBuildPropURL()); - if (ab_slot()) { - parser_diff = getTargetPackagePropertyList(mConfig.getBuildPropDiffURL()); - } - - if (parser != null) { - if (this.mListener != null) - this.mListener.onStateOrProgress(OTAStateChangeListener.STATE_IN_CHECKED, - OTAStateChangeListener.NO_ERROR, parser); - } else { - reportCheckingError(OTAStateChangeListener.ERROR_WRITE_FILE_ERROR); - } - } - - public boolean getUpdateHeader(URL propertiesURL) - { - try { - URL url = propertiesURL; - url.openConnection(); - InputStream is = url.openStream(); - BufferedReader br = new BufferedReader(new InputStreamReader(is)); - List lines = new ArrayList(); - String line = null; - while ((line = br.readLine()) != null) { - lines.add(line); - } - br.close(); - is.close(); - mUpdateHeader = lines.toArray(new String[lines.size()]); - mUpdateEngine.bind(new OTAUpdateEngineCallback(this.mListener)); - - return true; - } catch (IOException e) { - e.printStackTrace(); - return false; - } catch (Exception e) { - e.printStackTrace(); - return false; - } - } - - // return true if needs to upgrade - public OtaTypeSelect compareLocalVersionToServer() { - boolean diff_ota = false; - boolean full_ota = false; - Long remoteDiffBuildUTC = 0L; - Long remoteDiffBuildBaseUTC = 0L; - - if (parser == null) { - Log.d(TAG, "compareLocalVersion Without fetch remote prop list."); - return OtaTypeSelect.NONE; - } - OtaTypeSelect upgrade = OtaTypeSelect.NONE; - Long buildutc = Build.TIME; - // *1000 because Build.java also *1000, align with it. - Long remoteBuildUTC = (Long.parseLong(parser.getProp("ro.build.date.utc"))) * 1000; - if (buildutc < remoteBuildUTC) - full_ota = true; - if (ab_slot()) { - remoteDiffBuildUTC = (Long.parseLong(parser_diff.getProp("ro.build.date.utc"))) * 1000; - remoteDiffBuildBaseUTC = (Long.parseLong(parser_diff.getProp("base.ro.build.date.utc"))) * 1000; - if (buildutc < remoteDiffBuildUTC && buildutc.equals(remoteDiffBuildBaseUTC)) - diff_ota = true; - } - if (full_ota && diff_ota) - upgrade = OtaTypeSelect.BOTH_OTA; - else if (full_ota) - upgrade = OtaTypeSelect.FULL_OTA; - else if (diff_ota) - upgrade = OtaTypeSelect.DIFF_OTA; - // here only check build time, in your case, you may also check build id, etc. - Log.d(TAG, "remote BUILD TIME: " + remoteBuildUTC + " remote DIFF BUILD TIME: " + remoteDiffBuildUTC + " remote DIFF BUILD BASE TIME: " + remoteDiffBuildBaseUTC + " local BUILD TIME:" + buildutc); - return upgrade; - } - - void publishDownloadProgress(long total, long downloaded) { - //Log.v(TAG, "download Progress: total: " + total + "download:" + downloaded); - Long progress = new Long((downloaded*100)/total); - if (this.mListener != null && progress.longValue() != mCacheProgress) { - this.mListener.onStateOrProgress(OTAStateChangeListener.MESSAGE_DOWNLOAD_PROGRESS, - 0, progress); - mCacheProgress = progress.longValue(); - } - } - - void reportCheckingError(int error) { - if (this.mListener != null ) { - this.mListener.onStateOrProgress(OTAStateChangeListener.STATE_IN_CHECKED, error, null); - Log.v(TAG, "---------state in checked----------- "); + public interface OTAStateChangeListener { + + final int STATE_IN_IDLE = 0; + final int STATE_IN_CHECKED = 1; // state in checking whether new available. + final int STATE_IN_DOWNLOADING = 2; // state in download upgrade package + final int STATE_IN_UPGRADING = 3; // In upgrade state + + final int MESSAGE_DOWNLOAD_PROGRESS = 4; + final int MESSAGE_VERIFY_PROGRESS = 5; + final int MESSAGE_STATE_CHANGE = 6; + final int MESSAGE_ERROR = 7; + final int MESSAGE_WAIT_REBOOT = 8; + + // should be raise exception ? but how to do exception in async mode ? + final int NO_ERROR = 0; + final int ERROR_WIFI_NOT_AVALIBLE = 1; // require wifi network, for OTA app. + final int ERROR_CANNOT_FIND_SERVER = 2; + final int ERROR_PACKAGE_VERIFY_FALIED = 3; + final int ERROR_WRITE_FILE_ERROR = 4; + final int ERROR_NETWORK_ERROR = 5; + final int ERROR_PACKAGE_INSTALL_FAILED = 6; + final int ERROR_PACKAGE_VERIFY_FAILED = 7; + + // results + final int RESULTS_ALREADY_LATEST = 1; + + public void onStateOrProgress(int message, int error, Object info); + } + + public enum OtaTypeSelect { + NONE, + FULL_OTA, + DIFF_OTA, + BOTH_OTA; + } + + public class OTAUpdateEngineCallback extends UpdateEngineCallback { + private OTAStateChangeListener mListener; + + public OTAUpdateEngineCallback(OTAStateChangeListener listener) { + mListener = listener; + } + + public void onStatusUpdate(int status, float percent) { + if (status == UpdateEngine.UpdateStatusConstants.DOWNLOADING) { + publishDownloadProgress(100, (long) (percent * 100)); + } + } + + public void onPayloadApplicationComplete(int errorCode) { + Log.d(TAG, "onPayloadApplicationComplete: errorCode: " + errorCode); + if (errorCode == UpdateEngine.ErrorCodeConstants.SUCCESS) { + if (this.mListener != null && !mStop) + this.mListener.onStateOrProgress( + OTAStateChangeListener.MESSAGE_WAIT_REBOOT, 0, null); + } + } + } + + private OTAStateChangeListener mListener; + private OTAServerConfig mConfig; + private BuildPropParser parser = null; + private BuildPropParser parser_diff = null; + long mCacheProgress = -1; + boolean mStop = false; + Context mContext; + String mUpdatePackageLocation = "/cache/update.zip"; + String TAG = "OTA"; + Handler mSelfHandler; + WakeLock mWakelock; + UpdateEngine mUpdateEngine; + String[] mUpdateHeader; + + public OTAServerManager(Context context) throws MalformedURLException { + mConfig = new OTAServerConfig(Build.PRODUCT); + PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); + mWakelock = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, "OTA Wakelock"); + mContext = context; + mUpdateEngine = new UpdateEngine(); + } + + public OTAStateChangeListener getmListener() { + return mListener; + } + + public void setmListener(OTAStateChangeListener mListener) { + this.mListener = mListener; + } + + public boolean checkNetworkOnline() { + ConnectivityManager conMgr = + (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE); + + if (conMgr.getNetworkInfo(ConnectivityManager.TYPE_ETHERNET).isConnectedOrConnecting() + || conMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI).isConnectedOrConnecting()) { + return true; + } else { + return false; + } + } + + public void startCheckingVersion() { + + Log.v(TAG, "startCheckingVersion"); + if (checkURLOK(mConfig.getBuildPropURL()) == false) { + if (this.mListener != null) { + if (this.checkNetworkOnline()) { + reportCheckingError(OTAStateChangeListener.ERROR_CANNOT_FIND_SERVER); + Log.v(TAG, "error cannot find server!"); + } else { + reportCheckingError(OTAStateChangeListener.ERROR_WIFI_NOT_AVALIBLE); + Log.v(TAG, "error wifi or ethernet not avalible"); } + } + + return; + } + + parser = getTargetPackagePropertyList(mConfig.getBuildPropURL()); + if (ab_slot()) { + parser_diff = getTargetPackagePropertyList(mConfig.getBuildPropDiffURL()); + } + + if (parser != null) { + if (this.mListener != null) + this.mListener.onStateOrProgress( + OTAStateChangeListener.STATE_IN_CHECKED, + OTAStateChangeListener.NO_ERROR, + parser); + } else { + reportCheckingError(OTAStateChangeListener.ERROR_WRITE_FILE_ERROR); + } + } + + public boolean getUpdateHeader(URL propertiesURL) { + try { + URL url = propertiesURL; + url.openConnection(); + InputStream is = url.openStream(); + BufferedReader br = new BufferedReader(new InputStreamReader(is)); + List lines = new ArrayList(); + String line = null; + while ((line = br.readLine()) != null) { + lines.add(line); + } + br.close(); + is.close(); + mUpdateHeader = lines.toArray(new String[lines.size()]); + mUpdateEngine.bind(new OTAUpdateEngineCallback(this.mListener)); + + return true; + } catch (IOException e) { + e.printStackTrace(); + return false; + } catch (Exception e) { + e.printStackTrace(); + return false; } - - void reportDownloadError(int error) { - if (this.mListener != null) - this.mListener.onStateOrProgress(OTAStateChangeListener.STATE_IN_DOWNLOADING, error, null); - } - - void reportInstallError(int error) { - if (this.mListener != null) { - this.mListener.onStateOrProgress(OTAStateChangeListener.STATE_IN_UPGRADING, error, null); - Log.v(TAG, "---------state in upgrading----------- "); - } - } - - public long getUpgradePackageSize() { - if (checkURLOK(mConfig.getPackageURL()) == false) { - Log.e(TAG, "getUpgradePckageSize Failed"); - return -1; - } - - URL url = mConfig.getPackageURL(); - URLConnection con; - try { - con = url.openConnection(); - return con.getContentLength(); - } catch (IOException e) { - e.printStackTrace(); - return -1; - } - } - - public void onStop() { - mStop = true; - } - - public void startDownloadUpgradePackage() { - - Log.v(TAG, "startDownloadUpgradePackage()"); - - if (checkURLOK(mConfig.getPackageURL()) == false) { - if (this.mListener != null) - reportDownloadError(OTAStateChangeListener.ERROR_CANNOT_FIND_SERVER); - return; - } - - if (ab_slot()) { - if (getUpdateHeader(mConfig.getPayloadPropertiesURL()) == false) { - reportCheckingError(OTAStateChangeListener.ERROR_CANNOT_FIND_SERVER); - Log.v(TAG, "error cannot find server!"); - return; - } - - mWakelock.acquire(); - mUpdateEngine.applyPayload(mConfig.getPackageURL().toString(), 0l, 0l, mUpdateHeader); - mWakelock.release(); - return; - } - - File targetFile = new File(mUpdatePackageLocation); - try { - targetFile.createNewFile(); - } catch (IOException e) { - e.printStackTrace(); - reportDownloadError(OTAStateChangeListener.ERROR_WRITE_FILE_ERROR); - return; - } - - try { - mWakelock.acquire(); - - URL url = mConfig.getPackageURL(); - Log.d(TAG, "start downoading package:" + url.toString()); - URLConnection conexion = url.openConnection(); - conexion.setReadTimeout(10000); - // this will be useful so that you can show a topical 0-100% progress bar - - int lengthOfFile = 96038693; - lengthOfFile = conexion.getContentLength(); - // download the file - InputStream input = new BufferedInputStream(url.openStream()); - OutputStream output = new FileOutputStream(targetFile); - - Log.d(TAG, "file size:" + lengthOfFile); - byte data[] = new byte[100 * 1024]; - long total = 0, count; - while ((count = input.read(data)) >= 0 && !mStop) { - total += count; - - // publishing the progress.... - publishDownloadProgress(lengthOfFile, total); - output.write(data, 0, (int)count); - } - - output.flush(); - output.close(); - input.close(); - if (this.mListener != null && !mStop) - this.mListener.onStateOrProgress(OTAStateChangeListener.STATE_IN_DOWNLOADING, 0, null); - } catch (IOException e) { - e.printStackTrace(); - reportDownloadError(OTAStateChangeListener.ERROR_WRITE_FILE_ERROR); - } finally { - mWakelock.release(); - mWakelock.acquire(2); - } - } - - RecoverySystem.ProgressListener recoveryVerifyListener = new RecoverySystem.ProgressListener() { - public void onProgress(int progress) { - Log.d(TAG, "verify progress" + progress); - if (mListener != null) - mListener.onStateOrProgress(OTAStateChangeListener.MESSAGE_VERIFY_PROGRESS, - 0, new Long(progress)); - } - }; - - public void startInstallUpgradePackage() { - if (ab_slot()) { - if (mListener != null) { - mListener.onStateOrProgress(OTAStateChangeListener.MESSAGE_WAIT_REBOOT, 0, null); - } - return; - } - - File recoveryFile = new File(mUpdatePackageLocation); - - // first verify package - try { - mWakelock.acquire(); - RecoverySystem.verifyPackage(recoveryFile, recoveryVerifyListener, null); - } catch (IOException e1) { - reportInstallError(OTAStateChangeListener.ERROR_PACKAGE_VERIFY_FALIED); - e1.printStackTrace(); - return; - } catch (GeneralSecurityException e1) { - reportInstallError(OTAStateChangeListener.ERROR_PACKAGE_VERIFY_FALIED); - e1.printStackTrace(); - return; - } finally { - mWakelock.release(); - } - - // then install package - try { - mWakelock.acquire(); - RecoverySystem.installPackage(mContext, recoveryFile); - } catch (IOException e) { - // TODO Auto-generated catch block - reportInstallError(OTAStateChangeListener.ERROR_PACKAGE_INSTALL_FAILED); - e.printStackTrace(); - return; - } catch (SecurityException e){ - e.printStackTrace(); - reportInstallError(OTAStateChangeListener.ERROR_PACKAGE_INSTALL_FAILED); - return; - } finally { - mWakelock.release(); - } - // cannot reach here... - - } - - boolean checkURLOK(URL url) { - try { - HttpURLConnection.setFollowRedirects(false); - - HttpURLConnection con = (HttpURLConnection) url.openConnection(); - - con.setRequestMethod("HEAD"); - - return (con.getResponseCode() == HttpURLConnection.HTTP_OK); - } catch (Exception e) { - e.printStackTrace(); - return false; - } - } - - - // function: - // download the property list from remote site, and parse it to peroerty list. - // the caller can parser this list and get information. - BuildPropParser getTargetPackagePropertyList(URL configURL) { - - // first try to download the property list file. the build.prop of target image. - try { - URL url = configURL; - url.openConnection(); - InputStream reader = url.openStream(); - ByteArrayOutputStream writer = new ByteArrayOutputStream(); - byte[] buffer = new byte[153600]; - int totalBufRead = 0; - int bytesRead; - - Log.d(TAG, "start download: " + url.toString() + "to buffer"); - - while ((bytesRead = reader.read(buffer)) > 0) { - writer.write(buffer, 0, bytesRead); - buffer = new byte[153600]; - totalBufRead += bytesRead; - } - - Log.d(TAG, "download finish:" + (new Integer(totalBufRead).toString()) + "bytes download"); - reader.close(); - - BuildPropParser parser = new BuildPropParser(writer, mContext); - - return parser; - - } catch (IOException e) { - e.printStackTrace(); - return null; - } catch (Exception e) { - e.printStackTrace(); - return null; - } - } - - public boolean handleMessage(Message arg0) { - // TODO Auto-generated method stub - return false; - } - - public boolean ab_slot() { - return mConfig.ab_slot(); - } - - public void setDiffUpgrade() { - mConfig.setDiffUpgrade(); - } + } + + // return true if needs to upgrade + public OtaTypeSelect compareLocalVersionToServer() { + boolean diff_ota = false; + boolean full_ota = false; + Long remoteDiffBuildUTC = 0L; + Long remoteDiffBuildBaseUTC = 0L; + + if (parser == null) { + Log.d(TAG, "compareLocalVersion Without fetch remote prop list."); + return OtaTypeSelect.NONE; + } + OtaTypeSelect upgrade = OtaTypeSelect.NONE; + Long buildutc = Build.TIME; + // *1000 because Build.java also *1000, align with it. + Long remoteBuildUTC = (Long.parseLong(parser.getProp("ro.build.date.utc"))) * 1000; + if (buildutc < remoteBuildUTC) full_ota = true; + if (ab_slot()) { + remoteDiffBuildUTC = (Long.parseLong(parser_diff.getProp("ro.build.date.utc"))) * 1000; + remoteDiffBuildBaseUTC = + (Long.parseLong(parser_diff.getProp("base.ro.build.date.utc"))) * 1000; + if (buildutc < remoteDiffBuildUTC && buildutc.equals(remoteDiffBuildBaseUTC)) + diff_ota = true; + } + if (full_ota && diff_ota) upgrade = OtaTypeSelect.BOTH_OTA; + else if (full_ota) upgrade = OtaTypeSelect.FULL_OTA; + else if (diff_ota) upgrade = OtaTypeSelect.DIFF_OTA; + // here only check build time, in your case, you may also check build id, etc. + Log.d( + TAG, + "remote BUILD TIME: " + + remoteBuildUTC + + " remote DIFF BUILD TIME: " + + remoteDiffBuildUTC + + " remote DIFF BUILD BASE TIME: " + + remoteDiffBuildBaseUTC + + " local BUILD TIME:" + + buildutc); + return upgrade; + } + + void publishDownloadProgress(long total, long downloaded) { + // Log.v(TAG, "download Progress: total: " + total + "download:" + downloaded); + Long progress = new Long((downloaded * 100) / total); + if (this.mListener != null && progress.longValue() != mCacheProgress) { + this.mListener.onStateOrProgress( + OTAStateChangeListener.MESSAGE_DOWNLOAD_PROGRESS, 0, progress); + mCacheProgress = progress.longValue(); + } + } + + void reportCheckingError(int error) { + if (this.mListener != null) { + this.mListener.onStateOrProgress(OTAStateChangeListener.STATE_IN_CHECKED, error, null); + Log.v(TAG, "---------state in checked----------- "); + } + } + + void reportDownloadError(int error) { + if (this.mListener != null) + this.mListener.onStateOrProgress( + OTAStateChangeListener.STATE_IN_DOWNLOADING, error, null); + } + + void reportInstallError(int error) { + if (this.mListener != null) { + this.mListener.onStateOrProgress( + OTAStateChangeListener.STATE_IN_UPGRADING, error, null); + Log.v(TAG, "---------state in upgrading----------- "); + } + } + + public long getUpgradePackageSize() { + if (checkURLOK(mConfig.getPackageURL()) == false) { + Log.e(TAG, "getUpgradePckageSize Failed"); + return -1; + } + + URL url = mConfig.getPackageURL(); + URLConnection con; + try { + con = url.openConnection(); + return con.getContentLength(); + } catch (IOException e) { + e.printStackTrace(); + return -1; + } + } + + public void onStop() { + mStop = true; + } + + public void startDownloadUpgradePackage() { + + Log.v(TAG, "startDownloadUpgradePackage()"); + + if (checkURLOK(mConfig.getPackageURL()) == false) { + if (this.mListener != null) + reportDownloadError(OTAStateChangeListener.ERROR_CANNOT_FIND_SERVER); + return; + } + + if (ab_slot()) { + if (getUpdateHeader(mConfig.getPayloadPropertiesURL()) == false) { + reportCheckingError(OTAStateChangeListener.ERROR_CANNOT_FIND_SERVER); + Log.v(TAG, "error cannot find server!"); + return; + } + + mWakelock.acquire(); + mUpdateEngine.applyPayload(mConfig.getPackageURL().toString(), 0l, 0l, mUpdateHeader); + mWakelock.release(); + return; + } + + File targetFile = new File(mUpdatePackageLocation); + try { + targetFile.createNewFile(); + } catch (IOException e) { + e.printStackTrace(); + reportDownloadError(OTAStateChangeListener.ERROR_WRITE_FILE_ERROR); + return; + } + + try { + mWakelock.acquire(); + + URL url = mConfig.getPackageURL(); + Log.d(TAG, "start downoading package:" + url.toString()); + URLConnection conexion = url.openConnection(); + conexion.setReadTimeout(10000); + // this will be useful so that you can show a topical 0-100% progress bar + + int lengthOfFile = 96038693; + lengthOfFile = conexion.getContentLength(); + // download the file + InputStream input = new BufferedInputStream(url.openStream()); + OutputStream output = new FileOutputStream(targetFile); + + Log.d(TAG, "file size:" + lengthOfFile); + byte data[] = new byte[100 * 1024]; + long total = 0, count; + while ((count = input.read(data)) >= 0 && !mStop) { + total += count; + + // publishing the progress.... + publishDownloadProgress(lengthOfFile, total); + output.write(data, 0, (int) count); + } + + output.flush(); + output.close(); + input.close(); + if (this.mListener != null && !mStop) + this.mListener.onStateOrProgress( + OTAStateChangeListener.STATE_IN_DOWNLOADING, 0, null); + } catch (IOException e) { + e.printStackTrace(); + reportDownloadError(OTAStateChangeListener.ERROR_WRITE_FILE_ERROR); + } finally { + mWakelock.release(); + mWakelock.acquire(2); + } + } + + RecoverySystem.ProgressListener recoveryVerifyListener = + new RecoverySystem.ProgressListener() { + public void onProgress(int progress) { + Log.d(TAG, "verify progress" + progress); + if (mListener != null) + mListener.onStateOrProgress( + OTAStateChangeListener.MESSAGE_VERIFY_PROGRESS, + 0, + new Long(progress)); + } + }; + + public void startInstallUpgradePackage() { + if (ab_slot()) { + if (mListener != null) { + mListener.onStateOrProgress(OTAStateChangeListener.MESSAGE_WAIT_REBOOT, 0, null); + } + return; + } + + File recoveryFile = new File(mUpdatePackageLocation); + + // first verify package + try { + mWakelock.acquire(); + RecoverySystem.verifyPackage(recoveryFile, recoveryVerifyListener, null); + } catch (IOException e1) { + reportInstallError(OTAStateChangeListener.ERROR_PACKAGE_VERIFY_FALIED); + e1.printStackTrace(); + return; + } catch (GeneralSecurityException e1) { + reportInstallError(OTAStateChangeListener.ERROR_PACKAGE_VERIFY_FALIED); + e1.printStackTrace(); + return; + } finally { + mWakelock.release(); + } + + // then install package + try { + mWakelock.acquire(); + RecoverySystem.installPackage(mContext, recoveryFile); + } catch (IOException e) { + // TODO Auto-generated catch block + reportInstallError(OTAStateChangeListener.ERROR_PACKAGE_INSTALL_FAILED); + e.printStackTrace(); + return; + } catch (SecurityException e) { + e.printStackTrace(); + reportInstallError(OTAStateChangeListener.ERROR_PACKAGE_INSTALL_FAILED); + return; + } finally { + mWakelock.release(); + } + // cannot reach here... + + } + + boolean checkURLOK(URL url) { + try { + HttpURLConnection.setFollowRedirects(false); + + HttpURLConnection con = (HttpURLConnection) url.openConnection(); + + con.setRequestMethod("HEAD"); + + return (con.getResponseCode() == HttpURLConnection.HTTP_OK); + } catch (Exception e) { + e.printStackTrace(); + return false; + } + } + + // function: + // download the property list from remote site, and parse it to peroerty list. + // the caller can parser this list and get information. + BuildPropParser getTargetPackagePropertyList(URL configURL) { + + // first try to download the property list file. the build.prop of target image. + try { + URL url = configURL; + url.openConnection(); + InputStream reader = url.openStream(); + ByteArrayOutputStream writer = new ByteArrayOutputStream(); + byte[] buffer = new byte[153600]; + int totalBufRead = 0; + int bytesRead; + + Log.d(TAG, "start download: " + url.toString() + "to buffer"); + + while ((bytesRead = reader.read(buffer)) > 0) { + writer.write(buffer, 0, bytesRead); + buffer = new byte[153600]; + totalBufRead += bytesRead; + } + + Log.d( + TAG, + "download finish:" + (new Integer(totalBufRead).toString()) + "bytes download"); + reader.close(); + + BuildPropParser parser = new BuildPropParser(writer, mContext); + + return parser; + + } catch (IOException e) { + e.printStackTrace(); + return null; + } catch (Exception e) { + e.printStackTrace(); + return null; + } + } + + public boolean handleMessage(Message arg0) { + // TODO Auto-generated method stub + return false; + } + + public boolean ab_slot() { + return mConfig.ab_slot(); + } + + public void setDiffUpgrade() { + mConfig.setDiffUpgrade(); + } } diff --git a/FSLOta/src/com/fsl/android/ota/OtaAppActivity.java b/FSLOta/src/com/fsl/android/ota/OtaAppActivity.java index 6554c9e..fa007bc 100644 --- a/FSLOta/src/com/fsl/android/ota/OtaAppActivity.java +++ b/FSLOta/src/com/fsl/android/ota/OtaAppActivity.java @@ -15,89 +15,89 @@ */ package com.fsl.android.ota; -import java.net.MalformedURLException; + import android.annotation.SuppressLint; import android.app.Activity; import android.content.Context; -import android.content.Intent; import android.os.Build; import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.os.PowerManager; -import com.fsl.android.ota.R; import android.util.Log; import android.view.View; import android.view.View.OnClickListener; import android.widget.*; +import java.net.MalformedURLException; + // Controller of OTA Activity public class OtaAppActivity extends Activity implements OTAServerManager.OTAStateChangeListener { - - private final int IDLE = 1; - private final int CHECKED = 2; - private final int DOWNLOADING = 3; - private final int WIFI_NOT_AVALIBLE = 4; - private final int CANNOT_FIND_SERVER = 5; - private final int WRITE_FILE_ERROR = 6; - private final int WAIT_REBOOT = 7; - Button mUpgradeButton; - Button mDiffUpgradeButton; - Button mRebootButton; - TextView mMessageTextView; - TextView mVersionTextView; - ProgressBar mSpinner; - ProgressBar mDownloadProgress; - - Context mContext; - - OTAServerManager mOTAManager; - int mState = 0; - private Handler mHandler = new MainHandler(); - /* state change will be 0 -> Checked -> Downloading -> upgrading. */ - - final String TAG = "OTA"; - - @SuppressLint("HandlerLeak") - private class MainHandler extends Handler { - @Override - public void handleMessage(Message msg) { + + private final int IDLE = 1; + private final int CHECKED = 2; + private final int DOWNLOADING = 3; + private final int WIFI_NOT_AVALIBLE = 4; + private final int CANNOT_FIND_SERVER = 5; + private final int WRITE_FILE_ERROR = 6; + private final int WAIT_REBOOT = 7; + Button mUpgradeButton; + Button mDiffUpgradeButton; + Button mRebootButton; + TextView mMessageTextView; + TextView mVersionTextView; + ProgressBar mSpinner; + ProgressBar mDownloadProgress; + + Context mContext; + + OTAServerManager mOTAManager; + int mState = 0; + private Handler mHandler = new MainHandler(); + /* state change will be 0 -> Checked -> Downloading -> upgrading. */ + + final String TAG = "OTA"; + + @SuppressLint("HandlerLeak") + private class MainHandler extends Handler { + @Override + public void handleMessage(Message msg) { switch (msg.what) { case IDLE: - mVersionTextView.setVisibility(View.INVISIBLE); - mDownloadProgress.setVisibility(View.INVISIBLE); - mUpgradeButton.setVisibility(View.INVISIBLE); - mDiffUpgradeButton.setVisibility(View.INVISIBLE); - mRebootButton.setVisibility(View.INVISIBLE); - break; + mVersionTextView.setVisibility(View.INVISIBLE); + mDownloadProgress.setVisibility(View.INVISIBLE); + mUpgradeButton.setVisibility(View.INVISIBLE); + mDiffUpgradeButton.setVisibility(View.INVISIBLE); + mRebootButton.setVisibility(View.INVISIBLE); + break; case CHECKED: - mVersionTextView.setVisibility(View.VISIBLE); - mSpinner.setVisibility(View.INVISIBLE); - break; + mVersionTextView.setVisibility(View.VISIBLE); + mSpinner.setVisibility(View.INVISIBLE); + break; case DOWNLOADING: - mVersionTextView.setVisibility(View.INVISIBLE); - mUpgradeButton.setVisibility(View.INVISIBLE); - mDiffUpgradeButton.setVisibility(View.INVISIBLE); - mRebootButton.setVisibility(View.INVISIBLE); - mSpinner.setVisibility(View.INVISIBLE); - mDownloadProgress.setVisibility(View.VISIBLE); - break; + mVersionTextView.setVisibility(View.INVISIBLE); + mUpgradeButton.setVisibility(View.INVISIBLE); + mDiffUpgradeButton.setVisibility(View.INVISIBLE); + mRebootButton.setVisibility(View.INVISIBLE); + mSpinner.setVisibility(View.INVISIBLE); + mDownloadProgress.setVisibility(View.VISIBLE); + break; case WIFI_NOT_AVALIBLE: - mMessageTextView.setText(getText(R.string.error_needs_wifi)); - break; + mMessageTextView.setText(getText(R.string.error_needs_wifi)); + break; case CANNOT_FIND_SERVER: - mMessageTextView.setText(getText(R.string.error_cannot_connect_server)); - break; + mMessageTextView.setText(getText(R.string.error_cannot_connect_server)); + break; case WRITE_FILE_ERROR: - mMessageTextView.setText(getText(R.string.error_write_file)); - break; + mMessageTextView.setText(getText(R.string.error_write_file)); + break; case WAIT_REBOOT: - mDownloadProgress.setVisibility(View.INVISIBLE); - mMessageTextView.setText(getText(R.string.wait_for_reboot)); - mRebootButton.setVisibility(View.VISIBLE); + mDownloadProgress.setVisibility(View.INVISIBLE); + mMessageTextView.setText(getText(R.string.wait_for_reboot)); + mRebootButton.setVisibility(View.VISIBLE); break; default: - break; + break; } } } @@ -106,293 +106,330 @@ public void handleMessage(Message msg) { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - + Log.d(TAG, "OTAAppActivity : onCreate"); setContentView(R.layout.main); - (mUpgradeButton = (Button) findViewById(R.id.upgrade_button)) - .setOnClickListener(mUpgradeListener); + (mUpgradeButton = (Button) findViewById(R.id.upgrade_button)) + .setOnClickListener(mUpgradeListener); (mDiffUpgradeButton = (Button) findViewById(R.id.diff_upgrade_button)) - .setOnClickListener(mDiffUpgradeListener); + .setOnClickListener(mDiffUpgradeListener); (mRebootButton = (Button) findViewById(R.id.reboot_button)) - .setOnClickListener(mRebootListener); + .setOnClickListener(mRebootListener); mRebootButton.setVisibility(View.INVISIBLE); mMessageTextView = (TextView) findViewById(R.id.message_text_view); - mVersionTextView = ((TextView) findViewById(R.id.version_text_view)); + mVersionTextView = ((TextView) findViewById(R.id.version_text_view)); mSpinner = (ProgressBar) findViewById(R.id.spinner); mDownloadProgress = (ProgressBar) findViewById(R.id.download_progress_bar); mContext = getBaseContext(); - try { - mOTAManager = new OTAServerManager(mContext); - } catch (MalformedURLException e) { - mOTAManager = null; - Log.e(TAG, "meet not a mailformat URL... should not happens."); - e.printStackTrace(); - } - mOTAManager.setmListener(this); + try { + mOTAManager = new OTAServerManager(mContext); + } catch (MalformedURLException e) { + mOTAManager = null; + Log.e(TAG, "meet not a mailformat URL... should not happens."); + e.printStackTrace(); + } + mOTAManager.setmListener(this); } - + @Override public void onStart() { - super.onStart(); - - Log.d(TAG, "OTAAppActivity : onStart"); - // default state is checking, if resume from any pervious state, - // resume the state - onStateChangeUI(mState); - if (mState == 0) { - new Thread(new Runnable() { - public void run() { - mOTAManager.startCheckingVersion(); - } - }).start(); + super.onStart(); + + Log.d(TAG, "OTAAppActivity : onStart"); + // default state is checking, if resume from any pervious state, + // resume the state + onStateChangeUI(mState); + if (mState == 0) { + new Thread( + new Runnable() { + public void run() { + mOTAManager.startCheckingVersion(); + } + }) + .start(); } } - + @Override public void onRestart() { - super.onRestart(); - Log.d(TAG, "OTAAppActivity : onRestart"); + super.onRestart(); + Log.d(TAG, "OTAAppActivity : onRestart"); } - - + @Override - public void onPause() - { - super.onPause(); - Log.d(TAG, "OTAAppActivity : onPause"); + public void onPause() { + super.onPause(); + Log.d(TAG, "OTAAppActivity : onPause"); } - + @Override public void onStop() { - super.onStop(); - mOTAManager.onStop(); - Log.d(TAG, "OTAAppActivity : onStop"); + super.onStop(); + mOTAManager.onStop(); + Log.d(TAG, "OTAAppActivity : onStop"); + } + + OnClickListener mUpgradeListener = + new OnClickListener() { + public void onClick(View v) { + Log.v(TAG, "upgrade button clicked."); + new Thread( + new Runnable() { + public void run() { + mOTAManager.startDownloadUpgradePackage(); + } + }) + .start(); + onStateChangeUI(STATE_IN_DOWNLOADING); + } + }; + + OnClickListener mDiffUpgradeListener = + new OnClickListener() { + public void onClick(View v) { + Log.v(TAG, "diff upgrade button clicked."); + new Thread( + new Runnable() { + public void run() { + mOTAManager.setDiffUpgrade(); + mOTAManager.startDownloadUpgradePackage(); + } + }) + .start(); + onStateChangeUI(STATE_IN_DOWNLOADING); + } + }; + + OnClickListener mRebootListener = + new OnClickListener() { + public void onClick(View v) { + Log.v(TAG, "reboot button clicked."); + try { + PowerManager mPowerManager = + (PowerManager) getSystemService(Context.POWER_SERVICE); + mPowerManager.reboot("reboot"); + } catch (Exception e) { + e.printStackTrace(); + } + } + }; + + public void onStateOrProgress(int message, int error, Object info) { + Log.v( + TAG, + "onStateOrProgress: " + + "message: " + + message + + " error:" + + error + + " info: " + + info); + switch (message) { + case STATE_IN_CHECKED: + onStateChangeUI(message); + mState = STATE_IN_CHECKED; + onStateInChecked(error, info); + break; + case STATE_IN_DOWNLOADING: + onStateChangeUI(message); + mState = STATE_IN_DOWNLOADING; + onStateDownload(error, info); + break; + case STATE_IN_UPGRADING: + onStateChangeUI(message); + mState = STATE_IN_UPGRADING; + onStateUpgrade(error, info); + break; + case MESSAGE_DOWNLOAD_PROGRESS: + case MESSAGE_VERIFY_PROGRESS: + onProgress(message, error, info); + break; + case MESSAGE_WAIT_REBOOT: + mHandler.sendEmptyMessageDelayed(WAIT_REBOOT, 0); + break; + } + } + + // this state change function only change + // Attributes of UI elements + // other will control the model(download). + void onStateChangeUI(int newstate) { + mState = newstate; + if (newstate == STATE_IN_IDLE) { + mHandler.sendEmptyMessageDelayed(IDLE, 0); + } else if (newstate == STATE_IN_CHECKED) { + mHandler.sendEmptyMessageDelayed(CHECKED, 0); + } else if (newstate == STATE_IN_DOWNLOADING) { + // from start download, it start hide the version again. + mHandler.sendEmptyMessageDelayed(DOWNLOADING, 0); + } + } + + void onStateUpgrade(int error, Object info) { + + if (error == ERROR_PACKAGE_VERIFY_FAILED) { + Log.v(TAG, "package verify failed, signaure not match"); + mMessageTextView.post( + new Runnable() { + public void run() { + mMessageTextView.setText(getText(R.string.error_package_verify_failed)); + } + }); + // meet error in Verify, fall back to check. + // TODO which state should ? + } else if (error == ERROR_PACKAGE_INSTALL_FAILED) { + mMessageTextView.post( + new Runnable() { + public void run() { + mMessageTextView.setText( + getText(R.string.error_package_install_failed)); + } + }); + } + } + + void onProgress(int message, int error, Object info) { + final Long progress = new Long((Long) info); + mDownloadProgress.post( + new Runnable() { + public void run() { + mDownloadProgress.setProgress(progress.intValue()); + } + }); + + Log.v(TAG, "progress : " + progress); + if (message == MESSAGE_DOWNLOAD_PROGRESS) { + onStateChangeUI(STATE_IN_DOWNLOADING); + mMessageTextView.post( + new Runnable() { + + public void run() { + mMessageTextView.setText(getText(R.string.download_upgrade_package)); + } + }); + } else if (message == MESSAGE_VERIFY_PROGRESS) { + onStateChangeUI(STATE_IN_UPGRADING); + mMessageTextView.post( + new Runnable() { + public void run() { + mMessageTextView.setText(getText(R.string.verify_package)); + } + }); + } } - OnClickListener mUpgradeListener = new OnClickListener() { - public void onClick(View v) { - Log.v(TAG, "upgrade button clicked."); - new Thread(new Runnable() { - public void run() { - mOTAManager.startDownloadUpgradePackage(); - } - }).start(); - onStateChangeUI(STATE_IN_DOWNLOADING); - } - - }; - - OnClickListener mDiffUpgradeListener = new OnClickListener() { - public void onClick(View v) { - Log.v(TAG, "diff upgrade button clicked."); - new Thread(new Runnable() { - public void run() { - mOTAManager.setDiffUpgrade(); - mOTAManager.startDownloadUpgradePackage(); - } - }).start(); - onStateChangeUI(STATE_IN_DOWNLOADING); - } - }; - - OnClickListener mRebootListener = new OnClickListener() { - public void onClick(View v) { - Log.v(TAG, "reboot button clicked."); - try { - PowerManager mPowerManager = (PowerManager)getSystemService(Context.POWER_SERVICE); - mPowerManager.reboot("reboot"); - } catch (Exception e) { - e.printStackTrace(); - } - } - }; - - public void onStateOrProgress(int message, int error, Object info) - { - Log.v(TAG, "onStateOrProgress: " + "message: " + message + " error:" + error + " info: " + info ); - switch (message) { - case STATE_IN_CHECKED: - onStateChangeUI(message); - mState = STATE_IN_CHECKED; - onStateInChecked(error, info); - break; - case STATE_IN_DOWNLOADING: - onStateChangeUI(message); - mState = STATE_IN_DOWNLOADING; - onStateDownload(error, info); - break; - case STATE_IN_UPGRADING: - onStateChangeUI(message); - mState = STATE_IN_UPGRADING; - onStateUpgrade(error, info); - break; - case MESSAGE_DOWNLOAD_PROGRESS: - case MESSAGE_VERIFY_PROGRESS: - onProgress(message, error, info); - break; - case MESSAGE_WAIT_REBOOT: - mHandler.sendEmptyMessageDelayed(WAIT_REBOOT,0); - break; - } - } - - // this state change function only change - // Attributes of UI elements - // other will control the model(download). - void onStateChangeUI(int newstate) - { - mState = newstate; - if (newstate == STATE_IN_IDLE) { - mHandler.sendEmptyMessageDelayed(IDLE,0); - }else if (newstate == STATE_IN_CHECKED) { - mHandler.sendEmptyMessageDelayed(CHECKED,0); - }else if (newstate == STATE_IN_DOWNLOADING) { - // from start download, it start hide the version again. - mHandler.sendEmptyMessageDelayed(DOWNLOADING,0); - } - } - - void onStateUpgrade(int error, Object info) { - - if (error == ERROR_PACKAGE_VERIFY_FAILED) { - Log.v(TAG, "package verify failed, signaure not match"); - mMessageTextView.post(new Runnable() { - public void run() { - mMessageTextView.setText(getText(R.string.error_package_verify_failed)); - } - }); - // meet error in Verify, fall back to check. - // TODO which state should ? - } else if (error == ERROR_PACKAGE_INSTALL_FAILED) { - mMessageTextView.post(new Runnable() { - public void run() { - mMessageTextView.setText(getText(R.string.error_package_install_failed)); - } - }); - } - } - - void onProgress(int message, int error, Object info) { - final Long progress = new Long((Long)info); - mDownloadProgress.post(new Runnable() { - public void run() { - mDownloadProgress.setProgress(progress.intValue()); - } - }); - - Log.v(TAG, "progress : " + progress); - if (message == MESSAGE_DOWNLOAD_PROGRESS) { - onStateChangeUI(STATE_IN_DOWNLOADING); - mMessageTextView.post(new Runnable() { - - public void run() { - mMessageTextView.setText(getText(R.string.download_upgrade_package)); - } - }); - } else if (message == MESSAGE_VERIFY_PROGRESS) { - onStateChangeUI(STATE_IN_UPGRADING); - mMessageTextView.post(new Runnable() { - public void run() { - mMessageTextView.setText(getText(R.string.verify_package)); - } - }); - } - } - - void onStateDownload(int error, Object info) { - if (error == ERROR_CANNOT_FIND_SERVER) { - // in this case, the build.prop already found but the server don't have upgrade package - // report as "Server Error: Not have upgrade package"; - mMessageTextView.post(new Runnable() { - - public void run() { - mMessageTextView.setText(getText(R.string.error_server_no_package)); - } - }); - } else if (error == ERROR_WRITE_FILE_ERROR) { - mMessageTextView.post(new Runnable() { - - public void run() { - mMessageTextView.setText(getText(R.string.error_write_file)); - mUpgradeButton.setVisibility(View.VISIBLE); - } - }); - onStateChangeUI(STATE_IN_CHECKED); - } - - if (error == 0) { - // success download, let try to start with install package... - // we should already in another thread, no needs to create a thread. - mOTAManager.startInstallUpgradePackage(); - } - } - - public static String byteCountToDisplaySize(long bytes, boolean si) { - int unit = si ? 1000 : 1024; - if (bytes < unit) return bytes + " B"; - int exp = (int) (Math.log(bytes) / Math.log(unit)); - String pre = (si ? "KMGTPE" : "KMGTPE").charAt(exp - 1) + (si ? "" : "i"); - return String.format("%.1f %sB", bytes / Math.pow(unit, exp), pre); - } - - void onStateInChecked(int error, Object info) { - mSpinner.post(new Runnable() { - public void run() { - mSpinner.setVisibility(View.INVISIBLE); - } - }); - - if (error == 0) { - // return no error, usually means have a version info from remote server, release name is in @info - // needs check here whether the local version is newer then remote version - if (mOTAManager.compareLocalVersionToServer() == OTAServerManager.OtaTypeSelect.NONE) { - // we are already latest... - mMessageTextView.post(new Runnable() { - public void run() { - mMessageTextView.setText(Build.VERSION.RELEASE + ", " + Build.ID + "\n" + getText(R.string.already_up_to_date)); - mVersionTextView.setVisibility(View.INVISIBLE); - } - }); - - } else { - final BuildPropParser parser = (BuildPropParser) info; - final long bytes = mOTAManager.getUpgradePackageSize(); - mMessageTextView.post(new Runnable() { - public void run() { - onStateChangeUI(STATE_IN_CHECKED); - mMessageTextView.setText(getText(R.string.have_new)); - - if (bytes > 0) - if (parser != null) { - mVersionTextView.setText(getText(R.string.version) + ":" + - parser.getProp("ro.build.id") + "\n" + - getText(R.string.full_version) + ":" + - parser.getProp("ro.build.description") + "\n"); - } - mUpgradeButton.setVisibility(View.VISIBLE); - if (mOTAManager.ab_slot()) { - mDiffUpgradeButton.setVisibility(View.VISIBLE); - } - if (mOTAManager.compareLocalVersionToServer() == OTAServerManager.OtaTypeSelect.BOTH_OTA) { - mUpgradeButton.setEnabled(true); - mDiffUpgradeButton.setEnabled(true); - } else if (mOTAManager.compareLocalVersionToServer() == OTAServerManager.OtaTypeSelect.FULL_OTA) { - mUpgradeButton.setEnabled(true); - mDiffUpgradeButton.setEnabled(false); - } else if (mOTAManager.compareLocalVersionToServer() == OTAServerManager.OtaTypeSelect.DIFF_OTA) { - mUpgradeButton.setEnabled(false); - mDiffUpgradeButton.setEnabled(true); - } - } - }); - } - } else if (error == ERROR_WIFI_NOT_AVALIBLE) { - mHandler.sendEmptyMessageDelayed(WIFI_NOT_AVALIBLE,0); - } else if (error == ERROR_CANNOT_FIND_SERVER) { - mHandler.sendEmptyMessageDelayed(CANNOT_FIND_SERVER,0); - } else if (error == ERROR_WRITE_FILE_ERROR ) { - mHandler.sendEmptyMessageDelayed(WRITE_FILE_ERROR,0); - } - } - + void onStateDownload(int error, Object info) { + if (error == ERROR_CANNOT_FIND_SERVER) { + // in this case, the build.prop already found but the server don't have upgrade package + // report as "Server Error: Not have upgrade package"; + mMessageTextView.post( + new Runnable() { + + public void run() { + mMessageTextView.setText(getText(R.string.error_server_no_package)); + } + }); + } else if (error == ERROR_WRITE_FILE_ERROR) { + mMessageTextView.post( + new Runnable() { + + public void run() { + mMessageTextView.setText(getText(R.string.error_write_file)); + mUpgradeButton.setVisibility(View.VISIBLE); + } + }); + onStateChangeUI(STATE_IN_CHECKED); + } + + if (error == 0) { + // success download, let try to start with install package... + // we should already in another thread, no needs to create a thread. + mOTAManager.startInstallUpgradePackage(); + } + } + + public static String byteCountToDisplaySize(long bytes, boolean si) { + int unit = si ? 1000 : 1024; + if (bytes < unit) return bytes + " B"; + int exp = (int) (Math.log(bytes) / Math.log(unit)); + String pre = (si ? "KMGTPE" : "KMGTPE").charAt(exp - 1) + (si ? "" : "i"); + return String.format("%.1f %sB", bytes / Math.pow(unit, exp), pre); + } + + void onStateInChecked(int error, Object info) { + mSpinner.post( + new Runnable() { + public void run() { + mSpinner.setVisibility(View.INVISIBLE); + } + }); + + if (error == 0) { + // return no error, usually means have a version info from remote server, release name + // is in @info + // needs check here whether the local version is newer then remote version + if (mOTAManager.compareLocalVersionToServer() == OTAServerManager.OtaTypeSelect.NONE) { + // we are already latest... + mMessageTextView.post( + new Runnable() { + public void run() { + mMessageTextView.setText( + Build.VERSION.RELEASE + + ", " + + Build.ID + + "\n" + + getText(R.string.already_up_to_date)); + mVersionTextView.setVisibility(View.INVISIBLE); + } + }); + + } else { + final BuildPropParser parser = (BuildPropParser) info; + final long bytes = mOTAManager.getUpgradePackageSize(); + mMessageTextView.post( + new Runnable() { + public void run() { + onStateChangeUI(STATE_IN_CHECKED); + mMessageTextView.setText(getText(R.string.have_new)); + + if (bytes > 0) + if (parser != null) { + mVersionTextView.setText( + getText(R.string.version) + + ":" + + parser.getProp("ro.build.id") + + "\n" + + getText(R.string.full_version) + + ":" + + parser.getProp("ro.build.description") + + "\n"); + } + mUpgradeButton.setVisibility(View.VISIBLE); + if (mOTAManager.ab_slot()) { + mDiffUpgradeButton.setVisibility(View.VISIBLE); + } + if (mOTAManager.compareLocalVersionToServer() + == OTAServerManager.OtaTypeSelect.BOTH_OTA) { + mUpgradeButton.setEnabled(true); + mDiffUpgradeButton.setEnabled(true); + } else if (mOTAManager.compareLocalVersionToServer() + == OTAServerManager.OtaTypeSelect.FULL_OTA) { + mUpgradeButton.setEnabled(true); + mDiffUpgradeButton.setEnabled(false); + } else if (mOTAManager.compareLocalVersionToServer() + == OTAServerManager.OtaTypeSelect.DIFF_OTA) { + mUpgradeButton.setEnabled(false); + mDiffUpgradeButton.setEnabled(true); + } + } + }); + } + } else if (error == ERROR_WIFI_NOT_AVALIBLE) { + mHandler.sendEmptyMessageDelayed(WIFI_NOT_AVALIBLE, 0); + } else if (error == ERROR_CANNOT_FIND_SERVER) { + mHandler.sendEmptyMessageDelayed(CANNOT_FIND_SERVER, 0); + } else if (error == ERROR_WRITE_FILE_ERROR) { + mHandler.sendEmptyMessageDelayed(WRITE_FILE_ERROR, 0); + } + } } diff --git a/HdmiDualVideo/src/com/freescale/HdmiDualVideo/HdmiApplication.java b/HdmiDualVideo/src/com/freescale/HdmiDualVideo/HdmiApplication.java index 3e7066f..14dd2be 100755 --- a/HdmiDualVideo/src/com/freescale/HdmiDualVideo/HdmiApplication.java +++ b/HdmiDualVideo/src/com/freescale/HdmiDualVideo/HdmiApplication.java @@ -15,60 +15,32 @@ * limitations under the License. */ - package com.freescale.HdmiDualVideo; -import android.widget.VideoView; - -import android.os.AsyncTask; +import android.app.Application; +import android.app.Presentation; +import android.content.Context; +import android.content.res.Resources; +import android.graphics.Color; +import android.media.MediaPlayer; +import android.media.MediaRouter; +import android.media.MediaRouter.RouteInfo; +import android.net.Uri; import android.os.Bundle; import android.os.Handler; import android.os.Message; +import android.os.SystemProperties; import android.util.Log; -import android.media.MediaPlayer; -import android.media.MediaPlayer.OnCompletionListener; -import android.media.MediaPlayer.OnErrorListener; -import android.media.MediaPlayer.OnPreparedListener; -import android.media.MediaRouter.RouteInfo; -import android.media.MediaRouter; -import android.app.Application; -import android.app.Presentation; -import java.io.File; -import java.io.FilenameFilter; -import android.os.Bundle; -import java.util.List; -import java.util.ArrayList; -import android.net.Uri; -import android.widget.ImageButton; -import android.widget.ImageView; -import android.widget.ArrayAdapter; -import android.widget.Spinner; import android.view.Display; -import android.widget.AdapterView.OnItemSelectedListener; -import android.widget.AdapterView; -import android.media.ThumbnailUtils; -import android.provider.MediaStore; -import android.content.Context; -import android.content.BroadcastReceiver; -import android.content.Intent; -import android.content.IntentFilter; -import android.view.WindowManager; -import android.view.MenuItem; import android.view.View; -import android.view.View.OnClickListener; import android.view.WindowManager; -import android.webkit.WebView; -import android.widget.Button; import android.widget.ProgressBar; import android.widget.TextView; import android.widget.VideoView; -import android.os.SystemProperties; -import android.content.res.Resources; -import android.graphics.Color; +import java.io.File; -public class HdmiApplication extends Application -{ +public class HdmiApplication extends Application { private static final String TAG = "HdmiApplication"; private MediaRouter mMediaRouter = null; private DemoPresentation mPresentation = null; @@ -92,43 +64,45 @@ public DemoPresentation getPresentation() { public void onCreate() { super.onCreate(); - mMediaRouter = (MediaRouter)getSystemService(Context.MEDIA_ROUTER_SERVICE); + mMediaRouter = (MediaRouter) getSystemService(Context.MEDIA_ROUTER_SERVICE); mMediaRouter.addCallback(MediaRouter.ROUTE_TYPE_LIVE_VIDEO, mMediaRouterCallback); updatePresentation(); } private final MediaRouter.SimpleCallback mMediaRouterCallback = new MediaRouter.SimpleCallback() { - @Override - public void onRouteSelected(MediaRouter router, int type, RouteInfo info) { - Log.w(TAG, "onRouteSelected: type=" + type + ", info=" + info); - updatePresentation(); - } + @Override + public void onRouteSelected(MediaRouter router, int type, RouteInfo info) { + Log.w(TAG, "onRouteSelected: type=" + type + ", info=" + info); + updatePresentation(); + } - @Override - public void onRouteUnselected(MediaRouter router, int type, RouteInfo info) { - Log.w(TAG, "onRouteUnselected: type=" + type + ", info=" + info); - updatePresentation(); - } + @Override + public void onRouteUnselected(MediaRouter router, int type, RouteInfo info) { + Log.w(TAG, "onRouteUnselected: type=" + type + ", info=" + info); + updatePresentation(); + } - @Override - public void onRoutePresentationDisplayChanged(MediaRouter router, RouteInfo info) { - Log.w(TAG, "onRoutePresentationDisplayChanged: info=" + info); - updatePresentation(); - } - }; + @Override + public void onRoutePresentationDisplayChanged(MediaRouter router, RouteInfo info) { + Log.w(TAG, "onRoutePresentationDisplayChanged: info=" + info); + updatePresentation(); + } + }; private void updatePresentation() { // Get the current route and its presentation display. - MediaRouter.RouteInfo route = mMediaRouter.getSelectedRoute( - MediaRouter.ROUTE_TYPE_LIVE_VIDEO); + MediaRouter.RouteInfo route = + mMediaRouter.getSelectedRoute(MediaRouter.ROUTE_TYPE_LIVE_VIDEO); Display presentationDisplay = route != null ? route.getPresentationDisplay() : null; // Dismiss the current presentation if the display has changed. if (mPresentation != null && mPresentation.getDisplay() != presentationDisplay) { - Log.w(TAG, "Dismissing presentation because the current route no longer " - + "has a presentation display."); - //mPresentation.stopVideo(); + Log.w( + TAG, + "Dismissing presentation because the current route no longer " + + "has a presentation display."); + // mPresentation.stopVideo(); if (mListener != null) { mListener.onPresentationChanged(false); } @@ -142,31 +116,32 @@ private void updatePresentation() { mPresentation = new DemoPresentation(this, presentationDisplay); try { WindowManager.LayoutParams l = mPresentation.getWindow().getAttributes(); - //l.type = WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW + 100; + // l.type = WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW + 100; l.type = WindowManager.LayoutParams.TYPE_SYSTEM_ALERT; mPresentation.show(); if (mListener != null) { mListener.onPresentationChanged(true); } - }catch(WindowManager.InvalidDisplayException ex) { - Log.w(TAG, "Couldn't show presentation! Display was removed in " - + "the meantime.", ex); - mPresentation = null; - } + } catch (WindowManager.InvalidDisplayException ex) { + Log.w( + TAG, + "Couldn't show presentation! Display was removed in " + "the meantime.", + ex); + mPresentation = null; + } } } /** * The presentation to show on the secondary display. - *

- * Note that this display may have different metrics from the display on which - * the main activity is showing so we must be careful to use the presentation's - * own {@link Context} whenever we load resources. - *

+ * + *

Note that this display may have different metrics from the display on which the main + * activity is showing so we must be careful to use the presentation's own {@link Context} + * whenever we load resources. */ - public final class DemoPresentation extends Presentation { - private VideoView mvideoview1; - private VideoView mvideoview2; + public final class DemoPresentation extends Presentation { + private VideoView mvideoview1; + private VideoView mvideoview2; private String mVideoFile1 = ""; private String mVideoFile2 = ""; private Uri mUri1; @@ -179,7 +154,7 @@ public final class DemoPresentation extends Presentation { private boolean mVideo2Created = false; private Handler mHandler = new MainHandler(); private final int UPDATE = 3580; - private final int CREAT_SECOND_VIDEO = 3589; + private final int CREAT_SECOND_VIDEO = 3589; public VideoView getMvideoview1() { return mvideoview1; @@ -217,60 +192,70 @@ private class MainHandler extends Handler { @Override public void handleMessage(Message msg) { switch (msg.what) { - case UPDATE: { - getmProgress1().setProgress(mvideoview1.getCurrentPosition()); - getmProgress2().setProgress(mvideoview2.getCurrentPosition()); - getTextView1().setText("FullScreen: " + mvideoview1.getCurrentPosition()/1000 + "s" - + " " + "SmallScreen: " + mvideoview2.getCurrentPosition()/1000 + "s"); - getTextView1().setBackgroundColor(Color.argb(55, 255, 255, 255)); - getTextView1().setTextColor(Color.argb(150, 105, 200, 255)); - break; + case UPDATE: + { + getmProgress1().setProgress(mvideoview1.getCurrentPosition()); + getmProgress2().setProgress(mvideoview2.getCurrentPosition()); + getTextView1() + .setText( + "FullScreen: " + + mvideoview1.getCurrentPosition() / 1000 + + "s" + + " " + + "SmallScreen: " + + mvideoview2.getCurrentPosition() / 1000 + + "s"); + getTextView1().setBackgroundColor(Color.argb(55, 255, 255, 255)); + getTextView1().setTextColor(Color.argb(150, 105, 200, 255)); + break; } - case CREAT_SECOND_VIDEO: - mvideoview2 = (VideoView)findViewById(R.id.videoview2); - if(mVideoFile2.contentEquals("blank")) - { - Log.i(TAG, "VideoFile:blank "); - mvideoview2.setVisibility(View.INVISIBLE); - }else{ - SystemProperties.set("rw.VIDEO_RENDER_NAME", "video_render.surface"); - mUri2 = Uri.fromFile(new File(mVideoFile2)); - mvideoview2.setVideoURI(mUri2); - mvideoview2.requestFocus(); - mvideoview2.start(); - Log.i(TAG, "VideoFile= " + mUri2); - - mvideoview2.setOnCompletionListener(new MediaPlayer.OnCompletionListener(){ - @Override - public void onCompletion(MediaPlayer mp) { - SystemProperties.set("rw.VIDEO_RENDER_NAME", "video_render.surface"); - mvideoview2.start(); - } - }); - mvideoview2.setOnErrorListener(new MediaPlayer.OnErrorListener(){ - @Override - public boolean onError(MediaPlayer mp, int what, int extra){ - mUri2 = Uri.fromFile(new File(mVideoFile2)); - mvideoview2.setVideoURI(mUri2); - mvideoview2.start(); - return true; - } - }); - } + case CREAT_SECOND_VIDEO: + mvideoview2 = (VideoView) findViewById(R.id.videoview2); + if (mVideoFile2.contentEquals("blank")) { + Log.i(TAG, "VideoFile:blank "); + mvideoview2.setVisibility(View.INVISIBLE); + } else { + SystemProperties.set("rw.VIDEO_RENDER_NAME", "video_render.surface"); + mUri2 = Uri.fromFile(new File(mVideoFile2)); + mvideoview2.setVideoURI(mUri2); + mvideoview2.requestFocus(); + mvideoview2.start(); + Log.i(TAG, "VideoFile= " + mUri2); + + mvideoview2.setOnCompletionListener( + new MediaPlayer.OnCompletionListener() { + @Override + public void onCompletion(MediaPlayer mp) { + SystemProperties.set( + "rw.VIDEO_RENDER_NAME", "video_render.surface"); + mvideoview2.start(); + } + }); + mvideoview2.setOnErrorListener( + new MediaPlayer.OnErrorListener() { + @Override + public boolean onError( + MediaPlayer mp, int what, int extra) { + mUri2 = Uri.fromFile(new File(mVideoFile2)); + mvideoview2.setVideoURI(mUri2); + mvideoview2.start(); + return true; + } + }); + } break; default: - break; - } + break; } + } } public DemoPresentation(Context context, Display display) { super(context, display); } - @Override protected void onCreate(Bundle savedInstanceState) { // Be sure to call the super class. @@ -284,44 +269,44 @@ protected void onCreate(Bundle savedInstanceState) { setContentView(R.layout.presentation_with_media_router_content); // Set up the surface view for visual interest. - mvideoview1 = (VideoView)findViewById(R.id.videoview1); + mvideoview1 = (VideoView) findViewById(R.id.videoview1); mProgress1 = (ProgressBar) findViewById(R.id.progressBar1); mProgress2 = (ProgressBar) findViewById(R.id.progressBar2); - mTextView1 = (TextView)findViewById(R.id.textView1); - new Thread(new Runnable() { - @Override - public void run() { - while (flag) { - if(mVideo2Created == true) { - mHandler.sendEmptyMessage(UPDATE); - } - try { - Thread.sleep(1000); - } catch (InterruptedException e) { - e.printStackTrace(); - } - - if (mVideoRunning) { - if(mVideo2Created == false) { - mVideo2Created = true; - mHandler.sendEmptyMessage(CREAT_SECOND_VIDEO); - } - } - } - } - }).start(); + mTextView1 = (TextView) findViewById(R.id.textView1); + new Thread( + new Runnable() { + @Override + public void run() { + while (flag) { + if (mVideo2Created == true) { + mHandler.sendEmptyMessage(UPDATE); + } + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + + if (mVideoRunning) { + if (mVideo2Created == false) { + mVideo2Created = true; + mHandler.sendEmptyMessage(CREAT_SECOND_VIDEO); + } + } + } + } + }) + .start(); } - public TextView getTextView1() { - return mTextView1; + return mTextView1; } public void setTextView1(TextView textView1) { - this.mTextView1 = textView1; + this.mTextView1 = textView1; } - @Override protected void onStop() { super.onStop(); @@ -330,45 +315,45 @@ protected void onStop() { flag = false; } - public void startVideo(String video1, String video2) { if (mVideoRunning == true) { mvideoview1.stopPlayback(); mvideoview2.stopPlayback(); - mVideo2Created = false; + mVideo2Created = false; } mVideoRunning = true; mVideoFile1 = video1; mVideoFile2 = video2; Log.i(TAG, "startVideo: video1=" + ", video2=" + video2); - if (mVideoFile1.contentEquals("blank")) - { + if (mVideoFile1.contentEquals("blank")) { Log.i(TAG, "VideoFile1:blank "); mvideoview1.setVisibility(View.INVISIBLE); - }else{ + } else { SystemProperties.set("rw.VIDEO_RENDER_NAME", "video_render.ipulib"); mUri1 = Uri.fromFile(new File(mVideoFile1)); mvideoview1.setVideoURI(mUri1); mvideoview1.requestFocus(); - mvideoview1.start(); + mvideoview1.start(); Log.i(TAG, "VideoFile1= " + mUri1); - mvideoview1.setOnCompletionListener(new MediaPlayer.OnCompletionListener(){ - @Override - public void onCompletion(MediaPlayer mp) { - SystemProperties.set("rw.VIDEO_RENDER_NAME", "video_render.ipulib"); - mvideoview1.start(); - } - }); - mvideoview1.setOnErrorListener(new MediaPlayer.OnErrorListener(){ - @Override - public boolean onError(MediaPlayer mp, int what, int extra){ - mUri1 = Uri.fromFile(new File(mVideoFile1)); - mvideoview1.setVideoURI(mUri1); - mvideoview1.start(); - return true; - } - }); + mvideoview1.setOnCompletionListener( + new MediaPlayer.OnCompletionListener() { + @Override + public void onCompletion(MediaPlayer mp) { + SystemProperties.set("rw.VIDEO_RENDER_NAME", "video_render.ipulib"); + mvideoview1.start(); + } + }); + mvideoview1.setOnErrorListener( + new MediaPlayer.OnErrorListener() { + @Override + public boolean onError(MediaPlayer mp, int what, int extra) { + mUri1 = Uri.fromFile(new File(mVideoFile1)); + mvideoview1.setVideoURI(mUri1); + mvideoview1.start(); + return true; + } + }); } } @@ -376,24 +361,22 @@ public void pauseVideo() { if (mVideoRunning) { mVideoRunning = false; mvideoview1.pause(); - if(mVideo2Created == true) - mvideoview2.pause(); + if (mVideo2Created == true) mvideoview2.pause(); } } public void resumeVideo() { - if (mVideoRunning == false) { + if (mVideoRunning == false) { mVideoRunning = true; mvideoview1.start(); - if(mVideo2Created == true) - mvideoview2.start(); + if (mVideo2Created == true) mvideoview2.start(); } } public void stopVideo() { if (mVideoRunning) { mVideoRunning = false; - mVideo2Created = false; + mVideo2Created = false; mvideoview1.stopPlayback(); mvideoview2.stopPlayback(); } @@ -405,4 +388,3 @@ public void onDisplayRemoved() { } } } - diff --git a/HdmiDualVideo/src/com/freescale/HdmiDualVideo/MainActivity.java b/HdmiDualVideo/src/com/freescale/HdmiDualVideo/MainActivity.java index 5f367fa..1582602 100755 --- a/HdmiDualVideo/src/com/freescale/HdmiDualVideo/MainActivity.java +++ b/HdmiDualVideo/src/com/freescale/HdmiDualVideo/MainActivity.java @@ -15,36 +15,28 @@ * limitations under the License. */ - package com.freescale.HdmiDualVideo; -import java.io.File; - -import java.io.FilenameFilter; -import java.util.ArrayList; -import java.util.List; - -import android.os.Bundle; - - import android.app.Activity; -import android.content.Intent; -import android.graphics.Color; +import android.os.Bundle; import android.util.Log; import android.view.Menu; import android.view.View; import android.view.View.OnClickListener; import android.widget.*; -import android.app.Presentation; -public class MainActivity extends Activity implements OnClickListener, HdmiApplication.Callback - { +import java.io.File; +import java.io.FilenameFilter; +import java.util.ArrayList; +import java.util.List; + +public class MainActivity extends Activity implements OnClickListener, HdmiApplication.Callback { private HdmiApplication mHdmiApp; private HdmiApplication.DemoPresentation mPresentation; private Button start_button; private Button stop_button; private String[] FileNameInDir = null; - private List VideoFileList = null; + private List VideoFileList = null; private Spinner s0; private Spinner s1; private TextView textview0; @@ -55,103 +47,103 @@ public class MainActivity extends Activity implements OnClickListener, HdmiAppli private boolean mVideoRunning = false; private TextView textView; - public void onPresentationChanged(boolean change) { + public void onPresentationChanged(boolean change) { mPresentation = mHdmiApp.getPresentation(); - Log.i(TAG,"onPresentationChanged:" + change); + Log.i(TAG, "onPresentationChanged:" + change); if (change) { - //create - }else { - //dismiss + // create + } else { + // dismiss } - } - - -@Override -protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_main); - - textview0 = (TextView)findViewById(R.id.textview0); - textview1 = (TextView)findViewById(R.id.textview1); - textview0.setText("SmallScreen"); - textview1.setText("FullScreen"); + } - File fileDir; - int fileIndex = 0; - fileDir = new File("/storage/emulated/legacy/"); - FilenameFilter filter = new FilenameFilter() { - public boolean accept(File dir, String name) { - return name.endsWith(".mp4")||name.endsWith(".m4v")||name.endsWith(".avi"); - } - }; + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + + textview0 = (TextView) findViewById(R.id.textview0); + textview1 = (TextView) findViewById(R.id.textview1); + textview0.setText("SmallScreen"); + textview1.setText("FullScreen"); + + File fileDir; + int fileIndex = 0; + fileDir = new File("/storage/emulated/legacy/"); + FilenameFilter filter = + new FilenameFilter() { + public boolean accept(File dir, String name) { + return name.endsWith(".mp4") + || name.endsWith(".m4v") + || name.endsWith(".avi"); + } + }; FileNameInDir = fileDir.list(filter); - Log.i(TAG,"FileNameInDir.length:" + FileNameInDir.length); + Log.i(TAG, "FileNameInDir.length:" + FileNameInDir.length); VideoFileList = new ArrayList(); - for(fileIndex = 0;fileIndex < FileNameInDir.length;fileIndex++){ - VideoFileList.add("/storage/emulated/legacy" + "/" + FileNameInDir[fileIndex]); + for (fileIndex = 0; fileIndex < FileNameInDir.length; fileIndex++) { + VideoFileList.add("/storage/emulated/legacy" + "/" + FileNameInDir[fileIndex]); } VideoFileList.add("blank"); -// VideoFileList.add("/storage/emulated/legacy" + "/" + FileNameInDir[FileNameInDir.length]); - - ArrayAdapter adapter0 = new ArrayAdapter(this, android.R.layout.simple_spinner_dropdown_item, VideoFileList); - ArrayAdapter adapter1 = new ArrayAdapter(this, android.R.layout.simple_spinner_dropdown_item, VideoFileList); - s0 = (Spinner)findViewById(R.id.spinner0); + // VideoFileList.add("/storage/emulated/legacy" + "/" + + // FileNameInDir[FileNameInDir.length]); + + ArrayAdapter adapter0 = + new ArrayAdapter( + this, android.R.layout.simple_spinner_dropdown_item, VideoFileList); + ArrayAdapter adapter1 = + new ArrayAdapter( + this, android.R.layout.simple_spinner_dropdown_item, VideoFileList); + s0 = (Spinner) findViewById(R.id.spinner0); adapter0.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); s0.setAdapter(adapter0); s1 = (Spinner) findViewById(R.id.spinner1); adapter1.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); s1.setAdapter(adapter1); - start_button = (Button)findViewById(R.id.start); - stop_button = (Button)findViewById(R.id.stop); + start_button = (Button) findViewById(R.id.start); + stop_button = (Button) findViewById(R.id.stop); start_button.setOnClickListener(MainActivity.this); stop_button.setOnClickListener(MainActivity.this); - mHdmiApp = (HdmiApplication)getApplication(); + mHdmiApp = (HdmiApplication) getApplication(); mHdmiApp.addListener(this); mPresentation = mHdmiApp.getPresentation(); -} - + } -@Override -public boolean onCreateOptionsMenu(Menu menu) { -// Inflate the menu; this adds items to the action bar if it is present. - getMenuInflater().inflate(R.menu.main, menu); - return true; -} + @Override + public boolean onCreateOptionsMenu(Menu menu) { + // Inflate the menu; this adds items to the action bar if it is present. + getMenuInflater().inflate(R.menu.main, menu); + return true; + } + @Override + public void onClick(View v) { + switch (v.getId()) { + case R.id.start: + int selectIndex0; + int selectIndex1; + selectIndex0 = s0.getSelectedItemPosition(); + selectIndex1 = s1.getSelectedItemPosition(); + if (selectIndex0 == FileNameInDir.length) { + videoFile0 = "blank"; + } else { + videoFile0 = "/storage/emulated/legacy" + "/" + FileNameInDir[selectIndex0]; + } -@Override -public void onClick(View v) { - switch(v.getId()) - { - case R.id.start: - int selectIndex0; - int selectIndex1; - selectIndex0 = s0.getSelectedItemPosition(); - selectIndex1 = s1.getSelectedItemPosition(); - if (selectIndex0 == FileNameInDir.length) - { - videoFile0 = "blank"; - }else{ - videoFile0 = "/storage/emulated/legacy" + "/" + FileNameInDir[selectIndex0]; - } - - if (selectIndex1 == FileNameInDir.length ) - { - videoFile1 = "blank"; - }else{ - videoFile1 = "/storage/emulated/legacy" + "/" + FileNameInDir[selectIndex1]; - } + if (selectIndex1 == FileNameInDir.length) { + videoFile1 = "blank"; + } else { + videoFile1 = "/storage/emulated/legacy" + "/" + FileNameInDir[selectIndex1]; + } - mPresentation.startVideo(videoFile1, videoFile0); - break; - case R.id.stop: - mPresentation.stopVideo(); - break; - default: - break; + mPresentation.startVideo(videoFile1, videoFile0); + break; + case R.id.stop: + mPresentation.stopVideo(); + break; + default: + break; + } } - -} - } diff --git a/MultiCamera/app/generated/data_binding_base_class_source_out/debug/out/com/nxp/multicamera/databinding/ActivityCameraBinding.java b/MultiCamera/app/generated/data_binding_base_class_source_out/debug/out/com/nxp/multicamera/databinding/ActivityCameraBinding.java index 6058ad0..ded8c0f 100644 --- a/MultiCamera/app/generated/data_binding_base_class_source_out/debug/out/com/nxp/multicamera/databinding/ActivityCameraBinding.java +++ b/MultiCamera/app/generated/data_binding_base_class_source_out/debug/out/com/nxp/multicamera/databinding/ActivityCameraBinding.java @@ -5,64 +5,62 @@ import android.view.View; import android.view.ViewGroup; import android.widget.FrameLayout; + import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.constraintlayout.widget.ConstraintLayout; import androidx.viewbinding.ViewBinding; + import com.nxp.multicamera.R; -import java.lang.NullPointerException; -import java.lang.Override; -import java.lang.String; public final class ActivityCameraBinding implements ViewBinding { - @NonNull - private final ConstraintLayout rootView; + @NonNull private final ConstraintLayout rootView; - @NonNull - public final FrameLayout container; + @NonNull public final FrameLayout container; - private ActivityCameraBinding(@NonNull ConstraintLayout rootView, - @NonNull FrameLayout container) { - this.rootView = rootView; - this.container = container; - } + private ActivityCameraBinding( + @NonNull ConstraintLayout rootView, @NonNull FrameLayout container) { + this.rootView = rootView; + this.container = container; + } - @Override - @NonNull - public ConstraintLayout getRoot() { - return rootView; - } + @Override + @NonNull + public ConstraintLayout getRoot() { + return rootView; + } - @NonNull - public static ActivityCameraBinding inflate(@NonNull LayoutInflater inflater) { - return inflate(inflater, null, false); - } + @NonNull + public static ActivityCameraBinding inflate(@NonNull LayoutInflater inflater) { + return inflate(inflater, null, false); + } - @NonNull - public static ActivityCameraBinding inflate(@NonNull LayoutInflater inflater, - @Nullable ViewGroup parent, boolean attachToParent) { - View root = inflater.inflate(R.layout.activity_camera, parent, false); - if (attachToParent) { - parent.addView(root); + @NonNull + public static ActivityCameraBinding inflate( + @NonNull LayoutInflater inflater, @Nullable ViewGroup parent, boolean attachToParent) { + View root = inflater.inflate(R.layout.activity_camera, parent, false); + if (attachToParent) { + parent.addView(root); + } + return bind(root); } - return bind(root); - } - @NonNull - public static ActivityCameraBinding bind(@NonNull View rootView) { - // The body of this method is generated in a way you would not otherwise write. - // This is done to optimize the compiled bytecode for size and performance. - int id; - missingId: { - id = R.id.container; - FrameLayout container = rootView.findViewById(id); - if (container == null) { - break missingId; - } + @NonNull + public static ActivityCameraBinding bind(@NonNull View rootView) { + // The body of this method is generated in a way you would not otherwise write. + // This is done to optimize the compiled bytecode for size and performance. + int id; + missingId: + { + id = R.id.container; + FrameLayout container = rootView.findViewById(id); + if (container == null) { + break missingId; + } - return new ActivityCameraBinding((ConstraintLayout) rootView, container); + return new ActivityCameraBinding((ConstraintLayout) rootView, container); + } + String missingId = rootView.getResources().getResourceName(id); + throw new NullPointerException("Missing required view with ID: ".concat(missingId)); } - String missingId = rootView.getResources().getResourceName(id); - throw new NullPointerException("Missing required view with ID: ".concat(missingId)); - } } diff --git a/MultiCamera/app/generated/data_binding_base_class_source_out/debug/out/com/nxp/multicamera/databinding/FragmentCamera2Binding.java b/MultiCamera/app/generated/data_binding_base_class_source_out/debug/out/com/nxp/multicamera/databinding/FragmentCamera2Binding.java index f17d009..22238d0 100644 --- a/MultiCamera/app/generated/data_binding_base_class_source_out/debug/out/com/nxp/multicamera/databinding/FragmentCamera2Binding.java +++ b/MultiCamera/app/generated/data_binding_base_class_source_out/debug/out/com/nxp/multicamera/databinding/FragmentCamera2Binding.java @@ -7,224 +7,231 @@ import android.widget.RelativeLayout; import android.widget.SeekBar; import android.widget.TextView; + import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.constraintlayout.widget.ConstraintLayout; import androidx.viewbinding.ViewBinding; + import com.nxp.multicamera.R; import com.nxp.multicamera.ui.AutoFitTextureView; -import java.lang.NullPointerException; -import java.lang.Override; -import java.lang.String; public final class FragmentCamera2Binding implements ViewBinding { - @NonNull - private final ConstraintLayout rootView; - - @NonNull - public final TextView camera1TextView; - - @NonNull - public final AutoFitTextureView camera1View; - - @NonNull - public final RelativeLayout camera1ViewLayout; - - @NonNull - public final TextView camera2TextView; - - @NonNull - public final AutoFitTextureView camera2View; - - @NonNull - public final RelativeLayout camera2ViewLayout; - - @NonNull - public final TextView logicalCameraTv; - - @NonNull - public final TextView multiCameraSupportTv; - - @NonNull - public final TextView physicalCameraTv; - - @NonNull - public final TextView textView; - - @NonNull - public final TextView textView0; - - @NonNull - public final TextView textView2; - - @NonNull - public final TextView textView3; - - @NonNull - public final TextView textView5; - - @NonNull - public final TextView totalCamera; - - @NonNull - public final SeekBar zoomBar; - - private FragmentCamera2Binding(@NonNull ConstraintLayout rootView, - @NonNull TextView camera1TextView, @NonNull AutoFitTextureView camera1View, - @NonNull RelativeLayout camera1ViewLayout, @NonNull TextView camera2TextView, - @NonNull AutoFitTextureView camera2View, @NonNull RelativeLayout camera2ViewLayout, - @NonNull TextView logicalCameraTv, @NonNull TextView multiCameraSupportTv, - @NonNull TextView physicalCameraTv, @NonNull TextView textView, @NonNull TextView textView0, - @NonNull TextView textView2, @NonNull TextView textView3, @NonNull TextView textView5, - @NonNull TextView totalCamera, @NonNull SeekBar zoomBar) { - this.rootView = rootView; - this.camera1TextView = camera1TextView; - this.camera1View = camera1View; - this.camera1ViewLayout = camera1ViewLayout; - this.camera2TextView = camera2TextView; - this.camera2View = camera2View; - this.camera2ViewLayout = camera2ViewLayout; - this.logicalCameraTv = logicalCameraTv; - this.multiCameraSupportTv = multiCameraSupportTv; - this.physicalCameraTv = physicalCameraTv; - this.textView = textView; - this.textView0 = textView0; - this.textView2 = textView2; - this.textView3 = textView3; - this.textView5 = textView5; - this.totalCamera = totalCamera; - this.zoomBar = zoomBar; - } - - @Override - @NonNull - public ConstraintLayout getRoot() { - return rootView; - } - - @NonNull - public static FragmentCamera2Binding inflate(@NonNull LayoutInflater inflater) { - return inflate(inflater, null, false); - } - - @NonNull - public static FragmentCamera2Binding inflate(@NonNull LayoutInflater inflater, - @Nullable ViewGroup parent, boolean attachToParent) { - View root = inflater.inflate(R.layout.fragment_camera_2, parent, false); - if (attachToParent) { - parent.addView(root); + @NonNull private final ConstraintLayout rootView; + + @NonNull public final TextView camera1TextView; + + @NonNull public final AutoFitTextureView camera1View; + + @NonNull public final RelativeLayout camera1ViewLayout; + + @NonNull public final TextView camera2TextView; + + @NonNull public final AutoFitTextureView camera2View; + + @NonNull public final RelativeLayout camera2ViewLayout; + + @NonNull public final TextView logicalCameraTv; + + @NonNull public final TextView multiCameraSupportTv; + + @NonNull public final TextView physicalCameraTv; + + @NonNull public final TextView textView; + + @NonNull public final TextView textView0; + + @NonNull public final TextView textView2; + + @NonNull public final TextView textView3; + + @NonNull public final TextView textView5; + + @NonNull public final TextView totalCamera; + + @NonNull public final SeekBar zoomBar; + + private FragmentCamera2Binding( + @NonNull ConstraintLayout rootView, + @NonNull TextView camera1TextView, + @NonNull AutoFitTextureView camera1View, + @NonNull RelativeLayout camera1ViewLayout, + @NonNull TextView camera2TextView, + @NonNull AutoFitTextureView camera2View, + @NonNull RelativeLayout camera2ViewLayout, + @NonNull TextView logicalCameraTv, + @NonNull TextView multiCameraSupportTv, + @NonNull TextView physicalCameraTv, + @NonNull TextView textView, + @NonNull TextView textView0, + @NonNull TextView textView2, + @NonNull TextView textView3, + @NonNull TextView textView5, + @NonNull TextView totalCamera, + @NonNull SeekBar zoomBar) { + this.rootView = rootView; + this.camera1TextView = camera1TextView; + this.camera1View = camera1View; + this.camera1ViewLayout = camera1ViewLayout; + this.camera2TextView = camera2TextView; + this.camera2View = camera2View; + this.camera2ViewLayout = camera2ViewLayout; + this.logicalCameraTv = logicalCameraTv; + this.multiCameraSupportTv = multiCameraSupportTv; + this.physicalCameraTv = physicalCameraTv; + this.textView = textView; + this.textView0 = textView0; + this.textView2 = textView2; + this.textView3 = textView3; + this.textView5 = textView5; + this.totalCamera = totalCamera; + this.zoomBar = zoomBar; } - return bind(root); - } - - @NonNull - public static FragmentCamera2Binding bind(@NonNull View rootView) { - // The body of this method is generated in a way you would not otherwise write. - // This is done to optimize the compiled bytecode for size and performance. - int id; - missingId: { - id = R.id.camera_1_textView; - TextView camera1TextView = rootView.findViewById(id); - if (camera1TextView == null) { - break missingId; - } - - id = R.id.camera1View; - AutoFitTextureView camera1View = rootView.findViewById(id); - if (camera1View == null) { - break missingId; - } - - id = R.id.camera1ViewLayout; - RelativeLayout camera1ViewLayout = rootView.findViewById(id); - if (camera1ViewLayout == null) { - break missingId; - } - - id = R.id.camera_2_textView; - TextView camera2TextView = rootView.findViewById(id); - if (camera2TextView == null) { - break missingId; - } - - id = R.id.camera2View; - AutoFitTextureView camera2View = rootView.findViewById(id); - if (camera2View == null) { - break missingId; - } - - id = R.id.camera2ViewLayout; - RelativeLayout camera2ViewLayout = rootView.findViewById(id); - if (camera2ViewLayout == null) { - break missingId; - } - - id = R.id.logicalCameraTv; - TextView logicalCameraTv = rootView.findViewById(id); - if (logicalCameraTv == null) { - break missingId; - } - - id = R.id.multiCameraSupportTv; - TextView multiCameraSupportTv = rootView.findViewById(id); - if (multiCameraSupportTv == null) { - break missingId; - } - - id = R.id.physicalCameraTv; - TextView physicalCameraTv = rootView.findViewById(id); - if (physicalCameraTv == null) { - break missingId; - } - - id = R.id.textView; - TextView textView = rootView.findViewById(id); - if (textView == null) { - break missingId; - } - - id = R.id.textView0; - TextView textView0 = rootView.findViewById(id); - if (textView0 == null) { - break missingId; - } - - id = R.id.textView2; - TextView textView2 = rootView.findViewById(id); - if (textView2 == null) { - break missingId; - } - - id = R.id.textView3; - TextView textView3 = rootView.findViewById(id); - if (textView3 == null) { - break missingId; - } - - id = R.id.textView5; - TextView textView5 = rootView.findViewById(id); - if (textView5 == null) { - break missingId; - } - - id = R.id.totalCamera; - TextView totalCamera = rootView.findViewById(id); - if (totalCamera == null) { - break missingId; - } - - id = R.id.zoomBar; - SeekBar zoomBar = rootView.findViewById(id); - if (zoomBar == null) { - break missingId; - } - - return new FragmentCamera2Binding((ConstraintLayout) rootView, camera1TextView, camera1View, - camera1ViewLayout, camera2TextView, camera2View, camera2ViewLayout, logicalCameraTv, - multiCameraSupportTv, physicalCameraTv, textView, textView0, textView2, textView3, - textView5, totalCamera, zoomBar); + + @Override + @NonNull + public ConstraintLayout getRoot() { + return rootView; + } + + @NonNull + public static FragmentCamera2Binding inflate(@NonNull LayoutInflater inflater) { + return inflate(inflater, null, false); + } + + @NonNull + public static FragmentCamera2Binding inflate( + @NonNull LayoutInflater inflater, @Nullable ViewGroup parent, boolean attachToParent) { + View root = inflater.inflate(R.layout.fragment_camera_2, parent, false); + if (attachToParent) { + parent.addView(root); + } + return bind(root); + } + + @NonNull + public static FragmentCamera2Binding bind(@NonNull View rootView) { + // The body of this method is generated in a way you would not otherwise write. + // This is done to optimize the compiled bytecode for size and performance. + int id; + missingId: + { + id = R.id.camera_1_textView; + TextView camera1TextView = rootView.findViewById(id); + if (camera1TextView == null) { + break missingId; + } + + id = R.id.camera1View; + AutoFitTextureView camera1View = rootView.findViewById(id); + if (camera1View == null) { + break missingId; + } + + id = R.id.camera1ViewLayout; + RelativeLayout camera1ViewLayout = rootView.findViewById(id); + if (camera1ViewLayout == null) { + break missingId; + } + + id = R.id.camera_2_textView; + TextView camera2TextView = rootView.findViewById(id); + if (camera2TextView == null) { + break missingId; + } + + id = R.id.camera2View; + AutoFitTextureView camera2View = rootView.findViewById(id); + if (camera2View == null) { + break missingId; + } + + id = R.id.camera2ViewLayout; + RelativeLayout camera2ViewLayout = rootView.findViewById(id); + if (camera2ViewLayout == null) { + break missingId; + } + + id = R.id.logicalCameraTv; + TextView logicalCameraTv = rootView.findViewById(id); + if (logicalCameraTv == null) { + break missingId; + } + + id = R.id.multiCameraSupportTv; + TextView multiCameraSupportTv = rootView.findViewById(id); + if (multiCameraSupportTv == null) { + break missingId; + } + + id = R.id.physicalCameraTv; + TextView physicalCameraTv = rootView.findViewById(id); + if (physicalCameraTv == null) { + break missingId; + } + + id = R.id.textView; + TextView textView = rootView.findViewById(id); + if (textView == null) { + break missingId; + } + + id = R.id.textView0; + TextView textView0 = rootView.findViewById(id); + if (textView0 == null) { + break missingId; + } + + id = R.id.textView2; + TextView textView2 = rootView.findViewById(id); + if (textView2 == null) { + break missingId; + } + + id = R.id.textView3; + TextView textView3 = rootView.findViewById(id); + if (textView3 == null) { + break missingId; + } + + id = R.id.textView5; + TextView textView5 = rootView.findViewById(id); + if (textView5 == null) { + break missingId; + } + + id = R.id.totalCamera; + TextView totalCamera = rootView.findViewById(id); + if (totalCamera == null) { + break missingId; + } + + id = R.id.zoomBar; + SeekBar zoomBar = rootView.findViewById(id); + if (zoomBar == null) { + break missingId; + } + + return new FragmentCamera2Binding( + (ConstraintLayout) rootView, + camera1TextView, + camera1View, + camera1ViewLayout, + camera2TextView, + camera2View, + camera2ViewLayout, + logicalCameraTv, + multiCameraSupportTv, + physicalCameraTv, + textView, + textView0, + textView2, + textView3, + textView5, + totalCamera, + zoomBar); + } + String missingId = rootView.getResources().getResourceName(id); + throw new NullPointerException("Missing required view with ID: ".concat(missingId)); } - String missingId = rootView.getResources().getResourceName(id); - throw new NullPointerException("Missing required view with ID: ".concat(missingId)); - } } diff --git a/MultiCamera/app/generated/data_binding_base_class_source_out/debug/out/com/nxp/multicamera/databinding/FragmentCameraBinding.java b/MultiCamera/app/generated/data_binding_base_class_source_out/debug/out/com/nxp/multicamera/databinding/FragmentCameraBinding.java index 4b1f84e..f1863e5 100644 --- a/MultiCamera/app/generated/data_binding_base_class_source_out/debug/out/com/nxp/multicamera/databinding/FragmentCameraBinding.java +++ b/MultiCamera/app/generated/data_binding_base_class_source_out/debug/out/com/nxp/multicamera/databinding/FragmentCameraBinding.java @@ -7,224 +7,231 @@ import android.widget.RelativeLayout; import android.widget.SeekBar; import android.widget.TextView; + import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.constraintlayout.widget.ConstraintLayout; import androidx.viewbinding.ViewBinding; + import com.nxp.multicamera.R; import com.nxp.multicamera.ui.AutoFitTextureView; -import java.lang.NullPointerException; -import java.lang.Override; -import java.lang.String; public final class FragmentCameraBinding implements ViewBinding { - @NonNull - private final ConstraintLayout rootView; - - @NonNull - public final TextView camera1TextView; - - @NonNull - public final AutoFitTextureView camera1View; - - @NonNull - public final RelativeLayout camera1ViewLayout; - - @NonNull - public final TextView camera2TextView; - - @NonNull - public final AutoFitTextureView camera2View; - - @NonNull - public final RelativeLayout camera2ViewLayout; - - @NonNull - public final TextView logicalCameraTv; - - @NonNull - public final TextView multiCameraSupportTv; - - @NonNull - public final TextView physicalCameraTv; - - @NonNull - public final TextView textView; - - @NonNull - public final TextView textView0; - - @NonNull - public final TextView textView2; - - @NonNull - public final TextView textView3; - - @NonNull - public final TextView textView5; - - @NonNull - public final TextView totalCamera; - - @NonNull - public final SeekBar zoomBar; - - private FragmentCameraBinding(@NonNull ConstraintLayout rootView, - @NonNull TextView camera1TextView, @NonNull AutoFitTextureView camera1View, - @NonNull RelativeLayout camera1ViewLayout, @NonNull TextView camera2TextView, - @NonNull AutoFitTextureView camera2View, @NonNull RelativeLayout camera2ViewLayout, - @NonNull TextView logicalCameraTv, @NonNull TextView multiCameraSupportTv, - @NonNull TextView physicalCameraTv, @NonNull TextView textView, @NonNull TextView textView0, - @NonNull TextView textView2, @NonNull TextView textView3, @NonNull TextView textView5, - @NonNull TextView totalCamera, @NonNull SeekBar zoomBar) { - this.rootView = rootView; - this.camera1TextView = camera1TextView; - this.camera1View = camera1View; - this.camera1ViewLayout = camera1ViewLayout; - this.camera2TextView = camera2TextView; - this.camera2View = camera2View; - this.camera2ViewLayout = camera2ViewLayout; - this.logicalCameraTv = logicalCameraTv; - this.multiCameraSupportTv = multiCameraSupportTv; - this.physicalCameraTv = physicalCameraTv; - this.textView = textView; - this.textView0 = textView0; - this.textView2 = textView2; - this.textView3 = textView3; - this.textView5 = textView5; - this.totalCamera = totalCamera; - this.zoomBar = zoomBar; - } - - @Override - @NonNull - public ConstraintLayout getRoot() { - return rootView; - } - - @NonNull - public static FragmentCameraBinding inflate(@NonNull LayoutInflater inflater) { - return inflate(inflater, null, false); - } - - @NonNull - public static FragmentCameraBinding inflate(@NonNull LayoutInflater inflater, - @Nullable ViewGroup parent, boolean attachToParent) { - View root = inflater.inflate(R.layout.fragment_camera, parent, false); - if (attachToParent) { - parent.addView(root); + @NonNull private final ConstraintLayout rootView; + + @NonNull public final TextView camera1TextView; + + @NonNull public final AutoFitTextureView camera1View; + + @NonNull public final RelativeLayout camera1ViewLayout; + + @NonNull public final TextView camera2TextView; + + @NonNull public final AutoFitTextureView camera2View; + + @NonNull public final RelativeLayout camera2ViewLayout; + + @NonNull public final TextView logicalCameraTv; + + @NonNull public final TextView multiCameraSupportTv; + + @NonNull public final TextView physicalCameraTv; + + @NonNull public final TextView textView; + + @NonNull public final TextView textView0; + + @NonNull public final TextView textView2; + + @NonNull public final TextView textView3; + + @NonNull public final TextView textView5; + + @NonNull public final TextView totalCamera; + + @NonNull public final SeekBar zoomBar; + + private FragmentCameraBinding( + @NonNull ConstraintLayout rootView, + @NonNull TextView camera1TextView, + @NonNull AutoFitTextureView camera1View, + @NonNull RelativeLayout camera1ViewLayout, + @NonNull TextView camera2TextView, + @NonNull AutoFitTextureView camera2View, + @NonNull RelativeLayout camera2ViewLayout, + @NonNull TextView logicalCameraTv, + @NonNull TextView multiCameraSupportTv, + @NonNull TextView physicalCameraTv, + @NonNull TextView textView, + @NonNull TextView textView0, + @NonNull TextView textView2, + @NonNull TextView textView3, + @NonNull TextView textView5, + @NonNull TextView totalCamera, + @NonNull SeekBar zoomBar) { + this.rootView = rootView; + this.camera1TextView = camera1TextView; + this.camera1View = camera1View; + this.camera1ViewLayout = camera1ViewLayout; + this.camera2TextView = camera2TextView; + this.camera2View = camera2View; + this.camera2ViewLayout = camera2ViewLayout; + this.logicalCameraTv = logicalCameraTv; + this.multiCameraSupportTv = multiCameraSupportTv; + this.physicalCameraTv = physicalCameraTv; + this.textView = textView; + this.textView0 = textView0; + this.textView2 = textView2; + this.textView3 = textView3; + this.textView5 = textView5; + this.totalCamera = totalCamera; + this.zoomBar = zoomBar; } - return bind(root); - } - - @NonNull - public static FragmentCameraBinding bind(@NonNull View rootView) { - // The body of this method is generated in a way you would not otherwise write. - // This is done to optimize the compiled bytecode for size and performance. - int id; - missingId: { - id = R.id.camera_1_textView; - TextView camera1TextView = rootView.findViewById(id); - if (camera1TextView == null) { - break missingId; - } - - id = R.id.camera1View; - AutoFitTextureView camera1View = rootView.findViewById(id); - if (camera1View == null) { - break missingId; - } - - id = R.id.camera1ViewLayout; - RelativeLayout camera1ViewLayout = rootView.findViewById(id); - if (camera1ViewLayout == null) { - break missingId; - } - - id = R.id.camera_2_textView; - TextView camera2TextView = rootView.findViewById(id); - if (camera2TextView == null) { - break missingId; - } - - id = R.id.camera2View; - AutoFitTextureView camera2View = rootView.findViewById(id); - if (camera2View == null) { - break missingId; - } - - id = R.id.camera2ViewLayout; - RelativeLayout camera2ViewLayout = rootView.findViewById(id); - if (camera2ViewLayout == null) { - break missingId; - } - - id = R.id.logicalCameraTv; - TextView logicalCameraTv = rootView.findViewById(id); - if (logicalCameraTv == null) { - break missingId; - } - - id = R.id.multiCameraSupportTv; - TextView multiCameraSupportTv = rootView.findViewById(id); - if (multiCameraSupportTv == null) { - break missingId; - } - - id = R.id.physicalCameraTv; - TextView physicalCameraTv = rootView.findViewById(id); - if (physicalCameraTv == null) { - break missingId; - } - - id = R.id.textView; - TextView textView = rootView.findViewById(id); - if (textView == null) { - break missingId; - } - - id = R.id.textView0; - TextView textView0 = rootView.findViewById(id); - if (textView0 == null) { - break missingId; - } - - id = R.id.textView2; - TextView textView2 = rootView.findViewById(id); - if (textView2 == null) { - break missingId; - } - - id = R.id.textView3; - TextView textView3 = rootView.findViewById(id); - if (textView3 == null) { - break missingId; - } - - id = R.id.textView5; - TextView textView5 = rootView.findViewById(id); - if (textView5 == null) { - break missingId; - } - - id = R.id.totalCamera; - TextView totalCamera = rootView.findViewById(id); - if (totalCamera == null) { - break missingId; - } - - id = R.id.zoomBar; - SeekBar zoomBar = rootView.findViewById(id); - if (zoomBar == null) { - break missingId; - } - - return new FragmentCameraBinding((ConstraintLayout) rootView, camera1TextView, camera1View, - camera1ViewLayout, camera2TextView, camera2View, camera2ViewLayout, logicalCameraTv, - multiCameraSupportTv, physicalCameraTv, textView, textView0, textView2, textView3, - textView5, totalCamera, zoomBar); + + @Override + @NonNull + public ConstraintLayout getRoot() { + return rootView; + } + + @NonNull + public static FragmentCameraBinding inflate(@NonNull LayoutInflater inflater) { + return inflate(inflater, null, false); + } + + @NonNull + public static FragmentCameraBinding inflate( + @NonNull LayoutInflater inflater, @Nullable ViewGroup parent, boolean attachToParent) { + View root = inflater.inflate(R.layout.fragment_camera, parent, false); + if (attachToParent) { + parent.addView(root); + } + return bind(root); + } + + @NonNull + public static FragmentCameraBinding bind(@NonNull View rootView) { + // The body of this method is generated in a way you would not otherwise write. + // This is done to optimize the compiled bytecode for size and performance. + int id; + missingId: + { + id = R.id.camera_1_textView; + TextView camera1TextView = rootView.findViewById(id); + if (camera1TextView == null) { + break missingId; + } + + id = R.id.camera1View; + AutoFitTextureView camera1View = rootView.findViewById(id); + if (camera1View == null) { + break missingId; + } + + id = R.id.camera1ViewLayout; + RelativeLayout camera1ViewLayout = rootView.findViewById(id); + if (camera1ViewLayout == null) { + break missingId; + } + + id = R.id.camera_2_textView; + TextView camera2TextView = rootView.findViewById(id); + if (camera2TextView == null) { + break missingId; + } + + id = R.id.camera2View; + AutoFitTextureView camera2View = rootView.findViewById(id); + if (camera2View == null) { + break missingId; + } + + id = R.id.camera2ViewLayout; + RelativeLayout camera2ViewLayout = rootView.findViewById(id); + if (camera2ViewLayout == null) { + break missingId; + } + + id = R.id.logicalCameraTv; + TextView logicalCameraTv = rootView.findViewById(id); + if (logicalCameraTv == null) { + break missingId; + } + + id = R.id.multiCameraSupportTv; + TextView multiCameraSupportTv = rootView.findViewById(id); + if (multiCameraSupportTv == null) { + break missingId; + } + + id = R.id.physicalCameraTv; + TextView physicalCameraTv = rootView.findViewById(id); + if (physicalCameraTv == null) { + break missingId; + } + + id = R.id.textView; + TextView textView = rootView.findViewById(id); + if (textView == null) { + break missingId; + } + + id = R.id.textView0; + TextView textView0 = rootView.findViewById(id); + if (textView0 == null) { + break missingId; + } + + id = R.id.textView2; + TextView textView2 = rootView.findViewById(id); + if (textView2 == null) { + break missingId; + } + + id = R.id.textView3; + TextView textView3 = rootView.findViewById(id); + if (textView3 == null) { + break missingId; + } + + id = R.id.textView5; + TextView textView5 = rootView.findViewById(id); + if (textView5 == null) { + break missingId; + } + + id = R.id.totalCamera; + TextView totalCamera = rootView.findViewById(id); + if (totalCamera == null) { + break missingId; + } + + id = R.id.zoomBar; + SeekBar zoomBar = rootView.findViewById(id); + if (zoomBar == null) { + break missingId; + } + + return new FragmentCameraBinding( + (ConstraintLayout) rootView, + camera1TextView, + camera1View, + camera1ViewLayout, + camera2TextView, + camera2View, + camera2ViewLayout, + logicalCameraTv, + multiCameraSupportTv, + physicalCameraTv, + textView, + textView0, + textView2, + textView3, + textView5, + totalCamera, + zoomBar); + } + String missingId = rootView.getResources().getResourceName(id); + throw new NullPointerException("Missing required view with ID: ".concat(missingId)); } - String missingId = rootView.getResources().getResourceName(id); - throw new NullPointerException("Missing required view with ID: ".concat(missingId)); - } } diff --git a/MultiCamera/app/generated/source/buildConfig/debug/com/nxp/multicamera/BuildConfig.java b/MultiCamera/app/generated/source/buildConfig/debug/com/nxp/multicamera/BuildConfig.java index dc54039..fb13ef3 100644 --- a/MultiCamera/app/generated/source/buildConfig/debug/com/nxp/multicamera/BuildConfig.java +++ b/MultiCamera/app/generated/source/buildConfig/debug/com/nxp/multicamera/BuildConfig.java @@ -1,12 +1,10 @@ -/** - * Automatically generated file. DO NOT MODIFY - */ +/** Automatically generated file. DO NOT MODIFY */ package com.nxp.multicamera; public final class BuildConfig { - public static final boolean DEBUG = Boolean.parseBoolean("true"); - public static final String APPLICATION_ID = "com.nxp.multicamera"; - public static final String BUILD_TYPE = "debug"; - public static final int VERSION_CODE = 1; - public static final String VERSION_NAME = "1.0"; + public static final boolean DEBUG = Boolean.parseBoolean("true"); + public static final String APPLICATION_ID = "com.nxp.multicamera"; + public static final String BUILD_TYPE = "debug"; + public static final int VERSION_CODE = 1; + public static final String VERSION_NAME = "1.0"; } diff --git a/SecureIME/src/com/android/nxpime/SecureIMESurfaceView.java b/SecureIME/src/com/android/nxpime/SecureIMESurfaceView.java index c265662..dc7a6fc 100644 --- a/SecureIME/src/com/android/nxpime/SecureIMESurfaceView.java +++ b/SecureIME/src/com/android/nxpime/SecureIMESurfaceView.java @@ -1,97 +1,92 @@ package com.android.nxpime; import android.content.Context; -import android.graphics.Canvas; -import android.graphics.Color; -import android.graphics.Paint; -import android.view.KeyEvent; +import android.util.Log; import android.view.MotionEvent; +import android.view.Surface; import android.view.SurfaceHolder; import android.view.SurfaceHolder.Callback; import android.view.SurfaceView; -import android.view.Surface; -import android.util.Log; import android.view.inputmethod.EditorInfo; import android.view.inputmethod.InputConnection; -import android.text.InputType; public class SecureIMESurfaceView extends SurfaceView implements Callback { - private SurfaceHolder mHolder; - private Thread t; - private boolean flag; - private int x, y; - private static final String TAG = "SecureIMESurfaceView"; - private InputConnection mIC; - private int mSurfaceWidth = 720, mSurfaceHeight = 400; - - public SecureIMESurfaceView(Context context) { - super(context); - - this.setFilterTouchesWhenObscured(true); - - /* connect to AIDL service */ - connectAIDL(); - - mHolder = getHolder(); - mHolder.addCallback(this); - mHolder.setFixedSize(mSurfaceWidth, mSurfaceHeight); - } - - public void setInputConnection(InputConnection ic) { - mIC = ic; - } - - @Override - public void surfaceCreated(SurfaceHolder holder) { - Log.i(TAG, "in surfaceCreated!"); - startKeyboard(mHolder.getSurface()); - } - - @Override - public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {} - - @Override - public void surfaceDestroyed(SurfaceHolder holder) { - Log.i(TAG, "in surfaceDestroyed!"); - cleanup(); - } - - @Override - public boolean onTouchEvent(MotionEvent event) { - int key; - switch (event.getAction()) { - case MotionEvent.ACTION_UP: - x = (int) event.getX(); // get X coordinate - y = (int) event.getY(); // get Y coordinate - key = deliverInput(x, y); - /* only allow valid key */ - Log.i(TAG, "coordinate: X " + x + " Y " + y); - if ((key >= 0) && (key <= 9)) { - mIC.commitText(String.valueOf(key), 0); - } else if (key == 10) { - mIC.deleteSurroundingText(1, 0); - } else if (key == 11) { - mIC.performEditorAction(EditorInfo.IME_ACTION_DONE); - } else { - Log.e(TAG, "in surface onTouchEvent! Invalid touch input " + key + " abandon!"); - } - } - return true; - } - - /* connect AIDL service */ - private native int connectAIDL(); - - /* create surface and init keyboard */ - private native int startKeyboard(Surface surface); - - /* deliver coordinate to TEE and return the number */ - private native int deliverInput(int x, int y); - - /* clean up resource on exit */ - private native int cleanup(); - - static { - System.loadLibrary("secureime_jni"); - } + private SurfaceHolder mHolder; + private Thread t; + private boolean flag; + private int x, y; + private static final String TAG = "SecureIMESurfaceView"; + private InputConnection mIC; + private int mSurfaceWidth = 720, mSurfaceHeight = 400; + + public SecureIMESurfaceView(Context context) { + super(context); + + this.setFilterTouchesWhenObscured(true); + + /* connect to AIDL service */ + connectAIDL(); + + mHolder = getHolder(); + mHolder.addCallback(this); + mHolder.setFixedSize(mSurfaceWidth, mSurfaceHeight); + } + + public void setInputConnection(InputConnection ic) { + mIC = ic; + } + + @Override + public void surfaceCreated(SurfaceHolder holder) { + Log.i(TAG, "in surfaceCreated!"); + startKeyboard(mHolder.getSurface()); + } + + @Override + public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {} + + @Override + public void surfaceDestroyed(SurfaceHolder holder) { + Log.i(TAG, "in surfaceDestroyed!"); + cleanup(); + } + + @Override + public boolean onTouchEvent(MotionEvent event) { + int key; + switch (event.getAction()) { + case MotionEvent.ACTION_UP: + x = (int) event.getX(); // get X coordinate + y = (int) event.getY(); // get Y coordinate + key = deliverInput(x, y); + /* only allow valid key */ + Log.i(TAG, "coordinate: X " + x + " Y " + y); + if ((key >= 0) && (key <= 9)) { + mIC.commitText(String.valueOf(key), 0); + } else if (key == 10) { + mIC.deleteSurroundingText(1, 0); + } else if (key == 11) { + mIC.performEditorAction(EditorInfo.IME_ACTION_DONE); + } else { + Log.e(TAG, "in surface onTouchEvent! Invalid touch input " + key + " abandon!"); + } + } + return true; + } + + /* connect AIDL service */ + private native int connectAIDL(); + + /* create surface and init keyboard */ + private native int startKeyboard(Surface surface); + + /* deliver coordinate to TEE and return the number */ + private native int deliverInput(int x, int y); + + /* clean up resource on exit */ + private native int cleanup(); + + static { + System.loadLibrary("secureime_jni"); + } } diff --git a/SecureIME/src/com/android/nxpime/SecureInputIME.java b/SecureIME/src/com/android/nxpime/SecureInputIME.java index 0b63ab2..5e489d5 100644 --- a/SecureIME/src/com/android/nxpime/SecureInputIME.java +++ b/SecureIME/src/com/android/nxpime/SecureInputIME.java @@ -1,79 +1,67 @@ package com.android.nxpime; -import androidx.appcompat.app.AppCompatActivity; import android.inputmethodservice.InputMethodService; -import android.inputmethodservice.InputMethodService; -import android.inputmethodservice.Keyboard; -import android.inputmethodservice.KeyboardView; import android.text.InputType; +import android.util.Log; import android.view.View; import android.view.inputmethod.EditorInfo; import android.view.inputmethod.InputConnection; -import android.util.Log; - -import android.os.Bundle; -import android.view.Surface; -import android.widget.TextView; - -import java.io.FileDescriptor; public class SecureInputIME extends InputMethodService { - private InputConnection ic; - SecureIMESurfaceView imeSurfaceview = null; - private static final String TAG = "SecureIME"; + private InputConnection ic; + SecureIMESurfaceView imeSurfaceview = null; + private static final String TAG = "SecureIME"; - @Override - public void onCreate() { - super.onCreate(); - } + @Override + public void onCreate() { + super.onCreate(); + } - @Override - public View onCreateInputView() { - imeSurfaceview = new SecureIMESurfaceView(getApplicationContext()); - return imeSurfaceview; - } + @Override + public View onCreateInputView() { + imeSurfaceview = new SecureIMESurfaceView(getApplicationContext()); + return imeSurfaceview; + } - @Override - public void onWindowShown() { - super.onWindowShown(); - ic = getCurrentInputConnection(); - if (ic != null && imeSurfaceview != null) { - imeSurfaceview.setInputConnection(ic); - } else - Log.e(TAG, "Can not get valid InputConnection in onWindowShown()!"); - } + @Override + public void onWindowShown() { + super.onWindowShown(); + ic = getCurrentInputConnection(); + if (ic != null && imeSurfaceview != null) { + imeSurfaceview.setInputConnection(ic); + } else Log.e(TAG, "Can not get valid InputConnection in onWindowShown()!"); + } - @Override - public void onWindowHidden() { - super.onWindowHidden(); - ic = null; - if (getWindow() != null) - getWindow().hide(); - } + @Override + public void onWindowHidden() { + super.onWindowHidden(); + ic = null; + if (getWindow() != null) getWindow().hide(); + } - @Override - public boolean onEvaluateFullscreenMode() { - return false; - } + @Override + public boolean onEvaluateFullscreenMode() { + return false; + } - @Override - public boolean onEvaluateInputViewShown() { - EditorInfo info = getCurrentInputEditorInfo(); - if (info.inputType != (InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_VARIATION_PASSWORD)) { - switchToNextInputMethod(false); - return false; - } else { - return super.onEvaluateInputViewShown(); - } - } + @Override + public boolean onEvaluateInputViewShown() { + EditorInfo info = getCurrentInputEditorInfo(); + if (info.inputType + != (InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_VARIATION_PASSWORD)) { + switchToNextInputMethod(false); + return false; + } else { + return super.onEvaluateInputViewShown(); + } + } - @Override - public void onStartInput(EditorInfo attribute, boolean restarting) { - ic = getCurrentInputConnection(); - if (ic != null && imeSurfaceview != null) { - imeSurfaceview.setInputConnection(ic); - } else - Log.e(TAG, "Can not get valid InputConnection in onStartInput!"); - } + @Override + public void onStartInput(EditorInfo attribute, boolean restarting) { + ic = getCurrentInputConnection(); + if (ic != null && imeSurfaceview != null) { + imeSurfaceview.setInputConnection(ic); + } else Log.e(TAG, "Can not get valid InputConnection in onStartInput!"); + } } diff --git a/SleepAwakeAutoTest/src/com/freescale/sleepawake/MyActivity.java b/SleepAwakeAutoTest/src/com/freescale/sleepawake/MyActivity.java index 1db6df2..23da3e2 100755 --- a/SleepAwakeAutoTest/src/com/freescale/sleepawake/MyActivity.java +++ b/SleepAwakeAutoTest/src/com/freescale/sleepawake/MyActivity.java @@ -16,7 +16,6 @@ package com.freescale.sleepawake; import android.app.Activity; -import android.app.NotificationManager; import android.app.admin.DevicePolicyManager; import android.content.ComponentName; import android.content.Intent; @@ -26,105 +25,112 @@ import android.widget.Button; import android.widget.CheckBox; import android.widget.EditText; -import android.widget.Toast; import android.widget.TextView; +import android.widget.Toast; public class MyActivity extends Activity { - private EditText mEt_awake; - private EditText mEt_sleep; - private Button mBtn_start; - private CheckBox mCb_random; - private TextView mTv_times; - private static final int SLEEP_TIME_MIN = 5000; - private SharedPreferences mSp; - private SharedPreferences.Editor mEd; - private DevicePolicyManager mDpm; - private Button mBtn_stop; - - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_main); - initParam(); - } - - public void initParam(){ - mEt_awake = (EditText) findViewById(R.id.et_awake); - mEt_sleep = (EditText) findViewById(R.id.et_sleep); - mBtn_start = (Button) findViewById(R.id.btn_start) ; - mBtn_stop = (Button) findViewById(R.id.btn_stop); - mCb_random = (CheckBox) findViewById(R.id.cb_random); - mTv_times = (TextView) findViewById(R.id.tv_times); - mSp = getSharedPreferences("AwakeSleepAutoTest", MODE_PRIVATE); - mEd = mSp.edit(); - mDpm = (DevicePolicyManager) getSystemService(DEVICE_POLICY_SERVICE); - } - - @Override - protected void onStart() { - // TODO Auto-generated method stub - super.onStart(); - int times = mSp.getInt("times", 0); - - mTv_times.setText("Test times:"+times); - - } - - - @Override - protected void onResume() { - super.onResume(); - - ComponentName who = new ComponentName(this,MyAdmin.class); - if(mDpm.isAdminActive(who)){ - mBtn_start.setEnabled(true); - mBtn_stop.setEnabled(true); - }else{ - mBtn_start.setEnabled(false); - mBtn_stop.setEnabled(false); - } - } - - public void startTest(View v){ - - int awakeTime = Integer.parseInt(mEt_awake.getText().toString()) * 1000; - int sleepTime = Integer.parseInt(mEt_sleep.getText().toString()) * 1000; - - mTv_times.setText("Test times:0"); - mEd.putBoolean("isRandom", mCb_random.isChecked()); - mEd.commit(); - //ensure that the sleep time should not below 5s - if(sleepTime < SLEEP_TIME_MIN){ - Toast.makeText(getApplicationContext(), "SleepTime should be set above 5s", Toast.LENGTH_LONG).show(); - }else{ - Intent intent = new Intent(MyActivity.this, MyService.class); - intent.putExtra("awaketime", awakeTime); - intent.putExtra("sleeptime", sleepTime); - startService(intent); - Toast.makeText(getApplicationContext(), "SleepAwake Service has been started!", Toast.LENGTH_LONG).show(); - } - } - - public void stopTest(View v){ - Intent intent = new Intent("android.intent.action.CANCEL_MY_SLEEP_AWAKE"); - sendBroadcast(intent); - } - - public void setAdmin(View v){ - Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN); - ComponentName mDeviceAdminSample = new ComponentName(this,MyAdmin.class); - intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, mDeviceAdminSample); - intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION, - "Active the device administrators before start the test"); - startActivity(intent); - } - - public void uninstall(View view ){ - - ComponentName mDeviceAdminSample = new ComponentName(this,MyAdmin.class); - mDpm.removeActiveAdmin(mDeviceAdminSample); - mBtn_start.setEnabled(false); - mBtn_stop.setEnabled(false); - } - + private EditText mEt_awake; + private EditText mEt_sleep; + private Button mBtn_start; + private CheckBox mCb_random; + private TextView mTv_times; + private static final int SLEEP_TIME_MIN = 5000; + private SharedPreferences mSp; + private SharedPreferences.Editor mEd; + private DevicePolicyManager mDpm; + private Button mBtn_stop; + + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + initParam(); + } + + public void initParam() { + + mEt_awake = (EditText) findViewById(R.id.et_awake); + mEt_sleep = (EditText) findViewById(R.id.et_sleep); + mBtn_start = (Button) findViewById(R.id.btn_start); + mBtn_stop = (Button) findViewById(R.id.btn_stop); + mCb_random = (CheckBox) findViewById(R.id.cb_random); + mTv_times = (TextView) findViewById(R.id.tv_times); + mSp = getSharedPreferences("AwakeSleepAutoTest", MODE_PRIVATE); + mEd = mSp.edit(); + mDpm = (DevicePolicyManager) getSystemService(DEVICE_POLICY_SERVICE); + } + + @Override + protected void onStart() { + // TODO Auto-generated method stub + super.onStart(); + int times = mSp.getInt("times", 0); + + mTv_times.setText("Test times:" + times); + } + + @Override + protected void onResume() { + super.onResume(); + + ComponentName who = new ComponentName(this, MyAdmin.class); + if (mDpm.isAdminActive(who)) { + mBtn_start.setEnabled(true); + mBtn_stop.setEnabled(true); + } else { + mBtn_start.setEnabled(false); + mBtn_stop.setEnabled(false); + } + } + + public void startTest(View v) { + + int awakeTime = Integer.parseInt(mEt_awake.getText().toString()) * 1000; + int sleepTime = Integer.parseInt(mEt_sleep.getText().toString()) * 1000; + + mTv_times.setText("Test times:0"); + mEd.putBoolean("isRandom", mCb_random.isChecked()); + mEd.commit(); + // ensure that the sleep time should not below 5s + if (sleepTime < SLEEP_TIME_MIN) { + Toast.makeText( + getApplicationContext(), + "SleepTime should be set above 5s", + Toast.LENGTH_LONG) + .show(); + } else { + Intent intent = new Intent(MyActivity.this, MyService.class); + intent.putExtra("awaketime", awakeTime); + intent.putExtra("sleeptime", sleepTime); + startService(intent); + Toast.makeText( + getApplicationContext(), + "SleepAwake Service has been started!", + Toast.LENGTH_LONG) + .show(); + } + } + + public void stopTest(View v) { + Intent intent = new Intent("android.intent.action.CANCEL_MY_SLEEP_AWAKE"); + sendBroadcast(intent); + } + + public void setAdmin(View v) { + Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN); + ComponentName mDeviceAdminSample = new ComponentName(this, MyAdmin.class); + intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, mDeviceAdminSample); + intent.putExtra( + DevicePolicyManager.EXTRA_ADD_EXPLANATION, + "Active the device administrators before start the test"); + startActivity(intent); + } + + public void uninstall(View view) { + + ComponentName mDeviceAdminSample = new ComponentName(this, MyAdmin.class); + mDpm.removeActiveAdmin(mDeviceAdminSample); + mBtn_start.setEnabled(false); + mBtn_stop.setEnabled(false); + } } diff --git a/SleepAwakeAutoTest/src/com/freescale/sleepawake/MyAdmin.java b/SleepAwakeAutoTest/src/com/freescale/sleepawake/MyAdmin.java index 184b6e9..3e0f212 100755 --- a/SleepAwakeAutoTest/src/com/freescale/sleepawake/MyAdmin.java +++ b/SleepAwakeAutoTest/src/com/freescale/sleepawake/MyAdmin.java @@ -14,8 +14,7 @@ * limitations under the License. */ package com.freescale.sleepawake; -import android.app.admin.DeviceAdminReceiver; -public class MyAdmin extends DeviceAdminReceiver { +import android.app.admin.DeviceAdminReceiver; -} +public class MyAdmin extends DeviceAdminReceiver {} diff --git a/SleepAwakeAutoTest/src/com/freescale/sleepawake/MyReceiver.java b/SleepAwakeAutoTest/src/com/freescale/sleepawake/MyReceiver.java index 5a6ded5..cea7a5e 100755 --- a/SleepAwakeAutoTest/src/com/freescale/sleepawake/MyReceiver.java +++ b/SleepAwakeAutoTest/src/com/freescale/sleepawake/MyReceiver.java @@ -15,7 +15,6 @@ */ package com.freescale.sleepawake; - import android.app.Activity; import android.app.AlarmManager; import android.app.PendingIntent; @@ -32,109 +31,135 @@ public class MyReceiver extends BroadcastReceiver { - private static final String TAG = "Sleep"; - private boolean isRunning = true; - private int times = 0; - private SharedPreferences mSp; - private SharedPreferences.Editor mEd; - private int SleepDelayTimeRandom; - private int AwakeDelayTimeRandom; - - - @Override - public void onReceive(final Context context, final Intent intent) { - Thread t = new Thread(){ - public void run(){ - try { - String action = intent.getStringExtra("action"); - int SleepDelayTime = intent.getIntExtra("SleepDelayTime", 0); - int AwakeDelayTime = intent.getIntExtra("AwakeDelayTime", 0); - long ExpectedTime = intent.getLongExtra("ExpectedTime", 0); - boolean isRandom = mSp.getBoolean("isRandom", false); - if(isRandom == true){ - SleepDelayTimeRandom = SleepDelayTime + (int)(Math.random() * 500) - (int)(Math.random() * 500); - AwakeDelayTimeRandom = AwakeDelayTime + (int)(Math.random() * 500) - (int)(Math.random() * 500); - }else{ - SleepDelayTimeRandom = SleepDelayTime; - AwakeDelayTimeRandom = AwakeDelayTime; - } + private static final String TAG = "Sleep"; + private boolean isRunning = true; + private int times = 0; + private SharedPreferences mSp; + private SharedPreferences.Editor mEd; + private int SleepDelayTimeRandom; + private int AwakeDelayTimeRandom; + @Override + public void onReceive(final Context context, final Intent intent) { + Thread t = + new Thread() { + public void run() { + try { + String action = intent.getStringExtra("action"); + int SleepDelayTime = intent.getIntExtra("SleepDelayTime", 0); + int AwakeDelayTime = intent.getIntExtra("AwakeDelayTime", 0); + long ExpectedTime = intent.getLongExtra("ExpectedTime", 0); + boolean isRandom = mSp.getBoolean("isRandom", false); + if (isRandom == true) { + SleepDelayTimeRandom = + SleepDelayTime + + (int) (Math.random() * 500) + - (int) (Math.random() * 500); + AwakeDelayTimeRandom = + AwakeDelayTime + + (int) (Math.random() * 500) + - (int) (Math.random() * 500); + } else { + SleepDelayTimeRandom = SleepDelayTime; + AwakeDelayTimeRandom = AwakeDelayTime; + } - if (action.equals("sleep")) { - SystemClock.sleep(AwakeDelayTimeRandom); - Intent newIntent = new Intent("android.intent.action.MY_SLEEP_AWAKE"); - newIntent.putExtra("action","awake"); - newIntent.putExtra("SleepDelayTime",SleepDelayTime); - newIntent.putExtra("AwakeDelayTime",AwakeDelayTime); - newIntent.putExtra("ExpectedTime", System.currentTimeMillis() + SleepDelayTime); - ((AlarmManager)context.getSystemService("alarm")).set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis()+SleepDelayTimeRandom, PendingIntent.getBroadcast(context, 0, newIntent, PendingIntent.FLAG_CANCEL_CURRENT)); - if (!isRunning) - return; - toSleep(context); - } - else if (action.equals("awake")) { + if (action.equals("sleep")) { + SystemClock.sleep(AwakeDelayTimeRandom); + Intent newIntent = + new Intent("android.intent.action.MY_SLEEP_AWAKE"); + newIntent.putExtra("action", "awake"); + newIntent.putExtra("SleepDelayTime", SleepDelayTime); + newIntent.putExtra("AwakeDelayTime", AwakeDelayTime); + newIntent.putExtra( + "ExpectedTime", + System.currentTimeMillis() + SleepDelayTime); + ((AlarmManager) context.getSystemService("alarm")) + .set( + AlarmManager.RTC_WAKEUP, + System.currentTimeMillis() + SleepDelayTimeRandom, + PendingIntent.getBroadcast( + context, + 0, + newIntent, + PendingIntent.FLAG_CANCEL_CURRENT)); + if (!isRunning) return; + toSleep(context); + } else if (action.equals("awake")) { - long NowTime = System.currentTimeMillis(); - long slip = NowTime - ExpectedTime -900; - if(slip < 0){ - slip = (int)(Math.random() * 20); - NowTime = ExpectedTime + slip; - } - if(slip > 1000){ - Log.v(TAG, "timeout"); - } - Log.v(TAG, "slip="+slip+"ms,ExpectedTime="+ExpectedTime+"ms,NowTime="+NowTime+"ms"); - times = mSp.getInt("times", 0); - times++; - mEd.putInt("times", times); - mEd.commit(); - toAwake(context); - Intent newIntent = new Intent("android.intent.action.MY_SLEEP_AWAKE"); - newIntent.putExtra("action","sleep"); - newIntent.putExtra("SleepDelayTime",SleepDelayTime); - newIntent.putExtra("AwakeDelayTime",AwakeDelayTime); - context.sendBroadcast(newIntent); - } - } catch (Exception e) { - e.printStackTrace(); - } - } - }; + long NowTime = System.currentTimeMillis(); + long slip = NowTime - ExpectedTime - 900; + if (slip < 0) { + slip = (int) (Math.random() * 20); + NowTime = ExpectedTime + slip; + } + if (slip > 1000) { + Log.v(TAG, "timeout"); + } + Log.v( + TAG, + "slip=" + + slip + + "ms,ExpectedTime=" + + ExpectedTime + + "ms,NowTime=" + + NowTime + + "ms"); + times = mSp.getInt("times", 0); + times++; + mEd.putInt("times", times); + mEd.commit(); + toAwake(context); + Intent newIntent = + new Intent("android.intent.action.MY_SLEEP_AWAKE"); + newIntent.putExtra("action", "sleep"); + newIntent.putExtra("SleepDelayTime", SleepDelayTime); + newIntent.putExtra("AwakeDelayTime", AwakeDelayTime); + context.sendBroadcast(newIntent); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + }; - mSp = context.getSharedPreferences("AwakeSleepAutoTest", Activity.MODE_PRIVATE); - mEd = mSp.edit(); - if (intent.getAction().equals("android.intent.action.CANCEL_MY_SLEEP_AWAKE")) { - try { - isRunning = false; - Intent stopIntent = new Intent(context, MyService.class); - context.stopService(stopIntent); - mEd.putInt("times", 0); - mEd.commit(); - } catch (Throwable e) { - e.printStackTrace(); - } - } - else { - t.start(); - } - } + mSp = context.getSharedPreferences("AwakeSleepAutoTest", Activity.MODE_PRIVATE); + mEd = mSp.edit(); + if (intent.getAction().equals("android.intent.action.CANCEL_MY_SLEEP_AWAKE")) { + try { + isRunning = false; + Intent stopIntent = new Intent(context, MyService.class); + context.stopService(stopIntent); + mEd.putInt("times", 0); + mEd.commit(); + } catch (Throwable e) { + e.printStackTrace(); + } + } else { + t.start(); + } + } - public void toSleep(Context context) { + public void toSleep(Context context) { - DevicePolicyManager dpm = (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE); - ComponentName who = new ComponentName(context,MyAdmin.class); - if(dpm.isAdminActive(who)){ - dpm.lockNow(); - }else{ - Toast.makeText(context, "have not got the adminstration permission", 1).show(); - return ; - } - } + DevicePolicyManager dpm = + (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE); + ComponentName who = new ComponentName(context, MyAdmin.class); + if (dpm.isAdminActive(who)) { + dpm.lockNow(); + } else { + Toast.makeText(context, "have not got the adminstration permission", 1).show(); + return; + } + } - public void toAwake(Context context) { - PowerManager pm=(PowerManager) context.getSystemService(Context.POWER_SERVICE); - PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.SCREEN_DIM_WAKE_LOCK,"bright"); - wl.acquire(); - wl.release(); - } + public void toAwake(Context context) { + PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); + PowerManager.WakeLock wl = + pm.newWakeLock( + PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.SCREEN_DIM_WAKE_LOCK, + "bright"); + wl.acquire(); + wl.release(); + } } diff --git a/SleepAwakeAutoTest/src/com/freescale/sleepawake/MyService.java b/SleepAwakeAutoTest/src/com/freescale/sleepawake/MyService.java index 722cefe..a992769 100755 --- a/SleepAwakeAutoTest/src/com/freescale/sleepawake/MyService.java +++ b/SleepAwakeAutoTest/src/com/freescale/sleepawake/MyService.java @@ -26,54 +26,56 @@ public class MyService extends Service { - private MyReceiver receiver; - private NotificationManager notificationManager; - private int sleeptime; - private int awaketime; + private MyReceiver receiver; + private NotificationManager notificationManager; + private int sleeptime; + private int awaketime; + @Override + public IBinder onBind(Intent intent) { + // TODO Auto-generated method stub + return null; + } - @Override - public IBinder onBind(Intent intent) { - // TODO Auto-generated method stub - return null; - } + @Override + public void onCreate() { + receiver = new MyReceiver(); + IntentFilter filter = new IntentFilter(); + filter.addAction("android.intent.action.MY_SLEEP_AWAKE"); + filter.addAction("android.intent.action.CANCEL_MY_SLEEP_AWAKE"); + registerReceiver(receiver, filter); + } - @Override - public void onCreate() { - receiver = new MyReceiver(); - IntentFilter filter = new IntentFilter(); - filter.addAction("android.intent.action.MY_SLEEP_AWAKE"); - filter.addAction("android.intent.action.CANCEL_MY_SLEEP_AWAKE"); - registerReceiver(receiver, filter); - } + @Override + public void onStart(Intent intent, int startId) { + // Get sleeptime and awaketime from the EditView + sleeptime = intent.getIntExtra("sleeptime", 5); + awaketime = intent.getIntExtra("awaketime", 5); - @Override - public void onStart(Intent intent, int startId) { - //Get sleeptime and awaketime from the EditView - sleeptime = intent.getIntExtra("sleeptime", 5); - awaketime = intent.getIntExtra("awaketime", 5); + // Set the notification + notificationManager = + (NotificationManager) + this.getSystemService(android.content.Context.NOTIFICATION_SERVICE); + Notification notification = + new Notification(R.drawable.lock, "sleepawake", System.currentTimeMillis()); + notification.flags |= Notification.FLAG_AUTO_CANCEL; + RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.notification); + notification.contentView = contentView; + Intent cancelIntent = new Intent("android.intent.action.CANCEL_MY_SLEEP_AWAKE"); + PendingIntent cancelPendingIntent = PendingIntent.getBroadcast(this, 0, cancelIntent, 0); + notification.contentView.setOnClickPendingIntent(R.id.cancelButton, cancelPendingIntent); + notificationManager.notify(0, notification); - //Set the notification - notificationManager = (NotificationManager)this.getSystemService(android.content.Context.NOTIFICATION_SERVICE); - Notification notification = new Notification(R.drawable.lock, "sleepawake", System.currentTimeMillis()); - notification.flags |= Notification.FLAG_AUTO_CANCEL; - RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.notification); - notification.contentView = contentView; - Intent cancelIntent = new Intent("android.intent.action.CANCEL_MY_SLEEP_AWAKE"); - PendingIntent cancelPendingIntent = PendingIntent.getBroadcast(this, 0, cancelIntent, 0); - notification.contentView.setOnClickPendingIntent(R.id.cancelButton, cancelPendingIntent); - notificationManager.notify(0, notification); + Intent newIntent = new Intent("android.intent.action.MY_SLEEP_AWAKE"); + newIntent.putExtra("action", "sleep"); + newIntent.putExtra("SleepDelayTime", sleeptime); + newIntent.putExtra("AwakeDelayTime", awaketime); + sendBroadcast(newIntent); + } - Intent newIntent = new Intent("android.intent.action.MY_SLEEP_AWAKE"); - newIntent.putExtra("action","sleep"); - newIntent.putExtra("SleepDelayTime",sleeptime); - newIntent.putExtra("AwakeDelayTime",awaketime); - sendBroadcast(newIntent); - } - - @Override - public void onDestroy() { - unregisterReceiver(receiver); - notificationManager.cancel(0); - } + @Override + public void onDestroy() { + unregisterReceiver(receiver); + notificationManager.cancel(0); + } } diff --git a/Test_DualPlayback/src/com/freescale/test_dualplayback/MainActivity.java b/Test_DualPlayback/src/com/freescale/test_dualplayback/MainActivity.java index 66a327d..e16de05 100755 --- a/Test_DualPlayback/src/com/freescale/test_dualplayback/MainActivity.java +++ b/Test_DualPlayback/src/com/freescale/test_dualplayback/MainActivity.java @@ -15,21 +15,11 @@ * limitations under the License. */ - package com.freescale.test_dualplayback; -import java.io.File; - -import java.io.FilenameFilter; -import java.util.ArrayList; -import java.util.List; - -import android.os.Bundle; - - import android.app.Activity; import android.content.Intent; -import android.util.Log; +import android.os.Bundle; import android.view.Menu; import android.view.View; import android.view.View.OnClickListener; @@ -38,77 +28,83 @@ import android.widget.Spinner; import android.widget.TextView; -public class MainActivity extends Activity implements OnClickListener - { - private Button button; - private String[] FileNameInDir = null; - private List VideoFileList = null; - private Spinner s0; - private Spinner s1; - private TextView textview0; - private TextView textview1; - private String videoFile0 = ""; - private String videoFile1 = ""; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_main); - - textview0 = (TextView)findViewById(R.id.textview0); - textview1 = (TextView)findViewById(R.id.textview1); - textview0.setText("video displayed on HDMI"); - textview1.setText("video displayed on LCD"); +import java.io.File; +import java.io.FilenameFilter; +import java.util.ArrayList; +import java.util.List; - File fileDir; - int fileIndex = 0; - fileDir = new File("/storage/emulated/legacy/"); - FilenameFilter filter = new FilenameFilter() { - public boolean accept(File dir, String name) { - return name.endsWith(".mp4")||name.endsWith(".m4v")||name.endsWith(".avi"); - } - }; +public class MainActivity extends Activity implements OnClickListener { + private Button button; + private String[] FileNameInDir = null; + private List VideoFileList = null; + private Spinner s0; + private Spinner s1; + private TextView textview0; + private TextView textview1; + private String videoFile0 = ""; + private String videoFile1 = ""; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + + textview0 = (TextView) findViewById(R.id.textview0); + textview1 = (TextView) findViewById(R.id.textview1); + textview0.setText("video displayed on HDMI"); + textview1.setText("video displayed on LCD"); + + File fileDir; + int fileIndex = 0; + fileDir = new File("/storage/emulated/legacy/"); + FilenameFilter filter = + new FilenameFilter() { + public boolean accept(File dir, String name) { + return name.endsWith(".mp4") + || name.endsWith(".m4v") + || name.endsWith(".avi"); + } + }; FileNameInDir = fileDir.list(filter); VideoFileList = new ArrayList(); - for(fileIndex = 0;fileIndex < FileNameInDir.length;fileIndex++){ - VideoFileList.add("/storage/emulated/legacy" + "/" + FileNameInDir[fileIndex]); + for (fileIndex = 0; fileIndex < FileNameInDir.length; fileIndex++) { + VideoFileList.add("/storage/emulated/legacy" + "/" + FileNameInDir[fileIndex]); } - ArrayAdapter adapter0 = new ArrayAdapter(this, android.R.layout.simple_spinner_dropdown_item, VideoFileList); - ArrayAdapter adapter1 = new ArrayAdapter(this, android.R.layout.simple_spinner_dropdown_item, VideoFileList); - s0 = (Spinner)findViewById(R.id.spinner0); + ArrayAdapter adapter0 = + new ArrayAdapter( + this, android.R.layout.simple_spinner_dropdown_item, VideoFileList); + ArrayAdapter adapter1 = + new ArrayAdapter( + this, android.R.layout.simple_spinner_dropdown_item, VideoFileList); + s0 = (Spinner) findViewById(R.id.spinner0); adapter0.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); s0.setAdapter(adapter0); s1 = (Spinner) findViewById(R.id.spinner1); adapter1.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); s1.setAdapter(adapter1); - button = (Button)findViewById(R.id.firstActivityButton); - button.setText("Play the video"); - button.setOnClickListener(MainActivity.this); - - } - - - @Override - public boolean onCreateOptionsMenu(Menu menu) { - // Inflate the menu; this adds items to the action bar if it is present. - getMenuInflater().inflate(R.menu.activity_main, menu); - return true; - } - - - @Override - public void onClick(View v) { - // TODO Auto-generated method stub - Intent intent = new Intent(this,SecondActivity.class); - int selectIndex; - selectIndex = s0.getSelectedItemPosition(); - videoFile0 = "/storage/emulated/legacy" + "/" + FileNameInDir[selectIndex]; - selectIndex = s1.getSelectedItemPosition(); - videoFile1 = "/storage/emulated/legacy" + "/" + FileNameInDir[selectIndex]; - intent.putExtra("videofile0",videoFile0); - intent.putExtra("videofile1", videoFile1); - startActivity(intent); - - } - + button = (Button) findViewById(R.id.firstActivityButton); + button.setText("Play the video"); + button.setOnClickListener(MainActivity.this); + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + // Inflate the menu; this adds items to the action bar if it is present. + getMenuInflater().inflate(R.menu.activity_main, menu); + return true; + } + + @Override + public void onClick(View v) { + // TODO Auto-generated method stub + Intent intent = new Intent(this, SecondActivity.class); + int selectIndex; + selectIndex = s0.getSelectedItemPosition(); + videoFile0 = "/storage/emulated/legacy" + "/" + FileNameInDir[selectIndex]; + selectIndex = s1.getSelectedItemPosition(); + videoFile1 = "/storage/emulated/legacy" + "/" + FileNameInDir[selectIndex]; + intent.putExtra("videofile0", videoFile0); + intent.putExtra("videofile1", videoFile1); + startActivity(intent); + } } diff --git a/Test_DualPlayback/src/com/freescale/test_dualplayback/SecondActivity.java b/Test_DualPlayback/src/com/freescale/test_dualplayback/SecondActivity.java index 56bf061..adf7773 100755 --- a/Test_DualPlayback/src/com/freescale/test_dualplayback/SecondActivity.java +++ b/Test_DualPlayback/src/com/freescale/test_dualplayback/SecondActivity.java @@ -17,39 +17,24 @@ package com.freescale.test_dualplayback; -import android.os.Bundle; - -import android.app.Activity; -import android.view.Menu; - -import java.io.File; - - -import android.net.Uri; -import android.os.Bundle; import android.app.Activity; -import android.view.Menu; - - -import android.app.MediaRouteActionProvider; import android.app.Presentation; import android.content.Context; import android.content.DialogInterface; import android.content.res.Resources; import android.media.MediaPlayer; import android.media.MediaRouter; -import android.media.MediaPlayer.OnCompletionListener; -import android.media.MediaPlayer.OnErrorListener; -import android.media.MediaPlayer.OnPreparedListener; import android.media.MediaRouter.RouteInfo; +import android.net.Uri; +import android.os.Bundle; import android.util.Log; import android.view.Display; -import android.view.MenuItem; import android.view.View; import android.view.WindowManager; -import android.widget.TextView; import android.widget.VideoView; +import java.io.File; + public class SecondActivity extends Activity { private final String TAG = "PresentationWithMediaRouterActivity"; @@ -58,14 +43,14 @@ public class SecondActivity extends Activity { private VideoView mvideoview1; private VideoView mvideoview2; private boolean mPaused; - private static Uri mUri1; - private static Uri mUri2; + private static Uri mUri1; + private static Uri mUri2; private String VideoFile = ""; private String VideoFile1 = ""; /** - * Initialization of the Activity after it is first created. Must at least - * call {@link android.app.Activity#setContentView setContentView()} to - * describe what is to be displayed in the screen. + * Initialization of the Activity after it is first created. Must at least call {@link + * android.app.Activity#setContentView setContentView()} to describe what is to be displayed in + * the screen. */ @Override protected void onCreate(Bundle savedInstanceState) { @@ -75,7 +60,7 @@ protected void onCreate(Bundle savedInstanceState) { VideoFile = bundle.getString("videofile0"); VideoFile1 = bundle.getString("videofile1"); // Get the media router service. - mMediaRouter = (MediaRouter)getSystemService(Context.MEDIA_ROUTER_SERVICE); + mMediaRouter = (MediaRouter) getSystemService(Context.MEDIA_ROUTER_SERVICE); // See assets/res/any/layout/presentation_with_media_router_activity.xml for this // view layout definition, which is being set here as @@ -83,34 +68,41 @@ protected void onCreate(Bundle savedInstanceState) { setContentView(R.layout.presentation_with_media_router_activity); // Set up the surface view for visual interest. - mvideoview1 = (VideoView)findViewById(R.id.videoview1); - // mSurfaceView.setRenderer(new CubeRenderer(false)); - // VideoFile = "/storage/emulated/legacy/"+"Mpeg4_SP1_1920x1080_30fps_9346kbps_MP3_48KHz_64kbps_2ch.mp4"; - // VideoFile1 = "/storage/emulated/legacy/"+"H264_HP41_1920x1088_30fps_55.8Mbps_shields_ter.mp4"; + mvideoview1 = (VideoView) findViewById(R.id.videoview1); + // mSurfaceView.setRenderer(new CubeRenderer(false)); + // VideoFile = + // "/storage/emulated/legacy/"+"Mpeg4_SP1_1920x1080_30fps_9346kbps_MP3_48KHz_64kbps_2ch.mp4"; + // VideoFile1 = + // "/storage/emulated/legacy/"+"H264_HP41_1920x1088_30fps_55.8Mbps_shields_ter.mp4"; mUri1 = Uri.fromFile(new File(VideoFile1)); - mvideoview2 = (VideoView)findViewById(R.id.videoview2); + mvideoview2 = (VideoView) findViewById(R.id.videoview2); mUri2 = Uri.fromFile(new File(VideoFile)); mvideoview2.setVideoURI(mUri2); mvideoview2.requestFocus(); - mvideoview2.start(); - mvideoview2.setOnErrorListener(new MediaPlayer.OnErrorListener(){ - public boolean onError(MediaPlayer mp, int what, int extra){ - VideoFile = "/storage/emulated/legacy/"+"Mpeg4_SP1_1920x1080_30fps_9346kbps_MP3_48KHz_64kbps_2ch.mp4"; - mUri2 = Uri.fromFile(new File(VideoFile)); - mvideoview2.setVideoURI(mUri2); - mvideoview2.start(); - return true; - } - } ); - mvideoview2.setOnCompletionListener(new MediaPlayer.OnCompletionListener() { - @Override -public void onCompletion(MediaPlayer mp) { - VideoFile = "/storage/emulated/legacy/"+"Mpeg4_SP1_1920x1080_30fps_9346kbps_MP3_48KHz_64kbps_2ch.mp4"; - mvideoview2.start(); - } - }); - Log.i(TAG,"onCreate set video0"); - + mvideoview2.start(); + mvideoview2.setOnErrorListener( + new MediaPlayer.OnErrorListener() { + public boolean onError(MediaPlayer mp, int what, int extra) { + VideoFile = + "/storage/emulated/legacy/" + + "Mpeg4_SP1_1920x1080_30fps_9346kbps_MP3_48KHz_64kbps_2ch.mp4"; + mUri2 = Uri.fromFile(new File(VideoFile)); + mvideoview2.setVideoURI(mUri2); + mvideoview2.start(); + return true; + } + }); + mvideoview2.setOnCompletionListener( + new MediaPlayer.OnCompletionListener() { + @Override + public void onCompletion(MediaPlayer mp) { + VideoFile = + "/storage/emulated/legacy/" + + "Mpeg4_SP1_1920x1080_30fps_9346kbps_MP3_48KHz_64kbps_2ch.mp4"; + mvideoview2.start(); + } + }); + Log.i(TAG, "onCreate set video0"); } @Override @@ -151,16 +143,19 @@ protected void onStop() { mPresentation = null; } } + private void updatePresentation() { // Get the current route and its presentation display. - MediaRouter.RouteInfo route = mMediaRouter.getSelectedRoute( - MediaRouter.ROUTE_TYPE_LIVE_VIDEO); + MediaRouter.RouteInfo route = + mMediaRouter.getSelectedRoute(MediaRouter.ROUTE_TYPE_LIVE_VIDEO); Display presentationDisplay = route != null ? route.getPresentationDisplay() : null; // Dismiss the current presentation if the display has changed. if (mPresentation != null && mPresentation.getDisplay() != presentationDisplay) { - Log.i(TAG, "Dismissing presentation because the current route no longer " - + "has a presentation display."); + Log.i( + TAG, + "Dismissing presentation because the current route no longer " + + "has a presentation display."); mPresentation.dismiss(); mPresentation = null; } @@ -173,8 +168,10 @@ private void updatePresentation() { try { mPresentation.show(); } catch (WindowManager.InvalidDisplayException ex) { - Log.w(TAG, "Couldn't show presentation! Display was removed in " - + "the meantime.", ex); + Log.w( + TAG, + "Couldn't show presentation! Display was removed in " + "the meantime.", + ex); mPresentation = null; } } @@ -206,49 +203,46 @@ private void updateContents() { private final MediaRouter.SimpleCallback mMediaRouterCallback = new MediaRouter.SimpleCallback() { - @Override - public void onRouteSelected(MediaRouter router, int type, RouteInfo info) { - Log.d(TAG, "onRouteSelected: type=" + type + ", info=" + info); - updatePresentation(); - } - - @Override - public void onRouteUnselected(MediaRouter router, int type, RouteInfo info) { - Log.d(TAG, "onRouteUnselected: type=" + type + ", info=" + info); - updatePresentation(); - } - - @Override - public void onRoutePresentationDisplayChanged(MediaRouter router, RouteInfo info) { - Log.d(TAG, "onRoutePresentationDisplayChanged: info=" + info); - updatePresentation(); - } - }; - - /** - * Listens for when presentations are dismissed. - */ + @Override + public void onRouteSelected(MediaRouter router, int type, RouteInfo info) { + Log.d(TAG, "onRouteSelected: type=" + type + ", info=" + info); + updatePresentation(); + } + + @Override + public void onRouteUnselected(MediaRouter router, int type, RouteInfo info) { + Log.d(TAG, "onRouteUnselected: type=" + type + ", info=" + info); + updatePresentation(); + } + + @Override + public void onRoutePresentationDisplayChanged(MediaRouter router, RouteInfo info) { + Log.d(TAG, "onRoutePresentationDisplayChanged: info=" + info); + updatePresentation(); + } + }; + + /** Listens for when presentations are dismissed. */ private final DialogInterface.OnDismissListener mOnDismissListener = new DialogInterface.OnDismissListener() { - @Override - public void onDismiss(DialogInterface dialog) { - if (dialog == mPresentation) { - Log.i(TAG, "Presentation was dismissed."); - mPresentation = null; - updateContents(); - } - } - }; + @Override + public void onDismiss(DialogInterface dialog) { + if (dialog == mPresentation) { + Log.i(TAG, "Presentation was dismissed."); + mPresentation = null; + updateContents(); + } + } + }; /** * The presentation to show on the secondary display. - *

- * Note that this display may have different metrics from the display on which - * the main activity is showing so we must be careful to use the presentation's - * own {@link Context} whenever we load resources. - *

+ * + *

Note that this display may have different metrics from the display on which the main + * activity is showing so we must be careful to use the presentation's own {@link Context} + * whenever we load resources. */ - private final class DemoPresentation extends Presentation { + private final class DemoPresentation extends Presentation { private VideoView mvideoview1; public DemoPresentation(Context context, Display display) { @@ -268,25 +262,27 @@ protected void onCreate(Bundle savedInstanceState) { setContentView(R.layout.presentation_with_media_router_content); // Set up the surface view for visual interest. - mvideoview1 = (VideoView)findViewById(R.id.videoview1); + mvideoview1 = (VideoView) findViewById(R.id.videoview1); mvideoview1.setVideoURI(mUri1); mvideoview1.requestFocus(); - mvideoview1.start(); - mvideoview1.setOnCompletionListener(new MediaPlayer.OnCompletionListener(){ -@Override - public void onCompletion(MediaPlayer mp) { - mvideoview1.start(); - } - }); - mvideoview1.setOnErrorListener(new MediaPlayer.OnErrorListener(){ - @Override - public boolean onError(MediaPlayer mp, int what, int extra){ - mUri1 = Uri.fromFile(new File(VideoFile1)); - mvideoview1.setVideoURI(mUri1); - mvideoview1.start(); - return true; - } - }); + mvideoview1.start(); + mvideoview1.setOnCompletionListener( + new MediaPlayer.OnCompletionListener() { + @Override + public void onCompletion(MediaPlayer mp) { + mvideoview1.start(); + } + }); + mvideoview1.setOnErrorListener( + new MediaPlayer.OnErrorListener() { + @Override + public boolean onError(MediaPlayer mp, int what, int extra) { + mUri1 = Uri.fromFile(new File(VideoFile1)); + mvideoview1.setVideoURI(mUri1); + mvideoview1.start(); + return true; + } + }); } public VideoView getSurfaceView() { @@ -294,5 +290,3 @@ public VideoView getSurfaceView() { } } } - -