Android Open Source - PalmaBici Resource Proxy Impl






From Project

Back to project page PalmaBici.

License

The source code is released under:

GNU General Public License

If you think the Android project PalmaBici 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 2012 Sergio Garcia Villalonga (yayalose@gmail.com)
 *//ww  w . jav a 2  s .c  om
 * This file is part of PalmaBici.
 *
 *    PalmaBici is free software: you can redistribute it and/or modify
 *    it under the terms of the Affero GNU General Public License version 3
 *    as published by the Free Software Foundation.
 *
 *    PalmaBici is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    Affero GNU General Public License for more details
 *    (https://www.gnu.org/licenses/agpl-3.0.html).
 *    
 * This file is a slightly modified version of the same contained at
 * the osmandroid API examples. Get it at https://code.google.com/p/osmdroid/
 */

package com.poguico.palmabici.map;

import org.osmdroid.DefaultResourceProxyImpl;

import com.poguico.palmabici.R;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.Drawable;

/**
 * This is an extension of {@link org.osmdroid.DefaultResourceProxyImpl}
 * that first tries to get from the resources that this class is defined in.
 * If you don't want to copy this to your own app, you could instead use {@link org.osmdroid.util.ResourceProxyImpl}.
 */
public class ResourceProxyImpl extends DefaultResourceProxyImpl {

  private final Context mContext;

  public ResourceProxyImpl(final Context pContext) {
    super(pContext);
    mContext = pContext;
  }

  @Override
  public String getString(final string pResId) {
    try {
      final int res = R.string.class.getDeclaredField(pResId.name()).getInt(null);
      return mContext.getString(res);
    } catch (final Exception e) {
      return super.getString(pResId);
    }
  }

  @Override
  public String getString(final string pResId, final Object... formatArgs) {
    try {
      final int res = R.string.class.getDeclaredField(pResId.name()).getInt(null);
      return mContext.getString(res, formatArgs);
    } catch (final Exception e) {
      return super.getString(pResId, formatArgs);
    }
  }

  @Override
  public Bitmap getBitmap(final bitmap pResId) {
    try {
      final int res = R.drawable.class.getDeclaredField(pResId.name()).getInt(null);
      return BitmapFactory.decodeResource(mContext.getResources(), res);
    } catch (final Exception e) {
      return super.getBitmap(pResId);
    }
  }
  
  public Bitmap getBitmap(final String pResId) {
    try {
      final int res = R.drawable.class.getDeclaredField(pResId).getInt(null);
      return BitmapFactory.decodeResource(mContext.getResources(), res);
    } catch (final Exception e) {
      e.printStackTrace();
    }
    return null;
  }

  @Override
  public Drawable getDrawable(final bitmap pResId) {
    try {
      final int res = R.drawable.class.getDeclaredField(pResId.name()).getInt(null);
      return mContext.getResources().getDrawable(res);
    } catch (final Exception e) {
      return super.getDrawable(pResId);
    }
  }
}




Java Source Code List

com.poguico.palmabici.DatabaseManager.java
com.poguico.palmabici.MainActivity.java
com.poguico.palmabici.PreferencesActivity.java
com.poguico.palmabici.ShareActivity.java
com.poguico.palmabici.SynchronizableElement.java
com.poguico.palmabici.WelcomeActivity.java
com.poguico.palmabici.map.OpenStreetMapConstants.java
com.poguico.palmabici.map.ResourceProxyImpl.java
com.poguico.palmabici.map.StationMapFragment.java
com.poguico.palmabici.network.synchronizer.NetworkStationAlarm.java
com.poguico.palmabici.network.synchronizer.NetworkSyncCallback.java
com.poguico.palmabici.network.synchronizer.NetworkSynchronizerTask.java
com.poguico.palmabici.network.synchronizer.NetworkSynchronizer.java
com.poguico.palmabici.notification.NotificationManager.java
com.poguico.palmabici.parsers.Parser.java
com.poguico.palmabici.synchronizers.LocationSynchronizer.java
com.poguico.palmabici.util.BikeLane.java
com.poguico.palmabici.util.Formatter.java
com.poguico.palmabici.util.NetworkInformation.java
com.poguico.palmabici.util.Station.java
com.poguico.palmabici.widgets.CreditsDialog.java
com.poguico.palmabici.widgets.NewFeaturesDialog.java
com.poguico.palmabici.widgets.SidebarMenu.java
com.poguico.palmabici.widgets.StationInfoWidget.java