JAVA/android_studio 2024. 10. 29. 08:52

 

C:\>type scrcpy-serial_no.bat
rem C:\prj\2022-StandardPhaseTracer\utils\scrcpy-win64-v1.24>scrcpy.exe
rem scrcpy 1.24 <https://github.com/Genymobile/scrcpy>
rem ERROR: Multiple (2) ADB devices:
rem ERROR:     -->   (usb)      11160b600b7d0202            device  SM_G920S
rem ERROR:     -->   (usb)  To0be0filled0by0O0E0            device  X16_Power_D6F7_
rem ERROR: Select a device via -s (--serial), -d (--select-usb) or -e (--select-tcpip)
rem ERROR: Server connection failed
rem
rem

scrcpy -s 11160b600b7d0202

C:\>

'JAVA > android_studio' 카테고리의 다른 글

[Android, DialogFragment] 다이얼로그 프래그먼트 만들기  (0) 2025.03.21
자바 ArrayList 사용 방법  (0) 2024.10.31
Thread.sleep not crash app  (1) 2024.10.24
자바 코드 실행시간 구하기  (2) 2024.10.23
Timeout Dialog  (1) 2024.10.23
posted by cskimair
:
JAVA/android_studio 2024. 10. 24. 13:50

- Java Thread.sleep

https://stackoverflow.com/questions/43060701/thread-sleep-not-crashes-my-app

 

Thread.sleep not crashes my app

By calling Thread.sleep on the UI thread i expect my android app to crash, but it does not. I tried to explicitly run this on UI thread, by using runOnUiThread but the result was the same, the app

stackoverflow.com

 

posted by cskimair
:
JAVA/android_studio 2024. 10. 23. 12:01

 

-

long startTime = System.currentTimeMillis();

// 실행 시간을 측정하고자 하는 코드

long endTime = System.currentTimeMillis();
long elapsedTime = endTime - startTime;
System.out.println("Elapsed time: " + elapsedTime + "ms");
출처: https://alisyabob.tistory.com/396 [it 공부 끄적이기:티스토리]

 

https://alisyabob.tistory.com/396

 

[Java] 자바 코드 실행 시간 구하는 방법

[Java] 자바 코드 실행 시간 구하는 방법 알아보기 1. System.currentTimeMillis()와 System.nanoTime() 메서드를 사용하는 방법 System.currentTimeMillis() 메서드는 현재 시간을 밀리초 단위로 반환 long startTime = System

alisyabob.tistory.com

 

Instant start = Instant.now();

// 실행 시간을 측정하고자 하는 코드

Instant end = Instant.now();
long elapsedTime = Duration.between(start, end).toMillis();
System.out.println("Elapsed time: " + elapsedTime + "ms");
출처: https://alisyabob.tistory.com/396 [it 공부 끄적이기:티스토리]
posted by cskimair
:
JAVA/android_studio 2024. 10. 23. 10:42

-

public class MainActivity extends Activity {

    static final int TIME_OUT = 5000;

    static final int MSG_DISMISS_DIALOG = 0;

    private AlertDialog mAlertDialog;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        createDialog();
    }

    private Handler mHandler = new Handler() {
        public void handleMessage(android.os.Message msg) {
            switch (msg.what) {
            case MSG_DISMISS_DIALOG:
                if (mAlertDialog != null && mAlertDialog.isShowing()) {
                    mAlertDialog.dismiss();
                }
                break;

            default:
                break;
            }
        }
    };

    private void createDialog() {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setPositiveButton("OK", null)
            .setNegativeButton("cacel", null);
        mAlertDialog = builder.create();
        mAlertDialog.show();
        // dismiss dialog in TIME_OUT ms
        mHandler.sendEmptyMessageDelayed(MSG_DISMISS_DIALOG, TIME_OUT);
    }
}

https://stackoverflow.com/questions/17628784/how-to-timeout-an-alertdialog-in-android

 

How to timeout an AlertDialog in Android?

How can i handle timeout in an alertdialog. It has the standard yes/no button but i want to call the no button code if the user doesn't press anything in 5 minutes. I've looked at the class in Andr...

stackoverflow.com

 

'JAVA > android_studio' 카테고리의 다른 글

Thread.sleep not crash app  (1) 2024.10.24
자바 코드 실행시간 구하기  (2) 2024.10.23
GPS - UBLOX NEO-6M PPS pulse length and frequency setting  (0) 2024.10.04
안전하지 않은 앱 차단됨  (0) 2024.09.17
TedPermission  (0) 2024.09.17
posted by cskimair
:
JAVA/android_studio 2024. 10. 4. 14:34

 

- setting : 
https://www.waveshare.com/wiki/UART_GPS_NEO-6M

GPS - UBLOX NEO-6M  설정 프로그램 
- ucenter s/w 
https://www.u-blox.com/en/product/u-center

