summaryrefslogtreecommitdiffstats
path: root/src/com/android
diff options
context:
space:
mode:
authorJorim Jaggi <jjaggi@google.com>2016-05-24 00:30:00 -0700
committerJorim Jaggi <jjaggi@google.com>2016-06-02 19:09:51 -0700
commit7d98c8fca6d1edd51178a65847687d81562d7d6e (patch)
treecc8136cfcfb660fb73c026faf9bd1b514fa984fc /src/com/android
parentb30b95f9db068faf294e43fb7927d911ecfaf892 (diff)
downloadandroid_packages_wallpapers_LivePicker-7d98c8fca6d1edd51178a65847687d81562d7d6e.tar.gz
android_packages_wallpapers_LivePicker-7d98c8fca6d1edd51178a65847687d81562d7d6e.tar.bz2
android_packages_wallpapers_LivePicker-7d98c8fca6d1edd51178a65847687d81562d7d6e.zip
Adjust wallpaper picker to match static wallpaper picker
- Implement new action bar - Use BottomSheet behavior from design lib - Fill in values from live wallpaper if desired - Don't use separate dialog for loading state Bug: 28770685 Change-Id: I8dd862fe4c83f702e249f7f3644df89fee771f4f
Diffstat (limited to 'src/com/android')
-rw-r--r--src/com/android/wallpaper/livepicker/LiveWallpaperPreview.java250
1 files changed, 192 insertions, 58 deletions
diff --git a/src/com/android/wallpaper/livepicker/LiveWallpaperPreview.java b/src/com/android/wallpaper/livepicker/LiveWallpaperPreview.java
index 85f241f..34e92f1 100644
--- a/src/com/android/wallpaper/livepicker/LiveWallpaperPreview.java
+++ b/src/com/android/wallpaper/livepicker/LiveWallpaperPreview.java
@@ -16,37 +16,43 @@
package com.android.wallpaper.livepicker;
-import android.app.ActionBar;
import android.app.Activity;
import android.app.AlertDialog;
-import android.app.WallpaperManager;
import android.app.WallpaperInfo;
-import android.app.Dialog;
+import android.app.WallpaperManager;
+import android.content.ActivityNotFoundException;
+import android.content.ComponentName;
+import android.content.Context;
import android.content.DialogInterface;
-import android.graphics.Rect;
-import android.service.wallpaper.IWallpaperConnection;
-import android.service.wallpaper.IWallpaperService;
-import android.service.wallpaper.IWallpaperEngine;
-import android.service.wallpaper.WallpaperSettingsActivity;
-import android.content.ServiceConnection;
import android.content.Intent;
-import android.content.Context;
-import android.content.ComponentName;
-import android.os.RemoteException;
+import android.content.ServiceConnection;
+import android.content.pm.PackageManager;
+import android.content.res.Resources.NotFoundException;
+import android.graphics.Rect;
+import android.net.Uri;
+import android.os.Bundle;
import android.os.IBinder;
import android.os.ParcelFileDescriptor;
-import android.os.Bundle;
+import android.os.RemoteException;
+import android.service.wallpaper.IWallpaperConnection;
+import android.service.wallpaper.IWallpaperEngine;
+import android.service.wallpaper.IWallpaperService;
import android.service.wallpaper.WallpaperService;
+import android.service.wallpaper.WallpaperSettingsActivity;
+import android.support.design.widget.BottomSheetBehavior;
+import android.text.TextUtils;
+import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
-import android.view.WindowManager;
-import android.view.ViewGroup;
-import android.view.Window;
-import android.view.LayoutInflater;
-import android.util.Log;
+import android.view.View.OnClickListener;
+import android.view.WindowManager.LayoutParams;
+import android.view.animation.AnimationUtils;
+import android.widget.Button;
+import android.widget.ImageButton;
import android.widget.TextView;
+import android.widget.Toolbar;
import java.io.IOException;
@@ -55,6 +61,9 @@ public class LiveWallpaperPreview extends Activity {
private static final String LOG_TAG = "LiveWallpaperPreview";
+ // TODO: Remove once we have good data for testing.
+ private static final boolean SHOW_DUMMY_DATA = true;
+
private WallpaperManager mWallpaperManager;
private WallpaperConnection mWallpaperConnection;
@@ -62,8 +71,14 @@ public class LiveWallpaperPreview extends Activity {
private String mPackageName;
private Intent mWallpaperIntent;
- private View mView;
- private Dialog mDialog;
+ private TextView mAttributionTitle;
+ private TextView mAttributionSubtitle1;
+ private TextView mAttributionSubtitle2;
+ private Button mAttributionExploreButton;
+ private ImageButton mPreviewPaneArrow;
+ private View mBottomSheet;
+ private View mSpacer;
+ private View mLoading;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -78,29 +93,157 @@ public class LiveWallpaperPreview extends Activity {
setResult(RESULT_CANCELED);
finish();
}
-
initUI(info);
}
protected void initUI(WallpaperInfo info) {
+ getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE
+ | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
+ | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
+ setContentView(R.layout.live_wallpaper_preview);
+ mAttributionTitle = (TextView) findViewById(R.id.preview_attribution_pane_title);
+ mAttributionSubtitle1 = (TextView) findViewById(R.id.preview_attribution_pane_subtitle1);
+ mAttributionSubtitle2 = (TextView) findViewById(R.id.preview_attribution_pane_subtitle2);
+ mAttributionExploreButton = (Button) findViewById(
+ R.id.preview_attribution_pane_explore_button);
+ mPreviewPaneArrow = (ImageButton) findViewById(R.id.preview_attribution_pane_arrow);
+ mBottomSheet = findViewById(R.id.bottom_sheet);
+ mSpacer = findViewById(R.id.spacer);
+ mLoading = findViewById(R.id.loading);
+
mSettings = info.getSettingsActivity();
mPackageName = info.getPackageName();
mWallpaperIntent = new Intent(WallpaperService.SERVICE_INTERFACE)
.setClassName(info.getPackageName(), info.getServiceName());
- final ActionBar actionBar = getActionBar();
- actionBar.setCustomView(R.layout.live_wallpaper_preview);
- mView = actionBar.getCustomView();
+ setActionBar((Toolbar) findViewById(R.id.toolbar));
+ getActionBar().setDisplayHomeAsUpEnabled(true);
+ getActionBar().setDisplayShowTitleEnabled(false);
mWallpaperManager = WallpaperManager.getInstance(this);
mWallpaperConnection = new WallpaperConnection(mWallpaperIntent);
+
+ populateAttributionPane(info);
+ }
+
+ private void populateAttributionPane(WallpaperInfo info) {
+ if (!info.getShowMetadataInPreview() && !SHOW_DUMMY_DATA) {
+ mBottomSheet.setVisibility(View.GONE);
+ return;
+ }
+ final BottomSheetBehavior bottomSheetBehavior = BottomSheetBehavior.from(mBottomSheet);
+
+ OnClickListener onClickListener = new OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ if (bottomSheetBehavior.getState() == BottomSheetBehavior.STATE_COLLAPSED) {
+ bottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
+ } else if (bottomSheetBehavior.getState() == BottomSheetBehavior.STATE_EXPANDED) {
+ bottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
+ }
+ }
+ };
+ mPreviewPaneArrow.setOnClickListener(onClickListener);
+
+ bottomSheetBehavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
+ @Override
+ public void onStateChanged(View bottomSheet, int newState) {
+ if (newState == BottomSheetBehavior.STATE_COLLAPSED) {
+ mPreviewPaneArrow.setImageResource(R.drawable.ic_keyboard_arrow_up_white_24dp);
+ mPreviewPaneArrow.setContentDescription(
+ getResources().getString(R.string.expand_attribution_panel));
+ } else if (newState == BottomSheetBehavior.STATE_EXPANDED) {
+ mPreviewPaneArrow.setImageResource(
+ R.drawable.ic_keyboard_arrow_down_white_24dp);
+ mPreviewPaneArrow.setContentDescription(
+ getResources().getString(R.string.collapse_attribution_panel));
+ }
+ }
+
+ @Override
+ public void onSlide(View bottomSheet, float slideOffset) {
+ float alpha;
+ if (slideOffset >= 0) {
+ alpha = slideOffset;
+ } else {
+ alpha = 1f - slideOffset;
+ }
+ mAttributionTitle.setAlpha(slideOffset);
+ mAttributionSubtitle1.setAlpha(slideOffset);
+ mAttributionSubtitle2.setAlpha(slideOffset);
+ mAttributionExploreButton.setAlpha(slideOffset);
+ }
+ });
+
+ bottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
+ mPreviewPaneArrow.setImageResource(R.drawable.ic_keyboard_arrow_down_white_24dp);
+
+ if (SHOW_DUMMY_DATA) {
+ mAttributionTitle.setText("Diorama, Yosemite");
+ mAttributionSubtitle1.setText("Live Earth Collection - Android Earth");
+ mAttributionSubtitle2.setText("Lorem ipsum dolor sit amet, consectetur adipiscing elit."
+ + " Sed imperdiet et mauris molestie laoreet. Proin volutpat elit nec magna"
+ + " tempus, ac aliquet lectus volutpat.");
+ mAttributionExploreButton.setText("Explore");
+ } else {
+ PackageManager pm = getPackageManager();
+
+ CharSequence title = info.loadLabel(pm);
+ if (!TextUtils.isEmpty(title)) {
+ mAttributionTitle.setText(title);
+ } else {
+ mAttributionTitle.setVisibility(View.GONE);
+ }
+
+ try {
+ CharSequence author = info.loadAuthor(pm);
+ if (TextUtils.isEmpty(author)) {
+ throw new NotFoundException();
+ }
+ mAttributionSubtitle1.setText(author);
+ } catch (NotFoundException e) {
+ mAttributionSubtitle1.setVisibility(View.GONE);
+ }
+
+ try {
+ CharSequence description = info.loadDescription(pm);
+ if (TextUtils.isEmpty(description)) {
+ throw new NotFoundException();
+ }
+ mAttributionSubtitle2.setText(description);
+ } catch (NotFoundException e) {
+ mAttributionSubtitle2.setVisibility(View.GONE);
+ }
+
+ try {
+ Uri contextUri = info.loadContextUri(pm);
+ CharSequence contextDescription = info.loadContextDescription(pm);
+ if (contextUri == null) {
+ throw new NotFoundException();
+ }
+ mAttributionExploreButton.setText(contextDescription);
+ mAttributionExploreButton.setOnClickListener(v -> {
+ Intent intent = new Intent(Intent.ACTION_VIEW, contextUri);
+ intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ try {
+ startActivity(intent);
+ } catch (ActivityNotFoundException e) {
+ Log.e(LOG_TAG, "Couldn't find activity for context link.", e);
+ }
+ });
+ } catch (NotFoundException e) {
+ mAttributionExploreButton.setVisibility(View.GONE);
+ mSpacer.setVisibility(View.VISIBLE);
+ }
+ }
+
+
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
- if (mSettings != null) {
- getMenuInflater().inflate(R.menu.menu_preview, menu);
- }
+ getMenuInflater().inflate(R.menu.menu_preview, menu);
+ menu.findItem(R.id.configure).setVisible(mSettings != null);
return super.onCreateOptionsMenu(menu);
}
@@ -116,7 +259,7 @@ public class LiveWallpaperPreview extends Activity {
finish();
} else {
// Otherwise, prompt to either set on home or both home and lock screen.
- new AlertDialog.Builder(this)
+ new AlertDialog.Builder(this, android.R.style.Theme_Material_Light_Dialog)
.setTitle(R.string.set_live_wallpaper)
.setItems(R.array.which_wallpaper_options, new DialogInterface.OnClickListener() {
@Override
@@ -149,12 +292,19 @@ public class LiveWallpaperPreview extends Activity {
@Override
public boolean onOptionsItemSelected(MenuItem item) {
- if (item.getItemId() == R.id.configure) {
+ int id = item.getItemId();
+ if (id == R.id.configure) {
Intent intent = new Intent();
intent.setComponent(new ComponentName(mPackageName, mSettings));
intent.putExtra(WallpaperSettingsActivity.EXTRA_PREVIEW_MODE, true);
startActivity(intent);
return true;
+ } else if (id == R.id.set_wallpaper) {
+ setLiveWallpaper(getWindow().getDecorView());
+ return true;
+ } else if (id == android.R.id.home) {
+ onBackPressed();
+ return true;
}
return super.onOptionsItemSelected(item);
}
@@ -187,9 +337,7 @@ public class LiveWallpaperPreview extends Activity {
public void onAttachedToWindow() {
super.onAttachedToWindow();
- showLoading();
-
- mView.post(new Runnable() {
+ getWindow().getDecorView().post(new Runnable() {
public void run() {
if (!mWallpaperConnection.connect()) {
mWallpaperConnection = null;
@@ -198,31 +346,10 @@ public class LiveWallpaperPreview extends Activity {
});
}
- private void showLoading() {
- LayoutInflater inflater = LayoutInflater.from(this);
- TextView content = (TextView) inflater.inflate(R.layout.live_wallpaper_loading, null);
-
- mDialog = new Dialog(this, android.R.style.Theme_Black);
-
- Window window = mDialog.getWindow();
- WindowManager.LayoutParams lp = window.getAttributes();
-
- lp.width = WindowManager.LayoutParams.MATCH_PARENT;
- lp.height = WindowManager.LayoutParams.MATCH_PARENT;
- window.setType(WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA);
-
- mDialog.setContentView(content, new ViewGroup.LayoutParams(
- ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT
- ));
- mDialog.show();
- }
-
@Override
public void onDetachedFromWindow() {
super.onDetachedFromWindow();
- if (mDialog != null) mDialog.dismiss();
-
if (mWallpaperConnection != null) {
mWallpaperConnection.disconnect();
}
@@ -286,7 +413,7 @@ public class LiveWallpaperPreview extends Activity {
return true;
}
}
-
+
public void disconnect() {
synchronized (this) {
mConnected = false;
@@ -307,10 +434,9 @@ public class LiveWallpaperPreview extends Activity {
if (mWallpaperConnection == this) {
mService = IWallpaperService.Stub.asInterface(service);
try {
- final View view = mView;
- final View root = view.getRootView();
- mService.attach(this, view.getWindowToken(),
- WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA_OVERLAY,
+ final View root = getWindow().getDecorView();
+ mService.attach(this, root.getWindowToken(),
+ LayoutParams.TYPE_APPLICATION_MEDIA,
true, root.getWidth(), root.getHeight(),
new Rect(0, 0, 0, 0));
} catch (RemoteException e) {
@@ -352,6 +478,14 @@ public class LiveWallpaperPreview extends Activity {
@Override
public void engineShown(IWallpaperEngine engine) throws RemoteException {
+ mLoading.post(() -> {
+ mLoading.animate()
+ .alpha(0f)
+ .setDuration(220)
+ .setInterpolator(AnimationUtils.loadInterpolator(LiveWallpaperPreview.this,
+ android.R.interpolator.fast_out_linear_in))
+ .withEndAction(() -> mLoading.setVisibility(View.INVISIBLE));
+ });
}
}
}