From 37929416aa548d094bccbe61a8d27931e963a45d Mon Sep 17 00:00:00 2001 From: Trilok Tourani Date: Fri, 30 Jan 2015 22:22:54 +0530 Subject: [PATCH] Issue[19][20][25] solved. --- README.org | 20 +++++ res/layout/main.xml | 3 +- res/values/array.xml | 13 ++++ res/values/strings.xml | 3 + res/xml/settings.xml | 11 +++ .../android/AllBookmarkListFragment.java | 3 + .../bmark/android/BookMarkDetailActivity.java | 10 ++- .../bmark/android/BookmarkListFragment.java | 32 ++++---- .../bmark/android/BookmarkListsActivity.java | 60 ++++++++++++--- .../android/MineBookmarkListFragment.java | 8 +- .../bmark/android/prefs/SettingsActivity.java | 75 ++++++++++++++++++- 11 files changed, 203 insertions(+), 35 deletions(-) create mode 100644 res/values/array.xml diff --git a/README.org b/README.org index 3b2aa44..753697f 100644 --- a/README.org +++ b/README.org @@ -25,5 +25,25 @@ Licensed under GPLv3. See the file COPYING, included with this source. +xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx + +For Developers : +--------------- +*** For building/running the project on eclipse/android studio, the following libraries have to be imported namely: + +android-support-v4-1.jar +hamcrest-1.3.jar +annotations-10.0.2.jar +gson-2.2.2.jar +retrofit-1.2.1.jar +junit.jar +jetbrains-annotations.jar + +*** For importing BookieClient API and BookieParserClient API, download the source projects from here: + +https://github.com/bookieio/BookieClient +https://github.com/bookieio/BookieParserClient + +xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx diff --git a/res/layout/main.xml b/res/layout/main.xml index d8f178b..dc18e68 100644 --- a/res/layout/main.xml +++ b/res/layout/main.xml @@ -1,5 +1,6 @@ @@ -8,4 +9,4 @@ android:layout_width="match_parent" android:layout_height="match_parent" /> - \ No newline at end of file + diff --git a/res/values/array.xml b/res/values/array.xml new file mode 100644 index 0000000..205eb6f --- /dev/null +++ b/res/values/array.xml @@ -0,0 +1,13 @@ + + + + Dark + Light + Glass + + + 1 + 2 + 3 + + diff --git a/res/values/strings.xml b/res/values/strings.xml index fe861d0..fb085ac 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -1,6 +1,9 @@ Bookie + Fetching all Bookmarks" + Updating your Bookmarks + Please enter your username and API key in the Settings menu OK Cancel All diff --git a/res/xml/settings.xml b/res/xml/settings.xml index d863eb2..1ba99b3 100644 --- a/res/xml/settings.xml +++ b/res/xml/settings.xml @@ -46,5 +46,16 @@ android:defaultValue="@string/settings_parseurl_defaultvalue"/> + + + + + \ No newline at end of file diff --git a/src/main/java/us/bmark/android/AllBookmarkListFragment.java b/src/main/java/us/bmark/android/AllBookmarkListFragment.java index f76dc11..1ef4d61 100644 --- a/src/main/java/us/bmark/android/AllBookmarkListFragment.java +++ b/src/main/java/us/bmark/android/AllBookmarkListFragment.java @@ -1,11 +1,14 @@ package us.bmark.android; import android.os.Bundle; +import android.widget.Toast; public class AllBookmarkListFragment extends BookmarkListFragment { @Override void refresh() { + Toast.makeText(getActivity(),R.string.fetch_all_bm, + Toast.LENGTH_SHORT).show(); int nextPage = pagesLoaded; refreshState.setStateInProgress(); service.everyonesRecent(countPP, nextPage, new ServiceCallback()); diff --git a/src/main/java/us/bmark/android/BookMarkDetailActivity.java b/src/main/java/us/bmark/android/BookMarkDetailActivity.java index b128bbb..f4bfe2f 100644 --- a/src/main/java/us/bmark/android/BookMarkDetailActivity.java +++ b/src/main/java/us/bmark/android/BookMarkDetailActivity.java @@ -1,5 +1,9 @@ package us.bmark.android; + +import us.bmark.android.R; +import us.bmark.android.prefs.SharedPrefsBackedUserSettings; +import us.bmark.android.utils.IntentConstants; import android.content.Intent; import android.os.Bundle; import android.util.Log; @@ -13,8 +17,6 @@ import com.google.gson.JsonParseException; import com.google.gson.JsonSyntaxException; -import us.bmark.android.prefs.SharedPrefsBackedUserSettings; -import us.bmark.android.utils.IntentConstants; import us.bmark.bookieclient.Bookmark; import us.bmark.bookieclient.Tag; @@ -46,6 +48,8 @@ private void dealWithIntents() { populateFields(bmark); } catch (JsonSyntaxException e) { Log.e(TAG, "Error getting bookmark detail", e); + Toast.makeText(getActivity(),"Some error occured while fetching bookmark details" , + Toast.LENGTH_SHORT).show(); } } @@ -90,7 +94,7 @@ private TableRow createTagRow(CharSequence tagText) { } private UserSettings userSettings() { - return new SharedPrefsBackedUserSettings(this); + return (UserSettings) new SharedPrefsBackedUserSettings(this); } } diff --git a/src/main/java/us/bmark/android/BookmarkListFragment.java b/src/main/java/us/bmark/android/BookmarkListFragment.java index 90a7f81..e629a8f 100644 --- a/src/main/java/us/bmark/android/BookmarkListFragment.java +++ b/src/main/java/us/bmark/android/BookmarkListFragment.java @@ -1,6 +1,21 @@ package us.bmark.android; +import static us.bmark.android.utils.Utils.isBlank; + +import java.util.ArrayList; +import java.util.List; + +import retrofit.Callback; +import retrofit.RestAdapter; +import retrofit.RetrofitError; +import retrofit.client.Response; +import us.bmark.android.R; +import us.bmark.android.prefs.SharedPrefsBackedUserSettings; +import us.bmark.android.utils.ErrorHandler; +import us.bmark.android.utils.IntentConstants; +import us.bmark.android.utils.JustDisplayToastErrorHandler; import android.app.Activity; + import android.content.Context; import android.content.Intent; import android.net.Uri; @@ -17,25 +32,12 @@ import android.widget.ListView; import android.widget.TextView; -import com.google.gson.Gson; - -import java.util.ArrayList; -import java.util.List; - -import retrofit.Callback; -import retrofit.RestAdapter; -import retrofit.RetrofitError; -import retrofit.client.Response; -import us.bmark.android.prefs.SharedPrefsBackedUserSettings; -import us.bmark.android.utils.ErrorHandler; -import us.bmark.android.utils.IntentConstants; -import us.bmark.android.utils.JustDisplayToastErrorHandler; import us.bmark.bookieclient.BookieService; import us.bmark.bookieclient.BookieServiceUtils; import us.bmark.bookieclient.Bookmark; import us.bmark.bookieclient.BookmarkList; -import static us.bmark.android.utils.Utils.isBlank; +import com.google.gson.Gson; public abstract class BookmarkListFragment extends ListFragment { @@ -136,7 +138,7 @@ public View onCreateView(LayoutInflater inflater, public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); - settings = new SharedPrefsBackedUserSettings(getActivity()); + settings = (UserSettings) new SharedPrefsBackedUserSettings(getActivity()); String serverUrl = settings.getBaseUrl(); RestAdapter restAdapter = new RestAdapter.Builder() diff --git a/src/main/java/us/bmark/android/BookmarkListsActivity.java b/src/main/java/us/bmark/android/BookmarkListsActivity.java index 7dc7340..b3957d5 100644 --- a/src/main/java/us/bmark/android/BookmarkListsActivity.java +++ b/src/main/java/us/bmark/android/BookmarkListsActivity.java @@ -1,8 +1,16 @@ package us.bmark.android; +import java.util.ArrayList; +import java.util.Collection; + +import us.bmark.android.prefs.SettingsActivity; import android.app.ActionBar; import android.app.FragmentTransaction; import android.content.Intent; +import android.content.SharedPreferences; +import android.content.SharedPreferences.Editor; +import android.graphics.Color; +import android.graphics.drawable.ColorDrawable; import android.os.Bundle; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentActivity; @@ -13,14 +21,11 @@ import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; +import android.view.View; import android.view.Window; +import android.widget.ImageView; import android.widget.SearchView; -import java.util.ArrayList; -import java.util.Collection; - -import us.bmark.android.prefs.SettingsActivity; - public class BookmarkListsActivity extends FragmentActivity { private static final String TAG = BookmarkListsActivity.class.getName(); @@ -31,7 +36,7 @@ public class BookmarkListsActivity extends FragmentActivity { private BookmarkListFragment allFragment; private SearchBookmarkFragment searchFragment; private ViewPager pager; - + private ActionBar.TabListener tabListener = new ActionBar.TabListener() { @Override @@ -51,7 +56,11 @@ public void onTabReselected(ActionBar.Tab tab, FragmentTransaction ft) { }; private MultiRefreshStateObserver observer; private BookmarkListsActivity.BookiePagerAdapter tabsPagerAdapter; - + String id="something"; + SharedPreferences settings; + Editor editor; + String col; + ActionBar actionBar; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -59,11 +68,21 @@ public void onCreate(Bundle savedInstanceState) { setContentView(R.layout.main); pager = (ViewPager) findViewById(R.id.pager); createFragments(savedInstanceState); - - final ActionBar actionBar = getActionBar(); + id = getIntent().getStringExtra("caller"); + //Get Sharedpreferences + settings = getSharedPreferences("mypref", MODE_PRIVATE); + //Get editor + editor = settings.edit(); + //always set col to the color saved last time user had chosen it(for the first time 1--dark) + col = settings.getString("mycolor", "1"); + + actionBar = getActionBar(); actionBar.setDisplayHomeAsUpEnabled(false); // Hides the '<' button in the ActionBar actionBar.setHomeButtonEnabled(true); // Enables the 'B' icon to be tappable on the list Activity actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); + + //always change color to that. + ChangeColor(col); pager.setOnPageChangeListener( new ViewPager.SimpleOnPageChangeListener() { @@ -76,6 +95,25 @@ public void onPageSelected(int position) { }); } + //changing theme color of main + public void ChangeColor(String a){ + View v = findViewById(R.id.main); + if(a.equals("1")) + { + v.setBackgroundColor(Color.BLACK); + actionBar.setBackgroundDrawable(new ColorDrawable(Color.BLACK)); + } + else if(a.equals("2")) + { + v.setBackgroundColor(Color.GRAY); + actionBar.setBackgroundDrawable(new ColorDrawable(Color.GRAY)); + } + else if(a.equals("3")) + { + v.setBackgroundColor(Color.TRANSPARENT); + actionBar.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); + } + } @Override protected void onResume() { @@ -209,7 +247,6 @@ public Fragment getItem(int position) { return fragments[position]; } - @Override public CharSequence getPageTitle(int position) { return getString(titleIds[position]); } @@ -270,4 +307,5 @@ private void refreshActiveFragment() { (BookmarkListFragment) tabsPagerAdapter.getFragments()[pager.getCurrentItem()]; activeFragment.refresh(); } -} \ No newline at end of file + +} diff --git a/src/main/java/us/bmark/android/MineBookmarkListFragment.java b/src/main/java/us/bmark/android/MineBookmarkListFragment.java index 468d552..c7e6448 100644 --- a/src/main/java/us/bmark/android/MineBookmarkListFragment.java +++ b/src/main/java/us/bmark/android/MineBookmarkListFragment.java @@ -1,12 +1,12 @@ package us.bmark.android; +import static us.bmark.android.utils.Utils.isBlank; import android.os.Bundle; import android.view.Gravity; import android.view.View; import android.widget.ListView; import android.widget.TextView; - -import static us.bmark.android.utils.Utils.isBlank; +import android.widget.Toast; public class MineBookmarkListFragment extends BookmarkListFragment { @@ -17,6 +17,8 @@ void refresh() { ListView bookieList = getListView(); bookieList.setVisibility(View.GONE); } + Toast.makeText(getActivity(),R.string.update_your_bm, + Toast.LENGTH_SHORT).show(); int nextPage = pagesLoaded; refreshState.setStateInProgress(); service.recent(settings.getUsername(), @@ -38,6 +40,8 @@ public void onActivityCreated(Bundle savedInstanceState) { private void populateNotLoggedInTextView() { TextView userNotLoggedInMessagae = findView(R.id.userNotLoggedInMessagae); + Toast.makeText(getActivity(),R.string.please_enter, + Toast.LENGTH_SHORT).show(); userNotLoggedInMessagae.setVisibility(View.VISIBLE); userNotLoggedInMessagae.setText(R.string.message_user_not_logged_in); userNotLoggedInMessagae.setGravity(Gravity.CENTER); diff --git a/src/main/java/us/bmark/android/prefs/SettingsActivity.java b/src/main/java/us/bmark/android/prefs/SettingsActivity.java index ab23fee..d266d59 100644 --- a/src/main/java/us/bmark/android/prefs/SettingsActivity.java +++ b/src/main/java/us/bmark/android/prefs/SettingsActivity.java @@ -1,16 +1,85 @@ package us.bmark.android.prefs; +import us.bmark.android.BookmarkListsActivity; +import us.bmark.android.R; +import android.content.Intent; +import android.content.SharedPreferences; +import android.content.SharedPreferences.Editor; +import android.content.SharedPreferences.OnSharedPreferenceChangeListener; +import android.graphics.Color; import android.os.Bundle; import android.preference.PreferenceActivity; +import android.preference.PreferenceManager; -import us.bmark.android.R; - -public class SettingsActivity extends PreferenceActivity { +public class SettingsActivity extends PreferenceActivity implements OnSharedPreferenceChangeListener{ + SharedPreferences getPrefs; + SharedPreferences settings; + Editor editor; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); getActionBar().setDisplayHomeAsUpEnabled(true); addPreferencesFromResource(R.xml.settings); + + getPrefs = PreferenceManager + .getDefaultSharedPreferences(getBaseContext()); + settings = getSharedPreferences("mypref", MODE_PRIVATE); + editor = settings.edit(); + //As soon as it comes into SettingsActivity \, checks for last color, updates it. + String colorid = settings.getString("mycolor", "1"); + if(colorid.equals("1")) + { + getListView().setBackgroundColor(Color.BLACK); + } + else if(colorid.equals("2")) + { + getListView().setBackgroundColor(Color.GRAY); + } + else if(colorid.equals("3")) + { + getListView().setBackgroundColor(Color.TRANSPARENT); + } + + } + protected void onResume() { + super.onResume(); + // Set up a listener whenever a key changes + getPreferenceScreen().getSharedPreferences() + .registerOnSharedPreferenceChangeListener(this); } + + protected void onPause() { + super.onPause(); + // Unregister the listener whenever a key changes + getPreferenceScreen().getSharedPreferences() + .unregisterOnSharedPreferenceChangeListener(this); + } + + + @Override + public void onSharedPreferenceChanged(SharedPreferences arg0, String arg1) { + // TODO Auto-generated method stub + String bg_set = getPrefs + .getString("theme_preference",settings.getString("mycolor", "1")); + Intent intent = new Intent(SettingsActivity.this, BookmarkListsActivity.class); + intent.putExtra("caller","calling"); + + // Writing data to SharedPreferences + editor.putString("mycolor",bg_set); + editor.commit(); + //As soon as it is chosen, SettingsActivity background changes. + if(bg_set.equals("1")) + { + getListView().setBackgroundColor(Color.BLACK); + } + else if(bg_set.equals("2")) + { + getListView().setBackgroundColor(Color.GRAY); + } + else if(bg_set.equals("3")) + { + getListView().setBackgroundColor(Color.TRANSPARENT); + } + } }