2011-02-09 15 views
1

アプリケーションがダイアログを起動し、ダイアログが終了したときにロックを解除したときに、ユーザーがどんな方向にでも画面をロックしようとしています。ここに私のロックがあると、コードのロックを解除:ダイアログを表示しているときに画面の回転をロックしようとしています

// Sets screen rotation as fixed to current rotation setting 
    private void mLockScreenRotation() { 
     Log.d("####################", "screen orientation is " + mContext.getResources().getConfiguration().orientation); 
     // Stop the screen orientation changing during an event 
     if (mContext.getResources().getConfiguration().orientation == 1) 
      ((Activity) mContext).setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);   
     else ((Activity) mContext).setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); 
//  switch (mContext.getResources().getConfiguration().orientation) 
//  { 
//   case Configuration.ORIENTATION_PORTRAIT: 
//    ((Activity) mContext).setRequestedOrientation(
//     ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); 
//    break; 
//   case Configuration.ORIENTATION_LANDSCAPE: 
//    ((Activity) mContext).setRequestedOrientation(
//     ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); 
//    break; 
//  } 
    } 

    // allow screen rotations again 
    private void mUnLockScreenRotation() { 
     this.setRequestedOrientation(
       ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); 
     mIsScreenRotationLocked = false; 
    }

私は任意のダイアログを起動し、私は私のハンドラで、私のDialogInterface.OnClickListenerの中で()mUnlockScreenRotationを呼び出したとき、私はmLockScreenRotation()を呼び出します。

私の画面はロックされたままですが、一貫性がありません。これをどうやって処理するのか?

ありがとうございました!

