Post Reply

[Q] Date format in smali

12th February 2014, 12:35 PM   |  #1  
RBDoMGaM's Avatar
OP Senior Member
Flag Brasília
Thanks Meter: 60
 
119 posts
Join Date:Joined: Aug 2012
More
I trying to edit my date format in smali file to a custom date format like day & month (without year), this is the method code

 
.method private getTimeText()[Ljava/lang/String;
.locals 10

.prologue
const/16 v5, 0xc

const/4 v9, 0x1

.line 110
invoke-static {}, Ljava/util/Calendar;->getInstance()Ljava/util/Calendar;

move-result-object v0

.line 111
.local v0, calendar:Ljava/util/Calendar;
invoke-virtual {v0}, Ljava/util/Calendar;->getTime()Ljava/util/Date;

move-result-object v1

.line 112
.local v1, date:Ljava/util/Date;
invoke-virtual {v0, v5}, Ljava/util/Calendar;->get(I)I

move-result v3

.line 113
.local v3, min:I
const/16 v4, 0xb

invoke-virtual {v0, v4}, Ljava/util/Calendar;->get(I)I

move-result v2

.line 114
.local v2, hour:I
if-le v2, v5, :cond_0

iget-object v4, p0, Lcom/android/systemui/statusbar/StatusBarJellyHeaderView;->context:Landroid/content/Context;

invoke-static {v4}, Landroid/text/format/DateFormat;->is24HourFormat(Landroid/content/ContextZ

move-result v4

if-eq v4, v9, :cond_0

.line 115
add-int/lit8 v2, v2, -0xc

.line 116
:cond_0
const/4 v4, 0x2

new-array v4, v4, [Ljava/lang/String;

const/4 v5, 0x0

new-instance v6, Ljava/lang/StringBuilder;

invoke-direct {v6}, Ljava/lang/StringBuilder;-><init>()V

invoke-virtual {v6, v2}, Ljava/lang/StringBuilder;->append(I)Ljava/lang/StringBuilder;

move-result-object v6

const-string v7, ":"

invoke-virtual {v6, v7}, Ljava/lang/StringBuilder;->append(Ljava/lang/StringLjava/lang/StringBuilder;

move-result-object v6

const/16 v7, 0x9

if-le v3, v7, :cond_1

invoke-static {v3}, Ljava/lang/Integer;->valueOf(I)Ljava/lang/Integer;

move-result-object v7

:goto_0
invoke-virtual {v6, v7}, Ljava/lang/StringBuilder;->append(Ljava/lang/ObjectLjava/lang/StringBuilder;

move-result-object v6

invoke-virtual {v6}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

move-result-object v6

aput-object v6, v4, v5

new-instance v5, Ljava/lang/StringBuilder;

invoke-direct {v5}, Ljava/lang/StringBuilder;-><init>()V

const-string v6, "EEEE"

invoke-static {v6, v1}, Landroid/text/format/DateFormat;->format(Ljava/lang/CharSequence;Ljava/util/DateLjava/lang/CharSequence;

move-result-object v6

invoke-virtual {v5, v6}, Ljava/lang/StringBuilder;->append(Ljava/lang/ObjectLjava/lang/StringBuilder;

move-result-object v5

const-string v6, "\n"

invoke-virtual {v5, v6}, Ljava/lang/StringBuilder;->append(Ljava/lang/StringLjava/lang/StringBuilder;

move-result-object v5

iget-object v6, p0, Lcom/android/systemui/statusbar/StatusBarJellyHeaderView;->context:Landroid/content/Context;

invoke-static {v6}, Landroid/text/format/DateFormat;->getLongDateFormat(Landroid/content/ContextLjava/text/DateFormat;

move-result-object v6

invoke-virtual {v6, v1}, Ljava/text/DateFormat;->format(Ljava/util/DateLjava/lang/String;

move-result-object v6

invoke-virtual {v5, v6}, Ljava/lang/StringBuilder;->append(Ljava/lang/StringLjava/lang/StringBuilder;

move-result-object v5

invoke-virtual {v5}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

move-result-object v5

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

move-result-object v5

aput-object v5, v4, v9

return-object v4

:cond_1
new-instance v7, Ljava/lang/StringBuilder;

invoke-direct {v7}, Ljava/lang/StringBuilder;-><init>()V

const-string v8, "0"

invoke-virtual {v7, v8}, Ljava/lang/StringBuilder;->append(Ljava/lang/StringLjava/lang/StringBuilder;

move-result-object v7

invoke-virtual {v7, v3}, Ljava/lang/StringBuilder;->append(I)Ljava/lang/StringBuilder;

move-result-object v7

invoke-virtual {v7}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

move-result-object v7

goto :goto_0
.end method


I have edited getLongDateFormat to getMediumDateFormat but this is no look good, someone help me to make this customized?
Thanks
Attached Thumbnails
Click image for larger version

Name:	Screenshot-1.png
Views:	14
Size:	9.5 KB
ID:	2575032  
Last edited by RBDoMGaM; 12th February 2014 at 12:38 PM.
Post Reply Subscribe to Thread
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Top Threads in Android Q&A, Help & Troubleshooting by ThreadRank