Browse Source

Fixed dialog showing on small and large devices.

pull/11/head
Eric Kok 12 years ago
parent
commit
489fd94cd5
  1. 8
      core/res/layout/activity_dialogholder.xml
  2. 40
      core/res/layout/dialog_about.xml
  3. 15
      core/res/layout/dialog_changelog.xml
  4. 0
      core/res/menu/dialog_about.xml
  5. 11
      core/res/values/changelog.xml
  6. 42
      core/src/org/transdroid/core/gui/AboutFragment.java
  7. 91
      core/src/org/transdroid/core/gui/navigation/DialogHelper.java
  8. 53
      core/src/org/transdroid/core/gui/navigation/DialogHolderActivity.java
  9. 37
      core/src/org/transdroid/core/gui/settings/AboutDialog.java
  10. 37
      core/src/org/transdroid/core/gui/settings/ChangelogDialog.java
  11. 4
      core/src/org/transdroid/core/gui/settings/MainSettingsActivity.java
  12. 23
      core/src/org/transdroid/core/gui/settings/SystemSettingsActivity.java
  13. 2
      full/AndroidManifest.xml
  14. 1
      lite/AndroidManifest.xml

8
core/res/layout/activity_dialogholder.xml

@ -1,8 +0,0 @@ @@ -1,8 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- This layout is a simple wrapper to display dialogs (which might be show full screen, without border) -->
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/dialogholder"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".DialogHolderActivity" />

40
core/res/layout/fragment_about.xml → core/res/layout/dialog_about.xml

@ -3,46 +3,46 @@ @@ -3,46 +3,46 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_margin="@dimen/margin_default" >
android:padding="@dimen/margin_default" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="@string/app_name"
android:textSize="36sp"
android:textColor="@android:color/white"
android:fontFamily="sans-serif-condensed"
android:layout_marginBottom="@dimen/margin_half"
android:layout_marginTop="@dimen/margin_half"
android:drawableLeft="@drawable/ic_launcher"
android:drawablePadding="@dimen/margin_half"
android:layout_marginTop="@dimen/margin_half"
android:layout_marginBottom="@dimen/margin_half" />
android:fontFamily="sans-serif-condensed"
android:text="@string/app_name"
android:textColor="@android:color/white"
android:textSize="36sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="@string/system_description"
android:gravity="center" />
android:gravity="center"
android:text="@string/system_description" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="@dimen/margin_default"
android:fontFamily="sans-serif-condensed"
android:gravity="center"
android:text="@string/app_developer"
android:textColor="@android:color/white"
android:textSize="18sp"
android:fontFamily="sans-serif-condensed"
android:gravity="center" />
android:textSize="18sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="4dip"
android:layout_marginBottom="@dimen/margin_default"
android:text="@string/app_license"
android:gravity="center" />
android:layout_marginTop="4dip"
android:gravity="center"
android:text="@string/app_license" />
</LinearLayout>

15
core/res/layout/dialog_changelog.xml

@ -0,0 +1,15 @@ @@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="@dimen/margin_default"
android:fillViewport="true"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/system_changelog"
android:autoLink="web" />
</ScrollView>

0
core/res/menu/fragment_about.xml → core/res/menu/dialog_about.xml

11
core/res/values/changelog.xml

@ -0,0 +1,11 @@ @@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="system_changelog">
Transdroid 2.0.0-alpha1\n
- Totally reworked Holo-style interface\n
- Provide tablet interface on smaller tablets\n
- Automatically switch between local and remote IP configurations\n
\n
Older changes: http://www.transdroid.org/about/changelog/
</string>
</resources>

42
core/src/org/transdroid/core/gui/AboutFragment.java

@ -1,42 +0,0 @@ @@ -1,42 +0,0 @@
package org.transdroid.core.gui;
import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.EFragment;
import org.androidannotations.annotations.OptionsItem;
import org.androidannotations.annotations.OptionsMenu;
import android.app.Dialog;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.Window;
import com.actionbarsherlock.app.SherlockDialogFragment;
/**
* Fragment that shows info about the application developer and used open source libraries.
* @author Eric Kok
*/
@EFragment(resName="fragment_about")
@OptionsMenu(resName="fragment_about")
public class AboutFragment extends SherlockDialogFragment {
@AfterViews
protected void init() {
// TODO: Add list of used open source libraries
}
@OptionsItem(resName="action_visitwebsite")
protected void visitWebsite() {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://transdroid.org")));
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
// Allow presenting of this fragment as a dialog
Dialog dialog = super.onCreateDialog(savedInstanceState);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
return dialog;
}
}

91
core/src/org/transdroid/core/gui/navigation/DialogHelper.java

