Re: [android-developers] Problem refreshing a fragment edittext view from a dialogFragment after rotation

2012-06-06 Thread Bluemercury

Hi al! i've read the answer from Dianne, and it seems i can declare an 
interface in one fragment and then implement it on another. But for this i 
need the pointer to the fragment in question, she said:

 take advantage of the FragmentManager APIs to save a fragment pointer 
in a bundle and later retrieve it, to allow you to maintain direct pointers 
across state save/restore. 

What's the best way to do this? Here's my code to call the dialogfragment 
in the main frag:

dialFragment=DateTimePickerDialogFragment.newInstance(DateTimePickerDialogFragment.DATETIME_PICKER,
 
dateBeginTV);
  dialFragment.show(fragMan, dialog);

how can i send the pointer to the dialogfragment, and will it survive the 
rotation?


On Wednesday, June 6, 2012 8:20:30 AM UTC+1, al wrote:

 Ok, I assumed that text field was part of the activity. In your case 
 https://groups.google.com/forum/?fromgroups#!topic/android-developers/NBlMJnMaGboshould
  help, especially the answer of Dianne.

 In short: you might just do 
 dialogfragment.setTargetFragment(textfieldfragment) in the activity to 
 link the fragments. Android will then take care of that reference. In the 
 dialogFragment you can then pass the new value like 
 ((MyFragmentClass)getTargetFragment()).setDateTimeField(curDateTime()). 

  

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Re: [android-developers] Problem refreshing a fragment edittext view from a dialogFragment after rotation

2012-06-06 Thread Bluemercury
Also, there's 2 factors:
1- my DateTimePickerDialogFragment is being included in a different library 
project, so it will not know the sub type of Fragment being passed.
2- in one target fragment i will need, i have two edittexts in the same 
fragment so the DateTimePickerDialogFragment must somehow point to the 
correct edittext

regards,


On Wednesday, June 6, 2012 2:16:42 PM UTC+1, Bluemercury wrote:


 Hi al! i've read the answer from Dianne, and it seems i can declare an 
 interface in one fragment and then implement it on another. But for this i 
 need the pointer to the fragment in question, she said:

  take advantage of the FragmentManager APIs to save a fragment pointer 
 in a bundle and later retrieve it, to allow you to maintain direct pointers 
 across state save/restore. 

 What's the best way to do this? Here's my code to call the dialogfragment 
 in the main frag:

 dialFragment=DateTimePickerDialogFragment.newInstance(DateTimePickerDialogFragment.DATETIME_PICKER,
  
 dateBeginTV);
   dialFragment.show(fragMan, dialog);

 how can i send the pointer to the dialogfragment, and will it survive the 
 rotation?


 On Wednesday, June 6, 2012 8:20:30 AM UTC+1, al wrote:

 Ok, I assumed that text field was part of the activity. In your case 
 https://groups.google.com/forum/?fromgroups#!topic/android-developers/NBlMJnMaGboshould
  help, especially the answer of Dianne.

 In short: you might just do 
 dialogfragment.setTargetFragment(textfieldfragment) in the activity to 
 link the fragments. Android will then take care of that reference. In the 
 dialogFragment you can then pass the new value like 
 ((MyFragmentClass)getTargetFragment()).setDateTimeField(curDateTime()). 

  


-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Re: [android-developers] Problem refreshing a fragment edittext view from a dialogFragment after rotation

2012-06-05 Thread Bluemercury
Hi al! The thing is here im using  framents, the text field is on the 
fragment, not on the activity itself. The ideia was to create a dynamic 
dialofgragment without to mess around with the activity too much, since in 
this case the fragment is part of a viewpager in the activity. What if i 
use the   this.setRetainInstance(true);  on the fragment that holds the 
text field too?

regards,

On Tuesday, June 5, 2012 3:14:58 PM UTC+1, al wrote:

 Of course I'm guessing, but I think you should change the way you transfer 
 the new date/time value to the text widget.

 In the activity, say A1, you create the dialog and give it a reference to 
 the text field of A1. When the device is rotated, the activity is recreated 
 (= A2), but the dialog is not (due to this.setRetainInstance(true);). 
 I.e. the dialog still references the text field of A1, but you see the 
 activity A2. That's probably the cause of the observed behavior. As far as 
 I understand it, the way to go is to add a setDateTimeField() method to 
 the activity and to replace the code in the onClick method of the dialog 
 with something like 
 ((MyActivityClass)getActivity()).setDateTimeField(curDateTime()). 
 GetActivity() will return the current/correct activity since the dialog 
 will be attached to new activity as part of the configuration change.


-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Re: [android-developers] Problem refreshing a fragment edittext view from a dialogFragment after rotation

2012-06-04 Thread Bluemercury
Hi! Seems replying directly from gmail doesnt refresh this page. so im 
posting again, i changed the property like you said but if i call the 
dialogfragment, rotate the phone and press ok, it wont refresh the 
editext.Only if i call it again, dont rotate, and press ok. The problem 
happens when i rotate with the dialogfragment being visible, if the 
edittext has any value, before i rotate, by default it will show the values 
after rotation correctly , so the issue here lies when i rotate while 
showing the dialogfragment, seems the edittext i pass to it looses the 
connection with the view layout

regards,

On Sunday, June 3, 2012 3:14:16 PM UTC+1, Fred Niggle wrote:

 This is caused by the contents of the edittext not being saved when 
 rotated.
 If the edittext is defined via xml then set 

  android:freezesText=true

 to stop the edittext from loosing its contents upon rotation.

 Hope this help,
 Fred

 On 3 June 2012 01:09, Bluemercury joao.ro...@gmail.com wrote:

 So im adapting my DateTimePickerDialog implementation to a 
 DialogFragment, and right now it works well, i press the button to show the 
 dialogfragment choose a date/time value, press ok and it will show on the 
 fragment's edit text view.
 The problem is, if i press the button to show the dialog, then rotate, 
 everything seems to work well except when i press ok to fill the edittext 
 view it wont fill it with the choosen value. If i do this again it will 
 work. Seems the problem is when i rotate the edittext seems to loose the 
 view relation?
 Here's the frapgment that calls the dialog:

 public class MainFragment extends Fragment {

   Button button;

  TextView tv;

@Override

  public View onCreateView(LayoutInflater inflater, ViewGroup container,

  Bundle savedInstanceState) {

   this.setRetainInstance(true);

   View view= inflater.inflate(R.layout.main_fragment, container,false);

   button= (Button) view.findViewById(R.id.button1);

  tv=(TextView) view.findViewById(R.id.editText1);

  button.setOnClickListener(new OnClickListener() {

   @Override

  public void onClick(View v) {

  FragmentManager fm = getActivity().getSupportFragmentManager();

  
 DateTimePickerDialog.newInstance(DateTimePickerDialog.DATETIME_PICKER,tv).show(fm,
  
 dialog);

   }

  });

  return view;

  }

 }


 Here's the DateTimePickerDialog main methods:

 public static DateTimePickerDialog newInstance(int type,View view) {

  DateTimePickerDialog f = new DateTimePickerDialog();

  f.dialogType=type;

  f.currCal=Calendar.getInstance();

  f.element=view;


  Logger.write(DateTimePickerDialog, newInstance, Logger.INFO);

  return f;

  }


  public DateTimePickerDialog() {}



  @Override

  public View onCreateView(LayoutInflater inflater, ViewGroup container,

  Bundle savedInstanceState) {


  this.setRetainInstance(true);


  this.getDialog().requestWindowFeature(STYLE_NO_TITLE);

  this.setCancelable(false);


  type = null;


  switch(dialogType){


  case DATE_PICKER:

  type =inflater.inflate(R.layout.custom_date_picker_dialog, container, 
 false);

  
 type.findViewById(R.id.imagelogo).setBackgroundResource(R.drawable.ico_popup_data);

  //fillDialogHeader();

  dateDialog();

  break;

  case TIME_PICKER:

  type =inflater.inflate(R.layout.custom_time_picker_dialog, container, 
 false);

  
 type.findViewById(R.id.imagelogo).setBackgroundResource(R.drawable.ico_popup_hora);

  //fillDialogHeader();

  timeDialog();

  break;

  case DATETIME_PICKER:

  type =inflater.inflate(R.layout.custom_datetime_picker_dialog, 
 container, false);

  
 type.findViewById(R.id.imagelogo).setBackgroundResource(R.drawable.ico_popup_datahora);

  //fillDialogHeader();

  dateTimeDialog(); 

  }


  fillDialogHeader();

  //button clicks

  ok=(Button)type.findViewById(R.id.btn_change_date_ok);

  ok.setOnClickListener(this);

  clean=(Button)type.findViewById(R.id.btn_change_date_clean);

  clean.setOnClickListener(this);

  cancel=(Button)type.findViewById(R.id.btn_change_date_cancel);

  cancel.setOnClickListener(this);


  Logger.write(DateTimePickerDialog, onCreateView, Logger.INFO);

  return type;

  }


 Is the problem associated with passing the edittext view element?

 regards, 

  


  

 -- 
 You received this message because you are subscribed to the Google
 Groups Android Developers group.
 To post to this group, send email to android-developers@googlegroups.com
 To unsubscribe from this group, send email to
 android-developers+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/android-developers?hl=en




 -- 
 Magnetic Door Alarm 
 apphttps://play.google.com/store/apps/details?id=com.nds.magneticdooralarmis
  now available in Google Play
  

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers

