yashsingh1/xdaforums huggingface dataset:
[Java for Android App Development] MaartenXDA:
[MENTION=3283046]xcesco89[/MENTION] or mikrosmile, do you know why this code doesn't work?

The appdrawer one works fine and changes when I select a new value, but somehow the panels one just doesn't do anything. What can I do?

@Override
public boolean onPreferenceChange(HtcPreference pref, Object newvalue) {
// TODO Auto-generated method stub
/*
* we can't use the case statement here, but we can get the "clicked" item using the IF statement
*/

SharedPreferences prefs = PreferenceManager
.getDefaultSharedPreferences(Preferences.this);

HtcListPreference appdrawer = (HtcListPreference) findPreference("appdrawer");
appdrawer.setOnPreferenceChangeListener(this);

HtcListPreference panels = (HtcListPreference) findPreference("panels");
panels.setOnPreferenceChangeListener(this);

if(pref == appdrawer) {

if (newvalue.equals("1")) {

runRosie5();

}

if (newvalue.equals("2")) {

runRosie4x5();

}

if (newvalue.equals("3")) {

runRosie5x4();

}

if (newvalue.equals("4")) {

runRosie5x5();

}

}

if(pref == panels) {

if (newvalue.equals("1")) {

runRosie5();

}

if (newvalue.equals("2")) {

runRosie4x5();

}

}

return false;
}
[Java for Android App Development] xcesco89:
You need to find the views inside onCreate and the same for getdefaultsharedpreferences.

Close the onCreate method then use the [MENTION=439709]override[/MENTION]

onPreferenceChange(blah blah, Object newvalue) { ......}

You cannot set the listener inside the listener....the declaration of the listener must be outside the listener method and inside onCreate , so

onCreate(){

//find views and set listeners

//set sharedpreferences

} [MENTION=439709]override[/MENTION]

onPreferenceChange(){

//if statement for every preference with

//the PreferenCechangeListener

}

Inviato dal mio HTC One X con Tapatalk 2
[Java for Android App Development] MaartenXDA:
Thanks :) Will try and report

---------- Post added at 04:24 PM ---------- Previous post was at 04:21 PM ----------

Works and solves everything, thank you :D
[Java for Android App Development] MaartenXDA:
[MENTION=4382376]mikrosmile[/MENTION], I still don't get how to add an extra tab in the HTC Settings.apk. Could you explain that?
[Java for Android App Development] mikrosmile:
what? HTC Settings? You mean system settings application in the ROM?
[Java for Android App Development] MaartenXDA:
Yeah. I recall you once explained it to me trough PM, but I still don't understand it and you said you'd explain a little better ;)
[Java for Android App Development] nikwen:
Will apps using this SDK just run on HTC phones?

Or will you be able to get a sense UI on every ROM for your app?
[Java for Android App Development] mikrosmile:
and yeah only htc with sense (not htc with aosp rom)

no there is not way to get UI on other ROMs coz the app refer to libs in the system.. so technically no way.
[Java for Android App Development] mikrosmile:
oh ok i remember .. but this is not part of guide is already rom tweaking .. but i will make a thread about it later on
[Java for Android App Development] MaartenXDA:
Okay great, thank you :D
[Java for Android App Development] MaartenXDA:
It works perfectly xcesco :D Thank you!

But I have a problem now. I was using the PullToRefreshListView library, but for that I need to use getListView() and the activity should extend ListActivity for that. But, I can't set the activity to extend ListActivity if I want to use a HtcListView, 'cause that needs to extend HtcListActivity. So, is there any way to extend ListActivity but still use a HtcListView? I've seen in the HTC Demo apps that they just extend Activity, but that won't work as I'm parsing XML which needs a (Htc)ListActivity.

Any help is appreciated :)
[Java for Android App Development] mikrosmile:
You don't need to use HTClistactivity .. Simply use list activity but for adapter use htcadapter that's it and layout use HTC style try it ..
[Java for Android App Development] MaartenXDA:
Nope, that doesn't work :|
[Java for Android App Development] mikrosmile:
I didn't use htclistactivity in my apps and everything was working .. But I didn't try to use pull to refresh .. Send what log cat error u have now
[Java for Android App Development] xcesco89:
I think that creating a custom adapter class can solve the problem (check HtcListView class, this should natively extend ListActivity or Listview )

Inviato dal mio HTC One X con Tapatalk 2
[Java for Android App Development] MaartenXDA:
Hey guys :)

Do you know how to add button(s) in the bottom, kind of actionbar style? You know, the same as the buttons in the bottom of the attached screenshot.

