[Galaxy S II Android Development] remuntada78:
[MOD][Guide]How to change lockscreen clock position in real time

[YOUTUBE]LVXpTsfvXRc[/YOUTUBE]

Before modding do a Nandroid Backup

With this mod you can change lockscreen weather widget position too if activated

Thanks to [MENTION=3065070]Goldie[/MENTION] for his special threadhttp://xdaforums.com/galaxy-s2/development-derivatives/guide-understanding-creating-smali-mods-t2488033

To achieve you need:

SecSettings.apk

framework-res.apk

android.policy.jar

tool for decompile and compile like apktool 1.5.2;

tool for text edit like notepad++:

Start with SecSettings.apk:

Decompile SecSettings.apk ,go in res/xml ,open with text editor display_settings.xml and add the red lines

<CheckBoxPreference android:persistent="false" android:title="@string/display_saving" android:key="power_saving_mode" android:summary="@string/display_saving_mode_summary" />
<CheckBoxPreference android:persistent="false" android:title="@string/notification_pulse_title" android:key="notification_pulse" />
[COLOR="Red"]<PreferenceCategory android:title="@string/lockscreen_options">
<PreferenceScreen android:title="@string/lockscreen_clock_position">
<ListPreference android:entries="@array/lockscreen_clock_position_entries" android:title="@string/lockscreen_clock_position" android:key="clock_position" android:summary="@string/lockscreen_clock_position_summary" android:widgetLayout="@layout/round_more_icon" android:entryValues="@array/lockscreen_clock_position_values" />
</PreferenceScreen>
</PreferenceCategory>[/COLOR]

Go in res/value open with text editor arrays.xml and add at the end the red lines

[COLOR="Red"] <string-array name="lockscreen_clock_position_entries">
<item>At Top-Left</item>
<item>At Center-Left</item>
<item>At Bottom-Left</item>
<item>At Top-Center</item>
<item>At Center-Center</item>
<item>At Top-Right</item>
</string-array>
<string-array name="lockscreen_clock_position_values">
<item>0</item>
<item>1</item>
<item>2</item>
<item>3</item>
<item>4</item>
<item>5</item>
</string-array>[/COLOR]

Go in res/value open with text editor strings.xml and add at the end this lines

<string name="lockscreen_options">Lockscreen Options</string>
<string name="lockscreen_clock_position">Clock Position</string>
<string name="lockscreen_clock_position_summary">Choose the position of the clock</string>

Go in smali\com\android\settings\DisplaySettings.smali file and add the following lines in RED

.field private final mIntentReceiver:Landroid/content/BroadcastReceiver;

.field private mKeyBacklightmode:Landroid/preference/CheckBoxPreference;
[COLOR="Red"]
.field private mLockClockPos:Landroid/preference/ListPreference;
[/COLOR]
field private mMultiWindowModeObserver:Landroid/database/ContentObserver;

.field private mMultiWindowPref:Landroid/preference/CheckBoxPreference;

In the same file find .method public onCreate and add the following lines in RED

iput-object v12, p0, Lcom/android/settings/DisplaySettings;->mFontSizePref:Landroid/preference/ListPreference;

.line 424
iget-object v12, p0, Lcom/android/settings/DisplaySettings;->mFontSizePref:Landroid/preference/ListPreference;

invoke-virtual {v12, p0}, Landroid/preference/ListPreference;->setOnPreferenceChangeListener(Landroid/preference/Preference$OnPreferenceChangeListener;)V
[COLOR="Red"]
const-string v12, "clock_position"

invoke-virtual {p0, v12}, Lcom/android/settings/DisplaySettings;->findPreference(Ljava/lang/CharSequence;)Landroid/preference/Preference;

move-result-object v12

check-cast v12, Landroid/preference/ListPreference;

iput-object v12, p0, Lcom/android/settings/DisplaySettings;->mLockClockPos:Landroid/preference/ListPreference;

const-string v12, "clock_position"

const/4 v13, 0x0

