Commit 5419b4b5 authored by Max Lv's avatar Max Lv

Fix issues on Android 4.4

parent 28523091
......@@ -4,8 +4,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent">
<include layout="@layout/toolbar_light_dark" />
<fragment android:id="@+id/content"
class="com.github.shadowsocks.GlobalConfigFragment"
<LinearLayout android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
......
......@@ -22,6 +22,7 @@ package com.github.shadowsocks
import android.os.Bundle
import android.view.{LayoutInflater, View, ViewGroup}
import android.app.Fragment
class GlobalSettingsFragment extends ToolbarFragment {
......@@ -31,5 +32,24 @@ class GlobalSettingsFragment extends ToolbarFragment {
override def onViewCreated(view: View, savedInstanceState: Bundle) {
super.onViewCreated(view, savedInstanceState)
toolbar.setTitle(R.string.settings)
val fm = getChildFragmentManager()
val fragment = new GlobalConfigFragment()
val ft = fm.beginTransaction()
ft.replace(R.id.content, fragment)
ft.commit()
fm.executePendingTransactions()
}
override def onDetach() {
super.onDetach()
try {
val childFragmentManager = classOf[Fragment].getDeclaredField("mChildFragmentManager")
childFragmentManager.setAccessible(true)
childFragmentManager.set(this, null)
} catch {
case ex: Exception => // ignore
}
}
}
......@@ -207,25 +207,25 @@ class MainActivity extends Activity with ServiceBoundContext with Drawer.OnDrawe
new PrimaryDrawerItem()
.withIdentifier(DRAWER_PROFILES)
.withName(R.string.profiles)
.withIcon(ContextCompat.getDrawable(this, R.drawable.ic_action_description))
.withIcon(Utils.getAPICompatVectorDrawable(this, R.drawable.ic_action_description))
.withIconTintingEnabled(true),
new PrimaryDrawerItem()
.withIdentifier(DRAWER_GLOBAL_SETTINGS)
.withName(R.string.settings)
.withIcon(ContextCompat.getDrawable(this, R.drawable.ic_action_settings))
.withIcon(Utils.getAPICompatVectorDrawable(this, R.drawable.ic_action_settings))
.withIconTintingEnabled(true)
)
.addStickyDrawerItems(
new PrimaryDrawerItem()
.withIdentifier(DRAWER_RECOVERY)
.withName(R.string.recovery)
.withIcon(ContextCompat.getDrawable(this, R.drawable.ic_navigation_refresh))
.withIcon(Utils.getAPICompatVectorDrawable(this, R.drawable.ic_navigation_refresh))
.withIconTintingEnabled(true)
.withSelectable(false),
new PrimaryDrawerItem()
.withIdentifier(DRAWER_ABOUT)
.withName(R.string.about)
.withIcon(ContextCompat.getDrawable(this, R.drawable.ic_action_copyright))
.withIcon(Utils.getAPICompatVectorDrawable(this, R.drawable.ic_action_copyright))
.withIconTintingEnabled(true)
)
.withOnDrawerItemClickListener(this)
......@@ -301,6 +301,14 @@ class MainActivity extends Activity with ServiceBoundContext with Drawer.OnDrawe
val intent = getIntent
if (intent != null) handleShareIntent(intent)
app.profileManager.getFirstProfile match {
case Some(_) => // Ignore
case _ => {
val profile = app.profileManager.createProfile()
app.profileId(profile.id)
}
}
}
override def onNewIntent(intent: Intent) {
......
......@@ -29,7 +29,10 @@ import android.animation.{Animator, AnimatorListenerAdapter}
import android.content.pm.PackageManager
import android.content.{Context, Intent}
import android.graphics._
import android.graphics.drawable.Drawable
import android.os.Build
import android.support.v4.content.ContextCompat
import android.support.graphics.drawable.VectorDrawableCompat
import android.util.{Base64, DisplayMetrics, Log}
import android.view.View.MeasureSpec
import android.view.{Gravity, View, Window}
......@@ -49,6 +52,14 @@ object Utils {
def isLollipopOrAbove: Boolean = Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP
def getAPICompatVectorDrawable(callingContext: Context, resource_id: Int): Drawable = {
if (Build.VERSION.SDK_INT >= 21) {
return ContextCompat.getDrawable(callingContext.getApplicationContext(), resource_id);
} else {
return VectorDrawableCompat.create(callingContext.getResources(), resource_id, callingContext.getTheme());
}
}
def getSignature(context: Context): String = {
val info = context
.getPackageManager
......
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