├── .gitignore
├── LICENSE.md
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── spielpark
│ │ └── steve
│ │ └── bernieapp
│ │ └── ApplicationTest.java
│ └── main
│ ├── AndroidManifest.xml
│ ├── assets
│ ├── Freight.ttf
│ └── Jubilat.otf
│ ├── java
│ └── com
│ │ └── spielpark
│ │ └── steve
│ │ └── bernieapp
│ │ ├── actMainPage.java
│ │ ├── fragments
│ │ ├── BernRateFragment.java
│ │ ├── BottomNavFragment.java
│ │ ├── ConnectFragment.java
│ │ ├── DonateFragment.java
│ │ ├── FeedbackFragment.java
│ │ ├── IssuesFragment.java
│ │ ├── NavigationDrawerFragment.java
│ │ ├── NewsFragment.java
│ │ ├── OrganizeFragment.java
│ │ ├── SingleIssueFragment.java
│ │ └── SingleNewsFragment.java
│ │ ├── misc
│ │ ├── ImgTxtAdapter.java
│ │ └── Util.java
│ │ ├── tasks
│ │ ├── ConnectTask.java
│ │ ├── IssuesTask.java
│ │ └── NewsTask.java
│ │ └── wrappers
│ │ ├── Event.java
│ │ ├── ImgTxtItem.java
│ │ ├── Issue.java
│ │ ├── NavDrawerItem.java
│ │ └── NewsArticle.java
│ └── res
│ ├── anim
│ ├── view_fade_in.xml
│ ├── view_fade_in_fast.xml
│ └── view_slide_up.xml
│ ├── drawable-hdpi
│ ├── drawer_shadow.9.png
│ ├── ic_attach_money_white_24dp.png
│ ├── ic_check_circle_black_24dp.png
│ ├── ic_drawer.png
│ ├── ic_event_black_24dp.png
│ ├── ic_event_note_white_24dp.png
│ ├── ic_face_black_24dp.png
│ ├── ic_feedback_white_24dp.png
│ ├── ic_group_work_black_24dp.png
│ ├── ic_insert_chart_white_24dp.png
│ ├── ic_map_white_24dp.png
│ ├── ic_navigation_black_24dp.png
│ ├── ic_people_white_24dp.png
│ ├── ic_place_black_24dp.png
│ └── ic_public_white_24dp.png
│ ├── drawable-mdpi
│ ├── drawer_shadow.9.png
│ ├── ic_attach_money_white_24dp.png
│ ├── ic_check_circle_black_24dp.png
│ ├── ic_drawer.png
│ ├── ic_event_black_24dp.png
│ ├── ic_event_note_white_24dp.png
│ ├── ic_face_black_24dp.png
│ ├── ic_feedback_white_24dp.png
│ ├── ic_group_work_black_24dp.png
│ ├── ic_insert_chart_white_24dp.png
│ ├── ic_map_white_24dp.png
│ ├── ic_navigation_black_24dp.png
│ ├── ic_people_white_24dp.png
│ ├── ic_place_black_24dp.png
│ └── ic_public_white_24dp.png
│ ├── drawable-xhdpi
│ ├── drawer_shadow.9.png
│ ├── ic_attach_money_white_24dp.png
│ ├── ic_check_circle_black_24dp.png
│ ├── ic_drawer.png
│ ├── ic_event_black_24dp.png
│ ├── ic_event_note_white_24dp.png
│ ├── ic_face_black_24dp.png
│ ├── ic_feedback_white_24dp.png
│ ├── ic_group_work_black_24dp.png
│ ├── ic_insert_chart_white_24dp.png
│ ├── ic_map_white_24dp.png
│ ├── ic_navigation_black_24dp.png
│ ├── ic_people_white_24dp.png
│ ├── ic_place_black_24dp.png
│ └── ic_public_white_24dp.png
│ ├── drawable-xxhdpi
│ ├── drawer_shadow.9.png
│ ├── ic_attach_money_white_24dp.png
│ ├── ic_check_circle_black_24dp.png
│ ├── ic_drawer.png
│ ├── ic_event_black_24dp.png
│ ├── ic_event_note_white_24dp.png
│ ├── ic_face_black_24dp.png
│ ├── ic_feedback_white_24dp.png
│ ├── ic_group_work_black_24dp.png
│ ├── ic_insert_chart_white_24dp.png
│ ├── ic_map_white_24dp.png
│ ├── ic_navigation_black_24dp.png
│ ├── ic_people_white_24dp.png
│ ├── ic_place_black_24dp.png
│ └── ic_public_white_24dp.png
│ ├── drawable-xxxhdpi
│ ├── ic_attach_money_white_24dp.png
│ ├── ic_check_circle_black_24dp.png
│ ├── ic_event_black_24dp.png
│ ├── ic_event_note_white_24dp.png
│ ├── ic_face_black_24dp.png
│ ├── ic_feedback_white_24dp.png
│ ├── ic_group_work_black_24dp.png
│ ├── ic_insert_chart_white_24dp.png
│ ├── ic_map_white_24dp.png
│ ├── ic_navigation_black_24dp.png
│ ├── ic_people_white_24dp.png
│ ├── ic_place_black_24dp.png
│ └── ic_public_white_24dp.png
│ ├── drawable
│ ├── logo.png
│ ├── news_header_border.xml
│ ├── search_border.xml
│ ├── shadow.xml
│ └── vermont_state_house.png
│ ├── layout
│ ├── dialogue_checkbox.xml
│ ├── frag_bernrate.xml
│ ├── frag_bottom_nav.xml
│ ├── frag_connect.xml
│ ├── frag_donate.xml
│ ├── frag_event.xml
│ ├── frag_feedback.xml
│ ├── frag_issues.xml
│ ├── frag_nav.xml
│ ├── frag_newsarticles.xml
│ ├── frag_organize.xml
│ ├── frag_single_issue.xml
│ ├── layout_main_page.xml
│ ├── list_connect_events.xml
│ ├── list_drawer_item.xml
│ └── list_news_item.xml
│ ├── menu
│ └── share_menu.xml
│ ├── mipmap-hdpi
│ └── ic_launcher.png
│ ├── mipmap-mdpi
│ └── ic_launcher.png
│ ├── mipmap-xhdpi
│ └── ic_launcher.png
│ ├── mipmap-xxhdpi
│ └── ic_launcher.png
│ ├── mipmap-xxxhdpi
│ └── ic_launcher.png
│ ├── values-w820dp
│ └── dimens.xml
│ └── values
│ ├── dimens.xml
│ ├── strings.xml
│ └── styles.xml
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | # built application files
2 | *.apk
3 | *.ap_
4 |
5 | # files for the dex VM
6 | *.dex
7 |
8 | # Java class files
9 | *.class
10 |
11 | # generated files
12 | bin/
13 | gen/
14 | out/
15 | build/
16 |
17 | # Local configuration file (sdk path, etc)
18 | local.properties
19 |
20 | # Eclipse project files
21 | .classpath
22 | .project
23 |
24 | # Windows thumbnail db
25 | .DS_Store
26 |
27 | # IDEA/Android Studio project files, because
28 | # the project can be imported from settings.gradle
29 | .idea
30 | *.iml
31 |
32 | # Old-style IDEA project files
33 | *.ipr
34 | *.iws
35 |
36 | # Local IDEA workspace
37 | .idea/workspace.xml
38 |
39 | # Gradle cache
40 | .gradle
41 |
42 | # Sandbox stuff
43 | _sandbox
44 |
45 | # API keys
46 | key.xml
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | This is the Android application for Bernie Sanders
2 |
3 | Copyright (C) 2015 /r/CodersForSanders
4 |
5 | This program is free software: you can redistribute it and/or modify
6 | it under the terms of the GNU Affero General Public License as
7 | published by the Free Software Foundation, either version 3 of the
8 | License, or (at your option) any later version.
9 |
10 | This program is distributed in the hope that it will be useful,
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | GNU Affero General Public License for more details.
14 |
15 | You should have received a copy of the GNU Affero General Public License
16 | along with this program. If not, see .
17 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Bernie App for Android
2 |
3 | This is the Bernie App for Android
4 |
5 | Tracker Backlog: https://www.pivotaltracker.com/n/projects/1414762
6 |
7 | Slack channel (you can request access [here](https://docs.google.com/forms/d/1pmxGTX17qPkZV49iuLh3rN-Mj_Z6w6M_XtUJMZCMIP4/viewform)): https://codersforsanders.slack.com/messages/bernie-app/details/
8 |
9 | # Setting up your build environment
10 |
11 | This project compiles using Android Studio and gradle. You should be able to import from
12 | VCS in the Android Studio start-up panel. After importing, you'll need a couple of api keys.
13 | First off you'll need a Google Maps API key. After following the instructions to get an
14 | Android api key [here](https://developers.google.com/maps/documentation/android/signup),
15 | create a new file called key.xml under app/src/main/res/values. Your file should look this
16 |
17 | ```xml
18 |
19 |
20 | YOUR_API_KEY_HERE
21 |
22 | ```
23 |
24 | Make sure that this file is not under version control!
25 |
26 | For the time being, you'll also want to get hold of a Firesize api key [here](http://firesize.com/) and once
27 | you do, place it in the key.xml file. The api key in this case is going to be the top level domain.
28 | Your final file should look like this:
29 |
30 | ```xml
31 |
32 |
33 | GOOGLE_MAPS_API_KEY
34 | FIRE_SIZE_API_KEY
35 |
36 | ```
37 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 23
5 | buildToolsVersion "21.1.2"
6 |
7 | defaultConfig {
8 | applicationId "com.spielpark.steve.bernieapp"
9 | minSdkVersion 14
10 | targetSdkVersion 23
11 | versionCode 18
12 | versionName "1.6R"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | dependencies {
23 | compile fileTree(include: ['*.jar'], dir: 'libs')
24 | compile 'com.android.support:appcompat-v7:23.1.0'
25 | compile 'se.emilsjolander:StickyScrollViewItems:1.1.0'
26 | compile 'com.google.android.gms:play-services:8.1.0'
27 | compile 'com.squareup.picasso:picasso:2.5.2'
28 | }
29 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in E:\Programs & Shit\SDK Android/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/spielpark/steve/bernieapp/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.spielpark.steve.bernieapp;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
12 |
13 |
16 |
17 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
30 |
33 |
34 |
35 |
36 |
37 |
84 |
--------------------------------------------------------------------------------
/app/src/main/assets/Freight.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SandersForPresident/BernieAppAndroid/c76187f451cad5abec4664a57990b0ad206643d6/app/src/main/assets/Freight.ttf
--------------------------------------------------------------------------------
/app/src/main/assets/Jubilat.otf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SandersForPresident/BernieAppAndroid/c76187f451cad5abec4664a57990b0ad206643d6/app/src/main/assets/Jubilat.otf
--------------------------------------------------------------------------------
/app/src/main/java/com/spielpark/steve/bernieapp/actMainPage.java:
--------------------------------------------------------------------------------
1 | package com.spielpark.steve.bernieapp;
2 |
3 | import android.content.Intent;
4 | import android.content.SharedPreferences;
5 | import android.graphics.Color;
6 | import android.graphics.drawable.ColorDrawable;
7 | import android.net.Uri;
8 | import android.os.Bundle;
9 | import android.support.v4.app.Fragment;
10 | import android.support.v4.app.FragmentManager;
11 | import android.support.v4.view.MenuItemCompat;
12 | import android.support.v4.widget.DrawerLayout;
13 | import android.support.v7.app.ActionBar;
14 | import android.support.v7.app.ActionBarActivity;
15 | import android.support.v7.widget.ShareActionProvider;
16 | import android.util.Log;
17 | import android.view.Menu;
18 | import android.view.MenuInflater;
19 | import android.view.MenuItem;
20 | import android.view.View;
21 | import android.widget.TextView;
22 |
23 | import com.google.android.gms.appindexing.Action;
24 | import com.google.android.gms.appindexing.AppIndex;
25 | import com.google.android.gms.common.api.GoogleApiClient;
26 | import com.spielpark.steve.bernieapp.fragments.BernRateFragment;
27 | import com.spielpark.steve.bernieapp.fragments.ConnectFragment;
28 | import com.spielpark.steve.bernieapp.fragments.DonateFragment;
29 | import com.spielpark.steve.bernieapp.fragments.FeedbackFragment;
30 | import com.spielpark.steve.bernieapp.fragments.IssuesFragment;
31 | import com.spielpark.steve.bernieapp.fragments.NavigationDrawerFragment;
32 | import com.spielpark.steve.bernieapp.fragments.NewsFragment;
33 | import com.spielpark.steve.bernieapp.fragments.OrganizeFragment;
34 | import com.spielpark.steve.bernieapp.fragments.SingleIssueFragment;
35 | import com.spielpark.steve.bernieapp.fragments.SingleNewsFragment;
36 | import com.spielpark.steve.bernieapp.tasks.NewsTask;
37 | import com.spielpark.steve.bernieapp.wrappers.Issue;
38 | import com.spielpark.steve.bernieapp.wrappers.NewsArticle;
39 |
40 |
41 | public class actMainPage extends ActionBarActivity
42 | implements NavigationDrawerFragment.NavigationDrawerCallbacks {
43 | /**
44 | * Fragment managing the behaviors, interactions and presentation of the navigation drawer.
45 | */
46 | private NavigationDrawerFragment mNavigationDrawerFragment;
47 | private static SharedPreferences preferences;
48 | private static Fragment curFrag;
49 |
50 | private CharSequence mTitle;
51 |
52 | private GoogleApiClient client;
53 |
54 | @Override
55 | protected void onStop() {
56 | super.onStop();
57 | Action viewAction = Action.newAction(
58 | Action.TYPE_VIEW, // TODO: choose an action type.
59 | "actMainPage Page", // TODO: Define a title for the content shown.
60 | // TODO: If you have web page content that matches this app activity's content,
61 | // make sure this auto-generated web page URL is correct.
62 | // Otherwise, set the URL to null.
63 | Uri.parse("http://host/path"),
64 | // TODO: Make sure this auto-generated app deep link URI is correct.
65 | Uri.parse("android-app://com.spielpark.steve.bernieapp/http/host/path")
66 | );
67 | AppIndex.AppIndexApi.end(client, viewAction);
68 | // ATTENTION: This was auto-generated to implement the App Indexing API.
69 | // See https://g.co/AppIndexing/AndroidStudio for more information.
70 | client.disconnect();
71 | }
72 |
73 | @Override
74 | protected void onCreate(Bundle savedInstanceState) {
75 | super.onCreate(savedInstanceState);
76 | setContentView(R.layout.layout_main_page);
77 | mNavigationDrawerFragment = (NavigationDrawerFragment)
78 | getSupportFragmentManager().findFragmentById(R.id.navigation_drawer);
79 | mTitle = getTitle();
80 | // Set up the drawer.
81 | mNavigationDrawerFragment.setUp(
82 | R.id.navigation_drawer,
83 | (DrawerLayout) findViewById(R.id.drawer_layout));
84 | ActionBar bar = getSupportActionBar();
85 | bar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#147FD7")));
86 | mTitle = "News";
87 | preferences = getApplicationContext().getSharedPreferences("bernie_app_prefs", 0);
88 | adjustNavBarText(0);
89 | // ATTENTION: This was auto-generated to implement the App Indexing API.
90 | // See https://g.co/AppIndexing/AndroidStudio for more information.
91 | client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
92 | }
93 |
94 | @Override
95 | public void onNavigationDrawerItemSelected(int position) {
96 | if (curFrag instanceof ConnectFragment) {
97 | ConnectFragment.cancelTask(); //cancel loading the map.
98 | }
99 | // update the main content by replacing fragments
100 | FragmentManager fragmentManager = getSupportFragmentManager();
101 | fragmentManager.popBackStack("base", FragmentManager.POP_BACK_STACK_INCLUSIVE);
102 | Fragment replacement;
103 | switch (position) {
104 | case 0: {
105 | replacement = NewsFragment.getInstance();
106 | break;
107 | }
108 | case 1: {
109 | replacement = IssuesFragment.getInstance();
110 | break;
111 | }
112 | case 2: {
113 | replacement = OrganizeFragment.getInstance();
114 | break;
115 | }
116 | case 3: {
117 | replacement = ConnectFragment.getInstance();
118 | break;
119 | }
120 | case 4: {
121 | replacement = BernRateFragment.getInstance();
122 | break;
123 | }
124 | case 5: {
125 | replacement = DonateFragment.getInstance();
126 | break;
127 | }
128 | case 6: {
129 | replacement = FeedbackFragment.getInstance();
130 | break;
131 | }
132 | default: {
133 | replacement = NewsFragment.getInstance();
134 | }
135 | }
136 | if (replacement.isAdded()) return;
137 | adjustNavBarText(position);
138 | curFrag = replacement;
139 | onSectionAttached(++position);
140 | fragmentManager.beginTransaction()
141 | .replace(R.id.container, replacement)
142 | .commit();
143 | }
144 |
145 | public void onSectionAttached(int number) {
146 | switch (number) {
147 | case 1:
148 | mTitle = getString(R.string.title_section1);
149 | break;
150 | case 2:
151 | mTitle = getString(R.string.title_section2);
152 | break;
153 | case 3:
154 | mTitle = getString(R.string.title_section3);
155 | break;
156 | case 4:
157 | mTitle = getString(R.string.title_section4);
158 | break;
159 | case 5:
160 | mTitle = getString(R.string.title_section5);
161 | break;
162 | case 6:
163 | mTitle = getString(R.string.title_section6);
164 | break;
165 | case 7:
166 | mTitle = getString(R.string.title_section7);
167 | break;
168 | }
169 | }
170 |
171 | public void restoreActionBar() {
172 | ActionBar actionBar = getSupportActionBar();
173 | actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
174 | actionBar.setDisplayShowTitleEnabled(true);
175 | actionBar.setTitle(mTitle);
176 | }
177 |
178 | @Override
179 | public boolean onCreateOptionsMenu(Menu menu) {
180 | if (!mNavigationDrawerFragment.isDrawerOpen()) {
181 | restoreActionBar();
182 | //return true;
183 | }
184 | return super.onCreateOptionsMenu(menu);
185 | }
186 |
187 | @Override
188 | public void onBackPressed() {
189 | if (curFrag instanceof ConnectFragment) {
190 | ((ConnectFragment) curFrag).backPressed();
191 | return;
192 | } else if (curFrag instanceof OrganizeFragment) {
193 | if (((OrganizeFragment) curFrag).canGoBack()) {
194 | return;
195 | }
196 | }
197 | if (getSupportFragmentManager().getBackStackEntryCount() == 0) {
198 | this.finish();
199 | } else {
200 | getSupportFragmentManager().popBackStack("base", FragmentManager.POP_BACK_STACK_INCLUSIVE);
201 | }
202 | }
203 |
204 | public void loadEvent(NewsArticle e) {
205 | Fragment f = SingleNewsFragment.getInstance(e);
206 | FragmentManager manager = getSupportFragmentManager();
207 | if (manager.getBackStackEntryCount() > 0) {
208 | manager.popBackStack();
209 | }
210 | manager.beginTransaction().addToBackStack("base").replace(R.id.container, f).commit();
211 | curFrag = f;
212 | }
213 |
214 | public void loadIssue(Issue i) {
215 | Fragment f = SingleIssueFragment.newInstance(i);
216 | FragmentManager manager = getSupportFragmentManager();
217 | if (manager.getBackStackEntryCount() > 0) {
218 | manager.popBackStack();
219 | }
220 | manager.beginTransaction().addToBackStack("base").replace(R.id.container, f).commit();
221 | curFrag = f;
222 | }
223 |
224 | public SharedPreferences getPrefs() {
225 | return this.preferences;
226 | }
227 |
228 | public void loadHeaderArticle(View view) {
229 | if (NewsTask.getData() != null) {
230 | for (NewsArticle a : NewsTask.getData()) {
231 | if (a.getUrl().contains("press-release")) {
232 | this.loadEvent(a);
233 | break;
234 | }
235 | }
236 | }
237 | }
238 |
239 | public void adjustNavBarText(int selected) {
240 | TextView[] views = new TextView[]{
241 | (TextView) findViewById(R.id.newsTxt),
242 | (TextView) findViewById(R.id.issuesTxt),
243 | (TextView) findViewById(R.id.organizeTxt),
244 | (TextView) findViewById(R.id.connectTxt)
245 | };
246 | for (int i = 0; i < views.length; i++) {
247 | TextView t = views[i];
248 | if (t == null) {
249 | return;
250 | }
251 | if (i == selected) {
252 | t.setTextColor(Color.parseColor("#FFC207"));
253 | } else {
254 | t.setTextColor(Color.parseColor("#FFFFFF"));
255 | }
256 | }
257 | }
258 |
259 | public void switchPage(View view) {
260 | int selected = Integer.parseInt((String) view.getTag());
261 | onNavigationDrawerItemSelected(selected);
262 | onSectionAttached(selected + 1);
263 | restoreActionBar();
264 | adjustNavBarText(selected);
265 | NavigationDrawerFragment.setSelected(selected);
266 | }
267 |
268 | @Override
269 | public void onStart() {
270 | super.onStart();
271 |
272 | // ATTENTION: This was auto-generated to implement the App Indexing API.
273 | // See https://g.co/AppIndexing/AndroidStudio for more information.
274 | client.connect();
275 | Action viewAction = Action.newAction(
276 | Action.TYPE_VIEW, // TODO: choose an action type.
277 | "actMainPage Page", // TODO: Define a title for the content shown.
278 | // TODO: If you have web page content that matches this app activity's content,
279 | // make sure this auto-generated web page URL is correct.
280 | // Otherwise, set the URL to null.
281 | Uri.parse("http://host/path"),
282 | // TODO: Make sure this auto-generated app deep link URI is correct.
283 | Uri.parse("android-app://com.spielpark.steve.bernieapp/http/host/path")
284 | );
285 | AppIndex.AppIndexApi.start(client, viewAction);
286 | }
287 | }
288 |
--------------------------------------------------------------------------------
/app/src/main/java/com/spielpark/steve/bernieapp/fragments/BernRateFragment.java:
--------------------------------------------------------------------------------
1 | package com.spielpark.steve.bernieapp.fragments;
2 |
3 |
4 | import android.content.SharedPreferences;
5 | import android.os.Bundle;
6 | import android.support.v4.app.Fragment;
7 | import android.util.Log;
8 | import android.view.Gravity;
9 | import android.view.LayoutInflater;
10 | import android.view.View;
11 | import android.view.ViewGroup;
12 | import android.webkit.WebChromeClient;
13 | import android.webkit.WebSettings;
14 | import android.webkit.WebView;
15 | import android.widget.LinearLayout;
16 | import android.widget.RelativeLayout;
17 |
18 | import com.spielpark.steve.bernieapp.R;
19 | import com.spielpark.steve.bernieapp.actMainPage;
20 | import com.spielpark.steve.bernieapp.misc.Util;
21 |
22 |
23 | /**
24 | * A simple {@link Fragment} subclass.
25 | */
26 | public class BernRateFragment extends Fragment {
27 | private static BernRateFragment mInstance;
28 | private static String[] urls = new String[]{
29 | "");
62 | }
63 | return gen;
64 | }
65 |
66 | private void displayWebViews(String[] urls) {
67 | LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
68 | RelativeLayout.LayoutParams.WRAP_CONTENT,
69 | 900
70 | );
71 | LinearLayout parent = (LinearLayout) getView().findViewById(R.id.layoutBernRate);
72 | params.setMargins(8, 8, 8, 8);
73 | params.gravity = Gravity.CENTER_HORIZONTAL;
74 | for (String s : urls) {
75 | WebView wv = new WebView(getActivity());
76 | WebSettings settings = wv.getSettings();
77 | settings.setJavaScriptEnabled(true);
78 | wv.setLayoutParams(params);
79 | wv.setWebChromeClient(new WebChromeClient());
80 | wv.loadDataWithBaseURL("http://www.bernrate.com", s, "text/html", "UTF-8", null);
81 | parent.addView(wv);
82 | }
83 | }
84 |
85 | @Override
86 | public View onCreateView(LayoutInflater inflater, ViewGroup container,
87 | Bundle savedInstanceState) {
88 | // Inflate the layout for this fragment
89 | return inflater.inflate(R.layout.frag_bernrate, container, false);
90 | }
91 |
92 |
93 | }
94 |
--------------------------------------------------------------------------------
/app/src/main/java/com/spielpark/steve/bernieapp/fragments/BottomNavFragment.java:
--------------------------------------------------------------------------------
1 | package com.spielpark.steve.bernieapp.fragments;
2 |
3 | import android.os.Bundle;
4 | import android.support.v4.app.Fragment;
5 | import android.view.LayoutInflater;
6 | import android.view.View;
7 | import android.view.ViewGroup;
8 |
9 | import com.spielpark.steve.bernieapp.R;
10 |
11 |
12 | /**
13 | * A simple {@link Fragment} subclass.
14 | */
15 | public class BottomNavFragment extends Fragment {
16 |
17 | private static BottomNavFragment mInstance;
18 |
19 | public static BottomNavFragment getInstance() {
20 | if (mInstance == null) {
21 | mInstance = new BottomNavFragment();
22 | return mInstance;
23 | } else {
24 | return mInstance;
25 | }
26 | }
27 |
28 | @Override
29 | public View onCreateView(LayoutInflater inflater, ViewGroup container,
30 | Bundle savedInstanceState) {
31 | // Inflate the layout for this fragment
32 | return inflater.inflate(R.layout.frag_bottom_nav, container, false);
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/app/src/main/java/com/spielpark/steve/bernieapp/fragments/ConnectFragment.java:
--------------------------------------------------------------------------------
1 | package com.spielpark.steve.bernieapp.fragments;
2 |
3 |
4 | import android.app.Activity;
5 | import android.content.DialogInterface;
6 | import android.content.Intent;
7 | import android.graphics.Color;
8 | import android.net.Uri;
9 | import android.os.AsyncTask;
10 | import android.os.Bundle;
11 | import android.support.v4.app.Fragment;
12 | import android.text.Html;
13 | import android.text.method.ScrollingMovementMethod;
14 | import android.util.Log;
15 | import android.view.LayoutInflater;
16 | import android.view.View;
17 | import android.view.ViewGroup;
18 | import android.view.animation.Animation;
19 | import android.view.animation.AnimationUtils;
20 | import android.view.inputmethod.InputMethodManager;
21 | import android.widget.AdapterView;
22 | import android.widget.ArrayAdapter;
23 | import android.widget.Button;
24 | import android.widget.EditText;
25 | import android.widget.ListView;
26 | import android.widget.TextView;
27 | import android.widget.Toast;
28 |
29 | import com.google.android.gms.maps.CameraUpdateFactory;
30 | import com.google.android.gms.maps.GoogleMap;
31 | import com.google.android.gms.maps.MapsInitializer;
32 | import com.google.android.gms.maps.OnMapReadyCallback;
33 | import com.google.android.gms.maps.SupportMapFragment;
34 | import com.google.android.gms.maps.model.BitmapDescriptorFactory;
35 | import com.google.android.gms.maps.model.LatLng;
36 | import com.google.android.gms.maps.model.LatLngBounds;
37 | import com.google.android.gms.maps.model.Marker;
38 | import com.google.android.gms.maps.model.MarkerOptions;
39 | import com.spielpark.steve.bernieapp.R;
40 | import com.spielpark.steve.bernieapp.tasks.ConnectTask;
41 | import com.spielpark.steve.bernieapp.wrappers.Event;
42 |
43 | import java.util.ArrayList;
44 | import java.util.HashMap;
45 |
46 | /**
47 | * A simple {@link Fragment} subclass.
48 | */
49 | public class ConnectFragment extends Fragment {
50 | private static ConnectTask mTask;
51 | private static GoogleMap map;
52 | private HashMap mHashMap;
53 | public String mZip = "";
54 | public int mRadius = 50;
55 | public boolean fetchCountry = true;
56 | private static ConnectFragment mInstance;
57 | public static ConnectFragment getInstance() {
58 | if (mInstance == null) {
59 | mInstance = new ConnectFragment();
60 | return mInstance;
61 | } else {
62 | return mInstance;
63 | }
64 | }
65 |
66 | public static void cancelTask() {
67 | if (mTask != null) {
68 | if (mTask.getStatus() == AsyncTask.Status.RUNNING) {
69 | mTask.cancel(true);
70 | }
71 | }
72 | }
73 |
74 | @Override
75 | public void onViewCreated(View view, Bundle savedInstanceState) {
76 | getView().findViewById(R.id.c_btnRadius).setOnClickListener(new View.OnClickListener() {
77 | @Override
78 | public void onClick(View view) {
79 | android.support.v7.app.AlertDialog.Builder bld = new android.support.v7.app.AlertDialog.Builder(getActivity());
80 | bld.setTitle("Pick a Radius");
81 | bld.setSingleChoiceItems(R.array.radius_choices, 1, new DialogInterface.OnClickListener() {
82 | @Override
83 | public void onClick(DialogInterface dialogInterface, int i) {
84 | setRadius(i);
85 | dialogInterface.dismiss();
86 | }
87 | });
88 | bld.create().show();
89 | }
90 | });
91 | getView().findViewById(R.id.c_btnGo).setOnClickListener(new View.OnClickListener() {
92 | @Override
93 | public void onClick(View view) {
94 | fetchCountry = false;
95 | startTask();
96 | InputMethodManager inputMethodManager = (InputMethodManager) getActivity().getSystemService(Activity.INPUT_METHOD_SERVICE);
97 | inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0);
98 | }
99 | });
100 | ((ListView) getView().findViewById(R.id.c_listEvents)).setOnItemClickListener(new AdapterView.OnItemClickListener() {
101 | @Override
102 | public void onItemClick(AdapterView> adapterView, View view, int i, long l) {
103 | listItemClicked(i, false);
104 | }
105 | });
106 | fetchCountry = true;
107 | Toast.makeText(getActivity(), "Only Start Date Listed, Events May End at a Later Date", Toast.LENGTH_LONG).show();
108 | setUpMap();
109 | MapsInitializer.initialize(getActivity().getApplicationContext());
110 | super.onViewCreated(view, savedInstanceState);
111 | }
112 |
113 | private void listItemClicked(int pos, boolean alreadyLoaded) {
114 | final View base = getView();
115 | if (!alreadyLoaded) {
116 | View[] topViews = new View[]{
117 | base.findViewById(R.id.c_edtZip),
118 | base.findViewById(R.id.c_btnRadius),
119 | base.findViewById(R.id.c_btnGo)
120 | };
121 | for (final View v : topViews) {
122 | Animation anim = AnimationUtils.loadAnimation(getActivity(), R.anim.abc_slide_out_top);
123 | anim.setAnimationListener(new Animation.AnimationListener() {
124 | @Override
125 | public void onAnimationStart(Animation animation) {
126 |
127 | }
128 |
129 | @Override
130 | public void onAnimationEnd(Animation animation) {
131 | v.setVisibility(View.GONE);
132 | }
133 |
134 | @Override
135 | public void onAnimationRepeat(Animation animation) {
136 |
137 | }
138 | });
139 | v.startAnimation(anim);
140 | }
141 | final View list = base.findViewById(R.id.c_listEvents);
142 | Animation anim = AnimationUtils.loadAnimation(getActivity(), R.anim.abc_slide_out_bottom);
143 | anim.setAnimationListener(new Animation.AnimationListener() {
144 | @Override
145 | public void onAnimationStart(Animation animation) {
146 |
147 | }
148 |
149 | @Override
150 | public void onAnimationEnd(Animation animation) {
151 | list.setVisibility(View.GONE);
152 | }
153 |
154 | @Override
155 | public void onAnimationRepeat(Animation animation) {
156 |
157 | }
158 | });
159 | list.startAnimation(anim);
160 | View mapContainer = base.findViewById(R.id.c_mapContainer);
161 | mapContainer.startAnimation(new AnimationUtils().loadAnimation(getActivity(), R.anim.view_slide_up));
162 | }
163 | final Event e = ConnectTask.getEvents().get(pos);
164 | base.findViewById(R.id.cd_btnRSVP).setOnClickListener(new View.OnClickListener() {
165 | @Override
166 | public void onClick(View view) {
167 | Intent i = new Intent(Intent.ACTION_VIEW);
168 | i.setData(Uri.parse(e.getUrl()));
169 | startActivity(i);
170 | }
171 | });
172 | base.findViewById(R.id.cd_btnDirections).setOnClickListener(new View.OnClickListener() {
173 | @Override
174 | public void onClick(View view) {
175 | Uri gmmIntentUri = Uri.parse("geo:" + Double.toString(e.getLatitude()) + "," + Double.toString(e.getLongitude()));
176 | Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
177 | mapIntent.setPackage("com.google.android.apps.maps");
178 | startActivity(mapIntent);
179 | }
180 | });
181 | if (e.getDate() != null) ((TextView) base.findViewById(R.id.cd_txtDate)).setText(e.getDate());
182 | ((TextView) base.findViewById(R.id.cd_txtTitle)).setText(e.getName());
183 | ((TextView) base.findViewById(R.id.cd_txtDescContent)).setText(Html.fromHtml(e.getDescription()));
184 | ((TextView) base.findViewById(R.id.cd_txtDescContent)).setMovementMethod(new ScrollingMovementMethod());
185 | if (e.getVenue_city() != null) ((TextView) base.findViewById(R.id.cd_txtLocation)).setText(e.getVenue_addr() + "\n" + e.getVenue_city() + ", " + e.getState() + " - " + e.getZip());
186 | ((TextView) base.findViewById(R.id.cd_txtRSVP)).setText(e.isOfficial() ? "N/A" : Integer.toString(e.getAttendee_count()));
187 | Animation fadeIn = AnimationUtils.loadAnimation(getActivity(), alreadyLoaded ? R.anim.view_fade_in_fast : R.anim.view_fade_in);
188 | fadeIn.setAnimationListener(new Animation.AnimationListener() {
189 | @Override
190 | public void onAnimationStart(Animation animation) {
191 | base.findViewById(R.id.cd_container).setVisibility(View.VISIBLE);
192 | }
193 |
194 | @Override
195 | public void onAnimationEnd(Animation animation) {
196 | }
197 |
198 | @Override
199 | public void onAnimationRepeat(Animation animation) {
200 |
201 | }
202 | });
203 | base.findViewById(R.id.cd_container).startAnimation(fadeIn);
204 | }
205 |
206 | private void startTask() {
207 | cancelTask();
208 | if (fetchCountry) {
209 | mTask = new ConnectTask(getActivity(), getInstance());
210 | mTask.execute();
211 | } else if (validZip()) {
212 | getView().findViewById(R.id.c_btnGo).setEnabled(false);
213 | getView().findViewById(R.id.c_btnGo).setBackgroundColor(Color.parseColor("#CCCCCC"));
214 | getView().findViewById(R.id.c_progress).setVisibility(View.VISIBLE);
215 | mTask = new ConnectTask(getActivity(), getInstance());
216 | mTask.execute();
217 | } else {
218 | Toast.makeText(getActivity(), "Please enter a valid Zip Code!", Toast.LENGTH_SHORT).show();
219 | }
220 | }
221 |
222 | private boolean validZip() {
223 | String text = ((EditText) getView().findViewById(R.id.c_edtZip)).getText().toString();
224 | try {
225 | Integer.parseInt(text);
226 | } catch (NumberFormatException e) {
227 | return false;
228 | }
229 | mZip = text;
230 | return text.length() == 5;
231 | }
232 |
233 | private void setRadius(int m) {
234 | mRadius = m++ < 4 ? m*25 : ((m-2)*50);
235 | ((Button) getView().findViewById(R.id.c_btnRadius)).setText(mRadius + " miles");
236 | }
237 |
238 | @Override
239 | public View onCreateView(LayoutInflater inflater, ViewGroup container,
240 | Bundle savedInstanceState) {
241 | return inflater.inflate(R.layout.frag_connect, container, false);
242 | }
243 |
244 | private void setUpMap() {
245 | SupportMapFragment mapFragment = (SupportMapFragment) this.getChildFragmentManager().findFragmentById(R.id.c_map);
246 | mapFragment.getMapAsync(new OnMapReadyCallback() {
247 | @Override
248 | public void onMapReady(GoogleMap googleMap) {
249 | Log.d("Map Ready", "Bam.");
250 | ConnectFragment.this.map = googleMap;
251 | ConnectFragment.this.getView().findViewById(R.id.c_btnGo).setEnabled(true);
252 | ConnectFragment.this.getView().findViewById(R.id.c_progress).setVisibility(View.GONE);
253 | ConnectFragment.this.getView().findViewById(R.id.c_btnGo).setBackgroundColor(Color.parseColor("#147FD7"));
254 | }
255 | });
256 | startTask();
257 | }
258 |
259 | public void setMarkers() {
260 | map.clear();
261 | ArrayList events = ConnectTask.getEvents();
262 | if (events.size() == 0) {
263 | return; //There are no events to draw.
264 | }
265 | mHashMap = new HashMap<>(events.size());
266 | LatLngBounds.Builder bld = new LatLngBounds.Builder();
267 | LatLng pos;
268 | float hue;
269 | int id = 0;
270 | for (Event e : ConnectTask.getEvents()) {
271 | hue = e.isOfficial() ? 1.0f : 214f;
272 | pos = new LatLng(e.getLatitude(), e.getLongitude());
273 | mHashMap.put(map.addMarker(new MarkerOptions()
274 | .position(pos)
275 | .title(e.getName())
276 | .icon(BitmapDescriptorFactory.defaultMarker(hue))), id++);
277 | bld.include(pos);
278 | }
279 | LatLngBounds bounds = bld.build();
280 | map.animateCamera(CameraUpdateFactory.newLatLngBounds(bounds, 0));
281 | map.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {
282 | @Override
283 | public boolean onMarkerClick(final Marker marker) {
284 | final int id = Integer.parseInt(marker.getId().substring(1));
285 | if (getView().findViewById(R.id.cd_container).getVisibility() == View.VISIBLE) {
286 | listItemClicked(mHashMap.get(marker), true);
287 | return false;
288 | }
289 | final ListView list = (ListView) getView().findViewById(R.id.c_listEvents);
290 | list.post(new Runnable() {
291 | @Override
292 | public void run() {
293 | list.smoothScrollToPositionFromTop(mHashMap.get(marker), 0, 500);
294 | list.postDelayed(new Runnable() {
295 | @Override
296 | public void run() {
297 | list.setSelection(mHashMap.get(marker));
298 | }
299 | }, 510);
300 | }
301 | });
302 | return false;
303 | }
304 | });
305 | }
306 |
307 | public void updateViews(ArrayAdapter a) {
308 | View parent = getView();
309 | if (parent == null) {
310 | return; //We switched out of this view.
311 | }
312 | ListView list = (ListView) parent.findViewById(R.id.c_listEvents);
313 | list.setAdapter(a);
314 | list.setVisibility(View.VISIBLE);
315 | parent.findViewById(R.id.c_mapContainer).setVisibility(View.VISIBLE);
316 | parent.findViewById(R.id.c_progress).setVisibility(View.GONE);
317 | parent.findViewById(R.id.c_btnGo).setEnabled(true);
318 | parent.findViewById(R.id.c_btnGo).setBackgroundColor(Color.parseColor("#147FD7"));
319 | }
320 |
321 | public void backPressed() {
322 | View parent = getView();
323 | if (parent.findViewById(R.id.c_btnGo).getVisibility() == View.VISIBLE) {
324 | getActivity().finish();
325 | cancelTask();
326 | } else {
327 | parent.findViewById(R.id.c_edtZip).setVisibility(View.VISIBLE);
328 | parent.findViewById(R.id.c_btnRadius).setVisibility(View.VISIBLE);
329 | parent.findViewById(R.id.c_listEvents).setVisibility(View.VISIBLE);
330 | parent.findViewById(R.id.c_btnGo).setVisibility(View.VISIBLE);
331 | parent.findViewById(R.id.cd_container).setVisibility(View.GONE);
332 | }
333 | }
334 | }
335 |
--------------------------------------------------------------------------------
/app/src/main/java/com/spielpark/steve/bernieapp/fragments/DonateFragment.java:
--------------------------------------------------------------------------------
1 | package com.spielpark.steve.bernieapp.fragments;
2 |
3 | import android.content.Intent;
4 | import android.net.Uri;
5 | import android.os.Bundle;
6 | import android.support.v4.app.Fragment;
7 | import android.view.LayoutInflater;
8 | import android.view.View;
9 | import android.view.ViewGroup;
10 | import android.widget.ImageView;
11 |
12 | import com.spielpark.steve.bernieapp.R;
13 | import com.squareup.picasso.Picasso;
14 |
15 | /**
16 | * Created by Steve on 2/28/2016.
17 | */
18 | public class DonateFragment extends Fragment{
19 | private static DonateFragment mInstance;
20 |
21 | public static DonateFragment getInstance() {
22 | if (mInstance == null) {
23 | mInstance = new DonateFragment();
24 | }
25 | return mInstance;
26 | }
27 |
28 | @Override
29 | public void onViewCreated(View view, Bundle savedInstanceState) {
30 | super.onViewCreated(view, savedInstanceState);
31 | ImageView thermometer = ((ImageView) view.findViewById(R.id.d_imgThermometer));
32 | Picasso.with(getContext()).invalidate("https://secure.actblue.com/x/object/actblue-badges/page/reddit-for-bernie/thermometer/dark.png");
33 | Picasso.with(getContext()).load("https://secure.actblue.com/x/object/actblue-badges/page/reddit-for-bernie/thermometer/dark.png").into(thermometer);
34 | view.findViewById(R.id.d_btnDonate).setOnClickListener(new View.OnClickListener() {
35 | @Override
36 | public void onClick(View v) {
37 | Intent i = new Intent(Intent.ACTION_VIEW);
38 | i.setData(Uri.parse(getResources().getString(R.string.donate_url)));
39 | startActivity(i);
40 | }
41 | });
42 | }
43 |
44 | @Override
45 | public View onCreateView(LayoutInflater inflater, ViewGroup container,
46 | Bundle savedInstanceState) {
47 | // Inflate the layout for this fragment
48 | return inflater.inflate(R.layout.frag_donate, container, false);
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/app/src/main/java/com/spielpark/steve/bernieapp/fragments/FeedbackFragment.java:
--------------------------------------------------------------------------------
1 | package com.spielpark.steve.bernieapp.fragments;
2 |
3 |
4 | import android.os.Bundle;
5 | import android.support.v4.app.Fragment;
6 | import android.view.LayoutInflater;
7 | import android.view.View;
8 | import android.view.ViewGroup;
9 | import android.webkit.WebView;
10 |
11 | import com.spielpark.steve.bernieapp.BuildConfig;
12 | import com.spielpark.steve.bernieapp.R;
13 | import com.spielpark.steve.bernieapp.misc.Util;
14 |
15 | /**
16 | * A simple {@link Fragment} subclass.
17 | */
18 | public class FeedbackFragment extends Fragment {
19 | private static FeedbackFragment mInstance;
20 | @Override
21 | public void onViewCreated(View view, Bundle savedInstanceState) {
22 | super.onViewCreated(view, savedInstanceState);
23 | WebView wv = (WebView) view.findViewById(R.id.feedback_webview);
24 | StringBuilder bld = new StringBuilder();
25 | int[] wh = Util.getScreenWidthHeight(getActivity());
26 | int versionNo = BuildConfig.VERSION_CODE;
27 | bld.append("");
32 | wv.loadData(bld.toString(), "text/Html", "UTF-8");
33 | }
34 |
35 | public static FeedbackFragment getInstance() {
36 | if (mInstance == null) {
37 | mInstance = new FeedbackFragment();
38 | }
39 | return mInstance;
40 | }
41 |
42 | @Override
43 | public View onCreateView(LayoutInflater inflater, ViewGroup container,
44 | Bundle savedInstanceState) {
45 | return inflater.inflate(R.layout.frag_feedback, container, false);
46 | }
47 |
48 |
49 | }
50 |
--------------------------------------------------------------------------------
/app/src/main/java/com/spielpark/steve/bernieapp/fragments/IssuesFragment.java:
--------------------------------------------------------------------------------
1 | package com.spielpark.steve.bernieapp.fragments;
2 |
3 | import android.os.Bundle;
4 | import android.support.annotation.Nullable;
5 | import android.support.v4.app.Fragment;
6 | import android.view.LayoutInflater;
7 | import android.view.View;
8 | import android.view.ViewGroup;
9 | import android.widget.AdapterView;
10 | import android.widget.ListView;
11 | import android.widget.ProgressBar;
12 |
13 | import com.spielpark.steve.bernieapp.R;
14 | import com.spielpark.steve.bernieapp.actMainPage;
15 | import com.spielpark.steve.bernieapp.tasks.IssuesTask;
16 |
17 |
18 | /**
19 | * A simple {@link Fragment} subclass.
20 | */
21 | public class IssuesFragment extends Fragment {
22 |
23 | private static IssuesFragment mIntstance;
24 |
25 | public static IssuesFragment getInstance() {
26 | if (mIntstance == null) {
27 | mIntstance = new IssuesFragment();
28 | return mIntstance;
29 | } else {
30 | return mIntstance;
31 | }
32 | }
33 |
34 | @Override
35 | public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
36 | super.onViewCreated(view, savedInstanceState);
37 | final ListView newsList = (ListView) view.findViewById(R.id.listIssues);
38 | new IssuesTask(getActivity(), newsList, (ProgressBar) view.findViewById(R.id.progressBar)).execute();
39 | newsList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
40 | @Override
41 | public void onItemClick(AdapterView> parent, View view, int position, long id) {
42 | ((actMainPage)getActivity()).loadIssue(IssuesTask.getIssue(position));
43 | }
44 | });
45 | }
46 |
47 | @Override
48 | public void onCreate(Bundle savedInstanceState) {
49 | super.onCreate(savedInstanceState);
50 | }
51 |
52 | @Override
53 | public View onCreateView(LayoutInflater inflater, ViewGroup container,
54 | Bundle savedInstanceState) {
55 | // Inflate the layout for this fragment
56 | return inflater.inflate(R.layout.frag_issues, container, false);
57 | }
58 |
59 | }
60 |
--------------------------------------------------------------------------------
/app/src/main/java/com/spielpark/steve/bernieapp/fragments/NavigationDrawerFragment.java:
--------------------------------------------------------------------------------
1 | package com.spielpark.steve.bernieapp.fragments;
2 |
3 | import android.app.Activity;
4 | import android.content.Context;
5 | import android.content.SharedPreferences;
6 | import android.content.res.Configuration;
7 | import android.os.Bundle;
8 | import android.preference.PreferenceManager;
9 | import android.support.v4.app.ActionBarDrawerToggle;
10 | import android.support.v4.app.Fragment;
11 | import android.support.v4.view.GravityCompat;
12 | import android.support.v4.widget.DrawerLayout;
13 | import android.support.v7.app.ActionBar;
14 | import android.support.v7.app.ActionBarActivity;
15 | import android.view.LayoutInflater;
16 | import android.view.MenuItem;
17 | import android.view.View;
18 | import android.view.ViewGroup;
19 | import android.widget.AdapterView;
20 | import android.widget.ArrayAdapter;
21 | import android.widget.ImageView;
22 | import android.widget.ListView;
23 | import android.widget.TextView;
24 |
25 | import com.spielpark.steve.bernieapp.R;
26 | import com.spielpark.steve.bernieapp.wrappers.NavDrawerItem;
27 |
28 | /**
29 | * Fragment used for managing interactions for and presentation of a navigation drawer.
30 | * See the
31 | * design guidelines for a complete explanation of the behaviors implemented here.
32 | */
33 | public class NavigationDrawerFragment extends Fragment {
34 | /**
35 | * Remember the position of the selected item.
36 | */
37 | private static final String STATE_SELECTED_POSITION = "selected_navigation_drawer_position";
38 |
39 | /**
40 | * Per the design guidelines, you should show the drawer on launch until the user manually
41 | * expands it. This shared preference tracks this.
42 | */
43 | private static final String PREF_USER_LEARNED_DRAWER = "navigation_drawer_learned";
44 |
45 | /**
46 | * A pointer to the current callbacks instance (the Activity).
47 | */
48 | private NavigationDrawerCallbacks mCallbacks;
49 |
50 | /**
51 | * Helper component that ties the action bar to the navigation drawer.
52 | */
53 | private ActionBarDrawerToggle mDrawerToggle;
54 |
55 | private DrawerLayout mDrawerLayout;
56 | private static ListView mDrawerListView;
57 | private View mFragmentContainerView;
58 |
59 | private static int mCurrentSelectedPosition = 0;
60 | private boolean mFromSavedInstanceState;
61 | private boolean mUserLearnedDrawer;
62 |
63 | public static void setSelected(int i) {
64 | mCurrentSelectedPosition = i;
65 | mDrawerListView.setSelection(i);
66 | mDrawerListView.setItemChecked(i, true);
67 | }
68 |
69 | public NavigationDrawerFragment() {
70 | }
71 |
72 | @Override
73 | public void onCreate(Bundle savedInstanceState) {
74 | super.onCreate(savedInstanceState);
75 |
76 | // Read in the flag indicating whether or not the user has demonstrated awareness of the
77 | // drawer. See PREF_USER_LEARNED_DRAWER for details.
78 | SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getActivity());
79 | mUserLearnedDrawer = sp.getBoolean(PREF_USER_LEARNED_DRAWER, false);
80 |
81 | if (savedInstanceState != null) {
82 | mCurrentSelectedPosition = savedInstanceState.getInt(STATE_SELECTED_POSITION);
83 | mFromSavedInstanceState = true;
84 | }
85 |
86 | // Select either the default item (0) or the last selected item.
87 | selectItem(mCurrentSelectedPosition);
88 | }
89 |
90 | @Override
91 | public void onActivityCreated(Bundle savedInstanceState) {
92 | super.onActivityCreated(savedInstanceState);
93 | // Indicate that this fragment would like to influence the set of actions in the action bar.
94 | setHasOptionsMenu(true);
95 | }
96 |
97 | @Override
98 | public View onCreateView(LayoutInflater inflater, ViewGroup container,
99 | Bundle savedInstanceState) {
100 | mDrawerListView = (ListView) inflater.inflate(
101 | R.layout.frag_nav, container, false);
102 | mDrawerListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
103 | @Override
104 | public void onItemClick(AdapterView> parent, View view, int position, long id) {
105 | selectItem(position);
106 | }
107 | });
108 | NavDrawerItem[] datas = new NavDrawerItem[] {
109 | new NavDrawerItem(R.drawable.ic_public_white_24dp, getString(R.string.title_section1)),
110 | new NavDrawerItem(R.drawable.ic_event_note_white_24dp, getString(R.string.title_section2)),
111 | new NavDrawerItem(R.drawable.ic_people_white_24dp, getString(R.string.title_section3)),
112 | new NavDrawerItem(R.drawable.ic_map_white_24dp, getString(R.string.title_section4)),
113 | new NavDrawerItem(R.drawable.ic_insert_chart_white_24dp, getString(R.string.title_section5)),
114 | new NavDrawerItem(R.drawable.ic_attach_money_white_24dp, getString(R.string.title_section6)),
115 | new NavDrawerItem(R.drawable.ic_feedback_white_24dp, getString(R.string.title_section7)),
116 | };
117 | mDrawerListView.setAdapter(new NavDrawerAdapter(getActivity(), R.layout.list_drawer_item, datas));
118 | mDrawerListView.setItemChecked(mCurrentSelectedPosition, true);
119 | return mDrawerListView;
120 | }
121 |
122 | public boolean isDrawerOpen() {
123 | return mDrawerLayout != null && mDrawerLayout.isDrawerOpen(mFragmentContainerView);
124 | }
125 |
126 | /**
127 | * Users of this fragment must call this method to set up the navigation drawer interactions.
128 | *
129 | * @param fragmentId The android:id of this fragment in its activity's layout.
130 | * @param drawerLayout The DrawerLayout containing this fragment's UI.
131 | */
132 | public void setUp(int fragmentId, DrawerLayout drawerLayout) {
133 | mFragmentContainerView = getActivity().findViewById(fragmentId);
134 | mDrawerLayout = drawerLayout;
135 |
136 | // set a custom shadow that overlays the main content when the drawer opens
137 | mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
138 | // set up the drawer's list view with items and click listener
139 |
140 | ActionBar actionBar = getActionBar();
141 | actionBar.setDisplayHomeAsUpEnabled(true);
142 | actionBar.setHomeButtonEnabled(true);
143 |
144 | // ActionBarDrawerToggle ties together the the proper interactions
145 | // between the navigation drawer and the action bar app icon.
146 | mDrawerToggle = new ActionBarDrawerToggle(
147 | getActivity(), /* host Activity */
148 | mDrawerLayout, /* DrawerLayout object */
149 | R.drawable.ic_drawer, /* nav drawer image to replace 'Up' caret */
150 | R.string.navigation_drawer_open, /* "open drawer" description for accessibility */
151 | R.string.navigation_drawer_close /* "close drawer" description for accessibility */
152 | ) {
153 | @Override
154 | public void onDrawerClosed(View drawerView) {
155 | super.onDrawerClosed(drawerView);
156 | if (!isAdded()) {
157 | return;
158 | }
159 |
160 | getActivity().supportInvalidateOptionsMenu(); // calls onPrepareOptionsMenu()
161 | }
162 |
163 | @Override
164 | public void onDrawerOpened(View drawerView) {
165 | super.onDrawerOpened(drawerView);
166 | if (!isAdded()) {
167 | return;
168 | }
169 |
170 | if (!mUserLearnedDrawer) {
171 | // The user manually opened the drawer; store this flag to prevent auto-showing
172 | // the navigation drawer automatically in the future.
173 | mUserLearnedDrawer = true;
174 | SharedPreferences sp = PreferenceManager
175 | .getDefaultSharedPreferences(getActivity());
176 | sp.edit().putBoolean(PREF_USER_LEARNED_DRAWER, true).apply();
177 | }
178 | getActivity().supportInvalidateOptionsMenu(); // calls onPrepareOptionsMenu()
179 | }
180 | };
181 |
182 | // If the user hasn't 'learned' about the drawer, open it to introduce them to the drawer,
183 | // per the navigation drawer design guidelines.
184 | if (!mUserLearnedDrawer && !mFromSavedInstanceState) {
185 | mDrawerLayout.openDrawer(mFragmentContainerView);
186 | }
187 |
188 | // Defer code dependent on restoration of previous instance state.
189 | mDrawerLayout.post(new Runnable() {
190 | @Override
191 | public void run() {
192 | mDrawerToggle.syncState();
193 | }
194 | });
195 |
196 | mDrawerLayout.setDrawerListener(mDrawerToggle);
197 | }
198 |
199 | private void selectItem(int position) {
200 | mCurrentSelectedPosition = position;
201 | if (mDrawerListView != null) {
202 | mDrawerListView.setItemChecked(position, true);
203 | }
204 | if (mDrawerLayout != null) {
205 | mDrawerLayout.closeDrawer(mFragmentContainerView);
206 | }
207 | if (mCallbacks != null) {
208 | mCallbacks.onNavigationDrawerItemSelected(position);
209 | }
210 | }
211 |
212 | @Override
213 | public void onAttach(Activity activity) {
214 | super.onAttach(activity);
215 | try {
216 | mCallbacks = (NavigationDrawerCallbacks) activity;
217 | } catch (ClassCastException e) {
218 | throw new ClassCastException("Activity must implement NavigationDrawerCallbacks.");
219 | }
220 | }
221 |
222 | @Override
223 | public void onDetach() {
224 | super.onDetach();
225 | mCallbacks = null;
226 | }
227 |
228 | @Override
229 | public void onSaveInstanceState(Bundle outState) {
230 | super.onSaveInstanceState(outState);
231 | outState.putInt(STATE_SELECTED_POSITION, mCurrentSelectedPosition);
232 | }
233 |
234 | @Override
235 | public void onConfigurationChanged(Configuration newConfig) {
236 | super.onConfigurationChanged(newConfig);
237 | // Forward the new configuration the drawer toggle component.
238 | mDrawerToggle.onConfigurationChanged(newConfig);
239 | }
240 |
241 | @Override
242 | public boolean onOptionsItemSelected(MenuItem item) {
243 | if (mDrawerToggle.onOptionsItemSelected(item)) {
244 | return true;
245 | }
246 | return super.onOptionsItemSelected(item);
247 | }
248 |
249 | private ActionBar getActionBar() {
250 | return ((ActionBarActivity) getActivity()).getSupportActionBar();
251 | }
252 |
253 | /**
254 | * Callbacks interface that all activities using this fragment must implement.
255 | */
256 | public interface NavigationDrawerCallbacks {
257 | /**
258 | * Called when an item in the navigation drawer is selected.
259 | */
260 | void onNavigationDrawerItemSelected(int position);
261 | }
262 |
263 | private static class NavDrawerAdapter extends ArrayAdapter {
264 | private final Context context;
265 | private final int layoutResourceId;
266 | private NavDrawerItem data[] = null;
267 |
268 | public NavDrawerAdapter(Context context, int layoutResourceId, NavDrawerItem [] data)
269 | {
270 | super(context, layoutResourceId, data);
271 | this.context = context;
272 | this.layoutResourceId = layoutResourceId;
273 | this.data = data;
274 | }
275 |
276 | @Override
277 | public View getView(int position, View convertView, ViewGroup parent) {
278 | LayoutInflater inflater = ((Activity) context).getLayoutInflater();
279 |
280 | View v = inflater.inflate(layoutResourceId, parent, false);
281 |
282 | ImageView imageView = (ImageView) v.findViewById(R.id.navDrawerImageView);
283 | TextView textView = (TextView) v.findViewById(R.id.navDrawerTextView);
284 |
285 | NavDrawerItem choice = data[position];
286 |
287 | imageView.setImageResource(choice.icon);
288 | textView.setText(choice.name);
289 |
290 | return v;
291 | }
292 | }
293 | }
294 |
295 |
--------------------------------------------------------------------------------
/app/src/main/java/com/spielpark/steve/bernieapp/fragments/NewsFragment.java:
--------------------------------------------------------------------------------
1 | package com.spielpark.steve.bernieapp.fragments;
2 |
3 | /**
4 | * Created by Steve on 7/9/2015.
5 | */
6 |
7 | import android.os.Bundle;
8 | import android.support.annotation.Nullable;
9 | import android.support.v4.app.Fragment;
10 | import android.text.method.ScrollingMovementMethod;
11 | import android.view.LayoutInflater;
12 | import android.view.View;
13 | import android.view.ViewGroup;
14 | import android.widget.ListView;
15 | import android.widget.ProgressBar;
16 | import android.widget.TextView;
17 |
18 | import com.spielpark.steve.bernieapp.R;
19 | import com.spielpark.steve.bernieapp.tasks.NewsTask;
20 |
21 | /**
22 | * A placeholder fragment containing a simple view.
23 | */
24 | public class NewsFragment extends Fragment {
25 |
26 | private static NewsFragment mIntstance;
27 |
28 | public static NewsFragment getInstance() {
29 | if (mIntstance == null) {
30 | mIntstance = new NewsFragment();
31 | return mIntstance;
32 | } else {
33 | return mIntstance;
34 | }
35 | }
36 | @Override
37 | public void onViewCreated(final View view, @Nullable Bundle savedInstanceState) {
38 | super.onViewCreated(view, savedInstanceState);
39 | final ListView newsList = (ListView) view.findViewById(R.id.listNews);
40 | ((TextView) view.findViewById(R.id.txtSubHeader)).setMovementMethod(new ScrollingMovementMethod());
41 | new NewsTask(getActivity(), newsList, (ProgressBar) view.findViewById(R.id.progressBar), (TextView) view.findViewById(R.id.txtSubHeader), (TextView) view.findViewById(R.id.txtHeader)).execute();
42 | }
43 |
44 | @Override
45 | public View onCreateView(LayoutInflater inflater, ViewGroup container,
46 | Bundle savedInstanceState) {
47 | View rootView = inflater.inflate(R.layout.frag_newsarticles, container, false);
48 | return rootView;
49 | }
50 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/spielpark/steve/bernieapp/fragments/OrganizeFragment.java:
--------------------------------------------------------------------------------
1 | package com.spielpark.steve.bernieapp.fragments;
2 |
3 |
4 | import android.os.Bundle;
5 | import android.support.v4.app.Fragment;
6 | import android.view.LayoutInflater;
7 | import android.view.View;
8 | import android.view.ViewGroup;
9 | import android.webkit.HttpAuthHandler;
10 | import android.webkit.WebView;
11 | import android.webkit.WebViewClient;
12 | import android.widget.Toast;
13 |
14 | import com.spielpark.steve.bernieapp.R;
15 |
16 | /**
17 | * A simple {@link Fragment} subclass.
18 | */
19 | public class OrganizeFragment extends Fragment {
20 |
21 | private static OrganizeFragment mInstance;
22 | private static WebView browser;
23 | public static OrganizeFragment getInstance() {
24 | if (mInstance == null) {
25 | mInstance = new OrganizeFragment();
26 | return mInstance;
27 | } else {
28 | return mInstance;
29 | }
30 | }
31 |
32 | @Override
33 | public void onViewCreated(View view, Bundle savedInstanceState) {
34 | super.onViewCreated(view, savedInstanceState);
35 | browser = (WebView) getView().findViewById(R.id.o_webView);
36 | browser.getSettings().setJavaScriptEnabled(true);
37 | browser.getSettings().setAppCachePath(getActivity().getCacheDir().getPath());
38 | browser.getSettings().setAppCacheEnabled(true);
39 | browser.setWebViewClient(new WebViewClient() {
40 | @Override
41 | public void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm) {
42 | super.onReceivedHttpAuthRequest(view, handler, host, realm);
43 | Toast.makeText(getActivity(), "Logging in..", Toast.LENGTH_SHORT);
44 | }
45 |
46 | @Override
47 | public void onReceivedLoginRequest(WebView view, String realm, String account, String args) {
48 | super.onReceivedLoginRequest(view, realm, account, args);
49 | Toast.makeText(getActivity(), "Logging in -HTTP..", Toast.LENGTH_SHORT);
50 | }
51 | });
52 | browser.loadUrl("https://berniecrowd.org/?utm_source=bernie-app&utm_medium=android&utm_campaign=bernie-app");
53 | }
54 |
55 | @Override
56 | public View onCreateView(LayoutInflater inflater, ViewGroup container,
57 | Bundle savedInstanceState) {
58 | return inflater.inflate(R.layout.frag_organize, container, false);
59 | }
60 |
61 | public static boolean canGoBack() {
62 | if (browser.canGoBack()) {
63 | browser.goBack();
64 | return true;
65 | } else {
66 | return false;
67 | }
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/app/src/main/java/com/spielpark/steve/bernieapp/fragments/SingleIssueFragment.java:
--------------------------------------------------------------------------------
1 | package com.spielpark.steve.bernieapp.fragments;
2 |
3 | import android.content.Intent;
4 | import android.graphics.Color;
5 | import android.os.Bundle;
6 | import android.support.v4.app.Fragment;
7 | import android.support.v4.app.FragmentManager;
8 | import android.support.v4.view.MenuItemCompat;
9 | import android.support.v7.widget.ShareActionProvider;
10 | import android.text.Html;
11 | import android.text.method.LinkMovementMethod;
12 | import android.view.LayoutInflater;
13 | import android.view.Menu;
14 | import android.view.MenuInflater;
15 | import android.view.MenuItem;
16 | import android.view.View;
17 | import android.view.ViewGroup;
18 | import android.webkit.WebChromeClient;
19 | import android.webkit.WebView;
20 | import android.widget.TextView;
21 |
22 | import com.spielpark.steve.bernieapp.R;
23 | import com.spielpark.steve.bernieapp.wrappers.Issue;
24 |
25 | /**
26 | * A simple {@link Fragment} subclass.
27 | */
28 | public class SingleIssueFragment extends Fragment {
29 | private ShareActionProvider shareActionProvider;
30 | private static Issue mIssue;
31 |
32 | public static SingleIssueFragment newInstance(Issue i) {
33 | mIssue = i;
34 | return new SingleIssueFragment();
35 | }
36 |
37 | @Override
38 | public void onPause() {
39 | super.onPause();
40 | ((WebView) getView().findViewById(R.id.i_video)).onPause();
41 | }
42 |
43 | @Override
44 | public void onCreate(Bundle savedInstanceState) {
45 | super.onCreate(savedInstanceState);
46 | }
47 |
48 | @Override
49 | public void onViewCreated(View view, Bundle savedInstanceState) {
50 | super.onViewCreated(view, savedInstanceState);
51 | if (mIssue == null) {
52 | //User exited the app and returned to it, but android cleared some stuff from memory...
53 | getActivity().getSupportFragmentManager().popBackStack("base", FragmentManager.POP_BACK_STACK_INCLUSIVE);
54 | }
55 | final View root = getView();
56 | ((TextView) root.findViewById(R.id.i_txtTitle)).setText(mIssue.getTitle());
57 | ((TextView) root.findViewById(R.id.i_txtTitle)).setShadowLayer(13, 0, 0, Color.BLACK);
58 | ((TextView) root.findViewById(R.id.i_txtDate)).setText("Published " + mIssue.getPubDate());
59 | ((TextView) root.findViewById(R.id.i_txtDesc)).setText(Html.fromHtml(mIssue.getDesc()));
60 | ((TextView) root.findViewById(R.id.i_txtDesc)).setMovementMethod(new LinkMovementMethod());
61 | WebView wv = ((WebView) root.findViewById(R.id.i_video));
62 | wv.setWebChromeClient(new WebChromeClient());
63 | wv.getSettings().setJavaScriptEnabled(true);
64 | wv.loadDataWithBaseURL(null, mIssue.getEmbedURL(getActivity()), "text/Html", "UTF-8", null);
65 | }
66 |
67 | @Override
68 | public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
69 | inflater.inflate(R.menu.share_menu, menu);
70 | MenuItem item = menu.findItem(R.id.menu_item_share);
71 | shareActionProvider = (ShareActionProvider) MenuItemCompat.getActionProvider(item);
72 | shareActionProvider.setShareIntent(getShareIntent());
73 | shareActionProvider.setOnShareTargetSelectedListener(new ShareActionProvider.OnShareTargetSelectedListener() {
74 | @Override
75 | public boolean onShareTargetSelected(ShareActionProvider source, Intent intent) {
76 | getActivity().onBackPressed();
77 | return false;
78 | }
79 | });
80 | super.onCreateOptionsMenu(menu, inflater);
81 | }
82 |
83 | private Intent getShareIntent() {
84 | Intent shareIntent = new Intent(Intent.ACTION_SEND);
85 | shareIntent.setType("text/plain");
86 | StringBuilder text = new StringBuilder("Hey, here's Bernie Sanders' official stance on this issue -- \n");
87 | text.append(mIssue.getTitle());
88 | text.append("\n\nRead more here: " + mIssue.getUrl());
89 | text.append("\n\nSent from Bernie Sanders for President 2016 Android Application");
90 | shareIntent.putExtra(Intent.EXTRA_TEXT, text.toString());
91 | return shareIntent;
92 | }
93 |
94 | @Override
95 | public View onCreateView(LayoutInflater inflater, ViewGroup container,
96 | Bundle savedInstanceState) {
97 | setHasOptionsMenu(true);
98 | return inflater.inflate(R.layout.frag_single_issue, container, false);
99 | }
100 |
101 |
102 | }
103 |
--------------------------------------------------------------------------------
/app/src/main/java/com/spielpark/steve/bernieapp/fragments/SingleNewsFragment.java:
--------------------------------------------------------------------------------
1 | package com.spielpark.steve.bernieapp.fragments;
2 |
3 | import android.content.Intent;
4 | import android.graphics.Color;
5 | import android.net.Uri;
6 | import android.os.Bundle;
7 | import android.support.v4.app.Fragment;
8 | import android.support.v4.view.MenuItemCompat;
9 | import android.support.v7.widget.ShareActionProvider;
10 | import android.text.Html;
11 | import android.text.method.LinkMovementMethod;
12 | import android.util.Log;
13 | import android.view.LayoutInflater;
14 | import android.view.Menu;
15 | import android.view.MenuInflater;
16 | import android.view.MenuItem;
17 | import android.view.View;
18 | import android.view.ViewGroup;
19 | import android.widget.ImageView;
20 | import android.widget.TextView;
21 |
22 | import com.spielpark.steve.bernieapp.R;
23 | import com.spielpark.steve.bernieapp.misc.Util;
24 | import com.spielpark.steve.bernieapp.wrappers.NewsArticle;
25 |
26 | public class SingleNewsFragment extends Fragment {
27 | private static NewsArticle mEvent;
28 | private static SingleNewsFragment mInstance;
29 | private ShareActionProvider shareActionProvider;
30 |
31 | public static SingleNewsFragment getInstance(NewsArticle e) {
32 | mEvent = e;
33 | if (mInstance == null) {
34 | mInstance = new SingleNewsFragment();
35 | return mInstance;
36 | } else {
37 | return mInstance;
38 | }
39 | }
40 |
41 | @Override
42 | public void onViewCreated(View view, Bundle savedInstanceState) {
43 | super.onViewCreated(view, savedInstanceState);
44 | View root = getView();
45 | ((TextView) root.findViewById(R.id.e_txtTitle)).setText(mEvent.getTitle());
46 | ((TextView) root.findViewById(R.id.e_txtTitle)).setShadowLayer(13, 0, 0, Color.BLACK);
47 | ((TextView) root.findViewById(R.id.e_txtDate)).setText(mEvent.getPubDate());
48 | ((TextView) root.findViewById(R.id.e_txtDesc)).setText(Html.fromHtml(mEvent.getDesc()));
49 | ((TextView) root.findViewById(R.id.e_txtDesc)).setMovementMethod(new LinkMovementMethod());
50 | Util.getPicasso(getActivity()).load(mEvent.getImgSrc()).placeholder(R.drawable.logo).fit().into((ImageView)root.findViewById(R.id.e_imgLogo));
51 | root.findViewById(R.id.e_btnWebsite).setOnClickListener(new View.OnClickListener() {
52 | @Override
53 | public void onClick(View v) {
54 | Intent i = new Intent(Intent.ACTION_VIEW);
55 | i.setData(Uri.parse(mEvent.getUrl()));
56 | startActivity(i);
57 | }
58 | });
59 | }
60 |
61 | @Override
62 | public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
63 | inflater.inflate(R.menu.share_menu, menu);
64 | MenuItem item = menu.findItem(R.id.menu_item_share);
65 | shareActionProvider = (ShareActionProvider) MenuItemCompat.getActionProvider(item);
66 | shareActionProvider.setShareIntent(getShareIntent());
67 | shareActionProvider.setOnShareTargetSelectedListener(new ShareActionProvider.OnShareTargetSelectedListener() {
68 | @Override
69 | public boolean onShareTargetSelected(ShareActionProvider source, Intent intent) {
70 | return false;
71 | }
72 | });
73 | super.onCreateOptionsMenu(menu, inflater);
74 | }
75 |
76 | private Intent getShareIntent() {
77 | Intent shareIntent = new Intent(Intent.ACTION_SEND);
78 | shareIntent.setType("text/plain");
79 | StringBuilder text = new StringBuilder("Hey, check out this article on Bernie Sanders!\n");
80 | text.append(mEvent.getTitle());
81 | text.append("\n\nRead more here: " + mEvent.getUrl());
82 | text.append("\n\nSent from Bernie Sanders for President 2016 Android Application");
83 | shareIntent.putExtra(Intent.EXTRA_TEXT, text.toString());
84 | return shareIntent;
85 | }
86 |
87 | @Override
88 | public View onCreateView(LayoutInflater inflater, ViewGroup container,
89 | Bundle savedInstanceState) {
90 | // Inflate the layout for this fragment
91 | setHasOptionsMenu(true);
92 | return inflater.inflate(R.layout.frag_event, container, false);
93 | }
94 | }
95 |
--------------------------------------------------------------------------------
/app/src/main/java/com/spielpark/steve/bernieapp/misc/ImgTxtAdapter.java:
--------------------------------------------------------------------------------
1 | package com.spielpark.steve.bernieapp.misc;
2 |
3 | import android.app.Activity;
4 | import android.content.Context;
5 | import android.graphics.Typeface;
6 | import android.text.Html;
7 | import android.view.LayoutInflater;
8 | import android.view.View;
9 | import android.view.ViewGroup;
10 | import android.widget.ArrayAdapter;
11 | import android.widget.ImageView;
12 | import android.widget.TextView;
13 |
14 | import com.spielpark.steve.bernieapp.R;
15 | import com.spielpark.steve.bernieapp.wrappers.ImgTxtItem;
16 |
17 | import java.util.List;
18 |
19 | /**
20 | * Created by Steve on 8/14/2015.
21 | */
22 | public class ImgTxtAdapter extends ArrayAdapter {
23 | private Context ctx;
24 | private List list;
25 | private int layout;
26 |
27 | public ImgTxtAdapter(Context context, int resource, List objects) {
28 | super(context, resource, objects);
29 | this.ctx = context;
30 | this.layout = resource;
31 | this.list = objects;
32 | }
33 |
34 | @Override
35 | public View getView(int position, View convertView, ViewGroup parent) {
36 | ImgTxtItem item = (ImgTxtItem) list.get(position);
37 | ViewHolder v;
38 | if (convertView == null) {
39 | LayoutInflater inflater = ((Activity) ctx).getLayoutInflater();
40 | convertView = inflater.inflate(layout, parent, false);
41 | v = new ViewHolder();
42 | v.img = (ImageView) convertView.findViewById(R.id.picThumb);
43 | v.txt = (TextView) convertView.findViewById(R.id.txtItem);
44 | convertView.setTag(v);
45 | } else {
46 | v = (ViewHolder) convertView.getTag();
47 | }
48 | Util.getPicasso(ctx).load(item.getImgSrc()).fit().into(v.img);
49 | v.txt.setTypeface(Typeface.createFromAsset(ctx.getAssets(), "Jubilat.otf"));
50 | v.txt.setText(Html.fromHtml(item.getTxt()));
51 | return convertView;
52 | }
53 |
54 | private static class ViewHolder {
55 | TextView txt;
56 | ImageView img;
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/app/src/main/java/com/spielpark/steve/bernieapp/misc/Util.java:
--------------------------------------------------------------------------------
1 | package com.spielpark.steve.bernieapp.misc;
2 |
3 | import android.app.Activity;
4 | import android.content.Context;
5 | import android.content.DialogInterface;
6 | import android.content.SharedPreferences;
7 | import android.support.v7.app.AlertDialog;
8 | import android.util.DisplayMetrics;
9 | import android.util.Log;
10 | import android.view.LayoutInflater;
11 | import android.view.View;
12 | import android.widget.CheckBox;
13 |
14 | import com.spielpark.steve.bernieapp.R;
15 | import com.squareup.picasso.Picasso;
16 |
17 | /**
18 | * Created by Steve on 8/14/2015.
19 | */
20 | public class Util {
21 |
22 | private static Picasso p;
23 | public enum Preferences {
24 | BERNRATE_DIALOGUE("BernRate_ShowDialogue", 1);
25 |
26 | Preferences(String s, int i) {
27 | this.value = i;
28 | this.name = s;
29 | }
30 | public int value;
31 | public String name;
32 | }
33 |
34 | public static int[] getScreenWidthHeight(Activity ctx) {
35 | DisplayMetrics metrics = new DisplayMetrics();
36 | ctx.getWindowManager().getDefaultDisplay().getMetrics(metrics);
37 | int width = Math.round(metrics.widthPixels / metrics.density) - 24;
38 | int height = Math.round(metrics.heightPixels / metrics.density) / 3;
39 | return new int[] {width, height};
40 | }
41 |
42 | public static Picasso getPicasso(Context ctx) {
43 | if (p == null) {
44 | p = new Picasso.Builder(ctx).build();
45 | }
46 | return p;
47 | }
48 |
49 | public static int getFullScreenHeight(Activity ctx) {
50 | DisplayMetrics metrics = new DisplayMetrics();
51 | ctx.getWindowManager().getDefaultDisplay().getMetrics(metrics);
52 | int height = Math.round(metrics.heightPixels / metrics.density);
53 | return height;
54 | }
55 |
56 | public static AlertDialog getShowAgainDialogue(Context ctx, final SharedPreferences prefs, final Preferences p, String message) {
57 | LayoutInflater inflater = LayoutInflater.from(ctx);
58 | final View view = inflater.inflate(R.layout.dialogue_checkbox, null);
59 | AlertDialog.Builder bld = new AlertDialog.Builder(ctx, 4);
60 | bld.setMessage(message)
61 | .setTitle("Welcome!")
62 | .setPositiveButton("Ok", new DialogInterface.OnClickListener() {
63 | @Override
64 | public void onClick(DialogInterface dialogInterface, int i) {
65 | dialogInterface.dismiss();
66 | }
67 | })
68 | .setOnDismissListener(new DialogInterface.OnDismissListener() {
69 | @Override
70 | public void onDismiss(DialogInterface dialogInterface) {
71 | Log.d("Dialog", "Was dismissed.");
72 | boolean checked = ((CheckBox) view.findViewById(R.id.dia_checkbox)).isChecked();
73 | if (checked) {
74 | Log.d("Dialog Gen", "Box was checked, putting in things.");
75 | prefs.edit().putInt(p.name, 0).commit();
76 | }
77 | }
78 | })
79 | .setView(view);
80 | return bld.create();
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/app/src/main/java/com/spielpark/steve/bernieapp/tasks/ConnectTask.java:
--------------------------------------------------------------------------------
1 | package com.spielpark.steve.bernieapp.tasks;
2 |
3 | import android.app.Activity;
4 | import android.content.Context;
5 | import android.graphics.Typeface;
6 | import android.os.AsyncTask;
7 | import android.text.Html;
8 | import android.util.JsonReader;
9 | import android.util.JsonToken;
10 | import android.util.Log;
11 | import android.view.LayoutInflater;
12 | import android.view.View;
13 | import android.view.ViewGroup;
14 | import android.widget.ArrayAdapter;
15 | import android.widget.ImageView;
16 | import android.widget.TextView;
17 |
18 | import com.spielpark.steve.bernieapp.R;
19 | import com.spielpark.steve.bernieapp.fragments.ConnectFragment;
20 | import com.spielpark.steve.bernieapp.misc.Util;
21 | import com.spielpark.steve.bernieapp.wrappers.Event;
22 | import com.spielpark.steve.bernieapp.wrappers.ImgTxtItem;
23 |
24 | import java.io.BufferedReader;
25 | import java.io.IOException;
26 | import java.io.InputStreamReader;
27 | import java.net.URL;
28 | import java.text.ParseException;
29 | import java.text.SimpleDateFormat;
30 | import java.util.ArrayList;
31 | import java.util.Collections;
32 | import java.util.Date;
33 |
34 | /**
35 | * Created by Steve on 7/8/2015.
36 | */
37 | public class ConnectTask extends AsyncTask {
38 | private static ArrayList events;
39 | private static Context ctx;
40 | private static ConnectFragment frag;
41 |
42 | public ConnectTask(Context ctx, ConnectFragment frag) {
43 | this.frag = frag;
44 | this.ctx = ctx;
45 | }
46 |
47 | public static ArrayList getEvents() {
48 | return events;
49 | }
50 |
51 | @Override
52 | protected Object doInBackground(Object[] params) {
53 | events = new ArrayList<>();
54 | BufferedReader in = null;
55 | try {
56 | URL url = frag.fetchCountry ?
57 | new URL("https://go.berniesanders.com/page/event/search_results?orderby=date&format=json&limit=500") :
58 | new URL("https://go.berniesanders.com/page/event/search_results?orderby=date&format=json&zip_radius=" + frag.mRadius + "&zip=" + frag.mZip);
59 | Log.d("URL", url.toString());
60 | in = new BufferedReader(new InputStreamReader(url.openStream()));
61 | } catch (IOException e) {
62 | e.printStackTrace();
63 | }
64 | if (in == null) {
65 | Log.d("reader null", "no events, null reader,");
66 | Event e = new Event();
67 | e.setName("Unable to Load News");
68 | e.setDescription("Check your internet connection?");
69 | events.add(e);
70 | return null;
71 | }
72 | JsonReader reader = new JsonReader(in);
73 | try {
74 | readObjects(reader);
75 | } catch (IOException e) {
76 | e.printStackTrace();
77 | }
78 | return null;
79 | }
80 |
81 | @Override
82 | protected void onPostExecute(Object o) {
83 | super.onPostExecute(o);
84 | Log.d("OPE", "There are " + events.size() + " events.");
85 | Collections.sort(events);
86 | String[] titles = new String[events.size()];
87 | String[] dates = new String[events.size()];
88 | for (int i = 0; i < events.size(); i++) {
89 | titles[i] = getHTMLForTitle(events.get(i));
90 | dates[i] = getHTMLForDate(events.get(i).getDate());
91 | }
92 | ConnectAdapter adapter = new ConnectAdapter(ctx, R.layout.list_connect_events, dates, titles);
93 | frag.setMarkers();
94 | frag.updateViews(adapter);
95 | frag = null;
96 | }
97 |
98 | private void formatDate(Event e) {
99 | SimpleDateFormat ft = new SimpleDateFormat("yyyy-MM-dd");
100 | try {
101 | Date date = ft.parse(e.getDate());
102 | e.setDate(new SimpleDateFormat("MMMM d, yyyy").format(date));
103 | } catch (ParseException e1) {
104 | e1.printStackTrace();
105 | }
106 | }
107 |
108 | private String getHTMLForTitle(Event e) {
109 | StringBuilder bld = new StringBuilder();
110 | bld.append("").append(e.getName()).append("
");
111 | if (e.getVenue_city() != null) {
112 | bld.append(" ").append(e.getVenue_city()).append(", ").append(e.getState()).append(" - ").append(e.getZip()).append("
");
113 | bld.append(" Participating: ").append(e.isOfficial() ? "N/A" : Integer.toString(e.getAttendee_count()));
114 | }
115 | return bld.toString();
116 | }
117 |
118 | private String getHTMLForDate(String s) {
119 | String ret = s;
120 | SimpleDateFormat ft = new SimpleDateFormat("MMMM d, yyyy");
121 | try {
122 | Date date = ft.parse(s);
123 | ret = new SimpleDateFormat("''d'
'MMM''").format(date);
124 | } catch (ParseException e1) {
125 | e1.printStackTrace();
126 | }
127 | return ret;
128 | }
129 |
130 | private void readObjects(JsonReader reader) throws IOException {
131 | Log.d("JsonReader", "Beginning parsing");
132 | Event e = new Event();
133 | while (reader.hasNext()) {
134 | if (isCancelled()) {
135 | return;
136 | }
137 | if (reader.peek() == JsonToken.END_OBJECT) {
138 | Log.d("Adding..", "Adding event: " + e.getName());
139 | formatDate(e);
140 | events.add(e);
141 | e = new Event();
142 | reader.endObject();
143 | }
144 | if (reader.peek() == JsonToken.BEGIN_OBJECT) {
145 | reader.beginObject();
146 | }
147 | String next = reader.nextName();
148 | switch(next.toLowerCase().trim()) {
149 | case "results" : {
150 | reader.beginArray();
151 | if (reader.peek() == JsonToken.END_ARRAY) {
152 | //There's no events~!
153 | e.setName("No events in your area!");
154 | e.setDescription("Perhaps you want to create one? Visit www.berniesanders.com!");
155 | events.add(e);
156 | return;
157 | }
158 | reader.beginObject();
159 | break;
160 | }
161 | case "name" : {
162 | e.setName(reader.nextString());
163 | break;
164 | }
165 | case "start_day" : {
166 | e.setDate(reader.nextString());
167 | break;
168 | }
169 | case "start_time" : {
170 | e.setTime(reader.nextString());
171 | break;
172 | }
173 | case "url" : {
174 | e.setUrl(reader.nextString().replaceAll("\\\\", ""));
175 | break;
176 | }
177 | case "timezone" : {
178 | e.setTimezone(reader.nextString());
179 | break;
180 | }
181 | case "description" : {
182 | e.setDescription(reader.nextString());
183 | break;
184 | }
185 | case "event_type_name" : {
186 | e.setEventType(reader.nextString());
187 | break;
188 | }
189 | case "venue_name" : {
190 | e.setVenue(reader.nextString());
191 | break;
192 | }
193 | case "venue_state_cd" : {
194 | e.setState(reader.nextString());
195 | break;
196 | }
197 | case "venue_addr1" : {
198 | e.setVenue_addr(reader.nextString());
199 | break;
200 | }
201 | case "venue_city" : {
202 | e.setVenue_city(reader.nextString());
203 | break;
204 | }
205 | case "venue_zip" : {
206 | String zipped = reader.nextString().substring(0, 5);
207 | e.setZip(Integer.parseInt(zipped));
208 | break;
209 | }
210 | case "capacity" : {
211 | e.setCapacity(reader.nextInt());
212 | break;
213 | }
214 | case "latitude" : {
215 | e.setLatitude(reader.nextDouble());
216 | break;
217 | }
218 | case "longitude" : {
219 | e.setLongitude(reader.nextDouble());
220 | break;
221 | }
222 | case "is_official" : {
223 | e.setOfficial(reader.nextInt() == 1);
224 | break;
225 | }
226 | case "closed_msg" : {
227 | reader.skipValue(); //consume and throw away
228 | if (reader.peek() == JsonToken.END_OBJECT) {
229 | formatDate(e);
230 | events.add(e);
231 | e = new Event();
232 | reader.endObject();
233 | }
234 | break;
235 | }
236 | case "attendee_count" : {
237 | e.setAttendee_count(reader.nextInt());
238 | formatDate(e);
239 | events.add(e);
240 | e = new Event();
241 | reader.endObject();
242 | break;
243 | }
244 | default: {
245 | reader.skipValue();
246 | }
247 | }
248 | }
249 | reader.close();
250 | }
251 |
252 | private class ConnectAdapter extends ArrayAdapter {
253 | private String[] dates;
254 | private String[] titles;
255 | private int res;
256 |
257 | public ConnectAdapter(Context context, int resource, String[] dates, String[] titles) {
258 | super(context, resource, dates);
259 | this.dates = dates;
260 | this.titles = titles;
261 | this.res = resource;
262 | }
263 |
264 | @Override
265 | public Object getItem(int position) {
266 | return Html.fromHtml( dates[position] + " " + titles[position]);
267 | }
268 |
269 | @Override
270 | public int getCount() {
271 | return dates.length;
272 | }
273 |
274 | @Override
275 | public View getView(int position, View convertView, ViewGroup parent) {
276 | ViewHolder v;
277 | if (convertView == null) {
278 | LayoutInflater inflater = ((Activity) ctx).getLayoutInflater();
279 | convertView = inflater.inflate(res, parent, false);
280 | v = new ViewHolder();
281 | v.date = (TextView) convertView.findViewById(R.id.list_con_txtDate);
282 | v.title = (TextView) convertView.findViewById(R.id.list_con_txtDesc);
283 | convertView.setTag(v);
284 | } else {
285 | v = (ViewHolder) convertView.getTag();
286 | }
287 | v.date.setText(Html.fromHtml(dates[position]));
288 | v.date.setTypeface(Typeface.createFromAsset(ctx.getAssets(), "Jubilat.otf"));
289 | v.title.setText(Html.fromHtml(titles[position]));
290 | return convertView;
291 | }
292 |
293 | private class ViewHolder {
294 | TextView date;
295 | TextView title;
296 | }
297 | }
298 | }
299 |
--------------------------------------------------------------------------------
/app/src/main/java/com/spielpark/steve/bernieapp/tasks/IssuesTask.java:
--------------------------------------------------------------------------------
1 | package com.spielpark.steve.bernieapp.tasks;
2 |
3 | import android.content.Context;
4 | import android.os.AsyncTask;
5 | import android.text.Html;
6 | import android.util.JsonReader;
7 | import android.util.JsonToken;
8 | import android.util.Log;
9 | import android.view.View;
10 | import android.widget.ListView;
11 | import android.widget.ProgressBar;
12 |
13 | import com.spielpark.steve.bernieapp.R;
14 | import com.spielpark.steve.bernieapp.misc.ImgTxtAdapter;
15 | import com.spielpark.steve.bernieapp.wrappers.Issue;
16 |
17 | import java.io.BufferedReader;
18 | import java.io.IOException;
19 | import java.io.InputStreamReader;
20 | import java.net.URL;
21 | import java.util.ArrayList;
22 | import java.util.HashMap;
23 |
24 | /**
25 | * Created by Steve on 7/9/2015.
26 | */
27 | public class IssuesTask extends AsyncTask