将自定义应用添加到应用切换器面板

时间:2014-02-04 20:08:58

标签: android

我目前正在开发一款App Switcher,它还可以在应用切换器中添加自定义应用。所以,我已经建立了最近的应用程序加载器。这是应用程序的这一部分的代码:

public class Corners_RecentApps extends Activity {
 private ArrayList<PanelItemDetail> rowItems = null;
 private ListView listView;
 private ArrayList<String> packageName = null;
 private ArrayList<String> className = null;

 @Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  boolean rightpanel = getSharedPreferences(getPackageName() + "_preferences", Context.MODE_PRIVATE).getBoolean("panelpos_right", true);
  if(rightpanel){
  overridePendingTransition(R.anim.left_slide_in_fast, 0);
  setContentView(R.layout.right_side_panel);
  }
  else
  {
      overridePendingTransition(R.anim.right_slide_in_fast, 0);
      setContentView(R.layout.activity_left_side_panel);
  }
  ImageView imgbtn = (ImageView) findViewById(R.id.transparentbackground);
  ImageView panelbg = (ImageView) findViewById(R.id.panelbackground);
  listView = (ListView)findViewById(R.id.panelcontents);
  packageName = new ArrayList<String>();
  className = new ArrayList<String>();


  ActivityManager am = (ActivityManager) this.getSystemService(ACTIVITY_SERVICE);
  List<ActivityManager.RecentTaskInfo> tasks = am.getRecentTasks(30, 0);
  rowItems = new ArrayList<PanelItemDetail>();
  PackageManager pacMgr = getPackageManager();


  for (ActivityManager.RecentTaskInfo recentTask : tasks) {
   try {
    rowItems.add(new PanelItemDetail(pacMgr.getApplicationIcon(recentTask.origActivity.getPackageName())));
    packageName.add(recentTask.origActivity.getPackageName());
    className.add(recentTask.origActivity.getClassName());

    Log.d("#@#", "getPackageName = " + recentTask.origActivity.getPackageName());
    Log.d("#@#", "getClassName = " + recentTask.origActivity.getClassName());
   } catch (NameNotFoundException e) {
    e.printStackTrace();
   }
  }

  SharedPreferences myPreference = PreferenceManager.getDefaultSharedPreferences(this);
  String itembg = myPreference.getString("itembg_list", "");

  if(itembg.equals("defaults"))
  {
  PanelArrayAdapter adapter = new PanelArrayAdapter(this,R.layout.panelrow_default, rowItems);
  listView.setAdapter(adapter);
  }
  else if(itembg.equals("dark"))
  {
  PanelArrayAdapter adapter = new PanelArrayAdapter(this,R.layout.panelrow_dark, rowItems);
  listView.setAdapter(adapter);
  }
  else if(itembg.equals("light"))
  {
  PanelArrayAdapter adapter = new PanelArrayAdapter(this,R.layout.panelrow_light, rowItems);
  listView.setAdapter(adapter);
  }
  else
  {
  PanelArrayAdapter adapter = new PanelArrayAdapter(this,R.layout.panelrow_none, rowItems);
  listView.setAdapter(adapter);
  }
  listView.setOnItemClickListener(new OnItemClickListener() {
   @Override
public void onItemClick(AdapterView<?> parent, View view, int postion, long id) {
   try{
       boolean rightpanel = getSharedPreferences(getPackageName() + "_preferences", Context.MODE_PRIVATE).getBoolean("panelpos_right", true);

       Intent taskintent = getPackageManager().getLaunchIntentForPackage(packageName.get(postion).toString());
       startActivity(taskintent);


       if(rightpanel){
       overridePendingTransition(R.anim.right_slide_in, R.anim.zoom_out);
       }
       else
       {
           overridePendingTransition(R.anim.left_slide_in, R.anim.zoom_out);
       }
       finish();
   }

   catch (NullPointerException fail) {
       Toast.makeText(getApplicationContext(), "!", Toast.LENGTH_SHORT).show();
}

   } 
  });
  SharedPreferences panelbgpref = PreferenceManager.getDefaultSharedPreferences(this);
  String panelbgset = panelbgpref.getString("panelbg_list", "");

  if(panelbgset.equals("light"))
  {
      panelbg.setImageResource(R.drawable.panelbg_light);
  }
  else
  {
      panelbg.setImageResource(R.drawable.panelbg);
  }

  imgbtn.setOnClickListener(new View.OnClickListener(){
         @Override
        public void onClick(View v) {
             if(v.getId() ==R.id.transparentbackground){
                 moveTaskToBack(true);
                    finish();
             }
         } 
      });
 }

现在我想让用户在应用设置中定义最多3个应该在每个时刻显示的应用。

我该怎么做?

谢谢:)

0 个答案:

没有答案