- PPS setting : 25page 
https://www.waveshare.com/w/upload/a/a9/U-blox-6-Receiver-Description-Including-Protocol-Specification.pdf

> change guide: 

posted by cskimair
:
JAVA/eclipse 2024. 9. 28. 13:27

 

-

-

package SRC_1;
import java.io.File;
import java.util.Random; 

class SampleProject {

	//public static void main() {
	public static void main(String[] args) {
		
/* 		args = new String[3]; //3개의 저장공간을 가진 배열 초기화
		args[0] = "안녕"; //배열의 첫번째 공간에 데이터입력
		args[1] = "반가워"; //배열의 두번째 공간에 데이터입력
		args[2] = "버물리라고해"; //배열의 세번째 공간에 데이터입력
		
		System.out.println(args[0]);
		System.out.println(args[1]);
		System.out.println(args[2]);
*/		
		SampleProject smpl  = new SampleProject() ; 
		
		smpl.initZeroCrossingData() ; 
	}
	
	//Integer[] zc_Tinfo_server = new Integer[60] ; 
	int[] zc_Tinfo_server = new int[60] ;
	public Integer getRandomnumber(Integer begin, Integer end){
		//For a more generic "in between two numbers" use:

		Random r = new Random();
		int low = 10;
		int high = 100;
		int result = r.nextInt(high-low) + low;

		//This gives you a random number in between 10 (inclusive) and 100 (exclusive)
		
		return result ; 
	}
	
	String[] zc_finder ; 
	int[]  zc_finderInt ;
	
	/*
	 * output: 
	 idx=52, zc_Tinfo_server=52002, zc_finderInt[k - nStart  ]=52154, nDiff=3090
Hello world
nCnt=5
zc_finder: count=5
zc_finder[k=0]=49165, 0
zc_finder[k=1]=50161, 0
zc_finder[k=2]=51157, 0
zc_finder[k=3]=52154, 0
zc_finder[k=4]=53150, 0
idx=49, zc_Tinfo_server=49067, zc_finderInt[k - nStart  ]=49165, nDiff=98
idx=50, zc_Tinfo_server=50030, zc_finderInt[k - nStart  ]=50161, nDiff=131
idx=51, zc_Tinfo_server=51088, zc_finderInt[k - nStart  ]=51157, nDiff=69
idx=52, zc_Tinfo_server=52086, zc_finderInt[k - nStart  ]=52154, nDiff=68
idx=53, zc_Tinfo_server=53029, zc_finderInt[k - nStart  ]=53150, nDiff=121
	 */
	public void initZeroCrossingData() {

		String a2 ;
		String data = "1X05,49165,50161,51157,52154,53150,\n" ;   //20240927

		String aa = data;
		//Toast.makeText(getApplicationContext(), " MCU Data : " + data, Toast.LENGTH_LONG).show();
		//Log.d("phase", " PPPPPv  ---------------    PPPPPPPPP ======= > " + data + "\n");

		// new format recv(ex. aa) : "1X05,49165,50161,51157,52154,53150,\n"  //20240927
		
		System.out.println("Hello world" ); 
		for(Integer t = 0 ; t < 60 ; t++ ) {
			Random r = new Random();
			zc_Tinfo_server[t] = t * 1000  + r.nextInt(100) ; 
		}

		a2 = aa.substring(1, 2);// get phase id like "A", "B", "C"
		if( a2.equalsIgnoreCase("X")) { // 20240927-1
				int nCnt = Integer.valueOf(aa.substring(2, 4 ) )  ; // get number of zero-corssing time info.
				aa = aa.replaceAll("\n","");
				System.out.println("nCnt=" + nCnt ) ; 
				String str = aa.replace(" ", "") ;
				//String[] zc_finder = str.split(",");
				zc_finder = str.substring(5,  str.length()).split(",") ;
				zc_finderInt = new int[ nCnt  ] ;
				int nStart =0 ;
				
				System.out.println("zc_finder: count=" + zc_finder.length ) ; 
				
				for (int k = 0 ; k< nCnt  ; k++) {// convert String info. to int, skip index k=0, it is only count information  not data 
					zc_finderInt[k] =   (int) Integer.parseInt(zc_finder[k])     ; 
					System.out.println( "zc_finder[k="+ k + "]" +"=" + zc_finder[k] +", "  + nStart) ;
				}
				
				int nDiff =0; 
				try {
					nStart = (zc_finderInt[0] /1000 )%100 ;
				}catch( Exception e) {
					e.printStackTrace() ; 
				}
				
				for(int k =  nStart  ; k <  nStart + nCnt  ; k++  ){
					//Log.d("zc_Tinfo_server" , "idx=" + k  + ", zc_Tinfo_server=" +zc_Tinfo_server [k ] ) ;
					nDiff = Math.abs(zc_Tinfo_server[k ] - zc_finderInt[k - nStart ] )  ;//get diff. between server time and finder time  
					System.out.println("idx=" + k  + ", zc_Tinfo_server=" +zc_Tinfo_server [k ] + 
							", zc_finderInt[k - nStart  ]="+ zc_finderInt[k - nStart  ] + ", nDiff=" + nDiff ) ;
				}

				return ;
		}
	}
	
