Skip to content

Commit

Permalink
Minor changes + Casting permission for API level >= 28
Browse files Browse the repository at this point in the history
  • Loading branch information
obbimi committed Jan 17, 2019
1 parent 423d4d8 commit eb9391e
Show file tree
Hide file tree
Showing 11 changed files with 122 additions and 34 deletions.
4 changes: 2 additions & 2 deletions AndroidManifestCourtCare.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.doubleyellow.courtcaresquore"
android:versionCode="193"
android:versionName="4.13">
android:versionCode="210"
android:versionName="4.18">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
Expand Down
4 changes: 2 additions & 2 deletions AndroidManifestRacketlon.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.doubleyellow.racketlon"
android:versionCode="209"
android:versionName="4.17">
android:versionCode="210"
android:versionName="4.18">
<!--
<uses-feature android:name="android.permission.SEND_SMS" android:required="false" />
<uses-feature android:name="android.permission.INTERNET" android:required="true" />
Expand Down
7 changes: 5 additions & 2 deletions AndroidManifestSquore.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.doubleyellow.scoreboard"
android:versionCode="209"
android:versionName="4.17">
android:versionCode="210"
android:versionName="4.18">
<!--
<uses-feature android:name="android.permission.SEND_SMS" android:required="false" />
<uses-feature android:name="android.permission.INTERNET" android:required="true" />
Expand All @@ -20,6 +20,9 @@
<!-- for import/export functionality -->
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

<!-- android 9 casting -->
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" /> <!-- FOREGROUND_SERVICE is a normal permission, so the system automatically grants it to the requesting app. -->
<!--
<uses-feature android:name="android.permission.ACCESS_NETWORK_STATE" android:required="true" />
-->
Expand Down
13 changes: 8 additions & 5 deletions AndroidManifestTabletennis.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.doubleyellow.tabletennis"
android:versionCode="209"
android:versionName="4.17">
android:versionCode="210"
android:versionName="4.18">
<!--
<uses-feature android:name="android.permission.SEND_SMS" android:required="false" />
<uses-feature android:name="android.permission.INTERNET" android:required="true" />
Expand All @@ -20,9 +20,12 @@
<!-- for import/export functionality -->
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<!--
<uses-feature android:name="android.permission.ACCESS_NETWORK_STATE" android:required="true" />
-->

<!-- android 9 casting -->
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<!--
<uses-feature android:name="android.permission.ACCESS_NETWORK_STATE" android:required="true" />
-->
<uses-sdk/>

<supports-screens
Expand Down
4 changes: 2 additions & 2 deletions AndroidManifestUniOfNotthingham.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.doubleyellow.courtscore_uon"
android:versionCode="193"
android:versionName="4.13">
android:versionCode="210"
android:versionName="4.18">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
Expand Down
Binary file modified libs/AndroidBase.aar
Binary file not shown.
17 changes: 16 additions & 1 deletion src/com/doubleyellow/scoreboard/cast/CastHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ public class CastHelper

private static String APP_ID = null;

