Eric Kok
12 years ago
14 changed files with 231 additions and 133 deletions
@ -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" /> |
@ -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,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> |
@ -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; |
||||
} |
||||
|
||||
} |
@ -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); |
||||
} |
||||
|
||||
} |
@ -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."); |
||||
} |
||||
} |
||||
|
||||
} |
@ -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; |
||||
} |
||||
|
||||
} |
@ -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; |
||||
} |
||||
|
||||
} |
Loading…
Reference in new issue