Welcome to XDA

Search to go directly to your device's forum

Register an account

Unlock full posting privileges

Ask a question

No registration required
Post Reply

Adding custom apps to an app switcher panel

OP Florent1510

4th February 2014, 09:25 PM   |  #1  
OP Junior Member
Thanks Meter: 0
 
1 posts
Join Date:Joined: Feb 2014
I am currently working on an App Switcher with the ability to also add custom apps in the app switcher. So, I already got the recent apps loader built. This is the code for this part of the app:

Code:
    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();
				 }
			 } 
		  });
	 }
Now I want to let the users define in the app settings up to 3 own apps that should be shown on every moment.

How should I do that?


Thank you
Last edited by Florent1510; 4th February 2014 at 09:31 PM.
Post Reply Subscribe to Thread
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes