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

Search This thread

lithid-cm

Inactive Recognized Developer
Jul 1, 2010
3,189
2,956
Cleveland
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
NTlkx.png


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!​
 

Ofeliax

Senior Member
Aug 13, 2012
319
250
Hi , great tutorial:thumbup:
Can you show us the smali version?
Thanks
 
Last edited:

triptosyll

Senior Member
Jan 7, 2012
659
459
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!
 

mg2195

Senior Member
Dec 5, 2011
2,983
2,572
29
RSM
Will this work with CM10 4.1.2?


No, 4.2 only, as stated by OP

Sent from my Galaxy Nexus using Tapatalk 2

I'd assume he process would be very similar as cm is based off aosp...

Anyways I'm currently downloading the 4.2 aosp, gonna be making (trying) my own rom and will definitely be using this guide in the near future after Im sure I can get everything built. Thanks for the guide, if I'm successfully with what I plan to do, you will definitely be linked and credited.

Sent from my SGH-I997 using Tapatalk 2
 
  • Like
Reactions: GoSooners345

lithid-cm

Inactive Recognized Developer
Jul 1, 2010
3,189
2,956
Cleveland
I'd assume he process would be very similar as cm is based off aosp...

Anyways I'm currently downloading the 4.2 aosp, gonna be making (trying) my own rom and will definitely be using this guide in the near future after Im sure I can get everything built. Thanks for the guide, if I'm successfully with what I plan to do, you will definitely be linked and credited.

Sent from my SGH-I997 using Tapatalk 2
I was thinking about putting myself in front of a rom recently. If you are at all interested in teaming up for a rom project, PM. You seem legit and wouldn't mind it one bit.
 

Roladriz

Senior Member
Apr 5, 2010
112
33
This is badass!! Thank you so much lithid!!!!

EDIT: Question, What are the numbers representing?

addSystemTiles:380
addTemporaryTiles:571

I assumed they were line numbers but when I checked source it didn't look like anything was referring to addSystemTiles or addTemporaryTiles on those line numbers.

screenshot2au.png
 
Last edited:
  • Like
Reactions: lithid-cm

lithid-cm

Inactive Recognized Developer
Jul 1, 2010
3,189
2,956
Cleveland
I might have to revisit that, those line numbers are from my file, which is already been edited.

Sent from my Galaxy Nexus using xda premium
 

Top Liked Posts

  • There are no posts matching your filters.
  • 49
    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
    NTlkx.png


    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!​
    5
    I'd assume he process would be very similar as cm is based off aosp...

    Anyways I'm currently downloading the 4.2 aosp, gonna be making (trying) my own rom and will definitely be using this guide in the near future after Im sure I can get everything built. Thanks for the guide, if I'm successfully with what I plan to do, you will definitely be linked and credited.

    Sent from my SGH-I997 using Tapatalk 2
    I was thinking about putting myself in front of a rom recently. If you are at all interested in teaming up for a rom project, PM. You seem legit and wouldn't mind it one bit.
    4
    Great tut man... Thanks!!! :good:

    How do I get sources?

    This is the best part of learning android IMO.

    First, you can't build android in windows unless you want to do it in a VM. I have never done that. I partitioned a hard drive when I was beginning and soon realized that wasn't enough so I have a dedicated 1TB hard drive for Linux. You can build on mac but I've never done that either. Here are few links to get you headed in the right direction.


    http://source.android.com/source/initializing.html

    http://wiki.cyanogenmod.org/wiki/Galaxy_Nexus_(GSM):_Compile_CyanogenMod_(Linux)

    http://www.paranoid-rom.com/forum/guides-references/203-tut-how-to-compile-paranoidandroid-from-sauces

    EDIT: after linking you, I glanced at your thanks meter then googled you lol. Not sure if you are serious or not now. :)
    3
    Or just create a flashable zip. Then flash the new modded app
    Not really the point of this thread.
    1
    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.