add dual screen function

This commit is contained in:
Firefly
2015-09-24 13:57:37 +08:00
committed by cjp
parent 7bebe1667f
commit d1dd0d369b
9 changed files with 256 additions and 1 deletions

View File

@ -1869,6 +1869,24 @@
android:value="true" />
</activity>
<!-- add by wgh-->
<activity android:name="Settings$DualscreenSettingsActivity"
android:label="@string/dualscreen_setting"
android:taskAffinity="">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<action android:name="android.settings.DREAM_SETTINGS" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="com.android.settings.SHORTCUT" />
</intent-filter>
<meta-data android:name="com.android.settings.FRAGMENT_CLASS"
android:value="com.android.settings.dualscreen.DualscreenSettings" />
<meta-data android:name="com.android.settings.TOP_LEVEL_HEADER_ID"
android:resource="@id/display_settings" />
<meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
android:value="true" />
</activity>
<activity android:name="Settings$UserSettingsActivity"
android:label="@string/user_settings_title"
android:taskAffinity="">

Binary file not shown.

After

Width:  |  Height:  |  Size: 849 B

8
packages/apps/Settings/res/values-zh-rCN/strings.xml Normal file → Executable file
View File

@ -2540,6 +2540,14 @@
<string name="screenshot_storage_title">设置截屏图片存储位置</string>
<string name="later">秒以后截屏</string>
<!-- dual screen but different contents-->
<string name="dualscreen_setting">双屏显示</string>
<string name="dualscreen_manual">双屏显示手册</string>
<string name="dualscreen_settings_title">双屏显示</string>
<string name="dualscreen_manual_summary">"启用此功能如果有连接hdmi您可以在平板和电视两个屏幕上运行不同的应用比如说您可以在电视上播放视频而平板上运行其它应用程序。
\n\n两屏显示模式切换:\n <ul>\n两屏显示不同内容:\n 手指触摸屏幕左边50个像素区域快速向右滑动或者触摸屏幕右边50个像素区域快速向左滑动焦点应用窗口就只在电视上显示而平板上可以操作其它的应用程序。
\n\n两屏显示相同内容:\n 状态栏上有一个同步的按钮(在最近打开应用程序图标的右边),点击按钮即可让两屏显示相同内容。</ul>"</string>
<!-- ethernet settings by blb-->
<string name="ethernet_settings">以太网</string>
<string name="ethernet_connect">连接</string>

8
packages/apps/Settings/res/values/strings.xml Normal file → Executable file
View File

@ -6081,6 +6081,14 @@
<string name="screenshot_storage_title">Set the location of screenshot storage</string>
<string name="later">s later capture</string>
<!-- dual screen but different contents-->
<string name="dualscreen_setting">Dual-Screen</string>
<string name="dualscreen_manual">Dual-Screen Manual</string>
<string name="dualscreen_settings_title">Dual screen</string>
<string name="dualscreen_manual_summary">"When this feature is turned on,If the pad have connected to the HDMI,you can run different applications in pad and TV two screens,for example, you can play video on TV, and run other applications on pad.
\n\nThe switching of two display mode:\n <ul>\nShow different content on two screen:\n Touch screen on the left side of the 50 pixel region and fast slide to the right or touch screen on the right side of the 50 pixel region and fast slide to the left, the focus application window will only display on TV, and the pad can operate other applications.
\n\nShow same content on two screen:\n There is a simultaneous button on the status bar (right of the recently application icon), click on the button to make the two screen display the same content.</ul>"</string>
<!-- ethernet settings by blb-->
<string name="ethernet_settings">Ethernet</string>
<string name="ethernet_connect">Connect</string>

6
packages/apps/Settings/res/xml/display_settings.xml Normal file → Executable file
View File

@ -119,6 +119,12 @@
android:targetPackage="com.android.settings"
android:targetClass="com.android.settings.screen.ScreenScaleActivity" />
</Preference>
<!-- add by wgh-->
<PreferenceScreen
android:key="dualscreen"
android:title="@string/dualscreen_setting"
android:fragment="com.android.settings.dualscreen.DualscreenSettings" />
<ListPreference
android:key="main_screen_interface"/>

View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
<PreferenceScreen
android:key="dualscreen_manual"
android:fragment="com.android.settings.dualscreen.DualScreenSettings$ToggleDualScreenManualPreferenceFragment"
android:title="@string/dualscreen_manual"
/>
</PreferenceScreen>

View File

@ -104,5 +104,6 @@ public class Settings extends SettingsActivity {
public static class HdmiSettingsActivity extends SettingsActivity { /* empty */ }
public static class ScreenshotSettingsActivity extends SettingsActivity { /* empty */ }
public static class UsbConnectSettingsActivity extends SettingsActivity { /* empty */ }
public static class DualscreenSettingsActivity extends SettingsActivity { /* empty */ }
}

View File

@ -115,6 +115,7 @@ import com.android.settings.wifi.p2p.WifiP2pSettings;
import com.android.settings.HdmiSettings;
import com.android.settings.ScreenshotSetting;
import com.android.settings.UsbSetting;
import com.android.settings.dualscreen.DualscreenSettings;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
@ -312,7 +313,8 @@ public class SettingsActivity extends Activity
ApnSettings.class.getName(),
HdmiSettings.class.getName(),
ScreenshotSetting.class.getName(),
UsbSetting.class.getName()
UsbSetting.class.getName(),
DualscreenSettings.class.getName()
};