Re: [android-developers] onSaveInstanceState method on Fragment not called when corresponding FragmentActivity acts as a tab.

2012-05-23 Thread Bluemercury
Hi Dianne! Thanks for the reply. So you're saying i should use 
Activities(FragmentActivity) has tabs but instead use Fragments for each 
tab content?. What about dealing with different layouts like:

*Activity A- Fragment A, Activity B-FragmentB for portrait
*Actiivity A- Fragment A+ B for landscape

How can i achieve this if i use Fragments directly?

regards,

On Wednesday, May 23, 2012 6:46:47 AM UTC+1, Dianne Hackborn wrote:

 (1) If you are using fragments, don't use ActivityGroup or 
 LocalActivityActivityManager.  This class is deprecated. Use the new 
 Fragment and FragmentManager APIs instead; these are also available on 
 older platforms through the Android compatibility package.  
 http://developer.android.com/reference/android/app/ActivityGroup.html 

 (2) For the love of all, ghod please do not instantiate a 
 LocalActivityManager directly: This class is not normally used directly, 
 but rather created for you as part of the ActivityGroup implementation.   
 http://developer.android.com/reference/android/app/LocalActivityManager.html
  

 (3) Use the various sample code that shows how to use tabs with fragments, 
 such as 
 http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/app/FragmentTabs.html
  or 
 http://developer.android.com/resources/samples/Support4Demos/src/com/example/android/supportv4/app/FragmentTabs.html
  or 
 http://developer.android.com/resources/samples/Support4Demos/src/com/example/android/supportv4/app/FragmentTabsPager.html

 On Tue, May 22, 2012 at 10:25 AM, Bluemercury joao.ro...@gmail.comwrote:

 Hi! so im currently having a problem regarding the onSaveInstaceState 
 method in the Fragment class. This class is called from a FragmentActivity 
 that acts as a Tab created in another FragmentActivity, but i cant seem to 
 make the call to onSaveInstanceState to happen, here's some code:

 *mainmenu *class that generates the tabs:

 public class MainMenu extends FragmentActivity{


  private TabHost tabs=null;


  public String getWindowTitle() {

  return Home;

  }

  
 //@Override

  public int getLayoutId() {

  return R.layout.main_menu;

  }

  
 //@Override

  public int getThemeId() {

  return R.style.CustomTheme;

  }

  
 @Override

  public void onSaveInstanceState(Bundle bundle) {


  super.onSaveInstanceState(bundle);

  bundle.putInt(TAB,tabs.getCurrentTab());

   }


  @Override

  public void onRestoreInstanceState(Bundle bundle) {


 super.onRestoreInstanceState(bundle);

  tabs.setCurrentTab(bundle.getInt(TAB));



 }


  @Override

  public void onCreate(Bundle savedInstanceState) {


 setTheme(getThemeId()); 

  super.onCreate(savedInstanceState);

   setContentView(getLayoutId());

LocalActivityManager mlam = new LocalActivityManager(this, false);

  tabs=(TabHost)findViewById(android.R.id.tabhost);

  mlam.dispatchCreate(savedInstanceState);

  tabs.setup(mlam);


  TabHost.TabSpec spec;

  Intent intent;


 // Create an Intent to launch an Activity for the tab (to be reused)

  intent = new Intent().setClass(this, 
 MyProcessListFragmentActivity.class);

  spec = 
 tabs.newTabSpec(Home).setIndicator((buildTabIndicator(Home)))

  .setContent(intent);

  tabs.addTab(spec);


  // Create an Intent to launch an Activity for the tab (to be reused)

  intent = new Intent().setClass(this, SearchProcess.class);

  spec = 
 tabs.newTabSpec(Search).setIndicator((buildTabIndicator(Search)))

  .setContent(intent);


 // Create an Intent to launch an Activity for the tab (to be reused)

  intent = new Intent().setClass(this, MyProcessList.class);

  tabs.addTab(spec);

  spec = 
 tabs.newTabSpec(Options).setIndicator((buildTabIndicator(Options)))

  .setContent(intent);


  tabs.addTab(spec);


 tabs.setCurrentTab(0);



 }


 Here's the *MyprocessListGragmentActivity*:

 public class MyProcessListFragmentActivity extends FragmentActivity 
 implements MyProcessFragmentList.onProcessSelectedListener{

 @Override
  protected void onCreate(Bundle arg0) {
 super.onCreate(arg0);

 setContentView(R.layout.myprocesslist_fragment); 
  }
 }


 and the Fragment class *MyProcessFragmentList *called  from the layout :

 public class MyProcessFragmentList extends IpdmsCoreFragment {


  onProcessSelectedListener mListener;


 private PullToRefreshListView mPullRefreshListView;


  private LinkedListGenericMenuItemListDTO iTems;

  private ListMyProcessDTO tempList;

  private GenericMenuAdapter adapter;


  private int processListPage=1;



  // Container Activity must implement this interface

  public interface onProcessSelectedListener{


 public void onArticleSelected(MyProcessDTO process);

  }

  

  @Override

  public void onAttach(Activity activity) {

  super.onAttach(activity);


 try{

  mListener=(onProcessSelectedListener) activity;

  }catch(ClassCastException e){

  throw new ClassCastException(activity.toString() +  must implement 
 onProcessSelectedListener);

  }

  }

  


 @Override

  public void onSaveInstanceState

Re: [android-developers] onSaveInstanceState method on Fragment not called when corresponding FragmentActivity acts as a tab.

2012-05-23 Thread Bluemercury
Basically you cant use fragment activities has tabs am i correct???only 
fragments as tabsbut now how do i deal with layout orientation?if 
there's no activity for each fragment, the layout stays the same even if i 
have a different layout for landscape

On Wednesday, May 23, 2012 6:46:47 AM UTC+1, Dianne Hackborn wrote:

 (1) If you are using fragments, don't use ActivityGroup or 
 LocalActivityActivityManager.  This class is deprecated. Use the new 
 Fragment and FragmentManager APIs instead; these are also available on 
 older platforms through the Android compatibility package.  
 http://developer.android.com/reference/android/app/ActivityGroup.html 

 (2) For the love of all, ghod please do not instantiate a 
 LocalActivityManager directly: This class is not normally used directly, 
 but rather created for you as part of the ActivityGroup implementation.   
 http://developer.android.com/reference/android/app/LocalActivityManager.html
  

 (3) Use the various sample code that shows how to use tabs with fragments, 
 such as 
 http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/app/FragmentTabs.html
  or 
 http://developer.android.com/resources/samples/Support4Demos/src/com/example/android/supportv4/app/FragmentTabs.html
  or 
 http://developer.android.com/resources/samples/Support4Demos/src/com/example/android/supportv4/app/FragmentTabsPager.html

 On Tue, May 22, 2012 at 10:25 AM, Bluemercury joao.ro...@gmail.comwrote:

 Hi! so im currently having a problem regarding the onSaveInstaceState 
 method in the Fragment class. This class is called from a FragmentActivity 
 that acts as a Tab created in another FragmentActivity, but i cant seem to 
 make the call to onSaveInstanceState to happen, here's some code:

 *mainmenu *class that generates the tabs:

 public class MainMenu extends FragmentActivity{


  private TabHost tabs=null;


  public String getWindowTitle() {

  return Home;

  }

  
 //@Override

  public int getLayoutId() {

  return R.layout.main_menu;

  }

  
 //@Override

  public int getThemeId() {

  return R.style.CustomTheme;

  }

  
 @Override

  public void onSaveInstanceState(Bundle bundle) {


  super.onSaveInstanceState(bundle);

  bundle.putInt(TAB,tabs.getCurrentTab());

   }


  @Override

  public void onRestoreInstanceState(Bundle bundle) {


 super.onRestoreInstanceState(bundle);

  tabs.setCurrentTab(bundle.getInt(TAB));



 }


  @Override

  public void onCreate(Bundle savedInstanceState) {


 setTheme(getThemeId()); 

  super.onCreate(savedInstanceState);

   setContentView(getLayoutId());

LocalActivityManager mlam = new LocalActivityManager(this, false);

  tabs=(TabHost)findViewById(android.R.id.tabhost);

  mlam.dispatchCreate(savedInstanceState);

  tabs.setup(mlam);


  TabHost.TabSpec spec;

  Intent intent;


 // Create an Intent to launch an Activity for the tab (to be reused)

  intent = new Intent().setClass(this, 
 MyProcessListFragmentActivity.class);

  spec = 
 tabs.newTabSpec(Home).setIndicator((buildTabIndicator(Home)))

  .setContent(intent);

  tabs.addTab(spec);


  // Create an Intent to launch an Activity for the tab (to be reused)

  intent = new Intent().setClass(this, SearchProcess.class);

  spec = 
 tabs.newTabSpec(Search).setIndicator((buildTabIndicator(Search)))

  .setContent(intent);


 // Create an Intent to launch an Activity for the tab (to be reused)

  intent = new Intent().setClass(this, MyProcessList.class);

  tabs.addTab(spec);

  spec = 
 tabs.newTabSpec(Options).setIndicator((buildTabIndicator(Options)))

  .setContent(intent);


  tabs.addTab(spec);


 tabs.setCurrentTab(0);



 }


 Here's the *MyprocessListGragmentActivity*:

 public class MyProcessListFragmentActivity extends FragmentActivity 
 implements MyProcessFragmentList.onProcessSelectedListener{

 @Override
  protected void onCreate(Bundle arg0) {
 super.onCreate(arg0);

 setContentView(R.layout.myprocesslist_fragment); 
  }
 }


 and the Fragment class *MyProcessFragmentList *called  from the layout :

 public class MyProcessFragmentList extends IpdmsCoreFragment {


  onProcessSelectedListener mListener;


 private PullToRefreshListView mPullRefreshListView;


  private LinkedListGenericMenuItemListDTO iTems;

  private ListMyProcessDTO tempList;

  private GenericMenuAdapter adapter;


  private int processListPage=1;



  // Container Activity must implement this interface

  public interface onProcessSelectedListener{


 public void onArticleSelected(MyProcessDTO process);

  }

  

  @Override

  public void onAttach(Activity activity) {

  super.onAttach(activity);


 try{

  mListener=(onProcessSelectedListener) activity;

  }catch(ClassCastException e){

  throw new ClassCastException(activity.toString() +  must implement 
 onProcessSelectedListener);

  }

  }

  


 @Override

  public void onSaveInstanceState(Bundle outState) {

  super.onSaveInstanceState(outState);


  outState.putSerializable(LISTPROCESS

[android-developers] onSaveInstanceState method on Fragment not called when corresponding FragmentActivity acts as a tab.

2012-05-22 Thread Bluemercury
Hi! so im currently having a problem regarding the onSaveInstaceState 
method in the Fragment class. This class is called from a FragmentActivity 
that acts as a Tab created in another FragmentActivity, but i cant seem to 
make the call to onSaveInstanceState to happen, here's some code:

*mainmenu *class that generates the tabs:

public class MainMenu extends FragmentActivity{


 private TabHost tabs=null;


  public String getWindowTitle() {

 return Home;

 }


 //@Override

 public int getLayoutId() {

 return R.layout.main_menu;

 }


 //@Override

 public int getThemeId() {

 return R.style.CustomTheme;

 }


 @Override

 public void onSaveInstanceState(Bundle bundle) {


 super.onSaveInstanceState(bundle);

 bundle.putInt(TAB,tabs.getCurrentTab());

  }


 @Override

 public void onRestoreInstanceState(Bundle bundle) {


 super.onRestoreInstanceState(bundle);

 tabs.setCurrentTab(bundle.getInt(TAB));



 }


 @Override

 public void onCreate(Bundle savedInstanceState) {


 setTheme(getThemeId()); 

 super.onCreate(savedInstanceState);

  setContentView(getLayoutId());

  LocalActivityManager mlam = new LocalActivityManager(this, false);

 tabs=(TabHost)findViewById(android.R.id.tabhost);

 mlam.dispatchCreate(savedInstanceState);

 tabs.setup(mlam);


 TabHost.TabSpec spec;

 Intent intent;


 // Create an Intent to launch an Activity for the tab (to be reused)

 intent = new Intent().setClass(this, MyProcessListFragmentActivity.class);

 spec = tabs.newTabSpec(Home).setIndicator((buildTabIndicator(Home)))

 .setContent(intent);

 tabs.addTab(spec);


 // Create an Intent to launch an Activity for the tab (to be reused)

 intent = new Intent().setClass(this, SearchProcess.class);

 spec = 
 tabs.newTabSpec(Search).setIndicator((buildTabIndicator(Search)))

 .setContent(intent);


 // Create an Intent to launch an Activity for the tab (to be reused)

 intent = new Intent().setClass(this, MyProcessList.class);

 tabs.addTab(spec);

 spec = 
 tabs.newTabSpec(Options).setIndicator((buildTabIndicator(Options)))

 .setContent(intent);


 tabs.addTab(spec);


 tabs.setCurrentTab(0);



 }


Here's the *MyprocessListGragmentActivity*:

public class MyProcessListFragmentActivity extends FragmentActivity 
 implements MyProcessFragmentList.onProcessSelectedListener{

 @Override
 protected void onCreate(Bundle arg0) {
 super.onCreate(arg0);

 setContentView(R.layout.myprocesslist_fragment); 
 }
 }


and the Fragment class *MyProcessFragmentList *called  from the layout :

public class MyProcessFragmentList extends IpdmsCoreFragment {


 onProcessSelectedListener mListener;


 private PullToRefreshListView mPullRefreshListView;


 private LinkedListGenericMenuItemListDTO iTems;

  private ListMyProcessDTO tempList;

 private GenericMenuAdapter adapter;


 private int processListPage=1;



 // Container Activity must implement this interface

 public interface onProcessSelectedListener{


 public void onArticleSelected(MyProcessDTO process);

 }



 @Override

 public void onAttach(Activity activity) {

 super.onAttach(activity);


 try{

 mListener=(onProcessSelectedListener) activity;

 }catch(ClassCastException e){

 throw new ClassCastException(activity.toString() +  must implement 
 onProcessSelectedListener);

 }

 }




 @Override

 public void onSaveInstanceState(Bundle outState) {

 super.onSaveInstanceState(outState);


 outState.putSerializable(LISTPROCESS, adapter.getAllItems());

 }


The onSaveInstanceState never gets called on rotationbut if i run the 
Fragment Activity directly it works and it gets called

Regards, 
 
 

 

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] out of memory bitmap exceeds VM budget - on Rotation - Theme background reference guilt??

2012-03-07 Thread Bluemercury
So i was having this error after some rotations were made. After this i 
used the onDestroy method do get rid of drawables:


@Override
protected void onDestroy() {
super.onDestroy();
*unbindDrawables*(findViewById(android.R.id.content).getRootView());
System.gc();
Runtime.getRuntime().gc();
}

private void *unbindDrawables*(View view) {
if (view.getBackground() != null) {
view.getBackground().setCallback(null);
}
if (view instanceof ViewGroup) {
for (int i = 0; i  ((ViewGroup) view).getChildCount(); i++) {
unbindDrawables(((ViewGroup) view).getChildAt(i));
}
try {
((ViewGroup) view).removeAllViews();
}catch(UnsupportedOperationException mayHappen){

}
}

After implemeting this, i still got the errors on the more advanced phones 
like the Nexus S and Galaxy Nexus, so i thought about the background image 
that is being referenced in the style xml:

style name=CustomTheme parent=android:Theme
item name=android:windowTitleSize70dp/item
  item name=android:windowBackground@drawable/background_screen/item
item 
name=android:windowTitleBackgroundStyle@style/CustomWindowTitleBackground/item
 /style


after removing the reference in the style tag, i got rid of the errors, so 
i tried to add the image in the layout xml file instead to test it, and it 
still worked, so i assume the problem is the *unbindDrawables *method 
doesnt remove the background image because its reference is being made in 
the theme, so is there a way to deal with this with another approach??can i 
unbind the theme altogether? setTheme(0) didnt work either...

regards,

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] Converting Custom Dialog to DialogFragment.

2012-03-01 Thread Bluemercury
Hi! So im currently trying to make my custom dialogs persistent after 
rotation and i was going to use the onCreateDialog method for that. but it 
seems to be deprecated and instead i was pointed to the DialogFragment 
class.
 I've seen some tutorials in android developer page and my main question 
here, is if there's a simple way to use the already built  custom dialog. 
This is a custom DateTimePickerDialog that lets you choose what parameters 
you want (DateTime/Date/Time) and it uses compounds for building the 
dialog. So can i still use this custom dialog or do i have to rewrite it 
from scratch by extending the DialogFragment instead of extending Dialog 
class?

regards,

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] Long click in expandable list group items.

2012-02-27 Thread Bluemercury
Hi! im currently using an expandable list as an n-tree level list, and i 
use the long click to select any element, either group or childs, the 
problem is that the group row has a gradient gradient backgroup so 
translates in it not having any kind of highlight. i managed the normal 
click color, but im not getting any luck with the long click animation:

This is my group row xml:

*LinearLayout android:id=@+id/LinearLayout01*
* android:layout_width=fill_parent android:layout_height=45dip*
* xmlns:android=http://schemas.android.com/apk/res/android*
* android:background=@drawable/expandable_group_item*
* TextView *
* android:id=@+id/tvGroup *
* android:layout_width=fill_parent*
* android:layout_height=45dip *
* android:text=Groups *
* android:gravity=center_vertical|right*
* android:paddingLeft=5dip *
* android:paddingRight=5dip*
* android:textColor=# *
* android:textStyle=bold*
* android:textSize=17dip *
* /TextView*
*/LinearLayout*
*
*
This is the expandable_group_item_selector:

*selector xmlns:android=http://schemas.android.com/apk/res/android;*
* item android:state_window_focused=false 
android:drawable=@android:color/transparent /*
* *
*item android:state_focused=true android:state_pressed=true*
*
android:drawable=@drawable/list_selector_background_transition /*
*item android:state_focused=false android:state_pressed=true*
*
android:drawable=@drawable/list_selector_background_transition /*
*item android:state_focused=true*
*
android:drawable=@+drawable/list_selector_background_focus /*
*item android:state_focused=false*
*android:drawable=@+drawable/gradient_dialog_header /*
*/selector*

The focus and long click animation still dont work any ideas?

regards,

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] Re: Long click in expandable list group items.

2012-02-27 Thread Bluemercury
Basically what i want is default behaviour in all states but with my own 
backgroud gradient:S


On Monday, February 27, 2012 2:14:45 PM UTC, Bluemercury wrote:

 Hi! im currently using an expandable list as an n-tree level list, and i 
 use the long click to select any element, either group or childs, the 
 problem is that the group row has a gradient gradient backgroup so 
 translates in it not having any kind of highlight. i managed the normal 
 click color, but im not getting any luck with the long click animation:

 This is my group row xml:

 *LinearLayout android:id=@+id/LinearLayout01*
 * android:layout_width=fill_parent android:layout_height=45dip*
 * xmlns:android=http://schemas.android.com/apk/res/android*
 * android:background=@drawable/expandable_group_item*
 * TextView *
 * android:id=@+id/tvGroup *
 * android:layout_width=fill_parent*
 * android:layout_height=45dip *
 * android:text=Groups *
 * android:gravity=center_vertical|right*
 * android:paddingLeft=5dip *
 * android:paddingRight=5dip*
 * android:textColor=# *
 * android:textStyle=bold*
 * android:textSize=17dip *
 * /TextView*
 */LinearLayout*
 *
 *
 This is the expandable_group_item_selector:

 *selector xmlns:android=http://schemas.android.com/apk/res/android;*
 * item android:state_window_focused=false 
 android:drawable=@android:color/transparent /*
 * *
 *item android:state_focused=true android:state_pressed=true*
 *
 android:drawable=@drawable/list_selector_background_transition /*
 *item android:state_focused=false android:state_pressed=true*
 *
 android:drawable=@drawable/list_selector_background_transition /*
 *item android:state_focused=true*
 *
 android:drawable=@+drawable/list_selector_background_focus /*
 *item android:state_focused=false*
 *android:drawable=@+drawable/gradient_dialog_header /*
 */selector*

 The focus and long click animation still dont work any ideas?

 regards,


-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Re: [android-developers] Re: Long click in expandable list group items.

2012-02-27 Thread Bluemercury
i changed the expandable_group_item to this:

?xml version=1.0 encoding=utf-8?
selector xmlns:android=http://schemas.android.com/apk/res/android;
 item 
 android:state_window_focused=false 
 android:drawable=@android:color/transparent /
item 
android:state_focused=true 
android:state_pressed=true
  android:drawable=@android:color/transparent /
item 
android:state_focused=false 
android:state_pressed=true
android:drawable=@android:color/transparent /
item android:state_focused=true
android:drawable=@android:color/transparent /
 !-- the default item --
item android:drawable=@+drawable/gradient_dialog_header /
/selector 

Didnt change the row layout like you said, but it seems to be working as 
expected. Any reason to change like you said?

regards

On Monday, February 27, 2012 2:39:22 PM UTC, Kostya Vasilyev wrote:

  What you can do is:

 1) Add another layout to your group item layout, make sure its size 
 matches the entire group item. FrameLayout is probably easiest.
 2) Specify your own state-list background drawable for this layout.
 3) In this state-list drawable, specify transparent color for pressed / 
 focused / selected state, and the color you want for normal state as the 
 default.

 The way this'll work is that the color from your state-list drawable will 
 be used only if the item is not pressed / focused / selected. For those 
 states, your drawable will turn transparent and let the android list item 
 drawable show.

 You'll also need android:duplicateParentState on the layout added in step 
 1.

 -- Kostya

 On 02/27/2012 06:31 PM, Bluemercury wrote: 

 Basically what i want is default behaviour in all states but with my own 
 backgroud gradient:S 


 On Monday, February 27, 2012 2:14:45 PM UTC, Bluemercury wrote: 

 Hi! im currently using an expandable list as an n-tree level list, and i 
 use the long click to select any element, either group or childs, the 
 problem is that the group row has a gradient gradient backgroup so 
 translates in it not having any kind of highlight. i managed the normal 
 click color, but im not getting any luck with the long click animation: 

  This is my group row xml:

  *LinearLayout android:id=@+id/LinearLayout01*
 * android:layout_width=fill_parent android:layout_height=45dip*
 * xmlns:android=http://schemas.android.com/apk/res/android*
 * android:background=@drawable/expandable_group_item*
 * TextView *
 * android:id=@+id/tvGroup *
 * android:layout_width=fill_parent*
 * android:layout_height=45dip *
 * android:text=Groups *
 * android:gravity=center_vertical|right*
 * android:paddingLeft=5dip *
 * android:paddingRight=5dip*
 * android:textColor=# *
 * android:textStyle=bold*
 * android:textSize=17dip *
 * /TextView*
 */LinearLayout*
 *
 *
 This is the expandable_group_item_selector:

  *selector xmlns:android=http://schemas.android.com/apk/res/android;*
 * item android:state_window_focused=false 
 android:drawable=@android:color/transparent /*
 * *
 *item android:state_focused=true android:state_pressed=true*
 *
 android:drawable=@drawable/list_selector_background_transition /*
 *item android:state_focused=false android:state_pressed=true
 *
 *
 android:drawable=@drawable/list_selector_background_transition /*
 *item android:state_focused=true*
 *
 android:drawable=@+drawable/list_selector_background_focus /*
 *item android:state_focused=false*
 *android:drawable=@+drawable/gradient_dialog_header /*
 */selector*
  
  The focus and long click animation still dont work any ideas?
  
  regards,

  -- 
 You received this message because you are subscribed to the Google
 Groups Android Developers group.
 To post to this group, send email to android-developers@googlegroups.com
 To unsubscribe from this group, send email to
 android-developers+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/android-developers?hl=en 


  

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Re: [android-developers] Re: Long click in expandable list group items.

2012-02-27 Thread Bluemercury
Hi again Kostya, seems that the cursor focus isnt working althought that's 
not the most important thing it still is default behaviour so im wondering 
why it doesnt work. Also the extra layout was something like this?:


LinearLayout android:id=@+id/LinearLayout01
android:layout_width=fill_parent 
android:layout_height=45dip
xmlns:android=http://schemas.android.com/apk/res/android;
*android:background=@drawable/expandable_group_item*
*LinearLayout*
*android:layout_width=fill_parent *
* android:layout_height=fill_parent*
* android:duplicateParentState=true*
TextView 
android:id=@+id/tvGroup 
android:layout_width=fill_parent
android:layout_height=45dip 
android:text=Groups 
android:gravity=center_vertical|right
android:paddingLeft=5dip 
android:paddingRight=5dip
android:textColor=# 
android:textStyle=bold
android:textSize=17dip 
/TextView
*/LinearLayout*
/LinearLayout

ididnt understand if the new layout would wrap the textview like that.

regards,

On Monday, February 27, 2012 3:17:12 PM UTC, Kostya Vasilyev wrote:

 On 02/27/2012 06:57 PM, Bluemercury wrote:
 
  Didnt change the row layout like you said, but it seems to be working 
  as expected. Any reason to change like you said?
 
  regards

 I remember needing an extra layout in a similar case so that the 
 highlight background used by the list view and the state-list with 
 custom background wouldn't step on each other, but...

 ... no reason to change something that works :)


 -- K



-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Re: [android-developers] Re: Long click in expandable list group items.

2012-02-27 Thread Bluemercury
Ok ive made the change but the normal focus doesnt seem to be working, 
here's the expand_custom_row_group_layout:

*LinearLayout*
*xmlns:android=http://schemas.android.com/apk/res/android*
*android:id=@+id/LinearLayout01*
* android:layout_width=fill_parent *
* android:layout_height=45dip*
* LinearLayout*
*android:layout_width=fill_parent *
* android:layout_height=fill_parent*
* android:background=@drawable/expandable_group_item*
* android:duplicateParentState=true*
* TextView *
* android:id=@+id/tvGroup *
* android:layout_width=fill_parent*
* android:layout_height=45dip *
* android:text=Groups *
* android:gravity=center_vertical|right*
* android:paddingLeft=5dip *
* android:paddingRight=5dip*
* android:textColor=# *
* android:textStyle=bold*
* android:textSize=17dip *
* /TextView*
* /LinearLayout*
*/LinearLayout*
*
*
Here's the expandable_group_item:

?xml version=1.0 encoding=utf-8?
selector xmlns:android=http://schemas.android.com/apk/res/android;
 
   item  
   android:state_window_focused=false
   android:drawable=@android:color/transparent/ 
!-- Even though these two point to the same resource, have two states so 
the drawable will invalidate itself when coming out of pressed state. --
item 
android:drawable=@android:color/transparent 
android:state_pressed=true 
android:state_enabled=false 
android:state_focused=true/ 
 item 
android:drawable=@android:color/transparent 
android:state_enabled=false 
android:state_focused=true/ 
item 
android:drawable=@android:color/transparent 
android:state_pressed=true 
android:state_focused=true/ 
item 
android:drawable=@android:color/transparent 
android:state_pressed=true 
android:state_focused=false/ 
item 
 android:drawable=@android:color/transparent 
android:state_focused=true/
*!-- the default item --*
item 
android:drawable=@+drawable/gradient_dialog_header /
/selector

Am i missing something the in selector file?

regards,

On Monday, February 27, 2012 3:41:04 PM UTC, Kostya Vasilyev wrote:

  On 02/27/2012 07:25 PM, Bluemercury wrote: 

 Hi again Kostya, seems that the cursor focus isnt working althought that's 
 not the most important thing it still is default behaviour so im wondering 
 why it doesnt work. Also the extra layout was something like this?: 

  
 LinearLayout android:id=@+id/LinearLayout01
  android:layout_width=fill_parent 
  android:layout_height=45dip
  
 xmlns:android=http://schemas.android.com/apk/res/android;http://schemas.android.com/apk/res/android
  *android:background=@drawable/expandable_group_item*
  *LinearLayout*
 *android:layout_width=fill_parent *
 * android:layout_height=fill_parent*
 * android:duplicateParentState=true*
  

 Right - that's the backgrounds stepping on each other that I mentioned 
 earlier.

 The extra layout should be set up like this:

 LinearLayout android:id=@+id/LinearLayout01
 android:layout_width=fill_parent 
 android:layout_height=45dip
 xmlns:android=http://schemas.android.com/apk/res/android;http://schemas.android.com/apk/res/android
 
 LinearLayout
android:layout_width=fill_parent 
 android:layout_height=fill_parent
 *android:background=@drawable/expandable_group_item*
 android:duplicateParentState=true

 The top-level layout will have its background modified by the expandable 
 list view, to show selected / pressed state.

 The second layout has your custom color / gradient, and because it becomes 
 transparent when the item is selected / pressed, the background of the 
 top-level item will show through.

 -- Kostya

  

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Re: [android-developers] Re: Long click in expandable list group items.

2012-02-27 Thread Bluemercury
Okay, even after those changes i still get the focus color behind the 
gradient background. i just putted round corners in the gradient and i can 
see it behindlet me show what i have now then:

*expandable_group_item.xml:*

?xml version=1.0 encoding=utf-8?
selector xmlns:android=http://schemas.android.com/apk/res/android;   
  
item  
 android:state_focused=true
 android:drawable=@android:color/transparent/ 
item  
  android:state_pressed=true 
  android:drawable=@android:color/transparent / 
!-- the default item --
 item 
android:drawable=@+drawable/gradient_dialog_header /
/selector

*expand_custom_row_group_layout.xml:*

LinearLayout
xmlns:android=http://schemas.android.com/apk/res/android;
android:id=@+id/LinearLayout01
android:layout_width=fill_parent 
android:layout_height=45dip
LinearLayout
android:layout_width=fill_parent 
android:layout_height=fill_parent
android:background=@drawable/expandable_group_item
android:duplicateParentState=true
TextView 
android:id=@+id/tvGroup 
android:layout_width=fill_parent
android:layout_height=45dip 
android:text=Groups 
android:gravity=center_vertical|right
android:paddingLeft=5dip 
android:paddingRight=5dip
android:textColor=# 
android:textStyle=bold
android:textSize=17dip 
/TextView
/LinearLayout
/LinearLayout

*gradient_dialog_header:*

?xml version=1.0 encoding=utf-8?
!--  gradient used for grey header view element to match original android 
default type--
shape 
xmlns:android=http://schemas.android.com/apk/res/android;
android:shape=rectangle
gradient
 android:startColor=#C4D82D
 android:endColor=#99A923
 android:angle=90 /
corners 
android:bottomRightRadius=7dp 
android:bottomLeftRadius=7dp
android:topLeftRadius=7dp 
android:topRightRadius=7dp /
/shape



regards,



On Monday, February 27, 2012 3:58:51 PM UTC, Kostya Vasilyev wrote:

  On 02/27/2012 07:53 PM, Bluemercury wrote: 


  Am i missing something the in selector file?

  regards,


 Yes - the selector should only use @andorid:color/transparent for 
 state_pressed or state_focused true. Something like:

  ?xml version=1.0 encoding=utf-8?
 selector 
 xmlns:android=http://schemas.android.com/apk/res/android;http://schemas.android.com/apk/res/android
 
item   
android:state_focused=true
android:drawable=@android:color/transparent/ 
item   
 android:state_pressed=true 
 android:drawable=@android:color/transparent / 
 *!-- the default item --* 
 item 
 android:drawable=@+drawable/gradient_dialog_header /
 /selector
  
 This is it, no other items or states.

 What this does is - lets the framework's list item background show through 
 when the item is pressed or focused, and shows your own gradient when it's 
 not.

 -- Kostya

  

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Re: [android-developers] Re: Long click in expandable list group items.

2012-02-27 Thread Bluemercury
Ahh that was it, you only need the state_pressed and state_selected it 
seems, i had pressed and focused.
Many thanks, this was very useful. Still i have the impression this should 
be more simple than it actually is. :)

