# Question: Remapping apps



## RoLa (Jun 12, 2011)

I've harassed everyone I have listed on gtalk to try and get this to work but I'm still coming up short. I'm trying to get the alarm clock to launch by tapping the clock in the notification pane.










I started by plugging up the device and running a log.


```
adb logcat
```
I pull the notification pane down and see this line in the logcat.


```
D/PhoneStatusBar( 598): disable: < expand icons alerts TICKER* system_info back home recent clock >
```
I search the source tree for PhoneStatusBar.java inside SystemUI and added the following code provided by numerous developers.










After I compiled, I tried flashing and the activity "com.android.deskclock.AlarmClock" doesn't launch.

My n00bness sets in and I start over thinking. "Maybe things have to be added to the XML's?"

I open up SystemUI inside source and find res/layout/status_bar_header_expanded.XML and see the following


```
<com.android.systemui.statusbar.policy.Clock<br />
		android:id="@+id/clock"<br />
		android:layout_width="wrap_content"<br />
		android:layout_height="wrap_content"<br />
		android:layout_marginLeft="8dp"<br />
		android:singleLine="true"<br />
		android:textAppearance="@style/TextAppearance.StatusBar.Expanded.Clock"<br />
		/>
```
I add the following two lines to the bottom so now my XML looks like this


```
<com.android.systemui.statusbar.policy.Clock<br />
		android:id="@+id/clock"<br />
		android:layout_width="wrap_content"<br />
		android:layout_height="wrap_content"<br />
		android:layout_marginLeft="8dp"<br />
		android:singleLine="true"<br />
		android:textAppearance="@style/TextAppearance.StatusBar.Expanded.Clock"<br />
		android:contentDescription="@string/alarm_list_title"<br />
		android:clickable="true"<br />
		/>
```
I venture over to values/strings.XML and add the title for Alarms, like this


```
<!-- Title for AlarmClock activity --><br />
	<string name="alarm_list_title">Alarms</string>
```
Compile and yet defeated again. So I try changing

```
android:clickable="true"
```
 to

```
android:onClick="onClick"
```
Nothing is happening here and I'm getting a bit frustrated.

My questions:

Does the code in PhoneStatusBar.java look correct?
Is the code the only thing needed and was modifying the XML's an irrelevant step?
Is the code in the right java file?
Does Clock.java have an important role here because the XML code above has that as the title?

Thanks in advance and thanks to all who have gotten me this far.


----------



## bcrawford (Oct 14, 2011)

I'm still honing my programming skills, but I think I would try to figure out first if the click is being registered. Try adding

Log.d("ClockDebug", "Click registered");

right before the try block in your onClick method. If the click is registering than your problem lies in the launching of the clock app.


----------



## bcrawford (Oct 14, 2011)

I was wondering if [background=rgb(248, 248, 248)]com.android.systemui.statusbar.policy.Clock [/background]can be made clickable. Maybe you can include a transparent imagebutton over the clock display?


----------



## RoLa (Jun 12, 2011)

bcrawford said:


> I'm still honing my programming skills, but I think I would try to figure out first if the click is being registered. Try adding
> 
> Log.d("ClockDebug", "Click registered");
> 
> right before the try block in your onClick method. If the click is registering than your problem lies in the launching of the clock app.


Pardon my ignorance. Where does the try block start? Would it be like this?


```
try Log.d("ClockDebug", "Click registered");<br />
{
```
or like this?


```
Log.d("ClockDebug", "Click registered");try{
```
or niether?

Just so we are on the same page, I'll add this line before the try block, compile, run a log, tap the clock, and I should get an output of what if the click is registering?


----------



## yarly (Jun 22, 2011)

RoLa said:


> Pardon my ignorance. Where does the try block start? Would it be like this?
> 
> 
> ```
> ...


It really does not matter if you put the logging statement within the try block or before it as logging is not going to throw an exception. However, you have to put it after the curly brace and not in between "try" and the curly brace. I would put the Log statement on its own line though as well. Better for readability.

So either one of these will result in the same code execution:


```
try {<br />
Log.d("ClockDebug", "Click registered");<br />
<br />
// more code here....<br />
}<br />
<br />
Log.d("ClockDebug", "Click registered");<br />
try {<br />
<br />
// more code here....<br />
}
```
You can also debug the source with eclipse and put a breakpoint before the try block to have the code execution stop and let you trace through it line by line. I've never used Eclipse for Android, only Intellij, but it's possible to do in either one, just can't explain it to you for Eclipse and Intellij might be beyond you for now.

http://source.android.com/source/using-eclipse.html


----------



## RoLa (Jun 12, 2011)

Thanks for the response yarly. Jrummy got the button to click but I'm having a small problem with the force close.


```
E/AndroidRuntime( 1304): java.lang.IllegalStateException: Could not find a method onClick(View) in the activity class com.android.systemui.SystemUIService for onClick handler on view class com.android.systemui.statusbar.policy.Clock with id 'clock'
```
http://pastebin.com/MSLigjAq

I'm not 100% certain on how to add the method in the activity class. I know where it is supposed to go, (com.android.systemui.SystemUIService) and I have the code, (I think)

```
mStatusBarWindow.findViewById(R.id.clock).setOnClickListener(new OnClickListener(){
```
I'm just not sure how to implement to the java file.


----------



## JBirdVegas (Jun 11, 2011)

Don't put the onClick="MethodName" in the XML do it all in the java. If your on click is firing then add logging within the catch to see if you are calling the activity (clock) correctly.

Java should be straight forward like you have it. Gain a reference to the clock and attach an onclick listener.

When you specify an onClick in the XML then the object inherits that on click when it gets inflated, so when you click it still wants to look for a method called "onClick" not the attached listener you want to launch... if you wanted to call it from the XML then you can but you need to call an onClick method that exists in the java


----------



## RoLa (Jun 12, 2011)

The java that I have looks like this










Are you saying to take the reference I have and add it with the OnClickListener like this?










And then add logging right?? Like this?










And nuke the XML edits?


----------



## JBirdVegas (Jun 11, 2011)

Nuke the XML edits; register your listener just like you are; keep the logging that shows if the activity starts the try; but replace // do nothing with some logging... this way if the activity is not found you at least know your calling the wrong class


----------



## bcrawford (Oct 14, 2011)

RoLa said:


>


This looks pretty decent. Yeah like mentioned above, you can add some logging replacing:

// Do Nothing

with

Log.d("ClockDebug", "Application Not Found);

just to keep it simple for right now. Did you find out if the click is registering yet? Is it the stock clock you are trying to launch?

Here's an interesting link: http://stackoverflow.com/questions/3590955/intent-to-launch-the-clock-application-on-android


----------



## JBirdVegas (Jun 11, 2011)

ok I wanted to link you to this the first time but I wasn't around a computer so I was trying to push you in the right direction but here is how I did it in LiquidSmooth ICS edition:

Object reference:
https://github.com/L...usBar.java#L218
Object initialization and setting of onClick() action
https://github.com/L...usBar.java#L495
onClick() method:
https://github.com/L...sBar.java#L2513

the only required xml is be sure your android:id is set and correctly referenced in the object initialization

*our implementation was to provide two onClick options to the user the default pointed to Android's built in clock's set alarm activity but if the user wanted they could choose to point to google's calendar
**our implementation was on the date object not the clock but the logic is the same

... if that doesn't help I don't think anyone here can help lol


----------



## RoLa (Jun 12, 2011)

Thanks everyone. I really appreciate it.


----------

