Handle share intent in ProfileManagerActivity
This commit is contained in:
@@ -47,11 +47,21 @@
|
||||
</activity>
|
||||
|
||||
<activity
|
||||
android:name=".ParserActivity"
|
||||
android:theme="@style/PopupTheme"
|
||||
android:excludeFromRecents="true"
|
||||
android:taskAffinity=""
|
||||
android:name=".ShadowsocksRunnerActivity"
|
||||
android:theme="@android:style/Theme.NoDisplay"
|
||||
android:launchMode="singleTask">
|
||||
</activity>
|
||||
|
||||
<activity
|
||||
android:name=".ProfileManagerActivity"
|
||||
android:label="@string/profiles"
|
||||
android:parentActivityName=".Shadowsocks"
|
||||
android:excludeFromRecents="true"
|
||||
android:launchMode="singleTask">
|
||||
<intent-filter>
|
||||
<action android:name="com.github.shadowsocks.ProfileManagerActivity"/>
|
||||
<category android:name="android.intent.category.DEFAULT"/>
|
||||
</intent-filter>
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.VIEW"/>
|
||||
<category android:name="android.intent.category.DEFAULT"/>
|
||||
@@ -65,24 +75,6 @@
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<activity
|
||||
android:name=".ShadowsocksRunnerActivity"
|
||||
android:theme="@android:style/Theme.NoDisplay"
|
||||
android:launchMode="singleTask">
|
||||
</activity>
|
||||
|
||||
<activity
|
||||
android:name=".ProfileManagerActivity"
|
||||
android:label="@string/profiles"
|
||||
android:parentActivityName=".Shadowsocks"
|
||||
android:exported="false"
|
||||
android:launchMode="singleTask">
|
||||
<intent-filter>
|
||||
<action android:name="com.github.shadowsocks.ProfileManagerActivity"/>
|
||||
<category android:name="android.intent.category.DEFAULT"/>
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<activity
|
||||
android:name=".AppManager"
|
||||
android:label="@string/proxied_apps"
|
||||
|
||||
@@ -1,104 +0,0 @@
|
||||
/*
|
||||
* Shadowsocks - A shadowsocks client for Android
|
||||
* Copyright (C) 2014 <max.c.lv@gmail.com>
|
||||
*
|
||||
* 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/>.
|
||||
*
|
||||
*
|
||||
* ___====-_ _-====___
|
||||
* _--^^^#####// \\#####^^^--_
|
||||
* _-^##########// ( ) \\##########^-_
|
||||
* -############// |\^^/| \\############-
|
||||
* _/############// (@::@) \\############\_
|
||||
* /#############(( \\// ))#############\
|
||||
* -###############\\ (oo) //###############-
|
||||
* -#################\\ / VV \ //#################-
|
||||
* -###################\\/ \//###################-
|
||||
* _#/|##########/\######( /\ )######/\##########|\#_
|
||||
* |/ |#/\#/\#/\/ \#/\##\ | | /##/\#/ \/\#/\#/\#| \|
|
||||
* ` |/ V V ` V \#\| | | |/#/ V ' V V \| '
|
||||
* ` ` ` ` / | | | | \ ' ' ' '
|
||||
* ( | | | | )
|
||||
* __\ | | | | /__
|
||||
* (vvv(VVV)(VVV)vvv)
|
||||
*
|
||||
* HERE BE DRAGONS
|
||||
*
|
||||
*/
|
||||
|
||||
package com.github.shadowsocks
|
||||
|
||||
import android.content.{DialogInterface, Intent}
|
||||
import android.graphics.Color
|
||||
import android.graphics.drawable.ColorDrawable
|
||||
import android.nfc.{NdefMessage, NfcAdapter}
|
||||
import android.os.Bundle
|
||||
import android.support.v7.app.{AlertDialog, AppCompatActivity}
|
||||
import android.text.TextUtils
|
||||
import android.view.WindowManager
|
||||
import com.github.shadowsocks.utils.Parser
|
||||
|
||||
class ParserActivity extends AppCompatActivity {
|
||||
|
||||
override def onCreate(savedInstanceState: Bundle) {
|
||||
super.onCreate(savedInstanceState)
|
||||
handledSharedIntent()
|
||||
}
|
||||
|
||||
override def onNewIntent(intent: Intent) {
|
||||
super.onNewIntent(intent)
|
||||
setIntent(intent)
|
||||
handledSharedIntent()
|
||||
}
|
||||
|
||||
def handledSharedIntent() {
|
||||
val intent = getIntent()
|
||||
val sharedStr = intent.getAction match {
|
||||
case Intent.ACTION_VIEW => intent.getData.toString
|
||||
case NfcAdapter.ACTION_NDEF_DISCOVERED =>
|
||||
val rawMsgs = intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES)
|
||||
if (rawMsgs != null && rawMsgs.nonEmpty)
|
||||
new String(rawMsgs(0).asInstanceOf[NdefMessage].getRecords()(0).getPayload)
|
||||
else null
|
||||
case _ => null
|
||||
}
|
||||
if (TextUtils.isEmpty(sharedStr)) return
|
||||
val profiles = Parser.findAll(sharedStr).toList
|
||||
if (profiles.isEmpty) {
|
||||
finish()
|
||||
return
|
||||
}
|
||||
showAsPopup()
|
||||
val dialog = new AlertDialog.Builder(this)
|
||||
.setTitle(R.string.add_profile_dialog)
|
||||
.setCancelable(false)
|
||||
.setPositiveButton(android.R.string.yes, ((_, _) =>
|
||||
profiles.foreach(ShadowsocksApplication.profileManager.createProfile)): DialogInterface.OnClickListener)
|
||||
.setNegativeButton(android.R.string.no, null)
|
||||
.setMessage(profiles.mkString("\n"))
|
||||
.create()
|
||||
dialog.setOnDismissListener((_: DialogInterface) => finish()) // builder method was added in API 17
|
||||
dialog.show()
|
||||
}
|
||||
|
||||
def showAsPopup() {
|
||||
val window = getWindow
|
||||
window.setFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND, WindowManager.LayoutParams.FLAG_DIM_BEHIND)
|
||||
val params = window.getAttributes
|
||||
params.alpha = 1.0f
|
||||
params.dimAmount = 0.5f
|
||||
window.setAttributes(params.asInstanceOf[android.view.WindowManager.LayoutParams])
|
||||
window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT))
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import android.nfc.NfcAdapter.CreateNdefMessageCallback
|
||||
import android.nfc.{NdefMessage, NdefRecord, NfcAdapter, NfcEvent}
|
||||
import android.os.{Build, Bundle, Handler}
|
||||
import android.provider.Settings
|
||||
import android.support.v4.app.{NavUtils, TaskStackBuilder}
|
||||
import android.support.v7.app.{AlertDialog, AppCompatActivity}
|
||||
import android.support.v7.widget.RecyclerView.ViewHolder
|
||||
import android.support.v7.widget.Toolbar.OnMenuItemClickListener
|
||||
@@ -113,6 +114,9 @@ class ProfileManagerActivity extends AppCompatActivity with OnMenuItemClickListe
|
||||
def onClick(v: View) = {
|
||||
ShadowsocksApplication.switchProfile(item.id)
|
||||
finish
|
||||
if (isLauncherFromShareIntent){
|
||||
TaskStackBuilder.create(ProfileManagerActivity.this).addNextIntentWithParentStack(NavUtils.getParentActivityIntent(ProfileManagerActivity.this)).startActivities()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -181,6 +185,8 @@ class ProfileManagerActivity extends AppCompatActivity with OnMenuItemClickListe
|
||||
private var nfcEnable = false
|
||||
private var nfcBeamEnable = false
|
||||
|
||||
private var isLauncherFromShareIntent = false
|
||||
|
||||
override def onCreate(savedInstanceState: Bundle) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.layout_profiles)
|
||||
@@ -234,6 +240,17 @@ class ProfileManagerActivity extends AppCompatActivity with OnMenuItemClickListe
|
||||
|
||||
override def onResume() {
|
||||
super.onResume()
|
||||
isLauncherFromShareIntent = false
|
||||
handledShareIntent()
|
||||
updateNFCState()
|
||||
}
|
||||
|
||||
override def onNewIntent(intent: Intent): Unit ={
|
||||
super.onNewIntent(intent)
|
||||
setIntent(intent)
|
||||
}
|
||||
|
||||
def updateNFCState(): Unit = {
|
||||
nfcAdapter = NfcAdapter.getDefaultAdapter(this)
|
||||
if (nfcAdapter != null){
|
||||
nfcAvailable = true
|
||||
@@ -256,6 +273,34 @@ class ProfileManagerActivity extends AppCompatActivity with OnMenuItemClickListe
|
||||
}
|
||||
}
|
||||
|
||||
def handledShareIntent() {
|
||||
val intent = getIntent()
|
||||
val sharedStr = intent.getAction match {
|
||||
case Intent.ACTION_VIEW => intent.getData.toString
|
||||
case NfcAdapter.ACTION_NDEF_DISCOVERED =>
|
||||
val rawMsgs = intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES)
|
||||
if (rawMsgs != null && rawMsgs.nonEmpty)
|
||||
new String(rawMsgs(0).asInstanceOf[NdefMessage].getRecords()(0).getPayload)
|
||||
else null
|
||||
case _ => null
|
||||
}
|
||||
if (TextUtils.isEmpty(sharedStr)) return
|
||||
val profiles = Parser.findAll(sharedStr).toList
|
||||
if (profiles.isEmpty) {
|
||||
finish()
|
||||
return
|
||||
}
|
||||
val dialog = new AlertDialog.Builder(this)
|
||||
.setTitle(R.string.add_profile_dialog)
|
||||
.setPositiveButton(android.R.string.yes, ((_, _) =>
|
||||
profiles.foreach(ShadowsocksApplication.profileManager.createProfile)): DialogInterface.OnClickListener)
|
||||
.setNegativeButton(android.R.string.no, ((_, _) => finish()): DialogInterface.OnClickListener)
|
||||
.setMessage(profiles.mkString("\n"))
|
||||
.create()
|
||||
dialog.show()
|
||||
isLauncherFromShareIntent = true
|
||||
}
|
||||
|
||||
override def onStart() {
|
||||
super.onStart()
|
||||
registerCallback
|
||||
|
||||
Reference in New Issue
Block a user