regards, 

On Monday, February 27, 2012 4:18:27 PM UTC, Kostya Vasilyev wrote:

 On 02/27/2012 08:13 PM, Bluemercury wrote:
  Okay, even after those changes i still get the focus color behind the 
  gradient background. i just putted round corners in the gradient and i 
  can see it behindlet me show what i have now then:
 Here is my selector:

 ?xml version=1.0 encoding=utf-8?
 selector xmlns:android=http://schemas.android.com/apk/res/android;

 item android:drawable=@android:color/transparent 
 android:state_pressed=true/
 item android:drawable=@android:color/transparent 
 android:state_selected=true/
 item android:drawable=@color/message_list_read_background_dark/

 /selector

 I think you're missing android:state_selected in yours. Sorry about the 
 confusion - I was typing from memory and just now went to look at the code.

 -- Kostya



-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] Using Multiple selection List with different events for click in the item list or the checkbox

2012-01-04 Thread Bluemercury
Hi There! So im trying to create a multiple selection list with checkboxes 
and im using the arrayadapter with 
the R.layout.simple_list_item_multiple_choice option:

public static ArrayAdapter? listMultipleSelectionAdapterArray(List? 
elements, Context cont){
 ArrayAdapter? newAdapter=new ArrayAdapter(cont, 
android.R.layout.simple_list_item_multiple_choice,elements);
 return newAdapter;
}

