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

Fix issues on Android 4.4

parent 28523091
...@@ -4,9 +4,8 @@ ...@@ -4,9 +4,8 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent">
<include layout="@layout/toolbar_light_dark" /> <include layout="@layout/toolbar_light_dark" />
<fragment android:id="@+id/content" <LinearLayout android:id="@+id/content"
class="com.github.shadowsocks.GlobalConfigFragment" android:layout_width="match_parent"
android:layout_width="match_parent" android:layout_height="0dp"
android:layout_height="0dp" android:layout_weight="1"/>
android:layout_weight="1"/>
</LinearLayout> </LinearLayout>
...@@ -22,6 +22,7 @@ package com.github.shadowsocks ...@@ -22,6 +22,7 @@ package com.github.shadowsocks
import android.os.Bundle import android.os.Bundle
import android.view.{LayoutInflater, View, ViewGroup} import android.view.{LayoutInflater, View, ViewGroup}
import android.app.Fragment
class GlobalSettingsFragment extends ToolbarFragment { class GlobalSettingsFragment extends ToolbarFragment {
...@@ -31,5 +32,24 @@ class GlobalSettingsFragment extends ToolbarFragment { ...@@ -31,5 +32,24 @@ class GlobalSettingsFragment extends ToolbarFragment {
override def onViewCreated(view: View, savedInstanceState: Bundle) { override def onViewCreated(view: View, savedInstanceState: Bundle) {
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
toolbar.setTitle(R.string.settings) 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 ...@@ -207,25 +207,25 @@ class MainActivity extends Activity with ServiceBoundContext with Drawer.OnDrawe
new PrimaryDrawerItem() new PrimaryDrawerItem()
.withIdentifier(DRAWER_PROFILES) .withIdentifier(DRAWER_PROFILES)
.withName(R.string.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), .withIconTintingEnabled(true),
new PrimaryDrawerItem() new PrimaryDrawerItem()
.withIdentifier(DRAWER_GLOBAL_SETTINGS) .withIdentifier(DRAWER_GLOBAL_SETTINGS)
.withName(R.string.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) .withIconTintingEnabled(true)
) )
.addStickyDrawerItems( .addStickyDrawerItems(
new PrimaryDrawerItem() new PrimaryDrawerItem()
.withIdentifier(DRAWER_RECOVERY) .withIdentifier(DRAWER_RECOVERY)
.withName(R.string.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) .withIconTintingEnabled(true)
.withSelectable(false), .withSelectable(false),
new PrimaryDrawerItem() new PrimaryDrawerItem()
.withIdentifier(DRAWER_ABOUT) .withIdentifier(DRAWER_ABOUT)
.withName(R.string.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) .withIconTintingEnabled(true)
) )
.withOnDrawerItemClickListener(this) .withOnDrawerItemClickListener(this)
...@@ -301,6 +301,14 @@ class MainActivity extends Activity with ServiceBoundContext with Drawer.OnDrawe ...@@ -301,6 +301,14 @@ class MainActivity extends Activity with ServiceBoundContext with Drawer.OnDrawe
val intent = getIntent val intent = getIntent
if (intent != null) handleShareIntent(intent) 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) { override def onNewIntent(intent: Intent) {
......
...@@ -29,7 +29,10 @@ import android.animation.{Animator, AnimatorListenerAdapter} ...@@ -29,7 +29,10 @@ import android.animation.{Animator, AnimatorListenerAdapter}
import android.content.pm.PackageManager import android.content.pm.PackageManager
import android.content.{Context, Intent} import android.content.{Context, Intent}
import android.graphics._ import android.graphics._
import android.graphics.drawable.Drawable
import android.os.Build import android.os.Build
import android.support.v4.content.ContextCompat
import android.support.graphics.drawable.VectorDrawableCompat
import android.util.{Base64, DisplayMetrics, Log} import android.util.{Base64, DisplayMetrics, Log}
import android.view.View.MeasureSpec import android.view.View.MeasureSpec
import android.view.{Gravity, View, Window} import android.view.{Gravity, View, Window}
...@@ -49,6 +52,14 @@ object Utils { ...@@ -49,6 +52,14 @@ object Utils {
def isLollipopOrAbove: Boolean = Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP 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 = { def getSignature(context: Context): String = {
val info = context val info = context
.getPackageManager .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