Init Cherih
This commit is contained in:
74
src/com/cherish/settings/CherishSettings.java
Normal file
74
src/com/cherish/settings/CherishSettings.java
Normal file
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Copyright (C) 2016 The Pure Nexus Project
|
||||
* used for Cherish OS
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.cherish.settings;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.pm.ActivityInfo;
|
||||
import android.content.res.Configuration;
|
||||
import android.os.Bundle;
|
||||
import android.view.Surface;
|
||||
import android.preference.Preference;
|
||||
import com.android.settings.R;
|
||||
|
||||
import com.android.settings.SettingsPreferenceFragment;
|
||||
|
||||
public class CherishSettings extends SettingsPreferenceFragment {
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle icicle) {
|
||||
super.onCreate(icicle);
|
||||
|
||||
addPreferencesFromResource(R.xml.cherish_settings);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return MetricsProto.MetricsEvent.CHERISH_SETTINGS;
|
||||
}
|
||||
|
||||
public static void lockCurrentOrientation(Activity activity) {
|
||||
int currentRotation = activity.getWindowManager().getDefaultDisplay().getRotation();
|
||||
int orientation = activity.getResources().getConfiguration().orientation;
|
||||
int frozenRotation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
|
||||
switch (currentRotation) {
|
||||
case Surface.ROTATION_0:
|
||||
frozenRotation = orientation == Configuration.ORIENTATION_LANDSCAPE
|
||||
? ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
|
||||
: ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
|
||||
break;
|
||||
case Surface.ROTATION_90:
|
||||
frozenRotation = orientation == Configuration.ORIENTATION_PORTRAIT
|
||||
? ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT
|
||||
: ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
|
||||
break;
|
||||
case Surface.ROTATION_180:
|
||||
frozenRotation = orientation == Configuration.ORIENTATION_LANDSCAPE
|
||||
? ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE
|
||||
: ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT;
|
||||
break;
|
||||
case Surface.ROTATION_270:
|
||||
frozenRotation = orientation == Configuration.ORIENTATION_PORTRAIT
|
||||
? ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
|
||||
: ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE;
|
||||
break;
|
||||
}
|
||||
activity.setRequestedOrientation(frozenRotation);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user