Android Open Source - Muzei Full Screen Activity






From Project

Back to project page Muzei.

License

The source code is released under:

Apache License

If you think the Android project Muzei listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*
 * Copyright 2014 Google Inc.//w w  w .  j  ava 2 s.  co m
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.google.android.apps.muzei;

import android.animation.Animator;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.app.Activity;
import android.app.LoaderManager;
import android.content.AsyncTaskLoader;
import android.content.Loader;
import android.database.ContentObserver;
import android.graphics.Bitmap;
import android.graphics.Typeface;
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.NonNull;
import android.support.wearable.view.DismissOverlayView;
import android.util.Log;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.View;
import android.widget.TextView;

import com.google.android.apps.muzei.api.Artwork;
import com.google.android.apps.muzei.api.MuzeiContract;
import com.google.android.apps.muzei.util.PanView;
import com.google.android.apps.muzei.util.TypefaceUtil;

import net.nurik.roman.muzei.R;

import java.io.FileNotFoundException;

public class FullScreenActivity extends Activity implements LoaderManager.LoaderCallbacks<Bitmap> {
    private static final String TAG = FullScreenActivity.class.getSimpleName();

    private PanView mPanView;
    private View mLoadingIndicatorView;
    private View mScrimView;
    private View mMetadataContainerView;
    private TextView mTitleView;
    private TextView mBylineView;
    private DismissOverlayView mDismissOverlay;
    private GestureDetector mDetector;
    private Animator mBlurAnimator;
    private Handler mHandler = new Handler();

    private Artwork mArtwork;
    private boolean mMetadataVisible = false;

    public void onCreate(Bundle savedState) {
        super.onCreate(savedState);
        setContentView(R.layout.full_screen_activity);
        mPanView = (PanView) findViewById(R.id.pan_view);
        getLoaderManager().initLoader(0, null, this);

        mScrimView = findViewById(R.id.scrim);
        mLoadingIndicatorView = findViewById(R.id.loading_indicator);
        mHandler.postDelayed(mShowLoadingIndicatorRunnable, 500);

        mMetadataContainerView = findViewById(R.id.metadata_container);
        mTitleView = (TextView) findViewById(R.id.title);
        mBylineView = (TextView) findViewById(R.id.byline);

        Typeface tf = TypefaceUtil.getAndCache(this, "Alegreya-BlackItalic.ttf");
        mTitleView = (TextView) findViewById(R.id.title);
        mTitleView.setTypeface(tf);

        tf = TypefaceUtil.getAndCache(this, "Alegreya-Italic.ttf");
        mBylineView = (TextView) findViewById(R.id.byline);
        mBylineView.setTypeface(tf);

        // Configure the DismissOverlayView element
        mDismissOverlay = (DismissOverlayView) findViewById(R.id.dismiss_overlay);
        mDismissOverlay.setIntroText(R.string.dismiss_overlay_intro);
        mDismissOverlay.showIntroIfNecessary();
        mDetector = new GestureDetector(this, new GestureDetector.SimpleOnGestureListener() {
            @Override
            public boolean onSingleTapConfirmed(MotionEvent e) {
                if (mDismissOverlay.getVisibility() == View.VISIBLE) {
                    return false;
                }

                if (mMetadataVisible) {
                    setMetadataVisible(false);
                } else {
                    setMetadataVisible(true);
                }
                return true;
            }

            @Override
            public void onLongPress(MotionEvent ev) {
                if (mDismissOverlay.getVisibility() == View.VISIBLE) {
                    return;
                }
                mDismissOverlay.show();
            }
        });
    }

    private Runnable mShowLoadingIndicatorRunnable = new Runnable() {
        @Override
        public void run() {
            mLoadingIndicatorView.setVisibility(View.VISIBLE);
        }
    };

    private void setMetadataVisible(boolean metadataVisible) {
        mMetadataVisible = metadataVisible;
        if (mBlurAnimator != null) {
            mBlurAnimator.cancel();
        }

        AnimatorSet set = new AnimatorSet();
        set
                .play(ObjectAnimator.ofFloat(mPanView, "blurAmount", metadataVisible? 1f : 0f))
                .with(ObjectAnimator.ofFloat(mScrimView, View.ALPHA, metadataVisible ? 1f : 0f))
                .with(ObjectAnimator.ofFloat(mMetadataContainerView, View.ALPHA,
                        metadataVisible ? 1f : 0f));
        set.setDuration(getResources().getInteger(android.R.integer.config_shortAnimTime));

        mBlurAnimator = set;
        mBlurAnimator.start();
    }

