修复在Android O上创建快捷方式失败的问题;替换默认快捷方式图标
This commit is contained in:
BIN
.idea/caches/build_file_checksums.ser
generated
BIN
.idea/caches/build_file_checksums.ser
generated
Binary file not shown.
@@ -2,8 +2,8 @@ apply plugin: 'com.android.application'
|
|||||||
def AAVersion = '4.3.1'
|
def AAVersion = '4.3.1'
|
||||||
|
|
||||||
android {
|
android {
|
||||||
compileSdkVersion 25
|
compileSdkVersion 27
|
||||||
buildToolsVersion '26.0.2'
|
buildToolsVersion '27.0.3'
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
applicationId "org.autojs.autojs"
|
applicationId "org.autojs.autojs"
|
||||||
minSdkVersion 17
|
minSdkVersion 17
|
||||||
|
|||||||
@@ -1,15 +1,23 @@
|
|||||||
package org.autojs.autojs.external.shortcut;
|
package org.autojs.autojs.external.shortcut;
|
||||||
|
|
||||||
|
import android.app.PendingIntent;
|
||||||
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.content.IntentFilter;
|
||||||
import android.content.pm.ShortcutInfo;
|
import android.content.pm.ShortcutInfo;
|
||||||
import android.graphics.drawable.Icon;
|
import android.graphics.drawable.Icon;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
import android.support.annotation.RequiresApi;
|
import android.support.annotation.RequiresApi;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import io.reactivex.Observable;
|
||||||
|
import io.reactivex.subjects.PublishSubject;
|
||||||
|
import io.reactivex.subjects.Subject;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Stardust on 2017/10/25.
|
* Created by Stardust on 2017/10/25.
|
||||||
*/
|
*/
|
||||||
@@ -17,6 +25,7 @@ import java.util.List;
|
|||||||
@RequiresApi(api = Build.VERSION_CODES.N_MR1)
|
@RequiresApi(api = Build.VERSION_CODES.N_MR1)
|
||||||
public class ShortcutManager {
|
public class ShortcutManager {
|
||||||
|
|
||||||
|
|
||||||
private static ShortcutManager sInstance;
|
private static ShortcutManager sInstance;
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
private android.content.pm.ShortcutManager mShortcutManager;
|
private android.content.pm.ShortcutManager mShortcutManager;
|
||||||
@@ -34,14 +43,35 @@ public class ShortcutManager {
|
|||||||
return sInstance;
|
return sInstance;
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequiresApi(api = Build.VERSION_CODES.N_MR1)
|
|
||||||
public void addDynamicShortcut(CharSequence label, String id, Icon icon, Intent intent) {
|
@RequiresApi(api = Build.VERSION_CODES.O)
|
||||||
ShortcutInfo shortcut = new ShortcutInfo.Builder(mContext, id)
|
public void addPinnedShortcut(CharSequence label, String id, Icon icon, Intent intent) {
|
||||||
|
if (!mShortcutManager.isRequestPinShortcutSupported()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ShortcutInfo shortcut = buildShortcutInfo(label, id, icon, intent);
|
||||||
|
int req = getRequestCode(id);
|
||||||
|
PendingIntent successCallback = PendingIntent.getBroadcast(mContext, req,
|
||||||
|
mShortcutManager.createShortcutResultIntent(shortcut), 0);
|
||||||
|
mShortcutManager.requestPinShortcut(shortcut, successCallback.getIntentSender());
|
||||||
|
}
|
||||||
|
|
||||||
|
private ShortcutInfo buildShortcutInfo(CharSequence label, String id, Icon icon, Intent intent) {
|
||||||
|
return new ShortcutInfo.Builder(mContext, id)
|
||||||
.setIntent(intent)
|
.setIntent(intent)
|
||||||
.setShortLabel(label)
|
.setShortLabel(label)
|
||||||
.setLongLabel(label)
|
.setLongLabel(label)
|
||||||
.setIcon(icon)
|
.setIcon(icon)
|
||||||
.build();
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
private int getRequestCode(String id) {
|
||||||
|
return id.hashCode() >>> 16;
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequiresApi(api = Build.VERSION_CODES.N_MR1)
|
||||||
|
public void addDynamicShortcut(CharSequence label, String id, Icon icon, Intent intent) {
|
||||||
|
ShortcutInfo shortcut = buildShortcutInfo(label, id, icon, intent);
|
||||||
try {
|
try {
|
||||||
addDynamicShortcutUnchecked(shortcut);
|
addDynamicShortcutUnchecked(shortcut);
|
||||||
} catch (IllegalArgumentException shortcutsExceeded) {
|
} catch (IllegalArgumentException shortcutsExceeded) {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package org.autojs.autojs.ui.common;
|
package org.autojs.autojs.ui.common;
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Environment;
|
import android.os.Environment;
|
||||||
@@ -222,6 +223,7 @@ public class ScriptOperations {
|
|||||||
.putExtra(ShortcutCreateActivity.EXTRA_FILE, file));
|
.putExtra(ShortcutCreateActivity.EXTRA_FILE, file));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressLint("CheckResult")
|
||||||
public void delete(final ScriptFile scriptFile) {
|
public void delete(final ScriptFile scriptFile) {
|
||||||
Observable.fromPublisher(new Publisher<Boolean>() {
|
Observable.fromPublisher(new Publisher<Boolean>() {
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package org.autojs.autojs.ui.shortcut;
|
package org.autojs.autojs.ui.shortcut;
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
@@ -86,9 +87,11 @@ public class ShortcutCreateActivity extends AppCompatActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@SuppressLint("NewApi") //for fool android studio
|
||||||
private void createShortcut() {
|
private void createShortcut() {
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1 && mUseAndroidNShortcut.isChecked()) {
|
if ((Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1 && mUseAndroidNShortcut.isChecked())
|
||||||
createShortcutForAndroidN();
|
|| Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
|
createShortcutByShortcutManager();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Shortcut shortcut = new Shortcut(this);
|
Shortcut shortcut = new Shortcut(this);
|
||||||
@@ -105,22 +108,29 @@ public class ShortcutCreateActivity extends AppCompatActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@RequiresApi(api = Build.VERSION_CODES.N_MR1)
|
@RequiresApi(api = Build.VERSION_CODES.N_MR1)
|
||||||
private void createShortcutForAndroidN() {
|
private void createShortcutByShortcutManager() {
|
||||||
Icon icon;
|
Icon icon;
|
||||||
if (mIsDefaultIcon) {
|
if (mIsDefaultIcon) {
|
||||||
icon = Icon.createWithResource(this, R.drawable.ic_node_js_black);
|
icon = Icon.createWithResource(this, R.drawable.ic_file_type_js);
|
||||||
} else {
|
} else {
|
||||||
Bitmap bitmap = BitmapTool.drawableToBitmap(mIcon.getDrawable());
|
Bitmap bitmap = BitmapTool.drawableToBitmap(mIcon.getDrawable());
|
||||||
icon = Icon.createWithBitmap(bitmap);
|
icon = Icon.createWithBitmap(bitmap);
|
||||||
}
|
}
|
||||||
PersistableBundle extras = new PersistableBundle(1);
|
PersistableBundle extras = new PersistableBundle(1);
|
||||||
extras.putString(ScriptIntents.EXTRA_KEY_PATH, mScriptFile.getPath());
|
extras.putString(ScriptIntents.EXTRA_KEY_PATH, mScriptFile.getPath());
|
||||||
ShortcutManager.getInstance(this).addDynamicShortcut(mName.getText(), mScriptFile.getPath(), icon,
|
Intent intent = new Intent(this, ShortcutActivity.class)
|
||||||
new Intent(this, ShortcutActivity.class)
|
|
||||||
.putExtra(ScriptIntents.EXTRA_KEY_PATH, mScriptFile.getPath())
|
.putExtra(ScriptIntents.EXTRA_KEY_PATH, mScriptFile.getPath())
|
||||||
.setAction(Intent.ACTION_MAIN));
|
.setAction(Intent.ACTION_MAIN);
|
||||||
|
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
|
ShortcutManager.getInstance(this).addPinnedShortcut(mName.getText(), mScriptFile.getPath(), icon, intent);
|
||||||
|
} else {
|
||||||
|
ShortcutManager.getInstance(this).addDynamicShortcut(mName.getText(), mScriptFile.getPath(), icon, intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||||
if (resultCode != RESULT_OK) {
|
if (resultCode != RESULT_OK) {
|
||||||
|
|||||||
@@ -2,8 +2,8 @@
|
|||||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:width="128dp"
|
android:width="128dp"
|
||||||
android:height="128dp"
|
android:height="128dp"
|
||||||
android:viewportWidth="128"
|
android:viewportHeight="128"
|
||||||
android:viewportHeight="128">
|
android:viewportWidth="128">
|
||||||
|
|
||||||
<path
|
<path
|
||||||
android:fillColor="#46483E"
|
android:fillColor="#46483E"
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
apply plugin: 'com.android.library'
|
apply plugin: 'com.android.library'
|
||||||
|
|
||||||
android {
|
android {
|
||||||
compileSdkVersion 25
|
compileSdkVersion 27
|
||||||
buildToolsVersion '26.0.2'
|
buildToolsVersion '27.0.3'
|
||||||
|
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
minSdkVersion 17
|
minSdkVersion 17
|
||||||
|
|||||||
@@ -227,16 +227,6 @@ public class ScriptCanvas {
|
|||||||
return mCanvas.clipPath(path);
|
return mCanvas.clipPath(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public boolean clipRegion(Region region, Region.Op op) {
|
|
||||||
return mCanvas.clipRegion(region, op);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public boolean clipRegion(Region region) {
|
|
||||||
return mCanvas.clipRegion(region);
|
|
||||||
}
|
|
||||||
|
|
||||||
public DrawFilter getDrawFilter() {
|
public DrawFilter getDrawFilter() {
|
||||||
return mCanvas.getDrawFilter();
|
return mCanvas.getDrawFilter();
|
||||||
}
|
}
|
||||||
|
|||||||
BIN
autojs/src/main/res/drawable-xhdpi/ic_file_type_js.png
Normal file
BIN
autojs/src/main/res/drawable-xhdpi/ic_file_type_js.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 9.8 KiB |
Reference in New Issue
Block a user