Home | History | Annotate | Download | only in settings
      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.view.View;
     23 import android.widget.ListView;
     24 
     25 import com.android.settings.Settings.TetherSettingsActivity;
     26 
     27 import java.util.List;
     28 
     29 public class CreateShortcut extends LauncherActivity {
     30 
     31     @Override
     32     protected Intent getTargetIntent() {
     33         Intent targetIntent = new Intent(Intent.ACTION_MAIN, null);
     34         targetIntent.addCategory("com.android.settings.SHORTCUT");
     35         targetIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
     36         return targetIntent;
     37     }
     38 
     39     @Override
     40     protected void onListItemClick(ListView l, View v, int position, long id) {
     41         Intent shortcutIntent = intentForPosition(position);
     42         shortcutIntent.setFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
     43         Intent intent = new Intent();
     44         intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
     45                 Intent.ShortcutIconResource.fromContext(this, R.mipmap.ic_launcher_settings));
     46         intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
     47         intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, itemForPosition(position).label);
     48         setResult(RESULT_OK, intent);
     49         finish();
     50     }
     51 
     52     @Override
     53     protected boolean onEvaluateShowIcons() {
     54         return false;
     55     }
     56 
     57     /**
     58      * Perform query on package manager for list items.  The default
     59      * implementation queries for activities.
     60      */
     61     protected List<ResolveInfo> onQueryPackageManager(Intent queryIntent) {
     62         List<ResolveInfo> activities = super.onQueryPackageManager(queryIntent);
     63         if (activities == null) return null;
     64         for (int i = activities.size() - 1; i >= 0; i--) {
     65             ResolveInfo info = activities.get(i);
     66             if (info.activityInfo.name.endsWith(TetherSettingsActivity.class.getSimpleName())) {
     67                 if (!TetherSettings.showInShortcuts(this)) {
     68                     activities.remove(i);
     69                 }
     70             }
     71         }
     72         return activities;
     73     }
     74 }
     75