Android Open Source - egotrip Help Activity






From Project

Back to project page egotrip.

License

The source code is released under:

Apache License

If you think the Android project egotrip listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package net.myegotrip.egotrip.help;
// w w w  .j  av a2 s .  co m
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.channels.FileChannel;

import net.myegotrip.egotrip.R;
import net.myegotrip.egotrip.R.id;
import net.myegotrip.egotrip.R.layout;
import net.myegotrip.egotrip.R.string;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Environment;
import android.preference.PreferenceManager;
import android.text.Html;
import android.text.method.LinkMovementMethod;
import android.util.Log;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

public class HelpActivity extends Activity{
  private Context ctx;
  static public final String ARG_TEXT_ID = "text_id";

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.help);    
     // Set up so that formatted text can be in the help_page_intro text and so that html links are handled.
      TextView textView = (TextView) findViewById (R.id.help_page_intro);
      if (textView != null) {       
         textView.setText (Html.fromHtml (getString (R.string.help_page_intro_html)));
      }
      textView = (TextView) findViewById (R.id.help_summary_text1);
      if (textView != null) textView.setText(Html.fromHtml (""+textView.getText()));
      textView = (TextView) findViewById (R.id.help_summary_text2);
      if (textView != null) textView.setText(Html.fromHtml (""+textView.getText()));
      textView = (TextView) findViewById (R.id.help_summary_text3);
      if (textView != null) textView.setText(Html.fromHtml (""+textView.getText()));
      textView = (TextView) findViewById (R.id.help_summary_text4);
      if (textView != null) textView.setText(Html.fromHtml (""+textView.getText()));
      ctx=this;
  }

  public void onClickHelp (View v)
  {
   int id = v.getId ();
   int textId = -1;
   switch (id) {
   case R.id.help_button1 :
     textId = R.string.topic_section1;
     break;
   case R.id.help_button2 :
     textId = R.string.topic_section2;
     break;
   case R.id.help_button3 :
     textId = R.string.topic_section3;
     break;
   case R.id.help_button4 :
     textId = R.string.topic_section4;
     break;
   default:
     break;
   }
   if (textId >= 0) startInfoActivity (textId);
   else toast (getString(R.string.detailed_help_for_that_topic_is_not_available_), true);
  }
  
  
  
  
  private class ExportDatabaseFileTask extends AsyncTask<String, Void, Boolean> {
    
        private final ProgressDialog dialog = new ProgressDialog(ctx);

        // can use UI thread here
        protected void onPreExecute() {
           this.dialog.setMessage("Exporting database...");
           this.dialog.show();
        }

        // automatically done on worker thread (separate from UI thread)
        protected Boolean doInBackground(final String... args) {

           File dbFile =
                    new File(Environment.getDataDirectory() + "/data/net.myegotrip.egotrip/databases/egotrip");

           File exportDir = new File(Environment.getExternalStorageDirectory(), "");
           if (!exportDir.exists()) {
              exportDir.mkdirs();
           }
           File file = new File(exportDir, dbFile.getName()+".db");

           try {
              file.createNewFile();
              this.copyFile(dbFile, file);
              return true;
           } catch (IOException e) {
              Log.e("mypck", e.getMessage(), e);
              return false;
           }
        }

        // can use UI thread here
        protected void onPostExecute(final Boolean success) {
           if (this.dialog.isShowing()) {
              this.dialog.dismiss();
           }
           if (success) {
              Toast.makeText(ctx, "Export successful!", Toast.LENGTH_SHORT).show();
           } else {
              Toast.makeText(ctx, "Export failed", Toast.LENGTH_SHORT).show();
           }
        }

        void copyFile(File src, File dst) throws IOException {
           FileChannel inChannel = new FileInputStream(src).getChannel();
           FileChannel outChannel = new FileOutputStream(dst).getChannel();
           try {
              inChannel.transferTo(0, inChannel.size(), outChannel);
           } finally {
              if (inChannel != null)
                 inChannel.close();
              if (outChannel != null)
                 outChannel.close();
           }
        }

     }

  
  
  public void onClickBugReport(View v){
    ExportDatabaseFileTask export=new ExportDatabaseFileTask();
    export.execute(new String[] { });
  }
  
  
  

/**
 * Start a TopicActivity and show the text indicated by argument 1.
 * 
 * @param textId int - resource id of the text to show
 * @return void
 */

public void startInfoActivity (int textId)
{
    if (textId >= 0) {
       Intent intent = (new Intent(this, TopicActivity.class));
       intent.putExtra (ARG_TEXT_ID, textId);
       startActivity (intent);
    } else {
      toast (getString(R.string.no_information_is_available_for_topic_) + textId, true);
    }
} // end startInfoActivity

/**
 * Show a string on the screen via Toast.
 * 
 * @param msg String
 * @param longLength boolean - show message a long time
 * @return void
 */

public void toast (String msg, boolean longLength)
{
    Toast.makeText (getApplicationContext(), msg, 
                    (longLength ? Toast.LENGTH_LONG : Toast.LENGTH_SHORT)
                   ).show ();
}

}




Java Source Code List

net.myegotrip.egotrip.CommonGPSServiceFunctions.java
net.myegotrip.egotrip.ControlHandler.java
net.myegotrip.egotrip.ControlWindow.java
net.myegotrip.egotrip.DbListener.java
net.myegotrip.egotrip.DbTools.java
net.myegotrip.egotrip.DownloadProgressHandler.java
net.myegotrip.egotrip.FallbackDefaults.java
net.myegotrip.egotrip.GPSService.java
net.myegotrip.egotrip.Installation.java
net.myegotrip.egotrip.LocationUpdate.java
net.myegotrip.egotrip.MapViewActivity.java
net.myegotrip.egotrip.PrefActivity.java
net.myegotrip.egotrip.ReleaseConfig.java
net.myegotrip.egotrip.StartupActivity.java
net.myegotrip.egotrip.TaskDoneListener.java
net.myegotrip.egotrip.Tools.java
net.myegotrip.egotrip.TripManager.java
net.myegotrip.egotrip.help.HelpActivity.java
net.myegotrip.egotrip.help.TopicActivity.java
net.myegotrip.egotrip.image.ImageHandler.java
net.myegotrip.egotrip.map.MockLocationProvider.java
net.myegotrip.egotrip.map.PlacemarkOverlay.java
net.myegotrip.egotrip.map.Placemark.java
net.myegotrip.egotrip.map.RouteOverlay.java
net.myegotrip.egotrip.map.RoutePoint.java
net.myegotrip.egotrip.map.Trip.java
net.myegotrip.egotrip.metadata.EgotripMetadata.java
net.myegotrip.egotrip.metadata.GenericMetadata.java
net.myegotrip.egotrip.metadata.Icon.java
net.myegotrip.egotrip.metadata.Image.java
net.myegotrip.egotrip.metadata.MetadataManager.java
net.myegotrip.egotrip.metadata.Text.java
net.myegotrip.egotrip.net.BetaUpdateManager.java
net.myegotrip.egotrip.net.ProtocolConstants.java
net.myegotrip.egotrip.net.ServerReply.java
net.myegotrip.egotrip.net.Uploader.java
net.myegotrip.egotrip.profile.ProfileActivity.java
net.myegotrip.egotrip.profile.ProfilePrefActivity.java
net.myegotrip.egotrip.profile.ProfileView.java
net.myegotrip.egotrip.utils.DebugActivity.java
net.myegotrip.egotrip.utils.Debug.java
net.myegotrip.egotrip.utils.GuiUtils.java
net.myegotrip.egotrip.utils.IconItem.java
net.myegotrip.egotrip.utils.TwoDScrollView.java
net.myegotrip.egotrip.utils.XYScaleGestureDetector.java