Android Open Source - ColorWallpaper Choose Picture Preference






From Project

Back to project page ColorWallpaper.

License

The source code is released under:

Licensed under the Expat License. Copyright (C) 2013 Peter Occil Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the...

If you think the Android project ColorWallpaper 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.upokecenter.android.ui;
/*  w  ww. ja v a  2 s . co m*/
import android.content.Context;
import android.content.Intent;
import android.content.res.TypedArray;
import android.os.Bundle;
import android.os.Parcelable;
import android.preference.Preference;
import android.util.AttributeSet;

import com.upokecenter.util.IBoundAction;


public final class ChoosePicturePreference extends Preference {

  int callback=-1;

  @Override
  protected Parcelable onSaveInstanceState() {
    Parcelable state = super.onSaveInstanceState();
    PreferenceState ret = new PreferenceState(state,this.getClass());
    Bundle b=ret.getBundle();
    b.putInt("callback",callback);
    state=ret;
    return state;
  }

  @Override
  protected void onRestoreInstanceState(Parcelable state) {
    boolean isState=PreferenceState.isPreferenceState(state,this.getClass());
    super.onRestoreInstanceState(isState ? ((PreferenceState)state).getSuperState() : state);
    if(isState){
      Bundle b=((PreferenceState)state).getBundle();
      callback=b.getInt("callback");
      GetContentActivity.getCallbacks().rebindAction(callback,this);
    }
  }


  @Override
  protected Object onGetDefaultValue(TypedArray a, int index) {
    return a.getString(index);
  }


  private void persist(Object value){
    persistString((String)value);
  }

  private Object getPersisted(Object value){
    return getPersistedString(value==null ? "" : (String)value);
  }

  private String settingSummary = null;
  private String dialogTitle = null;

  public ChoosePicturePreference(Context context, AttributeSet attrs) {
    super(context, attrs);
    int summaryId=attrs.getAttributeResourceValue(
        "http://schemas.android.com/apk/res/android","summary",0);
    if(summaryId!=0){
      settingSummary=context.getResources().getString(summaryId);
    }
    int dialogTitleId=attrs.getAttributeResourceValue(
        "http://schemas.android.com/apk/res/android","dialogTitle",0);
    if(dialogTitleId!=0){
      dialogTitle=context.getResources().getString(dialogTitleId);
    }
  }

  private void showAction() {
    Intent intent=new Intent(Intent.ACTION_GET_CONTENT);
    intent.setClass(getContext(),GetContentActivity.class);
    callback=GetContentActivity.getCallbacks().registerAction(
        this,new IBoundAction<String>(){
          @Override
          public void action(Object obj, String... parameters) {
            ChoosePicturePreference pref=(ChoosePicturePreference)obj;
            if(parameters[0]!=null && pref.callChangeListener(parameters[0])){
              pref.persist(parameters[0]);
              pref.setSummary(String.format(
                  pref.settingSummary==null ? "" : pref.settingSummary,
                      pref.getPersisted(null)));
            }
          }
        });
    if(dialogTitle!=null){
      intent.putExtra(Intent.EXTRA_TITLE,dialogTitle);
    }
    intent.putExtra("com.upokecenter.android.extra.CALLBACK",callback);
    intent.putExtra("startValue",(String)getPersisted(null));
    getContext().startActivity(intent);
  }

  @Override
  protected void onClick() {
    super.onClick();
    showAction();
  }

  @Override
  protected void onSetInitialValue(boolean restorePersistedValue, Object defaultValue) {
    if (restorePersistedValue) {
      setSummary(String.format(settingSummary==null ? "" : settingSummary,getPersisted(defaultValue)));
    } else {
      persist(defaultValue);
      setSummary(String.format(settingSummary==null ? "" : settingSummary,getPersisted(defaultValue)));
    }
  }

}




Java Source Code List

com.upokecenter.android.colorwallpaper.ColorWallpaperService.java
com.upokecenter.android.colorwallpaper.LauncherActivity.java
com.upokecenter.android.colorwallpaper.SettingsActivity.java
com.upokecenter.android.location.DummyLocationHelper.java
com.upokecenter.android.location.ILocationHelper.java
com.upokecenter.android.location.ISimpleLocationListener.java
com.upokecenter.android.location.LocationHelper.java
com.upokecenter.android.net.ConnectivityHelper.java
com.upokecenter.android.net.DownloadService.java
com.upokecenter.android.net.IConnectionListener.java
com.upokecenter.android.ui.AlertDialogActivity.java
com.upokecenter.android.ui.AlertDialogPreference.java
com.upokecenter.android.ui.BaseSettingsActivity.java
com.upokecenter.android.ui.ChoosePicturePreference.java
com.upokecenter.android.ui.ColorPickerDialog.java
com.upokecenter.android.ui.ContinuousValuePreference.java
com.upokecenter.android.ui.DialogUtility.java
com.upokecenter.android.ui.GetContentActivity.java
com.upokecenter.android.ui.IChoiceListener.java
com.upokecenter.android.ui.IDialogUpdater.java
com.upokecenter.android.ui.IntentPreference.java
com.upokecenter.android.ui.PreferenceState.java
com.upokecenter.android.ui.ShareActivity.java
com.upokecenter.android.ui.UriPreference.java
com.upokecenter.android.util.AppManager.java
com.upokecenter.android.util.BitmapUtility.java
com.upokecenter.android.util.StorageUtility.java
com.upokecenter.android.wallpaper.BaseWallpaperService.java
com.upokecenter.util.XmlHelper.java