Skip to content

Commit

Permalink
Back button bug fixes.
Browse files Browse the repository at this point in the history
Website down catch.
  • Loading branch information
Jonathan Girven committed Nov 7, 2013
1 parent 344a43c commit 5d11735
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 54 deletions.
31 changes: 16 additions & 15 deletions src/uk/co/metweather/metweather/AboutActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,27 @@ public void onCreate(Bundle savedInstanceState) {

@Override
public boolean onOptionsItemSelected(MenuItem item) {
Intent myIntent;
// Intent myIntent;

switch (item.getItemId()) {
// Modified home button
// Returns to MainActivity or ConditionsActivity, passing arguments
case android.R.id.home:
if (extras.getInt(ConditionsActivity.SITE_POSITION) < 0) {
// If <0, return to MainActivity
myIntent = new Intent(this, MainActivity.class);
} else {
// Otherwise, we came from ConditionsActivity
myIntent = new Intent(this, ConditionsActivity.class);
myIntent.putExtra(ConditionsActivity.SITE_POSITION,
extras.getInt(ConditionsActivity.SITE_POSITION));
myIntent.putExtra(ConditionsActivity.FRAGMENT_POSITION,
extras.getInt(ConditionsActivity.FRAGMENT_POSITION));
}
// This is a back button
myIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(myIntent);
// if (extras.getInt(ConditionsActivity.SITE_POSITION) < 0) {
// // If <0, return to MainActivity
// myIntent = new Intent(this, MainActivity.class);
// } else {
// // Otherwise, we came from ConditionsActivity
// myIntent = new Intent(this, ConditionsActivity.class);
// myIntent.putExtra(ConditionsActivity.SITE_POSITION,
// extras.getInt(ConditionsActivity.SITE_POSITION));
// myIntent.putExtra(ConditionsActivity.FRAGMENT_POSITION,
// extras.getInt(ConditionsActivity.FRAGMENT_POSITION));
// }
// // This is a back button
// myIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
// startActivity(myIntent);
finish();
return true;

default:
Expand Down
10 changes: 5 additions & 5 deletions src/uk/co/metweather/metweather/ConditionsActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,19 @@ protected void onCreate(Bundle savedInstanceState) {
// Set up the ViewPager with the adapter.
mViewPager = (ViewPager) findViewById(R.id.fragment_container);
mViewPager.setAdapter(mConditionsPagerAdapter);

actionBar = getSupportActionBar();
// Swipes
mViewPager.setOnPageChangeListener(
new ViewPager.SimpleOnPageChangeListener() {
@Override
public void onPageSelected(int position) {
getSupportActionBar().setSelectedNavigationItem(position);
actionBar.setSelectedNavigationItem(position);
}
}
);


actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

if (savedInstanceState == null) {
inputArgs = getIntent().getExtras();
Expand All @@ -79,9 +82,6 @@ public void onPageSelected(int position) {
inputArgs = savedInstanceState;
}

actionBar = getSupportActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

// Create a tab listener that is called when the user changes tabs.
ActionBar.TabListener tabListener = new ActionBar.TabListener() {
@Override
Expand Down
15 changes: 8 additions & 7 deletions src/uk/co/metweather/metweather/FullScreenImageActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,14 @@ public boolean onOptionsItemSelected(MenuItem item) {
// Modified home button
// Returns to ConditionsActivity, passing arguments
case android.R.id.home:
myIntent = new Intent(this, ConditionsActivity.class);
myIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
myIntent.putExtra(ConditionsActivity.SITE_POSITION,
extras.getInt(ConditionsActivity.SITE_POSITION));
myIntent.putExtra(ConditionsActivity.FRAGMENT_POSITION,
extras.getInt(ConditionsActivity.FRAGMENT_POSITION));
startActivity(myIntent);
// myIntent = new Intent(this, ConditionsActivity.class);
// myIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
// myIntent.putExtra(ConditionsActivity.SITE_POSITION,
// extras.getInt(ConditionsActivity.SITE_POSITION));
// myIntent.putExtra(ConditionsActivity.FRAGMENT_POSITION,
// extras.getInt(ConditionsActivity.FRAGMENT_POSITION));
// startActivity(myIntent);
finish();
return true;

default:
Expand Down
73 changes: 46 additions & 27 deletions src/uk/co/metweather/metweather/GetWebpageInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@
import java.util.Map;

import android.os.AsyncTask;
import android.util.Log;
import android.widget.ImageView;
import android.widget.TextView;

public class GetWebpageInfo extends AsyncTask<TextView, Void, TextView[]> {

private static String TAG = "GetWebpageInfo";

// Download the HTML source of a website
// Process the text and display in a text view
List<String> text = new ArrayList<String>();
Expand Down Expand Up @@ -157,26 +161,37 @@ public List<String> HTMLLines( String url ) {
private String ProcessWind(List<String> text, int start, int end) {
String output = "";

List<String> result = StripHTML(text, start, end);
try {
List<String> result = StripHTML(text, start, end);

output += result.get(1) + "\n";
output += result.get(3) + "\n";
output += result.get(5) + "\n";
if (result.size() >= 5) {
output += result.get(1) + "\n";
output += result.get(3) + "\n";
output += result.get(5) + "\n";
}
} catch (Exception e) {
Log.e(TAG, "ProcessWind exception: " + e);
}

return output;
}


private String ProcessSea(List<String> text, int start, int end) {
String output = "";
List<String> result = StripHTML(text, start, end);
output += result.get(1) + "\n";

// Deal with Chimet supplementary information
if (result.size() > 2) {
output += result.get(2).replace("Wave Height (mean) ", "") + "\n";
output += result.get(3).replace("Wave Height (maximum)", "") + "\n";
output += result.get(4).replace("Wave Periodicity", "") + "\n";
try {
List<String> result = StripHTML(text, start, end);
output += result.get(1) + "\n";

// Deal with Chimet supplementary information
if (result.size() > 2) {
output += result.get(2).replace("Wave Height (mean) ", "") + "\n";
output += result.get(3).replace("Wave Height (maximum)", "") + "\n";
output += result.get(4).replace("Wave Periodicity", "") + "\n";
}
} catch (Exception e) {
Log.e(TAG, "ProcessSea exception: " + e);
}

return output;
Expand All @@ -186,22 +201,26 @@ private String ProcessSea(List<String> text, int start, int end) {
private String ProcessAtmo(List<String> text, int start, int end) {
String output = "";

List<String> result = StripHTML(text, start, end);

output += result.get(0).replace("Air", "") + "\n";

if (result.get(1).startsWith("Sea")) {
output += result.get(1).replace("Sea", "") + "\n";
} else {
output += "\n" + result.get(1).replace("Barometric Pressure", "") + "\n";
}

if (result.size() > 2) {
output += result.get(2).replace("Barometric Pressure", "") + "\n";
}

if (result.size() > 3) {
output += result.get(3).replace("Visibility", "") + "\n";
try {
List<String> result = StripHTML(text, start, end);

output += result.get(0).replace("Air", "") + "\n";

if (result.get(1).startsWith("Sea")) {
output += result.get(1).replace("Sea", "") + "\n";
} else {
output += "\n" + result.get(1).replace("Barometric Pressure", "") + "\n";
}

if (result.size() > 2) {
output += result.get(2).replace("Barometric Pressure", "") + "\n";
}

if (result.size() > 3) {
output += result.get(3).replace("Visibility", "") + "\n";
}
} catch (Exception e) {
Log.e(TAG, "ProcessAtmo exception: " + e);
}

return output;
Expand Down

0 comments on commit 5d11735

Please sign in to comment.