Commit 53fcba30 authored by Max Lv's avatar Max Lv

WiP, drawer works now

parent ae2319ca
...@@ -2,7 +2,6 @@ libraryDependencies ++= Seq( ...@@ -2,7 +2,6 @@ libraryDependencies ++= Seq(
"com.google.android" % "support-v4" % "r12", "com.google.android" % "support-v4" % "r12",
"com.google.android.analytics" % "analytics" % "2.0beta4", "com.google.android.analytics" % "analytics" % "2.0beta4",
"dnsjava" % "dnsjava" % "2.1.5", "dnsjava" % "dnsjava" % "2.1.5",
"com.nostra13.universalimageloader" % "universal-image-loader" % "1.8.4",
"com.google.android.admob" % "admob" % "6.3.1" "com.google.android.admob" % "admob" % "6.3.1"
) )
...@@ -10,6 +9,13 @@ libraryDependencies ++= Seq( ...@@ -10,6 +9,13 @@ libraryDependencies ++= Seq(
"com.actionbarsherlock" % "actionbarsherlock" % "4.4.0" artifacts(Artifact("actionbarsherlock", "apklib", "apklib")), "com.actionbarsherlock" % "actionbarsherlock" % "4.4.0" artifacts(Artifact("actionbarsherlock", "apklib", "apklib")),
"net.saik0.android.unifiedpreference" % "unifiedpreference" % "0.0.2" artifacts(Artifact("unifiedpreference", "apklib", "apklib")), "net.saik0.android.unifiedpreference" % "unifiedpreference" % "0.0.2" artifacts(Artifact("unifiedpreference", "apklib", "apklib")),
"org.jraf" % "android-switch-backport" % "1.0" artifacts(Artifact("android-switch-backport", "apklib", "apklib")), "org.jraf" % "android-switch-backport" % "1.0" artifacts(Artifact("android-switch-backport", "apklib", "apklib")),
"de.keyboardsurfer.android.widget" % "crouton" % "1.7" "net.simonvt.menudrawer" % "menudrawer" % "3.0.4" artifacts(Artifact("menudrawer", "apklib", "apklib"))
)
libraryDependencies ++= Seq(
"de.keyboardsurfer.android.widget" % "crouton" % "1.7",
"com.nostra13.universalimageloader" % "universal-image-loader" % "1.8.4",
"com.j256.ormlite" % "ormlite-core" % "4.47",
"com.j256.ormlite" % "ormlite-android" % "4.47"
) )
...@@ -5,8 +5,8 @@ import sbtandroid._ ...@@ -5,8 +5,8 @@ import sbtandroid._
import sbtandroid.AndroidPlugin._ import sbtandroid.AndroidPlugin._
object App { object App {
val version = "1.8.3" val version = "1.9.0"
val versionCode = 48 val versionCode = 50
} }
object General { object General {
...@@ -28,6 +28,7 @@ object General { ...@@ -28,6 +28,7 @@ object General {
"-keep interface com.actionbarsherlock.** { *; }", "-keep interface com.actionbarsherlock.** { *; }",
"-keep class org.jraf.android.backport.** { *; }", "-keep class org.jraf.android.backport.** { *; }",
"-keep class com.github.shadowsocks.** { *; }", "-keep class com.github.shadowsocks.** { *; }",
"-keep class * extends com.j256.ormlite.** { *; }",
"-keepattributes *Annotation*") "-keepattributes *Annotation*")
val proguardSettings = Seq ( val proguardSettings = Seq (
...@@ -36,8 +37,7 @@ object General { ...@@ -36,8 +37,7 @@ object General {
) )
val miscSettings = Seq ( val miscSettings = Seq (
cachePasswords := true, cachePasswords := true
publicServer := "127.0.0.1"
) )
lazy val fullAndroidSettings = lazy val fullAndroidSettings =
......
...@@ -6,4 +6,4 @@ resolvers += Resolver.url("madeye private releases", new URL("http://madeye-mave ...@@ -6,4 +6,4 @@ resolvers += Resolver.url("madeye private releases", new URL("http://madeye-mave
addSbtPlugin("org.scala-sbt" % "sbt-android" % "0.7.1-SNAPSHOT") addSbtPlugin("org.scala-sbt" % "sbt-android" % "0.7.1-SNAPSHOT")
addSbtPlugin("com.github.mpeltonen" % "sbt-idea" % "1.4.0") addSbtPlugin("com.github.mpeltonen" % "sbt-idea" % "1.5.1")
...@@ -9,8 +9,7 @@ ...@@ -9,8 +9,7 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:gravity="center_vertical" android:gravity="center_vertical"
android:layout_marginLeft="16dp" android:textSize="22sp"
android:textSize="28sp"
android:textColor="@color/title" android:textColor="@color/title"
android:text="@string/app_name" android:text="@string/app_name"
android:layout_alignParentLeft="true" android:layout_alignParentLeft="true"
......
...@@ -45,7 +45,7 @@ import android.graphics.Typeface ...@@ -45,7 +45,7 @@ import android.graphics.Typeface
import android.os._ import android.os._
import android.preference.{Preference, PreferenceManager} import android.preference.{Preference, PreferenceManager}
import android.util.Log import android.util.Log
import android.view.{ViewParent, KeyEvent} import android.view.{ViewGroup, Gravity, ViewParent, KeyEvent}
import android.widget.{LinearLayout, CompoundButton, RelativeLayout, TextView} import android.widget.{LinearLayout, CompoundButton, RelativeLayout, TextView}
import com.actionbarsherlock.view.Menu import com.actionbarsherlock.view.Menu
import com.actionbarsherlock.view.MenuItem import com.actionbarsherlock.view.MenuItem
...@@ -67,6 +67,8 @@ import android.app.backup.BackupManager ...@@ -67,6 +67,8 @@ import android.app.backup.BackupManager
import scala.concurrent.ops._ import scala.concurrent.ops._
import android.content.SharedPreferences.OnSharedPreferenceChangeListener import android.content.SharedPreferences.OnSharedPreferenceChangeListener
import com.google.ads.{AdRequest, AdSize, AdView} import com.google.ads.{AdRequest, AdSize, AdView}
import net.simonvt.menudrawer.MenuDrawer
import javax.swing.text.html.ListView
object Shadowsocks { object Shadowsocks {
...@@ -212,11 +214,14 @@ class Shadowsocks ...@@ -212,11 +214,14 @@ class Shadowsocks
private var switchButton: Switch = null private var switchButton: Switch = null
private var progressDialog: ProgressDialog = null private var progressDialog: ProgressDialog = null
private var settings: SharedPreferences = null
private var status: SharedPreferences = null
private var prepared = false
private var state = State.INIT private var state = State.INIT
private var receiver: StateBroadcastReceiver = null private var prepared = false
lazy val settings = PreferenceManager.getDefaultSharedPreferences(this)
lazy val status = getSharedPreferences(Key.status, Context.MODE_PRIVATE)
lazy val receiver = new StateBroadcastReceiver
lazy val drawer = MenuDrawer.attach(this)
private val handler: Handler = new Handler { private val handler: Handler = new Handler {
override def handleMessage(msg: Message) { override def handleMessage(msg: Message) {
...@@ -366,7 +371,7 @@ class Shadowsocks ...@@ -366,7 +371,7 @@ class Shadowsocks
} }
} }
def initAdView() { def initAdView(layoutResId: Int) {
if (settings.getString(Key.proxy, "") == "198.199.101.152") { if (settings.getString(Key.proxy, "") == "198.199.101.152") {
val adView = { val adView = {
if (isSinglePane) { if (isSinglePane) {
...@@ -375,7 +380,7 @@ class Shadowsocks ...@@ -375,7 +380,7 @@ class Shadowsocks
new AdView(this, AdSize.BANNER, "a151becb8068b09") new AdView(this, AdSize.BANNER, "a151becb8068b09")
} }
} }
val layoutView = getLayoutView(getListView.asInstanceOf[ViewParent]) val layoutView = findViewById(layoutResId).asInstanceOf[ViewGroup]
if (layoutView != null) { if (layoutView != null) {
layoutView.addView(adView, 0) layoutView.addView(adView, 0)
adView.loadAd(new AdRequest) adView.loadAd(new AdRequest)
...@@ -383,18 +388,35 @@ class Shadowsocks ...@@ -383,18 +388,35 @@ class Shadowsocks
} }
} }
override def setContentView(layoutResId: Int) {
drawer.setContentView(layoutResId)
initAdView(layoutResId)
onContentChanged()
}
/** Called when the activity is first created. */ /** Called when the activity is first created. */
override def onCreate(savedInstanceState: Bundle) { override def onCreate(savedInstanceState: Bundle) {
setHeaderRes(R.xml.shadowsocks_headers) setHeaderRes(R.xml.shadowsocks_headers)
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
val menuView = new TextView(this)
menuView.setTextColor(0xFFFFFFFF)
menuView.setText("As the drawer opens, the drawer indicator icon becomes smaller.")
menuView.setGravity(Gravity.CENTER)
drawer.setMenuView(menuView)
// The drawable that replaces the up indicator in the action bar
drawer.setSlideDrawable(R.drawable.ic_drawer)
// Whether the previous drawable should be shown
drawer.setDrawerIndicatorEnabled(true)
val switchLayout = getLayoutInflater val switchLayout = getLayoutInflater
.inflate(R.layout.layout_switch, null) .inflate(R.layout.layout_switch, null)
.asInstanceOf[RelativeLayout] .asInstanceOf[RelativeLayout]
getSupportActionBar.setCustomView(switchLayout) getSupportActionBar.setCustomView(switchLayout)
getSupportActionBar.setDisplayShowTitleEnabled(false) getSupportActionBar.setDisplayShowTitleEnabled(false)
getSupportActionBar.setDisplayShowCustomEnabled(true) getSupportActionBar.setDisplayShowCustomEnabled(true)
getSupportActionBar.setDisplayShowHomeEnabled(false) // getSupportActionBar.setDisplayShowHomeEnabled(false)
val title: TextView = switchLayout.findViewById(R.id.title).asInstanceOf[TextView] val title: TextView = switchLayout.findViewById(R.id.title).asInstanceOf[TextView]
val tf: Typeface = Typefaces.get(this, "fonts/Iceland.ttf") val tf: Typeface = Typefaces.get(this, "fonts/Iceland.ttf")
...@@ -402,13 +424,8 @@ class Shadowsocks ...@@ -402,13 +424,8 @@ class Shadowsocks
title.setText(R.string.app_name) title.setText(R.string.app_name)
switchButton = switchLayout.findViewById(R.id.switchButton).asInstanceOf[Switch] switchButton = switchLayout.findViewById(R.id.switchButton).asInstanceOf[Switch]
settings = PreferenceManager.getDefaultSharedPreferences(this)
status = getSharedPreferences(Key.status, Context.MODE_PRIVATE)
receiver = new StateBroadcastReceiver()
registerReceiver(receiver, new IntentFilter(Action.UPDATE_STATE)) registerReceiver(receiver, new IntentFilter(Action.UPDATE_STATE))
initAdView()
val init: Boolean = !Shadowsocks.isServiceStarted(this) val init: Boolean = !Shadowsocks.isServiceStarted(this)
if (init) { if (init) {
if (progressDialog == null) { if (progressDialog == null) {
...@@ -425,7 +442,7 @@ class Shadowsocks ...@@ -425,7 +442,7 @@ class Shadowsocks
} }
} }
override def onCreateOptionsMenu(menu: Menu): Boolean = { /* override def onCreateOptionsMenu(menu: Menu): Boolean = {
val isRoot = status.getBoolean(Key.isRoot, false) val isRoot = status.getBoolean(Key.isRoot, false)
menu menu
.add(0, 0, 0, R.string.recovery) .add(0, 0, 0, R.string.recovery)
...@@ -442,7 +459,7 @@ class Shadowsocks ...@@ -442,7 +459,7 @@ class Shadowsocks
.setShowAsAction(MenuItem.SHOW_AS_ACTION_WITH_TEXT) .setShowAsAction(MenuItem.SHOW_AS_ACTION_WITH_TEXT)
} }
true true
} }*/
override def onKeyDown(keyCode: Int, event: KeyEvent): Boolean = { override def onKeyDown(keyCode: Int, event: KeyEvent): Boolean = {
if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount == 0) { if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount == 0) {
...@@ -459,6 +476,11 @@ class Shadowsocks ...@@ -459,6 +476,11 @@ class Shadowsocks
override def onOptionsItemSelected(item: MenuItem): Boolean = { override def onOptionsItemSelected(item: MenuItem): Boolean = {
item.getItemId match { item.getItemId match {
case android.R.id.home => {
EasyTracker.getTracker.sendEvent(Shadowsocks.TAG, "home", getVersionName, 0L)
drawer.toggleMenu()
return true
}
case 0 => { case 0 => {
EasyTracker.getTracker.sendEvent(Shadowsocks.TAG, "reset", getVersionName, 0L) EasyTracker.getTracker.sendEvent(Shadowsocks.TAG, "reset", getVersionName, 0L)
recovery() recovery()
......
package com.github.shadowsocks.database
import com.j256.ormlite.android.apptools.OrmLiteSqliteOpenHelper
import android.content.Context
import android.database.sqlite.SQLiteDatabase
import com.j256.ormlite.support.ConnectionSource
import com.j256.ormlite.table.TableUtils
import com.j256.ormlite.dao.Dao
class DBHelper(implicit val context: Context) extends OrmLiteSqliteOpenHelper(context, "postnauka", null, 3) {
lazy val profileDao:Dao[Profile,Int] = getDao(classOf[Profile])
def onCreate(database: SQLiteDatabase, connectionSource: ConnectionSource) {
TableUtils.createTable(connectionSource, classOf[Profile])
}
def onUpgrade(database: SQLiteDatabase, connectionSource: ConnectionSource, oldVersion: Int, newVersion: Int) {
TableUtils.dropTable(connectionSource, classOf[Profile], true)
onCreate(database, connectionSource)
}
}
package com.github.shadowsocks.database
import com.j256.ormlite.field.{DataType, DatabaseField}
class Profile {
@DatabaseField(id = true)
var id: Int = 0
@DatabaseField
var name: String = null
@DatabaseField(foreign = true, canBeNull = false)
var host: String = null
@DatabaseField
var localPort: Int = 0
@DatabaseField
var remotePort: Int = 0
@DatabaseField
var password: String = null
@DatabaseField
var method: String = null
@DatabaseField
var date: String = null
@DatabaseField
var upload: Int = 0
@DatabaseField
var download: Int = 0
@DatabaseField
var chnroute: Boolean = false
@DatabaseField
var global: Boolean = false
@DatabaseField(dataType = DataType.LONG_STRING)
var individual: String = null
@DatabaseField(dataType = DataType.LONG_STRING)
var description: String = null
}
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