    @Override
    public boolean dispatchTouchEvent(@NonNull MotionEvent ev) {
        return mDetector.onTouchEvent(ev) || super.dispatchTouchEvent(ev);
    }

    @Override
    public Loader<Bitmap> onCreateLoader(int id, Bundle args) {
        return new AsyncTaskLoader<Bitmap>(this) {
            private ContentObserver mContentObserver;
            private Bitmap mImage;

            @Override
            protected void onStartLoading() {
                if (mImage != null) {
                    deliverResult(mImage);
                }
                if (mContentObserver == null) {
                    mContentObserver = new ContentObserver(null) {
                        @Override
                        public void onChange(boolean selfChange) {
                            onContentChanged();
                        }
                    };
                    getContentResolver().registerContentObserver(MuzeiContract.Artwork.CONTENT_URI,
                            true, mContentObserver);
                }
                forceLoad();
            }

            @Override
            public Bitmap loadInBackground() {
                try {
                    mArtwork = MuzeiContract.Artwork.getCurrentArtwork(FullScreenActivity.this);
                    mImage = MuzeiContract.Artwork.getCurrentArtworkBitmap(FullScreenActivity.this);
                    return mImage;
                } catch (FileNotFoundException e) {
                    Log.e(TAG, "Error getting artwork", e);
                    return null;
                }
            }

            @Override
            protected void onReset() {
                super.onReset();
                mImage = null;
                if (mContentObserver != null) {
                    getContentResolver().unregisterContentObserver(mContentObserver);
                }
            }
        };
    }

    @Override
    public void onLoadFinished(Loader<Bitmap> loader, final Bitmap image) {
        if (image == null) {
            return;
        }

        mHandler.removeCallbacks(mShowLoadingIndicatorRunnable);
        mLoadingIndicatorView.setVisibility(View.GONE);
        mPanView.setVisibility(View.VISIBLE);
        mPanView.setImage(image);
        mTitleView.setText(mArtwork.getTitle());
        mBylineView.setText(mArtwork.getByline());
    }

    @Override
    public void onLoaderReset(Loader<Bitmap> loader) {
        mPanView.setImage(null);
    }
}




Java Source Code List