	public void initZeroCrossingDataOld() {

		String a2 ;
		String data = "1X05,49165,50161,51157,52154,53150,\n" ;   //20240927

		String aa = data;
		//Toast.makeText(getApplicationContext(), " MCU Data : " + data, Toast.LENGTH_LONG).show();
		//Log.d("phase", " PPPPPv  ---------------    PPPPPPPPP ======= > " + data + "\n");

		// new format recv(ex. aa) : "1X05,49165,50161,51157,52154,53150,\n"  //20240927
		
		System.out.println("Hello world" ); 
		for(Integer t = 0 ; t < 60 ; t++ ) {
			Random r = new Random();
			zc_Tinfo_server[t] = t * 1000  + r.nextInt(100) ; 
		}

		a2 = aa.substring(1, 2);// get phase id like "A", "B", "C"
		if( a2.equalsIgnoreCase("X")) { // 20240927-1
				int nCnt = Integer.valueOf(aa.substring(2, 4 ) )  ; // get number of zero-corssing time info.
				aa = aa.replaceAll("\n","");
				System.out.println("nCnt=" + nCnt ) ; 
				String str = aa.replace(" ", "") ;
				//String[] zc_finder = str.split(",");
				String[] zc_finder = str.substring(5,  str.length()).split(",") ;
				Integer[]  zc_finderInt = new Integer[ nCnt  ] ;
				Integer nStart  ;
				
				System.out.println("zc_finder: count=" + zc_finder.length ) ; 
				
				nStart = 0 ; 
				for (Integer k = 0 ; k< nCnt  ; k++) {// skip index k=0, it is only count information  not data 
					zc_finderInt[k] = new Integer(zc_finder[ k]  )  ; 
					System.out.println( "zc_finder[k="+ k + "]" +"=" + zc_finder[k] +", "  + nStart) ;
				}				
				

				try {
					nStart = (zc_finderInt[0] /1000 )%100 ;
				}catch( Exception e) {
					e.printStackTrace() ; 
				}
				
				int nDiff =0; 
				
				for(Integer k = nStart ; k < nStart + nCnt  ; k++  ){
						//Log.d("zc_Tinfo_server" , "idx=" + k  + ", zc_Tinfo_server=" +zc_Tinfo_server [k ] ) ;
					//nDiff = Math.abs(zc_Tinfo_server[k].intValue() - zc_finderInt[k].intValue() )  ; 
						System.out.println("idx=" + k  + ", zc_Tinfo_server=" +zc_Tinfo_server [k ] + ", nDiff=" + nDiff ) ;
				}

				return ;
		}
	}	

	

}//출처: https://javacpro.tistory.com/11 [버물리의 IT공부:티스토리]


