Created
June 24, 2011 16:25
-
-
Save arnaudbos/1045133 to your computer and use it in GitHub Desktop.
(Robo)ActivityGroup holding one child activity at a time in a specified view container.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:panel="http://schemas.android.com/apk/res/uk.ac.brookes.arnaudbos.luscinia" | |
android:orientation="vertical" | |
android:layout_width="fill_parent" | |
android:layout_height="fill_parent" | |
android:background="@drawable/background" | |
> | |
<com.markupartist.android.widget.ActionBar | |
android:id="@+id/actionbar" | |
style="@style/ActionBar" | |
/> | |
<RelativeLayout | |
android:layout_width="fill_parent" | |
android:id="@+id/internal_content" | |
android:layout_height="fill_parent" | |
> | |
<org.miscwidgets.widget.Panel | |
android:layout_alignParentLeft="true" | |
android:gravity="center_vertical" | |
android:layout_width="wrap_content" | |
android:layout_height="fill_parent" | |
android:id="@+id/leftPanel" | |
android:paddingRight="4dip" | |
panel:handle="@+id/panelHandle" | |
panel:content="@+id/panelContent" | |
panel:position="left" | |
panel:openedHandle="@drawable/left_switcher_expanded_background" | |
panel:closedHandle="@drawable/left_switcher_collapsed_background" | |
panel:weight="100%p" | |
> | |
<Button | |
android:id="@+id/panelHandle" | |
android:layout_width="24dip" | |
android:layout_height="40dip" | |
/> | |
<LinearLayout | |
android:layout_weight="1" | |
android:layout_width="fill_parent" | |
android:layout_height="fill_parent" | |
android:orientation="horizontal" | |
android:id="@+id/panelContent" | |
> | |
<ScrollView | |
android:padding="4dip" | |
android:background="@drawable/background" | |
android:layout_alignTop="@+id/border_right" | |
android:layout_toLeftOf="@+id/border_right" | |
android:layout_height="fill_parent" | |
android:layout_weight="1" | |
android:layout_width="fill_parent" | |
> | |
<RelativeLayout | |
android:layout_width="fill_parent" | |
android:layout_height="wrap_content" | |
> | |
</RelativeLayout> | |
</ScrollView> | |
<LinearLayout | |
android:layout_width="1dip" | |
android:layout_height="fill_parent" | |
android:background="@color/brown" | |
> | |
</LinearLayout> | |
</LinearLayout> | |
</org.miscwidgets.widget.Panel> | |
<org.miscwidgets.widget.Panel | |
android:layout_alignParentBottom="true" | |
android:gravity="center_horizontal" | |
android:layout_width="fill_parent" | |
android:layout_height="wrap_content" | |
android:id="@+id/bottomPanel" | |
android:paddingTop="4dip" | |
panel:handle="@+id/panelHandle" | |
panel:content="@+id/panelContent" | |
panel:position="bottom" | |
panel:openedHandle="@drawable/bottom_switcher_expanded_background" | |
panel:closedHandle="@drawable/bottom_switcher_collapsed_background" | |
panel:height="154" | |
> | |
<Button | |
android:id="@+id/panelHandle" | |
android:layout_width="40dip" | |
android:layout_height="24dip" | |
/> | |
<LinearLayout | |
android:layout_width="fill_parent" | |
android:layout_height="wrap_content" | |
android:orientation="vertical" | |
android:id="@+id/panelContent" | |
> | |
<LinearLayout | |
android:layout_width="fill_parent" | |
android:layout_height="1dip" | |
android:background="@color/brown" | |
> | |
</LinearLayout> | |
<HorizontalScrollView | |
android:layout_width="fill_parent" | |
android:layout_height="wrap_content" | |
android:background="@drawable/background" | |
> | |
<LinearLayout | |
android:id="@+id/tracks" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:orientation="horizontal" | |
android:layout_gravity="left" | |
> | |
</LinearLayout> | |
</HorizontalScrollView> | |
</LinearLayout> | |
</org.miscwidgets.widget.Panel> | |
</RelativeLayout> | |
</LinearLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package uk.ac.brookes.arnaudbos.luscinia.views; | |
import java.util.ArrayList; | |
import java.util.List; | |
import org.miscwidgets.widget.EasingType.Type; | |
import org.miscwidgets.widget.ExpoInterpolator; | |
import org.miscwidgets.widget.Panel; | |
import roboguice.inject.InjectExtra; | |
import roboguice.inject.InjectResource; | |
import roboguice.inject.InjectView; | |
import uk.ac.brookes.arnaudbos.luscinia.R; | |
import uk.ac.brookes.arnaudbos.luscinia.utils.TemplateActivityMapper; | |
import uk.ac.brookes.arnaudbos.luscinia.widget.DocumentView; | |
import uk.ac.brookes.arnaudbos.luscinia.widget.FolderActivityGroup; | |
import android.content.Intent; | |
import android.os.Bundle; | |
import android.view.Menu; | |
import android.view.MenuItem; | |
import android.view.MenuItem.OnMenuItemClickListener; | |
import android.view.View; | |
import android.view.View.OnClickListener; | |
import android.widget.LinearLayout; | |
import android.widget.RelativeLayout; | |
import android.widget.Toast; | |
import com.markupartist.android.widget.ActionBar; | |
import com.markupartist.android.widget.ActionBar.Action; | |
public class FolderActivity extends FolderActivityGroup | |
{ | |
@InjectExtra("folder") private String folder; | |
@InjectResource(R.string.patient_title) private String patientTitle; | |
@InjectView(R.id.actionbar) private ActionBar actionBar; | |
@InjectView(R.id.internal_content) private RelativeLayout internalContentLayout; | |
@InjectView(R.id.tracks) private LinearLayout documentsTrack; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) | |
{ | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.folder); | |
this.setTargetLayout(internalContentLayout); | |
prepareActionBar(); | |
prepareDocumentsTrack(); | |
Panel panel = (Panel) findViewById(R.id.bottomPanel); | |
panel.setInterpolator(new ExpoInterpolator(Type.OUT)); | |
panel = (Panel) findViewById(R.id.leftPanel); | |
panel.setInterpolator(new ExpoInterpolator(Type.OUT)); | |
} | |
@Override | |
public boolean onCreateOptionsMenu(Menu menu) | |
{ | |
MenuItem item = menu.add("Dossier Médical Menu"); | |
item.setOnMenuItemClickListener(new OnMenuItemClickListener() | |
{ | |
@Override | |
public boolean onMenuItemClick(MenuItem item) | |
{ | |
return true; | |
} | |
}); | |
return getLocalActivityManager().getCurrentActivity().onCreateOptionsMenu(menu); | |
} | |
public boolean onPrepareOptionsMenu(Menu menu) | |
{ | |
menu.clear(); | |
return onCreateOptionsMenu(menu); | |
} | |
private void prepareActionBar() | |
{ | |
actionBar.setTitle(patientTitle+" "+folder); | |
actionBar.setHomeAction(new HomeAction()); | |
actionBar.addAction(new StubShareAction()); | |
actionBar.addAction(new StubSearchAction()); | |
} | |
private void prepareDocumentsTrack() | |
{ | |
//TODO | |
List<String> documents = new ArrayList<String>(); | |
documents.add("template-trans"); | |
documents.add("template-macrocible"); | |
for(final String template : documents) | |
{ | |
DocumentView doc = new DocumentView(this, getResources().getDrawable(R.drawable.no_folder_picture), template, null); | |
OnClickListener listener; | |
switch (TemplateActivityMapper.toActivity(template)) | |
{ | |
case TRANS: | |
listener = new OnClickListener() | |
{ | |
@Override | |
public void onClick(View v) | |
{ | |
startChildActivity(template, new Intent(FolderActivity.this, TransActivity.class)); | |
} | |
}; | |
doc.setOnClickListener(listener); | |
doc.setText("Transmission ciblée"); | |
break; | |
case MACROCIBLE: | |
listener = new OnClickListener() | |
{ | |
@Override | |
public void onClick(View v) | |
{ | |
startChildActivity(template, new Intent(FolderActivity.this, MacrocibleActivity.class)); | |
} | |
}; | |
doc.setOnClickListener(listener); | |
doc.setText("Fiche Macrocible"); | |
break; | |
case GENERIC: | |
default: | |
break; | |
} | |
documentsTrack.addView(doc); | |
} | |
startChildActivity("template-trans", new Intent(FolderActivity.this, TransActivity.class)); | |
} | |
private class HomeAction implements Action | |
{ | |
@Override | |
public void performAction(View view) | |
{ | |
Intent intent = new Intent(FolderActivity.this, DashboardActivity.class); | |
intent.putExtra("login", "osef"); | |
intent.putExtra("password", "osef"); | |
startActivity(intent); | |
FolderActivity.this.finish(); | |
} | |
@Override | |
public int getDrawable() | |
{ | |
return R.drawable.ic_title_home_default; | |
} | |
} | |
/** | |
* TODO: Stub class. Implement it. | |
*/ | |
private class StubShareAction implements Action | |
{ | |
@Override | |
public void performAction(View view) | |
{ | |
Toast.makeText(FolderActivity.this, "ShareAction", Toast.LENGTH_SHORT).show(); | |
} | |
@Override | |
public int getDrawable() | |
{ | |
return R.drawable.ic_title_share_default; | |
} | |
}; | |
/** | |
* TODO: Stub class. Implement it. | |
*/ | |
private class StubSearchAction implements Action | |
{ | |
@Override | |
public void performAction(View view) | |
{ | |
Toast.makeText(FolderActivity.this, "otherAction", Toast.LENGTH_SHORT).show(); | |
} | |
@Override | |
public int getDrawable() | |
{ | |
return R.drawable.ic_title_export_default; | |
} | |
}; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package uk.ac.brookes.arnaudbos.luscinia.widget; | |
import java.util.ArrayList; | |
import org.miscwidgets.widget.Panel; | |
import roboguice.activity.RoboActivityGroup; | |
import android.app.Activity; | |
import android.app.LocalActivityManager; | |
import android.content.Intent; | |
import android.os.Bundle; | |
import android.view.KeyEvent; | |
import android.view.ViewGroup; | |
import android.view.Window; | |
import android.widget.RelativeLayout; | |
public class FolderActivityGroup extends RoboActivityGroup | |
{ | |
private ArrayList<String> activityIdsList; | |
private ViewGroup targetLayout; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) | |
{ | |
super.onCreate(savedInstanceState); | |
if (activityIdsList == null) | |
{ | |
activityIdsList = new ArrayList<String> (); | |
} | |
} | |
@Override | |
public void finishFromChild(Activity child) | |
{ | |
LocalActivityManager manager = getLocalActivityManager(); | |
int index = activityIdsList.size()-1; | |
if (index < 1) | |
{ | |
finish(); | |
return; | |
} | |
manager.destroyActivity(activityIdsList.get(index), true); | |
activityIdsList.remove(index); | |
index--; | |
String lastId = activityIdsList.get(index); | |
Intent lastIntent = manager.getActivity(lastId).getIntent(); | |
Window newWindow = manager.startActivity(lastId, lastIntent); | |
targetLayout.removeViewAt(0); | |
targetLayout.addView(newWindow.getDecorView(), 0); | |
} | |
public void startChildActivity(String Id, Intent intent) | |
{ | |
Window window = getLocalActivityManager().startActivity(Id,intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)); | |
if (window != null) | |
{ | |
if(activityIdsList.contains(Id)) | |
{ | |
activityIdsList.remove(Id); | |
} | |
activityIdsList.add(Id); | |
if (!(targetLayout.getChildAt(0) instanceof Panel)) | |
{ | |
targetLayout.removeViewAt(0); | |
} | |
targetLayout.addView(window.getDecorView(), 0); | |
} | |
} | |
protected void setTargetLayout(RelativeLayout target) | |
{ | |
this.targetLayout = target; | |
} | |
@Override | |
final public boolean onKeyDown(int keyCode, KeyEvent event) | |
{ | |
if (keyCode == KeyEvent.KEYCODE_BACK) | |
{ | |
return true; | |
} | |
return super.onKeyDown(keyCode, event); | |
} | |
@Override | |
final public boolean onKeyUp(int keyCode, KeyEvent event) | |
{ | |
if (keyCode == KeyEvent.KEYCODE_BACK) | |
{ | |
onBackPressed(); | |
return true; | |
} | |
return super.onKeyUp(keyCode, event); | |
} | |
@Override | |
final public void onBackPressed () | |
{ | |
int length = activityIdsList.size(); | |
if ( length > 1) | |
{ | |
Activity current = getLocalActivityManager().getActivity(activityIdsList.get(length-1)); | |
current.finish(); | |
} | |
else | |
{ | |
finish(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment