1>frameworks\base\packages\SystemUI\res\layout-sw600dp\status_bar.xml:
<com.android.systemui.statusbar.policy.KeyButtonView android:id="@+id/sysbar_screenrotate" android:layout_width="80dip" android:layout_height="match_parent" android:src="@drawable/ic_sysbar_rotate" systemui:glowBackground="@drawable/ic_sysbar_highlight" /> android:visibility="visible" |
2>frameworks\base\packages\SystemUI\src\com\android\systemui\statusbar\tablet\TabletStatusBar.java:
import android.content.ServiceConnection; import android.content.ComponentName; import android.os.Messenger; import android.util.Log; import android.os.ServiceManager; import android.view.Surface; import android.view.IWindowManager;//cao import android.provider.Settings; import android.database.ContentObserver; import android.content.ContentResolver; public static boolean AUTO_ROTATE = true; //cao public static final String TAG = "TabletStatusBar"; View mRecentButton; View mScreenRotate;//cao private ContentObserver mScreenRotationObserver = new ContentObserver(new Handler()) { @Override public void onChange(boolean selfChange) { onScreenRotateChanged(); } }; public void onScreenRotateChanged() { final Context context = mContext; ContentResolver resolver = mContext.getContentResolver(); Slog.d(TAG, "onScreenRotateChanged-------------"); if (Settings.System.getInt(resolver,Settings.System.ACCELEROMETER_ROTATION, 0) != 0) { AUTO_ROTATE=true; ((ImageView)mScreenRotate).setImageResource(R.drawable.ic_sysbar_rotate); } else { ((ImageView)mScreenRotate).setImageResource(R.drawable.ic_sysbar_rotate_lock); AUTO_ROTATE=false; } } protected View makeStatusBarView() { //cao 20121228 ContentResolver resolver = mContext.getContentResolver(); resolver.registerContentObserver( Settings.System.getUriFor(Settings.System.ACCELEROMETER_ROTATION), true, mScreenRotationObserver); mScreenRotate = mNavigationArea.findViewById(R.id.sysbar_screenrotate); //set rotate icon if (Settings.System.getInt(resolver,Settings.System.ACCELEROMETER_ROTATION, 0) == 0) ((ImageView)mScreenRotate).setImageResource(R.drawable.ic_sysbar_rotate_lock); mScreenRotate.setOnClickListener(mOnClickListener); private View.OnClickListener mOnClickListener = new View.OnClickListener() { public void onClick(View v) { else if (v == mScreenRotate) { //mScreenRotate.setBackgroundResource(R.drawable.ic_sysbar_highlight); onClickScreenRotateButton(); //cao start } public void onClickScreenRotateButton() { Slog.d(TAG, "onClickScreenRotateButton-------------"); try { IWindowManager wm = IWindowManager.Stub.asInterface( ServiceManager.getService(Context.WINDOW_SERVICE)); if (!AUTO_ROTATE) { ((ImageView)mScreenRotate).setImageResource(R.drawable.ic_sysbar_rotate); wm.thawRotation(); } else { ((ImageView)mScreenRotate).setImageResource(R.drawable.ic_sysbar_rotate_lock); //wm.freezeRotation(Surface.ROTATION_0);//锁定为0方向 wm.freezeRotation(wm.getRotation());//锁定为当前方向 } } catch (RemoteException exc) { Log.w(TAG, "Unable to save auto-rotate setting");} } |