Sent from my awesome fridge
[Java for Android App Development] mikrosmile:
here it is.. example

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/imgV"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />

<RelativeLayout
android:id="@+id/relL"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<com.htc.widget.HtcFooter
android:id="@+id/foot"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true">
<com.htc.widget.HtcFooterButton
android:id="@+id/fCancel"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Cancel" />
<com.htc.widget.HtcFooterButton
android:id="@+id/fDelete"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Delete" />
<com.htc.widget.HtcFooterButton
android:id="@+id/fDownload"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Download" />

</com.htc.widget.HtcFooter>
</RelativeLayout>
</LinearLayout>

in the Activity (after the line where you extends your activity) add HtcFooterButton variables,

in on create method find views by id to each button and parse the actions you want.

result of above code

View attachment 2010141
[Java for Android App Development] Jonny:
Just wondering if anyone has found a way to use the resources in com.htc.resources.apk through xml layouts like some native HTC apps?

For example some HTC apps will have:

android:background="@com.htc:drawable/common_app_bkg"

in the layouts but when I try to do this on my own apps (even with the full HTC API's, not just the ones given in OpenSense SDK) it gives a resource not found error?
[Java for Android App Development] jmz:
If I'm using the HTC Preference Activity, is there a way to make the actionbar work. Looks kinda wierd without a action bar. I tried doing it the same way as the OP but it failed. Obviously can't have Actionbar in a preference layout. And had no luck inflating the preference layout into a linear layout programatically.

Thanks
[Java for Android App Development] mikrosmile:
I did a bit different .. I'll explain later
[Java for Android App Development] mikrosmile:
There is no differences between activity or preference activity for actionbar .. It should be the same .. Method for actionbar and in oncreate method call to setup actionbar .. If something wrong I will post example
[Java for Android App Development] mikrosmile:
Ok for this you can use this way.

In htc.resources open drawable folder, look for common_app_bkg xml file. Look for image it uses, copy the image to your project, copy the entire common_app_bkg.xml or create your own with the same data inside.

As you can see it is simple repeating of the png. And when you need it, just the same use in layout

android:background="@drawable/common_app_bkg"

as to find the way to use htc resources.. i dont know even how.. maybe it needs some special engineering tools..
[Java for Android App Development] mikrosmile:
Ok. It should be the same as in mainactivity for example.

here is my preferenceactivity

public class RomInfo extends HtcPreferenceActivity implements HtcPreference.OnPreferenceClickListener {
private ActionBarExt actionBarExt=null;
private ActionBarText actionBarText=null;
private ActionBarContainer actionBarContainer=null;

private void SetupActionBar()
{
actionBarExt=new ActionBarExt(this,getActionBar());
actionBarExt.enableHTCLandscape(false);
actionBarContainer=actionBarExt.getCustomContainer();
actionBarText=new ActionBarText(this);
actionBarContainer.setBackUpEnabled(false);
actionBarText.setPrimaryText("myHUB OTA");
actionBarContainer.addCenterView(actionBarText);
actionBarContainer.setRightDividerEnabled(true);
actionBarContainer.setBackUpOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
finish();
}
});
}

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.rom);
SetupActionBar();

}

It doesn't matter what layout you have..

And prefs using their own layout already you just need to use xml prefs instead of creating some freaky big layout with all types for checkboxes and etc..
[Java for Android App Development] mikrosmile:
Added HtcListView example. Look to OP ;)
[Java for Android App Development] jmz:
I set it up that way and this is the FC I get

Line 65 is actionBarExt=new ActionBarExt(this,getActionBar());

