summaryrefslogtreecommitdiff
path: root/org.fox.ttrss/src
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2015-11-28 16:30:12 +0300
committerAndrew Dolgov <[email protected]>2015-11-28 16:30:12 +0300
commit4b09961a303173eed338a3ef9f6974d2f932e120 (patch)
tree97edad3a0f5c57a610f3f65a2fc98f1f6e0f5673 /org.fox.ttrss/src
parentb28fef66e85854172103114c15f1722ad6375dea (diff)
implement chrome custom tabs
Diffstat (limited to 'org.fox.ttrss/src')
-rwxr-xr-xorg.fox.ttrss/src/main/AndroidManifest.xml6
-rwxr-xr-xorg.fox.ttrss/src/main/java/org/fox/ttrss/ArticleFragment.java17
-rwxr-xr-xorg.fox.ttrss/src/main/java/org/fox/ttrss/ArticleImagesPagerActivity.java4
-rwxr-xr-xorg.fox.ttrss/src/main/java/org/fox/ttrss/CommonActivity.java79
-rwxr-xr-xorg.fox.ttrss/src/main/java/org/fox/ttrss/HeadlinesFragment.java7
-rwxr-xr-xorg.fox.ttrss/src/main/java/org/fox/ttrss/OnlineActivity.java7
-rwxr-xr-x[-rw-r--r--]org.fox.ttrss/src/main/java/org/fox/ttrss/VideoPlayerActivity.java4
-rwxr-xr-x[-rw-r--r--]org.fox.ttrss/src/main/java/org/fox/ttrss/YoutubePlayerActivity.java4
-rwxr-xr-xorg.fox.ttrss/src/main/java/org/fox/ttrss/offline/OfflineActivity.java4
-rwxr-xr-xorg.fox.ttrss/src/main/java/org/fox/ttrss/offline/OfflineArticleFragment.java11
-rwxr-xr-xorg.fox.ttrss/src/main/res/anim/slide_in_left.xml24
-rwxr-xr-xorg.fox.ttrss/src/main/res/anim/slide_in_right.xml24
-rwxr-xr-xorg.fox.ttrss/src/main/res/anim/slide_out_left.xml24
-rwxr-xr-xorg.fox.ttrss/src/main/res/anim/slide_out_right.xml24
14 files changed, 197 insertions, 42 deletions
diff --git a/org.fox.ttrss/src/main/AndroidManifest.xml b/org.fox.ttrss/src/main/AndroidManifest.xml
index 562f1785..0d179949 100755
--- a/org.fox.ttrss/src/main/AndroidManifest.xml
+++ b/org.fox.ttrss/src/main/AndroidManifest.xml
@@ -1,11 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.fox.ttrss"
- android:versionCode="381"
- android:versionName="1.153" >
+ android:versionCode="382"
+ android:versionName="1.154" >
<uses-sdk
- android:minSdkVersion="15"
+ android:minSdkVersion="16"
android:targetSdkVersion="23" />
<uses-permission android:name="android.permission.INTERNET" />
diff --git a/org.fox.ttrss/src/main/java/org/fox/ttrss/ArticleFragment.java b/org.fox.ttrss/src/main/java/org/fox/ttrss/ArticleFragment.java
index 993c7fd9..8f7e556d 100755
--- a/org.fox.ttrss/src/main/java/org/fox/ttrss/ArticleFragment.java
+++ b/org.fox.ttrss/src/main/java/org/fox/ttrss/ArticleFragment.java
@@ -226,8 +226,9 @@ public class ArticleFragment extends Fragment {
URL url = new URL(m_article.link.trim());
String uri = new URI(url.getProtocol(), url.getUserInfo(), url.getHost(),
url.getPort(), url.getPath(), url.getQuery(), url.getRef()).toString();
- Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
- startActivity(intent);
+
+ m_activity.openUri(Uri.parse(uri));
+
} catch (Exception e) {
e.printStackTrace();
m_activity.toast(R.string.error_other_error);
@@ -264,8 +265,8 @@ public class ArticleFragment extends Fragment {
URL url = new URL(m_article.link.trim());
String uri = new URI(url.getProtocol(), url.getUserInfo(), url.getHost(),
url.getPort(), url.getPath(), url.getQuery(), url.getRef()).toString();
- Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
- startActivity(intent);
+
+ m_activity.openUri(Uri.parse(uri));
} catch (Exception e) {
e.printStackTrace();
m_activity.toast(R.string.error_other_error);
@@ -304,9 +305,8 @@ public class ArticleFragment extends Fragment {
m_article.comments_link : m_article.link);
String uri = new URI(url.getProtocol(), url.getUserInfo(), url.getHost(),
url.getPort(), url.getPath(), url.getQuery(), url.getRef()).toString();
- Intent intent = new Intent(Intent.ACTION_VIEW,
- Uri.parse(uri));
- startActivity(intent);
+
+ m_activity.openUri(Uri.parse(uri));
} catch (Exception e) {
e.printStackTrace();
m_activity.toast(R.string.error_other_error);
@@ -389,8 +389,7 @@ public class ArticleFragment extends Fragment {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
try {
- Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
- startActivity(intent);
+ m_activity.openUri(Uri.parse(url));
return true;
diff --git a/org.fox.ttrss/src/main/java/org/fox/ttrss/ArticleImagesPagerActivity.java b/org.fox.ttrss/src/main/java/org/fox/ttrss/ArticleImagesPagerActivity.java
index 15d712cb..39aa8fe4 100755
--- a/org.fox.ttrss/src/main/java/org/fox/ttrss/ArticleImagesPagerActivity.java
+++ b/org.fox.ttrss/src/main/java/org/fox/ttrss/ArticleImagesPagerActivity.java
@@ -387,9 +387,7 @@ public class ArticleImagesPagerActivity extends CommonActivity implements Gestur
case R.id.article_img_open:
if (url != null) {
try {
- Intent intent = new Intent(Intent.ACTION_VIEW,
- Uri.parse(url));
- startActivity(intent);
+ openUri(Uri.parse(url));
} catch (Exception e) {
e.printStackTrace();
toast(R.string.error_other_error);
diff --git a/org.fox.ttrss/src/main/java/org/fox/ttrss/CommonActivity.java b/org.fox.ttrss/src/main/java/org/fox/ttrss/CommonActivity.java
index c2fe90a1..efef731d 100755
--- a/org.fox.ttrss/src/main/java/org/fox/ttrss/CommonActivity.java
+++ b/org.fox.ttrss/src/main/java/org/fox/ttrss/CommonActivity.java
@@ -2,13 +2,23 @@ package org.fox.ttrss;
import android.annotation.SuppressLint;
+import android.app.PendingIntent;
+import android.content.ComponentName;
+import android.content.Intent;
import android.content.SharedPreferences;
import android.database.sqlite.SQLiteDatabase;
+import android.graphics.BitmapFactory;
+import android.net.Uri;
import android.os.Bundle;
import android.preference.PreferenceManager;
+import android.support.customtabs.CustomTabsCallback;
+import android.support.customtabs.CustomTabsClient;
+import android.support.customtabs.CustomTabsIntent;
+import android.support.customtabs.CustomTabsServiceConnection;
+import android.support.customtabs.CustomTabsSession;
import android.support.v7.app.ActionBarActivity;
-import android.util.DisplayMetrics;
import android.util.Log;
+import android.util.TypedValue;
import android.view.Display;
import android.widget.Toast;
@@ -42,6 +52,21 @@ public class CommonActivity extends ActionBarActivity implements SharedPreferenc
private String m_theme;
private boolean m_needRestart;
+ protected CustomTabsClient m_customTabClient;
+ protected CustomTabsServiceConnection m_customTabServiceConnection = new CustomTabsServiceConnection() {
+ @Override
+ public void onCustomTabsServiceConnected(ComponentName componentName, CustomTabsClient customTabsClient) {
+ m_customTabClient = customTabsClient;
+
+ m_customTabClient.warmup(0);
+ }
+
+ @Override
+ public void onServiceDisconnected(ComponentName componentName) {
+ m_customTabClient = null;
+ }
+ };
+
protected SharedPreferences m_prefs;
protected void setSmallScreen(boolean smallScreen) {
@@ -85,7 +110,7 @@ public class CommonActivity extends ActionBarActivity implements SharedPreferenc
@Override
public void onResume() {
super.onResume();
-
+
if (m_needRestart) {
Log.d(TAG, "restart requested");
@@ -96,6 +121,11 @@ public class CommonActivity extends ActionBarActivity implements SharedPreferenc
@Override
public void onDestroy() {
+
+ if (m_customTabServiceConnection != null) {
+ unbindService(m_customTabServiceConnection);
+ }
+
super.onDestroy();
}
@@ -114,6 +144,8 @@ public class CommonActivity extends ActionBarActivity implements SharedPreferenc
m_theme = m_prefs.getString("theme", CommonActivity.THEME_DEFAULT);
}
+ CustomTabsClient.bindCustomTabsService(this, "com.android.chrome", m_customTabServiceConnection);
+
super.onCreate(savedInstanceState);
}
@@ -172,5 +204,48 @@ public class CommonActivity extends ActionBarActivity implements SharedPreferenc
m_needRestart = Arrays.asList(filter).indexOf(key) != -1;
}
+ private CustomTabsSession getCustomTabSession() {
+ return m_customTabClient.newSession(new CustomTabsCallback() {
+ @Override
+ public void onNavigationEvent(int navigationEvent, Bundle extras) {
+ super.onNavigationEvent(navigationEvent, extras);
+ }
+ });
+ }
+
+ // uses chrome custom tabs when available
+ public void openUri(Uri uri) {
+ if (m_customTabClient != null) {
+
+ TypedValue tvBackground = new TypedValue();
+ getTheme().resolveAttribute(R.attr.colorPrimary, tvBackground, true);
+
+ CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder(getCustomTabSession());
+
+ builder.setStartAnimations(this, R.anim.slide_in_right, R.anim.slide_out_left);
+ builder.setExitAnimations(this, R.anim.slide_in_left, R.anim.slide_out_right);
+
+ builder.setToolbarColor(tvBackground.data);
+
+ Intent shareIntent = new Intent(Intent.ACTION_SEND);
+ shareIntent.setType("text/plain");
+ shareIntent.putExtra(Intent.EXTRA_SUBJECT, uri.toString());
+ shareIntent.putExtra(Intent.EXTRA_TEXT, uri.toString());
+
+ PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, shareIntent, 0);
+
+ builder.setActionButton(BitmapFactory.decodeResource(getResources(), R.drawable.ic_share),
+ getString(R.string.share_article), pendingIntent);
+
+ CustomTabsIntent intent = builder.build();
+
+ intent.launchUrl(this, uri);
+ } else {
+ Intent intent = new Intent(Intent.ACTION_VIEW, uri);
+
+ startActivity(intent);
+ }
+ }
+
}
diff --git a/org.fox.ttrss/src/main/java/org/fox/ttrss/HeadlinesFragment.java b/org.fox.ttrss/src/main/java/org/fox/ttrss/HeadlinesFragment.java
index 53dc944f..cfc8e058 100755
--- a/org.fox.ttrss/src/main/java/org/fox/ttrss/HeadlinesFragment.java
+++ b/org.fox.ttrss/src/main/java/org/fox/ttrss/HeadlinesFragment.java
@@ -185,8 +185,7 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
Article article = getArticleAtPosition(info.position);
if (article != null) {
- Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(article.link));
- startActivity(browserIntent);
+ m_activity.openUri(Uri.parse(article.link));
if (article.unread) {
article.unread = false;
@@ -1255,9 +1254,7 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
startActivity(intent);
} else {
- Intent intent = new Intent(Intent.ACTION_VIEW,
- Uri.parse(article.flavorStreamUri));
- startActivity(intent);
+ m_activity.openUri(Uri.parse(article.flavorStreamUri));
}
} else if ("video".equals(article.flavorImage.tagName().toLowerCase())) {
diff --git a/org.fox.ttrss/src/main/java/org/fox/ttrss/OnlineActivity.java b/org.fox.ttrss/src/main/java/org/fox/ttrss/OnlineActivity.java
index 5185ddc1..0039d3ea 100755
--- a/org.fox.ttrss/src/main/java/org/fox/ttrss/OnlineActivity.java
+++ b/org.fox.ttrss/src/main/java/org/fox/ttrss/OnlineActivity.java
@@ -532,9 +532,7 @@ public class OnlineActivity extends CommonActivity {
case R.id.article_img_open:
if (getLastContentImageHitTestUrl() != null) {
try {
- Intent intent = new Intent(Intent.ACTION_VIEW,
- Uri.parse(getLastContentImageHitTestUrl()));
- startActivity(intent);
+ openUri(Uri.parse(getLastContentImageHitTestUrl()));
} catch (Exception e) {
e.printStackTrace();
toast(R.string.error_other_error);
@@ -658,8 +656,7 @@ public class OnlineActivity extends CommonActivity {
public void onClick(DialogInterface dialog, int id) {
int selectedPosition = ((AlertDialog)dialog).getListView().getCheckedItemPosition();
- Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse((String)itemUrls[selectedPosition]));
- startActivity(browserIntent);
+ openUri(Uri.parse((String)itemUrls[selectedPosition]));
dialog.cancel();
}
diff --git a/org.fox.ttrss/src/main/java/org/fox/ttrss/VideoPlayerActivity.java b/org.fox.ttrss/src/main/java/org/fox/ttrss/VideoPlayerActivity.java
index 92c63b48..480ad530 100644..100755
--- a/org.fox.ttrss/src/main/java/org/fox/ttrss/VideoPlayerActivity.java
+++ b/org.fox.ttrss/src/main/java/org/fox/ttrss/VideoPlayerActivity.java
@@ -229,9 +229,7 @@ public class VideoPlayerActivity extends CommonActivity {
case R.id.article_vid_open:
if (m_streamUri != null) {
try {
- Intent intent = new Intent(Intent.ACTION_VIEW,
- Uri.parse(m_streamUri));
- startActivity(intent);
+ openUri(Uri.parse(m_streamUri));
} catch (Exception e) {
e.printStackTrace();
toast(R.string.error_other_error);
diff --git a/org.fox.ttrss/src/main/java/org/fox/ttrss/YoutubePlayerActivity.java b/org.fox.ttrss/src/main/java/org/fox/ttrss/YoutubePlayerActivity.java
index 7f2c2d6f..565b5fb9 100644..100755
--- a/org.fox.ttrss/src/main/java/org/fox/ttrss/YoutubePlayerActivity.java
+++ b/org.fox.ttrss/src/main/java/org/fox/ttrss/YoutubePlayerActivity.java
@@ -103,9 +103,7 @@ public class YoutubePlayerActivity extends CommonActivity implements YouTubePlay
case R.id.article_vid_open:
if (m_streamUri != null) {
try {
- Intent intent = new Intent(Intent.ACTION_VIEW,
- Uri.parse(m_streamUri));
- startActivity(intent);
+ openUri(Uri.parse(m_streamUri));
} catch (Exception e) {
e.printStackTrace();
toast(R.string.error_other_error);
diff --git a/org.fox.ttrss/src/main/java/org/fox/ttrss/offline/OfflineActivity.java b/org.fox.ttrss/src/main/java/org/fox/ttrss/offline/OfflineActivity.java
index ed46fc44..4575dd22 100755
--- a/org.fox.ttrss/src/main/java/org/fox/ttrss/offline/OfflineActivity.java
+++ b/org.fox.ttrss/src/main/java/org/fox/ttrss/offline/OfflineActivity.java
@@ -83,9 +83,7 @@ public class OfflineActivity extends CommonActivity {
case R.id.article_img_open:
if (getLastContentImageHitTestUrl() != null) {
try {
- Intent intent = new Intent(Intent.ACTION_VIEW,
- Uri.parse(getLastContentImageHitTestUrl()));
- startActivity(intent);
+ openUri(Uri.parse(getLastContentImageHitTestUrl()));
} catch (Exception e) {
e.printStackTrace();
toast(R.string.error_other_error);
diff --git a/org.fox.ttrss/src/main/java/org/fox/ttrss/offline/OfflineArticleFragment.java b/org.fox.ttrss/src/main/java/org/fox/ttrss/offline/OfflineArticleFragment.java
index 1e699e5e..d71d38b6 100755
--- a/org.fox.ttrss/src/main/java/org/fox/ttrss/offline/OfflineArticleFragment.java
+++ b/org.fox.ttrss/src/main/java/org/fox/ttrss/offline/OfflineArticleFragment.java
@@ -168,8 +168,8 @@ public class OfflineArticleFragment extends Fragment {
URL url = new URL(link.trim());
String uri = new URI(url.getProtocol(), url.getUserInfo(), url.getHost(),
url.getPort(), url.getPath(), url.getQuery(), url.getRef()).toString();
- Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
- startActivity(intent);
+
+ m_activity.openUri(Uri.parse(uri));
} catch (Exception e) {
e.printStackTrace();
m_activity.toast(R.string.error_other_error);
@@ -206,8 +206,8 @@ public class OfflineArticleFragment extends Fragment {
URL url = new URL(link.trim());
String uri = new URI(url.getProtocol(), url.getUserInfo(), url.getHost(),
url.getPort(), url.getPath(), url.getQuery(), url.getRef()).toString();
- Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
- startActivity(intent);
+
+ m_activity.openUri(Uri.parse(uri));
} catch (Exception e) {
e.printStackTrace();
m_activity.toast(R.string.error_other_error);
@@ -250,8 +250,7 @@ public class OfflineArticleFragment extends Fragment {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
try {
- Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
- startActivity(intent);
+ m_activity.openUri(Uri.parse(url));
return true;
diff --git a/org.fox.ttrss/src/main/res/anim/slide_in_left.xml b/org.fox.ttrss/src/main/res/anim/slide_in_left.xml
new file mode 100755
index 00000000..281da62a
--- /dev/null
+++ b/org.fox.ttrss/src/main/res/anim/slide_in_left.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/* //device/apps/common/res/anim/slide_in_left.xml
+**
+** Copyright 2007, Google Inc.
+**
+** 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.
+*/
+-->
+
+<set xmlns:android="http://schemas.android.com/apk/res/android">
+ <translate android:fromXDelta="-50%p" android:toXDelta="0" android:duration="200"/>
+ <alpha android:fromAlpha="0.0" android:toAlpha="1.0" android:duration="200" />
+</set> \ No newline at end of file
diff --git a/org.fox.ttrss/src/main/res/anim/slide_in_right.xml b/org.fox.ttrss/src/main/res/anim/slide_in_right.xml
new file mode 100755
index 00000000..6fbb8979
--- /dev/null
+++ b/org.fox.ttrss/src/main/res/anim/slide_in_right.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/* //device/apps/common/res/anim/slide_in_right.xml
+**
+** Copyright 2007, Google Inc.
+**
+** 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.
+*/
+-->
+
+<set xmlns:android="http://schemas.android.com/apk/res/android">
+ <translate android:fromXDelta="50%p" android:toXDelta="0" android:duration="200"/>
+ <alpha android:fromAlpha="0.0" android:toAlpha="1.0" android:duration="200" />
+</set> \ No newline at end of file
diff --git a/org.fox.ttrss/src/main/res/anim/slide_out_left.xml b/org.fox.ttrss/src/main/res/anim/slide_out_left.xml
new file mode 100755
index 00000000..b3adeaa6
--- /dev/null
+++ b/org.fox.ttrss/src/main/res/anim/slide_out_left.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/* //device/apps/common/res/anim/slide_out_left.xml
+**
+** Copyright 2007, Google Inc.
+**
+** 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.
+*/
+-->
+
+<set xmlns:android="http://schemas.android.com/apk/res/android">
+ <translate android:fromXDelta="0" android:toXDelta="-50%p" android:duration="200"/>
+ <alpha android:fromAlpha="1.0" android:toAlpha="0.0" android:duration="200" />
+</set> \ No newline at end of file
diff --git a/org.fox.ttrss/src/main/res/anim/slide_out_right.xml b/org.fox.ttrss/src/main/res/anim/slide_out_right.xml
new file mode 100755
index 00000000..30b5eba8
--- /dev/null
+++ b/org.fox.ttrss/src/main/res/anim/slide_out_right.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/* //device/apps/common/res/anim/slide_out_right.xml
+**
+** Copyright 2007, Google Inc.
+**
+** 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.
+*/
+-->
+
+<set xmlns:android="http://schemas.android.com/apk/res/android">
+ <translate android:fromXDelta="0" android:toXDelta="50%p" android:duration="200"/>
+ <alpha android:fromAlpha="1.0" android:toAlpha="0.0" android:duration="200" />
+</set> \ No newline at end of file