ToqAN Fixes Android 5.0 Notification Bug on Qualcomm Toq

The Qualcomm Toq is probably one of the lesser known smartwatches on the market … more

How to Root and Unlock the Google Nexus 6 on a Mac – XDA TV

In the past, XDA Developer TV Producer droidmodd3rx has shown you how to … more

Set Up Your MediaTek Device with Comprehensive Beginner’s Guide

As can be seen with the use of MediaTek chips in Android One devices … more

Sony Updates AOSP Sources to Android 5.0.1

Just a few days ago, Sony did an utterly fantastic job by pushing out numerous device trees for … more

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

Smile How to create Custom Button OnClick (CM7.2)

OP zorekh

11th March 2014, 04:57 AM   |  #1  
OP Junior Member
Flag Puebla, Angelopolis
Thanks Meter: 0
 
3 posts
Join Date:Joined: Aug 2013
More
Hello

I share my Mod

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


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

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:
.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:
android:tag="Package,Activity" to insert the activity to open 

android:onClick="zorekhcustombutton"
Sorry for mi bad english
9th June 2014, 06:33 AM   |  #2  
CosmicDan's Avatar
Senior Member
Flag Central Coast
Thanks Meter: 3,815
 
3,970 posts
Join Date:Joined: Jun 2009
Donate to Me
More
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!
Post Reply Subscribe to Thread
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes