new help activity, removing old code

This commit is contained in:
Dominik
2012-06-11 03:26:15 +03:00
parent ff4d0c26b9
commit 4f35355e8a
15 changed files with 409 additions and 351 deletions

View File

@@ -24,7 +24,7 @@ import java.util.Vector;
/**
* Singelton Implementation of a Preference Helper
*
*
*/
public class Preferences {
private static Preferences mPreferences;
@@ -135,26 +135,6 @@ public class Preferences {
editor.commit();
}
public boolean hasSeenChangeLog(String version) {
return mSharedPreferences.getBoolean(Constants.pref.HAS_SEEN_CHANGE_LOG + version, false);
}
public void setHasSeenChangeLog(String version, boolean value) {
SharedPreferences.Editor editor = mSharedPreferences.edit();
editor.putBoolean(Constants.pref.HAS_SEEN_CHANGE_LOG + version, value);
editor.commit();
}
public boolean hasSeenHelp() {
return mSharedPreferences.getBoolean(Constants.pref.HAS_SEEN_HELP, false);
}
public void setHasSeenHelp(boolean value) {
SharedPreferences.Editor editor = mSharedPreferences.edit();
editor.putBoolean(Constants.pref.HAS_SEEN_HELP, value);
editor.commit();
}
public String[] getKeyServers() {
String rawData = mSharedPreferences.getString(Constants.pref.KEY_SERVERS,
Constants.defaults.KEY_SERVERS);

View File

@@ -1,65 +0,0 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thialfihar.android.apg.ui;
import org.thialfihar.android.apg.R;
import org.thialfihar.android.apg.Constants;
import android.app.Activity;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;
public class AboutActivity extends Activity {
Activity mActivity;
/**
* Instantiate View for this Activity
*/
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.about_activity);
mActivity = this;
TextView versionText = (TextView) findViewById(R.id.about_version);
versionText.setText(getString(R.string.about_version) + " " + getVersion());
}
/**
* Get the current package version.
*
* @return The current version.
*/
private String getVersion() {
String result = "";
try {
PackageManager manager = mActivity.getPackageManager();
PackageInfo info = manager.getPackageInfo(mActivity.getPackageName(), 0);
result = String.format("%s (%s)", info.versionName, info.versionCode);
} catch (NameNotFoundException e) {
Log.w(Constants.TAG, "Unable to get application version: " + e.getMessage());
result = "Unable to get application version.";
}
return result;
}
}

View File

@@ -17,63 +17,146 @@
package org.thialfihar.android.apg.ui;
import org.thialfihar.android.apg.R;
import org.thialfihar.android.apg.util.Utils;
import com.actionbarsherlock.app.ActionBar;
import com.actionbarsherlock.app.SherlockActivity;
import com.actionbarsherlock.view.MenuItem;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.Html;
import android.text.method.LinkMovementMethod;
import android.support.v4.app.FragmentTransaction;
import android.widget.TextView;
public class HelpActivity extends SherlockActivity {
Activity mActivity;
TextView mHelpText;
import com.actionbarsherlock.app.ActionBar;
import com.actionbarsherlock.app.ActionBar.Tab;
import com.actionbarsherlock.view.MenuItem;
import java.util.ArrayList;
import android.content.Context;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import com.actionbarsherlock.app.SherlockFragmentActivity;
public class HelpActivity extends SherlockFragmentActivity {
ViewPager mViewPager;
TabsAdapter mTabsAdapter;
TextView tabCenter;
TextView tabText;
/**
* Menu Items
*/
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
startActivity(new Intent(this, MainActivity.class));
// app icon in Action Bar clicked; go home
Intent intent = new Intent(this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
return true;
default:
break;
return super.onOptionsItemSelected(item);
}
return false;
}
/**
* Instantiate View for this Activity
*/
@Override
protected void onCreate(Bundle savedInstanceState) {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.help_activity);
mViewPager = new ViewPager(this);
mViewPager.setId(R.id.pager);
final ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayShowTitleEnabled(true);
actionBar.setDisplayHomeAsUpEnabled(true);
setContentView(mViewPager);
ActionBar bar = getSupportActionBar();
bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
bar.setDisplayShowTitleEnabled(true);
bar.setDisplayHomeAsUpEnabled(true);
mActivity = this;
mTabsAdapter = new TabsAdapter(this, mViewPager);
mHelpText = (TextView) findViewById(R.id.help_text);
Bundle startBundle = new Bundle();
startBundle.putInt(HelpFragmentHtml.ARG_HTML_FILE, R.raw.help_start);
mTabsAdapter.addTab(bar.newTab().setText(getString(R.string.help_tab_start)),
HelpFragmentHtml.class, startBundle);
// load html from html file from /res/raw
String helpText = Utils.readContentFromResource(mActivity, R.raw.help);
// set text from resources with html markup
mHelpText.setText(Html.fromHtml(helpText));
// make links work
mHelpText.setMovementMethod(LinkMovementMethod.getInstance());
Bundle changelogBundle = new Bundle();
changelogBundle.putInt(HelpFragmentHtml.ARG_HTML_FILE, R.raw.help_changelog);
mTabsAdapter.addTab(bar.newTab().setText(getString(R.string.help_tab_changelog)),
HelpFragmentHtml.class, changelogBundle);
mTabsAdapter.addTab(bar.newTab().setText(getString(R.string.help_tab_about)),
HelpFragmentAbout.class, null);
}
}
public static class TabsAdapter extends FragmentPagerAdapter implements ActionBar.TabListener,
ViewPager.OnPageChangeListener {
private final Context mContext;
private final ActionBar mActionBar;
private final ViewPager mViewPager;
private final ArrayList<TabInfo> mTabs = new ArrayList<TabInfo>();
static final class TabInfo {
private final Class<?> clss;
private final Bundle args;
TabInfo(Class<?> _class, Bundle _args) {
clss = _class;
args = _args;
}
}
public TabsAdapter(SherlockFragmentActivity activity, ViewPager pager) {
super(activity.getSupportFragmentManager());
mContext = activity;
mActionBar = activity.getSupportActionBar();
mViewPager = pager;
mViewPager.setAdapter(this);
mViewPager.setOnPageChangeListener(this);
}
public void addTab(ActionBar.Tab tab, Class<?> clss, Bundle args) {
TabInfo info = new TabInfo(clss, args);
tab.setTag(info);
tab.setTabListener(this);
mTabs.add(info);
mActionBar.addTab(tab);
notifyDataSetChanged();
}
@Override
public int getCount() {
return mTabs.size();
}
@Override
public Fragment getItem(int position) {
TabInfo info = mTabs.get(position);
return Fragment.instantiate(mContext, info.clss.getName(), info.args);
}
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
}
public void onPageSelected(int position) {
mActionBar.setSelectedNavigationItem(position);
}
public void onPageScrollStateChanged(int state) {
}
public void onTabSelected(Tab tab, FragmentTransaction ft) {
Object tag = tab.getTag();
for (int i = 0; i < mTabs.size(); i++) {
if (mTabs.get(i) == tag) {
mViewPager.setCurrentItem(i);
}
}
}
public void onTabUnselected(Tab tab, FragmentTransaction ft) {
}
public void onTabReselected(Tab tab, FragmentTransaction ft) {
}
}
}

View File