@ -0,0 +1,91 @@ @@ -0,0 +1,91 @@
package org.transdroid.core.gui.navigation;
import java.io.Serializable;
import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.Extra;
import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.Window;
import com.actionbarsherlock.app.SherlockActivity;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuInflater;
import com.actionbarsherlock.view.MenuItem;
/**
* Helper class that show a dialog either as pop-up or as full screen activity. Should be used by calling
* {@link #showDialog(Context, DialogSpecification)} with in instance of the dialog specification that should be shown,
* from the calling activity's {@link Activity#onCreateDialog(int)}.
* @author Eric Kok
*/
@EActivity
public class DialogHelper extends SherlockActivity {
@Extra
protected DialogSpecification dialog;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(dialog.getDialogLayoutId());
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater menuInflater = getSupportMenuInflater();
menuInflater.inflate(dialog.getDialogMenuId(), menu);
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
return dialog.onMenuItemSelected(this, item.getItemId());
}
/**
* Call this from {@link Activity#onCreateDialog(int)}, supplying an instance of the {@link DialogSpecification}
* that should be shown to the user.
* @param context The activity that calls this method and which will own the constructed dialog
* @param dialog An instance of the specification for the dialog that needs to be shown
* @return Either an instance of a {@link Dialog} that the activity should further control or null if the dialog
* will instead be opened as a full screen activity
*/
public static Dialog showDialog(Context context, DialogSpecification dialog) {
// If the device is large (i.e. a tablet) then return a dialog to show
if (!NavigationHelper_.getInstance_(context).isSmallScreen())
return new PopupDialog(context, dialog);
// This is a small device; create a full screen dialog (which is just an activity)
DialogHelper_.intent(context).dialog(dialog).start();
return null;
}
/**
* A specific dialog that shows some layout (resource) as contents. It has no buttons or other chrome.
*/
protected static class PopupDialog extends Dialog {
public PopupDialog(Context context, DialogSpecification dialog) {
super(context);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(dialog.getDialogLayoutId());
}
}
/**
* Specification for some dialog that can be show to the user, consisting of a custom layout and possibly an action
* bar menu. Warning: the action bar, and thus the menu options, is only shown when the dialog is presented as full
* screen activity. Use only for unimportant actions.
*/
public interface DialogSpecification extends Serializable {
int getDialogLayoutId();
int getDialogMenuId();
boolean onMenuItemSelected(Activity ownerActivity, int selectedItemId);
}
}

53
core/src/org/transdroid/core/gui/navigation/DialogHolderActivity.java

@ -1,53 +0,0 @@ @@ -1,53 +0,0 @@
package org.transdroid.core.gui.navigation;
import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.Extra;
import org.transdroid.core.gui.log.Log;
import android.content.Context;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.FragmentTransaction;
import com.actionbarsherlock.app.SherlockFragmentActivity;
@EActivity(resName = "activity_dialogholder")
public class DialogHolderActivity extends SherlockFragmentActivity {
@Extra
protected String dialogType;
/**
* Use this method to show some dialog; it will show the dialog as full screen fragment on smaller devices. Use the
* DialogFragment's class here only; a new instance will be created by this holder activity.
*/
public static void showDialog(Context context, Class<? extends DialogFragment> dialogType) {
DialogHolderActivity_.intent(context).dialogType(dialogType.getName()).start();
}
@AfterViews
public void init() {
try {
// Instantiate an instance of the requested dialog
DialogFragment dialog = (DialogFragment) Class.forName(dialogType).newInstance();
// Determine if the dialog should be shown as full size screen
boolean isSmall = NavigationHelper_.getInstance_(this).isSmallScreen();
if (!isSmall) {
// Show as normal dialog
dialog.show(this.getSupportFragmentManager(), "about_dialog");
} else {
// Small device, so show the fragment full screen
FragmentTransaction ft = this.getSupportFragmentManager().beginTransaction();
// Note: the fragment is not added to the back stack, as this activity already is
ft.add(android.R.id.content, dialog).commit();
}
} catch (InstantiationException e) {
Log.e(this, "Tried to show a dialog of type " + dialogType + ", but that cannot be instantiated.");
} catch (IllegalAccessException e) {
Log.e(this, "Tried to show a dialog of type " + dialogType + ", but it is not accessible.");
} catch (ClassNotFoundException e) {
Log.e(this, "Tried to show a dialog of type " + dialogType + ", but that class doesn't exist.");
}
}
}

37
core/src/org/transdroid/core/gui/settings/AboutDialog.java

@ -0,0 +1,37 @@ @@ -0,0 +1,37 @@
package org.transdroid.core.gui.settings;
import org.transdroid.core.R;
import org.transdroid.core.gui.navigation.DialogHelper;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
/**
* Fragment that shows info about the application developer and used open source libraries.
* @author Eric Kok
*/
public class AboutDialog implements DialogHelper.DialogSpecification {
private static final long serialVersionUID = -4711432869714292985L;
@Override
public int getDialogLayoutId() {
return R.layout.dialog_about;
}
@Override
public int getDialogMenuId() {
return R.menu.dialog_about;
}
@Override
public boolean onMenuItemSelected(Activity ownerActivity, int selectedItemId) {
if (selectedItemId == R.id.action_visitwebsite) {
ownerActivity.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://transdroid.org")));
return true;
}
return false;
}
}

