diff --git a/src/main/res/drawable/background_header.png b/src/main/res/drawable/background_header.png new file mode 100644 index 00000000..b7460148 Binary files /dev/null and b/src/main/res/drawable/background_header.png differ diff --git a/src/main/res/layout/layout_header.xml b/src/main/res/layout/layout_header.xml new file mode 100644 index 00000000..9c9f8631 --- /dev/null +++ b/src/main/res/layout/layout_header.xml @@ -0,0 +1,10 @@ + + diff --git a/src/main/scala/com/github/shadowsocks/MainActivity.scala b/src/main/scala/com/github/shadowsocks/MainActivity.scala index 0281b8cf..c3ee042a 100644 --- a/src/main/scala/com/github/shadowsocks/MainActivity.scala +++ b/src/main/scala/com/github/shadowsocks/MainActivity.scala @@ -22,12 +22,13 @@ package com.github.shadowsocks import java.lang.System.currentTimeMillis import java.net.{HttpURLConnection, URL} -import java.util.Locale +import java.util.{Locale, Hashtable} import android.app.Activity import android.app.backup.BackupManager import android.content.SharedPreferences.OnSharedPreferenceChangeListener import android.content._ +import android.graphics.Typeface import android.net.{Uri, VpnService} import android.nfc.{NdefMessage, NfcAdapter} import android.os.{Build, Bundle, Handler} @@ -40,6 +41,7 @@ import android.util.Log import android.view.View import android.webkit.{WebView, WebViewClient} import android.widget.{TextView, Toast} + import com.github.jorgecastilloprz.FABProgressCircle import com.github.shadowsocks.ShadowsocksApplication.app import com.github.shadowsocks.aidl.IShadowsocksServiceCallback @@ -51,6 +53,27 @@ import com.mikepenz.materialdrawer.model.interfaces.IDrawerItem import com.mikepenz.materialdrawer.model.{PrimaryDrawerItem, SecondaryDrawerItem} import com.mikepenz.materialdrawer.{Drawer, DrawerBuilder} +object Typefaces { + def get(c: Context, assetPath: String): Typeface = { + cache synchronized { + if (!cache.containsKey(assetPath)) { + try { + cache.put(assetPath, Typeface.createFromAsset(c.getAssets, assetPath)) + } catch { + case e: Exception => + Log.e(TAG, "Could not get typeface '" + assetPath + "' because " + e.getMessage) + app.track(e) + return null + } + } + return cache.get(assetPath) + } + } + + private final val TAG = "Typefaces" + private final val cache = new Hashtable[String, Typeface] +} + object MainActivity { private final val TAG = "ShadowsocksMainActivity" private final val REQUEST_CONNECT = 1 @@ -209,7 +232,7 @@ class MainActivity extends Activity with ServiceBoundContext with Drawer.OnDrawe setContentView(R.layout.layout_main) drawer = new DrawerBuilder() .withActivity(this) - // TODO: .withHeader(R.drawable.some_header) + .withHeader(R.layout.layout_header) .addDrawerItems( new PrimaryDrawerItem() .withIdentifier(DRAWER_PROFILES) @@ -228,6 +251,12 @@ class MainActivity extends Activity with ServiceBoundContext with Drawer.OnDrawe .withOnDrawerItemClickListener(this) .withActionBarDrawerToggle(true) .build() + + val header = drawer.getHeader + val title = header.findViewById(R.id.drawer_title).asInstanceOf[TextView] + val tf = Typefaces.get(this, "fonts/Iceland.ttf") + if (tf != null) title.setTypeface(tf) + if (savedInstanceState == null) displayFragment(profilesFragment) stat = findViewById(R.id.stat) connectionTestText = findViewById(R.id.connection_test).asInstanceOf[TextView]