com.example.muzei.examplecontractwidget.ArtworkUpdateReceiver.java
com.example.muzei.examplecontractwidget.ArtworkUpdateService.java
com.example.muzei.examplecontractwidget.MuzeiAppWidgetProvider.java
com.example.muzei.examplesource500px.Config.java
com.example.muzei.examplesource500px.FiveHundredPxExampleArtSource.java
com.example.muzei.examplesource500px.FiveHundredPxService.java
com.example.muzei.watchface.ArtworkImageLoader.java
com.example.muzei.watchface.MuzeiExampleWatchface.java
com.example.muzei.watchface.WatchfaceArtworkImageLoader.java
com.google.android.apps.muzei.ActivateMuzeiIntentService.java
com.google.android.apps.muzei.ArtDetailViewport.java
com.google.android.apps.muzei.ArtworkCacheIntentService.java
com.google.android.apps.muzei.ArtworkCache.java
com.google.android.apps.muzei.FullScreenActivity.java
com.google.android.apps.muzei.LockScreenVisibleReceiver.java
com.google.android.apps.muzei.MuzeiActivity.java
com.google.android.apps.muzei.MuzeiApplication.java
com.google.android.apps.muzei.MuzeiWallpaperService.java
com.google.android.apps.muzei.MuzeiWatchFace.java
com.google.android.apps.muzei.MuzeiWearableListenerService.java
com.google.android.apps.muzei.MuzeiWearableListenerService.java
com.google.android.apps.muzei.NetworkChangeReceiver.java
com.google.android.apps.muzei.NewWallpaperNotificationReceiver.java
com.google.android.apps.muzei.PhotoSetAsTargetActivity.java
com.google.android.apps.muzei.SourceManager.java
com.google.android.apps.muzei.SourcePackageChangeReceiver.java
com.google.android.apps.muzei.SourceSubscriberService.java
com.google.android.apps.muzei.TaskQueueService.java
com.google.android.apps.muzei.WearableController.java
com.google.android.apps.muzei.api.Artwork.java
com.google.android.apps.muzei.api.MuzeiArtSource.java
com.google.android.apps.muzei.api.MuzeiContract.java
com.google.android.apps.muzei.api.RemoteMuzeiArtSource.java
com.google.android.apps.muzei.api.UserCommand.java
com.google.android.apps.muzei.api.internal.ProtocolConstants.java
com.google.android.apps.muzei.api.internal.SourceState.java
com.google.android.apps.muzei.event.ArtDetailOpenedClosedEvent.java
com.google.android.apps.muzei.event.ArtworkLoadingStateChangedEvent.java
com.google.android.apps.muzei.event.ArtworkSizeChangedEvent.java
com.google.android.apps.muzei.event.BlurAmountChangedEvent.java
com.google.android.apps.muzei.event.CurrentArtworkDownloadedEvent.java
com.google.android.apps.muzei.event.DimAmountChangedEvent.java
com.google.android.apps.muzei.event.GainedNetworkConnectivityEvent.java
com.google.android.apps.muzei.event.GalleryChosenUrisChangedEvent.java
com.google.android.apps.muzei.event.GreyAmountChangedEvent.java
com.google.android.apps.muzei.event.LockScreenVisibleChangedEvent.java
com.google.android.apps.muzei.event.SelectedSourceChangedEvent.java
com.google.android.apps.muzei.event.SelectedSourceStateChangedEvent.java
com.google.android.apps.muzei.event.SwitchingPhotosStateChangedEvent.java
com.google.android.apps.muzei.event.WallpaperActiveStateChangedEvent.java
com.google.android.apps.muzei.event.WallpaperSizeChangedEvent.java
com.google.android.apps.muzei.featuredart.FeaturedArtSource.java
com.google.android.apps.muzei.gallery.GalleryArtSource.java
com.google.android.apps.muzei.gallery.GalleryDatabase.java
com.google.android.apps.muzei.gallery.GalleryEmptyStateGraphicView.java
com.google.android.apps.muzei.gallery.GallerySettingsActivity.java
com.google.android.apps.muzei.gallery.GalleryStore.java
com.google.android.apps.muzei.provider.MuzeiProvider.java
com.google.android.apps.muzei.render.BitmapRegionLoader.java
com.google.android.apps.muzei.render.DemoRenderController.java
com.google.android.apps.muzei.render.GLColorOverlay.java
com.google.android.apps.muzei.render.GLPicture.java
com.google.android.apps.muzei.render.GLTextureView.java
com.google.android.apps.muzei.render.GLUtil.java
com.google.android.apps.muzei.render.ImageUtil.java
com.google.android.apps.muzei.render.MuzeiBlurRenderer.java
com.google.android.apps.muzei.render.MuzeiRendererFragment.java
com.google.android.apps.muzei.render.RealRenderController.java
com.google.android.apps.muzei.render.RenderController.java
com.google.android.apps.muzei.settings.AboutActivity.java
com.google.android.apps.muzei.settings.Prefs.java
com.google.android.apps.muzei.settings.SettingsActivity.java
com.google.android.apps.muzei.settings.SettingsAdvancedFragment.java
com.google.android.apps.muzei.settings.SettingsChooseSourceFragment.java
com.google.android.apps.muzei.util.AnimatedMuzeiLoadingSpinnerView.java
com.google.android.apps.muzei.util.AnimatedMuzeiLogoFragment.java
com.google.android.apps.muzei.util.AnimatedMuzeiLogoView.java
com.google.android.apps.muzei.util.CheatSheet.java
com.google.android.apps.muzei.util.DrawInsetsFrameLayout.java
com.google.android.apps.muzei.util.IOUtil.java
com.google.android.apps.muzei.util.ImageBlurrer.java
com.google.android.apps.muzei.util.LogUtil.java
com.google.android.apps.muzei.util.LogoPaths.java
com.google.android.apps.muzei.util.MathUtil.java
com.google.android.apps.muzei.util.MultiSelectionController.java
com.google.android.apps.muzei.util.ObservableHorizontalScrollView.java
com.google.android.apps.muzei.util.PanScaleProxyView.java
com.google.android.apps.muzei.util.PanView.java
com.google.android.apps.muzei.util.ScrimUtil.java
com.google.android.apps.muzei.util.Scrollbar.java
com.google.android.apps.muzei.util.SelectionBuilder.java
com.google.android.apps.muzei.util.ShadowDipsTextView.java
com.google.android.apps.muzei.util.SvgPathParser.java
com.google.android.apps.muzei.util.TickingFloatAnimator.java
com.google.android.apps.muzei.util.TypefaceUtil.java
com.google.android.apps.muzei.util.Zoomer.java
net.rbgrn.android.glwallpaperservice.BaseConfigChooser.java
net.rbgrn.android.glwallpaperservice.GLWallpaperService.java