Skip to content

Commit

Permalink
Added a Reading Mode that can be accessed from the menu
Browse files Browse the repository at this point in the history
Reading Mode utilizes the Snacktory library created by karussel which is
licensed under the Apache 2.0 license.
https://github.com/karussell/snacktory
  • Loading branch information
anthonycr committed Feb 5, 2015
1 parent 313f9fb commit 10668a0
Show file tree
Hide file tree
Showing 20 changed files with 2,659 additions and 80 deletions.
11 changes: 11 additions & 0 deletions AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,17 @@
<intent-filter>
<action android:name="android.intent.action.BOOKMARK" />

<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="acr.browser.lightning.ReadingActivity"
android:configChanges="orientation|screenSize|keyboardHidden|keyboard"
android:label="@string/reading_mode"
android:theme="@style/Theme.SettingsTheme" >
<intent-filter>
<action android:name="android.intent.action.READING" />

<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
Expand Down
Binary file added libs/jsoup-1.8.1.jar
Binary file not shown.
34 changes: 34 additions & 0 deletions res/layout/license_activity.xml
Original file line number Diff line number Diff line change
Expand Up @@ -140,5 +140,39 @@
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="#cdcdcd" />

<LinearLayout
android:id="@+id/licenseSnactory"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/listChoiceBackgroundIndicator"
android:orientation="vertical"
android:paddingBottom="10dp"
android:paddingTop="10dp" >

<TextView
android:id="@+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="16dp"
android:text="@string/snacktory"
android:textAppearance="?android:attr/textAppearanceMedium" />

<TextView
android:id="@+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="16dp"
android:text="@string/apache"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="@color/light" />
</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="#cdcdcd" />

</LinearLayout>
39 changes: 39 additions & 0 deletions res/layout/reading_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<include layout="@layout/toolbar_settings" />

<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent" >

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="20dp"
android:orientation="vertical">

<TextView
android:id="@+id/textViewTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:gravity="center_horizontal|center_vertical"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />

<TextView
android:id="@+id/textViewBody"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="start"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />

</LinearLayout>
</ScrollView>

</LinearLayout>
148 changes: 76 additions & 72 deletions res/menu-xlarge/main.xml
Original file line number Diff line number Diff line change
@@ -1,73 +1,77 @@
<!--
Copyright 2014 A.C.R. Development
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->

<menu xmlns:android="http://schemas.android.com/apk/res/android" >

<item
android:id="@+id/action_back"
android:checkable="false"
android:enabled="true"
android:icon="?arrowBackDrawable"
android:showAsAction="always"
android:title="@string/action_back"
android:visible="true">
</item>
<item
android:id="@+id/action_forward"
android:checkable="false"
android:enabled="true"
android:icon="?arrowForwardDrawable"
android:showAsAction="always"
android:title="@string/action_forward"
android:visible="true">
</item>
<item
android:id="@+id/action_new_tab"
android:title="@string/action_new_tab">
</item>
<item
android:id="@+id/action_incognito"
android:title="@string/action_incognito">
</item>
<item
android:id="@+id/action_share"
android:title="@string/action_share"/>
<item
android:id="@+id/action_history"
android:title="@string/action_history">
</item>
<item
android:id="@+id/action_find"
android:title="@string/action_find">
</item>
<item
android:id="@+id/action_copy"
android:title="@string/action_copy">
</item>
<item
android:id="@+id/action_bookmarks"
android:title="@string/action_bookmarks">
</item>
<item
android:id="@+id/action_add_bookmark"
android:title="@string/action_add_bookmark">
</item>
<item
android:id="@+id/action_settings"
android:title="@string/settings">
</item>

<!--
Copyright 2014 A.C.R. Development
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->

<menu xmlns:android="http://schemas.android.com/apk/res/android" >

<item
android:id="@+id/action_back"
android:checkable="false"
android:enabled="true"
android:icon="?arrowBackDrawable"
android:showAsAction="always"
android:title="@string/action_back"
android:visible="true">
</item>
<item
android:id="@+id/action_forward"
android:checkable="false"
android:enabled="true"
android:icon="?arrowForwardDrawable"
android:showAsAction="always"
android:title="@string/action_forward"
android:visible="true">
</item>
<item
android:id="@+id/action_new_tab"
android:title="@string/action_new_tab">
</item>
<item
android:id="@+id/action_incognito"
android:title="@string/action_incognito">
</item>
<item
android:id="@+id/action_share"
android:title="@string/action_share"/>
<item
android:id="@+id/action_history"
android:title="@string/action_history">
</item>
<item
android:id="@+id/action_find"
android:title="@string/action_find">
</item>
<item
android:id="@+id/action_copy"
android:title="@string/action_copy">
</item>
<item
android:id="@+id/action_bookmarks"
android:title="@string/action_bookmarks">
</item>
<item
android:id="@+id/action_add_bookmark"
android:title="@string/action_add_bookmark">
</item>
<item
android:id="@+id/action_reading_mode"
android:title="@string/reading_mode">
</item>
<item
android:id="@+id/action_settings"
android:title="@string/settings">
</item>

</menu>
Expand Down
1 change: 1 addition & 0 deletions res/menu/main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<item android:id="@+id/action_copy" android:title="@string/action_copy" ></item>
<item android:id="@+id/action_bookmarks" android:title="@string/action_bookmarks" ></item>
<item android:id="@+id/action_add_bookmark" android:title="@string/action_add_bookmark" ></item>
<item android:id="@+id/action_reading_mode" android:title="@string/reading_mode" ></item>
<item android:id="@+id/action_settings" android:title="@string/settings" ></item>

</menu>
4 changes: 4 additions & 0 deletions res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -198,4 +198,8 @@
<string name="third_party">Block 3rd Party Cookies</string>
<string name="available_lollipop">This feature is only available on Android 5.0+</string>
<string name="color_mode">Enable Color Mode</string>
<string name="reading_mode">Reader Mode</string>
<string name="loading">Loading&#8230;</string>
<string name="loading_failed">Couldn\'t load anything from the page.</string>
<string name="snacktory">Snacktory</string>
</resources>
26 changes: 18 additions & 8 deletions src/acr/browser/lightning/BrowserActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ private synchronized void initialize() {
mDrawerListRight.setDividerHeight(0);
setNavigationDrawerWidth();
mDrawerLayout.setDrawerListener(new DrawerLocker());

mWebpageBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_webpage);
mActionBar = getSupportActionBar();
final TypedArray styledAttributes = mContext.getTheme().obtainStyledAttributes(
Expand Down Expand Up @@ -350,7 +350,7 @@ public boolean willChangeBounds() {
};
anim.setDuration(300);
anim.setInterpolator(new DecelerateInterpolator());
anim.setAnimationListener(new AnimationListener(){
anim.setAnimationListener(new AnimationListener() {

@Override
public void onAnimationStart(Animation animation) {
Expand All @@ -368,7 +368,7 @@ public void onAnimationEnd(Animation animation) {
@Override
public void onAnimationRepeat(Animation animation) {
}

});
new Handler().postDelayed(new Runnable() {

Expand Down Expand Up @@ -488,12 +488,12 @@ public boolean onLongClick(View v) {
checkForTor();

}

private class DrawerLocker implements DrawerListener {

@Override
public void onDrawerClosed(View v) {
if(v == mDrawerRight){
if (v == mDrawerRight) {
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED, mDrawerLeft);
} else {
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED, mDrawerRight);
Expand All @@ -502,7 +502,7 @@ public void onDrawerClosed(View v) {

@Override
public void onDrawerOpened(View v) {
if(v == mDrawerRight){
if (v == mDrawerRight) {
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED, mDrawerLeft);
} else {
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED, mDrawerRight);
Expand All @@ -516,7 +516,7 @@ public void onDrawerSlide(View v, float arg) {
@Override
public void onDrawerStateChanged(int arg) {
}

}

public boolean handleMenuItemClick(MenuItem item) {
Expand Down Expand Up @@ -596,6 +596,11 @@ public boolean handleMenuItemClick(MenuItem item) {
case R.id.action_find:
findInPage();
return true;
case R.id.action_reading_mode:
Intent read = new Intent(this, ReadingActivity.class);
read.putExtra(Constants.LOAD_READING_URL, mCurrentView.getUrl());
startActivity(read);
return true;
default:
return super.onOptionsItemSelected(item);
}
Expand Down Expand Up @@ -912,6 +917,11 @@ public boolean onOptionsItemSelected(MenuItem item) {
case R.id.action_find:
findInPage();
return true;
case R.id.action_reading_mode:
Intent read = new Intent(this, ReadingActivity.class);
read.putExtra(Constants.LOAD_READING_URL, mCurrentView.getUrl());
startActivity(read);
return true;
default:
return super.onOptionsItemSelected(item);
}
Expand Down Expand Up @@ -1622,7 +1632,7 @@ public void onClick(View view) {
}

});

ViewCompat.jumpDrawablesToCurrentState(holder.exit);

LightningView web = data.get(position);
Expand Down
2 changes: 2 additions & 0 deletions src/acr/browser/lightning/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ private Constants() {
public static final String JAVASCRIPT_INVERT_PAGE = "javascript:(function(){var e='img {-webkit-filter: invert(100%);'+'-moz-filter: invert(100%);'+'-o-filter: invert(100%);'+'-ms-filter: invert(100%); }',t=document.getElementsByTagName('head')[0],n=document.createElement('style');if(!window.counter){window.counter=1}else{window.counter++;if(window.counter%2==0){var e='html {-webkit-filter: invert(0%); -moz-filter: invert(0%); -o-filter: invert(0%); -ms-filter: invert(0%); }'}}n.type='text/css';if(n.styleSheet){n.styleSheet.cssText=e}else{n.appendChild(document.createTextNode(e))}t.appendChild(n)})();";
public static final String JAVASCRIPT_TEXT_REFLOW = "javascript:document.getElementsByTagName('body')[0].style.width=window.innerWidth+'px';";

public static final String LOAD_READING_URL = "ReadingUrl";

public static final String SEPARATOR = "\\|\\$\\|SEPARATOR\\|\\$\\|";
public static final String HTTP = "http://";
public static final String HTTPS = "https://";
Expand Down
4 changes: 4 additions & 0 deletions src/acr/browser/lightning/LicenseActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ protected void onCreate(Bundle savedInstanceState) {
findViewById(R.id.licenseAOSP).setOnClickListener(this);
findViewById(R.id.licenseHosts).setOnClickListener(this);
findViewById(R.id.licenseOrbot).setOnClickListener(this);
findViewById(R.id.licenseSnactory).setOnClickListener(this);
}

@Override
Expand All @@ -47,6 +48,9 @@ public void onClick(View v) {
case R.id.licenseOrbot:
actionView("http://www.gnu.org/licenses/lgpl.html");
break;
case R.id.licenseSnactory:
actionView("http://www.apache.org/licenses/LICENSE-2.0");
break;
}
}

Expand Down
Loading

0 comments on commit 10668a0

Please sign in to comment.