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

[4.2] [QuickSettings] How to add new toggles to 4.2 Android

OP lithid-cm

14th November 2012, 08:02 PM   |  #1  
lithid-cm's Avatar
OP Recognized Developer
Flag Cleveland
Thanks Meter: 2,969
 
3,177 posts
Join Date:Joined: Jul 2010
More
This is just going to be a quick rundown on what do to add new toggles to android new QuickSettings system. This will take place in SystemUI.

Custom QuickSettings Toggles


Path: frameworks/base/packages/SystemUI
Files:
src/com/android/systemui/statusbar/phone/QuickSettings.java
There are two options when creating a toggle.
addSystemTiles:380 - Static tiles with useful information.
addTemporaryTiles:571 - This type of tile will get removed without activity, for example, the alarm quick setting is a temp tile.

I used SystemTiles
Code:
        // CpuInfo tile
        QuickSettingsTileView cpuInfoTile = (QuickSettingsTileView)
                inflater.inflate(R.layout.quick_settings_tile, parent, false);
        cpuInfoTile.setContent(R.layout.quick_settings_tile_cpuinfo, inflater);
        cpuInfoTile.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startSettingsActivity(Intent.ACTION_POWER_USAGE_SUMMARY);
            }
        });
        mModel.addCpuInfoTile(cpuInfoTile, new QuickSettingsModel.RefreshCallback() {
            @Override
            public void refreshView(QuickSettingsTileView view, State state) {
                ImageView iv = (ImageView) view.findViewById(R.id.cpuinfo_image);
                TextView tva = (TextView) view.findViewById(R.id.cpuinfoa_textview);
                TextView tvb = (TextView) view.findViewById(R.id.cpuinfob_textview);
                Drawable d = mContext.getResources().getDrawable(R.drawable.ic_settings_performance);
		String GOV = fileReadOneLine(GOV_FILE);
		String FREQ = fileReadOneLine(SCALE_CUR_FILE);
                iv.setImageDrawable(d);
                tva.setText(GOV);
                tvb.setText(FREQ);
                view.setContentDescription(
                        mContext.getString(R.string.accessibility_quick_settings_cpuinfo, GOV));
            }
        });
        parent.addView(cpuInfoTile);
src/com/android/systemui/statusbar/phone/QuickSettingsModel.java:174
This is needed for the widget inside the toggle to get updated. You can view other definitions in here to update various states.
Code:
    private QuickSettingsTileView mCpuInfoTile;
    private RefreshCallback mCpuInfoCallback;
    private State mCpuInfoState = new State();
res/layout/quick_settings_tile_cpuinfo.xml
This is where we create the layout of the tile and call it from java.
Code:
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2012 The Android Open Source Project

     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
     You may obtain a copy of the License at

          http://www.apache.org/licenses/LICENSE-2.0

     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     See the License for the specific language governing permissions and
     limitations under the License.
-->
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:orientation="vertical">
    <ImageView
        android:id="@+id/cpuinfo_image"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:paddingBottom="10dp"
        />
    <TextView
        style="@style/TextAppearance.QuickSettings.TileView"
        android:id="@+id/cpuinfoa_textview"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:textColor="#287AA9"
        android:gravity="center"
        />
    <TextView
        style="@style/TextAppearance.QuickSettings.TileView"
        android:id="@+id/cpuinfob_textview"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:textColor="#287AA9"
        android:gravity="center"
        />
</LinearLayout>
res/values/strings.xml
Needed to setContentDescription()
Code:
    <string name="accessibility_quick_settings_cpuinfo">CpuInfo <xliff:g id="meminfo" example="CpuInfo">%s</xliff:g>.</string>
I know this is a very general overview, but the actuality is there is so much that can be done with this, it would be hard to go into extreme detail. Would be better to just simply leave that stuff for questions in this thread.

If you want to know more, please just ask. Lets make android OURS!
The Following 50 Users Say Thank You to lithid-cm For This Useful Post: [ View ]
14th November 2012, 08:11 PM   |  #2  
marty331's Avatar
Senior Member
Dallas, TX
Thanks Meter: 246
 
782 posts
Join Date:Joined: Jun 2011
More
Would root be required to implement this?

Sent from my SGH-I997 using xda premium
14th November 2012, 08:13 PM   |  #3  
lithid-cm's Avatar
OP Recognized Developer
Flag Cleveland
Thanks Meter: 2,969
 
3,177 posts
Join Date:Joined: Jul 2010
More
Quote:
Originally Posted by marty331

Would root be required to implement this?

Sent from my SGH-I997 using xda premium

It would be since you have to push the file back onto the system.
The Following User Says Thank You to lithid-cm For This Useful Post: [ View ]
14th November 2012, 10:57 PM   |  #4  
Ofeliax's Avatar
Senior Member
Thanks Meter: 244
 
315 posts
Join Date:Joined: Aug 2012
Hi , great tutorial:thumbup:
Can you show us the smali version?
Thanks
Last edited by Ofeliax; 15th November 2012 at 12:28 AM.
15th November 2012, 12:37 AM   |  #5  
lithid-cm's Avatar
OP Recognized Developer
Flag Cleveland
Thanks Meter: 2,969
 
3,177 posts
Join Date:Joined: Jul 2010
More
Quote:
Originally Posted by Ofeliax

Hi , great tutorial:thumbup:
Can you show us the smali version?
Thanks

No idea, I have no experience using smali. You can just compile SystemUI from source.
15th November 2012, 04:43 AM   |  #6  
triptosyll's Avatar
Senior Member
Flag Mineral Point
Thanks Meter: 461
 
659 posts
Join Date:Joined: Jan 2012
More
Lithid ur the man. Once I can get this inline kernel building accomplished for aosp for my device, I can compile it. Then I will be playing with this for sure!! I can't wait!
15th November 2012, 04:49 AM   |  #7  
Peteragent5's Avatar
Recognized Contributor
Flag Richmond
Thanks Meter: 1,984
 
1,268 posts
Join Date:Joined: Jan 2012
Donate to Me
More
Quote:
Originally Posted by lithid-cm

It would be since you have to push the file back onto the system.

Or just create a flashable zip. Then flash the new modded app
The Following User Says Thank You to Peteragent5 For This Useful Post: [ View ]
15th November 2012, 04:54 AM   |  #8  
lithid-cm's Avatar
OP Recognized Developer
Flag Cleveland
Thanks Meter: 2,969
 
3,177 posts
Join Date:Joined: Jul 2010
More
Quote:
Originally Posted by Peteragent5

Or just create a flashable zip. Then flash the new modded app

Not really the point of this thread.
The Following 3 Users Say Thank You to lithid-cm For This Useful Post: [ View ]
15th November 2012, 08:40 AM   |  #9  
mDroidd's Avatar
Recognized Contributor
Thanks Meter: 1,385
 
1,833 posts
Join Date:Joined: Aug 2011
Donate to Me
Geest tutorial, this is gonna be my first thing to do when I come back from school lol!



Sent from my Galaxy Nexus using Tapatalk 2
15th November 2012, 09:31 PM   |  #10  
mDroidd's Avatar
Recognized Contributor
Thanks Meter: 1,385
 
1,833 posts
Join Date:Joined: Aug 2011
Donate to Me
How did you decompile your SystemUI?
When I try to do that with mine it's giving an error ..

Sent from my Galaxy Nexus using Tapatalk 2

Post Reply Subscribe to Thread
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes