Switch the downloader to an ActionBar Tab

And hopefully finish up cleaning up the bin/ and gen/ folders...
This commit is contained in:
Bradlee Speice
2014-04-15 22:18:21 -04:00
parent 5fb077a40d
commit 431ce603c6
26 changed files with 328 additions and 779 deletions

View File

@ -3,11 +3,8 @@ package org.bspeice.minimalbible;
import org.bspeice.minimalbible.activities.NavigationDrawerFragment;
import org.bspeice.minimalbible.activities.downloader.DownloaderActivity;
import com.readystatesoftware.systembartint.SystemBarTintManager;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.Fragment;
@ -22,6 +19,8 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import com.readystatesoftware.systembartint.SystemBarTintManager;
public class BibleViewer extends ActionBarActivity implements
NavigationDrawerFragment.NavigationDrawerCallbacks {

View File

@ -2,6 +2,11 @@ package org.bspeice.minimalbible;
public class MinimalBibleConstants {
public static final String DOWNLOAD_PREFS_FILE = "DOWNLOADER_PREFERENCES";
public static class DownloadPreferences {
public static final String DOWNLOAD_PREFS_FILE = "DOWNLOADER_PREFERENCES";
public static final String KEY_DOWNLOAD_ENABLED = "HAS_ENABLED_DOWNLOAD";
public static final String KEY_PERM_DISABLE_DOWNLOAD = "PERMANENTLY_DISABLE_DOWNLOAD";
}
}

View File

@ -1,28 +1,19 @@
package org.bspeice.minimalbible.activities;
import org.bspeice.minimalbible.R;
import org.bspeice.minimalbible.R.drawable;
import org.bspeice.minimalbible.R.id;
import org.bspeice.minimalbible.R.layout;
import org.bspeice.minimalbible.R.menu;
import org.bspeice.minimalbible.R.string;
import org.bspeice.minimalbible.activities.downloader.DownloaderActivity;
import com.readystatesoftware.systembartint.SystemBarTintManager;
import android.support.v7.app.ActionBarActivity;
import android.app.Activity;
import android.support.v7.app.ActionBar;
import android.support.v4.app.Fragment;
import android.support.v4.app.ActionBarDrawerToggle;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.os.Build;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v4.app.ActionBarDrawerToggle;
import android.support.v4.app.Fragment;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBarActivity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
@ -34,6 +25,8 @@ import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;
import com.readystatesoftware.systembartint.SystemBarTintManager;
/**
* Fragment used for managing interactions for and presentation of a navigation
* drawer. See the <a href=

View File

@ -1,76 +1,243 @@
package org.bspeice.minimalbible.activities.downloader;
import org.bspeice.minimalbible.MinimalBibleConstants;
import org.bspeice.minimalbible.R;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.Menu;
import android.widget.Toast;
public class DownloaderActivity extends Activity {
private static final String KEY_DOWNLOAD_ENABLED = "HAS_ENABLED_DOWNLOAD";
public static final String KEY_PERM_DISABLE_DOWNLOAD = "PERMANENTLY_DISABLE_DOWNLOAD";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_downloader);
// Display a warning about internet connectivity
displayInternetWarning();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.downloader, menu);
return true;
}
private void displayInternetWarning() {
SharedPreferences prefs = getSharedPreferences(MinimalBibleConstants.DOWNLOAD_PREFS_FILE, MODE_PRIVATE);
// If downloading has not been enabled, or user has permanently disabled downloading, WARN THEM!
if (!prefs.getBoolean(KEY_DOWNLOAD_ENABLED, false) || prefs.getBoolean(KEY_PERM_DISABLE_DOWNLOAD, false)) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
DownloadDialogListener dialogListener = new DownloadDialogListener();
builder.setMessage("About to contact servers to download content. Continue?")
.setPositiveButton("Yes", dialogListener).setNegativeButton("No", dialogListener)
.setCancelable(false).show();
}
}
private void downloadModules() {
}
private class DownloadDialogListener implements DialogInterface.OnClickListener {
@Override
public void onClick(DialogInterface dialog, int which) {
switch (which){
case DialogInterface.BUTTON_POSITIVE:
// Clicked ready to continue - allow downloading in the future
SharedPreferences prefs = getSharedPreferences(MinimalBibleConstants.DOWNLOAD_PREFS_FILE, MODE_PRIVATE);
prefs.edit().putBoolean(KEY_DOWNLOAD_ENABLED, true).commit();
// And warn them that it has been enabled in the future.
Toast.makeText(DownloaderActivity.this,
"Downloading now enabled. Disable in settings.", Toast.LENGTH_SHORT).show();
downloadModules();
break;
case DialogInterface.BUTTON_NEGATIVE:
// Not going to continue, still show what has
// already been downloaded.
break;
}
}
}
}
package org.bspeice.minimalbible.activities.downloader;
import java.util.Locale;
import org.bspeice.minimalbible.MinimalBibleConstants.DownloadPreferences;
import org.bspeice.minimalbible.R;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.view.ViewPager;
import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBarActivity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;
public class DownloaderActivity extends ActionBarActivity implements
ActionBar.TabListener {
/**
* The {@link android.support.v4.view.PagerAdapter} that will provide
* fragments for each of the sections. We use a {@link FragmentPagerAdapter}
* derivative, which will keep every loaded fragment in memory. If this
* becomes too memory intensive, it may be best to switch to a
* {@link android.support.v4.app.FragmentStatePagerAdapter}.
*/
SectionsPagerAdapter mSectionsPagerAdapter;
/**
* The {@link ViewPager} that will host the section contents.
*/
ViewPager mViewPager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_downloader);
// Set up the action bar.
final ActionBar actionBar = getSupportActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
// Create the adapter that will return a fragment for each of the three
// primary sections of the activity.
mSectionsPagerAdapter = new SectionsPagerAdapter(
getSupportFragmentManager());
// Set up the ViewPager with the sections adapter.
mViewPager = (ViewPager) findViewById(R.id.pager);
mViewPager.setAdapter(mSectionsPagerAdapter);
// When swiping between different sections, select the corresponding
// tab. We can also use ActionBar.Tab#select() to do this if we have
// a reference to the Tab.
mViewPager
.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
@Override
public void onPageSelected(int position) {
actionBar.setSelectedNavigationItem(position);
}
});
// For each of the sections in the app, add a tab to the action bar.
for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) {
// Create a tab with text corresponding to the page title defined by
// the adapter. Also specify this Activity object, which implements
// the TabListener interface, as the callback (listener) for when
// this tab is selected.
actionBar.addTab(actionBar.newTab()
.setText(mSectionsPagerAdapter.getPageTitle(i))
.setTabListener(this));
}
// Display a warning about internet connectivity
displayInternetWarning();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.downloader, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
public void onTabSelected(ActionBar.Tab tab,
FragmentTransaction fragmentTransaction) {
// When the given tab is selected, switch to the corresponding page in
// the ViewPager.
mViewPager.setCurrentItem(tab.getPosition());
}
@Override
public void onTabUnselected(ActionBar.Tab tab,
FragmentTransaction fragmentTransaction) {
}
@Override
public void onTabReselected(ActionBar.Tab tab,
FragmentTransaction fragmentTransaction) {
}
/**
* A {@link FragmentPagerAdapter} that returns a fragment corresponding to
* one of the sections/tabs/pages.
*/
public class SectionsPagerAdapter extends FragmentPagerAdapter {
public SectionsPagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int position) {
// getItem is called to instantiate the fragment for the given page.
// Return a PlaceholderFragment (defined as a static inner class
// below).
return PlaceholderFragment.newInstance(position + 1);
}
@Override
public int getCount() {
// Show 3 total pages.
return 3;
}
@Override
public CharSequence getPageTitle(int position) {
Locale l = Locale.getDefault();
switch (position) {
case 0:
return getString(R.string.title_section1).toUpperCase(l);
case 1:
return getString(R.string.title_section2).toUpperCase(l);
case 2:
return getString(R.string.title_section3).toUpperCase(l);
}
return null;
}
}
/**
* A placeholder fragment containing a simple view.
*/
public static class PlaceholderFragment extends Fragment {
/**
* The fragment argument representing the section number for this
* fragment.
*/
private static final String ARG_SECTION_NUMBER = "section_number";
/**
* Returns a new instance of this fragment for the given section number.
*/
public static PlaceholderFragment newInstance(int sectionNumber) {
PlaceholderFragment fragment = new PlaceholderFragment();
Bundle args = new Bundle();
args.putInt(ARG_SECTION_NUMBER, sectionNumber);
fragment.setArguments(args);
return fragment;
}
public PlaceholderFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_downloader,
container, false);
TextView textView = (TextView) rootView
.findViewById(R.id.section_label);
textView.setText(Integer.toString(getArguments().getInt(
ARG_SECTION_NUMBER)));
return rootView;
}
}
private void displayInternetWarning() {
SharedPreferences prefs = getSharedPreferences(DownloadPreferences.DOWNLOAD_PREFS_FILE, MODE_PRIVATE);
// If downloading has not been enabled, or user has permanently disabled downloading, WARN THEM!
if (!prefs.getBoolean(DownloadPreferences.KEY_DOWNLOAD_ENABLED, false) || prefs.getBoolean(DownloadPreferences.KEY_PERM_DISABLE_DOWNLOAD, false)) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
DownloadDialogListener dialogListener = new DownloadDialogListener();
builder.setMessage("About to contact servers to download content. Continue?")
.setPositiveButton("Yes", dialogListener).setNegativeButton("No", dialogListener)
.setCancelable(false).show();
}
}
private void downloadModules() {
}
private class DownloadDialogListener implements DialogInterface.OnClickListener {
@Override
public void onClick(DialogInterface dialog, int which) {
switch (which){
case DialogInterface.BUTTON_POSITIVE:
// Clicked ready to continue - allow downloading in the future
SharedPreferences prefs = getSharedPreferences(DownloadPreferences.DOWNLOAD_PREFS_FILE, MODE_PRIVATE);
prefs.edit().putBoolean(DownloadPreferences.KEY_DOWNLOAD_ENABLED, true).commit();
// And warn them that it has been enabled in the future.
Toast.makeText(DownloaderActivity.this,
"Downloading now enabled. Disable in settings.", Toast.LENGTH_SHORT).show();
downloadModules();
break;
case DialogInterface.BUTTON_NEGATIVE:
// Not going to continue, still show what has
// already been downloaded.
break;
}
}
}
}