Commit 171a60f4 authored by David Papazian's avatar David Papazian

Set drive to use uploaded extension api

parent b3880c6d
driveplugin
\ No newline at end of file
......@@ -2,9 +2,9 @@
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/api/api.iml" filepath="$PROJECT_DIR$/api/api.iml" />
<module fileurl="file://$PROJECT_DIR$/driveplugin.iml" filepath="$PROJECT_DIR$/driveplugin.iml" />
<module fileurl="file://$PROJECT_DIR$/mobile/mobile.iml" filepath="$PROJECT_DIR$/mobile/mobile.iml" />
<module fileurl="file://$PROJECT_DIR$/vlc-android-drive.iml" filepath="$PROJECT_DIR$/vlc-android-drive.iml" />
</modules>
</component>
</project>
\ No newline at end of file
/*
* *************************************************************************
* build.gradle.java
* **************************************************************************
* Copyright © 2015 VLC authors and VideoLAN
* Author: Geoffrey Métais
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
* ***************************************************************************
*/
apply plugin: 'com.android.library'
android {
compileSdkVersion 23
buildToolsVersion '23.0.2'
defaultConfig {
minSdkVersion 8
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
}
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /home/dekans/SDK/android-sdk-linux/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# Add any project specific keep options here:
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
/*
* *************************************************************************
* ApplicationTest.java
* **************************************************************************
* Copyright © 2015 VLC authors and VideoLAN
* Author: Geoffrey Métais
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
* ***************************************************************************
*/
package org.videolan.vlc.extensions.api;
import android.app.Application;
import android.test.ApplicationTestCase;
/**
* <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a>
*/
public class ApplicationTest extends ApplicationTestCase<Application> {
public ApplicationTest() {
super(Application.class);
}
}
\ No newline at end of file
<!--
~ **************************************************************************
~ AndroidManifest.xml.java
~ ***************************************************************************
~ Copyright © 2015 VLC authors and VideoLAN
~ Author: Geoffrey Métais
~
~ This program is free software; you can redistribute it and/or modify
~ it under the terms of the GNU General Public License as published by
~ the Free Software Foundation; either version 2 of the License, or
~ (at your option) any later version.
~
~ This program is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
~ GNU General Public License for more details.
~
~ You should have received a copy of the GNU General Public License
~ along with this program; if not, write to the Free Software
~ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
~ ***************************************************************************
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.videolan.vlc.plugin.api">
<application android:allowBackup="true" android:label="@string/app_name"
android:supportsRtl="true">
</application>
</manifest>
package org.videolan.vlc.extensions.api;
import org.videolan.vlc.extensions.api.VLCExtensionItem;
import android.net.Uri;
interface IExtensionHost {
// Protocol version 1
oneway void updateList(in String title, in List<VLCExtensionItem> items, boolean showParams);
oneway void playUri(in Uri uri, String title);
oneway void unBind(int index);
}
package org.videolan.vlc.extensions.api;
import org.videolan.vlc.extensions.api.IExtensionHost;
import org.videolan.vlc.extensions.api.VLCExtensionItem;
interface IExtensionService {
// Protocol version 1
oneway void onInitialize(int index, in IExtensionHost host);
oneway void browse(int intId, String stringId); // longId?
oneway void refresh();
}
package org.videolan.vlc.extensions.api;
parcelable VLCExtensionItem;
/*
* *************************************************************************
* VLCExtensionItem.java
* **************************************************************************
* Copyright © 2015 VLC authors and VideoLAN
* Author: Geoffrey Métais
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
* ***************************************************************************
*/
package org.videolan.vlc.extensions.api;
import android.os.Parcel;
import android.os.Parcelable;
public class VLCExtensionItem implements Parcelable {
public static final int TYPE_DIRECTORY = 0;
public static final int TYPE_VIDEO = 1;
public static final int TYPE_AUDIO = 2;
public static final int TYPE_PLAYLIST = 3;
public static final int TYPE_SUBTITLE = 4;
public static final int TYPE_OTHER_FILE = 5;
public String stringId;
public int intId;
public String link;
public String title;
public String subTitle;
//TODO choose how to deal with icons
public String imageLink; // for content provider
public int type; // Using VLC icons. maybe with iconRes?
public VLCExtensionItem(String stringId, int intId, String link, String title, String subTitle, String imageLink, int type) {
this.stringId = stringId;
this.intId = intId;
this.link = link;
this.title = title;
this.subTitle = subTitle;
this.imageLink = imageLink;
this.type = type;
}
public VLCExtensionItem() {
}
private VLCExtensionItem(Parcel in) {
readFromParcel(in);
}
public static final Parcelable.Creator<VLCExtensionItem> CREATOR = new
Parcelable.Creator<VLCExtensionItem>() {
public VLCExtensionItem createFromParcel(Parcel in) {
return new VLCExtensionItem(in);
}
public VLCExtensionItem[] newArray(int size) {
return new VLCExtensionItem[size];
}
};
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(stringId);
dest.writeInt(intId);
dest.writeString(link);
dest.writeString(title);
dest.writeString(subTitle);
dest.writeString(imageLink);
dest.writeInt(type);
}
public void readFromParcel(Parcel in) {
stringId = in.readString();
intId = in.readInt();
link = in.readString();
title = in.readString();
subTitle = in.readString();
imageLink = in.readString();
type = in.readInt();
}
}
package org.videolan.vlc.extensions.api;
import android.app.Service;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.IBinder;
import android.os.Looper;
import android.os.RemoteException;
import android.support.annotation.Nullable;
import java.util.List;
public abstract class VLCExtensionService extends Service{
private static final String TAG = "VLC/ExtensionService";
private int mIndex = -1;
private static final ComponentName VLC_HOST_SERVICE =
new ComponentName("org.videolan.vlc",
"org.videolan.vlc.plugin.PluginService");
IExtensionHost mHost;
Context mContext = this;
private volatile Looper mServiceLooper;
protected volatile Handler mServiceHandler;
protected abstract void browse(int intId, String stringId);
protected abstract void refresh();
@Override
public void onCreate() {
super.onCreate();
HandlerThread thread = new HandlerThread(
"VLCExtension:" + getClass().getSimpleName());
thread.start();
mServiceLooper = thread.getLooper();
mServiceHandler = new Handler(mServiceLooper);
}
@Nullable
@Override
public IBinder onBind(Intent intent) {
return mBinder;
}
@Override
public void onDestroy() {
super.onDestroy();
try {
mHost.unBind(mIndex);
} catch (RemoteException e) {}
mServiceHandler.removeCallbacksAndMessages(null); // remove all callbacks
mServiceLooper.quit();
}
public void playUri(Uri uri, String title) {
try {
mHost.playUri(uri, title);
} catch (RemoteException e) {
e.printStackTrace();
}
}
protected void updateList(String title, List<VLCExtensionItem> items, boolean showParams){
try {
mHost.updateList(title, items, showParams);
} catch (RemoteException e) {
e.printStackTrace();
}
}
protected void onInitialize() {};
private final IExtensionService.Stub mBinder = new IExtensionService.Stub() {
@Override
public void onInitialize(int index, IExtensionHost host) throws RemoteException {
mIndex = index;
mHost = host;
mServiceHandler.post(new Runnable() {
@Override
public void run() {
VLCExtensionService.this.onInitialize();
}
});
}
@Override
public void browse(final int id, final String text) throws RemoteException {
mServiceHandler.post(new Runnable() {
@Override
public void run() {
VLCExtensionService.this.browse(id, text);
}
});
}
@Override
public void refresh() {
mServiceHandler.post(new Runnable() {
@Override
public void run() {
VLCExtensionService.this.refresh();
}
});
}
};
}
package org.videolan.vlc.extensions.api.tools;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.provider.Settings;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.app.AlertDialog;
import org.videolan.vlc.plugin.api.R;
public class Dialogs {
public static AlertDialog showAlertDialog(@NonNull Context context, @NonNull int title,
@NonNull int message,
@Nullable DialogInterface.OnCancelListener cancelListener) {
return showAlertDialog(context, title, message, cancelListener, null, null);
}
public static AlertDialog showAlertDialog(@NonNull Context context, @NonNull int title,
@NonNull int message,
@Nullable DialogInterface.OnCancelListener cancelListener,
@Nullable DialogInterface.OnClickListener positiveAction,
@Nullable DialogInterface.OnClickListener negativeAction) {
AlertDialog.Builder builder = new AlertDialog.Builder(context)
.setMessage(message)
.setTitle(title);
if (cancelListener != null) {
builder.setCancelable(true)
.setOnCancelListener(cancelListener);
}
if (positiveAction != null) {
builder.setPositiveButton(android.R.string.ok, positiveAction);
}
if (negativeAction != null) {
builder.setPositiveButton(android.R.string.cancel, negativeAction);
}
AlertDialog alert = builder.create();
alert.show();
return alert;
}
/**
*
* @param context The context to use for Dialog display
* @param cancelListener The listener wich will be triggered after dialog cancelation or positive action
* @return the AlertDialog instance
*/
public static AlertDialog showNetworkNeeded(@NonNull final Context context,
@NonNull final DialogInterface.OnCancelListener cancelListener) {
return showAlertDialog(context, R.string.network_error_title, R.string.network_error_message,
cancelListener, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
context.startActivity(new Intent(Settings.ACTION_WIFI_SETTINGS));
dialog.cancel();
}
}, null);
}
}
<!--
~ **************************************************************************
~ strings.xml.java
~ ***************************************************************************
~ Copyright © 2015 VLC authors and VideoLAN
~ Author: Geoffrey Métais
~
~ This program is free software; you can redistribute it and/or modify
~ it under the terms of the GNU General Public License as published by
~ the Free Software Foundation; either version 2 of the License, or
~ (at your option) any later version.
~
~ This program is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
~ GNU General Public License for more details.
~
~ You should have received a copy of the GNU General Public License
~ along with this program; if not, write to the Free Software
~ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
~ ***************************************************************************
-->
<resources>
<string name="app_name">Plugin API</string>
<string name="network_error_title">No Internet connection</string>
<string name="network_error_message">This extension needs your device to be connected to internet</string>
</resources>
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="TransparentTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:background">@android:color/transparent</item>
<item name="background">@android:color/transparent</item>
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:colorBackgroundCacheHint">@android:color/transparent</item>
<item name="android:windowContentOverlay">@android:color/transparent</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowAnimationStyle">@android:color/transparent</item>
</style>
</resources>
\ No newline at end of file
/*
* *************************************************************************
* ExampleUnitTest.java
* **************************************************************************
* Copyright © 2015 VLC authors and VideoLAN
* Author: Geoffrey Métais
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
* ***************************************************************************
*/
package org.videolan.vlc.extensions.api;
import org.junit.Test;
import static org.junit.Assert.*;
/**
* To work on unit tests, switch the Test Artifact in the Build Variants view.
*/
public class ExampleUnitTest {
@Test
public void addition_isCorrect() throws Exception {
assertEquals(4, 2 + 2);
}
}
\ No newline at end of file
......@@ -5,7 +5,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.5.0'
classpath 'com.android.tools.build:gradle:2.3.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
......@@ -15,6 +15,9 @@ buildscript {
allprojects {
repositories {
jcenter()
maven {
url 'https://dl.bintray.com/davidpapazian2/maven/'
}
}
}
......
#Fri Dec 11 13:48:23 CET 2015
#Wed Jul 26 10:21:09 CEST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.8-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion '23.0.2'
compileSdkVersion 26
buildToolsVersion '26.0.1'
defaultConfig {
applicationId "org.videolan.driveplugin"
minSdkVersion 9
targetSdkVersion 22
targetSdkVersion 26
versionCode 1
versionName "1.0"
}
......@@ -22,8 +22,8 @@ android {
dependencies {
// compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
compile 'com.android.support:appcompat-v7:25.2.0'
compile 'com.android.support:design:25.2.0'
compile 'com.google.android.gms:play-services-drive:8.3.0'
compile 'com.google.android.gms:play-services-plus:8.3.0'
compile('com.google.api-client:google-api-client-android:1.20.0') {
......@@ -32,5 +32,5 @@ dependencies {
compile('com.google.apis:google-api-services-drive:v2-rev170-1.20.0') {
exclude group: 'org.apache.httpcomponents'
}
compile project(':api')
compile 'davidpapazian:api:0.3'
}
package org.videolan.driveplugin;
import android.accounts.Account;
import android.app.Application;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
......@@ -14,6 +15,7 @@ public class DriveApplication extends Application {
private ExtensionService mService;
private String mToken;
private String mEmail;
private Account mAccount;
private SharedPreferences mSettings;
@Override
......@@ -41,6 +43,14 @@ public class DriveApplication extends Application {
mSettings.edit().putString(DriveApplication.EMAIL_KEY, mEmail).apply();
}
public void setAccount(Account account){
mAccount = account;
}
public Account getAccount() {
return mAccount;
}
public String getToken(){
return mToken;
......
......@@ -17,13 +17,13 @@ public class ExtensionService extends VLCExtensionService {
@Override
protected void browse(int intId, String stringId) {
protected void browse(String stringId) {
startActivity(new Intent(this, LoginActivity.class).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
}
@Override
protected void onInitialize() {
browse(0, null);
browse(null);
}
@Override
......
package org.videolan.driveplugin;
import android.Manifest;
import android.accounts.AccountManager;
import android.content.ActivityNotFoundException;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentSender;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.util.Log;
......@@ -38,14 +43,24 @@ public class LoginActivity extends AppCompatActivity implements GoogleApiClient.
private GoogleApiClient mGoogleApiClient;
private String mToken;
private String mEmail;
private android.accounts.Account mAccount;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mApplication = (DriveApplication) getApplication();
mEmail = mApplication.getAccountName();
if (!TextUtils.isEmpty(mEmail))
getAccessToken();
mAccount = mApplication.getAccount();
mToken = mApplication.getToken();
}
@Override
protected void onStart() {
super.onStart();
if (!TextUtils.isEmpty(mToken))
connect();
else if (!TextUtils.isEmpty(mEmail))
checkPermission();
else
pickUserAccount();
}
......@@ -62,15 +77,55 @@ public class LoginActivity extends AppCompatActivity implements GoogleApiClient.
mApplication.setGoogleApiClient(mGoogleApiClient);
}
private void checkPermission() {
int permissionCheck = ContextCompat.checkSelfPermission(this, Manifest.permission.GET_ACCOUNTS);
if (permissionCheck == PackageManager.PERMISSION_GRANTED) {