2013-06-04 4 views
1

저는 Redlaser의 스캐너 라이브러리로 구축 된 바코드 스캐너 응용 프로그램에서 작업 중이며 카메라의 방향을 전환하는 버튼을 스캐너 오버레이에 구현하려고합니다. 나는 많은 시간 동안이 문제에 있었고 나는 여전히 어떤 해결책도 찾을 수 없다. 다음은 시도했지만 시도하지 못한 솔루션 목록입니다. 어쩌면 누군가가 그걸 개선하거나 뭔가 다른 것을 생각해 낼 수 있습니다.카메라 방향 변경

1. 그대로 회전 - 그대로 방향을 유지하고 버튼을 돌리십시오. 사용할 수 없음 : 회전은 Android 2.3에서 사용할 수 없으며 앱은 2.3과 호환되어야합니다.

2. 오리엔테이션을 변경하려면 android:configChanges="keyboardHidden|orientation|screenSize"setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);을 사용하십시오. 기능적 :이 뷰를 회전 시키지만 이미지가 왜곡되며 전화기를 위로 움직이면 카메라가 왼쪽으로 이동합니다. 솔루션 2. 불가능

3.Use camera.setDisplayOrientation(90); :camera 객체가 RedLaser 라이브러리 코드 내에서 위치와 내가 액세스 할 수 없습니다. 즉 ScannerActivity.java에는 Camera 객체가 없습니다. 그래서 나는 사용되는 것에 대한 참조를 만드는 방법을 모른다.

4. 사용 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);확실하지 않음 :이 작동하지만이 작업이 다시 시작되고 데이터를 유지해야합니다. 나는 this article에 익숙하지만 그것을 사용하는 좋은 방법을 찾지 못했습니다. 어떤 활동이 포함 된 모든 데이터에 ArrayList<BarcodeResult>이 저장되기를 바랍니다.

아이디어가 있으십니까?

+0

이 문서에서는 중요한 데이터를 유지하는 방법에 대해 설명합니다. 정확히 무슨 문제가 있습니까? – Fildor

+0

글쎄, 어떻게 'ArrayList '항목을 세션간에 저장할 수 있습니까? 또는 다른 유형의 비 프리미티브. – Sebek

+0

글쎄, 당신은 파일에 직렬화하거나 DB에 쓸 수 있습니다. "좋은 길"은 무엇이라고 생각하십니까? 그 기사를 [데이터 지속성] (http://developer.android.com/guide/topics/data/data-storage.html)과 결합해야 할 것입니다. – Fildor

답변

1

좋습니다, 알겠습니다! 전체 UI를 붙여 세로 및 가로에 대한 새로운 하나에 대한 원본을 사용

레이아웃 XML을 복사 5.In : 내시는이 위대한 생각을했다 물론

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" > 

<LinearLayout 
    android:id="@+id/preview_frame_overlay" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_centerInParent="true" 
    android:orientation="vertical" 
    android:visibility="visible" > 

    <!-- here is the rest of the portait layout code --> 

</LinearLayout> 

<LinearLayout 
    android:id="@+id/preview_frame_overlay2" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_centerInParent="true" 
    android:orientation="vertical" 
    android:rotation="90" 
    android:visibility="gone" > 

<!-- here is the rest of the landscape layout code --> 

</LinearLayout> 

당신이 사용해야 android:configChanges="keyboardHidden|orientation|screenSize"

그리고 스캔 활동에 당신이 볼 수와 방향에 따라 사용할 수 있습니다 어떤 버튼을 변경해야합니다 :

//in onCreate 
if (!ProductionActivity.settingLandscape) // if landscape set to portait 
       { 

        portraitView.setVisibility(View.VISIBLE); 
        landscapeView.setVisibility(View.GONE); 
        findViewById(R.id.view_finder).setVisibility(View.VISIBLE); 
        findViewById(R.id.view_finder2).setVisibility(View.GONE); 
        ChangeToLandscape(false); 

       } else 
       { 

        portraitView.setVisibility(View.GONE); 
        landscapeView.setVisibility(View.VISIBLE); 
        findViewById(R.id.view_finder).setVisibility(View.GONE); 
        findViewById(R.id.view_finder2).setVisibility(View.VISIBLE); 
        ChangeToLandscape(true); 

        android.view.ViewGroup.LayoutParams params1 = landscapeView.getLayoutParams(); //used to resize screen 
        params1.height = mDisplay.getWidth(); 
        landscapeView.setLayoutParams(params1); 

       } 

그리고우리가 버튼을 참조 위임을 업데이트방법 :

private void ChangeToLandscape(boolean landscape) 
     { 
      if (landscape) 
       { 
        hintTextView = (TextView) findViewById(R.id.hint_text2); 
        foundTextView = (TextView) findViewById(R.id.num_found_text2); 
        tvLastBarcode = (TextView) findViewById(R.id.tv_lastBarcode2); 
        doneButton = (Button) findViewById(R.id.button_done2); 
        bMultiscan = (Button) findViewById(R.id.bMultiscan2); 
        toggleTorchButton = (Button) findViewById(R.id.button_toggle_torch2); 
        toggleLineButton = (Button) findViewById(R.id.button_toggle_line2); 
        bRotate = (Button) findViewById(R.id.bRotate2); 
        viewfinderView = findViewById(R.id.view_finder2); 

       } else 
       { 
        hintTextView = (TextView) findViewById(R.id.hint_text); 
        foundTextView = (TextView) findViewById(R.id.num_found_text); 
        tvLastBarcode = (TextView) findViewById(R.id.tv_lastBarcode); 
        doneButton = (Button) findViewById(R.id.button_done); 
        bMultiscan = (Button) findViewById(R.id.bMultiscan); 
        toggleTorchButton = (Button) findViewById(R.id.button_toggle_torch); 
        toggleLineButton = (Button) findViewById(R.id.button_toggle_line); 
        bRotate = (Button) findViewById(R.id.bRotate); 
        viewfinderView = findViewById(R.id.view_finder); 
       } 
    //and then we re-assign the buttons delegates 
    doneButton.setOnClickListener(new OnClickListener() 
       { 
        public void onClick(View v) 
         { 
          doneScanning(); 
         } 
       }); //....etc 
    } 

활동이 결코 나의 데이터가 보존하고 위대한 작품을 다시 시작하지이 아이디어를 사용.