This works fine, but i was wondering if its possible to separate the item 
list click event from the checkbox one?Like if i click in the item i will 
go to another screen and clicking above the check will change its state.

regards,

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] Re: Using Multiple selection List with different events for click in the item list or the checkbox

2012-01-04 Thread Bluemercury
No one?i created a custom arrayadapter but i dont know if i can get all 
checked items without any connection to the custom row that has the 
checkbox...

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] getLastNonConfigurationInstace returns null if task is launched from a Spinner OnItemSelectedListener

2011-12-21 Thread Bluemercury
Hi all! so currently i have an activity that laucnhes an async task from 
inside the spinner onItemSelected method with the select int year value:

spinYears.setOnItemSelectedListener(
 new OnItemSelectedListener() {

@Override
public void onItemSelected(AdapterView? item, View arg1,
int arg2, long arg3) {

yearSelected=(Integer) item.getSelectedItem(); 
doAsyncTask();

}

@Override
public void onNothingSelected(AdapterView? arg0) {
// TODO Auto-generated method stub

}});

*here's the doAsyncTask method:*

/**
 * do asynctask for background work
 */
public void doAsyncTask(){
//get task back in case of rotation
task= (QuadrosMobileActivityTask?, ?, ?)getLastNonConfigurationInstance();

if(task==null){ 
 task=new PeriodoFeriasDbAsyncTask(this);
((PeriodoFeriasDbAsyncTask)task).execute(yearSelected);
}else{
task.attach(this);
}
}


if i rotate the phone the task runs again, but if i put the doAsyncTask() 
method call outside of the listener it works as it should.any reason 
for this?why would calling a task inside the spinner listener be different?

regards,


-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Re: [android-developers] AsyncTask null exception for the activity reference in the doInBackground method while rotating.

2011-11-18 Thread Bluemercury
Hi there! Sorry for posting here again, but i was hoping if i could try 
this sample, you said to put the synchronized in the detach method here:

void detach() {
*activity=null;*
}

in the asynctask, is this correct?but detach() is only called in the 
activity and not the in the async task itself, i thought synchronized 
methods assumed that they're both launched from 2 different threadsbut 
in this case the activity(UI thread) calls the detach method like you said, 
but the async task doesnt, only the attach method...

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] Re: AsyncTask null exception for the activity reference in the doInBackground method while rotating.

2011-10-27 Thread Bluemercury
What about extending the async task and then implement the logic directly 
in the doInbackground method?

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Re: [android-developers] Re: AsyncTask null exception for the activity reference in the doInBackground method while rotating.

2011-10-27 Thread Bluemercury
Yes i have a indeterminate progressBar in the header, the spinner one, but 
im using broadcast to all the activities which have the spinner to show or 
hide it if there's a task running in the background :


@Override
protected void onPreExecute() {
Logger.write(QuadrosMobileActivityTask ,  AsyncTask pre execution + 
Current Activity: +activity.getClass().getName(), Logger.INFO);

Intent broadcast = new Intent();
broadcast.setAction(SHOW_PROGRESSBAR);
mApp.sendBroadcast(broadcast);
mApp.setProgressBarInitialState(ProgressBar.VISIBLE);
} 

@Override
protected Object doInBackground(Void... params) {
 *do{*
* SystemClock.sleep(50); *
* }while(activity==null);*
*
*
* Logger.write(QuadrosMobileActivityTask ,  AsyncTask background 
initialized +Current Activity: +activity.getClass().getName(), 
Logger.INFO);*
* return activity.doBackGroundRequest();//method implemented by all sub 
activities*
}


@Override
protected void onPostExecute(Object result) {

if(activity!=null){
Logger.write(QuadrosMobileActivityTask ,  AsyncTask post execution 
+Current Activity: +activity.getClass().getName(), Logger.INFO);
 //update results
activity.updateResultsInUi(result);
 mApp.getAsyncTasks().remove(this); 

//check if there's more tasks in the collection
if(mApp.getAsyncTasks().isEmpty()){
Intent broadcast = new Intent();
broadcast.setAction(HIDE_PROGRESSBAR);
mApp.sendBroadcast(broadcast);
mApp.setProgressBarInitialState(ProgressBar.GONE);
 }
}
 }

the bold text is the one that gives problems.but in the pre and post 
there's no problem having the activity reference...


-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Re: [android-developers] Re: AsyncTask null exception for the activity reference in the doInBackground method while rotating.

2011-10-27 Thread Bluemercury
Hi there! Yes i removed the code from  activity.doBackgroundRequest to the 
extending Async Tasks doInBackground, i think it might solve this, BUT i 
will se the thread synchronization topic.
Thanks for the attention.

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] Re: AsyncTask null exception for the activity reference in the doInBackground method while rotating.

2011-10-26 Thread Bluemercury
No one?

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Re: [android-developers] AsyncTask null exception for the activity reference in the doInBackground method while rotating.

2011-10-26 Thread Bluemercury
yes the detach is called on the activity thread in the 
onReatainNonConfigurationInstance method...:

   *@Override*
* public Object onRetainNonConfigurationInstance() {*
* if(task!=null)*
* task.detach();*
*
*
* return(task);*
* }*