@@ -0,0 +1,94 @@
/*
* Copyright (C) 2012 Dominik Schürmann <dominik@dominikschuermann.de>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thialfihar.android.apg.ui;
import org.thialfihar.android.apg.Constants;
import org.thialfihar.android.apg.R;
import org.thialfihar.android.apg.util.Utils;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Bundle;
import android.text.Html;
import android.text.method.LinkMovementMethod;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import com.actionbarsherlock.app.SherlockFragment;
public class HelpFragmentAbout extends SherlockFragment {
/**
* Workaround for Android Bug. See
* http://stackoverflow.com/questions/8748064/starting-activity-from
* -fragment-causes-nullpointerexception
*/
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
setUserVisibleHint(true);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.help_fragment_about, container, false);
// load html from html file from /res/raw
String aboutText = Utils.readContentFromResource(this.getActivity(), R.raw.help_about);
TextView versionText = (TextView) view.findViewById(R.id.help_about_version);
versionText.setText(getString(R.string.help_about_version) + " " + getVersion());
TextView aboutTextView = (TextView) view.findViewById(R.id.help_about_text);
// load html into textview
aboutTextView.setText(Html.fromHtml(aboutText));
// make links work
aboutTextView.setMovementMethod(LinkMovementMethod.getInstance());
// no flickering when clicking textview for Android < 4
aboutTextView.setTextColor(getResources().getColor(android.R.color.black));
return view;
}
/**
* Get the current package version.
*
* @return The current version.
*/
private String getVersion() {
String result = "";
try {
PackageManager manager = getActivity().getPackageManager();
PackageInfo info = manager.getPackageInfo(getActivity().getPackageName(), 0);
result = String.format("%s (%s)", info.versionName, info.versionCode);
} catch (NameNotFoundException e) {
Log.w(Constants.TAG, "Unable to get application version: " + e.getMessage());
result = "Unable to get application version.";
}
return result;
}
}

View File

@@ -0,0 +1,96 @@
/*
* Copyright (C) 2012 Dominik Schürmann <dominik@dominikschuermann.de>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thialfihar.android.apg.ui;
import org.thialfihar.android.apg.util.Utils;
import android.app.Activity;
import android.os.Bundle;
import android.text.Html;
import android.text.method.LinkMovementMethod;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ScrollView;
import android.widget.TextView;
import com.actionbarsherlock.app.SherlockFragment;
public class HelpFragmentHtml extends SherlockFragment {
private Activity mActivity;
private int htmlFile;
public static final String ARG_HTML_FILE = "htmlFile";
/**
* Create a new instance of HelpFragmentHtml, providing "htmlFile" as an argument.
*/
static HelpFragmentHtml newInstance(int htmlFile) {
HelpFragmentHtml f = new HelpFragmentHtml();
// Supply html raw file input as an argument.
Bundle args = new Bundle();
args.putInt(ARG_HTML_FILE, htmlFile);
f.setArguments(args);
return f;
}
/**
* Workaround for Android Bug. See
* http://stackoverflow.com/questions/8748064/starting-activity-from
* -fragment-causes-nullpointerexception
*/
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
setUserVisibleHint(true);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
htmlFile = getArguments().getInt(ARG_HTML_FILE);
// load html from html file from /res/raw
String helpText = Utils.readContentFromResource(this.getActivity(), htmlFile);
mActivity = getActivity();
ScrollView scroller = new ScrollView(mActivity);
TextView text = new TextView(mActivity);
// padding
int padding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 16, mActivity
.getResources().getDisplayMetrics());
text.setPadding(padding, padding, padding, 0);
scroller.addView(text);
// load html into textview
text.setText(Html.fromHtml(helpText));
// make links work
text.setMovementMethod(LinkMovementMethod.getInstance());
// no flickering when clicking textview for Android < 4
text.setTextColor(getResources().getColor(android.R.color.black));
return scroller;
}
}

View File

