Commit 3186eddf authored by はあ's avatar はあ
Browse files

Update bin/cloudbrowser/android/src/org/videolan/cloudbrowser/FileOutput.java

Deleted bin/cloudbrowser/android/src/org/videolan/cloudbrowser/AuthView.java, bin/cloudbrowser/android/src/org/videolan/cloudbrowser/CloudBrowser.java, bin/cloudbrowser/android/src/org/videolan/cloudbrowser/FileInput.java, bin/cloudbrowser/android/src/org/videolan/cloudbrowser/NotificationHelper.java, bin/cloudbrowser/android/src/org/videolan/cloudbrowser/NotificationService.java, bin/cloudbrowser/android/src/org/videolan/cloudbrowser/Utility.java files
parent d595d474
package org.videolan.cloudbrowser;
import android.app.Activity;
import android.os.Bundle;
import android.net.Uri;
import android.content.Intent;
public class AuthView extends Activity {
private boolean m_intent_run = false;
public static AuthView m_current;
@Override
protected void onResume() {
super.onResume();
Bundle intent_extras = getIntent().getExtras();
CharSequence sequence = intent_extras == null ?
null : intent_extras.getCharSequence("address");
String url = sequence == null ? null : sequence.toString();
m_current = this;
if (!m_intent_run) {
m_intent_run = true;
if (url != null) {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
Bundle extras = new Bundle();
extras.putBinder("android.support.customtabs.extra.SESSION", null);
intent.putExtras(extras);
setTitle("Cloud Browser Consent Screen");
startActivity(intent);
}
} else {
finish();
}
}
}
package org.videolan.cloudbrowser;
import android.os.Bundle;
import android.content.Intent;
import android.content.res.Configuration;
import android.view.WindowManager;
import android.database.Cursor;
import android.provider.OpenableColumns;
import android.net.Uri;
import android.content.pm.ActivityInfo;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import org.qtproject.qt5.android.bindings.QtActivity;
import com.google.android.gms.ads.MobileAds;
import com.google.android.gms.ads.AdView;
import com.google.android.gms.ads.AdSize;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdListener;
public class CloudBrowser extends QtActivity {
private NotificationHelper m_notification_helper;
private ViewGroup m_view_group;
private RelativeLayout m_ad_view;
private boolean m_ad_view_visible = false;
private void updateAdView() {
if (m_ad_view != null && m_view_group != null)
m_view_group.removeView(m_ad_view);
if (!m_ad_view_visible) return;
final AdView ad = new AdView(this);
ad.setAdUnitId("ca-app-pub-9966958697007244/9093813086");
ad.setAdSize(new AdSize(AdSize.FULL_WIDTH, 50));
ad.setAdListener(new AdListener() {
private boolean m_loaded;
public void attach() {
if (!m_loaded && m_ad_view_visible) {
m_loaded = true;
m_ad_view = new RelativeLayout(CloudBrowser.this);
RelativeLayout.LayoutParams ad_layout_params =
new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.FILL_PARENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
ad_layout_params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
m_ad_view.addView(ad, ad_layout_params);
m_view_group.addView(m_ad_view, new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.FILL_PARENT,
RelativeLayout.LayoutParams.FILL_PARENT));
}
}
public void onAdLoaded() {
runOnUiThread(new Runnable() {
public void run() {
Utility.onActionRequested("SHOW_AD");
attach();
}
});
}
public void onAdFailedToLoad(int error) {
Utility.onActionRequested("HIDE_AD");
}
});
ad.loadAd(new AdRequest.Builder().build());
}
@Override
public void onCreate(Bundle state) {
super.onCreate(state);
m_notification_helper = new NotificationHelper(this);
MobileAds.initialize(this, "ca-app-pub-9966958697007244~3913638593");
View view = getWindow().getDecorView().getRootView();
if (view instanceof ViewGroup) {
m_view_group = (ViewGroup) view;
updateAdView();
}
}
@Override
public void onConfigurationChanged(Configuration config) {
super.onConfigurationChanged(config);
updateAdView();
}
@Override
public void onActivityResult(int request, int result, Intent data) {
super.onActivityResult(request, result, data);
Utility.onRequestResult(request, result, data);
}
@Override
public void onDestroy() {
m_notification_helper.release();
super.onDestroy();
}
public void showAd() {
runOnUiThread(new Runnable() {
public void run() {
m_ad_view_visible = true;
updateAdView();
}
});
}
public void hideAd() {
runOnUiThread(new Runnable() {
public void run() {
m_ad_view_visible = false;
if (m_ad_view != null)
m_ad_view.setVisibility(View.INVISIBLE);
}
});
}
public void setDefaultOrientation() {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
}
public void setLandScapeOrientation() {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}
public void enableKeepScreenOn() {
runOnUiThread(new Runnable() {
public void run() {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
}
});
}
public void disableKeepScreenOn() {
runOnUiThread(new Runnable() {
public void run() {
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
}
});
}
public Intent openWebPage(String url) {
Intent intent = new Intent(this, AuthView.class);
intent.putExtra("address", url);
return intent;
}
public void closeWebPage(Intent i) {
if (AuthView.m_current != null) {
Intent intent = new Intent(this, AuthView.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
AuthView.m_current.startActivity(intent);
AuthView.m_current.finish();
AuthView.m_current = null;
}
}
public NotificationHelper notification() {
return m_notification_helper;
}
public String filename(Uri uri) {
Cursor cursor = getContentResolver().
query(uri, null, null, null, null, null);
String result = "";
try {
if (cursor != null && cursor.moveToFirst())
result = cursor.getString(
cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME));
} finally {
cursor.close();
}
return result;
}
}
package org.videolan.cloudbrowser;
import android.os.ParcelFileDescriptor;
import android.content.Context;
import java.io.FileInputStream;
import java.io.IOException;
public class FileInput {
private ParcelFileDescriptor m_descriptor;
private FileInputStream m_stream;
public FileInput(Context context, String uri) throws IOException {
m_descriptor = context.getContentResolver().
openFileDescriptor(Utility.stringToUri(uri), "r");
m_stream = new FileInputStream(m_descriptor.getFileDescriptor());
}
public long size() throws IOException {
return m_descriptor.getStatSize();
}
public boolean reset() throws IOException {
m_stream.close();
m_stream = new FileInputStream(m_descriptor.getFileDescriptor());
return true;
}
public void close() throws IOException {
m_stream.close();
m_descriptor.close();
}
public byte[] read(int size) throws IOException {
byte[] buffer = new byte[size];
int nsize = m_stream.read(buffer);
if (nsize == -1)
return new byte[0];
byte[] result = new byte[nsize];
for (int i = 0; i < nsize; i++)
result[i] = buffer[i];
return result;
}
}
package org.videolan.cloudbrowser;
import android.os.ParcelFileDescriptor;
import android.content.Context;
import java.io.FileOutputStream;
import java.io.IOException;
public class FileOutput {
private ParcelFileDescriptor m_descriptor;
private FileOutputStream m_stream;
public FileOutput(Context context, String uri) throws IOException {
m_descriptor = context.getContentResolver().
openFileDescriptor(Utility.stringToUri(uri), "w");
m_stream = new FileOutputStream(m_descriptor.getFileDescriptor());
}
public void write(byte[] data) throws IOException {
m_stream.write(data);
}
public void close() throws IOException {
m_stream.close();
m_descriptor.close();
}
}
package org.videolan.cloudbrowser;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.Context;
import android.graphics.BitmapFactory;
import android.os.Build;
public class NotificationHelper {
private Context m_context;
private NotificationManager m_notification_manager;
private Receiver m_receiver;
private static final String ActionPlay = "PLAY";
private static final String ActionPause = "PAUSE";
private static final String ActionNext = "NEXT";
public static final int PlayerNotification = 1;
private static class Receiver extends BroadcastReceiver {
public void onReceive(Context ctx, Intent intent) {
Utility.onActionRequested(intent.getAction());
}
}
public NotificationHelper(Context context) {
m_context = context;
m_notification_manager =
(NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
m_receiver = new Receiver();
final IntentFilter filter = new IntentFilter();
filter.addAction(ActionPlay);
filter.addAction(ActionPause);
filter.addAction(ActionNext);
context.registerReceiver(m_receiver, filter);
hidePlayerNotification();
m_context.startService(
new Intent(context, NotificationService.class)
);
}
public void release() {
m_context.unregisterReceiver(m_receiver);
hidePlayerNotification();
}
public void showPlayerNotification(
boolean playing,
String icon,
String content_text,
String title
) {
final PendingIntent play_intent = PendingIntent.getBroadcast(m_context,
0, new Intent(ActionPlay), PendingIntent.FLAG_UPDATE_CURRENT);
final PendingIntent pause_intent = PendingIntent.getBroadcast(m_context,
0, new Intent(ActionPause), PendingIntent.FLAG_UPDATE_CURRENT);
final PendingIntent next_intent = PendingIntent.getBroadcast(m_context,
0, new Intent(ActionNext), PendingIntent.FLAG_UPDATE_CURRENT);
final Intent intent = new Intent(m_context, CloudBrowser.class);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
final PendingIntent content_intent = PendingIntent.getActivity(m_context,
0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
Notification.Builder builder = new Notification.Builder(m_context);
builder.setSmallIcon(R.drawable.icon).
setOngoing(playing).
setContentText(content_text).
setContentTitle(title).
setLargeIcon(BitmapFactory.decodeFile(icon)).
setContentIntent(content_intent);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
builder.setStyle(new Notification.MediaStyle().setShowActionsInCompactView(0, 1));
if (!playing)
builder.addAction(R.drawable.play, ActionPlay, play_intent);
else
builder.addAction(R.drawable.pause, ActionPause, pause_intent);
builder.addAction(R.drawable.next, ActionNext, next_intent);
m_notification_manager.notify(PlayerNotification, builder.build());
}
public void hidePlayerNotification() {
m_notification_manager.cancel(PlayerNotification);
}
}
package org.videolan.cloudbrowser;
import android.app.Service;
import android.app.NotificationManager;
import android.os.IBinder;
import android.content.Intent;
import android.content.Context;
public class NotificationService extends Service {
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public void onTaskRemoved(Intent intent) {
NotificationManager notification_manager =
(NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
notification_manager.cancel(NotificationHelper.PlayerNotification);
stopSelf();
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
return START_NOT_STICKY;
}
}
package org.videolan.cloudbrowser;
import android.net.Uri;
import android.content.Intent;
public class Utility {
public static native void onActionRequested(String action);
public static native void onRequestResult(int request, int result, Intent data);
public static Uri stringToUri(String uri) {
String basename = uri.substring(0, uri.lastIndexOf('/') + 1);
String filename = uri.substring(uri.lastIndexOf('/') + 1);
return Uri.parse(basename + Uri.encode(Uri.decode(filename)));
}
public static Intent openFileDialog() {
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.setType("*/*");
intent.addCategory(Intent.CATEGORY_OPENABLE);
return intent;
}
public static Intent createFileDialog(String filename) {
Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT);
intent.setType("*/*");
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.putExtra(Intent.EXTRA_TITLE, filename);
intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
return intent;
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment