Android Open Source - UpdateMaster Abstract View Controller






From Project

Back to project page UpdateMaster.

License

The source code is released under:

Apache License

If you think the Android project UpdateMaster 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

package com.cvsi.updatemaster.controller;
//www. j  av  a  2  s  .com
import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.cvsi.updatemaster.data.Resource;

/**
 * Created by rivasyshyn on 17.09.2014.
 */
public abstract class AbstractViewController extends Fragment implements RemoteImageProvider {

    private Resource mData;

    public static interface OnItemSelectedListener {
        public void onItemSelected(Resource resource);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        getData();

        if (mData != null) {
            updateView(mData);
        }
        return null;
    }

    protected void onItemSelected(Resource resource) {
        Activity activity = getActivity();
        if (activity instanceof OnItemSelectedListener) {
            ((OnItemSelectedListener) activity).onItemSelected(resource);
        } else {
            throw new IllegalStateException(String.format("activity %s should implement %s", activity, OnItemSelectedListener.class.getCanonicalName()));
        }
    }

    protected Resource getData() {
        if (mData == null) {
            mData = getArguments().getParcelable("data");
        }
        return mData;
    }

    @Override
    public void loadImage(ImageView view, String url) {
        if (getActivity() instanceof RemoteImageProvider) {
            ((RemoteImageProvider) getActivity()).loadImage(view, url);
        }
    }

    protected abstract void updateView(Resource resource);

}




Java Source Code List

com.cvsi.updatemaster.ApplicationTest.java
com.cvsi.updatemaster.activities.MainActivity.java
com.cvsi.updatemaster.activities.SplashActivity.java
com.cvsi.updatemaster.controller.AbstractViewController.java
com.cvsi.updatemaster.controller.ListFragment.java
com.cvsi.updatemaster.controller.PackageFragment.java
com.cvsi.updatemaster.controller.RemoteImageProvider.java
com.cvsi.updatemaster.data.PackageInfo.java
com.cvsi.updatemaster.data.Resource.java
com.cvsi.updatemaster.dialogs.ErrorDialog.java
com.cvsi.updatemaster.dialogs.SettingsDialog.java
com.cvsi.updatemaster.utils.SelfUpdateUtil.java