public class TestMemorySize {
	public static void memoryStats() {
	    int mb = 1024 * 1024;
	    // get Runtime instance
	    Runtime instance = Runtime.getRuntime();
	    System.out.println("***** Heap utilization statistics [MB] *****\n");
	    // available memory
	    System.out.println("Total Memory: " + instance.totalMemory() / mb);
	    // free memory
	    System.out.println("Free Memory: " + instance.freeMemory() / mb);
	    // used memory
	    System.out.println("Used Memory: "
	            + (instance.totalMemory() - instance.freeMemory()) / mb);
	    // Maximum available memory
	    System.out.println("Max Memory: " + instance.maxMemory() / mb);
	}	
	  public static void main(String[] args) {
		  memoryStats(); 
	  /* Total number of processors or cores available to the JVM */
	  System.out.println("Available processors (cores): " + 
	  Runtime.getRuntime().availableProcessors());

	  /* Total amount of free memory available to the JVM */
	  System.out.println("Free memory (bytes): " + 
	  Runtime.getRuntime().freeMemory());

	  /* This will return Long.MAX_VALUE if there is no preset limit */
	  long maxMemory = Runtime.getRuntime().maxMemory();
	  /* Maximum amount of memory the JVM will attempt to use */
	  System.out.println("Maximum memory (bytes): " + 
	  (maxMemory == Long.MAX_VALUE ? "no limit" : maxMemory));

	  /* Total memory currently in use by the JVM */
	  System.out.println("Total memory (bytes): " + 
	  Runtime.getRuntime().totalMemory() + "\n" );
	  System.out.println("KB: " + (double) (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / 1024 + "\n");
	  /* Get a list of all filesystem roots on this system */
	  File[] roots = File.listRoots();

	  /* For each filesystem root, print some info */
	  for (File root : roots) {
	    System.out.println("File system root: " + root.getAbsolutePath());
	    System.out.println("Total space (bytes): " + root.getTotalSpace());
	    System.out.println("Free space (bytes): " + root.getFreeSpace());
	    System.out.println("Usable space (bytes): " + root.getUsableSpace());
	  }
	 }
	}
/* 실행결과 , Output : 
입력데이터: "1X05,49165,50161,51157,52154,53150,\n" 

- 실행결과 
Hello world
nCnt=5
zc_finder[k=1]=49165
zc_finder[k=2]=50161
zc_finder[k=3]=51157
zc_finder[k=4]=52154
zc_finder[k=5]=53150
idx=49, zc_Tinfo_server=49020
idx=50, zc_Tinfo_server=50019
idx=51, zc_Tinfo_server=51065
idx=52, zc_Tinfo_server=52067
idx=53, zc_Tinfo_server=53067

※ 자바 Integer클래스와 int 데이터타입 
[Java] Integer - 생성자, int 변환
https://priming.tistory.com/23


*/

package SRC_1;

import java.io.File;

import java.util.Random; 

class SampleProject {
 public SampleProject() {}; 

//public static void main() {
public static void main(String[] args) {

/*  args = new String[3]; //3개의 저장공간을 가진 배열 초기화
args[0] = "안녕"; //배열의 첫번째 공간에 데이터입력
args[1] = "반가워"; //배열의 두번째 공간에 데이터입력
args[2] = "버물리라고해"; //배열의 세번째 공간에 데이터입력

System.out.println(args[0]);
System.out.println(args[1]);
System.out.println(args[2]);
*/
SampleProject smpl  = new SampleProject() ; 

smpl.initZeroCrossingData() ; 
}

Integer[] zc_Tinfo_server = new Integer[60] ; 
public Integer getRandomnumber(Integer begin, Integer end){
//For a more generic "in between two numbers" use:

Random r = new Random();
int low = 10;
int high = 100;
int result = r.nextInt(high-low) + low;

//This gives you a random number in between 10 (inclusive) and 100 (exclusive)

return result ; 
}


public void initZeroCrossingData() {

String a2 ;
String data = "1X05,49165,50161,51157,52154,53150,\n" ;   //20240927

String aa = data;
//Toast.makeText(getApplicationContext(), " MCU Data : " + data, Toast.LENGTH_LONG).show();
//Log.d("phase", " PPPPPv  ---------------    PPPPPPPPP ======= > " + data + "\n");

// new format recv(ex. aa) : "1X05,49165,50161,51157,52154,53150,\n"  //20240927

System.out.println("Hello world" ); 
for(Integer t = 0 ; t < 60 ; t++ ) {
Random r = new Random();
zc_Tinfo_server[t] = t * 1000  + r.nextInt(100) ; 
}

a2 = aa.substring(1, 2);// get phase id like "A", "B", "C"
if( a2.equalsIgnoreCase("X")) { // 20240927-1
int nCnt = Integer.valueOf(aa.substring(2, 4 ) )  ; // get number of zero-corssing time info.
aa = aa.replaceAll("\n","");
System.out.println("nCnt=" + nCnt ) ; 
String str = aa.replace(" ", "") ;
String[] zc_finder = str.split(",");
Integer[]  zc_finderInt = new Integer[ nCnt  ] ;
Integer nStart  ;
//foreach( String )
for (Integer k = 1 ; k<= nCnt  ; k++) {// skip index k=0, it is only count information  not data 
//zc_finderT[k] = new Integer ( Integer.valueOf(zc_finder[k]) ) ; 
//zc_infoT[k] = Integer.valueOf(zc_info[k]) ;
//Log.d("ZC_TInfo", "k=" + zc_infoT[k] + ", zc_timeInfo=" + zc_infoT[k]  % 1000  ) ;
zc_finderInt[k-1] = new Integer(zc_finder[ k]  )  ; 
System.out.println( "zc_finder[k="+ k + "]" +"=" + zc_finder[k]   ) ;
}

nStart = 0 ; 

try {
nStart = (zc_finderInt[0] /1000 )%100 ;
}catch( Exception e) {
e.printStackTrace() ; 
}

for(Integer k = nStart ; k < nStart + nCnt  ; k++  ){
//Log.d("zc_Tinfo_server" , "idx=" + k  + ", zc_Tinfo_server=" +zc_Tinfo_server [k ] ) ;
System.out.println("idx=" + k  + ", zc_Tinfo_server=" +zc_Tinfo_server [k ] ) ;
}


//zc_Tinfo_server

return ;
}
}

}//출처: https://javacpro.tistory.com/11 [버물리의 IT공부:티스토리]

posted by cskimair
: