# Need Java help on developing new android settings UI



## rgocal (Sep 13, 2012)

Names Ryan and I'm a rom developer over at phandroid and I'm currently developing a rom for the Droid Razr called Bionx Nx.
Anyways I started developing a new ui I want to use for the Android Settings. I have the usual like a cpu controller settings, beats audio settings, spare parts, launcher manager, ect. and thats all stored in a small toolbox that acts like spare parts but Instead of adding those activities in the android settings like everyone else usually does, I wanted to go beyond that and create a small application to view these settings in the Pager UI format.

Right now, this is what I have started. When I debug the application on my razr, the application starts up and shows me the pager ui starting at the first column. I have the columns named like About, Settings, Preferences, Tools. With each swipe to a different page, I want the settings or options to be viewed by the user so If you slide to the Settings column, All the Android Settings would appear as options. (Yes ik i would have to add in the activities from the com.android.settings as targets in a xml) however, here is my delima i need a developer or java expert to help me with.
I would like each page to be linked to a xml dedicated to each page or tab so I can add what I want to appear but IDK how to do so. I dont have good java skills and Iv been reading and reading and just cant get it.










so for instance, above, settings is selected. I have an xml written and labled as settings.xml. I would like that xml to appear and the options I add to appear and be selectable as well. so, really when you swiped over to the settings tab, it would almost be like if you did select your android settings.

Can anyone help me on this? I would very much appreciate it and I will toss you the code I have if it helps. I will donate to whom ever helps me.
You can reach me at [email protected] for questioning.


----------



## JBirdVegas (Jun 11, 2011)

I'm happy to help you here but there is no need for this to be private.

there is an example on using the ViewPager on the Android Developers site.

Each page will be a fragment, and you need to inflate the xml in the java.

something like this should work:

```
<br />
ViewGroup mRootViewGroup;<br />
Button mButton;<br />
<br />
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {<br />
	mRootViewGroup = (ViewGroup) inflater.inflate(R.layout.fragment_my_sweet_fragment, null);<br />
	// initialize object references here by calling them against the ViewGroup ie.<br />
	mButton = (Button) mRootViewGroup.findViewById(R.id.my_sweet_button);<br />
	return mRootViewGroup;<br />
}
```
note: you should remember to manage the Android App Life Cycle in each fragment.

if that doesn't help you need to post some code so we can help you find the error.


----------



## rgocal (Sep 13, 2012)

Ok so i was reading the right subject. Il see if this helps me if not i grab the code.


----------



## rgocal (Sep 13, 2012)

I thought I nailed this but never got it 0.0 Been indulged in other projects. Anyways, I redid the app with source I found and I believe the new layout is better built for my needs in this app. I am aware i have to inflate an xml in each page but confused on how todo this method. My goal is to build a toolkit similar to the MIUI toolkit but universal for all aosp builds. so, heres what i got sofar.

/res/layout/
-farleft
-farright
-left
-main
-middle
-middle

farleft = settings
left = preference
middle = tools
right = advance
farright = about

farleft.xml

```
<br />
<?xml version="1.0" encoding="utf-8"?><br />
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"<br />
	style="@style/Theme.holo"<br />
	android:layout_width="fill_parent"<br />
	android:layout_height="fill_parent"<br />
	android:orientation="vertical" ><br />
	<TextView<br />
		android:layout_width="fill_parent"<br />
		android:layout_height="wrap_content"<br />
		android:background="@drawable/ab_transparent_holo"<br />
		android:gravity="center"<br />
		android:text="@string/farleft_text" /><br />
</LinearLayout><br />
```
main is the layout xml called when activity is started.
main.xml

```
<br />
<?xml version="1.0" encoding="utf-8"?><br />
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"<br />
	android:layout_width="fill_parent"<br />
	android:layout_height="fill_parent"<br />
	android:orientation="vertical" ><br />
	<android.support.v4.view.ViewPager<br />
		android:id="@+id/myfivepanelpager"<br />
		style="@style/Theme.holo"<br />
		android:layout_width="match_parent"<br />
		android:layout_height="24dp"<br />
		android:layout_weight="0.11" ><br />
	</android.support.v4.view.ViewPager><br />
</LinearLayout><br />
```
on each page, id like a preference page or header page to be displayed. A xml that I can manually change upon building and decompiling via apktool so I can add more tools as I build or new preference screens.
In the advance page, id like to make a cpu controller page but thats on my own time. Like the miui toolkit.

NavigatorActivity.java

```
<br />
package com.Biotic.navigator;<br />
import android.app.Activity;<br />
import android.content.Context;<br />
import android.os.Bundle;<br />
import android.os.Parcelable;<br />
import android.support.v4.view.PagerAdapter;<br />
import android.support.v4.view.ViewPager;<br />
import android.view.LayoutInflater;<br />
import android.view.View;<br />
public class NavigatorActivity extends Activity {<br />
		/** Called when the activity is first created. */<br />
		@Override<br />
		public void onCreate(Bundle savedInstanceState) {<br />
				super.onCreate(savedInstanceState);<br />
				setContentView(R.layout.main);<br />
			  <br />
				MyPagerAdapter adapter = new MyPagerAdapter();<br />
				ViewPager myPager = (ViewPager) findViewById(R.id.myfivepanelpager);<br />
				myPager.setAdapter(adapter);<br />
				myPager.setCurrentItem(0);<br />
		}<br />
		private class MyPagerAdapter extends PagerAdapter {<br />
				public int getCount() {<br />
						return 5;<br />
				}<br />
				public Object instantiateItem(View collection, int position) {<br />
						LayoutInflater inflater = (LayoutInflater) collection.getContext()<br />
										.getSystemService(Context.LAYOUT_INFLATER_SERVICE);<br />
						int resId = 0;<br />
						switch (position) {<br />
						case 0:<br />
								resId = R.layout.farleft;<br />
								break;<br />
						case 1:<br />
								resId = R.layout.left;<br />
								break;<br />
						case 2:<br />
								resId = R.layout.middle;<br />
								break;<br />
						case 3:<br />
								resId = R.layout.right;<br />
								break;<br />
						case 4:<br />
								resId = R.layout.farright;<br />
								break;<br />
						}<br />
						View view = inflater.inflate(resId, null);<br />
						((ViewPager) collection).addView(view, 0);<br />
						return view;<br />
				}<br />
				@Override<br />
				public void destroyItem(View arg0, int arg1, Object arg2) {<br />
						((ViewPager) arg0).removeView((View) arg2);<br />
				}<br />
				@Override<br />
				public void finishUpdate(View arg0) {<br />
						// TODO Auto-generated method stub<br />
				}<br />
				@Override<br />
				public boolean isViewFromObject(View arg0, Object arg1) {<br />
						return arg0 == ((View) arg1);<br />
				}<br />
				@Override<br />
				public void restoreState(Parcelable arg0, ClassLoader arg1) {<br />
						// TODO Auto-generated method stub<br />
				}<br />
				@Override<br />
				public Parcelable saveState() {<br />
						// TODO Auto-generated method stub<br />
						return null;<br />
				}<br />
				@Override<br />
				public void startUpdate(View arg0) {<br />
						// TODO Auto-generated method stub<br />
				}<br />
		}<br />
}<br />
```
Anyone willing to help me would be awesome.

Again, this app is more or less a layout than anything but "referencing" users to activities withen the rom but giving them a new UI to manage their rom instead of the android settings.


----------