View File

@ -0,0 +1,202 @@
/*
* Copyright (C) 2012 The Android Open Source Project
*
* 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.android.settings.dualscreen;
import android.app.Activity;
import android.app.Dialog;
import android.app.DialogFragment;
import android.app.Fragment;
import android.content.ContentResolver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.pm.PackageManager;
import android.database.DataSetObserver;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.preference.PreferenceFragment;
import android.preference.PreferenceGroupAdapter;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.Switch;
import android.widget.TextView;
import android.database.ContentObserver;
import android.os.Handler;
import android.provider.Settings;
import android.app.ActivityManagerNative;
import android.app.IActivityManager;
import android.content.res.Configuration;
import android.os.RemoteException;
import com.android.settings.R;
import android.view.Gravity;
import com.android.settings.SettingsActivity;
import com.android.settings.SettingsPreferenceFragment;
import com.android.settings.widget.SwitchBar;
public class DualscreenSettings extends SettingsPreferenceFragment implements SwitchBar.OnSwitchChangeListener {
private static final String TAG = DualscreenSettings.class.getSimpleName();
static final boolean DEBUG = true;
private static final String KEY_DUALSCREEN_MANUAL = "dualscreen_manual";
private boolean mOpened;
private final String store_key = Settings.System.DUAL_SCREEN_MODE;
private final String icon_key = Settings.System.DUAL_SCREEN_ICON_USED;
private final int DUAL_SCREEN_CLOSE = 0;
private final int DUAL_SCREEN_OPEN = 1;
private Context mContext;
private SwitchBar mSwitchBar;
@Override
public void onAttach(Activity activity) {
logd("onAttach(%s)", activity.getClass().getSimpleName());
super.onAttach(activity);
mContext = activity;
}
@Override
public void onCreate(Bundle icicle) {
logd("onCreate(%s)", icicle);
super.onCreate(icicle);
//mManual = (PreferenceScreen)findPreference(KEY_DUALSCREEN_MANUAL);
}
@Override
public void onSwitchChanged(Switch switchView, boolean isChecked) {
logd("-----------------------------isChecked:"+isChecked);
int value = DUAL_SCREEN_CLOSE;
mContext.getContentResolver().unregisterContentObserver(mValueObserver);
mContext.getContentResolver().registerContentObserver(Settings.System.getUriFor(store_key), false, mValueObserver);
if (isChecked) {
value = DUAL_SCREEN_OPEN;
} else {
Settings.System.putInt(mContext.getContentResolver(), icon_key, 0);
}
Settings.System.putInt(mContext.getContentResolver(), store_key, value);
handleStateChanged(value);
}
@Override
public void onStart() {
logd("onStart()");
super.onStart();
}
@Override
public void onDestroyView() {
logd("onDestroyView()");
super.onDestroyView();
mSwitchBar.removeOnSwitchChangeListener(this);
mSwitchBar.hide();
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
logd("onActivityCreated(%s)", savedInstanceState);
super.onActivityCreated(savedInstanceState);
ListView listView = getListView();
listView.setItemsCanFocus(true);
TextView emptyView = (TextView) getView().findViewById(android.R.id.empty);
emptyView.setText(R.string.dualscreen_manual_summary);
emptyView.setTextSize(24);
emptyView.setGravity(Gravity.LEFT);
listView.setEmptyView(emptyView);
final SettingsActivity sa = (SettingsActivity) getActivity();
mSwitchBar = sa.getSwitchBar();
mSwitchBar.addOnSwitchChangeListener(this);
mSwitchBar.show();
}
@Override
public void onPause() {
logd("onPause()");
super.onPause();
mContext.getContentResolver().unregisterContentObserver(mValueObserver);
}
@Override
public void onResume() {
logd("onResume()");
super.onResume();
handleStateChanged(getDualScreenValue());
mContext.getContentResolver().registerContentObserver(Settings.System.getUriFor(store_key), false, mValueObserver);
}
private int getDualScreenValue(){
return Settings.System.getInt(mContext.getContentResolver(), store_key, DUAL_SCREEN_CLOSE);
}
void handleStateChanged(int state) {
switch (state) {
case DUAL_SCREEN_CLOSE:
mSwitchBar.setChecked(false);
break;
case DUAL_SCREEN_OPEN:
mSwitchBar.setChecked(true);
break;
}
}
private final ContentObserver mValueObserver = new ContentObserver(new Handler()) {
@Override
public void onChange(boolean selfChange) {
final boolean enable = (DUAL_SCREEN_CLOSE != getDualScreenValue());
Log.d(TAG, "onchagne enable=" + enable + ", selfChange=" + selfChange);
try {
IActivityManager am = ActivityManagerNative.getDefault();
Configuration config = am.getConfiguration();
// Will set userSetLocale to indicate this isn't some passing default - the user
// wants this remembered
config.setDualScreenFlag(enable);
am.updateConfiguration(config);
} catch (RemoteException e) {
// Intentionally left blank
}
}
};
private static void logd(String msg, Object... args) {
if (DEBUG)
Log.d(TAG, args == null || args.length == 0 ? msg : String.format(msg, args));
}
}