/** Always called by the app */
public void initCasting(Activity context) {
if (NOT_SUPPORTED_IN_SDK) { return; }

Expand All @@ -129,6 +130,17 @@ public void initCastMenu(Menu menu) {
mediaRouteMenuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
MediaRouteActionProvider mediaRouteActionProvider = (MediaRouteActionProvider) MenuItemCompat.getActionProvider(mediaRouteMenuItem);
mediaRouteActionProvider.setRouteSelector(mediaRouteSelector);
/*
mediaRouteMenuItem.setOnActionExpandListener(new MenuItem.OnActionExpandListener() {
@Override public boolean onMenuItemActionExpand(MenuItem item) {
return false;
}
@Override public boolean onMenuItemActionCollapse(MenuItem item) {
return false;
}
});
*/
}
public void startCast() {
if (NOT_SUPPORTED_IN_SDK) { return; }
Expand Down Expand Up @@ -171,9 +183,12 @@ private static class MediaRouterCallback extends android.support.v7.media.MediaR
private MediaRouterCallback(Activity context) {
this.context = context;
}

/** Invoked as soon as a cast device is selected from the menu */
@Override public void onRouteSelected(MediaRouter router, MediaRouter.RouteInfo route) {
Log.d(TAG, "Route selected :" + route.getName());
if ( RWValues.Permission.Granted.equals(PreferenceValues.doesUserHavePermissionToCast(context, route.getName(), true)) == false ) {
return;
}
GoogleApiAvailability instance = GoogleApiAvailability.getInstance(); // e.g. Living or Court 1. If e.g. Netflix is playing on the device: mDescription=Netflix
int iResult = instance.isGooglePlayServicesAvailable(context);
switch (iResult) {
Expand Down
5 changes: 5 additions & 0 deletions src/com/doubleyellow/scoreboard/feed/FeedKeys.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

import com.doubleyellow.scoreboard.Brand;

import java.util.Locale;

enum FeedKeys {
FeedMetaData,
/** array with sequence in with to present the feed types */
Expand All @@ -38,4 +40,7 @@ public String getBrandSuffixed() {
public String getLangSuffixed(String sLang) {
return this.toString() + "-" + sLang;
}
public String getLocalSuffixed(Locale locale) {
return this.toString() + "-" + locale.toString();
}
}
48 changes: 46 additions & 2 deletions src/com/doubleyellow/scoreboard/feed/ShowTypesAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,13 @@
package com.doubleyellow.scoreboard.feed;

import android.content.Context;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.LocaleList;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
Expand All @@ -47,6 +51,7 @@
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;

class ShowTypesAdapter extends BaseAdapter implements ContentReceiver
{
Expand Down Expand Up @@ -298,8 +303,39 @@ private void fillWithRootEntries(String sContent) {
}
}

// for earlier selected 'Types', place them on top of the list
List<String> lMyFeedTypes = PreferenceValues.getUsedFeedTypes(context);
// if defined for users locale, add certain types to top
List<String> lLocaleFeedTypes = new ArrayList<>();
{
List<Locale> lLocales = new ArrayList<>(); // most important FIRST
{
Resources res = context.getResources();
Configuration resCfg = res.getConfiguration();
if ( Build.VERSION.SDK_INT >= Build.VERSION_CODES.N /* 24 */ ) {
LocaleList locales = resCfg.getLocales();
if ( locales.isEmpty() == false ) {
for(int i=0; i<locales.size();i++) {
lLocales.add(locales.get(i));
}
}
} else {
Locale deviceLocale = RWValues.getDeviceLocale(context);
lLocales.add(deviceLocale);
}
}
if ( ListUtil.isNotEmpty(lLocales) ) {
for ( Locale locale : lLocales ) {
String[] saKeys = new String[] { FeedKeys.Sequence.getLocalSuffixed(locale), FeedKeys.Sequence.getLangSuffixed(locale.getLanguage()), FeedKeys.Sequence.getLangSuffixed(locale.getCountry()) };
for( String sKey :saKeys ) {
JSONArray typesLocale = joMetaData.optJSONArray(sKey);
if ( JsonUtil.isNotEmpty(typesLocale) ) {
List<String> lTmp = JsonUtil.asListOfStrings(typesLocale);
lTmp.removeAll(lLocaleFeedTypes);
lLocaleFeedTypes.addAll(lTmp);
}
}
}
}
}

try {
for ( int i=0; i < JsonUtil.size(types); i++ ) {
Expand All @@ -311,6 +347,14 @@ private void fillWithRootEntries(String sContent) {
String sUrl = PreferenceValues.getFeedsFeedURL(context);
//TODO: show some message about the url that does not work
}
// if, based on device locale, some feeds are more useful to the user, add them to the top
if ( ListUtil.isNotEmpty(lLocaleFeedTypes) ) {
lLocaleFeedTypes.retainAll(lKeys);
lKeys.removeAll(lLocaleFeedTypes);
lKeys.addAll(0, lLocaleFeedTypes);
}
// for earlier selected 'Types', place them on top of the list
List<String> lMyFeedTypes = PreferenceValues.getUsedFeedTypes(context);
if ( ListUtil.isNotEmpty(lMyFeedTypes) ) {
lMyFeedTypes.retainAll(lKeys);
lKeys.removeAll(lMyFeedTypes);
Expand Down
36 changes: 20 additions & 16 deletions src/com/doubleyellow/scoreboard/main/ScoreBoard.java
Original file line number Diff line number Diff line change
Expand Up @@ -834,8 +834,8 @@ private void addItem(int iActionId, int iCaptionId, int iImageId) {
//-------------------------------------------------------------------------

public static ToggleResult bUseActionBar = ToggleResult.nothing;
private boolean bHapticFeedbackPerPoint = false;
private boolean bHapticFeedbackOnGameEnd = false;
private boolean m_bHapticFeedbackPerPoint = false;
private boolean m_bHapticFeedbackOnGameEnd = false;

/** onCreate() is followed by onstart() onresume(). Also called after orientation change */
@Override public void onCreate(Bundle savedInstanceState) {
Expand Down Expand Up @@ -974,8 +974,8 @@ private void addItem(int iActionId, int iCaptionId, int iImageId) {
layout.setOnTouchListener(new TouchBothListener(clickBothListener, longClickBothListener));
}

bHapticFeedbackPerPoint = PreferenceValues.hapticFeedbackPerPoint(ScoreBoard.this);
bHapticFeedbackOnGameEnd = PreferenceValues.hapticFeedbackOnGameEnd(ScoreBoard.this);
m_bHapticFeedbackPerPoint = PreferenceValues.hapticFeedbackPerPoint(ScoreBoard.this);
m_bHapticFeedbackOnGameEnd = PreferenceValues.hapticFeedbackOnGameEnd(ScoreBoard.this);

initColors();
initCountries();
Expand Down Expand Up @@ -1030,9 +1030,9 @@ private void initCountryList() {

updateDemoThread(this);

bHapticFeedbackPerPoint = PreferenceValues.hapticFeedbackPerPoint(this);
bHapticFeedbackOnGameEnd = PreferenceValues.hapticFeedbackOnGameEnd(this);
m_liveScoreShare = PreferenceValues.isConfiguredForLiveScore(this);
m_bHapticFeedbackPerPoint = PreferenceValues.hapticFeedbackPerPoint(this);
m_bHapticFeedbackOnGameEnd = PreferenceValues.hapticFeedbackOnGameEnd(this);
m_liveScoreShare = PreferenceValues.isConfiguredForLiveScore(this);

updateMicrophoneFloatButton();
updateTimerFloatButton();
Expand Down Expand Up @@ -2459,7 +2459,7 @@ private class SpecialScoreChangeListener implements Model.OnSpecialScoreChangeLi
}
@Override public void OnGameEndReached(Player leadingPlayer) {
if ( bInitializingModelListeners ) { return; }
if ( bHapticFeedbackOnGameEnd ) {
if ( m_bHapticFeedbackOnGameEnd ) {
SystemUtil.doVibrate(ScoreBoard.this, 800);
}
updateMicrophoneFloatButton();
Expand Down Expand Up @@ -2531,8 +2531,7 @@ private class SpecialScoreChangeListener implements Model.OnSpecialScoreChangeLi
}

@Override public void OnFirstPointOfGame() {
ShareMatchPrefs liveScoreShare = PreferenceValues.isConfiguredForLiveScore(ScoreBoard.this);
if ( matchModel.getGameNrInProgress()==1 && ShareMatchPrefs.LinkWithFullDetailsEachHalf.equals(liveScoreShare) ) {
if ( matchModel.getGameNrInProgress()==1 && ShareMatchPrefs.LinkWithFullDetailsEachHalf.equals(m_liveScoreShare) ) {
// share if livescoring is 'Semi-On' to let the match appear in the list a.s.a.p.
shareScoreSheet(ScoreBoard.this, matchModel, false);
}
Expand Down Expand Up @@ -2560,7 +2559,7 @@ private class SpecialScoreChangeListener implements Model.OnSpecialScoreChangeLi
private class ScoreChangeListener implements Model.OnScoreChangeListener
{
@Override public void OnScoreChange(Player p, int iTotal, int iDelta, Call call) {
if ( bHapticFeedbackPerPoint ) {
if ( m_bHapticFeedbackPerPoint ) {
int lDuration = iDelta == 1 ? 200 : 500;
SystemUtil.doVibrate(ScoreBoard.this, lDuration);
}
Expand Down Expand Up @@ -2588,8 +2587,7 @@ private class ScoreChangeListener implements Model.OnScoreChangeListener
}
}

ShareMatchPrefs liveScoreShare = PreferenceValues.isConfiguredForLiveScore(ScoreBoard.this);
if ( (bInitializingModelListeners == false) && (iTotal != 0) && ShareMatchPrefs.LinkWithFullDetailsEachPoint.equals(liveScoreShare) && (matchModel.isLocked() == false) ) {
if ( (bInitializingModelListeners == false) && (iTotal != 0) && ShareMatchPrefs.LinkWithFullDetailsEachPoint.equals(m_liveScoreShare) && (matchModel.isLocked() == false) ) {
//shareScoreSheet(ScoreBoard.this, matchModel, false);
// start timer to post in e.g. 2 seconds. Restart this timer as soon as another point is scored
shareScoreSheetDelayed(2000);
Expand Down Expand Up @@ -2676,7 +2674,7 @@ private class ServeSideChangeListener implements Model.OnServeSideChangeListener

private class GameEndListener implements Model.OnGameEndListener {
@Override public void OnGameEnded(Player winningPlayer) {
if ( bHapticFeedbackOnGameEnd ) {
if ( m_bHapticFeedbackOnGameEnd ) {
SystemUtil.doVibrate(ScoreBoard.this, 200);
}
if ( EnumSet.of(ShareMatchPrefs.LinkWithFullDetailsEachGame, ShareMatchPrefs.LinkWithFullDetailsEachHalf).contains(m_liveScoreShare) ) {
Expand Down Expand Up @@ -3794,8 +3792,7 @@ private void showTimer(Type timerType, boolean bAutoTriggered) {
addToDialogStack(twoTimerView);

// ensure the match shows up in the list of live score a.s.a.p. so e.g. when warmup timer is started
ShareMatchPrefs liveScoreShare = PreferenceValues.isConfiguredForLiveScore(ScoreBoard.this);
if ( ( matchModel.hasStarted() == false ) && ShareMatchPrefs.LinkWithFullDetailsEachPoint.equals(liveScoreShare) && (matchModel.isLocked() == false) ) {
if ( ( matchModel.hasStarted() == false ) && ShareMatchPrefs.LinkWithFullDetailsEachPoint.equals(m_liveScoreShare) && (matchModel.isLocked() == false) ) {
shareScoreSheetDelayed(1000);
}
}
Expand Down Expand Up @@ -3882,6 +3879,12 @@ private void autoShowTossDialog() {
private boolean _showWhoServesDialog() {
ServerToss serverToss = new ServerToss(this, matchModel, this);
addToDialogStack(serverToss);

// ensure the match shows up in the list of live score a.s.a.p. so e.g. when toss dialog is started
if ( ( matchModel.hasStarted() == false ) && ShareMatchPrefs.LinkWithFullDetailsEachPoint.equals(m_liveScoreShare) && (matchModel.isLocked() == false) ) {
shareScoreSheetDelayed(1000);
}

return true;
}

Expand Down Expand Up @@ -5214,6 +5217,7 @@ private void initCasting(Activity context) {
}
private void initCastMenu(Menu menu) {
castHelper.initCastMenu(menu);
PreferenceValues.doesUserHavePermissionToCast(this, "Any device", true);
}
private void setModelForCast(Model matchModel) {
castHelper.setModelForCast(matchModel);
Expand Down
18 changes: 16 additions & 2 deletions src/com/doubleyellow/scoreboard/prefs/PreferenceValues.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import android.content.res.Resources;
import android.database.Cursor;
import android.graphics.Color;
import android.os.Build;
import android.os.Environment;
import android.preference.*;
import android.provider.ContactsContract;
Expand Down Expand Up @@ -1564,8 +1565,8 @@ public static StartupAction getStartupAction(Context context) {
// very first install/run

int appVersionCode = RWValues.getAppVersionCode(context);
final int NO_SHOWCASE_FOR_VERSION = 209;
final String NO_SHOWCASE_FOR_VERSION_BEFORE = "2019-01-05";
final int NO_SHOWCASE_FOR_VERSION = 210;
final String NO_SHOWCASE_FOR_VERSION_BEFORE = "2019-01-19";
if ( appVersionCode > NO_SHOWCASE_FOR_VERSION ) {
// need to adjust the datecheck below
Log.w(TAG, "[getStartupAction] Adjust version code check!!");
Expand Down Expand Up @@ -1919,6 +1920,19 @@ private static List<String> getContactsFromGroup(Context context, long iGroupId
// Permissions
//-------------------------------------------------------------

public static Permission doesUserHavePermissionToCast(Context context, String sCastDeviceName, boolean bRequestIfRequired) {
Permission permission;
if ( Build.VERSION.SDK_INT < Build.VERSION_CODES.P /* = 28 */ ) {
permission = Permission.Granted;
} else {
permission = requestPermission(context, PreferenceKeys.Cast_ShowGraphDuringTimer, Manifest.permission.FOREGROUND_SERVICE, bRequestIfRequired);
}

if ( RWValues.Permission.Granted.equals(permission) == false ) {
Toast.makeText(context, "Need foreground permission for casting to work on " + sCastDeviceName, Toast.LENGTH_LONG).show();
}
return permission;
}
static Permission doesUserHavePermissionToReadContacts(Context context, boolean bRequestIfRequired) {
return requestPermission(context, PreferenceKeys.readContactsForAutoCompletion, Manifest.permission.READ_CONTACTS, bRequestIfRequired);
}
Expand Down

0 comments on commit eb9391e

Please sign in to comment.