diff --git a/app/src/androidTest/java/io/github/protino/data/TestDb.java b/app/src/androidTest/java/io/github/protino/data/TestDb.java index 5200736..be727ab 100644 --- a/app/src/androidTest/java/io/github/protino/data/TestDb.java +++ b/app/src/androidTest/java/io/github/protino/data/TestDb.java @@ -27,7 +27,7 @@ public class TestDb extends AndroidTestCase { public static final String LOG_TAG = TestDb.class.getSimpleName(); // Since we want each test to start with a clean slate - void deleteTheDatabase() { + private void deleteTheDatabase() { mContext.deleteDatabase(WeatherDbHelper.DATABASE_NAME); } diff --git a/app/src/androidTest/java/io/github/protino/data/TestProvider.java b/app/src/androidTest/java/io/github/protino/data/TestProvider.java index d53a581..555ddb8 100644 --- a/app/src/androidTest/java/io/github/protino/data/TestProvider.java +++ b/app/src/androidTest/java/io/github/protino/data/TestProvider.java @@ -40,6 +40,29 @@ public class TestProvider extends AndroidTestCase { public static final String LOG_TAG = TestProvider.class.getSimpleName(); + static private final int BULK_INSERT_RECORDS_TO_INSERT = 10; + + public static ContentValues[] createBulkInsertWeatherValues(long locationRowId) { + long currentTestDate = TestUtilities.TEST_DATE; + long millisecondsInADay = 1000 * 60 * 60 * 24; + ContentValues[] returnContentValues = new ContentValues[BULK_INSERT_RECORDS_TO_INSERT]; + + for (int i = 0; i < BULK_INSERT_RECORDS_TO_INSERT; i++, currentTestDate += millisecondsInADay) { + ContentValues weatherValues = new ContentValues(); + weatherValues.put(WeatherContract.WeatherEntry.COLUMN_LOC_KEY, locationRowId); + weatherValues.put(WeatherContract.WeatherEntry.COLUMN_DATE, currentTestDate); + weatherValues.put(WeatherContract.WeatherEntry.COLUMN_DEGREES, 1.1); + weatherValues.put(WeatherContract.WeatherEntry.COLUMN_HUMIDITY, 1.2 + 0.01 * (float) i); + weatherValues.put(WeatherContract.WeatherEntry.COLUMN_PRESSURE, 1.3 - 0.01 * (float) i); + weatherValues.put(WeatherContract.WeatherEntry.COLUMN_MAX_TEMP, 75 + i); + weatherValues.put(WeatherContract.WeatherEntry.COLUMN_MIN_TEMP, 65 - i); + weatherValues.put(WeatherContract.WeatherEntry.COLUMN_SHORT_DESC, "Asteroids"); + weatherValues.put(WeatherContract.WeatherEntry.COLUMN_WIND_SPEED, 5.5 + 0.2 * (float) i); + weatherValues.put(WeatherContract.WeatherEntry.COLUMN_WEATHER_ID, 321); + returnContentValues[i] = weatherValues; + } + return returnContentValues; + } /* This helper function deletes all records from both database tables using the ContentProvider. @@ -131,7 +154,7 @@ public void testProviderRegistry() { // Make sure that the registered authority matches the authority from the Contract. assertEquals("Error: WeatherProvider registered with authority: " + providerInfo.authority + - " instead of authority: " + WeatherContract.CONTENT_AUTHORITY, + " instead of authority: " + WeatherContract.CONTENT_AUTHORITY, providerInfo.authority, WeatherContract.CONTENT_AUTHORITY); } catch (PackageManager.NameNotFoundException e) { // I guess the provider isn't registered correctly. @@ -176,7 +199,6 @@ public void testGetType() { LocationEntry.CONTENT_TYPE, type); } - /* This test uses the database directly to insert and then uses the ContentProvider to read out the data. Uncomment this test to see if the basic weather query functionality @@ -187,7 +209,6 @@ public void testBasicWeatherQuery() { WeatherDbHelper dbHelper = new WeatherDbHelper(mContext); SQLiteDatabase db = dbHelper.getWritableDatabase(); - ContentValues testValues = TestUtilities.createNorthPoleLocationValues(); long locationRowId = TestUtilities.insertNorthPoleLocationValues(mContext); // Fantastic. Now that we have a location, add some weather! @@ -238,7 +259,7 @@ public void testBasicLocationQueries() { // Has the NotificationUri been set correctly? --- we can only test this easily against API // level 19 or greater because getNotificationUri was added in API level 19. - if ( Build.VERSION.SDK_INT >= 19 ) { + if (Build.VERSION.SDK_INT >= 19) { assertEquals("Error: Location Query did not properly set NotificationUri", locationCursor.getNotificationUri(), LocationEntry.CONTENT_URI); } @@ -273,7 +294,7 @@ public void testUpdateLocation() { int count = mContext.getContentResolver().update( LocationEntry.CONTENT_URI, updatedValues, LocationEntry._ID + "= ?", - new String[] { Long.toString(locationRowId)}); + new String[]{Long.toString(locationRowId)}); assertEquals(count, 1); // Test to make sure our observer is called. If not, we throw an assertion. @@ -300,7 +321,6 @@ public void testUpdateLocation() { cursor.close(); } - // Make sure we can still delete after adding/updating stuff // // Student: Uncomment this test after you have completed writing the insert functionality @@ -435,30 +455,6 @@ public void testDeleteRecords() { mContext.getContentResolver().unregisterContentObserver(weatherObserver); } - - static private final int BULK_INSERT_RECORDS_TO_INSERT = 10; - static ContentValues[] createBulkInsertWeatherValues(long locationRowId) { - long currentTestDate = TestUtilities.TEST_DATE; - long millisecondsInADay = 1000*60*60*24; - ContentValues[] returnContentValues = new ContentValues[BULK_INSERT_RECORDS_TO_INSERT]; - - for ( int i = 0; i < BULK_INSERT_RECORDS_TO_INSERT; i++, currentTestDate+= millisecondsInADay ) { - ContentValues weatherValues = new ContentValues(); - weatherValues.put(WeatherContract.WeatherEntry.COLUMN_LOC_KEY, locationRowId); - weatherValues.put(WeatherContract.WeatherEntry.COLUMN_DATE, currentTestDate); - weatherValues.put(WeatherContract.WeatherEntry.COLUMN_DEGREES, 1.1); - weatherValues.put(WeatherContract.WeatherEntry.COLUMN_HUMIDITY, 1.2 + 0.01 * (float) i); - weatherValues.put(WeatherContract.WeatherEntry.COLUMN_PRESSURE, 1.3 - 0.01 * (float) i); - weatherValues.put(WeatherContract.WeatherEntry.COLUMN_MAX_TEMP, 75 + i); - weatherValues.put(WeatherContract.WeatherEntry.COLUMN_MIN_TEMP, 65 - i); - weatherValues.put(WeatherContract.WeatherEntry.COLUMN_SHORT_DESC, "Asteroids"); - weatherValues.put(WeatherContract.WeatherEntry.COLUMN_WIND_SPEED, 5.5 + 0.2 * (float) i); - weatherValues.put(WeatherContract.WeatherEntry.COLUMN_WEATHER_ID, 321); - returnContentValues[i] = weatherValues; - } - return returnContentValues; - } - // Student: Uncomment this test after you have completed writing the BulkInsert functionality // in your provider. Note that this test will work with the built-in (default) provider // implementation, which just inserts records one-at-a-time, so really do implement the diff --git a/app/src/androidTest/java/io/github/protino/data/TestUriMatcher.java b/app/src/androidTest/java/io/github/protino/data/TestUriMatcher.java index 6964729..0618170 100644 --- a/app/src/androidTest/java/io/github/protino/data/TestUriMatcher.java +++ b/app/src/androidTest/java/io/github/protino/data/TestUriMatcher.java @@ -28,7 +28,6 @@ public class TestUriMatcher extends AndroidTestCase { private static final String LOCATION_QUERY = "London, UK"; private static final long TEST_DATE = 1419033600L; // December 20th, 2014 - private static final long TEST_LOCATION_ID = 10L; // content://com.example.android.sunshine.app/weather" private static final Uri TEST_WEATHER_DIR = WeatherContract.WeatherEntry.CONTENT_URI; diff --git a/app/src/androidTest/java/io/github/protino/data/TestUtilities.java b/app/src/androidTest/java/io/github/protino/data/TestUtilities.java index c644750..5ffc872 100644 --- a/app/src/androidTest/java/io/github/protino/data/TestUtilities.java +++ b/app/src/androidTest/java/io/github/protino/data/TestUtilities.java @@ -26,27 +26,27 @@ import android.os.HandlerThread; import android.test.AndroidTestCase; -import io.github.protino.utils.PollingCheck; - import java.util.Map; import java.util.Set; +import io.github.protino.utils.PollingCheck; + /* Students: These are functions and some test data to make it easier to test your database and Content Provider. Note that you'll want your WeatherContract class to exactly match the one in our solution to use these as-given. */ public class TestUtilities extends AndroidTestCase { - static final String TEST_LOCATION = "99705"; - static final long TEST_DATE = 1419033600L; // December 20th, 2014 + public static final String TEST_LOCATION = "99705"; + public static final long TEST_DATE = 1419033600L; // December 20th, 2014 - static void validateCursor(String error, Cursor valueCursor, ContentValues expectedValues) { + public static void validateCursor(String error, Cursor valueCursor, ContentValues expectedValues) { assertTrue("Empty cursor returned. " + error, valueCursor.moveToFirst()); validateCurrentRecord(error, valueCursor, expectedValues); valueCursor.close(); } - static void validateCurrentRecord(String error, Cursor valueCursor, ContentValues expectedValues) { + public static void validateCurrentRecord(String error, Cursor valueCursor, ContentValues expectedValues) { Set> valueSet = expectedValues.valueSet(); for (Map.Entry entry : valueSet) { String columnName = entry.getKey(); @@ -62,7 +62,7 @@ static void validateCurrentRecord(String error, Cursor valueCursor, ContentValue /* Students: Use this to create some default weather values for your database tests. */ - static ContentValues createWeatherValues(long locationRowId) { + public static ContentValues createWeatherValues(long locationRowId) { ContentValues weatherValues = new ContentValues(); weatherValues.put(WeatherContract.WeatherEntry.COLUMN_LOC_KEY, locationRowId); weatherValues.put(WeatherContract.WeatherEntry.COLUMN_DATE, TEST_DATE); @@ -82,7 +82,7 @@ static ContentValues createWeatherValues(long locationRowId) { Students: You can uncomment this helper function once you have finished creating the LocationEntry part of the WeatherContract. */ - static ContentValues createNorthPoleLocationValues() { + public static ContentValues createNorthPoleLocationValues() { // Create a new map of values, where column names are the keys ContentValues testValues = new ContentValues(); testValues.put(WeatherContract.LocationEntry.COLUMN_LOCATION_SETTING, TEST_LOCATION); @@ -97,7 +97,7 @@ static ContentValues createNorthPoleLocationValues() { Students: You can uncomment this function once you have finished creating the LocationEntry part of the WeatherContract as well as the WeatherDbHelper. */ - static long insertNorthPoleLocationValues(Context context) { + public static long insertNorthPoleLocationValues(Context context) { // insert our test records into the database WeatherDbHelper dbHelper = new WeatherDbHelper(context); SQLiteDatabase db = dbHelper.getWritableDatabase(); @@ -112,6 +112,10 @@ static long insertNorthPoleLocationValues(Context context) { return locationRowId; } + public static TestContentObserver getTestContentObserver() { + return TestContentObserver.getTestContentObserver(); + } + /* Students: The functions we provide inside of TestProvider use this utility class to test the ContentObserver callbacks using the PollingCheck class that we grabbed from the Android @@ -120,9 +124,14 @@ static long insertNorthPoleLocationValues(Context context) { Note that this only tests that the onChange function is called; it does not test that the correct Uri is returned. */ - static class TestContentObserver extends ContentObserver { - final HandlerThread mHT; - boolean mContentChanged; + public static class TestContentObserver extends ContentObserver { + public final HandlerThread mHT; + public boolean mContentChanged; + + private TestContentObserver(HandlerThread ht) { + super(new Handler(ht.getLooper())); + mHT = ht; + } static TestContentObserver getTestContentObserver() { HandlerThread ht = new HandlerThread("ContentObserverThread"); @@ -130,11 +139,6 @@ static TestContentObserver getTestContentObserver() { return new TestContentObserver(ht); } - private TestContentObserver(HandlerThread ht) { - super(new Handler(ht.getLooper())); - mHT = ht; - } - // On earlier versions of Android, this onChange method is called @Override public void onChange(boolean selfChange) { @@ -160,8 +164,4 @@ protected boolean check() { mHT.quit(); } } - - static TestContentObserver getTestContentObserver() { - return TestContentObserver.getTestContentObserver(); - } } diff --git a/app/src/androidTest/java/io/github/protino/utils/PollingCheck.java b/app/src/androidTest/java/io/github/protino/utils/PollingCheck.java index 5154cae..f13c9da 100644 --- a/app/src/androidTest/java/io/github/protino/utils/PollingCheck.java +++ b/app/src/androidTest/java/io/github/protino/utils/PollingCheck.java @@ -30,6 +30,20 @@ public PollingCheck(long timeout) { mTimeout = timeout; } + public static void check(CharSequence message, long timeout, Callable condition) + throws Exception { + while (timeout > 0) { + if (condition.call()) { + return; + } + + Thread.sleep(TIME_SLICE); + timeout -= TIME_SLICE; + } + + Assert.fail(message.toString()); + } + protected abstract boolean check(); public void run() { @@ -54,18 +68,4 @@ public void run() { Assert.fail("unexpected timeout"); } - - public static void check(CharSequence message, long timeout, Callable condition) - throws Exception { - while (timeout > 0) { - if (condition.call()) { - return; - } - - Thread.sleep(TIME_SLICE); - timeout -= TIME_SLICE; - } - - Assert.fail(message.toString()); - } } \ No newline at end of file diff --git a/app/src/main/java/io/github/protino/ItemChoiceManager.java b/app/src/main/java/io/github/protino/ItemChoiceManager.java index ffbb8ad..9ebf1fe 100644 --- a/app/src/main/java/io/github/protino/ItemChoiceManager.java +++ b/app/src/main/java/io/github/protino/ItemChoiceManager.java @@ -41,13 +41,13 @@ public class ItemChoiceManager { /** * Running state of which positions are currently checked */ - SparseBooleanArray mCheckStates = new SparseBooleanArray(); + private SparseBooleanArray mCheckStates = new SparseBooleanArray(); /** * Running state of which IDs are currently checked. * If there is a value for a given key, the checked state for that ID is true * and the value holds the last known position in the adapter for that id. */ - LongSparseArray mCheckedIdStates = new LongSparseArray(); + private LongSparseArray mCheckedIdStates = new LongSparseArray(); private int mChoiceMode; private RecyclerView.Adapter mAdapter; private RecyclerView.AdapterDataObserver mAdapterDataObserver = new RecyclerView.AdapterDataObserver() { @@ -66,6 +66,25 @@ public ItemChoiceManager(RecyclerView.Adapter adapter) { mAdapter = adapter; } + //Lifecycle start + public void onRestoreInstanceState(Bundle savedInstanceState) { + byte[] states = savedInstanceState.getByteArray(SELECTED_ITEMS_KEY); + if (null != states) { + Parcel inParcel = Parcel.obtain(); + inParcel.unmarshall(states, 0, states.length); + inParcel.setDataPosition(0); + mCheckStates = inParcel.readSparseBooleanArray(); + final int numStates = inParcel.readInt(); + mCheckedIdStates.clear(); + for (int i = 0; i < numStates; i++) { + final long key = inParcel.readLong(); + final int value = inParcel.readInt(); + mCheckedIdStates.put(key, value); + } + } + } +//Lifecycle end + public void onClick(RecyclerView.ViewHolder vh) { if (mChoiceMode == AbsListView.CHOICE_MODE_NONE) return; @@ -110,6 +129,8 @@ public void onClick(RecyclerView.ViewHolder vh) { case AbsListView.CHOICE_MODE_MULTIPLE_MODAL: { throw new RuntimeException("Multiple Modal not implemented in ItemChoiceManager."); } + default://ignore + break; } } @@ -188,23 +209,6 @@ public void onBindViewHolder(RecyclerView.ViewHolder vh, int position) { ViewCompat.setActivated(vh.itemView, checked); } - public void onRestoreInstanceState(Bundle savedInstanceState) { - byte[] states = savedInstanceState.getByteArray(SELECTED_ITEMS_KEY); - if (null != states) { - Parcel inParcel = Parcel.obtain(); - inParcel.unmarshall(states, 0, states.length); - inParcel.setDataPosition(0); - mCheckStates = inParcel.readSparseBooleanArray(); - final int numStates = inParcel.readInt(); - mCheckedIdStates.clear(); - for (int i = 0; i < numStates; i++) { - final long key = inParcel.readLong(); - final int value = inParcel.readInt(); - mCheckedIdStates.put(key, value); - } - } - } - public void onSaveInstanceState(Bundle outState) { Parcel outParcel = Parcel.obtain(); outParcel.writeSparseBooleanArray(mCheckStates); diff --git a/app/src/main/java/io/github/protino/activity/MainActivity.java b/app/src/main/java/io/github/protino/activity/MainActivity.java index 593ee4d..c8c45aa 100644 --- a/app/src/main/java/io/github/protino/activity/MainActivity.java +++ b/app/src/main/java/io/github/protino/activity/MainActivity.java @@ -46,7 +46,7 @@ public class MainActivity extends AppCompatActivity implements ForecastFragment. private static boolean mTwoPane; private String mLocation; -//Lifecycle start + //Lifecycle start @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -130,6 +130,8 @@ public boolean onOptionsItemSelected(MenuItem item) { case R.id.action_refresh: SunshineSyncAdapter.syncImmediately(this); return true; + default: //ignore + break; } return super.onOptionsItemSelected(item); } diff --git a/app/src/main/java/io/github/protino/adapter/ForecastAdapter.java b/app/src/main/java/io/github/protino/adapter/ForecastAdapter.java index 176d8bf..ddeb83e 100644 --- a/app/src/main/java/io/github/protino/adapter/ForecastAdapter.java +++ b/app/src/main/java/io/github/protino/adapter/ForecastAdapter.java @@ -58,6 +58,11 @@ public ForecastAdapter(Context context, ForecastAdapterOnClickHandler clickHandl itemChoiceManager.setChoiceMode(choiceMode); } +//Lifecycle start + public void onRestoreInstanceState(Bundle savedInstanceState) { + itemChoiceManager.onRestoreInstanceState(savedInstanceState); + } +//Lifecycle end public void setUseTodayLayout(boolean useTodayLayout) { mUseTodayLayout = useTodayLayout; @@ -76,6 +81,8 @@ public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { layoutId = R.layout.list_item_forecast; break; } + default://ignore + break; } View view = LayoutInflater.from(parent.getContext()).inflate(layoutId, parent, false); view.setFocusable(true); @@ -140,10 +147,6 @@ public void onBindViewHolder(ViewHolder holder, int position) { itemChoiceManager.onBindViewHolder(holder, position); } - public void onRestoreInstanceState(Bundle savedInstanceState) { - itemChoiceManager.onRestoreInstanceState(savedInstanceState); - } - public void onSaveInstanceState(Bundle outState) { itemChoiceManager.onSaveInstanceState(outState); } diff --git a/app/src/main/java/io/github/protino/customView/CompassView.java b/app/src/main/java/io/github/protino/customView/CompassView.java index 0b475b4..8937d8d 100644 --- a/app/src/main/java/io/github/protino/customView/CompassView.java +++ b/app/src/main/java/io/github/protino/customView/CompassView.java @@ -25,14 +25,13 @@ * Created by Gurupad on 21-Aug-16. */ public class CompassView extends View { - Paint mCircleBorderPaint; - Paint mCircleFillPaint; - Paint mArrowPaint; - int mHeight; - int mWidth; + public Paint mCircleBorderPaint; + public Paint mCircleFillPaint; + public Paint mArrowPaint; + public int mHeight; - int speed; - int direction; + public int speed; + public int direction; public CompassView(Context context, AttributeSet attrs) { super(context, attrs); diff --git a/app/src/main/java/io/github/protino/customView/LocationEditText.java b/app/src/main/java/io/github/protino/customView/LocationEditText.java index a0b9d28..657992c 100644 --- a/app/src/main/java/io/github/protino/customView/LocationEditText.java +++ b/app/src/main/java/io/github/protino/customView/LocationEditText.java @@ -106,11 +106,12 @@ protected void showDialog(Bundle state) { editText.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { + //ignore } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { - + //ignore } @Override diff --git a/app/src/main/java/io/github/protino/data/WeatherProvider.java b/app/src/main/java/io/github/protino/data/WeatherProvider.java index ff9b341..439d0fc 100644 --- a/app/src/main/java/io/github/protino/data/WeatherProvider.java +++ b/app/src/main/java/io/github/protino/data/WeatherProvider.java @@ -88,6 +88,18 @@ public static UriMatcher buildUriMatcher() { return uriMatcher; } + //Lifecycle start + /* + Students: We've coded this for you. We just create a new WeatherDbHelper for later use + here. + */ + @Override + public boolean onCreate() { + mOpenHelper = new WeatherDbHelper(getContext()); + return true; + } +//Lifecycle end + private Cursor getWeatherByLocationSetting(Uri uri, String[] projection, String sortOrder) { String locationSetting = WeatherContract.WeatherEntry.getLocationSettingFromUri(uri); long startDate = WeatherContract.WeatherEntry.getStartDateFromUri(uri); @@ -128,16 +140,6 @@ private Cursor getWeatherByLocationSettingAndDate( ); } - /* - Students: We've coded this for you. We just create a new WeatherDbHelper for later use - here. - */ - @Override - public boolean onCreate() { - mOpenHelper = new WeatherDbHelper(getContext()); - return true; - } - /* Students: Here's where you'll code the getType function that uses the UriMatcher. You can test this by uncommenting testGetType in TestProvider. @@ -287,17 +289,18 @@ private void normalizeDate(ContentValues values) { public int update(@NonNull Uri uri, ContentValues values, String selection, String[] selectionArgs) { final SQLiteDatabase db = mOpenHelper.getReadableDatabase(); final int match = sUriMatcher.match(uri); + String tempSelection = selection; int rowsUpdated; - if (selection == null) selection = "1"; + if (tempSelection == null) tempSelection = "1"; switch (match) { case WEATHER: { normalizeDate(values); - rowsUpdated = db.update(WeatherContract.WeatherEntry.TABLE_NAME, values, selection, selectionArgs); + rowsUpdated = db.update(WeatherContract.WeatherEntry.TABLE_NAME, values, tempSelection, selectionArgs); break; } case LOCATION: { - rowsUpdated = db.update(WeatherContract.LocationEntry.TABLE_NAME, values, selection, selectionArgs); + rowsUpdated = db.update(WeatherContract.LocationEntry.TABLE_NAME, values, tempSelection, selectionArgs); break; } default: diff --git a/app/src/main/java/io/github/protino/fragment/DetailFragment.java b/app/src/main/java/io/github/protino/fragment/DetailFragment.java index 4333bce..3d5ccc8 100644 --- a/app/src/main/java/io/github/protino/fragment/DetailFragment.java +++ b/app/src/main/java/io/github/protino/fragment/DetailFragment.java @@ -102,7 +102,7 @@ public DetailFragment() { setHasOptionsMenu(true); } -//Lifecycle start + //Lifecycle start @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { @@ -297,5 +297,6 @@ public void onLoadFinished(Loader loader, Cursor data) { @Override public void onLoaderReset(Loader loader) { + //ignore } } \ No newline at end of file diff --git a/app/src/main/java/io/github/protino/fragment/ForecastFragment.java b/app/src/main/java/io/github/protino/fragment/ForecastFragment.java index d681fdc..43c72fd 100644 --- a/app/src/main/java/io/github/protino/fragment/ForecastFragment.java +++ b/app/src/main/java/io/github/protino/fragment/ForecastFragment.java @@ -100,6 +100,7 @@ public class ForecastFragment extends Fragment implements LoaderManager.LoaderCa public ForecastFragment() { } +//Lifecycle start @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -107,36 +108,6 @@ public void onCreate(Bundle savedInstanceState) { setHasOptionsMenu(true); } - @Override - public void onResume() { - SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getActivity()); - sp.registerOnSharedPreferenceChangeListener(this); - super.onResume(); - } - - @Override - public void onPause() { - SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getActivity()); - sp.unregisterOnSharedPreferenceChangeListener(this); - super.onPause(); - } - - @Override - public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { - inflater.inflate(R.menu.menu_main, menu); - } - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - int id = item.getItemId(); - if (id == R.id.action_map) { - openPreferredLocationInMap(); - return true; - } - - return super.onOptionsItemSelected(item); - } - @Override public void onInflate(Activity activity, AttributeSet attrs, Bundle savedInstanceState) { super.onInflate(activity, attrs, savedInstanceState); @@ -184,22 +155,20 @@ public void onClick(Long date, ForecastAdapter.ViewHolder vh) { mRecyclerView.setAdapter(mForecastAdapter); final View parallaxView = rootView.findViewById(R.id.parallax_bar); - if (null != parallaxView) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { - mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() { - @TargetApi(Build.VERSION_CODES.HONEYCOMB) - @Override - public void onScrolled(RecyclerView recyclerView, int dx, int dy) { - super.onScrolled(recyclerView, dx, dy); - int max = parallaxView.getHeight(); - if (dy > 0) { - parallaxView.setTranslationY(Math.max(-max, parallaxView.getTranslationY() - dy / 2)); - } else { - parallaxView.setTranslationY(Math.min(0, parallaxView.getTranslationY() - dy / 2)); - } + if (null != parallaxView && Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { + mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() { + @TargetApi(Build.VERSION_CODES.HONEYCOMB) + @Override + public void onScrolled(RecyclerView recyclerView, int dx, int dy) { + super.onScrolled(recyclerView, dx, dy); + int max = parallaxView.getHeight(); + if (dy > 0) { + parallaxView.setTranslationY(Math.max(-max, parallaxView.getTranslationY() - dy / 2)); + } else { + parallaxView.setTranslationY(Math.min(0, parallaxView.getTranslationY() - dy / 2)); } - }); - } + } + }); } final AppBarLayout appbarView = (AppBarLayout) rootView.findViewById(R.id.appbar); @@ -246,6 +215,45 @@ public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); } + @Override + public void onResume() { + SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getActivity()); + sp.registerOnSharedPreferenceChangeListener(this); + super.onResume(); + } + + @Override + public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { + inflater.inflate(R.menu.menu_main, menu); + } + + @Override + public void onPause() { + SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getActivity()); + sp.unregisterOnSharedPreferenceChangeListener(this); + super.onPause(); + } + + @Override + public void onDestroy() { + super.onDestroy(); + if (null != mRecyclerView) { + mRecyclerView.clearOnScrollListeners(); + } + } +//Lifecycle end + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + int id = item.getItemId(); + if (id == R.id.action_map) { + openPreferredLocationInMap(); + return true; + } + + return super.onOptionsItemSelected(item); + } + // since we read the location when we create the loader, all we need to do is restart things public void onLocationChanged() { getLoaderManager().restartLoader(FORECAST_LOADER, null, this); @@ -354,14 +362,6 @@ public boolean onPreDraw() { } - @Override - public void onDestroy() { - super.onDestroy(); - if (null != mRecyclerView) { - mRecyclerView.clearOnScrollListeners(); - } - } - @Override public void onLoaderReset(Loader loader) { mForecastAdapter.swapCursor(null); @@ -403,6 +403,7 @@ private void updateEmptyView() { if (!Utility.isNetworkAvailable(getActivity())) { message = R.string.empty_forecast_list_no_network; } + break; } tv.setText(message); } diff --git a/app/src/main/java/io/github/protino/sync/SunshineSyncAdapter.java b/app/src/main/java/io/github/protino/sync/SunshineSyncAdapter.java index 2970af2..4331ae5 100644 --- a/app/src/main/java/io/github/protino/sync/SunshineSyncAdapter.java +++ b/app/src/main/java/io/github/protino/sync/SunshineSyncAdapter.java @@ -634,7 +634,7 @@ private void notifyWeather() { * @param lon the longitude of the city * @return the row ID of the added location. */ - long addLocation(String locationSetting, String cityName, double lat, double lon) { + private long addLocation(String locationSetting, String cityName, double lat, double lon) { long locationId; // First, check if the location with this city name exists in the db diff --git a/app/src/main/java/io/github/protino/wearable/WearableDataService.java b/app/src/main/java/io/github/protino/wearable/WearableDataService.java index f468b4e..673b52f 100644 --- a/app/src/main/java/io/github/protino/wearable/WearableDataService.java +++ b/app/src/main/java/io/github/protino/wearable/WearableDataService.java @@ -20,6 +20,7 @@ import android.app.Service; import android.content.Context; import android.content.Intent; +import android.content.res.Resources; import android.database.Cursor; import android.net.Uri; import android.os.Bundle; @@ -125,7 +126,7 @@ private class SendUpdates extends Thread { WeatherContract.WeatherEntry.COLUMN_MIN_TEMP }; private final String location; - DataMap dataMap = new DataMap(); + private DataMap dataMap = new DataMap(); private SendUpdates(String location) { this.location = location; @@ -169,7 +170,7 @@ private DataMap fetchData() throws Exception { cursor.close(); return dataMap; } - throw new Exception("No data found in the database"); + throw new Resources.NotFoundException("No data found in the database"); } private void sendData(String path, DataMap dataMap) { diff --git a/app/src/main/java/io/github/protino/widget/DetailWidgetRemoteViewsService.java b/app/src/main/java/io/github/protino/widget/DetailWidgetRemoteViewsService.java index a833eb2..b969067 100644 --- a/app/src/main/java/io/github/protino/widget/DetailWidgetRemoteViewsService.java +++ b/app/src/main/java/io/github/protino/widget/DetailWidgetRemoteViewsService.java @@ -53,12 +53,12 @@ public RemoteViewsFactory onGetViewFactory(Intent intent) { private class ListRemoteViewFactory implements RemoteViewsService.RemoteViewsFactory { // these indices must match the projection - static final int INDEX_WEATHER_ID = 0; - static final int INDEX_WEATHER_DATE = 1; - static final int INDEX_WEATHER_CONDITION_ID = 2; - static final int INDEX_WEATHER_DESC = 3; - static final int INDEX_WEATHER_MAX_TEMP = 4; - static final int INDEX_WEATHER_MIN_TEMP = 5; + private static final int INDEX_WEATHER_ID = 0; + private static final int INDEX_WEATHER_DATE = 1; + private static final int INDEX_WEATHER_CONDITION_ID = 2; + private static final int INDEX_WEATHER_DESC = 3; + private static final int INDEX_WEATHER_MAX_TEMP = 4; + private static final int INDEX_WEATHER_MIN_TEMP = 5; private final String[] FORECAST_COLUMNS = { WeatherContract.WeatherEntry.TABLE_NAME + "." + WeatherContract.WeatherEntry._ID, WeatherContract.WeatherEntry.COLUMN_DATE, @@ -68,7 +68,7 @@ private class ListRemoteViewFactory implements RemoteViewsService.RemoteViewsFac WeatherContract.WeatherEntry.COLUMN_MIN_TEMP }; private final String LOG_TAG = ListRemoteViewFactory.class.getSimpleName(); - Context context; + private Context context; private Cursor data = null; ListRemoteViewFactory(Context applicationContext) { diff --git a/app/src/test/java/io/github/protino/ExampleUnitTest.java b/app/src/test/java/io/github/protino/ExampleUnitTest.java deleted file mode 100644 index 02934ca..0000000 --- a/app/src/test/java/io/github/protino/ExampleUnitTest.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright 2016 Gurupad Mamadapur - * - * 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 io.github.protino; - -import org.junit.Test; - -import static org.junit.Assert.*; - -/** - * To work on unit tests, switch the Test Artifact in the Build Variants view. - */ -public class ExampleUnitTest { - @Test - public void addition_isCorrect() throws Exception { - assertEquals(4, 2 + 2); - } -} \ No newline at end of file diff --git a/wear/src/main/java/io/github/protino/SunshineWatchFaceService.java b/wear/src/main/java/io/github/protino/SunshineWatchFaceService.java index 15affb5..1b32ccb 100644 --- a/wear/src/main/java/io/github/protino/SunshineWatchFaceService.java +++ b/wear/src/main/java/io/github/protino/SunshineWatchFaceService.java @@ -79,6 +79,8 @@ public void handleMessage(Message message) { long delayMs = 500 - (timeMs % 500); updateTimeHandler.sendEmptyMessageDelayed(MSG_UPDATE_TIME, delayMs); break; + default: //ignore + break; } } }; diff --git a/wear/src/main/java/io/github/protino/SunshineWatchFaceWearableConfigActivity.java b/wear/src/main/java/io/github/protino/SunshineWatchFaceWearableConfigActivity.java index 98cba7b..3fa1e6e 100644 --- a/wear/src/main/java/io/github/protino/SunshineWatchFaceWearableConfigActivity.java +++ b/wear/src/main/java/io/github/protino/SunshineWatchFaceWearableConfigActivity.java @@ -124,7 +124,7 @@ public int getItemCount() { } public class CustomViewHolder extends RecyclerView.ViewHolder { - CircledImageView imageView; + private CircledImageView imageView; public CustomViewHolder(View view) { super(view);