And here's the method that attachs the activity back to the thread:
/**
 * do asynctask for background work
 */
public void doAsyncTask(){
//get task back in case of rotation
task= (QuadrosMobileActivityTask)getLastNonConfigurationInstance();

if(task==null){
task= new QuadrosMobileActivityTask(this);
task.execute();
//add to the set of tasks
QuadrosMobileApplicationContext appliContext= 
(QuadrosMobileApplicationContext)getApplicationContext();
appliContext.getAsyncTasks().add(task);
}else{
task.attach(this);
}
}

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] Re: AsyncTask null exception for the activity reference in the doInBackground method while rotating.

2011-10-26 Thread Bluemercury
Well the thing is, this Asynctask is binded to a parent activity, that the 
subactivities use when they want  to do some background work. They each 
implement the method you see in the code i've posted, the *
activity.doBackGroundRequest(); *
I've actually had errors even after the line if(activity!=null)...so how 
can i synchronized the code...

regards,

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] Re: AsyncTask null exception for the activity reference in the doInBackground method while rotating.

2011-10-26 Thread Bluemercury
Also wouldnt using the activity.getApplicationContext() result in the same 
problem??? if activity is null i would stil lget the null exception???

regards,

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] Re: AsyncTask null exception for the activity reference in the doInBackground method while rotating.

2011-10-26 Thread Bluemercury
yes, but how can i get the method from the activity that contains the logic 
to do in the background from the context, is this possible? im getting null 
exception for the activity after verifying if the activity is not null:

   if(activity!=null){
return activity.doBackGroundRequest();
}else{
Logger.write(QuadrosMobileActivityTask , AsyncTask finished while no 
Activity was attached., Logger.INFO);
return null;}

}

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Re: [android-developers] Re: AsyncTask null exception for the activity reference in the doInBackground method while rotating.

2011-10-26 Thread Bluemercury
How so? each activity launches its own async task with its own specific 
logicwhen you rotate you just detach the current activity from the 
async task, the activity gets destroyed, a new one is created and attached 
to the SAME async task  

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] Re: AsyncTask null exception for the activity reference in the doInBackground method while rotating.

2011-10-26 Thread Bluemercury
Hey Skyler, thanks for the link. so i need to get rid of activity reference 
on the doInBackground...i assume its possible to use the activity reference 
in the preExecute and post

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] Re: AsyncTask null exception for the activity reference in the doInBackground method while rotating.

2011-10-26 Thread Bluemercury
Hi again skyler, thanks for the reply, yes the code im using in the 
doInBackground deals with the logic i want to do in the background that 
each activity has, in this case the method doBackgroundRequest is the 
method every activity uses if it wants to use an async task...but it seems 
this structure needs to be altered

regards,

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] AsyncTask null exception for the activity reference in the doInBackground method while rotating.

2011-10-25 Thread Bluemercury
So im using an AsyncTask but i'm getting random null exceptions for the 
activity reference in the doInBackground method. Anyway here's the non 
inner public async task:

public class QuadrosMobileActivityTask extends AsyncTaskVoid, Void, 
Object{
 *protected QuadrosMobileActivity activity=null;*
protected QuadrosMobileApplicationContext mApp;

public QuadrosMobileActivityTask(*QuadrosMobileActivity activity*) {

attach(*activity*);
mApp=(QuadrosMobileApplicationContext)* activity.getApplication()*;
}

@Override
protected void onPreExecute() {
Logger.write(QuadrosMobileActivityTask ,  AsyncTask pre execution + 
Current Activity: +*activity.getClass().getName()*, Logger.INFO);

Intent broadcast = new Intent();
broadcast.setAction(SHOW_PROGRESSBAR);
mApp.sendBroadcast(broadcast);
mApp.setProgressBarInitialState(ProgressBar.VISIBLE);
} 

@Override
protected Object doInBackground(Void... params) {

if(*activity!=null*){
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
Logger.write(QuadrosMobileActivityTask ,  AsyncTask background 
initialized +Current Activity: 
+*activity.getClass().getName(),*Logger.INFO); 
return *activity.doBackGroundRequest(); --getting random null exceptions 
for activity reference*
}else{
Logger.write(QuadrosMobileActivityTask , AsyncTask finished while no 
Activity was attached., Logger.INFO);
return null;}

}


@Override
protected void onPostExecute(Object result) {

if(*activity!=null*){
Logger.write(QuadrosMobileActivityTask ,  AsyncTask post execution 
+Current Activity: +*activity.getClass().getName()*, Logger.INFO);
 //update results
*activity.updateResultsInUi(result);*
 mApp.getAsyncTasks().remove(this); 

//check if there's more tasks in the collection
if(mApp.getAsyncTasks().isEmpty()){
Intent broadcast = new Intent();
broadcast.setAction(HIDE_PROGRESSBAR);
mApp.sendBroadcast(broadcast);
mApp.setProgressBarInitialState(ProgressBar.GONE);
 }
}
 }

void detach() {
*activity=null;*
}

void attach(QuadrosMobileActivity *activity*) {
*this.activity=activity;*
}
}

Is there any reason this should even happen???does the sleep timer is 
really necessary for waiting after the rotation is finished?

regards,

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Re: [android-developers] Re: runOnUIThread method in doInBackground of Async Task...

2011-10-04 Thread Bluemercury
The only static variable in use is an int, for maintaining the state of a 
progress bar while switching activities. the updateResultsinUi() is an 
abstract method tha is implemented by sub activties classes.

regards,

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] runOnUIThread method in doInBackground of Async Task...

2011-10-03 Thread Bluemercury
Hi! im using an Async-Task and currently im using runOnUiThread in the 
doInBackground method to refresh activities UI, this seems to be working but 
on rotation it loses the data and im usng the 
getLastNonConfigurationInstance and the onRetainNonConfigurationInstance 
methods, here's the parent class method that calls the async task:


/**
 * do asynctask for background work
 */
public void doAsyncTask(){
//get task back in case of rotation
task= (QuadrosMobileActivityTask)getLastNonConfigurationInstance();

if(task==null){
task= new QuadrosMobileActivityTask(this);
task.execute();
//add to the set of tasks
QuadrosMobileApplicationContext appliContext= 
(QuadrosMobileApplicationContext)getApplicationContext();
appliContext.getAsyncTasks().add(task);
}else{
task.attach(this);
}
}

Here's the async task as normal class(non inner class) main methods;

   @Override
protected void onPreExecute() {
Logger.write(QuadrosMobileActivityTask ,  AsyncTask pre execution + 
Current Activity: +activity.getClass().getName(), Logger.INFO);

if(QuadrosMobileActivity.themeId!=R.style.CustomThemeNoHeader){
activity.findViewById(R.id.progressView).setVisibility(ProgressBar.VISIBLE);
}
QuadrosMobileActivity.progressBarstate=ProgressBar.VISIBLE;
} 

@Override
protected String doInBackground(Void... params) {
Logger.write(QuadrosMobileActivityTask , initialized, Logger.INFO);
return activity.*updateResultsInUi()*;
}

@Override
protected void onPostExecute(String result) {
Logger.write(QuadrosMobileActivityTask ,  AsyncTask post execution 
+Current Activity: +activity.getClass().getName(), Logger.INFO);

if(activity!=null)
Toast.makeText(activity, result, Toast.LENGTH_LONG).show();
//remove this task from collection
QuadrosMobileApplicationContext appliContext= 
QuadrosMobileApplicationContext.getInstance();
appliContext.getAsyncTasks().remove(this); 

//check if there's more tasks in the collection
if(appliContext.getAsyncTasks().isEmpty()){
if(QuadrosMobileActivity.themeId!=R.style.CustomThemeNoHeader){
activity.findViewById(R.id.progressView).setVisibility(ProgressBar.GONE);
}
QuadrosMobileActivity.progressBarstate=ProgressBar.GONE;
}
}

And the sub activities *updateResultsInUi() *method:

