Attend XDA's Second Annual Developer Conference, XDA:DevCon 2014!
5,743,029 Members 42,412 Now Online
XDA Developers Android and Mobile Development Forum

How to create Custom Button OnClick (CM7.2)

Tip us?
 
zorekh
Old
#1  
Junior Member - OP
Thanks Meter 0
Posts: 3
Join Date: Aug 2013
Location: Puebla, Angelopolis
Smile How to create Custom Button OnClick (CM7.2)

Hello

I share my Mod

Decompile your SystemUI (with Apk Multi Tool or other tool)


Code:
Select Code
Go to smali/android/systemui/statusbar  and open StatusBarService.Smali
and find

Code:
Select Code
.method public settingsButton(Landroid/view/View;)V
    .locals 3
    .parameter "v"

    .prologue
    .line 1717
    invoke-virtual {p1}, Landroid/view/View;->getContext()Landroid/content/Context;

    move-result-object v0

    new-instance v1, Landroid/content/Intent;

    const-string v2, "android.settings.SETTINGS"

    invoke-direct {v1, v2}, Landroid/content/Intent;-><init>(Ljava/lang/String;)V

    const/high16 v2, 0x1000

    invoke-virtual {v1, v2}, Landroid/content/Intent;->setFlags(I)Landroid/content/Intent;

    move-result-object v1

    invoke-virtual {v0, v1}, Landroid/content/Context;->startActivity(Landroid/content/Intent;)V

    invoke-virtual {p0}, Lcom/android/systemui/statusbar/StatusBarService;->animateCollapse()V

    .line 1720
    return-void
.end method
below just copy and paste the code

Code:
Select Code
.method public zorekhcustombutton(Landroid/view/View;)V
    .locals 11
    .parameter "v"

    .prologue
    new-instance v0, Landroid/content/Intent;

    invoke-direct {v0}, Landroid/content/Intent;-><init>()V

    invoke-virtual {p1}, Landroid/view/View;->getTag()Ljava/lang/Object;

    move-result-object v5

    check-cast v5, Ljava/lang/String;

    :try_start_0
    const-string v3, ","

    invoke-virtual {v5, v3}, Ljava/lang/String;->split(Ljava/lang/String;)[Ljava/lang/String;

    move-result-object v6

    const/4 v4, 0x0

    aget-object v4, v6, v4

    const/4 v7, 0x1

    aget-object v7, v6, v7

    invoke-virtual {v0, v4, v7}, Landroid/content/Intent;->setClassName(Ljava/lang/String;Ljava/lang/String;)Landroid/content/Intent;

    const/high16 v2, 0x1000

    invoke-virtual {v0, v2}, Landroid/content/Intent;->setFlags(I)Landroid/content/Intent;

    move-result-object v0

    invoke-virtual {p0, v0}, Landroid/content/Context;->startActivity(Landroid/content/Intent;)V
    :try_end_0
    .catch Ljava/lang/Exception; {:try_start_0 .. :try_end_0} :catch_0

    :goto_0
    const-string v1, "statusbar"

    invoke-virtual {p0, v1}, Landroid/content/Context;->getSystemService(Ljava/lang/String;)Ljava/lang/Object;

    move-result-object v0

    check-cast v0, Landroid/app/StatusBarManager;

    invoke-virtual {v0}, Landroid/app/StatusBarManager;->collapse()V

    return-void

    :catch_0
    move-exception v0

    .local v0, e:Ljava/lang/Exception;
    invoke-virtual {v0}, Ljava/lang/Exception;->printStackTrace()V

    const-string v10, "Error:\n"

    invoke-virtual {v10, v5}, Ljava/lang/String;->concat(Ljava/lang/String;)Ljava/lang/String;

    move-result-object v5

    const/16 v9, 0x7d0

    invoke-static {p0, v5, v9}, Landroid/widget/Toast;->makeText(Landroid/content/Context;Ljava/lang/CharSequence;I)Landroid/widget/Toast;

    move-result-object v8

    invoke-virtual {v8}, Landroid/widget/Toast;->show()V

    goto :goto_0
.end method
use now

Code:
Select Code
android:tag="Package,Activity" to insert the activity to open 

android:onClick="zorekhcustombutton"
Sorry for mi bad english
 
CosmicDan
Old
#2  
CosmicDan's Avatar
Senior Member
Thanks Meter 3802
Posts: 3,970
Join Date: Jun 2009
Location: Central Coast

 
DONATE TO ME
Nice work mate! I was just googling for quick reference to start activity in smali, and this is best result so far. Some suggestions though:

Add to title or subtitle something like "Start Activity from XML tag in Smali"

And maybe some comments in your code like this:

[code]
# v0 is an instance of Intent
# v4 is the packageName, e.g. "com.android.settings"
# v7 is the className, e.g. ".DateTimeSettingsSetupWizard"
invoke-virtual {v0, v4, v7}, Landroid/content/Intent;->setClassName(Ljava/lang/String;Ljava/lang/StringLandroid/content/Intent;
[code]

Cheers!

XtreamerMobile Developer


My GitHub | My Apps on AppBrain


Goodbye Xperia 2011 scene - on to greater things

Current Community Projects:
Turbo Tools - Suspended
TBA...

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


XDA PORTAL POSTS

Slide Dial Replacement Dialer Lets You Make Calls from Anywhere

If you frequently make phone calls, your dialer (aka phone app)is one of the … more

Navigate with Your Samsung Gear 2 Using DMA Navi Watch

Whether you’re travelling to a new destination or exploring some previously … more

Xperia Z1 Stereo Speaker Mod, Cell Phone Unlocking Legal Again! – XDA Developer TV

Cell Phone Unlocking is legal again!! That and much … more