06-18 05:18:05.538: E/AndroidRuntime(21642): FATAL EXCEPTION: main
06-18 05:18:05.538: E/AndroidRuntime(21642): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.jmz.led.enabler/com.jmz.led.enabler.MainActivity}: java.lang.RuntimeException: invalid null argument
06-18 05:18:05.538: E/AndroidRuntime(21642):	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2355)
06-18 05:18:05.538: E/AndroidRuntime(21642):	at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2391)
06-18 05:18:05.538: E/AndroidRuntime(21642):	at android.app.ActivityThread.access$600(ActivityThread.java:151)
06-18 05:18:05.538: E/AndroidRuntime(21642):	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1335)
06-18 05:18:05.538: E/AndroidRuntime(21642):	at android.os.Handler.dispatchMessage(Handler.java:99)
06-18 05:18:05.538: E/AndroidRuntime(21642):	at android.os.Looper.loop(Looper.java:155)
06-18 05:18:05.538: E/AndroidRuntime(21642):	at android.app.ActivityThread.main(ActivityThread.java:5520)
06-18 05:18:05.538: E/AndroidRuntime(21642):	at java.lang.reflect.Method.invokeNative(Native Method)
06-18 05:18:05.538: E/AndroidRuntime(21642):	at java.lang.reflect.Method.invoke(Method.java:511)
06-18 05:18:05.538: E/AndroidRuntime(21642):	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1029)
06-18 05:18:05.538: E/AndroidRuntime(21642):	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:796)
06-18 05:18:05.538: E/AndroidRuntime(21642):	at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:110)
06-18 05:18:05.538: E/AndroidRuntime(21642):	at dalvik.system.NativeStart.main(Native Method)
06-18 05:18:05.538: E/AndroidRuntime(21642): Caused by: java.lang.RuntimeException: invalid null argument
06-18 05:18:05.538: E/AndroidRuntime(21642):	at com.htc.widget.ActionBarExt.<init>(ActionBarExt.java:45)
06-18 05:18:05.538: E/AndroidRuntime(21642):	at com.jmz.led.enabler.MainActivity.SetupActionBar(MainActivity.java:65)
06-18 05:18:05.538: E/AndroidRuntime(21642):	at com.jmz.led.enabler.MainActivity.onCreate(MainActivity.java:38)
06-18 05:18:05.538: E/AndroidRuntime(21642):	at android.app.Activity.performCreate(Activity.java:5066)
06-18 05:18:05.538: E/AndroidRuntime(21642):	at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1101)
06-18 05:18:05.538: E/AndroidRuntime(21642):	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2311)
06-18 05:18:05.538: E/AndroidRuntime(21642):	... 12 more
[Java for Android App Development] mikrosmile:
Send me your code .. MainActivity and xml prefs
[Java for Android App Development] mikrosmile:
did u send me all code you have?
[Java for Android App Development] xcesco89:
look at your log :

06-18 05:18:05.538: E/AndroidRuntime(21642): at com.jmz.led.enabler.MainActivity.SetupActionBar(MainActivity.java:65)
06-18 05:18:05.538: E/AndroidRuntime(21642): at com.jmz.led.enabler.MainActivity.onCreate(MainActivity.java:38)

the problems seems to be in your SetupActionBar() method ;)

i think could be this:

actionBarContainer.setBackUpOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
finish();
}
});

try to call:

actionBarContainer.setBackUpOnClickListener([B]new OnClickListener()[/B] {
[MENTION=439709]override[/MENTION]
public void onClick(View v) {
//... stuff ...
}
})
[Java for Android App Development] jmz:
Yes that is all
[Java for Android App Development] jmz:
Its failing out on line 65 getActionBar()

There is no actionbar setup so that is returning null causing the error. At least that's what I understand of the error and method description.
[Java for Android App Development] mikrosmile:
try to use this method

public class YourClass extends HtcPreference...{
public static ActionBarText mActionText;

private void SetupActionBar()
{
Object obj = new ActionBarExt(this, getActionBar());
((ActionBarExt)obj).setFullScreenEnabled(true);
((ActionBarExt)obj).enableHTCLandscape(false);
mActionText = new ActionBarText(this);
mActionText.setPrimaryText("Your Text");
obj = ((ActionBarExt)obj).getCustomContainer();
((ActionBarContainer)obj).setRightDividerEnabled(true);
((ActionBarContainer)obj).addCenterView(mActionText);
}

.....
[Java for Android App Development] jmz:
Still "invalid null argument" on Object obj = new ActionBarExt(this, getActionBar());
[Java for Android App Development] jmz:
Well I ended up fixing it. I created a new app and just copied my code into it. Not sure how that fixed it but it did. Thanks guys
[Java for Android App Development] MaartenXDA:
Maybe you had set the theme as NoActionbar?
[Java for Android App Development] jmz:
has anyone been able to add Admob ads to the preferencescreen? I can do it on standard sdk preferencescreen but not the HTC one.
[Java for Android App Development] mikrosmile:
What error do u have ? I don't have ads on my apps so have no idea

Отправлено с моего HTC One через Tapatalk
[Java for Android App Development] mikrosmile:
Also you can try to implement layout instead of preferenceactivity ... I mean you will have normal activity but layout will contain preferensescreen and other what you need . Maybe it will help

Отправлено с моего HTC One через Tapatalk
[Java for Android App Development] jmz:
Caused by: java.lang.ClassCastException: Ad Preferences cannot be cast to com.htc.preference.Htc Preference
[Java for Android App Development] mikrosmile:
Do u know how to use layout as preferences?

Отправлено с моего HTC One через Tapatalk
[Java for Android App Development] MaartenXDA:
Delete
[Java for Android App Development] Mikanoshi:
How to detect if phone has HTC Sense? And how to implement default interface as a fallback?

Now I'm doing something like this:

public boolean isHTCSensePrefs() {
try {
Class.forName("com.htc.preference.HtcPreferenceActivity");
Class.forName("com.htc.preference.HtcPreferenceFragment");
} catch (ClassNotFoundException e) {
return false;
}
return true;
}
@ override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

Intent next = null;
if (isHTCSensePrefs()) {
Log.i("WidgetSnap", "HTC Sense detected, starting sense UI");
next = new Intent().setClassName("com.example.app","com.example.app.SettingsSense");
} else {
Log.i("WidgetSnap", "No HTC Sense detected, starting default UI");
next = new Intent().setClassName("com.example.app","com.example.app.SettingsDefault");
}
if (next != null)
{
startActivity(next);
finish();
}
}
[Java for Android App Development] Nx Biotic:
Got a question regarding the 3dot menu. If you enable split action bar and gain the black menu bar in sense 5. Is there a way to use that space and tell the app to display actions buttons and a menu at the top action bar? I have several items in my menu and 2 of which could be in reality buttons or actiin providers. I want to display these 2 actions on the bottom actionbar and show the menu button in the actionbar. Would this be possible?
[Java for Android App Development] Nx Biotic:
Guess this thread is dead...

Next question would be

-how to enable home as up in Sense Actionbar
[Java for Android App Development] mikrosmile:
Here's answer - http://xdaforums.com/showpost.php?p=42096896&postcount=72

use HTC's Footer button instead splitactionbar :)
[Java for Android App Development] mikrosmile:
m not sure what you mean, but - implement ClickListener to your item in actionbar and find the way to return listview to top position.
[Java for Android App Development] Nx Biotic:
Footer huh, no wonder i couldnt find anything

---------- Post added at 04:46 PM ---------- Previous post was at 04:45 PM ----------

For instance, using the launcher icon in top left as a back button. So, good example is the Sense Settings
[Java for Android App Development] mikrosmile:
ah, you mean back button action?

like this ? View attachment 2552783
[Java for Android App Development] Nx Biotic:
Correct
[Java for Android App Development] mikrosmile:
((ActionBarContainer)obj).setBackUpEnabled(true);
((ActionBarContainer)obj).setBackUpOnClickListener(new View.OnClickListener(){

@Override
public void onClick(View v) {
finish();

}

});
[Java for Android App Development] Nx Biotic:
Thank you for clearing up a few headaches lol

Btw dev of HTC Flip on Play Store
[Java for Android App Development] mikrosmile:
welcome :)

Im the developer of myHUB application as you may notice already in my sig :)

btw - if you need more help with Sense devving, you can contact me in Hangouts, im open for help
[Java for Android App Development] Nx Biotic:
We need more exclusive apps for Sense
[Java for Android App Development] Nx Biotic:
Does Open Sense work with Sense 6? Im getting force closes...
[Java for Android App Development] Jonny:
You need to update the HTC Extension framework - HTC changed a bunch of stuff in sense 6 and removed their previous ActionBarExt API which is most likely the cause of the crash (was for me on one of my apps at any rate).

Edit: Instructions here & here note for the second link you need to add the dex2jar'd HTCExtension.jar file into the android-19 directory instead of android-16. Also I haven't updated the attachment in the second post so you'll have to dex2jar the HTCExtension from a Sense 6 ROM to get that :)
[Java for Android App Development] Nx Biotic:
Thankyou Sir! So, I can extract that from my M8?
[Java for Android App Development] Jonny:
Yep that's the file - you first need to deodex it though so its maybe easier pulling it from a stock deodexed ROM ;)
[Java for Android App Development] Nx Biotic:
That's to simple lol.
[Java for Android App Development] Nx Biotic:
Are these what we need.

https://www.dropbox.com/sh/5cx73utyafpwe2v/S5HNTR8D-y

courtesy of Vipor team (Stock from M7 Sense 6 port)
[Java for Android App Development] Jonny:
Yes, now you need to open those .jar files up in 7-zip or similar and extract the classes.dex files from them, then run the classes.dex files through dex2jar :)
[Java for Android App Development] Nx Biotic:
Alrighty man

Edit: Got the jar ready, just need to see if it works
[Java for Android App Development] Nx Biotic:
I got HTCExtension.jar for Sense 6 ready for Eclipse and Android Studio. I set it up with Google API 19

