Add a header layout
This commit is contained in:
Binary file not shown.
|
After Width: | Height: | Size: 18 KiB |
@@ -0,0 +1,10 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:id="@+id/drawer_title"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="shadowsocks"
|
||||||
|
android:gravity="center"
|
||||||
|
android:background="@drawable/background_header"
|
||||||
|
android:textSize="32sp"
|
||||||
|
android:textColor="@android:color/white"/>
|
||||||
@@ -22,12 +22,13 @@ package com.github.shadowsocks
|
|||||||
|
|
||||||
import java.lang.System.currentTimeMillis
|
import java.lang.System.currentTimeMillis
|
||||||
import java.net.{HttpURLConnection, URL}
|
import java.net.{HttpURLConnection, URL}
|
||||||
import java.util.Locale
|
import java.util.{Locale, Hashtable}
|
||||||
|
|
||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
import android.app.backup.BackupManager
|
import android.app.backup.BackupManager
|
||||||
import android.content.SharedPreferences.OnSharedPreferenceChangeListener
|
import android.content.SharedPreferences.OnSharedPreferenceChangeListener
|
||||||
import android.content._
|
import android.content._
|
||||||
|
import android.graphics.Typeface
|
||||||
import android.net.{Uri, VpnService}
|
import android.net.{Uri, VpnService}
|
||||||
import android.nfc.{NdefMessage, NfcAdapter}
|
import android.nfc.{NdefMessage, NfcAdapter}
|
||||||
import android.os.{Build, Bundle, Handler}
|
import android.os.{Build, Bundle, Handler}
|
||||||
@@ -40,6 +41,7 @@ import android.util.Log
|
|||||||
import android.view.View
|
import android.view.View
|
||||||
import android.webkit.{WebView, WebViewClient}
|
import android.webkit.{WebView, WebViewClient}
|
||||||
import android.widget.{TextView, Toast}
|
import android.widget.{TextView, Toast}
|
||||||
|
|
||||||
import com.github.jorgecastilloprz.FABProgressCircle
|
import com.github.jorgecastilloprz.FABProgressCircle
|
||||||
import com.github.shadowsocks.ShadowsocksApplication.app
|
import com.github.shadowsocks.ShadowsocksApplication.app
|
||||||
import com.github.shadowsocks.aidl.IShadowsocksServiceCallback
|
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.model.{PrimaryDrawerItem, SecondaryDrawerItem}
|
||||||
import com.mikepenz.materialdrawer.{Drawer, DrawerBuilder}
|
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 {
|
object MainActivity {
|
||||||
private final val TAG = "ShadowsocksMainActivity"
|
private final val TAG = "ShadowsocksMainActivity"
|
||||||
private final val REQUEST_CONNECT = 1
|
private final val REQUEST_CONNECT = 1
|
||||||
@@ -209,7 +232,7 @@ class MainActivity extends Activity with ServiceBoundContext with Drawer.OnDrawe
|
|||||||
setContentView(R.layout.layout_main)
|
setContentView(R.layout.layout_main)
|
||||||
drawer = new DrawerBuilder()
|
drawer = new DrawerBuilder()
|
||||||
.withActivity(this)
|
.withActivity(this)
|
||||||
// TODO: .withHeader(R.drawable.some_header)
|
.withHeader(R.layout.layout_header)
|
||||||
.addDrawerItems(
|
.addDrawerItems(
|
||||||
new PrimaryDrawerItem()
|
new PrimaryDrawerItem()
|
||||||
.withIdentifier(DRAWER_PROFILES)
|
.withIdentifier(DRAWER_PROFILES)
|
||||||
@@ -228,6 +251,12 @@ class MainActivity extends Activity with ServiceBoundContext with Drawer.OnDrawe
|
|||||||
.withOnDrawerItemClickListener(this)
|
.withOnDrawerItemClickListener(this)
|
||||||
.withActionBarDrawerToggle(true)
|
.withActionBarDrawerToggle(true)
|
||||||
.build()
|
.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)
|
if (savedInstanceState == null) displayFragment(profilesFragment)
|
||||||
stat = findViewById(R.id.stat)
|
stat = findViewById(R.id.stat)
|
||||||
connectionTestText = findViewById(R.id.connection_test).asInstanceOf[TextView]
|
connectionTestText = findViewById(R.id.connection_test).asInstanceOf[TextView]
|
||||||
|
|||||||
Reference in New Issue
Block a user