invoke-static {v8, v12, v13}, Landroid/provider/Settings$System;->getInt(Landroid/content/ContentResolver;Ljava/lang/String;I)I

move-result v12

iget-object v13, p0, Lcom/android/settings/DisplaySettings;->mLockClockPos:Landroid/preference/ListPreference;

invoke-static {v12}, Ljava/lang/String;->valueOf(I)Ljava/lang/String;

move-result-object v12

invoke-virtual {v13, v12}, Landroid/preference/ListPreference;->setValue(Ljava/lang/String;)V

iget-object v13, p0, Lcom/android/settings/DisplaySettings;->mLockClockPos:Landroid/preference/ListPreference;

invoke-virtual {v13, p0}, Landroid/preference/SwitchPreferenceScreen;->setOnPreferenceChangeListener(Landroid/preference/Preference$OnPreferenceChangeListener;)V [/COLOR]

.line 426

In the same file find .method public onPreferenceChange then find this code and add the red lines ,in blue line some explanation

const-string v2, "contextualpage_settings"

invoke-virtual {v2, v0}, Ljava/lang/String;->equals(Ljava/lang/Object;)Z

move-result v0

if-eqz v0, [COLOR="Red"]:cond_clockpos[/COLOR] [COLOR="Blue"]change this from cond_2 to cond_clockpos[/COLOR]

.line 1089
check-cast p2, Ljava/lang/Boolean;

invoke-virtual {p2}, Ljava/lang/Boolean;->booleanValue()Z

move-result v0

if-eqz v0, :cond_e

in the same method find this code and add the red lines

.line 1100
const-string v1, "DisplaySettings"

const-string v3, "CONTEXTUALPAGE_SWITCH_CHANGED changed = false"

invoke-static {v1, v3}, Landroid/util/Log;->secD(Ljava/lang/String;Ljava/lang/String;)I

goto :goto_7

:cond_11
move-wide v0, v4

goto/16 :goto_3
[COLOR="Red"]
:cond_clockpos
iget-object v1, p0, Lcom/android/settings/DisplaySettings;->mLockClockPos:Landroid/preference/ListPreference;

if-ne p1, v1, :cond_2

check-cast p2, Ljava/lang/String;

invoke-static {p2}, Ljava/lang/Integer;->valueOf(Ljava/lang/String;)Ljava/lang/Integer;

move-result-object v1

invoke-virtual {v1}, Ljava/lang/Integer;->intValue()I

move-result v0

invoke-virtual {p0}, Lcom/android/settings/DisplaySettings;->getContentResolver()Landroid/content/ContentResolver;

move-result-object v1

const-string v2, "clock_position"

invoke-static {v1, v2, v0}, Landroid/provider/Settings$System;->putInt(Landroid/content/ContentResolver;Ljava/lang/String;I)Z

goto/16 :goto_4 [/COLOR]
.end method

Save all changes and compile SecSettings

framework-res.apk part

Decompile framework-res.apk go in res/layout and open keyguard_circlelock_main.xml file find and change the following line

from this

<FrameLayout android:id="@id/circle_lockscreen_clock" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignParentTop="true" />

to this

<FrameLayout android:id="@id/circle_lockscreen_clock" android:layout_width="fill_parent" android:layout_height="[COLOR="Red"]match_parent[/COLOR]" android:layout_alignParentTop="true" />

save changes then go in res/layout-hdpi and open keyguard_circlelock_clockwidget.xml file and replace whole file with the following lines

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:orientation="vertical" android:id="@id/clock_root" android:paddingTop="4.0dip" android:paddingBottom="6.0dip" android:layout_width="match_parent" android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<view android:gravity="center" android:id="@id/clock_emergency" android:layout_width="fill_parent" android:layout_height="17.0dip" class="com.android.internal.policy.impl.sec.ClockWidget$EmergencyCall">
<TextView android:textSize="12.0dip" android:textColor="#ffebebeb" android:ellipsize="none" android:gravity="center" android:id="@id/clock_emergency_text" android:layout_width="fill_parent" android:layout_height="wrap_content" android:singleLine="true" android:shadowColor="@color/black" android:shadowDx="1.0" android:shadowDy="1.0" android:shadowRadius="0.25" />
</view>
<view android:id="@id/clock_clock" android:layout_width="match_parent" android:layout_height="match_parent" class="com.android.internal.policy.impl.sec.ClockWidget$Clock">
<LinearLayout android:gravity="center" android:orientation="vertical" android:id="@id/clock_time_and_date" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginTop="4.0dip">
<RelativeLayout android:layout_width="wrap_content" android:layout_height="wrap_content">
<LinearLayout android:gravity="center" android:id="@id/clock_time" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true">
<ImageView android:id="@id/zzz_hour01" android:layout_width="wrap_content" android:layout_height="wrap_content" />
<ImageView android:id="@id/zzz_hour02" android:layout_width="wrap_content" android:layout_height="wrap_content" />
<ImageView android:id="@id/zzz_colon01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/keyguard_lockscreen_time_dot" />
<ImageView android:id="@id/zzz_minute01" android:layout_width="wrap_content" android:layout_height="wrap_content" />
<ImageView android:id="@id/zzz_minute02" android:layout_width="wrap_content" android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout android:orientation="vertical" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_toRightOf="@id/clock_time" android:layout_alignBottom="@id/clock_time">
<TextView android:textSize="23.0dip" android:textColor="#fff8f8f8" android:id="@id/zzz_ampm" android:paddingLeft="3.0dip" android:paddingBottom="5.0dip" android:layout_width="wrap_content" android:layout_height="wrap_content" android:shadowColor="#55000000" android:shadowDx="3.0" android:shadowDy="3.0" android:shadowRadius="1.0" />
</LinearLayout>
</RelativeLayout>
<TextView android:textSize="20.0dip" android:textStyle="bold" android:textColor="#fff6f7c9" android:gravity="bottom|center" android:id="@id/zzz_date_month" android:layout_width="wrap_content" android:layout_height="24.0dip" android:layout_marginTop="2.0dip" android:shadowColor="#aa000000" android:shadowDy="2.0" android:shadowRadius="1.0" />
<view android:gravity="center" android:id="@id/clock_charge" android:paddingTop="5.0dip" android:visibility="invisible" android:layout_width="wrap_content" android:layout_height="wrap_content" android:minHeight="24.0dip" class="com.android.internal.policy.impl.sec.ClockWidget$Charge">
<ImageView android:id="@id/clock_charge_icon" android:paddingRight="3.0dip" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/keyguard_lockscreen_ic_charging" />
<ImageView android:id="@id/clock_cmas_icon" android:paddingRight="3.0dip" android:visibility="gone" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/keyguard_lockscreen_ic_cmas" />
<TextView android:textSize="17.0dip" android:textColor="#fff9f9f9" android:ellipsize="marquee" android:gravity="bottom" android:id="@id/clock_charge_text" android:layout_width="wrap_content" android:layout_height="24.0dip" android:singleLine="true" android:shadowColor="#55000000" android:shadowDx="1.0" android:shadowDy="1.0" android:shadowRadius="1.0" />
</view>
<LinearLayout android:gravity="center" android:orientation="horizontal" android:id="@id/dualClock_time_and_date" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginTop="14.0dip">
<LinearLayout android:orientation="vertical" android:id="@id/dual_clock_local" android:layout_width="160.0dip" android:layout_height="wrap_content">
<TextView android:textSize="18.0dip" android:textColor="#ffdcdcdc" android:ellipsize="marquee" android:gravity="bottom" android:id="@id/zzz_local_locale" android:layout_width="fill_parent" android:layout_height="22.0dip" android:singleLine="true" android:shadowColor="#55000000" android:shadowDx="3.0" android:shadowDy="3.0" android:shadowRadius="1.0" />
<LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content">
<ImageView android:id="@id/zzz_local_hour01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginRight="-4.0dip" />
<ImageView android:id="@id/zzz_local_hour02" android:layout_width="wrap_content" android:layout_height="wrap_content" />
<ImageView android:id="@id/zzz_local_colon01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/keyguard_lockscreen_dual_time_dot" />
<ImageView android:id="@id/zzz_local_minute01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginRight="-4.0dip" />
<ImageView android:id="@id/zzz_local_minute02" android:layout_width="wrap_content" android:layout_height="wrap_content" />
<TextView android:textSize="17.0dip" android:textColor="#fff8f8f8" android:ellipsize="none" android:gravity="bottom" android:layout_gravity="bottom" android:id="@id/local_am_pm" android:layout_width="wrap_content" android:layout_height="29.0dip" android:layout_marginBottom="3.0dip" android:singleLine="true" android:shadowColor="#55000000" android:shadowDx="3.0" android:shadowDy="3.0" android:shadowRadius="1.0" />
</LinearLayout>
<TextView android:textSize="20.0dip" android:textColor="#fff6f7c9" android:ellipsize="marquee" android:gravity="bottom" android:id="@id/zzz_local_date_month" android:layout_width="fill_parent" android:layout_height="25.0dip" android:singleLine="true" android:shadowColor="#aa000000" android:shadowDy="2.0" android:shadowRadius="1.0" />
</LinearLayout>
<LinearLayout android:orientation="vertical" android:id="@id/dual_clock_home" android:layout_width="wrap_content" android:layout_height="wrap_content">
<LinearLayout android:gravity="bottom" android:layout_width="fill_parent" android:layout_height="wrap_content">
<ImageView android:paddingBottom="2.0dip" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/keyguard_lockscreen_ic_home" />
<TextView android:textSize="18.0dip" android:textColor="#ffdcdcdc" android:ellipsize="marquee" android:gravity="bottom" android:id="@id/zzz_home_locale" android:layout_width="fill_parent" android:layout_height="22.0dip" android:singleLine="true" android:shadowColor="#55000000" android:shadowDx="3.0" android:shadowDy="3.0" android:shadowRadius="1.0" />
</LinearLayout>
<LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content">
<ImageView android:id="@id/zzz_home_hour01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginRight="-4.0dip" />
<ImageView android:id="@id/zzz_home_hour02" android:layout_width="wrap_content" android:layout_height="wrap_content" />
<ImageView android:id="@id/zzz_home_colon01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/keyguard_lockscreen_dual_time_dot" />
<ImageView android:id="@id/zzz_home_minute01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginRight="-4.0dip" />
<ImageView android:id="@id/zzz_home_minute02" android:layout_width="wrap_content" android:layout_height="wrap_content" />
<TextView android:textSize="17.0dip" android:textColor="#fff8f8f8" android:ellipsize="none" android:gravity="bottom" android:layout_gravity="bottom" android:id="@id/home_am_pm" android:layout_width="wrap_content" android:layout_height="29.0dip" android:layout_marginBottom="3.0dip" android:singleLine="true" android:shadowColor="#55000000" android:shadowDx="3.0" android:shadowDy="3.0" android:shadowRadius="1.0" />
</LinearLayout>
<TextView android:textSize="20.0dip" android:textColor="#fff6f7c9" android:ellipsize="marquee" android:gravity="bottom" android:id="@id/zzz_home_date_month" android:layout_width="fill_parent" android:layout_height="25.0dip" android:singleLine="true" android:shadowColor="#aa000000" android:shadowDy="2.0" android:shadowRadius="1.0" />
</LinearLayout>
</LinearLayout>
<view android:orientation="vertical" android:id="@id/clock_weather" android:paddingTop="8.0dip" android:layout_width="fill_parent" android:layout_height="wrap_content" class="com.android.internal.policy.impl.sec.ClockWidget$Weather">
<TextView android:textSize="16.0dip" android:textColor="#ffebebeb" android:ellipsize="none" android:gravity="center" android:id="@id/clock_weather_no_service" android:padding="15.0dip" android:visibility="gone" android:layout_width="fill_parent" android:layout_height="wrap_content" android:singleLine="true" android:shadowColor="@color/black" android:shadowDx="1.0" android:shadowDy="1.0" android:shadowRadius="1.0" />
<LinearLayout android:gravity="center" android:orientation="vertical" android:id="@id/clock_weather_data_box" android:layout_width="fill_parent" android:layout_height="wrap_content">
<LinearLayout android:gravity="top" android:layout_width="wrap_content" android:layout_height="wrap_content">
<TextView android:textSize="39.0dip" android:typeface="sans" android:textColor="#fff9f9f9" android:gravity="bottom" android:id="@id/clock_weather_temp" android:layout_width="wrap_content" android:layout_height="44.0dip" android:layout_marginTop="3.0dip" android:shadowColor="#55000000" android:shadowDx="3.0" android:shadowDy="3.0" android:shadowRadius="1.0" />
<ImageView android:id="@id/clock_weather_temp_unit" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/keyguard_lockscreen_ic_celsius" />
<ImageView android:id="@id/clock_weather_icon" android:layout_width="83.0dip" android:layout_height="49.0dip" android:scaleType="fitXY" />
</LinearLayout>
<TextView android:textSize="23.0dip" android:textColor="#fff9f9f9" android:ellipsize="marquee" android:gravity="bottom" android:id="@id/clock_weather_city" android:layout_width="wrap_content" android:layout_height="25.0dip" android:singleLine="true" android:shadowColor="#55000000" android:shadowDx="3.0" android:shadowDy="3.0" android:shadowRadius="1.0" android:marqueeRepeatLimit="marquee_forever" />
<ImageView android:id="@id/clock_weather_logo_icon" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/keyguard_lockscreen_ic_weather_logo" />
</LinearLayout>
</view>
</LinearLayout>
</view>
</LinearLayout>

Save all changes and compile framework-res

android.policy.jar part

Decompile android.policy.jar and go in com/android/internal/policy/impl/sec and open ClockWidget$Clock.smali file , find the following method .method protected onFinishInflate()V and add the red lines

.method protected onFinishInflate()V
.registers [COLOR="Red"]7[/COLOR]

.prologue
const/4 v1, 0x1

.line 994
invoke-super {p0}, Landroid/widget/FrameLayout;->onFinishInflate()V

.line 996
const v0, 0x10202ca

invoke-virtual {p0, v0}, Lcom/android/internal/policy/impl/sec/ClockWidget$Clock;->findViewById(I)Landroid/view/View;

move-result-object v0

check-cast v0, Landroid/widget/LinearLayout;
[COLOR="Red"]
iget-object v2, p0, Lcom/android/internal/policy/impl/sec/ClockWidget$Clock;->mContext:Landroid/content/Context;

invoke-virtual {v2}, Landroid/content/Context;->getContentResolver()Landroid/content/ContentResolver;

move-result-object v2

const-string v3, "clock_position"

const/4 v4, 0x0

invoke-static {v2, v3, v4}, Landroid/provider/Settings$System;->getInt(Landroid/content/ContentResolver;Ljava/lang/String;I)I

move-result v2

const v3, 0x1

if-eq v2, v3, :cond_0

const v3, 0x2

if-eq v2, v3, :cond_1

const v3, 0x3

if-eq v2, v3, :cond_2

const v3, 0x4

if-eq v2, v3, :cond_3

const v3, 0x5

if-eq v2, v3, :cond_4

const/16 v4, 0x70

goto:goto_set

:cond_0
const/16 v4, 0x10

goto:goto_set

:cond_1
const/16 v4, 0x50

goto:goto_set

:cond_2
const/16 v4, 0x01

goto:goto_set

:cond_3
const/16 v4, 0x11

goto:goto_set

:cond_4
const/16 v4, 0x05

:goto_set
invoke-virtual {v0, v4}, Landroid/widget/LinearLayout;->setGravity(I)V
[/COLOR]
iput-object v0, p0, Lcom/android/internal/policy/impl/sec/ClockWidget$Clock;->mSingleClock:Landroid/widget/LinearLayout;

.line 997

Save all changes and compile android.policy then put SecSettings.apk , framework-res.apk and android.policy.jar in your device