Commit d4ec43e5 authored by Mygod's avatar Mygod

Add more material design (1)

parent a3fbefa5
...@@ -36,7 +36,7 @@ libraryDependencies ++= Seq( ...@@ -36,7 +36,7 @@ libraryDependencies ++= Seq(
"com.google.android.gms" % "play-services-ads" % "8.1.0", "com.google.android.gms" % "play-services-ads" % "8.1.0",
"com.google.android.gms" % "play-services-analytics" % "8.1.0", "com.google.android.gms" % "play-services-analytics" % "8.1.0",
"com.android.support" % "support-v4" % "23.1.0", "com.android.support" % "support-v4" % "23.1.0",
"com.github.mrengineer13" % "snackbar" % "1.2.0", "com.android.support" % "design" % "23.1.0",
"com.nostra13.universalimageloader" % "universal-image-loader" % "1.9.4", "com.nostra13.universalimageloader" % "universal-image-loader" % "1.9.4",
"com.j256.ormlite" % "ormlite-core" % "4.48", "com.j256.ormlite" % "ormlite-core" % "4.48",
"com.j256.ormlite" % "ormlite-android" % "4.48" "com.j256.ormlite" % "ormlite-android" % "4.48"
...@@ -44,6 +44,7 @@ libraryDependencies ++= Seq( ...@@ -44,6 +44,7 @@ libraryDependencies ++= Seq(
proguardOptions in Android ++= Seq("-keep class android.support.v4.app.** { *; }", proguardOptions in Android ++= Seq("-keep class android.support.v4.app.** { *; }",
"-keep interface android.support.v4.app.** { *; }", "-keep interface android.support.v4.app.** { *; }",
"-keep class android.support.v7.widget.Toolbar { <init>(...); }",
"-keep class com.actionbarsherlock.** { *; }", "-keep class com.actionbarsherlock.** { *; }",
"-keep interface com.actionbarsherlock.** { *; }", "-keep interface com.actionbarsherlock.** { *; }",
"-keep class org.jraf.android.backport.** { *; }", "-keep class org.jraf.android.backport.** { *; }",
......
...@@ -64,7 +64,7 @@ ...@@ -64,7 +64,7 @@
<activity <activity
android:name=".AppManager" android:name=".AppManager"
android:theme="@style/Theme.AppManager" android:theme="@style/Theme.Material"
android:label="@string/app_name" android:label="@string/app_name"
android:parentActivityName=".Shadowsocks"> android:parentActivityName=".Shadowsocks">
<intent-filter> <intent-filter>
......
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FFFFFFFF"
android:pathData="M19.35,10.04C18.67,6.59 15.64,4 12,4 9.11,4 6.6,5.64 5.35,8.04 2.34,8.36 0,10.91 0,14c0,3.31 2.69,6 6,6h13c2.76,0 5,-2.24 5,-5 0,-2.64 -2.05,-4.78 -4.65,-4.96z"/>
</vector>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FFFFFFFF"
android:pathData="M19.35,10.04C18.67,6.59 15.64,4 12,4c-1.48,0 -2.85,0.43 -4.01,1.17l1.46,1.46C10.21,6.23 11.08,6 12,6c3.04,0 5.5,2.46 5.5,5.5v0.5H19c1.66,0 3,1.34 3,3 0,1.13 -0.64,2.11 -1.56,2.62l1.45,1.45C23.16,18.16 24,16.68 24,15c0,-2.64 -2.05,-4.78 -4.65,-4.96zM3,5.27l2.75,2.74C2.56,8.15 0,10.77 0,14c0,3.31 2.69,6 6,6h11.73l2,2L21,20.73 4.27,4 3,5.27zM7.73,10l8,8H6c-2.21,0 -4,-1.79 -4,-4s1.79,-4 4,-4h1.73z"/>
</vector>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FFFFFFFF"
android:pathData="M19.35,10.04C18.67,6.59 15.64,4 12,4 9.11,4 6.6,5.64 5.35,8.04 2.34,8.36 0,10.91 0,14c0,3.31 2.69,6 6,6h13c2.76,0 5,-2.24 5,-5 0,-2.64 -2.05,-4.78 -4.65,-4.96zM19,18H6c-2.21,0 -4,-1.79 -4,-4s1.79,-4 4,-4h0.71C7.37,7.69 9.48,6 12,6c3.04,0 5.5,2.46 5.5,5.5v0.5H19c1.66,0 3,1.34 3,3s-1.34,3 -3,3z"/>
</vector>
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2010 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.
-->
<transition xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/md__list_pressed_holo_dark" />
<item android:drawable="@drawable/md__list_longpressed_holo" />
</transition>
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2010 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.
-->
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_window_focused="false" android:drawable="@color/md__transparent" />
<!-- Even though these two point to the same resource, have two states so the drawable will invalidate itself when coming out of pressed state. -->
<item android:state_focused="true" android:state_enabled="false" android:state_pressed="true" android:drawable="@drawable/md__list_selector_disabled_holo_dark" />
<item android:state_focused="true" android:state_enabled="false" android:drawable="@drawable/md__list_selector_disabled_holo_dark" />
<item android:state_focused="true" android:state_pressed="true" android:drawable="@drawable/md__list_selector_background_transition_holo_dark" />
<item android:state_focused="false" android:state_pressed="true" android:drawable="@drawable/md__list_selector_background_transition_holo_dark" />
<item android:state_focused="true" android:drawable="@drawable/md__list_focused_holo" />
</selector>
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
android:layout_height="fill_parent" android:layout_height="fill_parent"
android:orientation="vertical" android:orientation="vertical"
android:duplicateParentState="false"> android:duplicateParentState="false">
<include layout="@layout/toolbar_light_dark" />
<RelativeLayout <RelativeLayout
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
......
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent" android:layout_height="match_parent">
<include layout="@layout/toolbar_light_dark" />
<fragment android:name="com.github.shadowsocks.ShadowsocksSettings"
android:id="@android:id/content" android:layout_below="@+id/toolbar"
android:layout_width="match_parent" android:layout_height="match_parent" />
<android.support.design.widget.FloatingActionButton android:id="@+id/fab" android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:backgroundTint="@color/material_blue_500"
android:src="@drawable/ic_cloud_off"
android:layout_gravity="end|bottom"
android:layout_alignBottom="@+id/toolbar"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginRight="16dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="-28dp" app:elevation="6dp"
app:pressedTranslationZ="6dp" app:borderWidth="0dp" />
</RelativeLayout>
<?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">
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:textSize="26sp"
android:textColor="@color/title"
android:text="@string/screen_name"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"/>
<Switch
android:id="@+id/switchButton"
android:switchTextAppearance="@android:style/TextAppearance.Small.Inverse"
android:enabled="false"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight = "10dp"
android:layout_centerVertical="true"/>
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_height="?attr/actionBarSize" android:layout_width="match_parent"
android:background="?attr/colorPrimary" android:elevation="4dp"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" android:id="@+id/toolbar" />
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<!-- File created by the Android Action Bar Style Generator
Copyright (C) 2011 The Android Open Source Project
Copyright (C) 2012 readyState Software Ltd
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.
-->
<resources>
<style name="Theme.Shadow" parent="@android:style/Theme.Material.Light.DarkActionBar">
<item name="android:actionBarItemBackground">@drawable/selectable_background_shadow</item>
<item name="android:popupMenuStyle">@style/PopupMenu.Shadow</item>
<item name="android:dropDownListViewStyle">@style/DropDownListView.Shadow</item>
<item name="android:actionBarTabStyle">@style/ActionBarTabStyle.Shadow</item>
<item name="android:actionDropDownStyle">@style/DropDownNav.Shadow</item>
<item name="android:actionBarStyle">@style/ActionBar.Solid.Shadow</item>
<item name="android:actionModeBackground">@drawable/cab_background_top_shadow</item>
<item name="android:actionModeSplitBackground">@drawable/cab_background_bottom_shadow</item>
<!-- Light.DarkActionBar specific -->
<item name="android:actionBarWidgetTheme">@style/Theme.Shadow.Widget</item>
<item name="android:textAppearanceLargePopupMenu">@style/m_textAppearanceLargePopupMenu</item>
<item name="android:textAppearanceSmallPopupMenu" >@style/m_textAppearanceSmallPopupMenu</item>
</style>
<style name="ActionBar.Solid.Shadow" parent="@android:style/Widget.Material.ActionBar">
<item name="android:background">@drawable/ab_background_textured_shadow</item>
<item name="android:backgroundStacked">@drawable/ab_stacked_solid_shadow</item>
<item name="android:backgroundSplit">@drawable/ab_background_textured_shadow</item>
</style>
<style name="ActionBar.Transparent.Shadow" parent="@android:style/Widget.Material.ActionBar">
<item name="android:background">@drawable/ab_transparent_shadow</item>
</style>
<style name="PopupMenu.Shadow" parent="@android:style/Widget.Material.ListPopupWindow">
<item name="android:popupBackground">@drawable/menu_dropdown_panel_shadow</item>
</style>
<style name="m_textAppearanceSmallPopupMenu" parent="@android:style/TextAppearance.Material.Widget.PopupMenu.Small">
<item name="android:textColor">@android:color/black</item>
</style>
<style name="m_textAppearanceLargePopupMenu" parent="@android:style/TextAppearance.Material.Widget.PopupMenu.Large">
<item name="android:textColor">@android:color/black</item>
</style>
<style name="DropDownListView.Shadow" parent="@android:style/Widget.Material.ListView.DropDown">
<item name="android:listSelector">@drawable/selectable_background_shadow</item>
</style>
<style name="ActionBarTabStyle.Shadow" parent="@android:style/Widget.Material.ActionBar.TabView">
<item name="android:background">@drawable/tab_indicator_ab_shadow</item>
</style>
<style name="DropDownNav.Shadow" parent="@android:style/Widget.Material.Spinner">
<item name="android:background">@drawable/spinner_background_ab_shadow</item>
<item name="android:popupBackground">@drawable/menu_dropdown_panel_shadow</item>
<item name="android:dropDownSelector">@drawable/selectable_background_shadow</item>
</style>
<!-- this style is only referenced in a Light.DarkActionBar based theme -->
<style name="Theme.Shadow.Widget" parent="@android:style/Theme.Material">
<item name="android:popupMenuStyle">@style/PopupMenu.Shadow</item>
<item name="android:dropDownListViewStyle">@style/DropDownListView.Shadow</item>
<item name="android:textColor">@android:color/white</item>
<item name="android:textAppearanceLargePopupMenu">@style/m_textAppearanceLargePopupMenu</item>
<item name="android:textAppearanceSmallPopupMenu" >@style/m_textAppearanceSmallPopupMenu</item>
</style>
<style name="PopupTheme" parent="@android:style/Theme.Material.Light">
<item name="android:windowActionBar">false</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowFrame">@null</item>
<item name="android:windowIsFloating">false</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item>
<item name="android:windowSoftInputMode">stateAlwaysHidden</item>
<item name="android:windowActionModeOverlay">true</item>
<item name="android:colorBackgroundCacheHint">@null</item>
<item name="android:windowCloseOnTouchOutside">true</item>
<item name="android:windowIsTranslucent">true</item>
</style>
</resources>
...@@ -12,4 +12,12 @@ ...@@ -12,4 +12,12 @@
<color name="md__transparent">#00000000</color> <color name="md__transparent">#00000000</color>
<color name="md__defaultBackground">#FF555555</color> <color name="md__defaultBackground">#FF555555</color>
<color name="material_blue_500">#2196F3</color>
<color name="material_blue_grey_300">#90A4AE</color>
<color name="material_blue_grey_500">#607D8B</color>
<color name="material_blue_grey_700">#455A64</color>
<color name="material_accent_300">@color/material_blue_grey_300</color>
<color name="material_accent_500">@color/material_blue_grey_500</color>
<color name="material_accent_700">@color/material_blue_grey_700</color>
</resources> </resources>
...@@ -16,11 +16,27 @@ ...@@ -16,11 +16,27 @@
<resources> <resources>
<style name="Theme.AppManager" parent="@style/Theme.Shadow"> <style name="Theme.Material" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:alertDialogTheme">@style/Theme.Material.Dialog.Alert</item>
<item name="android:dialogTheme">@style/Theme.Material.Dialog</item>
<item name="android:navigationBarColor">@color/material_accent_700</item>
<item name="colorAccent">@color/material_accent_500</item>
<item name="colorButtonNormal">@color/material_accent_500</item>
<item name="colorPrimary">@color/material_accent_500</item>
<item name="colorPrimaryDark">@color/material_accent_700</item>
</style>
<style name="Theme.Material.Dialog" parent="Theme.AppCompat.Light.Dialog">
<item name="colorAccent">@color/material_accent_500</item>
<item name="colorPrimary">@color/material_accent_500</item>
<item name="colorPrimaryDark">@color/material_accent_700</item>
</style>
<style name="Theme.Material.Dialog.Alert" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="colorAccent">@color/material_accent_500</item>
<item name="colorPrimary">@color/material_accent_500</item>
<item name="colorPrimaryDark">@color/material_accent_700</item>
</style> </style>
<style name="PopupTheme" parent="@android:style/Theme.Holo.Light"> <style name="PopupTheme" parent="Theme.Material.Dialog">
<item name="android:windowActionBar">false</item>
<item name="android:windowNoTitle">true</item> <item name="android:windowNoTitle">true</item>
<item name="android:windowFrame">@null</item> <item name="android:windowFrame">@null</item>
<item name="android:windowIsFloating">false</item> <item name="android:windowIsFloating">false</item>
...@@ -29,12 +45,11 @@ ...@@ -29,12 +45,11 @@
<item name="android:windowSoftInputMode">stateAlwaysHidden</item> <item name="android:windowSoftInputMode">stateAlwaysHidden</item>
<item name="android:windowActionModeOverlay">true</item> <item name="android:windowActionModeOverlay">true</item>
<item name="android:colorBackgroundCacheHint">@null</item> <item name="android:colorBackgroundCacheHint">@null</item>
<item name="android:windowCloseOnTouchOutside">true</item>
<item name="android:windowIsTranslucent">true</item> <item name="android:windowIsTranslucent">true</item>
</style> </style>
<!-- Variation on the Light theme that turns off the title --> <!-- Variation on the Light theme that turns off the title -->
<style name="Theme.Shadowsocks" parent="@style/Theme.Shadow"> <style name="Theme.Shadowsocks" parent="Theme.Material">
<item name="menuDrawerStyle">@style/MenuDrawerStyle</item> <item name="menuDrawerStyle">@style/MenuDrawerStyle</item>
</style> </style>
...@@ -57,7 +72,7 @@ ...@@ -57,7 +72,7 @@
</style> </style>
<style name="MenuDrawer.Widget.Title"> <style name="MenuDrawer.Widget.Title">
<item name="android:background">@drawable/md__list_selector_holo_dark</item> <item name="android:background">?android:attr/selectableItemBackground</item>
<item name="android:textAppearance">?android:attr/textAppearance</item> <item name="android:textAppearance">?android:attr/textAppearance</item>
<item name="android:textColor">?android:attr/textColorPrimaryInverse</item> <item name="android:textColor">?android:attr/textColorPrimaryInverse</item>
<item name="android:textSize">18sp</item> <item name="android:textSize">18sp</item>
......
<?xml version="1.0" encoding="utf-8"?>
<!-- File created by the Android Action Bar Style Generator
Copyright (C) 2011 The Android Open Source Project
Copyright (C) 2012 readyState Software Ltd
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.
-->
<resources>
<style name="Theme.Shadow" parent="@android:style/Theme.Holo.Light.DarkActionBar">
<item name="android:actionBarItemBackground">@drawable/selectable_background_shadow</item>
<item name="android:popupMenuStyle">@style/PopupMenu.Shadow</item>
<item name="android:dropDownListViewStyle">@style/DropDownListView.Shadow</item>
<item name="android:actionBarTabStyle">@style/ActionBarTabStyle.Shadow</item>
<item name="android:actionDropDownStyle">@style/DropDownNav.Shadow</item>
<item name="android:actionBarStyle">@style/ActionBar.Solid.Shadow</item>
<item name="android:actionModeBackground">@drawable/cab_background_top_shadow</item>
<item name="android:actionModeSplitBackground">@drawable/cab_background_bottom_shadow</item>
<item name="android:actionModeCloseButtonStyle">@style/ActionButton.CloseMode.Shadow</item>
<!-- Light.DarkActionBar specific -->
<item name="android:actionBarWidgetTheme">@style/Theme.Shadow.Widget</item>
<item name="android:textAppearanceLargePopupMenu">@style/m_textAppearanceLargePopupMenu</item>
<item name="android:textAppearanceSmallPopupMenu" >@style/m_textAppearanceSmallPopupMenu</item>
</style>
<style name="ActionBar.Solid.Shadow" parent="@android:style/Widget.Holo.ActionBar">
<item name="android:background">@drawable/ab_background_textured_shadow</item>
<item name="android:backgroundStacked">@drawable/ab_stacked_solid_shadow</item>
<item name="android:backgroundSplit">@drawable/ab_background_textured_shadow</item>
<item name="android:progressBarStyle">@style/ProgressBar.Shadow</item>
</style>
<style name="ActionBar.Transparent.Shadow" parent="@android:style/Widget.Holo.ActionBar">
<item name="android:background">@drawable/ab_transparent_shadow</item>
<item name="android:progressBarStyle">@style/ProgressBar.Shadow</item>
</style>
<style name="PopupMenu.Shadow" parent="@android:style/Widget.Holo.ListPopupWindow">
<item name="android:popupBackground">@drawable/menu_dropdown_panel_shadow</item>
</style>
<style name="m_textAppearanceSmallPopupMenu" parent="@android:style/TextAppearance.Holo.Widget.PopupMenu.Small">
<item name="android:textColor">@android:color/white</item>
</style>
<style name="m_textAppearanceLargePopupMenu" parent="@android:style/TextAppearance.Holo.Widget.PopupMenu.Large">
<item name="android:textColor">@android:color/white</item>
</style>
<style name="DropDownListView.Shadow" parent="@android:style/Widget.Holo.ListView.DropDown">
<item name="android:listSelector">@drawable/selectable_background_shadow</item>
</style>
<style name="ActionBarTabStyle.Shadow" parent="@android:style/Widget.Holo.ActionBar.TabView">
<item name="android:background">@drawable/tab_indicator_ab_shadow</item>
</style>
<style name="DropDownNav.Shadow" parent="@android:style/Widget.Holo.Spinner">
<item name="android:background">@drawable/spinner_background_ab_shadow</item>
<item name="android:popupBackground">@drawable/menu_dropdown_panel_shadow</item>
<item name="android:dropDownSelector">@drawable/selectable_background_shadow</item>
</style>
<style name="ProgressBar.Shadow" parent="@android:style/Widget.Holo.ProgressBar.Horizontal">
<item name="android:progressDrawable">@drawable/progress_horizontal_shadow</item>
</style>
<style name="ActionButton.CloseMode.Shadow" parent="@android:style/Widget.Holo.ActionButton.CloseMode">
<item name="android:background">@drawable/btn_cab_done_shadow</item>
</style>
<!-- this style is only referenced in a Light.DarkActionBar based theme -->
<style name="Theme.Shadow.Widget" parent="@android:style/Theme.Holo">
<item name="android:popupMenuStyle">@style/PopupMenu.Shadow</item>
<item name="android:dropDownListViewStyle">@style/DropDownListView.Shadow</item>
<item name="android:textColor">@android:color/white</item>
<item name="android:textAppearanceLargePopupMenu">@style/m_textAppearanceLargePopupMenu</item>
<item name="android:textAppearanceSmallPopupMenu" >@style/m_textAppearanceSmallPopupMenu</item>
</style>
</resources>
...@@ -49,6 +49,7 @@ import android.graphics.{Bitmap, PixelFormat} ...@@ -49,6 +49,7 @@ import android.graphics.{Bitmap, PixelFormat}
import android.os.Bundle import android.os.Bundle
import android.os.Handler import android.os.Handler
import android.preference.PreferenceManager import android.preference.PreferenceManager
import android.support.v7.widget.Toolbar
import android.view.Menu import android.view.Menu
import android.view.MenuItem import android.view.MenuItem
import android.view.View import android.view.View
...@@ -260,9 +261,6 @@ class AppManager extends Activity with OnCheckedChangeListener with OnClickListe ...@@ -260,9 +261,6 @@ class AppManager extends Activity with OnCheckedChangeListener with OnClickListe
} }
Toast.makeText(this, R.string.action_import_err, Toast.LENGTH_SHORT).show() Toast.makeText(this, R.string.action_import_err, Toast.LENGTH_SHORT).show()
return false return false
case android.R.id.home =>
navigateUpTo(getParentActivityIntent)
return true
} }
super.onOptionsItemSelected(item) super.onOptionsItemSelected(item)
} }
...@@ -277,11 +275,14 @@ class AppManager extends Activity with OnCheckedChangeListener with OnClickListe ...@@ -277,11 +275,14 @@ class AppManager extends Activity with OnCheckedChangeListener with OnClickListe
handler = new Handler() handler = new Handler()
val actionBar = getActionBar
actionBar.setTitle(R.string.proxied_help)
actionBar.setDisplayHomeAsUpEnabled(true)
actionBar.setDisplayShowHomeEnabled(false)
this.setContentView(R.layout.layout_apps) this.setContentView(R.layout.layout_apps)
val toolbar = findViewById(R.id.toolbar).asInstanceOf[Toolbar]
toolbar.setTitle(R.string.proxied_help)
toolbar.setNavigationIcon(R.drawable.abc_ic_ab_back_mtrl_am_alpha)
toolbar.setNavigationOnClickListener((v: View) => {
val intent = getParentActivityIntent
if (intent == null) finish else navigateUpTo(intent)
})
this.overlay = View.inflate(this, R.layout.overlay, null).asInstanceOf[TextView] this.overlay = View.inflate(this, R.layout.overlay, null).asInstanceOf[TextView]
getWindowManager.addView(overlay, new getWindowManager.addView(overlay, new
WindowManager.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT,
......
...@@ -51,12 +51,13 @@ import android.graphics.{Bitmap, Color, Typeface} ...@@ -51,12 +51,13 @@ import android.graphics.{Bitmap, Color, Typeface}
import android.net.{Uri, VpnService} import android.net.{Uri, VpnService}
import android.os._ import android.os._
import android.preference._ import android.preference._
import android.support.v4.content.ContextCompat import android.support.design.widget.{FloatingActionButton, Snackbar}
import android.support.v7.app.AppCompatActivity
import android.support.v7.widget.Toolbar
import android.util.{DisplayMetrics, Log} import android.util.{DisplayMetrics, Log}
import android.view._ import android.view._
import android.webkit.{WebView, WebViewClient} import android.webkit.{WebView, WebViewClient}
import android.widget._ import android.widget._
import com.github.mrengineer13.snackbar._
import com.github.shadowsocks.aidl.{IShadowsocksService, IShadowsocksServiceCallback} import com.github.shadowsocks.aidl.{IShadowsocksService, IShadowsocksServiceCallback}
import com.github.shadowsocks.database._ import com.github.shadowsocks.database._
import com.github.shadowsocks.preferences.{PasswordEditTextPreference, ProfileEditTextPreference, SummaryEditTextPreference} import com.github.shadowsocks.preferences.{PasswordEditTextPreference, ProfileEditTextPreference, SummaryEditTextPreference}
...@@ -173,8 +174,7 @@ object Shadowsocks { ...@@ -173,8 +174,7 @@ object Shadowsocks {
} }
class Shadowsocks class Shadowsocks
extends PreferenceActivity extends AppCompatActivity
with CompoundButton.OnCheckedChangeListener
with MenuAdapter.MenuListener { with MenuAdapter.MenuListener {
// Flags // Flags
...@@ -184,8 +184,9 @@ class Shadowsocks ...@@ -184,8 +184,9 @@ class Shadowsocks
var singlePane: Int = -1 var singlePane: Int = -1
// Variables // Variables
var switchButton: Switch = null private var serviceStarted = false
var progressDialog: ProgressDialog = null var fab: FloatingActionButton = _
var progressDialog: ProgressDialog = _
var progressTag = -1 var progressTag = -1
var state = State.INIT var state = State.INIT
var prepared = false var prepared = false
...@@ -210,7 +211,7 @@ class Shadowsocks ...@@ -210,7 +211,7 @@ class Shadowsocks
case ignored: RemoteException => // Nothing case ignored: RemoteException => // Nothing
} }
// Update the UI // Update the UI
if (switchButton != null) switchButton.setEnabled(true) if (fab != null) fab.setEnabled(true)
if (State.isAvailable(bgService.getState)) { if (State.isAvailable(bgService.getState)) {
setPreferenceEnabled(enabled = true) setPreferenceEnabled(enabled = true)
} else { } else {
...@@ -218,8 +219,6 @@ class Shadowsocks ...@@ -218,8 +219,6 @@ class Shadowsocks
setPreferenceEnabled(enabled = false) setPreferenceEnabled(enabled = false)
} }
state = bgService.getState state = bgService.getState
// set the listener
switchButton.setOnCheckedChangeListener(Shadowsocks.this)
if (!status.getBoolean(getVersionName, false)) { if (!status.getBoolean(getVersionName, false)) {
status.edit.putBoolean(getVersionName, true).commit() status.edit.putBoolean(getVersionName, true).commit()
...@@ -228,7 +227,7 @@ class Shadowsocks ...@@ -228,7 +227,7 @@ class Shadowsocks
} }
override def onServiceDisconnected(name: ComponentName) { override def onServiceDisconnected(name: ComponentName) {
if (switchButton != null) switchButton.setEnabled(false) if (fab != null) fab.setEnabled(false)
try { try {
if (bgService != null) bgService.unregisterCallback(callback) if (bgService != null) bgService.unregisterCallback(callback)
} catch { } catch {
...@@ -238,8 +237,10 @@ class Shadowsocks ...@@ -238,8 +237,10 @@ class Shadowsocks
} }
} }
private lazy val settings = PreferenceManager.getDefaultSharedPreferences(this) private lazy val preferences =
private lazy val status = getSharedPreferences(Key.status, Context.MODE_PRIVATE) getFragmentManager.findFragmentById(android.R.id.content).asInstanceOf[ShadowsocksSettings]
lazy val settings = PreferenceManager.getDefaultSharedPreferences(this)
lazy val status = getSharedPreferences(Key.status, Context.MODE_PRIVATE)
private lazy val preferenceReceiver = new PreferenceBroadcastReceiver private lazy val preferenceReceiver = new PreferenceBroadcastReceiver
private lazy val drawer = MenuDrawer.attach(this) private lazy val drawer = MenuDrawer.attach(this)
private lazy val menuAdapter = new MenuAdapter(this, getMenuList) private lazy val menuAdapter = new MenuAdapter(this, getMenuList)
...@@ -265,13 +266,12 @@ class Shadowsocks ...@@ -265,13 +266,12 @@ class Shadowsocks
} }
private def changeSwitch(checked: Boolean) { private def changeSwitch(checked: Boolean) {
switchButton.setOnCheckedChangeListener(null) serviceStarted = checked
switchButton.setChecked(checked) fab.setImageResource(if (checked) R.drawable.ic_cloud else R.drawable.ic_cloud_off)
if (switchButton.isEnabled) { if (fab.isEnabled) {
switchButton.setEnabled(false) fab.setEnabled(false)
handler.postDelayed(() => switchButton.setEnabled(true), 1000) handler.postDelayed(() => fab.setEnabled(true), 1000)
} }
switchButton.setOnCheckedChangeListener(this)
} }
private def showProgress(msg: Int): Handler = { private def showProgress(msg: Int): Handler = {
...@@ -374,16 +374,9 @@ class Shadowsocks ...@@ -374,16 +374,9 @@ class Shadowsocks
} }
def isTextEmpty(s: String, msg: String): Boolean = { def isTextEmpty(s: String, msg: String): Boolean = {
if (s == null || s.length <= 0) { if (s != null && s.length > 0) return false
new SnackBar.Builder(this) Snackbar.make(getWindow.getDecorView.findViewById(android.R.id.content), msg, Snackbar.LENGTH_LONG).show
.withMessage(msg) true
.withActionMessageId(R.string.error)
.withStyle(SnackBar.Style.ALERT)
.withDuration(SnackBar.LONG_SNACK)
.show()
return true
}
false
} }
def cancelStart() { def cancelStart() {
...@@ -416,24 +409,6 @@ class Shadowsocks ...@@ -416,24 +409,6 @@ class Shadowsocks
} }
} }
def onCheckedChanged(compoundButton: CompoundButton, checked: Boolean) {
if (compoundButton eq switchButton) {
checked match {
case true =>
if (isReady)
prepareStartService()
else
changeSwitch(checked = false)
case false =>
serviceStop()
}
if (switchButton.isEnabled) {
switchButton.setEnabled(false)
handler.postDelayed(() => switchButton.setEnabled(true), 1000)
}
}
}
def getLayoutView(view: ViewParent): LinearLayout = { def getLayoutView(view: ViewParent): LinearLayout = {
view match { view match {
case layout: LinearLayout => layout case layout: LinearLayout => layout
...@@ -470,7 +445,7 @@ class Shadowsocks ...@@ -470,7 +445,7 @@ class Shadowsocks
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
addPreferencesFromResource(R.xml.pref_all) setContentView(R.layout.layout_main)
// Update the profile // Update the profile
if (!status.getBoolean(getVersionName, false)) { if (!status.getBoolean(getVersionName, false)) {
...@@ -502,24 +477,32 @@ class Shadowsocks ...@@ -502,24 +477,32 @@ class Shadowsocks
} }
// Initialize action bar // Initialize action bar
val switchLayout = getLayoutInflater val toolbar = findViewById(R.id.toolbar).asInstanceOf[Toolbar]
.inflate(R.layout.layout_switch, null) toolbar.setTitle(getTitle)
.asInstanceOf[RelativeLayout] val field = classOf[Toolbar].getDeclaredField("mTitleTextView")
val title: TextView = switchLayout.findViewById(R.id.title).asInstanceOf[TextView] field.setAccessible(true)
val title: TextView = field.get(toolbar).asInstanceOf[TextView]
val tf: Typeface = Typefaces.get(this, "fonts/Iceland.ttf") val tf: Typeface = Typefaces.get(this, "fonts/Iceland.ttf")
if (tf != null) title.setTypeface(tf) if (tf != null) title.setTypeface(tf)
switchButton = switchLayout.findViewById(R.id.switchButton).asInstanceOf[Switch] fab = findViewById(R.id.fab).asInstanceOf[FloatingActionButton]
getActionBar.setCustomView(switchLayout) fab.setOnClickListener((v: View) => {
getActionBar.setDisplayShowTitleEnabled(false) serviceStarted = !serviceStarted
getActionBar.setDisplayShowCustomEnabled(true) serviceStarted match {
if (Utils.isLollipopOrAbove) { case true =>
getWindow.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) if (isReady)
getWindow.setStatusBarColor(ContextCompat.getColor(this, R.color.grey3)) prepareStartService()
getActionBar.setDisplayHomeAsUpEnabled(true) else
getActionBar.setHomeAsUpIndicator(R.drawable.ic_drawer) changeSwitch(checked = false)
} else { case false =>
getActionBar.setIcon(R.drawable.ic_stat_shadowsocks) serviceStop()
}
if (fab.isEnabled) {
fab.setEnabled(false)
handler.postDelayed(() => fab.setEnabled(true), 1000)
} }
})
toolbar.setNavigationIcon(R.drawable.ic_drawer)
toolbar.setNavigationOnClickListener((v: View) => drawer.toggleMenu())
title.setOnLongClickListener((v: View) => { title.setOnLongClickListener((v: View) => {
if (Utils.isLollipopOrAbove && bgService != null if (Utils.isLollipopOrAbove && bgService != null
&& (bgService.getState == State.INIT || bgService.getState == State.STOPPED)) { && (bgService.getState == State.INIT || bgService.getState == State.STOPPED)) {
...@@ -785,18 +768,8 @@ class Shadowsocks ...@@ -785,18 +768,8 @@ class Shadowsocks
buf.toList buf.toList
} }
override def onOptionsItemSelected(item: MenuItem): Boolean = {
item.getItemId match {
case android.R.id.home =>
drawer.toggleMenu()
return true
}
super.onOptionsItemSelected(item)
}
protected override def onPause() { protected override def onPause() {
super.onPause() super.onPause()
switchButton.setOnCheckedChangeListener(null)
prepared = false prepared = false
} }
...@@ -812,8 +785,6 @@ class Shadowsocks ...@@ -812,8 +785,6 @@ class Shadowsocks
changeSwitch(checked = false) changeSwitch(checked = false)
} }
state = bgService.getState state = bgService.getState
// set the listener
switchButton.setOnCheckedChangeListener(Shadowsocks.this)
} }
ConfigUtils.refresh(this) ConfigUtils.refresh(this)
...@@ -825,13 +796,13 @@ class Shadowsocks ...@@ -825,13 +796,13 @@ class Shadowsocks
private def setPreferenceEnabled(enabled: Boolean) { private def setPreferenceEnabled(enabled: Boolean) {
for (name <- Shadowsocks.PROXY_PREFS) { for (name <- Shadowsocks.PROXY_PREFS) {
val pref = findPreference(name) val pref = preferences.findPreference(name)
if (pref != null) { if (pref != null) {
pref.setEnabled(enabled) pref.setEnabled(enabled)
} }
} }
for (name <- Shadowsocks.FEATRUE_PREFS) { for (name <- Shadowsocks.FEATRUE_PREFS) {
val pref = findPreference(name) val pref = preferences.findPreference(name)
if (pref != null) { if (pref != null) {
if (Seq(Key.isGlobalProxy, Key.proxyedApps) if (Seq(Key.isGlobalProxy, Key.proxyedApps)
.contains(name)) { .contains(name)) {
...@@ -846,11 +817,11 @@ class Shadowsocks ...@@ -846,11 +817,11 @@ class Shadowsocks
private def updatePreferenceScreen() { private def updatePreferenceScreen() {
val profile = currentProfile val profile = currentProfile
for (name <- Shadowsocks.PROXY_PREFS) { for (name <- Shadowsocks.PROXY_PREFS) {
val pref = findPreference(name) val pref = preferences.findPreference(name)
Shadowsocks.updatePreference(pref, name, profile) Shadowsocks.updatePreference(pref, name, profile)
} }
for (name <- Shadowsocks.FEATRUE_PREFS) { for (name <- Shadowsocks.FEATRUE_PREFS) {
val pref = findPreference(name) val pref = preferences.findPreference(name)
Shadowsocks.updatePreference(pref, name, profile) Shadowsocks.updatePreference(pref, name, profile)
} }
} }
...@@ -983,22 +954,14 @@ class Shadowsocks ...@@ -983,22 +954,14 @@ class Shadowsocks
try { try {
val port: Int = Integer.valueOf(text) val port: Int = Integer.valueOf(text)
if (!low && port <= 1024) { if (!low && port <= 1024) {
new SnackBar.Builder(this) Snackbar.make(getWindow.getDecorView.findViewById(android.R.id.content), R.string.port_alert,
.withMessageId(R.string.port_alert) Snackbar.LENGTH_LONG).show
.withActionMessageId(R.string.error)
.withStyle(SnackBar.Style.ALERT)
.withDuration(SnackBar.LONG_SNACK)
.show()
return false return false
} }
} catch { } catch {
case ex: Exception => case ex: Exception =>
new SnackBar.Builder(this) Snackbar.make(getWindow.getDecorView.findViewById(android.R.id.content), R.string.port_alert,
.withMessageId(R.string.port_alert) Snackbar.LENGTH_LONG).show
.withActionMessageId(R.string.error)
.withStyle(SnackBar.Style.ALERT)
.withDuration(SnackBar.LONG_SNACK)
.show()
return false return false
} }
true true
...@@ -1072,14 +1035,8 @@ class Shadowsocks ...@@ -1072,14 +1035,8 @@ class Shadowsocks
clearDialog() clearDialog()
} }
changeSwitch(checked = false) changeSwitch(checked = false)
if (m != null) { if (m != null) Snackbar.make(getWindow.getDecorView.findViewById(android.R.id.content),
new SnackBar.Builder(Shadowsocks.this) getString(R.string.vpn_error).formatLocal(Locale.ENGLISH, m), Snackbar.LENGTH_LONG).show
.withMessage(getString(R.string.vpn_error).formatLocal(Locale.ENGLISH, m))
.withActionMessageId(R.string.error)
.withStyle(SnackBar.Style.ALERT)
.withDuration(SnackBar.LONG_SNACK)
.show()
}
setPreferenceEnabled(enabled = true) setPreferenceEnabled(enabled = true)
case State.STOPPING => case State.STOPPING =>
if (progressDialog == null) { if (progressDialog == null) {
......
package com.github.shadowsocks
import android.os.Bundle
import android.preference.PreferenceFragment
// TODO: Move related logic here
class ShadowsocksSettings extends PreferenceFragment {
override def onCreate(savedInstanceState: Bundle) {
super.onCreate(savedInstanceState)
addPreferencesFromResource(R.xml.pref_all)
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment