diff --git a/app/build.gradle b/app/build.gradle index 6c1d618..39bdd9a 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -24,6 +24,9 @@ android { proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } + dexOptions { + jumboMode true + } } dependencies { diff --git a/app/src/main/java/com/wbrawner/simplemarkdown/EditPagerAdapter.java b/app/src/main/java/com/wbrawner/simplemarkdown/EditPagerAdapter.java new file mode 100644 index 0000000..f2e52cc --- /dev/null +++ b/app/src/main/java/com/wbrawner/simplemarkdown/EditPagerAdapter.java @@ -0,0 +1,63 @@ +package com.wbrawner.simplemarkdown; + +/** + * Created by billy on 7/29/2017. + */ + +import android.content.Context; +import android.content.res.Configuration; +import android.support.v4.app.Fragment; +import android.support.v4.app.FragmentManager; +import android.support.v4.app.FragmentPagerAdapter; + +import static com.wbrawner.simplemarkdown.MainActivity.FRAGMENT_EDIT; +import static com.wbrawner.simplemarkdown.MainActivity.FRAGMENT_PREVIEW; +import static com.wbrawner.simplemarkdown.MainActivity.NUM_PAGES; + +class EditPagerAdapter extends FragmentPagerAdapter { + private Context mContext; + + public EditPagerAdapter(FragmentManager fm, Context context) { + super(fm); + mContext = context; + } + + @Override + public Fragment getItem(int position) { + switch (position) { + case FRAGMENT_EDIT: + return new EditFragment(); + case FRAGMENT_PREVIEW: + return new PreviewFragment(); + } + return null; + } + + @Override + public int getCount() { + return NUM_PAGES; + } + + @Override + public CharSequence getPageTitle(int position) { + int stringId = 0; + switch (position) { + case FRAGMENT_EDIT: + stringId = R.string.action_edit; + break; + case FRAGMENT_PREVIEW: + stringId = R.string.action_preview; + break; + } + return mContext.getString(stringId); + } + + @Override + public float getPageWidth(int position) { + if (mContext.getResources().getConfiguration().orientation + == Configuration.ORIENTATION_LANDSCAPE) { + return 0.5f; + } + return super.getPageWidth(position); + } +} diff --git a/app/src/main/java/com/wbrawner/simplemarkdown/MainActivity.java b/app/src/main/java/com/wbrawner/simplemarkdown/MainActivity.java index ef194bd..4ee99f1 100644 --- a/app/src/main/java/com/wbrawner/simplemarkdown/MainActivity.java +++ b/app/src/main/java/com/wbrawner/simplemarkdown/MainActivity.java @@ -4,9 +4,11 @@ import android.Manifest; import android.app.ProgressDialog; import android.content.ActivityNotFoundException; import android.content.ClipData; +import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.content.pm.PackageManager; +import android.content.res.Configuration; import android.net.Uri; import android.os.Environment; import android.support.annotation.Nullable; @@ -29,6 +31,7 @@ import android.util.Log; import android.view.Menu; import android.view.MenuItem; import android.view.SearchEvent; +import android.view.WindowManager; import android.webkit.MimeTypeMap; import android.widget.EditText; import android.widget.Toast; @@ -44,6 +47,10 @@ public class MainActivity extends AppCompatActivity public static final String AUTHORITY = "com.wbrawner.simplemarkdown.fileprovider"; private static final int REQUEST_WRITE_STORAGE = 0; private static File mFilesDir; + public static final int FRAGMENT_EDIT = 0; + public static final int FRAGMENT_PREVIEW = 1; + public static final int NUM_PAGES = 2; + @BindView(R.id.pager) ViewPager pager; @BindView(R.id.layout_tab) @@ -83,7 +90,9 @@ public class MainActivity extends AppCompatActivity super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ButterKnife.bind(this); - pager.setAdapter(new EditPagerAdapter(getSupportFragmentManager())); + pager.setAdapter( + new EditPagerAdapter(getSupportFragmentManager(), MainActivity.this) + ); mFilesDir = getFilesDir(); checkDirectories(); Intent intent = getIntent(); @@ -231,53 +240,12 @@ public class MainActivity extends AppCompatActivity } } } - - public class EditPagerAdapter extends FragmentPagerAdapter { - private static final int FRAGMENT_EDIT = 0; - public static final int FRAGMENT_PREVIEW = 1; - private static final int NUM_PAGES = 2; - - public EditPagerAdapter(FragmentManager fm) { - super(fm); - } - - @Override - public Fragment getItem(int position) { - switch (position) { - case FRAGMENT_EDIT: - return new EditFragment(); - case FRAGMENT_PREVIEW: - return new PreviewFragment(); - } - return null; - } - - @Override - public int getCount() { - return NUM_PAGES; - } - - @Override - public CharSequence getPageTitle(int position) { - int stringId = 0; - switch (position) { - case FRAGMENT_EDIT: - stringId = R.string.action_edit; - break; - case FRAGMENT_PREVIEW: - stringId = R.string.action_preview; - break; - } - return getString(stringId); - } - } - @Override public void onBackPressed() { - if (pager.getCurrentItem() == EditPagerAdapter.FRAGMENT_EDIT) + if (pager.getCurrentItem() == FRAGMENT_EDIT) super.onBackPressed(); else - pager.setCurrentItem(EditPagerAdapter.FRAGMENT_EDIT); + pager.setCurrentItem(FRAGMENT_EDIT); } @Override diff --git a/app/src/main/res/layout/fragment_edit.xml b/app/src/main/res/layout/fragment_edit.xml index 02f2669..f9453ce 100644 --- a/app/src/main/res/layout/fragment_edit.xml +++ b/app/src/main/res/layout/fragment_edit.xml @@ -2,7 +2,6 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" - android:padding="8dp" tools:context="com.wbrawner.simplemarkdown.EditFragment">