Ammendment:私は私の画面をロックしていますコード:

 public void displayProgressDialog(){ 
     mLockScreenRotation(); 
     // Get local handle on class progress dialog for optimization purposes 
     ProgressDialog temp = mProgressDialog = new ProgressDialog(this); 

     // Get message string (for some reason this dialog can't handle res IDs for messages) 
     String message = getString(R.string.downloading); 

     // Set some paramaters 
     temp.setIndeterminate(true); 
     temp.setTitle(R.string.weather_data); 
     temp.setMessage(message); 
     temp.setCancelable(false); 
     temp.getWindow().setFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND, 
       WindowManager.LayoutParams.MEMORY_TYPE_PUSH_BUFFERS /*WindowManager.LayoutParams.FLAG_BLUR_BEHIND*/); 

     temp.show(); 
    } 

    public void displayLocationSearchDialog(){ 
     mLockScreenRotation(); 
     // Get local handle on class progress dialog for optimization purposes 
     ProgressDialog temp = mCoordinateSearchDialog = new ProgressDialog(this); 

     // Get message string (for some reason this dialog can't handle res IDs for messages) 
     String message = getString(R.string.searching); 

     // Set some paramaters 
     temp.setIndeterminate(true); 
     temp.setTitle(R.string.location_search); 
     temp.setMessage(message); 
     temp.setCancelable(false); 
     temp.getWindow().setFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND, 
       WindowManager.LayoutParams.FLAG_BLUR_BEHIND); 

     temp.show(); 

    } 

    public void showDatafeedFailedDialog(){ 
     mLockScreenRotation(); 
     new AlertDialog.Builder(this) 
      .setTitle(R.string.network_error) 
      .setMessage(R.string.weather_data_failed) 
      .setPositiveButton(R.string.try_again, mTryAgainListener) 
      .setNegativeButton(R.string.dismiss, null) 
      .create() 
      .show(); 
    } 

    public void showCoordinateSearchFailedDialog(){ 
     mLockScreenRotation(); 
     new AlertDialog.Builder(this) 
     .setTitle(R.string.network_error) 
     .setMessage(R.string.location_search_failed) 
     .setPositiveButton(R.string.try_again, mCoordTryAgainListener) 
     .setNegativeButton(R.string.dismiss, null) 
     .create() 
     .show(); 
    } 

    private void showGpsAlertDialog(){ 
     mLockScreenRotation(); 
     new AlertDialog.Builder(this) 
      .setTitle(R.string.gps_error) 
      .setMessage(R.string.gps_error_details) 
      .setNeutralButton(R.string.dismiss, null) 
      .setPositiveButton(R.string.go_to_settings, mToSettingsListener) 
      .create() 
      .show(); 
    } 

    private void showGpsSearchingDialog(){ 
     mLockScreenRotation(); 
     ProgressDialog temp = mGpsSearchAlertDialog = new ProgressDialog(this); 

     String message = getString(R.string.location_services_details); 
     String btnText = getString(R.string.cancel); 

     temp.setIndeterminate(true); 
     temp.setTitle(R.string.location_services); 
     temp.setMessage(message); 
     temp.setButton(btnText, mCancelGpsSearchListener); 
     temp.setCancelable(true); 
     temp.getWindow().setFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND, 
       WindowManager.LayoutParams.FLAG_BLUR_BEHIND); 

     temp.show(); 
    } 

    private void showGpsTimeoutAlertDialog(){ 
     mLockScreenRotation(); 
     new AlertDialog.Builder(this) 
     .setTitle(R.string.gps_error) 
     .setMessage(R.string.gps_timeout_message) 
     .setPositiveButton(R.string.try_again, mGpsTimeoutListener) 
     .setNegativeButton(R.string.dismiss, mGpsTimeoutListener) // check this line with free if still no good 
     .create() 
     .show(); 
    } 

    private void showWeatherAlertDialog(){ 
     Log.d("############", "weather alert dialog"); 
     mLockScreenRotation(); 
     String message = null; 
     if(mWD.getWarningTypes() == null) return; 
     int cnt = 0; 
     int size = mWD.getWarningTypes().size() - 1; 
     for(String warningType : mWD.getWarningTypes()){ 
      if(cnt == 0) message = warningType; 
      else if(cnt == size) message += " and " + warningType; 
      else message += ", " + warningType; 
      cnt++; 
     } 

     new AlertDialog.Builder(this) 
      .setTitle(R.string.watches_and_warnings) 
      .setMessage(message) 
      .setPositiveButton(R.string.go_to_accuweather, mToAlertWebListener) 
      .setNeutralButton(R.string.dismiss, null) 
      .create() 
      .show(); 
    } 

    private void showNeedLocationAlertDialog() { 
     mLockScreenRotation(); 
     new AlertDialog.Builder(this).setTitle(R.string.error).setMessage(
     R.string.add_location).setNeutralButton(R.string.dismiss, null) 
     .setPositiveButton(R.string.okay, mToLocationSearchListener) 
     .create().show(); 
    } 

    private void showConnectivityAlertDialog() { 
     mLockScreenRotation(); 
     new AlertDialog.Builder(this).setTitle(R.string.network_error) 
     .setMessage(R.string.no_connection).setNeutralButton(
     R.string.dismiss, null).create().show(); 
    } 

    private void showCurrentUrlInBrowser(){ 
     // Show current conditions web page 
     if(mWD.getURL() == null || mWD.getURL().length()
+0

「mLockScreenRotation」と呼ばれるコードを投稿してください。 – user432209

+0

私はmLockScreenRotationを呼び出すコードを追加しました。 – taraloca

答えて

0

代わりのダイアログ内向きを変更するための呼び出しを入れて(そしておそらく却下は直後にダイアログを言った)、あなたのダイアログにonDismissリスナーを実装してみてください(here)。

+0

ダイアログを起動するときに最初の画面の向きの方向を固定する必要があります。私はこれがonDismissリスナを使って私の画面をロックする方法はわかりません。 – taraloca

+0

質問が間違っている可能性があります。 「時には画面がロックされていることがある」と言うと、ダイアログが閉じられた後でも、画面がロックされたままになっていたとしても、あなたはそれを意味すると思っていました。 –

+0

再テストしようとしていますが、私のために働いています。テスト対象のデバイスはどのプラットフォームのバージョンですか?どのようなタイプのダイアログに基づいて動作が変更されますか(一貫してロックされます。見せている? –

1

これは悪い解決策ですが、機能します。 LG GT540(Android 2.3.7)とAsus Transformer(Android 3.2)でテスト済み:

private void stopRotate() 
{ 
    if(getResources().getConfiguration().orientation == 1) 
    { 
     if(display.getOrientation() == 1 || display.getOrientation() == 2) 
      setRequestedOrientation(9); 
     else  
      setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); 
    } 
    else 
    { 
     if(display.getOrientation() == 2 || display.getOrientation() == 3) 
      setRequestedOrientation(8); 
     else  
      setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); 
    } 
} 

private void startRotate() 
{ 
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); 
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR); 
} 
関連する問題