Skip to content

Commit

Permalink
Merge pull request #49 from ITVlab/admob
Browse files Browse the repository at this point in the history
Admob
  • Loading branch information
Fleker committed Apr 27, 2017
2 parents c4d02ec + 965be8d commit 9961a79
Show file tree
Hide file tree
Showing 43 changed files with 1,106 additions and 86 deletions.
5 changes: 3 additions & 2 deletions app/build.gradle
Expand Up @@ -8,8 +8,8 @@ android {
applicationId "news.androidtv.tvapprepo"
minSdkVersion 21
targetSdkVersion 25
versionCode 11
versionName "1.0.7-b"
versionCode 12
versionName "1.0.7-c"
}
buildTypes {
release {
Expand Down Expand Up @@ -60,6 +60,7 @@ dependencies {
compile 'com.google.firebase:firebase-database:10.0.1'
compile 'com.google.android.gms:play-services-ads:10.0.1'
compile 'com.google.firebase:firebase-config:10.0.1'
compile 'com.google.firebase:firebase-ads:10.0.1'

// compile 'com.colortv:android-sdk:2.1.0'
compile 'com.github.bumptech.glide:glide:3.7.0'
Expand Down
@@ -1,13 +1,52 @@
package news.androidtv.tvapprepo;

import android.app.Application;
import android.content.ComponentName;
import android.content.Intent;
import android.test.ApplicationTestCase;
import android.util.Log;

import java.io.File;
import java.net.URISyntaxException;

import dalvik.annotation.TestTargetClass;
import news.androidtv.tvapprepo.intents.IntentUriGenerator;

/**
* <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a>
*/
public class ApplicationTest extends ApplicationTestCase<Application> {
public static final String TAG = ApplicationTest.class.getSimpleName();

public ApplicationTest() {
super(Application.class);
}

public void testWebBookmarks() {
final String expected = "intent://google.com#Intent;scheme=http;end";
String actual = IntentUriGenerator.generateWebBookmark("http://google.com");
Log.d(TAG, actual);
assertEquals(expected, actual);
}

public void testActivityShortcut() {
final String expected = "intent:#Intent;component=news.androidtv.tvapprepo/.activities.SettingsActivity;end";
String actual = IntentUriGenerator.generateActivityShortcut(new ComponentName("news.androidtv.tvapprepo", ".activities.SettingsActivity"));
Log.d(TAG, actual);
assertEquals(expected, actual);
}

public void testFileOpening() {
// Note: This can be flaky if your device doesn't have this file. Future versions of this
// test should create and delete a temporary file.
final String expected = "intent:///storage/emulated/0/Download/com.felkertech.n.cumulustv.test.apk#Intent;scheme=file;launchFlags=0x10000000;end";
String actual = IntentUriGenerator.generateVideoPlayback(new File("/storage/emulated/0/Download/com.felkertech.n.cumulustv.test.apk"));
Log.d(TAG, actual);
assertEquals(expected, actual);
}

public void testOpenGoogle() throws URISyntaxException {
String string = "intent:#Intent;component=news.androidtv.tvapprepo/.activities.SettingsActivity;end";
getContext().startActivity(Intent.parseUri(string, Intent.URI_INTENT_SCHEME));
}
}
9 changes: 9 additions & 0 deletions app/src/main/AndroidManifest.xml
Expand Up @@ -55,6 +55,15 @@
</intent-filter>
</activity>

<activity android:name=".activities.AdvancedShortcutActivity"
android:exported="true"
android:theme="@style/Theme.Panel"
android:enabled="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</intent-filter>
</activity>

<meta-data
android:name="io.fabric.ApiKey"
android:value="dfe843f8af6acfe924ff6efa0c816fda4ece9f5c" />
Expand Down
@@ -0,0 +1,129 @@
package news.androidtv.tvapprepo.activities;

import android.app.Activity;
import android.content.ComponentName;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.ResolveInfo;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AlertDialog;
import android.util.Log;
import android.view.ContextThemeWrapper;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.Switch;
import android.widget.Toast;

import news.androidtv.tvapprepo.R;
import news.androidtv.tvapprepo.iconography.IconsTask;
import news.androidtv.tvapprepo.iconography.PackedIcon;
import news.androidtv.tvapprepo.model.AdvancedOptions;
import news.androidtv.tvapprepo.utils.GenerateShortcutHelper;

/**
* Created by Nick on 4/24/2017.
*
* Dialogs are not a very good user interface if they start nesting. Instead, we will use a pull-out
* panel that comes in from the right and shows a variety of settings. This will scale a lot better
* as we can have more real-estate.
*/
public class AdvancedShortcutActivity extends Activity {
private static final String TAG = AdvancedShortcutActivity.class.getSimpleName();

public static final String EXTRA_RESOLVE_INFO = "resolveInfo";
public static final String EXTRA_ADVANCED_OPTIONS = "advancedOptions";

private AdvancedOptions advancedOptions;
private ResolveInfo resolveInfo;
private IconsTask.IconsReceivedCallback callback = new IconsTask.IconsReceivedCallback() {
@Override
public void onIcons(PackedIcon[] icons) {
Log.d(TAG, icons.length + "<<<");
// Show all icons for the user to select (or let them do their own)
LinearLayout iconDialogLayout = (LinearLayout) findViewById(R.id.icon_list);
iconDialogLayout.removeAllViews();
for (final PackedIcon icon : icons) {
ImageButton imageButton = new ImageButton(AdvancedShortcutActivity.this);
imageButton.setImageDrawable(icon.icon);
imageButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (icon.isBanner) {
advancedOptions.setBannerBitmap(icon.getBitmap());
} else {
advancedOptions.setIconBitmap(icon.getBitmap());
}
Log.d(TAG, advancedOptions.toString());
}
});
iconDialogLayout.addView(imageButton);
}
}
};

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getActionBar() != null) {
getActionBar().hide();
}
setContentView(R.layout.activity_advanced);

