Attend XDA's Second Annual Developer Conference, XDA:DevCon 2014!
5,742,296 Members 51,859 Now Online
XDA Developers Android and Mobile Development Forum

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

Tip us?
 
lithid-cm
Old
#1  
lithid-cm's Avatar
Recognized Developer - OP
Thanks Meter 2963
Posts: 3,177
Join Date: Jul 2010
Location: Cleveland
Default [4.2] [QuickSettings] How to add new toggles to 4.2 Android

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:
Select 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:
Select 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:
Select 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:
Select 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!

Quote:
Choosy moms choose JIF, the others JFIO
Twitter | Google Plus | Scripts | Github | AOSCompiler

The Following 50 Users Say Thank You to lithid-cm For This Useful Post: [ Click to Expand ]
 
marty331
Old
#2  
marty331's Avatar
Senior Member
Thanks Meter 243
Posts: 781
Join Date: Jun 2011
Location: Dallas, TX
Would root be required to implement this?

Sent from my SGH-I997 using xda premium
Current Devices:
Phone: Nexus 4
ROMs: CM10.1

Device: Nexus 7
ROM: Stock Rooted
CM10

Previous:

Phone: Infuse SGH-I997
ROMs: Infused 2.2
Serendipity VII
CM7
CM9
CM10

Device: Kindle Fire
ROMs: CM7
ICS/CM9
 
lithid-cm
Old
#3  
lithid-cm's Avatar
Recognized Developer - OP
Thanks Meter 2963
Posts: 3,177
Join Date: Jul 2010
Location: Cleveland
Quote:
Originally Posted by marty331 View Post
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.

Quote:
Choosy moms choose JIF, the others JFIO
Twitter | Google Plus | Scripts | Github | AOSCompiler

The Following User Says Thank You to lithid-cm For This Useful Post: [ Click to Expand ]
 
Ofeliax
Old
(Last edited by Ofeliax; 14th November 2012 at 11:28 PM.)
#4  
Ofeliax's Avatar
Senior Member
Thanks Meter 244
Posts: 315
Join Date: Aug 2012
Hi , great tutorial:thumbup:
Can you show us the smali version?
Thanks
 
lithid-cm
Old
#5  
lithid-cm's Avatar
Recognized Developer - OP
Thanks Meter 2963
Posts: 3,177
Join Date: Jul 2010
Location: Cleveland
Quote:
Originally Posted by Ofeliax View Post
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.

Quote:
Choosy moms choose JIF, the others JFIO
Twitter | Google Plus | Scripts | Github | AOSCompiler

 
triptosyll
Old
#6  
triptosyll's Avatar
Senior Member
Thanks Meter 461
Posts: 659
Join Date: Jan 2012
Location: Mineral Point
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!
Bacon in my coffee, please? You don't have any bacon?! Unacceptable!!!
 
Peteragent5
Old
#7  
Peteragent5's Avatar
Recognized Contributor
Thanks Meter 1965
Posts: 1,268
Join Date: Jan 2012
Location: Richmond

 
DONATE TO ME
Quote:
Originally Posted by lithid-cm View Post
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
Away for 2 months.
 

Galaxy Gio GT-S5660M | Galaxy Nexus GT-I9250M | BlackBerry PlayBook
GitHub
The Following User Says Thank You to Peteragent5 For This Useful Post: [ Click to Expand ]
 
lithid-cm
Old
#8  
lithid-cm's Avatar
Recognized Developer - OP
Thanks Meter 2963
Posts: 3,177
Join Date: Jul 2010
Location: Cleveland
Quote:
Originally Posted by Peteragent5 View Post
Or just create a flashable zip. Then flash the new modded app
Not really the point of this thread.

Quote:
Choosy moms choose JIF, the others JFIO
Twitter | Google Plus | Scripts | Github | AOSCompiler

The Following 3 Users Say Thank You to lithid-cm For This Useful Post: [ Click to Expand ]
 
mDroidd
Old
#9  
mDroidd's Avatar
Recognized Contributor
Thanks Meter 1382
Posts: 1,833
Join Date: 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
 
mDroidd
Old
#10  
mDroidd's Avatar
Recognized Contributor
Thanks Meter 1382
Posts: 1,833
Join Date: 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

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes