Skip to content

Commit

Permalink
Merge pull request #42 from jtmcn/beta
Browse files Browse the repository at this point in the history
Update master to latest beta
  • Loading branch information
kevinhinterlong authored Jun 14, 2017
2 parents d3e4feb + 953c860 commit 84d56e1
Show file tree
Hide file tree
Showing 34 changed files with 607 additions and 168 deletions.
12 changes: 9 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ android {
applicationId "com.jtmcn.archwiki.viewer"
minSdkVersion 15
targetSdkVersion 25
versionCode 8
versionName "1.0.7"
versionCode 12
versionName "1.0.11"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}

Expand All @@ -27,7 +27,13 @@ dependencies {
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:support-v4:25.3.1'
compile 'com.jakewharton:butterknife:8.6.0'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.6.0'

compile 'com.google.code.gson:gson:2.7'

compile 'com.android.support:design:25.3.1'
compile 'com.android.support:support-v4:25.3.1'
compile 'com.android.support:appcompat-v7:25.3.1'
testCompile 'junit:junit:4.12'
}
10 changes: 10 additions & 0 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,13 @@
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}-keepnames class org.glassfish.** { *; }

-keep class android.support.v7.internal.** { *; }
-keep interface android.support.v7.internal.** { *; }
-keep class android.support.v7.** { *; }
-keep interface android.support.v7.** { *; }

# butterknife
-dontwarn butterknife.internal.**
-keep class **$$ViewInjector { *; }
-keepnames class * { @butterknife.InjectView *;}
4 changes: 1 addition & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,8 @@
android:resource="@xml/searchable" />
</activity>
<activity
android:name=".WikiPrefsActivity"
android:name=".PreferencesActivity"
android:label="@string/app_name">
<!-- android:theme="@android:style/Theme.Holo.Light" -->

<intent-filter>
<action android:name="com.jtmcn.archwiki.viewer.WIKIPREFS" />

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
/*
* Copyright (C) 2015 takahirom
*
* 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.
*/

package com.github.takahirom.webview_in_coodinator_layout;

import android.content.Context;
import android.support.v4.view.MotionEventCompat;
import android.support.v4.view.NestedScrollingChild;
import android.support.v4.view.NestedScrollingChildHelper;
import android.support.v4.view.ViewCompat;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.webkit.WebView;

public class NestedWebView extends WebView implements NestedScrollingChild {
private final int[] mScrollOffset = new int[2];
private final int[] mScrollConsumed = new int[2];
private int mLastY;
private int mNestedOffsetY;
private NestedScrollingChildHelper mChildHelper;

public NestedWebView(Context context) {
this(context, null);
}

public NestedWebView(Context context, AttributeSet attrs) {
this(context, attrs, android.R.attr.webViewStyle);
}

public NestedWebView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
mChildHelper = new NestedScrollingChildHelper(this);
setNestedScrollingEnabled(true);
}

@Override
public boolean onTouchEvent(MotionEvent ev) {
boolean returnValue = false;

MotionEvent event = MotionEvent.obtain(ev);
final int action = MotionEventCompat.getActionMasked(event);
if (action == MotionEvent.ACTION_DOWN) {
mNestedOffsetY = 0;
}
int eventY = (int) event.getY();
event.offsetLocation(0, mNestedOffsetY);
switch (action) {
case MotionEvent.ACTION_MOVE:
int deltaY = mLastY - eventY;
// NestedPreScroll
if (dispatchNestedPreScroll(0, deltaY, mScrollConsumed, mScrollOffset)) {
deltaY -= mScrollConsumed[1];
mLastY = eventY - mScrollOffset[1];
event.offsetLocation(0, -mScrollOffset[1]);
mNestedOffsetY += mScrollOffset[1];
}
returnValue = super.onTouchEvent(event);

// NestedScroll
if (dispatchNestedScroll(0, mScrollOffset[1], 0, deltaY, mScrollOffset)) {
event.offsetLocation(0, mScrollOffset[1]);
mNestedOffsetY += mScrollOffset[1];
mLastY -= mScrollOffset[1];
}
break;
case MotionEvent.ACTION_DOWN:
returnValue = super.onTouchEvent(event);
mLastY = eventY;
// start NestedScroll
startNestedScroll(ViewCompat.SCROLL_AXIS_VERTICAL);
break;
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
returnValue = super.onTouchEvent(event);
// end NestedScroll
stopNestedScroll();
break;
}
return returnValue;
}

@Override
public boolean isNestedScrollingEnabled() {
return mChildHelper.isNestedScrollingEnabled();
}

// Nested Scroll implements
@Override
public void setNestedScrollingEnabled(boolean enabled) {
mChildHelper.setNestedScrollingEnabled(enabled);
}

@Override
public boolean startNestedScroll(int axes) {
return mChildHelper.startNestedScroll(axes);
}

@Override
public void stopNestedScroll() {
mChildHelper.stopNestedScroll();
}

@Override
public boolean hasNestedScrollingParent() {
return mChildHelper.hasNestedScrollingParent();
}

@Override
public boolean dispatchNestedScroll(int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed,
int[] offsetInWindow) {
return mChildHelper.dispatchNestedScroll(dxConsumed, dyConsumed, dxUnconsumed, dyUnconsumed, offsetInWindow);
}

@Override
public boolean dispatchNestedPreScroll(int dx, int dy, int[] consumed, int[] offsetInWindow) {
return mChildHelper.dispatchNestedPreScroll(dx, dy, consumed, offsetInWindow);
}

@Override
public boolean dispatchNestedFling(float velocityX, float velocityY, boolean consumed) {
return mChildHelper.dispatchNestedFling(velocityX, velocityY, consumed);
}

@Override
public boolean dispatchNestedPreFling(float velocityX, float velocityY) {
return mChildHelper.dispatchNestedPreFling(velocityX, velocityY);
}

}
78 changes: 41 additions & 37 deletions app/src/main/java/com/jtmcn/archwiki/viewer/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,49 +1,55 @@
package com.jtmcn.archwiki.viewer;

import android.app.Activity;
import android.app.SearchManager;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v4.view.MenuItemCompat;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.SearchView;
import android.support.v7.widget.ShareActionProvider;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.widget.ProgressBar;
import android.widget.SearchView;
import android.widget.Toast;

import com.jtmcn.archwiki.viewer.data.SearchResult;
import com.jtmcn.archwiki.viewer.data.SearchResultsBuilder;
import com.jtmcn.archwiki.viewer.data.WikiPage;
import com.jtmcn.archwiki.viewer.tasks.Fetch;
import com.jtmcn.archwiki.viewer.tasks.FetchUrl;
import com.jtmcn.archwiki.viewer.utils.AndroidUtils;
import com.jtmcn.archwiki.viewer.utils.SettingsUtils;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends Activity implements FetchUrl.OnFinish<List<SearchResult>> {
import butterknife.BindView;
import butterknife.ButterKnife;

public class MainActivity extends AppCompatActivity implements FetchUrl.OnFinish<List<SearchResult>> {
public static final String TAG = MainActivity.class.getSimpleName();
@BindView(R.id.wiki_view) WikiView wikiViewer;
@BindView(R.id.toolbar) Toolbar toolbar;
private ShareActionProvider shareActionProvider;
private SearchView searchView;
private MenuItem searchMenuItem;
private WikiView wikiViewer;
private List<SearchResult> currentSuggestions;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.wiki_layout);
setContentView(R.layout.activity_main);
ButterKnife.bind(this);

wikiViewer = (WikiView) findViewById(R.id.wvMain);
ProgressBar progressBar = (ProgressBar) findViewById(R.id.ProgressBar);
setSupportActionBar(toolbar);

wikiViewer.buildView(progressBar, getActionBar());
ProgressBar progressBar = ButterKnife.findById(this, R.id.progress_bar);
wikiViewer.buildView(progressBar, getSupportActionBar());

wikiViewer.setWebChromeClient(new WebChromeClient());
handleIntent(getIntent());
}

Expand Down Expand Up @@ -78,15 +84,7 @@ private void handleIntent(Intent intent) {
*/
public void updateWebSettings() {
WebSettings webSettings = wikiViewer.getSettings();

SharedPreferences prefs = PreferenceManager
.getDefaultSharedPreferences(getApplicationContext());

// https://stackoverflow.com/questions/11346916/listpreference-use-string-array-as-entry-and-integer-array-as-entry-values-does
// the value of this preference must be parsed as a string
// todo make a settings utils class to wrap this
String fontSizePref = prefs.getString(WikiPrefsActivity.KEY_TEXT_SIZE, "2");
int fontSize = Integer.valueOf(fontSizePref);
int fontSize = SettingsUtils.getFontSize(this);

//todo this setting should be changed to a slider, remove deprecated call
// deprecated method must be used until Android API 14
Expand Down Expand Up @@ -114,7 +112,7 @@ public void updateWebSettings() {
public boolean onPrepareOptionsMenu(Menu menu) {
SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
searchMenuItem = menu.findItem(R.id.menu_search);
final SearchView searchView = (SearchView) searchMenuItem.getActionView();
searchView = (SearchView) MenuItemCompat.getActionView(searchMenuItem);
searchView.setOnQueryTextFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
Expand All @@ -124,7 +122,6 @@ public void onFocusChange(View v, boolean hasFocus) {
}
});
searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
this.searchView = searchView;
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
Expand All @@ -135,12 +132,12 @@ public boolean onQueryTextSubmit(String query) {
@Override
public boolean onQueryTextChange(String newText) {
if (newText.isEmpty()) {
searchView.setSuggestionsAdapter(null);
setCursorAdapter(new ArrayList<SearchResult>());
return true;
} else {
String searchUrl = SearchResultsBuilder.getSearchQuery(newText);
Fetch.search(MainActivity.this, searchUrl);
return false;
return true;
}
}
});
Expand Down Expand Up @@ -170,24 +167,25 @@ public void hideSearchView() {

@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.options, menu);
getMenuInflater().inflate(R.menu.menu, menu);
MenuItem share = menu.findItem(R.id.menu_share);
shareActionProvider = (ShareActionProvider) MenuItemCompat.getActionProvider(share);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.menu_settings:
startActivity(new Intent(this, WikiPrefsActivity.class));
break;
case R.id.menu_share:
WikiPage wikiPage = wikiViewer.getCurrentWebPage();
if (wikiPage != null) {
AndroidUtils.shareText(wikiPage.getPageTitle(), wikiPage.getPageUrl(), this);
} else { //// TODO: 5/14/2017 either make sure this never happens or localize the strings
Log.w(TAG, "Failed to share current page " + wikiViewer.getUrl());
Toast.makeText(this, "Sorry, can't share this page!", Toast.LENGTH_SHORT).show();
}
Intent intent = AndroidUtils.shareText(wikiPage.getPageTitle(), wikiPage.getPageUrl(), this);
shareActionProvider.setShareIntent(intent);
break;
case R.id.refresh:
wikiViewer.onRefresh();
break;
case R.id.menu_settings:
startActivity(new Intent(this, PreferencesActivity.class));
break;
case R.id.exit:
finish();
Expand All @@ -200,6 +198,12 @@ public boolean onOptionsItemSelected(MenuItem item) {
@Override
public void onFinish(List<SearchResult> results) {
currentSuggestions = results;
searchView.setSuggestionsAdapter(SearchResultsAdapter.getCursorAdapter(this, currentSuggestions));
setCursorAdapter(currentSuggestions);
}

private void setCursorAdapter(List<SearchResult> currentSuggestions) {
searchView.setSuggestionsAdapter(
SearchResultsAdapter.getCursorAdapter(this, currentSuggestions)
);
}
}
Loading

0 comments on commit 84d56e1

Please sign in to comment.