@@ -1,4 +1,5 @@
/*
* Copyright (C) 2012 Dominik Schürmann <dominik@dominikschuermann.de>
* Copyright (C) 2010 Thialfihar <thi@thialfihar.org>
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -28,13 +29,9 @@ import com.actionbarsherlock.app.SherlockActivity;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuItem;
import android.app.Dialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.View;
import android.widget.TextView;
public class MainActivity extends SherlockActivity {
static {
@@ -80,94 +77,6 @@ public class MainActivity extends SherlockActivity {
actionBar.setDisplayShowTitleEnabled(true);
actionBar.setDisplayHomeAsUpEnabled(false);
actionBar.setHomeButtonEnabled(false);
// if (!mPreferences.hasSeenHelp()) {
// showDialog(Id.dialog.help);
// }
//
// if (Apg.isReleaseVersion(this) && !mPreferences.hasSeenChangeLog(Apg.getVersion(this))) {
// showDialog(Id.dialog.change_log);
// }
}
@Override
protected Dialog onCreateDialog(int id) {
switch (id) {
// case Id.dialog.change_log: {
// AlertDialog.Builder alert = new AlertDialog.Builder(this);
//
// alert.setTitle("Changes " + Apg.getFullVersion(this));
// LayoutInflater inflater = (LayoutInflater) this
// .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
// View layout = inflater.inflate(R.layout.info, null);
// TextView message = (TextView) layout.findViewById(R.id.message);
//
// message.setText("Changes:\n" + "* \n" + "\n"
// + "WARNING: be careful editing your existing keys, as they "
// + "WILL be stripped of certificates right now.\n" + "\n"
// + "Also: key cross-certification is NOT supported, so signing "
// + "with those keys will get a warning when the signature is " + "checked.\n"
// + "\n" + "I hope APG continues to be useful to you, please send "
// + "bug reports, feature wishes, feedback.");
// alert.setView(layout);
//
// alert.setCancelable(false);
// alert.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
// public void onClick(DialogInterface dialog, int id) {
// MainActivity.this.removeDialog(Id.dialog.change_log);
// mPreferences.setHasSeenChangeLog(Apg.getVersion(MainActivity.this), true);
// }
// });
//
// return alert.create();
// }
// case Id.dialog.help: {
// AlertDialog.Builder alert = new AlertDialog.Builder(this);
//
// alert.setTitle(R.string.title_help);
//
// LayoutInflater inflater = (LayoutInflater) this
// .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
// View layout = inflater.inflate(R.layout.info, null);
// TextView message = (TextView) layout.findViewById(R.id.message);
// message.setText(R.string.text_help);
//
// TransformFilter packageNames = new TransformFilter() {
// public final String transformUrl(final Matcher match, String url) {
// String name = match.group(1).toLowerCase();
// if (name.equals("astro")) {
// return "com.metago.astro";
// } else if (name.equals("k-9 mail")) {
// return "com.fsck.k9";
// } else {
// return "org.openintents.filemanager";
// }
// }
// };
//
// Pattern pattern = Pattern.compile("(OI File Manager|ASTRO|K-9 Mail)");
// String scheme = "market://search?q=pname:";
// message.setAutoLinkMask(0);
// Linkify.addLinks(message, pattern, scheme, null, packageNames);
//
// alert.setView(layout);
//
// alert.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
// public void onClick(DialogInterface dialog, int id) {
// MainActivity.this.removeDialog(Id.dialog.help);
// mPreferences.setHasSeenHelp(true);
// }
// });
//
// return alert.create();
// }
default: {
return super.onCreateDialog(id);
}
}
}
@Override
@@ -175,40 +84,22 @@ public class MainActivity extends SherlockActivity {
menu.add(0, Id.menu.option.preferences, 0, R.string.menu_preferences)
.setIcon(R.drawable.ic_menu_settings)
.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
menu.add(0, Id.menu.option.about, 1, R.string.menu_about).setIcon(R.drawable.ic_menu_about)
.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case Id.menu.option.about: {
startActivity(new Intent(this, AboutActivity.class));
return true;
}
case Id.menu.option.preferences: {
case Id.menu.option.preferences:
startActivity(new Intent(this, PreferencesActivity.class));
return true;
}
default: {
default:
break;
}
}
return false;
}
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
TextView nameTextView = (TextView) v.findViewById(R.id.accountName);
if (nameTextView != null) {
menu.setHeaderTitle(nameTextView.getText());
menu.add(0, Id.menu.delete, 0, R.string.menu_deleteAccount);
}
}
}