1 /* 2 * Copyright (C) 2010 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.settings; 18 19 import android.app.LauncherActivity; 20 import android.content.Intent; 21 import android.content.pm.ResolveInfo; 22 import android.os.Bundle; 23 import android.view.View; 24 import android.widget.ListView; 25 26 import com.android.settings.Settings.TetherSettingsActivity; 27 28 import java.util.List; 29 30 public class CreateShortcut extends LauncherActivity { 31 32 @Override 33 protected Intent getTargetIntent() { 34 Intent targetIntent = new Intent(Intent.ACTION_MAIN, null); 35 targetIntent.addCategory("com.android.settings.SHORTCUT"); 36 targetIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 37 return targetIntent; 38 } 39 40 @Override 41 protected void onListItemClick(ListView l, View v, int position, long id) { 42 Intent shortcutIntent = intentForPosition(position); 43 shortcutIntent.setFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); 44 Intent intent = new Intent(); 45 intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, 46 Intent.ShortcutIconResource.fromContext(this, R.mipmap.ic_launcher_settings)); 47 intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent); 48 intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, itemForPosition(position).label); 49 setResult(RESULT_OK, intent); 50 finish(); 51 } 52 53 @Override 54 protected boolean onEvaluateShowIcons() { 55 return false; 56 } 57 58 /** 59 * Perform query on package manager for list items. The default 60 * implementation queries for activities. 61 */ 62 protected List<ResolveInfo> onQueryPackageManager(Intent queryIntent) { 63 List<ResolveInfo> activities = super.onQueryPackageManager(queryIntent); 64 if (activities == null) return null; 65 for (int i = activities.size() - 1; i >= 0; i--) { 66 ResolveInfo info = activities.get(i); 67 if (info.activityInfo.name.endsWith(TetherSettingsActivity.class.getSimpleName())) { 68 if (!TetherSettings.showInShortcuts(this)) { 69 activities.remove(i); 70 } 71 } 72 } 73 return activities; 74 } 75 } 76