runOnUiThread(
 new Runnable() {

@Override
public void run() { 
((TextView)findViewById(R.id.nome_value)).setText(quadro.getNome());
//((TextView)findViewById(R.id.nif_value)).setText(quadro.getDadosPessoais().getNumeroContribuinte());
((TextView)findViewById(R.id.datanasc_value)).setText(DateTimeZoneUtils.getInstance().sqlLiteDateTimeFormat(quadro.getDadosPessoais().getDataNascimento()));
((TextView)findViewById(R.id.provincia_value)).setText(quadro.getResidencia().getProvincia());
((TextView)findViewById(R.id.municipio_value)).setText(quadro.getResidencia().getMunicipio());
((TextView)findViewById(R.id.comuna_value)).setText(quadro.getResidencia().getComuna());
((TextView)findViewById(R.id.bairro_value)).setText(quadro.getResidencia().getBairro());
((TextView)findViewById(R.id.rua_value)).setText(quadro.getResidencia().getRua());
}
}
);

Can i use the runOnUIThread method inside the doInBackground method of 
AsyncTask??
regards,

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] Async Task, rotation and indeterminate progressbar in custom header.

2011-09-23 Thread Bluemercury
Hi! So i've been trying to get a solution for a very specific problem that 
involves using Async tasks and dealing with the rotation and also a custom 
header that contains a progressbar view(the small spinner one, including a 
text view saying Loading...). I've followed 
thishttps://github.com/commonsguy/cw-android/blob/master/Rotation/RotationAsync/src/com/commonsware/android/rotation/async/RotationAsync.java
 example 
to deal with the async tasks and the rotation, but i still have the problem 
of the progressbar, if activity A launches a task and i imediately go to 
activitity B, the progress bar in activity B should still appear visibile 
even though the task was launched from activity A, how do i this without a 
static reference for the progressbar view?, the postexecute method of the 
async have to consider the possibility that the progressbar reference should 
now be in another activity, right?
Here's my code for my parent activity where subactivities extend from:

public abstract class ParentClass extends Activity{

protected static ProgressBar progressHeader = null;
protected static TextView progressLoading = null;;

protected static int progressBarstate=ProgressBar.GONE;
protected static int themeId;

private ProgressBarThread task=null;

//this method will get the id for the layout 
public abstract int getLayoutId();
//this method will launch respejcting oncreate logic for each activity 
public abstract void initActivity();
//thi smethod will return window header menu context text string
public abstract String getWindowTitle();
//this method is used to refresh contents for a screen
public abstract void updateResultsInUi();
//nethod for definined specific theme 
public abstract int getThemeId();


@Override
protected void onCreate(Bundle savedInstanceState) {


//set theme first for showing correct header
setTheme(getThemeId());

super.onCreate(savedInstanceState);

themeId=getThemeId();
//in case the screen will have a header
if(getThemeId()!=R.style.CustomThemeNoHeader){

requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);

setContentView(getLayoutId());

getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, 
R.layout.custom_window_title);

//set text header
((TextView)findViewById(R.id.header_title)).setText(getWindowTitle());

progressRefreshState(progressBarstate);

}else
{
setContentView(getLayoutId());
}

//execute subactivity logic
initActivity();

}

/**
 * check for loading/spinner icon in
 *  case there's a thread working in background
 */
@Override
public void onRestart () {
super.onRestart();
if(getThemeId()!=R.style.CustomThemeNoHeader){
//Toast.makeText(this, visible(0):  + ProgressBar.VISIBLE+ : Current : + 
getProgressBarstate(), Toast.LENGTH_LONG).show();
progressRefreshState(progressBarstate);

}
}


@Override
public Object onRetainNonConfigurationInstance() {
if(task!=null)
task.detach();

return(task);
}

/**
 * refresh static references for both progress 
 * info views and set visibility state
 */
private void progressRefreshState(int state) {

progressHeader  = (ProgressBar) findViewById(R.id.progresspinner);
progressLoading = (TextView) findViewById(R.id.progresstext); 

progressHeader .setVisibility(state);
progressLoading.setVisibility(state);
}

//todo change location for getting session
protected String getSession(){

LogInManager login=new LogInManager(ParentClass.this);
try {
boolean session=login.getNewSession(
QuadrosMobileApplicationContext.getInstance().getUser(),
QuadrosMobileApplicationContext.getInstance().getPass());

if(session)
return getString(R.string.login_sucessful);
else
return getString(R.string.login_failed);
} catch (RequestException e) {
return e.getMessage();
}
}

/**
 * do asynctask for background work
 */
public void doAsyncTask(){

task= (ProgressBarThread)getLastNonConfigurationInstance();

if(task==null){
task= new ProgressBarThread(this);
task.execute();
//add to the set of tasks
QuadrosMobileApplicationContext appliContext= 
(QuadrosMobileApplicationContext)getApplicationContext();
appliContext.getAsyncTasks().add(task);
}else{
task.attach(this);
}
}


static public class ProgressBarThread extends AsyncTaskVoid, Void, Void{
ParentClass activity=null;



public ProgressBarThread(ParentClass activity) {

attach(activity);
}

@Override
protected void onPreExecute() {
Logger.write(ProgressBarThread ,  AsyncTask pre execution , 
Logger.INFO);

if(themeId!=R.style.CustomThemeNoHeader){
progressHeader.setVisibility(ProgressBar.VISIBLE);
progressLoading.setVisibility(ProgressBar.VISIBLE);
}
progressBarstate=ProgressBar.VISIBLE;
} 

@Override
protected Void doInBackground(Void... params) {
Logger.write(ProgressBarThread , initialized, Logger.INFO);
activity.updateResultsInUi();
Logger.write(ProgressBarThread , Finish, Logger.INFO);
return null;
}

@Override
protected void onPostExecute(Void result) {
Logger.write(ProgressBarThread ,  AsyncTask post execution , 
Logger.INFO);

//remove this task from collection
QuadrosMobileApplicationContext 

[android-developers] Re: Async Task, rotation and indeterminate progressbar in custom header.

2011-09-23 Thread Bluemercury
IS there a way to avoid the static references to the views, but at the same 
time giving the possibility of the tasks to change the visibility of the 
progressbar even if the current activity visible is not the one who laucnhed 
the task initially?

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] Re: AsyncTask and screen rotation

2011-09-22 Thread Bluemercury
Hi there! CAn you share your code for this combination? Right now im using 
an async task in my parent activity to launch threads, i also have a custom 
header with a progressbar(indeterminate) where my threads change its state. 
Right now this seems to be working, but the problem arises when i rotate the 
phone. Im trying to use the onConfigurationChanged method to deal with the 
image on the custom header that is different for the landspace layout, i and 
i seem to have managed it. The problem is the screen layouts, i cant seem to 
make them appear like when the activity is recreated again


-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Re: [android-developers] Re: AsyncTask and screen rotation

2011-09-22 Thread Bluemercury
How do you something like this:

Heres my onCreate of the parent activity:

protected void onCreate(Bundle savedInstanceState) {


//set theme first for showing correct header
setTheme(getThemeId());

super.onCreate(savedInstanceState);

themeId=getThemeId();
//in case the screen will have a header
if(getThemeId()!=R.style.CustomThemeNoHeader){

requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);

setContentView(getLayoutId());

getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, 
R.layout.custom_window_title);

//set text header
((TextView)findViewById(R.id.header_title)).setText(getWindowTitle());

progressRefreshState(getProgressBarstate());

}else
{
setContentView(getLayoutId());
}

//execute subactivity logic
initActivity();

}


And here's the onConfigurationChanged:

public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);

 ImageView header = (ImageView) this.findViewById(R.id.header);
 LinearLayout container=(LinearLayout)findViewById(R.id.layout);
 
 if(header!=null)
header.setImageDrawable(getResources().getDrawable(R.drawable.top_green_header_image));

 //setContentView(getLayoutId())
if (newConfig.orientation==Configuration.ORIENTATION_LANDSCAPE) { 
container.setOrientation(LinearLayout.HORIZONTAL);
}
else {
 container.setOrientation(LinearLayout.VERTICAL);
}
}

The linearlayout variable is the id i gave to the xml linearlaouts for the 
full screen but its not working correctly like if restart the activity

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en