Remove the no longer needed quick switch
This commit is contained in:
@@ -98,18 +98,6 @@
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<activity android:name=".ShadowsocksQuickSwitchActivity"
|
||||
android:label="@string/quick_switch"
|
||||
android:launchMode="singleInstance"
|
||||
android:excludeFromRecents="true"
|
||||
android:taskAffinity=""
|
||||
android:theme="@style/Theme.Material.Dialog">
|
||||
<intent-filter>
|
||||
<action android:name="com.github.shadowsocks.QUICK_SWITCH" />
|
||||
<category android:name="android.intent.category.DEFAULT"/>
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<activity
|
||||
android:name=".QuickToggleShortcut"
|
||||
android:label="@string/quick_toggle"
|
||||
|
||||
@@ -8,14 +8,6 @@
|
||||
android:targetPackage="com.github.shadowsocks"
|
||||
android:targetClass="com.github.shadowsocks.QuickToggleShortcut" />
|
||||
</shortcut>
|
||||
<shortcut android:shortcutId="switch"
|
||||
android:icon="@drawable/ic_qu_shadowsocks_launcher"
|
||||
android:shortcutShortLabel="@string/quick_switch"
|
||||
android:shortcutLongLabel="@string/quick_switch">
|
||||
<intent android:action="android.intent.action.MAIN"
|
||||
android:targetPackage="com.github.shadowsocks"
|
||||
android:targetClass="com.github.shadowsocks.ShadowsocksQuickSwitchActivity" />
|
||||
</shortcut>
|
||||
<shortcut android:shortcutId="scan"
|
||||
android:icon="@drawable/ic_qu_camera_launcher"
|
||||
android:shortcutShortLabel="@string/add_profile_methods_scan_qr_code"
|
||||
|
||||
@@ -24,13 +24,12 @@ import java.util.Locale
|
||||
|
||||
import android.app.{KeyguardManager, NotificationManager, PendingIntent}
|
||||
import android.content.{BroadcastReceiver, Context, Intent, IntentFilter}
|
||||
import android.os.PowerManager
|
||||
import android.os.{Build, PowerManager}
|
||||
import android.support.v4.app.NotificationCompat
|
||||
import android.support.v4.app.NotificationCompat.BigTextStyle
|
||||
import android.support.v4.content.ContextCompat
|
||||
import com.github.shadowsocks.aidl.IShadowsocksServiceCallback.Stub
|
||||
import com.github.shadowsocks.utils.{TrafficMonitor, Action, State, Utils}
|
||||
import com.github.shadowsocks.ShadowsocksApplication.app
|
||||
import com.github.shadowsocks.utils.{Action, State, TrafficMonitor, Utils}
|
||||
|
||||
/**
|
||||
* @author Mygod
|
||||
@@ -60,14 +59,8 @@ class ShadowsocksNotification(private val service: BaseService, profileName: Str
|
||||
.setContentIntent(PendingIntent.getActivity(service, 0, new Intent(service, classOf[MainActivity])
|
||||
.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT), 0))
|
||||
.setSmallIcon(R.drawable.ic_stat_shadowsocks)
|
||||
builder.addAction(R.drawable.ic_navigation_close,
|
||||
if (Build.VERSION.SDK_INT < 24) builder.addAction(R.drawable.ic_navigation_close,
|
||||
service.getString(R.string.stop), PendingIntent.getBroadcast(service, 0, new Intent(Action.CLOSE), 0))
|
||||
app.profileManager.getAllProfiles match {
|
||||
case Some(profiles) => if (profiles.length > 1)
|
||||
builder.addAction(R.drawable.ic_action_settings, service.getString(R.string.quick_switch),
|
||||
PendingIntent.getActivity(service, 0, new Intent(Action.QUICK_SWITCH), 0))
|
||||
case _ =>
|
||||
}
|
||||
private lazy val style = new BigTextStyle(builder)
|
||||
private var isVisible = true
|
||||
update(if (service.getSystemService(Context.POWER_SERVICE).asInstanceOf[PowerManager].isScreenOn)
|
||||
|
||||
@@ -1,96 +0,0 @@
|
||||
/*******************************************************************************/
|
||||
/* */
|
||||
/* Copyright (C) 2016 by Max Lv <max.c.lv@gmail.com> */
|
||||
/* Copyright (C) 2016 by Mygod Studio <contact-shadowsocks-android@mygod.be> */
|
||||
/* */
|
||||
/* 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 <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/*******************************************************************************/
|
||||
|
||||
package com.github.shadowsocks
|
||||
|
||||
import android.content.pm.ShortcutManager
|
||||
import android.content.res.Resources
|
||||
import android.os.{Build, Bundle}
|
||||
import android.support.v7.app.AppCompatActivity
|
||||
import android.support.v7.widget.{DefaultItemAnimator, LinearLayoutManager, RecyclerView, Toolbar}
|
||||
import android.view.{LayoutInflater, View, ViewGroup}
|
||||
import android.widget.CheckedTextView
|
||||
import com.github.shadowsocks.database.Profile
|
||||
import com.github.shadowsocks.utils.Utils
|
||||
import com.github.shadowsocks.ShadowsocksApplication.app
|
||||
|
||||
/**
|
||||
* Created by Lucas on 3/10/16.
|
||||
*/
|
||||
class ShadowsocksQuickSwitchActivity extends AppCompatActivity {
|
||||
|
||||
private class ProfileViewHolder(val view: View) extends RecyclerView.ViewHolder(view) with View.OnClickListener {
|
||||
{
|
||||
val typedArray = obtainStyledAttributes(Array(android.R.attr.selectableItemBackground))
|
||||
view.setBackgroundResource(typedArray.getResourceId(0, 0))
|
||||
typedArray.recycle()
|
||||
}
|
||||
private var item: Profile = _
|
||||
private val text = itemView.findViewById(android.R.id.text1).asInstanceOf[CheckedTextView]
|
||||
itemView.setOnClickListener(this)
|
||||
|
||||
def bind(item: Profile) {
|
||||
this.item = item
|
||||
text.setText(item.name)
|
||||
text.setChecked(item.id == app.profileId)
|
||||
}
|
||||
|
||||
def onClick(v: View) {
|
||||
app.switchProfile(item.id)
|
||||
Utils.startSsService(ShadowsocksQuickSwitchActivity.this)
|
||||
finish()
|
||||
}
|
||||
}
|
||||
|
||||
private class ProfilesAdapter extends RecyclerView.Adapter[ProfileViewHolder] {
|
||||
val profiles: List[Profile] = app.profileManager.getAllProfiles.getOrElse(List.empty[Profile])
|
||||
|
||||
def getItemCount: Int = profiles.length
|
||||
|
||||
def onBindViewHolder(vh: ProfileViewHolder, i: Int): Unit = i match {
|
||||
case _ => vh.bind(profiles(i))
|
||||
}
|
||||
|
||||
private val name = "select_dialog_singlechoice_" + (if (Build.VERSION.SDK_INT >= 21) "material" else "holo")
|
||||
|
||||
def onCreateViewHolder(vg: ViewGroup, i: Int) = new ProfileViewHolder(LayoutInflater.from(vg.getContext)
|
||||
.inflate(Resources.getSystem.getIdentifier(name, "layout", "android"), vg, false))
|
||||
}
|
||||
|
||||
private val profilesAdapter = new ProfilesAdapter
|
||||
|
||||
override def onCreate(savedInstanceState: Bundle) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.layout_quick_switch)
|
||||
|
||||
val toolbar = findViewById(R.id.toolbar).asInstanceOf[Toolbar]
|
||||
toolbar.setTitle(R.string.quick_switch)
|
||||
|
||||
val profilesList = findViewById(R.id.profilesList).asInstanceOf[RecyclerView]
|
||||
val lm = new LinearLayoutManager(this)
|
||||
profilesList.setLayoutManager(lm)
|
||||
profilesList.setItemAnimator(new DefaultItemAnimator)
|
||||
profilesList.setAdapter(profilesAdapter)
|
||||
if (app.profileId >= 0) lm.scrollToPosition(profilesAdapter.profiles.zipWithIndex.collectFirst {
|
||||
case (profile, i) if profile.id == app.profileId => i
|
||||
}.getOrElse(0))
|
||||
if (Build.VERSION.SDK_INT >= 25) getSystemService(classOf[ShortcutManager]).reportShortcutUsed("switch")
|
||||
}
|
||||
}
|
||||
@@ -173,7 +173,6 @@ object Action {
|
||||
final val CONNECTED = "com.github.shadowsocks.CONNECTED" // TODO
|
||||
final val PROFILE_CHANGED = "com.github.shadowsocks.PROFILE_CHANGED"
|
||||
final val PROFILE_REMOVED = "com.github.shadowsocks.PROFILE_REMOVED"
|
||||
final val QUICK_SWITCH = "com.github.shadowsocks.QUICK_SWITCH"
|
||||
|
||||
final val EXTRA_PROFILE_ID = "com.github.shadowsocks.EXTRA_PROFILE_ID"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user