Skip to content

Commit

Permalink
various bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
evilbunny2008 committed Mar 27, 2018
1 parent e6bc217 commit 8f824b3
Show file tree
Hide file tree
Showing 10 changed files with 97 additions and 101 deletions.
5 changes: 4 additions & 1 deletion app/src/main/java/com/odiousapps/weewxweather/About.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ public class About
{
private Common common;

About() {}
About(Common common)
{
this.common = common;
}

View myAbout(LayoutInflater inflater, ViewGroup container)
{
Expand Down
4 changes: 3 additions & 1 deletion app/src/main/java/com/odiousapps/weewxweather/Forecast.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ View myForecast(LayoutInflater inflater, ViewGroup container)
public boolean onLongClick(View v)
{
Vibrator vibrator = (Vibrator)common.context.getSystemService(Context.VIBRATOR_SERVICE);
vibrator.vibrate(150);
if(vibrator != null)
vibrator.vibrate(150);
Common.LogMessage("long press");
forceRefresh();
return true;
Expand Down Expand Up @@ -185,6 +186,7 @@ private void generateForecast()
int code = tmp.getInt("code");
String stmp;

@SuppressLint("SimpleDateFormat")
SimpleDateFormat sdf = new SimpleDateFormat("dd MMM yyyy HH:mm");
long rssCheck = common.GetIntPref("rssCheck", 0);
rssCheck *= 1000;
Expand Down
25 changes: 16 additions & 9 deletions app/src/main/java/com/odiousapps/weewxweather/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@

public class MainActivity extends AppCompatActivity
{
private SectionsPagerAdapter mSectionsPagerAdapter;
private ViewPager mViewPager;
private TabLayout tabLayout;
private Common common;

Expand All @@ -33,10 +31,10 @@ protected void onCreate(Bundle savedInstanceState)

common = new Common(this);

mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
SectionsPagerAdapter mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());

// Set up the ViewPager with the sections adapter.
mViewPager = findViewById(R.id.container);
ViewPager mViewPager = findViewById(R.id.container);
mViewPager.setAdapter(mSectionsPagerAdapter);

tabLayout = findViewById(R.id.tabs);
Expand All @@ -46,9 +44,9 @@ protected void onCreate(Bundle savedInstanceState)

try
{
if (common.GetStringPref("BASE_URL", "").equals(""))
tabLayout.getTabAt(5).select();
} catch (NullPointerException e) {
if(common.GetStringPref("BASE_URL", "").equals(""))
switchToTab(5);
} catch (Exception e) {
e.printStackTrace();
}

Expand Down Expand Up @@ -80,7 +78,16 @@ private void switchToTab(int tab)
tab = 0;
if(tab > 7)
tab = 7;
tabLayout.getTabAt(tab).select();

if(tabLayout.getTabAt(tab) != null)
{
try
{
tabLayout.getTabAt(tab).select();
} catch (Exception e) {
e.printStackTrace();
}
}
}

public void getWeather()
Expand Down Expand Up @@ -160,7 +167,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
Settings settings = new Settings(common);
return settings.mySettings(inflater, container);
} else if(getArguments().getInt(ARG_SECTION_NUMBER) == 7) {
About a = new About();
About a = new About(common);
return a.myAbout(inflater, container);
} else {
View rootView = inflater.inflate(R.layout.fragment_main, container, false);
Expand Down
5 changes: 1 addition & 4 deletions app/src/main/java/com/odiousapps/weewxweather/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import android.content.Intent;
import android.os.Handler;
import android.os.Message;
import android.support.design.widget.TabLayout;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
Expand All @@ -29,9 +28,8 @@

class Settings implements AdapterView.OnItemSelectedListener
{
private Common common = null;
private Common common;
private EditText et1;
View rootView;

private ProgressDialog dialog;

Expand All @@ -46,7 +44,6 @@ class Settings implements AdapterView.OnItemSelectedListener
View mySettings(LayoutInflater inflater, ViewGroup container)
{
final View rootView = inflater.inflate(R.layout.fragment_settings, container, false);
this.rootView = rootView;

et1 = rootView.findViewById(R.id.settings);
et1.setText(common.GetStringPref("SETTINGS_URL", "https://example.com/weewx/settings.txt"));
Expand Down
11 changes: 6 additions & 5 deletions app/src/main/java/com/odiousapps/weewxweather/Stats.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ View myStats(LayoutInflater inflater, ViewGroup container)
public boolean onLongClick(View v)
{
Vibrator vibrator = (Vibrator)common.context.getSystemService(Context.VIBRATOR_SERVICE);
vibrator.vibrate(150);
if(vibrator != null)
vibrator.vibrate(150);
Common.LogMessage("long press");
forceRefresh();
return true;
Expand Down Expand Up @@ -68,19 +69,19 @@ else if(action != null && action.equals(myService.EXIT_INTENT))
}
};

public void forceRefresh()
private void forceRefresh()
{
if(myService.singleton != null)
myService.singleton.getWeather();
}

public void checkFields(TextView tv, String txt)
private void checkFields(TextView tv, String txt)
{
if(!tv.getText().toString().equals(txt))
tv.setText(txt);
}

public void updateFields()
private void updateFields()
{
int iw = 17;

Expand Down Expand Up @@ -152,7 +153,7 @@ public void updateFields()
stmp = "</table><br>";
sb.append(stmp);

if (bits.length >= 110 && !bits[110].equals(""))
if(bits.length >= 110 && !bits[110].equals(""))
{
sb.append("<span style='font-size:18pt;font-weight:bold;'>This Month's Statistics</span>");
sb.append("<table style='width:100%;border:0px;'>");
Expand Down
5 changes: 3 additions & 2 deletions app/src/main/java/com/odiousapps/weewxweather/Weather.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ View myWeather(LayoutInflater inflater, ViewGroup container)
public boolean onLongClick(View v)
{
Vibrator vibrator = (Vibrator)common.context.getSystemService(Context.VIBRATOR_SERVICE);
vibrator.vibrate(150);
if(vibrator != null)
vibrator.vibrate(150);
Common.LogMessage("long press");
reloadWebView();
return true;
Expand All @@ -83,7 +84,7 @@ public boolean onLongClick(View v)
return updateFields();
}

protected void reloadWebView()
private void reloadWebView()
{
Common.LogMessage("reload radar...");
wv.getSettings().setAppCacheEnabled(false);
Expand Down
30 changes: 5 additions & 25 deletions app/src/main/java/com/odiousapps/weewxweather/Webcam.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,25 @@
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.os.Handler;
import android.os.Message;
import android.os.Vibrator;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.ImageView;

import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.net.URL;

class Webcam
{
private Common common;
private ImageView iv;
private File f;
private Bitmap bm;

Webcam(Common common)
{
Expand Down Expand Up @@ -63,9 +56,7 @@ public boolean onLongClick(View v)
private void reloadWebView()
{
Common.LogMessage("reload webcam...");
String webcam = common.GetStringPref("WEBCAM_URL", "");

final String webURL = webcam;
final String webURL = common.GetStringPref("WEBCAM_URL", "");

Thread t = new Thread(new Runnable()
{
Expand All @@ -76,7 +67,7 @@ public void run()
{
Common.LogMessage("starting to download bitmap");
InputStream is = new URL(webURL).openStream();
Bitmap bm = BitmapFactory.decodeStream(is);
bm = BitmapFactory.decodeStream(is);

int width = bm.getWidth();
int height = bm.getHeight();
Expand All @@ -85,13 +76,8 @@ public void run()
matrix.postRotate(90);

Bitmap scaledBitmap = Bitmap.createScaledBitmap(bm,width,height,true);
bm = Bitmap.createBitmap(scaledBitmap , 0, 0, scaledBitmap .getWidth(), scaledBitmap .getHeight(), matrix, true);

Bitmap rotatedBitmap = Bitmap.createBitmap(scaledBitmap , 0, 0, scaledBitmap .getWidth(), scaledBitmap .getHeight(), matrix, true);

f = new File(common.context.getCacheDir(), "tempBMP");
FileOutputStream outStream = new FileOutputStream(f);
rotatedBitmap.compress(Bitmap.CompressFormat.JPEG, 85, outStream);
outStream.close();
Common.LogMessage("done downloading, prompt handler to draw to iv");
handlerDone.sendEmptyMessage(0);
} catch (Exception e) {
Expand All @@ -109,13 +95,7 @@ public void run()
@Override
public void handleMessage(Message msg)
{
if(f.exists())
{
Bitmap myBitmap = BitmapFactory.decodeFile(f.getAbsolutePath());
iv.setImageBitmap(myBitmap);
//noinspection ResultOfMethodCallIgnored
f.delete();
}
iv.setImageBitmap(bm);
}
};

Expand Down
27 changes: 13 additions & 14 deletions app/src/main/java/com/odiousapps/weewxweather/myService.java
Original file line number Diff line number Diff line change
Expand Up @@ -255,21 +255,20 @@ public void onReceive(Context context, Intent intent)
{
if (intent != null && intent.getAction() != null)
{
if (intent.getAction().equals(Intent.ACTION_SCREEN_ON))
switch(intent.getAction())
{
Common.LogMessage("ACTION_SCREEN_ON");
}
else if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF))
{
Common.LogMessage("ACTION_SCREEN_OFF");
doUpdate = false;
// stop updating until the ACTION_USER_PRESENT is seen
}
else if (intent.getAction().equals(Intent.ACTION_USER_PRESENT))
{
doUpdate = true;
SendIntents();
Common.LogMessage("ACTION_USER_PRESENT");
case Intent.ACTION_SCREEN_ON:
Common.LogMessage("ACTION_SCREEN_ON");
return;
case Intent.ACTION_SCREEN_OFF:
Common.LogMessage("ACTION_SCREEN_OFF");
doUpdate = false;
// stop updating until the ACTION_USER_PRESENT is seen
return;
case Intent.ACTION_USER_PRESENT:
doUpdate = true;
SendIntents();
Common.LogMessage("ACTION_USER_PRESENT");
}
}
}
Expand Down
Loading

0 comments on commit 8f824b3

Please sign in to comment.