-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #49 from ITVlab/admob
Admob
- Loading branch information
Showing
43 changed files
with
1,106 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
app/src/androidTest/java/news/androidtv/tvapprepo/ApplicationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
129 changes: 129 additions & 0 deletions
129
app/src/main/java/news/androidtv/tvapprepo/activities/AdvancedShortcutActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
} | ||
} |
Oops, something went wrong.