diff --git a/.github/faq.md b/.github/faq.md index 742e3df3..02ebab23 100644 --- a/.github/faq.md +++ b/.github/faq.md @@ -9,10 +9,9 @@ Cannot connect to server: Crash: [Submit an issue](https://github.com/shadowsocks/shadowsocks-android/issues/new) with logcat attached, or submit a crash report to Google Play. Then, try wiping app data. -### UI tips +### How to create a widget and/or switch profile based on network connectivity? -* Tap the number to enter the port you wish to use; (if the keyboard doesn't pop up automatically for some reason) -* Use Tasker integration to create a desktop widget. +Use [Tasker](http://tasker.dinglisch.net/) integration. ### How to add QR code from local gallery? diff --git a/build.sbt b/build.sbt index 9c859376..acb71230 100644 --- a/build.sbt +++ b/build.sbt @@ -20,10 +20,13 @@ lazy val commonSettings = Seq( resConfigs := Seq("fa", "ja", "ko", "ru", "zh-rCN", "zh-rTW"), + resolvers += Resolver.jcenterRepo, + resolvers += Resolver.bintrayRepo("gericop", "maven"), resolvers += "google" at "https://maven.google.com" ) val supportLibsVersion = "27.0.2" +val takisoftFixVersion = "27.0.2.0" lazy val root = Project(id = "shadowsocks-android", base = file(".")) .settings(commonSettings) .aggregate(plugin, mobile) @@ -34,7 +37,11 @@ run in Android := (run in (mobile, Android)).evaluated lazy val plugin = project .settings(commonSettings) .settings( - libraryDependencies += "com.android.support" % "preference-v14" % supportLibsVersion + libraryDependencies ++= + "com.android.support" % "preference-v14" % supportLibsVersion :: + "com.takisoft.fix" % "preference-v7" % takisoftFixVersion :: + "com.takisoft.fix" % "preference-v7-simplemenu" % takisoftFixVersion :: + Nil ) lazy val mobile = project diff --git a/mobile/src/main/java/com/github/shadowsocks/DialogFragment.java b/mobile/src/main/java/com/github/shadowsocks/DialogFragment.java deleted file mode 100644 index b05b2ade..00000000 --- a/mobile/src/main/java/com/github/shadowsocks/DialogFragment.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.github.shadowsocks; - -import android.app.Activity; - -/** - * This helper class is used to solve Java-Scala interop problem. Use onAttach(Context) and remove this class - * when minSdkVersion >= 23. - * - * @author Mygod - */ -public class DialogFragment extends android.app.DialogFragment { - protected void superOnAttach(Activity activity) { - super.onAttach(activity); - } -} diff --git a/mobile/src/main/res/values/colors.xml b/mobile/src/main/res/values/colors.xml index 64da4fad..afa4fe44 100644 --- a/mobile/src/main/res/values/colors.xml +++ b/mobile/src/main/res/values/colors.xml @@ -1,4 +1,5 @@ #7488A1 + @color/material_accent_200 diff --git a/mobile/src/main/res/values/styles.xml b/mobile/src/main/res/values/styles.xml index 956d9f2d..027dd5af 100644 --- a/mobile/src/main/res/values/styles.xml +++ b/mobile/src/main/res/values/styles.xml @@ -1,8 +1,5 @@ - - - - - - - - - - - diff --git a/plugin/src/main/scala/be/mygod/preference/DialogPreferencePlus.scala b/plugin/src/main/scala/be/mygod/preference/DialogPreferencePlus.scala deleted file mode 100644 index 36b02fc8..00000000 --- a/plugin/src/main/scala/be/mygod/preference/DialogPreferencePlus.scala +++ /dev/null @@ -1,28 +0,0 @@ -/*******************************************************************************/ -/* */ -/* Copyright (C) 2017 by Max Lv */ -/* Copyright (C) 2017 by Mygod Studio */ -/* */ -/* This program is free software: you can redistribute it and/or modify */ -/* it under the terms of the GNU General Public License as published by */ -/* the Free Software Foundation, either version 3 of the License, or */ -/* (at your option) any later version. */ -/* */ -/* This program is distributed in the hope that it will be useful, */ -/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ -/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ -/* GNU General Public License for more details. */ -/* */ -/* You should have received a copy of the GNU General Public License */ -/* along with this program. If not, see . */ -/* */ -/*******************************************************************************/ - -package be.mygod.preference - -import android.app.DialogFragment -import android.support.v7.preference.DialogPreference - -trait DialogPreferencePlus extends DialogPreference { - def createDialog(): DialogFragment -} diff --git a/plugin/src/main/scala/be/mygod/preference/EditTextPreference.scala b/plugin/src/main/scala/be/mygod/preference/EditTextPreference.scala deleted file mode 100644 index a57fb98d..00000000 --- a/plugin/src/main/scala/be/mygod/preference/EditTextPreference.scala +++ /dev/null @@ -1,67 +0,0 @@ -/*******************************************************************************/ -/* */ -/* Copyright (C) 2017 by Max Lv */ -/* Copyright (C) 2017 by Mygod Studio */ -/* */ -/* This program is free software: you can redistribute it and/or modify */ -/* it under the terms of the GNU General Public License as published by */ -/* the Free Software Foundation, either version 3 of the License, or */ -/* (at your option) any later version. */ -/* */ -/* This program is distributed in the hope that it will be useful, */ -/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ -/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ -/* GNU General Public License for more details. */ -/* */ -/* You should have received a copy of the GNU General Public License */ -/* along with this program. If not, see . */ -/* */ -/*******************************************************************************/ - -package be.mygod.preference - -import android.content.Context -import android.support.v7.preference.{EditTextPreference => Parent} -import android.support.v7.widget.AppCompatEditText -import android.text.InputType -import android.util.AttributeSet -import android.view.ViewGroup -import android.widget.FrameLayout -import com.github.shadowsocks.plugin.R - -/** - * Fixed EditTextPreference + SummaryPreference with password support! - * Based on: https://github.com/Gericop/Android-Support-Preference-V7-Fix/tree/master/app/src/main/java/android/support/v7/preference - */ -class EditTextPreference(context: Context, attrs: AttributeSet = null) extends Parent(context, attrs) - with DialogPreferencePlus with SummaryPreference { - val editText = new AppCompatEditText(context, attrs) - editText.setId(android.R.id.edit) - - { - val arr = context.obtainStyledAttributes(Array(R.attr.dialogPreferredPadding)) - val margin = arr.getDimensionPixelOffset(0, 0) - arr.recycle() - val params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT) - params.setMargins(margin, 0, margin, 0) - editText.setLayoutParams(params) - } - - override def createDialog() = new EditTextPreferenceDialogFragment() - - override protected def getSummaryValue: String = { - var text = getText - if (text == null) text = "" - val inputType = editText.getInputType - if (inputType == (InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD) || - inputType == (InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_WEB_PASSWORD) || - inputType == (InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_VARIATION_PASSWORD)) - "\u2022" * text.length else text - } - - override def setText(text: String): Unit = { - val old = getText - super.setText(text) - if (old != text) notifyChanged() - } -} diff --git a/plugin/src/main/scala/be/mygod/preference/EditTextPreferenceDialogFragment.scala b/plugin/src/main/scala/be/mygod/preference/EditTextPreferenceDialogFragment.scala deleted file mode 100644 index e8ed19e4..00000000 --- a/plugin/src/main/scala/be/mygod/preference/EditTextPreferenceDialogFragment.scala +++ /dev/null @@ -1,53 +0,0 @@ -/*******************************************************************************/ -/* */ -/* Copyright (C) 2017 by Max Lv */ -/* Copyright (C) 2017 by Mygod Studio */ -/* */ -/* This program is free software: you can redistribute it and/or modify */ -/* it under the terms of the GNU General Public License as published by */ -/* the Free Software Foundation, either version 3 of the License, or */ -/* (at your option) any later version. */ -/* */ -/* This program is distributed in the hope that it will be useful, */ -/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ -/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ -/* GNU General Public License for more details. */ -/* */ -/* You should have received a copy of the GNU General Public License */ -/* along with this program. If not, see . */ -/* */ -/*******************************************************************************/ - -package be.mygod.preference - -import android.support.v14.preference.PreferenceDialogFragment -import android.support.v7.widget.AppCompatEditText -import android.view.{View, ViewGroup} - -class EditTextPreferenceDialogFragment extends PreferenceDialogFragment { - private lazy val preference = getPreference.asInstanceOf[EditTextPreference] - protected lazy val editText: AppCompatEditText = preference.editText - - override protected def onBindDialogView(view: View) { - super.onBindDialogView(view) - editText.setText(preference.getText) - val text = editText.getText - if (text != null) editText.setSelection(0, text.length) - val oldParent = editText.getParent.asInstanceOf[ViewGroup] - if (oldParent eq view) return - if (oldParent != null) oldParent.removeView(editText) - val oldEdit = view.findViewById[View](android.R.id.edit) - if (oldEdit == null) return - val container = oldEdit.getParent.asInstanceOf[ViewGroup] - if (container == null) return - container.removeView(oldEdit) - container.addView(editText, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT) - } - - override protected def needInputMethod = true - - def onDialogClosed(positiveResult: Boolean): Unit = if (positiveResult) { - val value = editText.getText.toString - if (preference.callChangeListener(value)) preference.setText(value) - } -} diff --git a/plugin/src/main/scala/be/mygod/preference/NumberPickerPreference.scala b/plugin/src/main/scala/be/mygod/preference/NumberPickerPreference.scala deleted file mode 100644 index 9b303670..00000000 --- a/plugin/src/main/scala/be/mygod/preference/NumberPickerPreference.scala +++ /dev/null @@ -1,65 +0,0 @@ -/*******************************************************************************/ -/* */ -/* Copyright (C) 2017 by Max Lv */ -/* Copyright (C) 2017 by Mygod Studio */ -/* */ -/* This program is free software: you can redistribute it and/or modify */ -/* it under the terms of the GNU General Public License as published by */ -/* the Free Software Foundation, either version 3 of the License, or */ -/* (at your option) any later version. */ -/* */ -/* This program is distributed in the hope that it will be useful, */ -/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ -/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ -/* GNU General Public License for more details. */ -/* */ -/* You should have received a copy of the GNU General Public License */ -/* along with this program. If not, see . */ -/* */ -/*******************************************************************************/ - -package be.mygod.preference - -import android.content.Context -import android.content.res.TypedArray -import android.support.v7.preference.DialogPreference -import android.util.AttributeSet -import android.view.ContextThemeWrapper -import android.widget.NumberPicker -import com.github.shadowsocks.plugin.R - -class NumberPickerPreference(private val context: Context, attrs: AttributeSet = null) - extends DialogPreference(context, attrs) with DialogPreferencePlus with SummaryPreference { - private[preference] val picker = new NumberPicker(new ContextThemeWrapper(context, R.style.NumberPickerStyle)) - private var value: Int = _ - - { - val a: TypedArray = context.obtainStyledAttributes(attrs, R.styleable.NumberPickerPreference) - setMin(a.getInt(R.styleable.NumberPickerPreference_min, 0)) - setMax(a.getInt(R.styleable.NumberPickerPreference_max, Int.MaxValue - 1)) - a.recycle() - } - - override def createDialog() = new NumberPickerPreferenceDialogFragment() - - def getValue: Int = value - def getMin: Int = if (picker == null) 0 else picker.getMinValue - def getMax: Int = picker.getMaxValue - def setValue(i: Int) { - if (i == value) return - picker.setValue(i) - value = picker.getValue - persistInt(value) - notifyChanged() - } - def setMin(value: Int): Unit = picker.setMinValue(value) - def setMax(value: Int): Unit = picker.setMaxValue(value) - - override protected def onGetDefaultValue(a: TypedArray, index: Int): AnyRef = - a.getInt(index, getMin).asInstanceOf[AnyRef] - override protected def onSetInitialValue(restorePersistedValue: Boolean, defaultValue: Any) { - val default = defaultValue.asInstanceOf[Int] - setValue(if (restorePersistedValue) getPersistedInt(default) else default) - } - protected def getSummaryValue: AnyRef = getValue.asInstanceOf[AnyRef] -} diff --git a/plugin/src/main/scala/be/mygod/preference/NumberPickerPreferenceDialogFragment.scala b/plugin/src/main/scala/be/mygod/preference/NumberPickerPreferenceDialogFragment.scala deleted file mode 100644 index 5f8f50ab..00000000 --- a/plugin/src/main/scala/be/mygod/preference/NumberPickerPreferenceDialogFragment.scala +++ /dev/null @@ -1,52 +0,0 @@ -/*******************************************************************************/ -/* */ -/* Copyright (C) 2017 by Max Lv */ -/* Copyright (C) 2017 by Mygod Studio */ -/* */ -/* This program is free software: you can redistribute it and/or modify */ -/* it under the terms of the GNU General Public License as published by */ -/* the Free Software Foundation, either version 3 of the License, or */ -/* (at your option) any later version. */ -/* */ -/* This program is distributed in the hope that it will be useful, */ -/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ -/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ -/* GNU General Public License for more details. */ -/* */ -/* You should have received a copy of the GNU General Public License */ -/* along with this program. If not, see . */ -/* */ -/*******************************************************************************/ - -package be.mygod.preference - -import android.content.Context -import android.support.v14.preference.PreferenceDialogFragment -import android.view.{View, ViewGroup} -import android.widget.NumberPicker - -class NumberPickerPreferenceDialogFragment extends PreferenceDialogFragment { - private lazy val preference = getPreference.asInstanceOf[NumberPickerPreference] - private lazy val picker = preference.picker - - override protected def onCreateDialogView(context: Context): NumberPicker = { - val parent = picker.getParent.asInstanceOf[ViewGroup] - if (parent != null) parent.removeView(picker) - picker - } - - override protected def onBindDialogView(view: View) { - super.onBindDialogView(view) - picker.setValue(preference.getValue) - } - - override protected def needInputMethod = true - - def onDialogClosed(positiveResult: Boolean) { - picker.clearFocus() // commit changes - if (positiveResult) { - val value = picker.getValue - if (preference.callChangeListener(value)) preference.setValue(value) - } - } -} diff --git a/plugin/src/main/scala/be/mygod/preference/PreferenceCategory.scala b/plugin/src/main/scala/be/mygod/preference/PreferenceCategory.scala deleted file mode 100644 index 4128010a..00000000 --- a/plugin/src/main/scala/be/mygod/preference/PreferenceCategory.scala +++ /dev/null @@ -1,38 +0,0 @@ -/*******************************************************************************/ -/* */ -/* Copyright (C) 2017 by Max Lv */ -/* Copyright (C) 2017 by Mygod Studio */ -/* */ -/* This program is free software: you can redistribute it and/or modify */ -/* it under the terms of the GNU General Public License as published by */ -/* the Free Software Foundation, either version 3 of the License, or */ -/* (at your option) any later version. */ -/* */ -/* This program is distributed in the hope that it will be useful, */ -/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ -/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ -/* GNU General Public License for more details. */ -/* */ -/* You should have received a copy of the GNU General Public License */ -/* along with this program. If not, see . */ -/* */ -/*******************************************************************************/ - -package be.mygod.preference - -import android.content.Context -import android.support.v7.preference.{PreferenceViewHolder, PreferenceCategory => Base} -import android.util.AttributeSet -import android.view.ViewGroup.MarginLayoutParams - -/** - * Based on: https://github.com/Gericop/Android-Support-Preference-V7-Fix/blob/4c2bb2896895dbedb37b659b36bd2a96b33c1605/preference-v7/src/main/java/com/takisoft/fix/support/v7/preference/PreferenceCategory.java - * - * @author Mygod - */ -class PreferenceCategory(context: Context, attrs: AttributeSet = null) extends Base(context, attrs) { - override def onBindViewHolder(holder: PreferenceViewHolder) { - super.onBindViewHolder(holder) - holder.findViewById(android.R.id.title).getLayoutParams.asInstanceOf[MarginLayoutParams].bottomMargin = 0 - } -} diff --git a/plugin/src/main/scala/be/mygod/preference/PreferenceFragment.scala b/plugin/src/main/scala/be/mygod/preference/PreferenceFragment.scala deleted file mode 100644 index 95139398..00000000 --- a/plugin/src/main/scala/be/mygod/preference/PreferenceFragment.scala +++ /dev/null @@ -1,55 +0,0 @@ -/*******************************************************************************/ -/* */ -/* Copyright (C) 2017 by Max Lv */ -/* Copyright (C) 2017 by Mygod Studio */ -/* */ -/* This program is free software: you can redistribute it and/or modify */ -/* it under the terms of the GNU General Public License as published by */ -/* the Free Software Foundation, either version 3 of the License, or */ -/* (at your option) any later version. */ -/* */ -/* This program is distributed in the hope that it will be useful, */ -/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ -/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ -/* GNU General Public License for more details. */ -/* */ -/* You should have received a copy of the GNU General Public License */ -/* along with this program. If not, see . */ -/* */ -/*******************************************************************************/ - -package be.mygod.preference - -import android.app.DialogFragment -import android.os.Bundle -import android.support.v14.preference.{PreferenceFragment => Base} -import android.support.v7.preference.{Preference, PreferenceScreen} -import android.view.{LayoutInflater, View, ViewGroup} - -abstract class PreferenceFragment extends Base { - override def onCreateView(inflater: LayoutInflater, container: ViewGroup, savedInstanceState: Bundle): View = - super.onCreateView(inflater, container, savedInstanceState) - - protected final def displayPreferenceDialog(key: String, fragment: DialogFragment, other: Bundle = null) { - val bundle = new Bundle(1) - bundle.putString("key", key) - if (other != null) bundle.putAll(other) - fragment.setArguments(bundle) - fragment.setTargetFragment(this, 0) - getFragmentManager.beginTransaction() - .add(fragment, "android.support.v14.preference.PreferenceFragment.DIALOG") - .commitAllowingStateLoss() - } - - override def onDisplayPreferenceDialog(preference: Preference): Unit = preference match { - case dpp: DialogPreferencePlus => displayPreferenceDialog(preference.getKey, dpp.createDialog()) - case _ => super.onDisplayPreferenceDialog(preference) - } - - override protected def onCreateAdapter(screen: PreferenceScreen) = new PreferenceGroupAdapter(screen) - - override def onResume() { - super.onResume() - getListView.scrollBy(0, 0) - } -} diff --git a/plugin/src/main/scala/be/mygod/preference/PreferenceGroupAdapter.scala b/plugin/src/main/scala/be/mygod/preference/PreferenceGroupAdapter.scala deleted file mode 100644 index 8df8b6ef..00000000 --- a/plugin/src/main/scala/be/mygod/preference/PreferenceGroupAdapter.scala +++ /dev/null @@ -1,87 +0,0 @@ -/*******************************************************************************/ -/* */ -/* Copyright (C) 2017 by Max Lv */ -/* Copyright (C) 2017 by Mygod Studio */ -/* */ -/* This program is free software: you can redistribute it and/or modify */ -/* it under the terms of the GNU General Public License as published by */ -/* the Free Software Foundation, either version 3 of the License, or */ -/* (at your option) any later version. */ -/* */ -/* This program is distributed in the hope that it will be useful, */ -/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ -/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ -/* GNU General Public License for more details. */ -/* */ -/* You should have received a copy of the GNU General Public License */ -/* along with this program. If not, see . */ -/* */ -/*******************************************************************************/ - -package be.mygod.preference - -import java.lang.reflect.Field -import java.util - -import android.os.Build -import android.support.v4.content.ContextCompat -import android.support.v4.view.ViewCompat -import android.support.v7.preference.{PreferenceGroup, PreferenceViewHolder, PreferenceGroupAdapter => Old} -import android.view.{LayoutInflater, View, ViewGroup} -import com.github.shadowsocks.plugin.R - -/** - * Fix by: https://github.com/Gericop/Android-Support-Preference-V7-Fix/commit/7de016b007e28a264001a8bb353f110a7f64bb69 - * - * @author Mygod - */ -object PreferenceGroupAdapter { - private var preferenceLayoutsField: Field = _ - private var fieldResId: Field = _ - private var fieldWidgetResId: Field = _ - private val preferenceViewHolderConstructor = classOf[PreferenceViewHolder].getDeclaredConstructor(classOf[View]) - - { - val oldClass = classOf[Old] - preferenceLayoutsField = oldClass.getDeclaredField("mPreferenceLayouts") - preferenceLayoutsField.setAccessible(true) - val c = oldClass.getDeclaredClasses.filter(c => c.getSimpleName == "PreferenceLayout").head - fieldResId = c.getDeclaredField("resId") - fieldResId.setAccessible(true) - fieldWidgetResId = c.getDeclaredField("widgetResId") - fieldWidgetResId.setAccessible(true) - preferenceViewHolderConstructor.setAccessible(true) - } -} - -class PreferenceGroupAdapter(group: PreferenceGroup) extends Old(group) { - import PreferenceGroupAdapter._ - - protected lazy val preferenceLayouts: util.List[AnyRef] = - preferenceLayoutsField.get(this).asInstanceOf[util.List[AnyRef]] - - override def onCreateViewHolder(parent: ViewGroup, viewType: Int): PreferenceViewHolder = - if (Build.VERSION.SDK_INT < 21) { - val context = parent.getContext - val inflater = LayoutInflater.from(context) - val pl = preferenceLayouts.get(viewType) - val view = inflater.inflate(fieldResId.get(pl).asInstanceOf[Int], parent, false) - if (view.getBackground == null) { - val array = context.obtainStyledAttributes(null, R.styleable.BackgroundStyle) - var background = array.getDrawable(R.styleable.BackgroundStyle_android_selectableItemBackground) - if (background == null) - background = ContextCompat.getDrawable(context, android.R.drawable.list_selector_background) - array.recycle() - val (s, t, e, b) = (ViewCompat.getPaddingStart(view), view.getPaddingTop, - ViewCompat.getPaddingEnd(view), view.getPaddingBottom) - view.setBackground(background) - ViewCompat.setPaddingRelative(view, s, t, e, b) - } - val widgetFrame = view.findViewById[ViewGroup](android.R.id.widget_frame) - if (widgetFrame != null) { - val widgetResId = fieldWidgetResId.get(pl).asInstanceOf[Int] - if (widgetResId != 0) inflater.inflate(widgetResId, widgetFrame) else widgetFrame.setVisibility(View.GONE) - } - preferenceViewHolderConstructor.newInstance(view) - } else super.onCreateViewHolder(parent, viewType) -} diff --git a/plugin/src/main/scala/be/mygod/preference/SummaryPreference.scala b/plugin/src/main/scala/be/mygod/preference/SummaryPreference.scala deleted file mode 100755 index e1ba4e62..00000000 --- a/plugin/src/main/scala/be/mygod/preference/SummaryPreference.scala +++ /dev/null @@ -1,45 +0,0 @@ -/*******************************************************************************/ -/* */ -/* Copyright (C) 2017 by Max Lv */ -/* Copyright (C) 2017 by Mygod Studio */ -/* */ -/* This program is free software: you can redistribute it and/or modify */ -/* it under the terms of the GNU General Public License as published by */ -/* the Free Software Foundation, either version 3 of the License, or */ -/* (at your option) any later version. */ -/* */ -/* This program is distributed in the hope that it will be useful, */ -/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ -/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ -/* GNU General Public License for more details. */ -/* */ -/* You should have received a copy of the GNU General Public License */ -/* along with this program. If not, see . */ -/* */ -/*******************************************************************************/ - -package be.mygod.preference - -import android.support.v7.preference.Preference - -/** - * Make your preference support %s in summary. Override getSummaryValue to customize what to put in. - * Based on: - * https://github.com/android/platform_frameworks_base/blob/master/core/java/android/preference/ListPreference.java - * - * @author Mygod - */ -trait SummaryPreference extends Preference { - protected def getSummaryValue: AnyRef - - /** - * Returns the summary of this SummaryPreference. If the summary has a String formatting marker in it - * (i.e. "%s" or "%1$s"), then the current entry value will be substituted in its place. - * - * @return the summary with appropriate string substitution - */ - override def getSummary: String = { - val summary = super.getSummary - if (summary == null) null else String.format(summary.toString, getSummaryValue) - } -} diff --git a/plugin/src/main/scala/com/github/shadowsocks/plugin/OptionsCapableActivity.scala b/plugin/src/main/scala/com/github/shadowsocks/plugin/OptionsCapableActivity.scala index c2cb0f39..829e495d 100644 --- a/plugin/src/main/scala/com/github/shadowsocks/plugin/OptionsCapableActivity.scala +++ b/plugin/src/main/scala/com/github/shadowsocks/plugin/OptionsCapableActivity.scala @@ -1,8 +1,8 @@ package com.github.shadowsocks.plugin -import android.app.Activity import android.content.Intent import android.os.Bundle +import android.support.v7.app.AppCompatActivity import android.widget.Toast /** @@ -10,7 +10,7 @@ import android.widget.Toast * * @author Mygod */ -trait OptionsCapableActivity extends Activity { +trait OptionsCapableActivity extends AppCompatActivity { protected def pluginOptions(intent: Intent = getIntent): PluginOptions = try new PluginOptions(intent.getStringExtra(PluginContract.EXTRA_OPTIONS)) catch { case exc: IllegalArgumentException =>