本帖最后由 Sarkozy 于 2015-1-30 17:48 编辑
看到Sarkozy大大的移花接木系列,感觉不错,接着移花接木的IP来一发。
对象:SuperChm
目的:添加退出对话框到SuperChm
Sarkozy大大写的基本上都是启动系列,这一篇就算是补充一下(高攀一下)
先来张图吧。
点击取消无任何反应,添加确定退出app。
开始介入正题:
引导页,启动时对话框这些事件触发都可以放在onCreate里面来触发。那么退出对话框放在哪里呢,一般情况下app会自己带退出对话框或者自定义的东西。但是SuperChm是没有的,或者说我下的版本是没有的。这个时候就需要自己去创造这个触发事件了。
如果开发过android的人都知道,Android在高版本的sdk里面会有一个onBackPressed函数,那我们就来自己重写这个函数。
根据manifest文件描述
我们找到启动类,那么最后退出的逻辑应该也要写在这里。
首先我们来自己写一个退出用的函数,请允许我在这里卖一个关子。
退出函数如下:
[Java] 纯文本查看 复制代码 .method private exit(Landroid/app/Activity;)V
.locals 4
.param p1, "activity" # Landroid/app/Activity;
.prologue
.line 30
sget v2, Landroid/os/Build$VERSION;->SDK_INT:I
const/16 v3, 0xb
if-lt v2, v3, :cond_0
.line 31
new-instance v0, Landroid/app/AlertDialog$Builder;
const/4 v2, 0x3
invoke-direct {v0, p1, v2}, Landroid/app/AlertDialog$Builder;-><init>(Landroid/content/Context;I)V
.line 35
.local v0, "builder":Landroid/app/AlertDialog$Builder;
:goto_0
const-string v2, "Are you sure exit?"
invoke-virtual {v0, v2}, Landroid/app/AlertDialog$Builder;->setMessage(Ljava/lang/CharSequence;)Landroid/app/AlertDialog$Builder;
.line 37
const-string v2, "Yes"
new-instance v3, Lcom/jrzheng/superchm/Activity/MainActivity$8;
invoke-direct {v3, p0}, Lcom/jrzheng/superchm/Activity/MainActivity$8;-><init>(Lcom/jrzheng/superchm/Activity/MainActivity;)V
invoke-virtual {v0, v2, v3}, Landroid/app/AlertDialog$Builder;->setPositiveButton(Ljava/lang/CharSequence;Landroid/content/DialogInterface$OnClickListener;)Landroid/app/AlertDialog$Builder;
.line 44
const-string v2, "No"
new-instance v3, Lcom/jrzheng/superchm/Activity/MainActivity$9;
invoke-direct {v3, p0}, Lcom/jrzheng/superchm/Activity/MainActivity$9;-><init>(Lcom/jrzheng/superchm/Activity/MainActivity;)V
invoke-virtual {v0, v2, v3}, Landroid/app/AlertDialog$Builder;->setNegativeButton(Ljava/lang/CharSequence;Landroid/content/DialogInterface$OnClickListener;)Landroid/app/AlertDialog$Builder;
.line 50
invoke-virtual {v0}, Landroid/app/AlertDialog$Builder;->create()Landroid/app/AlertDialog;
move-result-object v1
.line 51
.local v1, "dialog":Landroid/app/AlertDialog;
invoke-virtual {v1}, Landroid/app/AlertDialog;->show()V
.line 52
return-void
.line 33
.end local v0 # "builder":Landroid/app/AlertDialog$Builder;
.end local v1 # "dialog":Landroid/app/AlertDialog;
:cond_0
new-instance v0, Landroid/app/AlertDialog$Builder;
invoke-direct {v0, p1}, Landroid/app/AlertDialog$Builder;-><init>(Landroid/content/Context;)V
.restart local v0 # "builder":Landroid/app/AlertDialog$Builder;
goto :goto_0
.end method
以上就是退出函数主体,由于我们在上面写了一个内部类,这样编译出来后会有内部内类的smail文件。我们现在开始添加内部类的smail。原apk的主类逆向出来的时候只有如下内部类
那我们就在后面添加自己的smail。添加后如图所示:
MainActivity$8的代码如下:
[Java] 纯文本查看 复制代码 .class Lcom/jrzheng/superchm/Activity/MainActivity$8;
.super Ljava/lang/Object;
.source "MainActivity.java"
# interfaces
.implements Landroid/content/DialogInterface$OnClickListener;
# annotations
.annotation system Ldalvik/annotation/EnclosingMethod;
value = Lcom/jrzheng/superchm/Activity/MainActivity;->exit(Landroid/app/Activity;)V
.end annotation
.annotation system Ldalvik/annotation/InnerClass;
accessFlags = 0x0
name = null
.end annotation
# instance fields
.field final synthetic this$0:Lcom/jrzheng/superchm/Activity/MainActivity;
# direct methods
.method constructor <init>(Lcom/jrzheng/superchm/Activity/MainActivity;)V
.locals 0
.prologue
.line 1
iput-object p1, p0, Lcom/jrzheng/superchm/Activity/MainActivity$8;->this$0:Lcom/jrzheng/superchm/Activity/MainActivity;
.line 37
invoke-direct {p0}, Ljava/lang/Object;-><init>()V
return-void
.end method
# virtual methods
.method public onClick(Landroid/content/DialogInterface;I)V
.locals 1
.param p1, "dialog" # Landroid/content/DialogInterface;
.param p2, "id" # I
.prologue
.line 40
invoke-interface {p1}, Landroid/content/DialogInterface;->dismiss()V
.line 41
const/4 v0, 0x0
invoke-static {v0}, Ljava/lang/System;->exit(I)V
.line 42
return-void
.end method
MainActivity$9的代码如下:
[AppleScript] 纯文本查看 复制代码 .class Lcom/jrzheng/superchm/Activity/MainActivity$9;
.super Ljava/lang/Object;
.source "MainActivity.java"
# interfaces
.implements Landroid/content/DialogInterface$OnClickListener;
# annotations
.annotation system Ldalvik/annotation/EnclosingMethod;
value = Lcom/jrzheng/superchm/Activity/MainActivity;->exit(Landroid/app/Activity;)V
.end annotation
.annotation system Ldalvik/annotation/InnerClass;
accessFlags = 0x0
name = null
.end annotation
# instance fields
.field final synthetic this$0:Lcom/jrzheng/superchm/Activity/MainActivity;
# direct methods
.method constructor <init>(Lcom/jrzheng/superchm/Activity/MainActivity;)V
.locals 0
.prologue
.line 1
iput-object p1, p0, Lcom/jrzheng/superchm/Activity/MainActivity$9;->this$0:Lcom/jrzheng/superchm/Activity/MainActivity;
.line 44
invoke-direct {p0}, Ljava/lang/Object;-><init>()V
return-void
.end method
# virtual methods
.method public onClick(Landroid/content/DialogInterface;I)V
.locals 0
.param p1, "dialog" # Landroid/content/DialogInterface;
.param p2, "id" # I
.prologue
.line 47
invoke-interface {p1}, Landroid/content/DialogInterface;->dismiss()V
.line 48
return-void
.end method
最后在主类里面重写onBackPressed函数添加exit函数
如此便完成了移花接木之退出对话框的添加。希望大家喜欢。
你的回复是作者们的动力0.0
转载请说明地址:pd521.com
|