37
core/src/org/transdroid/core/gui/settings/ChangelogDialog.java

@ -0,0 +1,37 @@ @@ -0,0 +1,37 @@
package org.transdroid.core.gui.settings;
import org.transdroid.core.R;
import org.transdroid.core.gui.navigation.DialogHelper;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
/**
* Fragment that shows recent app changes.
* @author Eric Kok
*/
public class ChangelogDialog implements DialogHelper.DialogSpecification {
private static final long serialVersionUID = -4563410777022941124L;
@Override
public int getDialogLayoutId() {
return R.layout.dialog_changelog;
}
@Override
public int getDialogMenuId() {
return R.menu.dialog_about;
}
@Override
public boolean onMenuItemSelected(Activity ownerActivity, int selectedItemId) {
if (selectedItemId == R.id.action_visitwebsite) {
ownerActivity.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://transdroid.org/about/changelog/")));
return true;
}
return false;
}
}

4
core/src/org/transdroid/core/gui/settings/MainSettingsActivity.java

@ -36,15 +36,13 @@ public class MainSettingsActivity extends SherlockPreferenceActivity { @@ -36,15 +36,13 @@ public class MainSettingsActivity extends SherlockPreferenceActivity {
@Bean
protected SearchHelper searchHelper;
@SuppressWarnings("deprecation")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Note: Settings are loaded in onResume()
}
@SuppressWarnings("deprecation")
@Override
protected void onResume() {
super.onResume();

23
core/src/org/transdroid/core/gui/settings/SystemSettingsActivity.java

@ -4,22 +4,23 @@ import org.androidannotations.annotations.Bean; @@ -4,22 +4,23 @@ import org.androidannotations.annotations.Bean;
import org.androidannotations.annotations.EActivity;
import org.transdroid.core.R;
import org.transdroid.core.app.settings.ApplicationSettings;
import org.transdroid.core.gui.AboutFragment;
import org.transdroid.core.gui.log.ErrorLogSender;
import org.transdroid.core.gui.navigation.DialogHolderActivity;
import org.transdroid.core.gui.navigation.DialogHelper;
import android.app.Dialog;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceClickListener;
import android.widget.Toast;
import com.actionbarsherlock.app.SherlockPreferenceActivity;
@EActivity
public class SystemSettingsActivity extends SherlockPreferenceActivity {
protected static final int DIALOG_CHANGELOG = 0;
protected static final int DIALOG_ABOUT = 1;
protected static final String INSTALLHELP_URI = "http://www.transdroid.org/download/";
@Bean
@ -59,20 +60,30 @@ public class SystemSettingsActivity extends SherlockPreferenceActivity { @@ -59,20 +60,30 @@ public class SystemSettingsActivity extends SherlockPreferenceActivity {
};
private OnPreferenceClickListener onChangeLogClick = new OnPreferenceClickListener() {
@SuppressWarnings("deprecation")
@Override
public boolean onPreferenceClick(Preference preference) {
// TODO: Implement change log screen
Toast.makeText(SystemSettingsActivity.this, "TODO: Implement change log screen", Toast.LENGTH_LONG).show();
showDialog(DIALOG_CHANGELOG);
return true;
}
};
private OnPreferenceClickListener onAboutClick = new OnPreferenceClickListener() {
@SuppressWarnings("deprecation")
@Override
public boolean onPreferenceClick(Preference preference) {
DialogHolderActivity.showDialog(SystemSettingsActivity.this, AboutFragment.class);
showDialog(DIALOG_ABOUT);
return true;
}
};
protected Dialog onCreateDialog(int id) {
switch (id) {
case DIALOG_CHANGELOG:
return DialogHelper.showDialog(this, new ChangelogDialog());
case DIALOG_ABOUT:
return DialogHelper.showDialog(this, new AboutDialog());
}
return null;
};
}

2
full/AndroidManifest.xml

@ -61,7 +61,7 @@ @@ -61,7 +61,7 @@
<activity android:name="org.transdroid.core.gui.settings.RssfeedSettingsActivity_" />
<activity android:name="org.transdroid.core.gui.settings.NotificationSettingsActivity_" />
<activity android:name="org.transdroid.core.gui.settings.SystemSettingsActivity_" />
<activity android:name="org.transdroid.core.gui.navigation.DialogHolderActivity_" />
<activity android:name="org.transdroid.core.gui.navigation.DialogHelper_" />
<!-- Search -->
<activity

1
lite/AndroidManifest.xml

@ -59,6 +59,7 @@ @@ -59,6 +59,7 @@
<activity android:name="org.transdroid.core.gui.settings.ServerSettingsActivity_" />
<activity android:name="org.transdroid.core.gui.settings.NotificationSettingsActivity_" />
<activity android:name="org.transdroid.core.gui.settings.SystemSettingsActivity_" />
<activity android:name="org.transdroid.core.gui.navigation.DialogHelper_" />
</application>

Loading…
Cancel
Save