Merge pull request #4729 from volzhs/android-23

Supporting Android API 23 (Android 6.0)
This commit is contained in:
Rémi Verschelde 2016-06-07 09:45:24 +02:00
commit aed5474238
12 changed files with 51 additions and 158 deletions

View File

@ -200,6 +200,6 @@ $$ADD_PERMISSION_CHUNKS$$
<uses-permission android:name="godot.custom.18"/>
<uses-permission android:name="godot.custom.19"/>
<uses-sdk android:minSdkVersion="10" android:targetSdkVersion="19"/>
<uses-sdk android:minSdkVersion="10" android:targetSdkVersion="23"/>
</manifest>

View File

@ -3,7 +3,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.0'
classpath 'com.android.tools.build:gradle:1.3.1'
}
}
@ -17,7 +17,7 @@ allprojects {
}
dependencies {
compile 'com.android.support:support-v4:23.+' // can be removed if minSdkVersion 16 and modify DownloadNotification.java & V14CustomNotification.java
$$GRADLE_DEPENDENCIES$$
}
@ -25,10 +25,12 @@ android {
lintOptions {
abortOnError false
disable 'MissingTranslation'
}
compileSdkVersion 19
buildToolsVersion "19.1"
compileSdkVersion 23
buildToolsVersion "23.0.3"
useLibrary 'org.apache.http.legacy'
packagingOptions {
exclude 'META-INF/LICENSE'
@ -36,7 +38,7 @@ android {
}
defaultConfig {
minSdkVersion 14
targetSdkVersion 19
targetSdkVersion 23
}
sourceSets {
main {

View File

@ -80,7 +80,7 @@
</RelativeLayout>
<LinearLayout
android:id="@+id/downloaderDashboard"
android:id="@+id/downloadButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >

View File

@ -1,7 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="godot_project_name_string">godot-project-name-fa</string>
<string name="testuf8">سلام</string>
<string name="text_paused_cellular">آیا می خواهید بر روی اتصال داده همراه دانلود را شروع کنید؟ بر اساس نوع سطح داده شما این ممکن است برای شما هزینه مالی داشته باشد.</string>
<string name="text_paused_cellular_2">اگر نمی خواهید بر روی اتصال داده همراه دانلود را شروع کنید ، دانلود به صورت خودکار در زمان دسترسی به وای-فای شروع می شود.</string>
<string name="text_button_resume_cellular">ادامه دانلود</string>

View File

@ -146,11 +146,11 @@ public class LicenseChecker implements ServiceConnection {
if (mService == null) {
Log.i(TAG, "Binding to licensing service.");
try {
Intent serviceIntent = new Intent(new String(Base64.decode("Y29tLmFuZHJvaWQudmVuZGluZy5saWNlbnNpbmcuSUxpY2Vuc2luZ1NlcnZpY2U=")));
serviceIntent.setPackage("com.android.vending");
boolean bindResult = mContext
.bindService(
new Intent(
new String(
Base64.decode("Y29tLmFuZHJvaWQudmVuZGluZy5saWNlbnNpbmcuSUxpY2Vuc2luZ1NlcnZpY2U="))),
serviceIntent,
this, // ServiceConnection.
Context.BIND_AUTO_CREATE);

View File

@ -33,6 +33,10 @@ public class Constants {
public static final String EXP_PATH = File.separator + "Android"
+ File.separator + "obb" + File.separator;
// save to private app's data on Android 6.0 to skip requesting permission.
public static final String EXP_PATH_API23 = File.separator + "Android"
+ File.separator + "data" + File.separator;
/** The intent that gets sent when the service must wake up for a retry */
public static final String ACTION_RETRY = "android.intent.action.DOWNLOAD_WAKEUP";
@ -70,7 +74,7 @@ public class Constants {
* The number of times that the download manager will retry its network
* operations when no progress is happening before it gives up.
*/
public static final int MAX_RETRIES = 5;
public static final int MAX_RETRIES = 10;
/**
* The minimum amount of time that the download manager accepts for

View File

@ -19,6 +19,7 @@ package com.google.android.vending.expansion.downloader;
import com.godot.game.R;
import android.content.Context;
import android.os.Build;
import android.os.Environment;
import android.os.StatFs;
import android.os.SystemClock;
@ -220,8 +221,8 @@ public class Helpers {
static public String getSaveFilePath(Context c) {
File root = Environment.getExternalStorageDirectory();
String path = root.toString() + Constants.EXP_PATH + c.getPackageName();
return path;
String path = Build.VERSION.SDK_INT >= 23 ? Constants.EXP_PATH_API23 : Constants.EXP_PATH;
return root.toString() + path + c.getPackageName();
}
/**

View File

@ -25,6 +25,6 @@ public class CustomNotificationFactory {
if (android.os.Build.VERSION.SDK_INT > 13)
return new V14CustomNotification();
else
return new V3CustomNotification();
throw new RuntimeException();
}
}

View File

@ -27,6 +27,7 @@ import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.os.Messenger;
import android.support.v4.app.NotificationCompat;
/**
* This class handles displaying the notification associated with the download
@ -48,8 +49,9 @@ public class DownloadNotification implements IDownloaderClient {
private IDownloaderClient mClientProxy;
final ICustomNotification mCustomNotification;
private Notification mNotification;
private Notification mCurrentNotification;
// NotificationCompat.Builder is used to support API < 16. This can be changed to Notification.Builder if minimum API >= 16.
private NotificationCompat.Builder mNotificationBuilder;
private NotificationCompat.Builder mCurrentNotificationBuilder;
private CharSequence mLabel;
private String mCurrentText;
private PendingIntent mContentIntent;
@ -132,17 +134,14 @@ public class DownloadNotification implements IDownloaderClient {
}
mCurrentText = mContext.getString(stringDownloadID);
mCurrentTitle = mLabel.toString();
mCurrentNotification.tickerText = mLabel + ": " + mCurrentText;
mCurrentNotification.icon = iconResource;
mCurrentNotification.setLatestEventInfo(mContext, mCurrentTitle, mCurrentText,
mContentIntent);
if (ongoingEvent) {
mCurrentNotification.flags |= Notification.FLAG_ONGOING_EVENT;
} else {
mCurrentNotification.flags &= ~Notification.FLAG_ONGOING_EVENT;
mCurrentNotification.flags |= Notification.FLAG_AUTO_CANCEL;
}
mNotificationManager.notify(NOTIFICATION_ID, mCurrentNotification);
mCurrentNotificationBuilder.setTicker(mLabel + ": " + mCurrentText);
mCurrentNotificationBuilder.setSmallIcon(iconResource);
mCurrentNotificationBuilder.setContentTitle(mCurrentTitle);
mCurrentNotificationBuilder.setContentText(mCurrentText);
mCurrentNotificationBuilder.setContentIntent(mContentIntent);
mCurrentNotificationBuilder.setOngoing(ongoingEvent);
mCurrentNotificationBuilder.setAutoCancel(!ongoingEvent);
mNotificationManager.notify(NOTIFICATION_ID, mCurrentNotificationBuilder.build());
}
}
@ -154,10 +153,12 @@ public class DownloadNotification implements IDownloaderClient {
}
if (progress.mOverallTotal <= 0) {
// we just show the text
mNotification.tickerText = mCurrentTitle;
mNotification.icon = android.R.drawable.stat_sys_download;
mNotification.setLatestEventInfo(mContext, mLabel, mCurrentText, mContentIntent);
mCurrentNotification = mNotification;
mNotificationBuilder.setTicker(mCurrentTitle);
mNotificationBuilder.setSmallIcon(android.R.drawable.stat_sys_download);
mNotificationBuilder.setContentTitle(mCurrentTitle);
mNotificationBuilder.setContentText(mCurrentText);
mNotificationBuilder.setContentIntent(mContentIntent);
mCurrentNotificationBuilder = mNotificationBuilder;
} else {
mCustomNotification.setCurrentBytes(progress.mOverallProgress);
mCustomNotification.setTotalBytes(progress.mOverallTotal);
@ -166,9 +167,9 @@ public class DownloadNotification implements IDownloaderClient {
mCustomNotification.setTicker(mLabel + ": " + mCurrentText);
mCustomNotification.setTitle(mLabel);
mCustomNotification.setTimeRemaining(progress.mTimeRemaining);
mCurrentNotification = mCustomNotification.updateNotification(mContext);
mCurrentNotificationBuilder = mCustomNotification.updateNotification(mContext);
}
mNotificationManager.notify(NOTIFICATION_ID, mCurrentNotification);
mNotificationManager.notify(NOTIFICATION_ID, mCurrentNotificationBuilder.build());
}
public interface ICustomNotification {
@ -186,7 +187,7 @@ public class DownloadNotification implements IDownloaderClient {
void setTimeRemaining(long timeRemaining);
Notification updateNotification(Context c);
NotificationCompat.Builder updateNotification(Context c);
}
/**
@ -219,8 +220,8 @@ public class DownloadNotification implements IDownloaderClient {
mContext.getSystemService(Context.NOTIFICATION_SERVICE);
mCustomNotification = CustomNotificationFactory
.createCustomNotification();
mNotification = new Notification();
mCurrentNotification = mNotification;
mNotificationBuilder = new NotificationCompat.Builder(ctx);
mCurrentNotificationBuilder = mNotificationBuilder;
}

View File

@ -22,6 +22,7 @@ import com.google.android.vending.expansion.downloader.Helpers;
import android.app.Notification;
import android.app.PendingIntent;
import android.content.Context;
import android.support.v4.app.NotificationCompat;
public class V14CustomNotification implements DownloadNotification.ICustomNotification {
@ -53,13 +54,14 @@ public class V14CustomNotification implements DownloadNotification.ICustomNotifi
mCurrentKB = currentBytes;
}
void setProgress(Notification.Builder builder) {
void setProgress(NotificationCompat.Builder builder) {
}
@Override
public Notification updateNotification(Context c) {
Notification.Builder builder = new Notification.Builder(c);
public NotificationCompat.Builder updateNotification(Context c) {
// NotificationCompat.Builder is used to support API < 16. This can be changed to Notification.Builder if minimum API >= 16.
NotificationCompat.Builder builder = new NotificationCompat.Builder(c);
builder.setContentTitle(mTitle);
if (mTotalKB > 0 && -1 != mCurrentKB) {
builder.setProgress((int) (mTotalKB >> 8), (int) (mCurrentKB >> 8), false);
@ -80,7 +82,7 @@ public class V14CustomNotification implements DownloadNotification.ICustomNotifi
builder.setContentIntent(mPendingIntent);
builder.setOnlyAlertOnce(true);
return builder.getNotification();
return builder;
}
@Override

View File

@ -1,116 +0,0 @@
/*
* Copyright (C) 2012 The Android Open Source Project
*
* 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.google.android.vending.expansion.downloader.impl;
import com.godot.game.R;
import com.google.android.vending.expansion.downloader.Helpers;
import android.app.Notification;
import android.app.PendingIntent;
import android.content.Context;
import android.graphics.BitmapFactory;
import android.view.View;
import android.widget.RemoteViews;
public class V3CustomNotification implements DownloadNotification.ICustomNotification {
CharSequence mTitle;
CharSequence mTicker;
int mIcon;
long mTotalBytes = -1;
long mCurrentBytes = -1;
long mTimeRemaining;
PendingIntent mPendingIntent;
Notification mNotification = new Notification();
@Override
public void setIcon(int icon) {
mIcon = icon;
}
@Override
public void setTitle(CharSequence title) {
mTitle = title;
}
@Override
public void setTotalBytes(long totalBytes) {
mTotalBytes = totalBytes;
}
@Override
public void setCurrentBytes(long currentBytes) {
mCurrentBytes = currentBytes;
}
@Override
public Notification updateNotification(Context c) {
Notification n = mNotification;
n.icon = mIcon;
n.flags |= Notification.FLAG_ONGOING_EVENT;
if (android.os.Build.VERSION.SDK_INT > 10) {
n.flags |= Notification.FLAG_ONLY_ALERT_ONCE; // only matters for
// Honeycomb
}
// Build the RemoteView object
RemoteViews expandedView = new RemoteViews(
c.getPackageName(),
R.layout.status_bar_ongoing_event_progress_bar);
expandedView.setTextViewText(R.id.title, mTitle);
// look at strings
expandedView.setViewVisibility(R.id.description, View.VISIBLE);
expandedView.setTextViewText(R.id.description,
Helpers.getDownloadProgressString(mCurrentBytes, mTotalBytes));
expandedView.setViewVisibility(R.id.progress_bar_frame, View.VISIBLE);
expandedView.setProgressBar(R.id.progress_bar,
(int) (mTotalBytes >> 8),
(int) (mCurrentBytes >> 8),
mTotalBytes <= 0);
expandedView.setViewVisibility(R.id.time_remaining, View.VISIBLE);
expandedView.setTextViewText(
R.id.time_remaining,
c.getString(R.string.time_remaining_notification,
Helpers.getTimeRemaining(mTimeRemaining)));
expandedView.setTextViewText(R.id.progress_text,
Helpers.getDownloadProgressPercent(mCurrentBytes, mTotalBytes));
expandedView.setImageViewResource(R.id.appIcon, mIcon);
n.contentView = expandedView;
n.contentIntent = mPendingIntent;
return n;
}
@Override
public void setPendingIntent(PendingIntent contentIntent) {
mPendingIntent = contentIntent;
}
@Override
public void setTicker(CharSequence ticker) {
mTicker = ticker;
}
@Override
public void setTimeRemaining(long timeRemaining) {
mTimeRemaining = timeRemaining;
}
}

View File

@ -467,7 +467,7 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC
// Build the full path to the app's expansion files
try {
expansion_pack_path = Environment.getExternalStorageDirectory().toString() + "/Android/obb/"+this.getPackageName();
expansion_pack_path = Helpers.getSaveFilePath(getApplicationContext());
expansion_pack_path+="/"+"main."+getPackageManager().getPackageInfo(getPackageName(), 0).versionCode+"."+this.getPackageName()+".obb";
} catch (Exception e) {
e.printStackTrace();