rework layout
This commit is contained in:
+6
-1
@@ -37,7 +37,12 @@
|
||||
<activity
|
||||
android:name=".AppManager"
|
||||
android:theme="@style/Theme.GAEProxy"
|
||||
android:label="@string/app_name"/>
|
||||
android:label="@string/app_name">
|
||||
<intent-filter>
|
||||
<action android:name="com.github.shadowsocks.AppManager" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<service
|
||||
android:name=".ShadowsocksService"
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.github.shadowsocks</groupId>
|
||||
@@ -35,6 +35,13 @@
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.actionbarsherlock</groupId>
|
||||
<artifactId>actionbarsherlock</artifactId>
|
||||
<version>4.3.0</version>
|
||||
<type>apklib</type>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.google.android.analytics</groupId>
|
||||
<artifactId>analytics</artifactId>
|
||||
@@ -47,6 +54,20 @@
|
||||
<version>1.5</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>net.saik0.android.unifiedpreference</groupId>
|
||||
<artifactId>unifiedpreference</artifactId>
|
||||
<version>0.0.2</version>
|
||||
<type>apklib</type>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.jraf</groupId>
|
||||
<artifactId>android-switch-backport</artifactId>
|
||||
<version>1.0</version>
|
||||
<type>apklib</type>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
<build>
|
||||
<finalName>${project.artifactId}</finalName>
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical" android:duplicateParentState="false">
|
||||
<TextView android:text="@string/proxyed_help"
|
||||
android:layout_width="fill_parent" android:layout_height="wrap_content"
|
||||
android:textSize="16sp" android:padding="3px" />
|
||||
<ListView android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content" android:id="@+id/applistview"></ListView>
|
||||
android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical" android:duplicateParentState="false">
|
||||
<TextView android:text="@string/proxied_help"
|
||||
android:layout_width="fill_parent" android:layout_height="wrap_content"
|
||||
android:textSize="16sp" android:padding="3dp"/>
|
||||
<ListView android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content" android:id="@+id/applistview"/>
|
||||
</LinearLayout>
|
||||
@@ -13,6 +13,5 @@
|
||||
|
||||
<CheckBox android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" android:id="@+id/itemcheck"></CheckBox>
|
||||
|
||||
</TableRow>
|
||||
</TableLayout>
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<org.jraf.android.backport.switchwidget.Switch
|
||||
android:id="@+id/switchButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_centerVertical="true"/>
|
||||
|
||||
</RelativeLayout>
|
||||
@@ -1,22 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Zirco Browser for Android
|
||||
|
||||
Copyright (C) 2010 - 2011 J. Devauchelle and contributors.
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
version 3 as published by the Free Software Foundation.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
-->
|
||||
|
||||
<resources>
|
||||
|
||||
<!-- Variation on the Light theme that turns off the title -->
|
||||
<style name="Theme.GAEProxy" parent="android:Theme.Holo.Light"/>
|
||||
|
||||
</resources>
|
||||
@@ -29,7 +29,7 @@
|
||||
</array>
|
||||
|
||||
<!-- feature category -->
|
||||
<string name="fearute_cat">Feature Settings</string>
|
||||
<string name="feature_cat">Feature Settings</string>
|
||||
<string name="http_proxy">HTTP Proxy</string>
|
||||
<string name="http_proxy_summary">Local HTTP Proxy</string>
|
||||
<string name="dns_proxy">DNS Proxy</string>
|
||||
@@ -40,10 +40,10 @@
|
||||
<string name="auto_set_proxy">Global Proxy</string>
|
||||
<string name="auto_set_proxy_summary">Set up system wide proxy
|
||||
</string>
|
||||
<string name="proxyed_apps">Individual Proxy</string>
|
||||
<string name="proxyed_apps_summary">Set individual proxy for apps
|
||||
<string name="proxied_apps">Individual Proxy</string>
|
||||
<string name="proxied_apps_summary">Set individual proxy for apps
|
||||
</string>
|
||||
<string name="proxyed_help">Select apps to use with Shadowsocks:</string>
|
||||
<string name="proxied_help">Select apps to use with Shadowsocks:</string>
|
||||
<string name="bypass_apps">Bypass Mode</string>
|
||||
<string name="bypass_apps_summary">Enable this option to bypass selected apps</string>
|
||||
<string name="auto_connect">Auto Connect</string>
|
||||
|
||||
Executable → Regular
+4
-1
@@ -17,6 +17,9 @@
|
||||
<resources>
|
||||
|
||||
<!-- Variation on the Light theme that turns off the title -->
|
||||
<style name="Theme.GAEProxy" parent="android:Theme.Light"/>
|
||||
<style name="Theme.GAEProxy" parent="@style/Theme.Sherlock.Light">
|
||||
<item name="switchStyle">@style/Widget.Holo.Light.CompoundButton.Switch</item>
|
||||
</style>
|
||||
|
||||
|
||||
</resources>
|
||||
Executable
+50
@@ -0,0 +1,50 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<CheckBoxPreference
|
||||
android:defaultValue="false"
|
||||
android:key="isHTTPProxy"
|
||||
android:summary="@string/http_proxy_summary"
|
||||
android:title="@string/http_proxy">
|
||||
</CheckBoxPreference>
|
||||
<CheckBoxPreference
|
||||
android:defaultValue="true"
|
||||
android:key="isDNSProxy"
|
||||
android:summary="@string/dns_proxy_summary"
|
||||
android:title="@string/dns_proxy">
|
||||
</CheckBoxPreference>
|
||||
<CheckBoxPreference
|
||||
android:defaultValue="true"
|
||||
android:key="isGFWList"
|
||||
android:summary="@string/auto_set_gfwlist_summary"
|
||||
android:title="@string/auto_set_gfwlist">
|
||||
</CheckBoxPreference>
|
||||
<CheckBoxPreference
|
||||
android:defaultValue="true"
|
||||
android:key="isGlobalProxy"
|
||||
android:disableDependentsState="true"
|
||||
android:summary="@string/auto_set_proxy_summary"
|
||||
android:title="@string/auto_set_proxy">
|
||||
</CheckBoxPreference>
|
||||
<CheckBoxPreference
|
||||
android:defaultValue="false"
|
||||
android:dependency="isGlobalProxy"
|
||||
android:key="isBypassApps"
|
||||
android:summary="@string/bypass_apps_summary"
|
||||
android:title="@string/bypass_apps">
|
||||
</CheckBoxPreference>
|
||||
<Preference
|
||||
android:key="proxyedApps"
|
||||
android:dependency="isGlobalProxy"
|
||||
android:summary="@string/proxied_apps_summary"
|
||||
android:title="@string/proxied_apps">
|
||||
<intent android:action="com.github.shadowsocks.AppManager"/>
|
||||
</Preference>
|
||||
<CheckBoxPreference
|
||||
android:key="isAutoConnect"
|
||||
android:summary="@string/auto_connect_summary"
|
||||
android:title="@string/auto_connect">
|
||||
</CheckBoxPreference>
|
||||
|
||||
|
||||
</PreferenceScreen>
|
||||
Executable
+36
@@ -0,0 +1,36 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<com.github.shadowsocks.preferences.SummaryEditTextPreference
|
||||
android:defaultValue="198.199.101.152"
|
||||
android:key="proxy"
|
||||
android:summary="@string/proxy_summary"
|
||||
android:title="@string/proxy">
|
||||
</com.github.shadowsocks.preferences.SummaryEditTextPreference>
|
||||
<com.github.shadowsocks.preferences.SummaryEditTextPreference
|
||||
android:defaultValue="443"
|
||||
android:key="remotePort"
|
||||
android:summary="@string/remote_port_summary"
|
||||
android:title="@string/remote_port">
|
||||
</com.github.shadowsocks.preferences.SummaryEditTextPreference>
|
||||
<com.github.shadowsocks.preferences.SummaryEditTextPreference
|
||||
android:defaultValue="1080"
|
||||
android:key="port"
|
||||
android:summary="@string/port_summary"
|
||||
android:title="@string/port">
|
||||
</com.github.shadowsocks.preferences.SummaryEditTextPreference>
|
||||
<com.github.shadowsocks.preferences.SummaryEditTextPreference
|
||||
android:defaultValue="u1rRWTssNv0p"
|
||||
android:key="sitekey"
|
||||
android:summary="@string/sitekey_summary"
|
||||
android:title="@string/sitekey">
|
||||
</com.github.shadowsocks.preferences.SummaryEditTextPreference>
|
||||
<ListPreference
|
||||
android:defaultValue="rc4"
|
||||
android:key="encMethod"
|
||||
android:entries="@array/enc_method_entry"
|
||||
android:entryValues="@array/enc_method_value"
|
||||
android:title="@string/enc_method">
|
||||
</ListPreference>
|
||||
|
||||
</PreferenceScreen>
|
||||
@@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<preference-headers xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:unified="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
<header
|
||||
unified:fragment="com.github.shadowsocks.Shadowsocks$ProxyFragment"
|
||||
unified:title="@string/proxy_cat"
|
||||
unified:preferenceRes="@xml/pref_proxy"/>
|
||||
<header
|
||||
unified:fragment="com.github.shadowsocks.Shadowsocks$FeatureFragment"
|
||||
unified:title="@string/feature_cat"
|
||||
unified:preferenceRes="@xml/pref_feature"/>
|
||||
|
||||
|
||||
</preference-headers>
|
||||
@@ -1,102 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<PreferenceCategory android:title="@string/function_cat">
|
||||
<CheckBoxPreference
|
||||
android:key="isRunning"
|
||||
android:disableDependentsState="true"
|
||||
android:summary="@string/service_summary"
|
||||
android:title="@string/service_controller">
|
||||
</CheckBoxPreference>
|
||||
|
||||
</PreferenceCategory>
|
||||
<PreferenceCategory android:title="@string/proxy_cat">
|
||||
<EditTextPreference
|
||||
android:dependency="isRunning"
|
||||
android:defaultValue="198.199.101.152"
|
||||
android:key="proxy"
|
||||
android:summary="@string/proxy_summary"
|
||||
android:title="@string/proxy">
|
||||
</EditTextPreference>
|
||||
<EditTextPreference
|
||||
android:dependency="isRunning"
|
||||
android:defaultValue="443"
|
||||
android:key="remotePort"
|
||||
android:summary="@string/remote_port_summary"
|
||||
android:title="@string/remote_port">
|
||||
</EditTextPreference>
|
||||
<EditTextPreference
|
||||
android:dependency="isRunning"
|
||||
android:defaultValue="1080"
|
||||
android:key="port"
|
||||
android:summary="@string/port_summary"
|
||||
android:title="@string/port">
|
||||
</EditTextPreference>
|
||||
<EditTextPreference
|
||||
android:dependency="isRunning"
|
||||
android:defaultValue="u1rRWTssNv0p"
|
||||
android:key="sitekey"
|
||||
android:summary="@string/sitekey_summary"
|
||||
android:title="@string/sitekey">
|
||||
</EditTextPreference>
|
||||
<ListPreference
|
||||
android:dependency="isRunning"
|
||||
android:defaultValue="rc4"
|
||||
android:key="encMethod"
|
||||
android:entries="@array/enc_method_entry"
|
||||
android:entryValues="@array/enc_method_value"
|
||||
android:title="@string/enc_method">
|
||||
</ListPreference>
|
||||
</PreferenceCategory>
|
||||
<PreferenceCategory android:title="@string/fearute_cat">
|
||||
<CheckBoxPreference
|
||||
android:dependency="isRunning"
|
||||
android:defaultValue="false"
|
||||
android:key="isHTTPProxy"
|
||||
android:summary="@string/http_proxy_summary"
|
||||
android:title="@string/http_proxy">
|
||||
</CheckBoxPreference>
|
||||
<CheckBoxPreference
|
||||
android:dependency="isRunning"
|
||||
android:defaultValue="true"
|
||||
android:key="isDNSProxy"
|
||||
android:summary="@string/dns_proxy_summary"
|
||||
android:title="@string/dns_proxy">
|
||||
</CheckBoxPreference>
|
||||
<CheckBoxPreference
|
||||
android:dependency="isRunning"
|
||||
android:defaultValue="true"
|
||||
android:key="isGFWList"
|
||||
android:summary="@string/auto_set_gfwlist_summary"
|
||||
android:title="@string/auto_set_gfwlist">
|
||||
</CheckBoxPreference>
|
||||
<CheckBoxPreference
|
||||
android:dependency="isRunning"
|
||||
android:defaultValue="true"
|
||||
android:key="isGlobalProxy"
|
||||
android:summary="@string/auto_set_proxy_summary"
|
||||
android:title="@string/auto_set_proxy">
|
||||
</CheckBoxPreference>
|
||||
<CheckBoxPreference
|
||||
android:dependency="isRunning"
|
||||
android:defaultValue="false"
|
||||
android:key="isBypassApps"
|
||||
android:summary="@string/bypass_apps_summary"
|
||||
android:title="@string/bypass_apps">
|
||||
</CheckBoxPreference>
|
||||
<Preference
|
||||
android:dependency="isRunning"
|
||||
android:key="proxyedApps"
|
||||
android:summary="@string/proxyed_apps_summary"
|
||||
android:title="@string/proxyed_apps">
|
||||
</Preference>
|
||||
<CheckBoxPreference
|
||||
android:dependency="isRunning"
|
||||
android:key="isAutoConnect"
|
||||
android:summary="@string/auto_connect_summary"
|
||||
android:title="@string/auto_connect">
|
||||
</CheckBoxPreference>
|
||||
|
||||
</PreferenceCategory>
|
||||
|
||||
</PreferenceScreen>
|
||||
@@ -53,20 +53,29 @@ import android.os.Message;
|
||||
import android.preference.*;
|
||||
import android.util.Log;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.Toast;
|
||||
import com.actionbarsherlock.view.Menu;
|
||||
import com.actionbarsherlock.view.MenuItem;
|
||||
import com.google.analytics.tracking.android.EasyTracker;
|
||||
import net.saik0.android.unifiedpreference.UnifiedPreferenceFragment;
|
||||
import net.saik0.android.unifiedpreference.UnifiedSherlockPreferenceActivity;
|
||||
import org.jraf.android.backport.switchwidget.Switch;
|
||||
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
public class Shadowsocks extends PreferenceActivity implements
|
||||
OnSharedPreferenceChangeListener {
|
||||
public class Shadowsocks extends UnifiedSherlockPreferenceActivity
|
||||
implements CompoundButton.OnCheckedChangeListener, OnSharedPreferenceChangeListener {
|
||||
|
||||
public static final String PREFS_NAME = "Shadowsocks";
|
||||
public static final String[] PROXY_PREFS = {"proxy", "remotePort", "port"
|
||||
, "sitekey", "encMethod"};
|
||||
public static final String[] FEATRUE_PREFS = {"isHTTPProxy", "isDNSProxy", "isGFWList", "isGlobalProxy", "isBypassApps"
|
||||
, "proxyedApps", "isAutoConnect"};
|
||||
private static final String TAG = "Shadowsocks";
|
||||
private static final int MSG_CRASH_RECOVER = 1;
|
||||
private static final int MSG_INITIAL_FINISH = 2;
|
||||
@@ -94,14 +103,7 @@ public class Shadowsocks extends PreferenceActivity implements
|
||||
super.handleMessage(msg);
|
||||
}
|
||||
};
|
||||
private EditTextPreference proxyText;
|
||||
private EditTextPreference portText;
|
||||
private EditTextPreference remotePortText;
|
||||
private EditTextPreference sitekeyText;
|
||||
private ListPreference encMethodText;
|
||||
private Preference proxyedApps;
|
||||
private CheckBoxPreference isBypassAppsCheck;
|
||||
private CheckBoxPreference isRunningCheck;
|
||||
private Switch switchButton;
|
||||
|
||||
private void copyAssets(String path) {
|
||||
|
||||
@@ -161,67 +163,43 @@ public class Shadowsocks extends PreferenceActivity implements
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
|
||||
if (compoundButton == switchButton) {
|
||||
if (!serviceStart()) {
|
||||
switchButton.setChecked(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the activity is first created.
|
||||
*/
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
setHeaderRes(R.xml.shadowsocks_headers);
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
addPreferencesFromResource(R.xml.shadowsocks_preference);
|
||||
RelativeLayout switchLayout = (RelativeLayout)
|
||||
getLayoutInflater().inflate(R.layout.layout_switch, null);
|
||||
|
||||
proxyText = (EditTextPreference) findPreference("proxy");
|
||||
portText = (EditTextPreference) findPreference("port");
|
||||
remotePortText = (EditTextPreference) findPreference("remotePort");
|
||||
sitekeyText = (EditTextPreference) findPreference("sitekey");
|
||||
encMethodText = (ListPreference) findPreference("encMethod");
|
||||
proxyedApps = findPreference("proxyedApps");
|
||||
getSupportActionBar().setCustomView(switchLayout);
|
||||
getSupportActionBar().setDisplayShowTitleEnabled(false);
|
||||
getSupportActionBar().setDisplayShowCustomEnabled(true);
|
||||
|
||||
isBypassAppsCheck = (CheckBoxPreference) findPreference("isBypassApps");
|
||||
isRunningCheck = (CheckBoxPreference) findPreference("isRunning");
|
||||
switchButton = (Switch) switchLayout.findViewById(R.id.switchButton);
|
||||
|
||||
if (mProgressDialog == null) {
|
||||
mProgressDialog = ProgressDialog.show(this, "",
|
||||
getString(R.string.initializing), true, true);
|
||||
}
|
||||
|
||||
new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
Utils.isRoot();
|
||||
|
||||
String versionName;
|
||||
try {
|
||||
versionName = getPackageManager().getPackageInfo(
|
||||
getPackageName(), 0).versionName;
|
||||
} catch (NameNotFoundException e) {
|
||||
versionName = "NONE";
|
||||
}
|
||||
|
||||
final SharedPreferences settings = PreferenceManager
|
||||
.getDefaultSharedPreferences(Shadowsocks.this);
|
||||
|
||||
if (!settings.getBoolean(versionName, false)) {
|
||||
Editor edit = settings.edit();
|
||||
edit.putBoolean(versionName, true);
|
||||
edit.commit();
|
||||
reset();
|
||||
}
|
||||
|
||||
handler.sendEmptyMessage(MSG_INITIAL_FINISH);
|
||||
}
|
||||
}.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
menu.add(Menu.NONE, Menu.FIRST + 1, 1, getString(R.string.recovery))
|
||||
.setIcon(android.R.drawable.ic_menu_delete);
|
||||
menu.add(Menu.NONE, Menu.FIRST + 2, 2, getString(R.string.about))
|
||||
.setIcon(android.R.drawable.ic_menu_info_details);
|
||||
menu.add(0, 0, 0, R.string.recovery)
|
||||
.setIcon(android.R.drawable.ic_menu_revert)
|
||||
.setShowAsAction(MenuItem.SHOW_AS_ACTION_WITH_TEXT);
|
||||
menu.add(0, 1, 1, R.string.about)
|
||||
.setIcon(android.R.drawable.ic_menu_info_details)
|
||||
.setShowAsAction(MenuItem.SHOW_AS_ACTION_WITH_TEXT);
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -235,11 +213,6 @@ public class Shadowsocks extends PreferenceActivity implements
|
||||
editor.putBoolean("isConnected", ShadowsocksService.isServiceStarted());
|
||||
editor.commit();
|
||||
|
||||
if (mProgressDialog != null) {
|
||||
mProgressDialog.dismiss();
|
||||
mProgressDialog = null;
|
||||
}
|
||||
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
@@ -256,14 +229,13 @@ public class Shadowsocks extends PreferenceActivity implements
|
||||
return super.onKeyDown(keyCode, event);
|
||||
}
|
||||
|
||||
// 菜单项被选择事件
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case Menu.FIRST + 1:
|
||||
case 0:
|
||||
recovery();
|
||||
break;
|
||||
case Menu.FIRST + 2:
|
||||
case 1:
|
||||
String versionName = "";
|
||||
try {
|
||||
versionName = getPackageManager().getPackageInfo(
|
||||
@@ -276,57 +248,27 @@ public class Shadowsocks extends PreferenceActivity implements
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
|
||||
// Unregister the listener whenever a key changes
|
||||
getPreferenceScreen().getSharedPreferences()
|
||||
PreferenceManager.getDefaultSharedPreferences(this)
|
||||
.unregisterOnSharedPreferenceChangeListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen,
|
||||
Preference preference) {
|
||||
SharedPreferences settings = PreferenceManager
|
||||
.getDefaultSharedPreferences(this);
|
||||
|
||||
if (preference.getKey() != null
|
||||
&& preference.getKey().equals("proxyedApps")) {
|
||||
Intent intent = new Intent(this, AppManager.class);
|
||||
startActivity(intent);
|
||||
} else if (preference.getKey() != null
|
||||
&& preference.getKey().equals("isRunning")) {
|
||||
if (!serviceStart()) {
|
||||
Editor edit = settings.edit();
|
||||
edit.putBoolean("isRunning", false);
|
||||
edit.commit();
|
||||
}
|
||||
}
|
||||
return super.onPreferenceTreeClick(preferenceScreen, preference);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
SharedPreferences settings = PreferenceManager
|
||||
.getDefaultSharedPreferences(this);
|
||||
|
||||
if (settings.getBoolean("isGlobalProxy", false)) {
|
||||
proxyedApps.setEnabled(false);
|
||||
isBypassAppsCheck.setEnabled(false);
|
||||
} else {
|
||||
proxyedApps.setEnabled(true);
|
||||
isBypassAppsCheck.setEnabled(true);
|
||||
}
|
||||
|
||||
Editor edit = settings.edit();
|
||||
|
||||
if (ShadowsocksService.isServiceStarted()) {
|
||||
edit.putBoolean("isRunning", true);
|
||||
switchButton.setChecked(true);
|
||||
} else {
|
||||
if (settings.getBoolean("isRunning", false)) {
|
||||
new Thread() {
|
||||
@@ -338,33 +280,44 @@ public class Shadowsocks extends PreferenceActivity implements
|
||||
}.start();
|
||||
}
|
||||
edit.putBoolean("isRunning", false);
|
||||
switchButton.setChecked(false);
|
||||
}
|
||||
|
||||
edit.commit();
|
||||
|
||||
// Setup the initial values
|
||||
setPreferenceEnabled();
|
||||
|
||||
if (!settings.getString("sitekey", "").equals(""))
|
||||
sitekeyText.setSummary(settings.getString("sitekey", ""));
|
||||
|
||||
if (!settings.getString("encMethod", "").equals(""))
|
||||
encMethodText.setSummary(settings.getString("encMethod", ""));
|
||||
|
||||
if (!settings.getString("port", "").equals(""))
|
||||
portText.setSummary(settings.getString("port",
|
||||
getString(R.string.port_summary)));
|
||||
|
||||
if (!settings.getString("remotePort", "").equals(""))
|
||||
remotePortText.setSummary(settings.getString("remotePort",
|
||||
getString(R.string.remote_port_summary)));
|
||||
|
||||
if (!settings.getString("proxy", "").equals(""))
|
||||
proxyText.setSummary(settings.getString("proxy",
|
||||
getString(R.string.proxy_summary)));
|
||||
|
||||
// Set up a listener whenever a key changes
|
||||
getPreferenceScreen().getSharedPreferences()
|
||||
switchButton.setOnCheckedChangeListener(this);
|
||||
PreferenceManager.getDefaultSharedPreferences(this)
|
||||
.registerOnSharedPreferenceChangeListener(this);
|
||||
|
||||
}
|
||||
|
||||
private void setPreferenceEnabled() {
|
||||
SharedPreferences settings = PreferenceManager
|
||||
.getDefaultSharedPreferences(Shadowsocks.this);
|
||||
|
||||
boolean enabled = !settings.getBoolean("isRunning", false)
|
||||
&& !settings.getBoolean("isConnecting", false);
|
||||
|
||||
for (String name : PROXY_PREFS) {
|
||||
Preference pref = findPreference(name);
|
||||
if (pref != null) {
|
||||
pref.setEnabled(enabled);
|
||||
}
|
||||
}
|
||||
for (String name : FEATRUE_PREFS) {
|
||||
Preference pref = findPreference(name);
|
||||
if (pref != null) {
|
||||
if (name.equals("isBypassApps")
|
||||
|| name.equals("proxyedApps")) {
|
||||
boolean isGlobalProxy = settings.getBoolean("isGlobalProxy", false);
|
||||
pref.setEnabled(enabled && !isGlobalProxy);
|
||||
} else {
|
||||
pref.setEnabled(enabled);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -376,9 +329,9 @@ public class Shadowsocks extends PreferenceActivity implements
|
||||
|
||||
if (key.equals("isRunning")) {
|
||||
if (settings.getBoolean("isRunning", false)) {
|
||||
isRunningCheck.setChecked(true);
|
||||
switchButton.setChecked(true);
|
||||
} else {
|
||||
isRunningCheck.setChecked(false);
|
||||
switchButton.setChecked(false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -397,44 +350,8 @@ public class Shadowsocks extends PreferenceActivity implements
|
||||
}
|
||||
}
|
||||
|
||||
if (key.equals("isGlobalProxy")) {
|
||||
if (settings.getBoolean("isGlobalProxy", false)) {
|
||||
proxyedApps.setEnabled(false);
|
||||
isBypassAppsCheck.setEnabled(false);
|
||||
} else {
|
||||
proxyedApps.setEnabled(true);
|
||||
isBypassAppsCheck.setEnabled(true);
|
||||
}
|
||||
}
|
||||
|
||||
if (key.equals("remotePort")) {
|
||||
if (settings.getString("remotePort", "").equals("")) {
|
||||
remotePortText.setSummary(getString(R.string.remote_port_summary));
|
||||
} else {
|
||||
remotePortText.setSummary(settings.getString("remotePort", ""));
|
||||
}
|
||||
} else if (key.equals("port")) {
|
||||
if (settings.getString("port", "").equals("")) {
|
||||
portText.setSummary(getString(R.string.port_summary));
|
||||
} else {
|
||||
portText.setSummary(settings.getString("port", ""));
|
||||
}
|
||||
} else if (key.equals("sitekey")) {
|
||||
if (settings.getString("sitekey", "").equals("")) {
|
||||
sitekeyText.setSummary(getString(R.string.sitekey_summary));
|
||||
} else {
|
||||
sitekeyText.setSummary(settings.getString("sitekey", ""));
|
||||
}
|
||||
} else if (key.equals("encMethod")) {
|
||||
if (!settings.getString("encMethod", "").equals("")) {
|
||||
encMethodText.setSummary(settings.getString("encMethod", ""));
|
||||
}
|
||||
} else if (key.equals("proxy")) {
|
||||
if (settings.getString("proxy", "").equals("")) {
|
||||
proxyText.setSummary(getString(R.string.proxy_summary));
|
||||
} else {
|
||||
proxyText.setSummary(settings.getString("proxy", ""));
|
||||
}
|
||||
if (key.equals("isRunning") || key.equals("isGlobalProxy")) {
|
||||
setPreferenceEnabled();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -442,12 +359,56 @@ public class Shadowsocks extends PreferenceActivity implements
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
EasyTracker.getInstance().activityStart(this);
|
||||
|
||||
final SharedPreferences settings = PreferenceManager
|
||||
.getDefaultSharedPreferences(Shadowsocks.this);
|
||||
|
||||
boolean init = !settings.getBoolean("isRunning", false)
|
||||
&& !settings.getBoolean("isConnecting", false);
|
||||
|
||||
if (init) {
|
||||
if (mProgressDialog == null) {
|
||||
mProgressDialog = ProgressDialog.show(this, "",
|
||||
getString(R.string.initializing), true, true);
|
||||
}
|
||||
|
||||
new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
Utils.isRoot();
|
||||
|
||||
String versionName;
|
||||
try {
|
||||
versionName = getPackageManager().getPackageInfo(
|
||||
getPackageName(), 0).versionName;
|
||||
} catch (NameNotFoundException e) {
|
||||
versionName = "NONE";
|
||||
}
|
||||
|
||||
|
||||
if (!settings.getBoolean(versionName, false)) {
|
||||
Editor edit = settings.edit();
|
||||
edit.putBoolean(versionName, true);
|
||||
edit.commit();
|
||||
reset();
|
||||
}
|
||||
|
||||
handler.sendEmptyMessage(MSG_INITIAL_FINISH);
|
||||
}
|
||||
}.start();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop() {
|
||||
super.onStop();
|
||||
EasyTracker.getInstance().activityStop(this);
|
||||
|
||||
if (mProgressDialog != null) {
|
||||
mProgressDialog.dismiss();
|
||||
mProgressDialog = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
@@ -560,4 +521,97 @@ public class Shadowsocks extends PreferenceActivity implements
|
||||
alert.show();
|
||||
}
|
||||
|
||||
public static class ProxyFragment extends UnifiedPreferenceFragment
|
||||
implements OnSharedPreferenceChangeListener {
|
||||
|
||||
private void setPreferenceEnabled() {
|
||||
SharedPreferences settings = PreferenceManager
|
||||
.getDefaultSharedPreferences(getActivity());
|
||||
|
||||
boolean enabled = !settings.getBoolean("isRunning", false)
|
||||
&& !settings.getBoolean("isConnecting", false);
|
||||
|
||||
for (String name : PROXY_PREFS) {
|
||||
Preference pref = findPreference(name);
|
||||
if (pref != null) {
|
||||
pref.setEnabled(enabled);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
setPreferenceEnabled();
|
||||
|
||||
// Set up a listener whenever a key changes
|
||||
getPreferenceScreen().getSharedPreferences()
|
||||
.registerOnSharedPreferenceChangeListener(this);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
// Unregister the listener whenever a key changes
|
||||
getPreferenceScreen().getSharedPreferences()
|
||||
.unregisterOnSharedPreferenceChangeListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
||||
if (key.equals("isRunning") || key.equals("isGlobalProxy")) {
|
||||
setPreferenceEnabled();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class FeatureFragment extends UnifiedPreferenceFragment
|
||||
implements OnSharedPreferenceChangeListener {
|
||||
|
||||
private void setPreferenceEnabled() {
|
||||
SharedPreferences settings = PreferenceManager
|
||||
.getDefaultSharedPreferences(getActivity());
|
||||
|
||||
boolean enabled = !settings.getBoolean("isRunning", false)
|
||||
&& !settings.getBoolean("isConnecting", false);
|
||||
|
||||
for (String name : FEATRUE_PREFS) {
|
||||
Preference pref = findPreference(name);
|
||||
if (pref != null) {
|
||||
if (name.equals("isBypassApps")
|
||||
|| name.equals("proxyedApps")) {
|
||||
boolean isGlobalProxy = settings.getBoolean("isGlobalProxy", false);
|
||||
pref.setEnabled(enabled && !isGlobalProxy);
|
||||
} else {
|
||||
pref.setEnabled(enabled);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
setPreferenceEnabled();
|
||||
|
||||
// Set up a listener whenever a key changes
|
||||
getPreferenceScreen().getSharedPreferences()
|
||||
.registerOnSharedPreferenceChangeListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
// Unregister the listener whenever a key changes
|
||||
getPreferenceScreen().getSharedPreferences()
|
||||
.unregisterOnSharedPreferenceChangeListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
||||
if (key.equals("isRunning") || key.equals("isGlobalProxy")) {
|
||||
setPreferenceEnabled();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.github.shadowsocks.preferences;
|
||||
|
||||
import android.content.Context;
|
||||
import android.preference.EditTextPreference;
|
||||
import android.util.AttributeSet;
|
||||
import com.github.shadowsocks.R;
|
||||
|
||||
public class SummaryEditTextPreference extends EditTextPreference {
|
||||
|
||||
private CharSequence mDefaultSummary;
|
||||
|
||||
public SummaryEditTextPreference(Context context, AttributeSet attrs, int defStyle) {
|
||||
super(context, attrs, defStyle);
|
||||
mDefaultSummary = getSummary();
|
||||
}
|
||||
|
||||
public SummaryEditTextPreference(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
mDefaultSummary = getSummary();
|
||||
}
|
||||
|
||||
public SummaryEditTextPreference(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDialogClosed(boolean positiveResult) {
|
||||
super.onDialogClosed(positiveResult);
|
||||
if (positiveResult) {
|
||||
String value = getEditText().getText().toString();
|
||||
if (value.isEmpty()) {
|
||||
setSummary(mDefaultSummary);
|
||||
} else {
|
||||
setSummary(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user