Edit: We need commoncntrl.jar and HTC Extension.jar so il get those prepared and upload for you guys.

I think we will need a new Guide for Sense 6 open sense development.
[Java for Android App Development] MaartenXDA:
Can someone upload the deodexed commoncntrl.jar and HTC Extension.jar from HTC Sense 6? I'd like to work on it and downloading a whole ROM just for this seems a bit over the top.
[Java for Android App Development] Nx Biotic:
il get to it after Easter and show how i added it to google api 19
[Java for Android App Development] MaartenXDA:
Thanks :D And no need for the explaination, I've done this before. Just a new phone
[Java for Android App Development] mikrosmile:
Added full Sense 6 SDK reference package http://xdaforums.com/showpost.php?p=40029074&postcount=4

Just place in add-ons folder. Works with Android 19 API
[Java for Android App Development] Nx Biotic:
If thats the case, https://code.google.com/p/insertcoin-m8-port-for-m7/source/browse/#svn/trunk/system/framework

All yours bud, dex the 2 jars or any others you need and go from there

---------- Post added at 03:11 PM ---------- Previous post was at 03:10 PM ----------

profit indeed! Thank you
[Java for Android App Development] MaartenXDA:
Okay so I ran into a little problem here, while making TabProvider, I get this error on the CarouselProvider import: The import com.htc.fragment.content.CarouselProvider cannot be resolved.

Any idea's on to what I should change it?
[Java for Android App Development] mikrosmile:
there's some changes in all code. Delete all imports you have already in the app and one by one import back with new SDK.

As for tabs there's new classes. Don't have eclipe running now. will explain later
[Java for Android App Development] mikrosmile:
Gonna make some changes and updates to the guide. Will add Sense 6 specific guides
[Java for Android App Development] Nx Biotic:
Will be attempting an OpenSense 6 port to one of my devices so thisl be interesting and helpful to see.
[Java for Android App Development] mikrosmile:
Added Sense 6 Carousel Tab sample http://xdaforums.com/showpost.php?p=40028901&postcount=2
[Java for Android App Development] mikrosmile:
Added sample how to add HTC's Release to Refresh method (Swipe2Refresh) in Post 2
[Java for Android App Development] mikrosmile:
Added Sense 6 Theme support sample in Post 2. Enjoy ;)
[Java for Android App Development] Nx Biotic:
Awesome
[Java for Android App Development] Nx Biotic:
I made a small example activity for OpenSense 6 during a walk using AIDE and got this. Is this because I mis-wrote the xml or because of theme

View attachment 2721934
[Java for Android App Development] Jonny:
Post the code and layout xml, can't tell what's happening in that though it looks like if you have an actionbar the background color for it is set to white or something.
[Java for Android App Development] mikrosmile:
nop. when you not setting up actionbar it will be white.
[Java for Android App Development] Nx Biotic:
public class MainActivity extends HtcPreferenceActivity {

private ActionBarExt actionBarExt=null;

private ActionBarText actionBarText=null;

private void SetupActionBar() {

actionBarExt=new ActionBarExt(this,getActionBar());

actionBarText=new ActionBarText(this);

actionBarText.setPrimaryText("OpenSense Parts");

}

[MENTION=439709]override[/MENTION]

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

addPreferencesFromResource(R.xml.prefs);

SetupActionBar();

}

}
[Java for Android App Development] mikrosmile:
Wrong info, sorry, You need to setTheme to your activity, then it will be the preffered color.

And set theme before actionbar and setcontentview is called
[Java for Android App Development] Nx Biotic:
public class MainActivity extends HtcPreferenceActivity {

private ActionBarExt actionBarExt=null;

private ActionBarText actionBarText=null;

private ActionBarContainer actionBarContainer=null;

private Context context;

private void SetupActionBar() {

actionBarExt=new ActionBarExt(this,getActionBar());

actionBarContainer=actionBarExt.getCustomContainer();

actionBarText=new ActionBarText(this);

actionBarText.setPrimaryText("OpenSense Dev");

actionBarContainer.addCenterView(actionBarText);

}

public static int getHtcThemeID(Context context, int i)

{

return HtcWrapConfiguration.getHtcThemeId(context, i);

}

[MENTION=439709]override[/MENTION]

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

addPreferencesFromResource(R.xml.prefs);

SetupActionBar();

setTheme(getHtcThemeID(context, 3));

}

}
[Java for Android App Development] mikrosmile:
setTheme and after SetupActionBar