if (getIntent().hasExtra(EXTRA_RESOLVE_INFO)) {
resolveInfo = getIntent().getParcelableExtra(EXTRA_RESOLVE_INFO);
}
if (getIntent().hasExtra(EXTRA_ADVANCED_OPTIONS)) {
advancedOptions = getIntent().getParcelableExtra(EXTRA_ADVANCED_OPTIONS);
}

if (advancedOptions == null) {
advancedOptions = new AdvancedOptions(this);
}

loadCustomIconography();

findViewById(R.id.generate).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
publish();
finish();
}
});

// Turn into side-panel
// Sets the size and position of dialog activity.
WindowManager.LayoutParams layoutParams = getWindow().getAttributes();
layoutParams.gravity = Gravity.END | Gravity.CENTER_VERTICAL;
layoutParams.width = getResources().getDimensionPixelSize(R.dimen.side_panel_width);
layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT;
getWindow().setAttributes(layoutParams);
}

private void publish() {
boolean isGame = ((Switch) findViewById(R.id.switch_isgame)).isChecked();
String bannerUrl =
((EditText) findViewById(R.id.edit_banner)).getText().toString();
if (!bannerUrl.isEmpty()) {
advancedOptions.setBannerUrl(bannerUrl);
}
advancedOptions.setIsGame(isGame);
GenerateShortcutHelper.generateShortcut(this, resolveInfo, advancedOptions);
}

private void loadCustomIconography() {
if (resolveInfo != null) {
IconsTask.getIconsForComponentName(this,
new ComponentName(resolveInfo.activityInfo.packageName,
resolveInfo.activityInfo.name), callback);

} else {
Toast.makeText(this, "Cannot set banner of non-app yet", Toast.LENGTH_SHORT).show();
}
}
}

0 comments on commit 9961a79

Please sign in to comment.