/*
* Copyright (c) 2012 Daniel Huckaby
*
* 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.handlerexploit.prime.example.activities;
import java.util.List;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.LoaderManager.LoaderCallbacks;
import android.support.v4.content.Loader;
import android.view.View;
import android.widget.ImageView;
import com.handlerexploit.prime.drawable.RemoteStateListDrawable;
import com.handlerexploit.prime.example.R;
import com.handlerexploit.prime.example.utils.Utilities;
import com.handlerexploit.prime.example.utils.Utilities.Image;
import com.handlerexploit.prime.example.utils.WrappedAsyncTaskLoader;
public class RemoteStateListExample extends FragmentActivity implements LoaderCallbacks<RemoteStateListDrawable> {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.statelist_content);
getSupportLoaderManager().initLoader(0, null, this);
}
@Override
public Loader<RemoteStateListDrawable> onCreateLoader(int arg0, Bundle arg1) {
return new WrappedAsyncTaskLoader<RemoteStateListDrawable>(this) {
@Override
public RemoteStateListDrawable loadInBackground() {
List<Image> images = Utilities.getRandomThumbnailImages(RemoteStateListExample.this);
RemoteStateListDrawable remoteStateListDrawable = new RemoteStateListDrawable(RemoteStateListExample.this);
remoteStateListDrawable.addRemoteState(new int[] {android.R.attr.state_pressed}, images.get(0).imageURL);
remoteStateListDrawable.addRemoteState(new int[] {android.R.attr.state_focused}, images.get(1).imageURL);
remoteStateListDrawable.addRemoteState(new int[] {}, images.get(2).imageURL);
return remoteStateListDrawable;
}
};
}
@Override
public void onLoadFinished(Loader<RemoteStateListDrawable> arg0, RemoteStateListDrawable arg1) {
findViewById(R.id.exampleContainer).setVisibility(View.VISIBLE);
findViewById(R.id.progressContainer).setVisibility(View.GONE);
ImageView icon = (ImageView) findViewById(R.id.icon);
icon.setImageDrawable(arg1);
}
@Override
public void onLoaderReset(Loader<RemoteStateListDrawable> arg0) {
findViewById(R.id.exampleContainer).setVisibility(View.GONE);
findViewById(R.id.progressContainer).setVisibility(View.VISIBLE);
}
}