コード例 #1
0
 @Override
 public Resources getResources() {
   if (mProxyActivity == this) {
     return super.getResources();
   } else {
     if (mProxyActivity != null) {
       return mProxyActivity.getResources();
     } else {
       return super.getResources();
     }
   }
 }
コード例 #2
0
  public QuranPageWorker(FragmentActivity activity) {
    mContext = activity;
    mResources = activity.getResources();
    ImageCacheFragment fragment =
        ImageCacheFragment.getImageCacheFragment(activity.getSupportFragmentManager());
    mMemoryCache = fragment.mRetainedCache;
    if (mMemoryCache != null) {
      return;
    }

    final int memClass =
        ((ActivityManager) activity.getSystemService(Context.ACTIVITY_SERVICE)).getMemoryClass();
    final int cacheSize = 1024 * 1024 * memClass / 8;
    final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024);
    Log.d(
        TAG,
        "memory class: " + memClass + ", cache size: " + cacheSize + ", max memory: " + maxMemory);
    mMemoryCache =
        new LruCache<String, BitmapDrawable>(cacheSize) {
          @Override
          protected void entryRemoved(
              boolean evicted, String key, BitmapDrawable oldValue, BitmapDrawable newValue) {
            if (RecyclingBitmapDrawable.class.isInstance(oldValue)) {
              ((RecyclingBitmapDrawable) oldValue).setIsCached(false);
            }
          }

          @Override
          protected int sizeOf(String key, BitmapDrawable bitmapDrawable) {
            Bitmap bitmap = bitmapDrawable.getBitmap();
            if (Build.VERSION.SDK_INT >= 12) {
              return bitmap.getByteCount();
            }

            Log.d(
                TAG,
                "row bytes: "
                    + bitmap.getRowBytes()
                    + ", height: "
                    + bitmap.getHeight()
                    + ", "
                    + (bitmap.getRowBytes() * bitmap.getHeight()));
            return bitmap.getRowBytes() * bitmap.getHeight();
          }
        };
    fragment.mRetainedCache = mMemoryCache;

    Log.d(TAG, "initial LruCache size: " + (memClass / 8));
  }
コード例 #3
0
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    ViewGroup rootView =
        (ViewGroup) inflater.inflate(R.layout.fragment_intro_first_page, container, false);

    Bitmap b =
        ImageHelper.getRoundedCornerBitmap(
            BitmapFactory.decodeResource(mContext.getResources(), mResId),
            Utilities.getDensityPixels(5, mContext));

    ImageView mPageImageView = ((ImageView) rootView.findViewById(R.id.introPageImageView));
    mPageImageView.setImageBitmap(b);

    return rootView;
  }
コード例 #4
0
  protected void viewsInit() {
    AppState.logX(
        TAG,
        String.format(
            "viewsInit: titleViewEmptyListTextSize = %f, " + "titleViewPluralsTextSize = %f",
            titleViewEmptyListTextSize, titleViewPluralsTextSize));

    final FragmentActivity activity = getActivity();

    getListView().setBackgroundColor(Background.windowBackgroundGet(activity));

    titleViewLayout = (LinearLayout) activity.findViewById(titleLayoutViewId);
    titleView = (TextView) activity.findViewById(titleViewId);
    titleDivider = (View) activity.findViewById(titleDividerId);
    // titleDivider.setBackgroundDrawable(Background.solidListDividerDrawableGet());
    titleDivider.setBackgroundColor(getResources().getColor(R.color.white));

    // check if the list is populated
    int count = list.size();
    if (count == 0) {
      titleViewLayout.setLayoutParams(
          new LinearLayout.LayoutParams(
              LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT));
      titleView.setLayoutParams(
          new LinearLayout.LayoutParams(
              LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT));

      titleView.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleViewEmptyListTextSize);
      titleView.setTextColor(Background.textColorGet(activity));
      titleView.setBackgroundColor(Background.windowBackgroundGet(activity));
      titleView.setGravity(titleViewEmptyListGravity);
      if (titleViewEmptyListString != null) titleView.setText(titleViewEmptyListString);
      else titleView.setText(titleViewEmptyListResid);
    } else {
      titleViewLayout.setLayoutParams(
          new LinearLayout.LayoutParams(
              LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT));
      titleView.setLayoutParams(
          new LinearLayout.LayoutParams(
              LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT));

      // display the list title
      titleView.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleViewPluralsTextSize);
      titleView.setTextColor(Background.textColorGet(activity));
      titleView.setTypeface(Typeface.DEFAULT_BOLD);
      titleView.setBackgroundColor(Background.listHeaderGet(activity));
      titleView.setGravity(titleViewPluralsGravity);
      String format = getResources().getQuantityText(titleViewPluralsResid, list.size()).toString();
      String title = String.format(format, titleViewPluralsParams);
      titleView.setText(title);

      listAdapter = new GenericListItemsAdapter(getActivity(), itemLayoutId, list);

      if ((listView = getListView()) == null)
        listView = (ListView) activity.findViewById(listViewId);

      listView.setDivider(Background.solidListDividerDrawableGet());
      listView.setDividerHeight(
          (int) activity.getResources().getDimension(R.dimen.default_line_spacer_height));
      listView.setLongClickable(true);
      setListAdapter(listAdapter);
      registerForContextMenu(listView);

      getListView().setOnScrollListener(this);
    }

    if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
      applyButtonResid = R.id.genericListItemsLeftButton;
      cancelButtonResid = R.id.genericListItemsRightButton;
    }

    if ((applyButton = (Button) activity.findViewById(applyButtonResid)) != null) {
      applyButton.setText(applyButtonLabel);
      applyButton.setOnClickListener(applyButtonListener);
      applyButton.setVisibility(
          count == 0 || listType == GenericListType.List ? Button.INVISIBLE : Button.VISIBLE);
      applyButton.setTextColor(Background.textColorGet(activity));
      applyButton.setBackgroundDrawable(Background.positiveButtonSelectorGet(activity));
    }

    if ((cancelButton = (Button) activity.findViewById(cancelButtonResid)) != null) {
      cancelButton.setText(cancelButtonLabel);
      cancelButton.setOnClickListener(cancelButtonListener);
      cancelButton.setVisibility(
          count == 0 || listType == GenericListType.List ? Button.INVISIBLE : Button.VISIBLE);
      cancelButton.setTextColor(Background.textColorGet(activity));
      cancelButton.setBackgroundDrawable(Background.negativeButtonSelectorGet(activity));
    }
  }
コード例 #5
0
 @Override
 protected void onPreExecute() {
   // TODO Auto-generated method stub
   super.onPreExecute();
   PromptUtil.showDialog(activity, activity.getResources().getString(R.string.loading));
 }
コード例 #6
0
 /**
  * Creates an ImageLoader with Bitmap memory cache.
  *
  * @param activity
  */
 public SimpleImageLoader(FragmentActivity activity) {
   super(
       newRequestQueue(activity, null),
       BitmapImageCache.getInstance(activity.getSupportFragmentManager()),
       activity.getResources());
 }
コード例 #7
0
 /** {@inheritDoc} */
 @Override
 public void setTitle(int resId) {
   mTitle = mActivity.getResources().getString(resId);
 }
コード例 #8
0
  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
    View view = convertView;
    int type = getItemViewType(position);
    if (view == null) {
      if (type == LOADING) view = inflater.inflate(R.layout.uv_loading_item, null);
      else if (type == FORUM) view = inflater.inflate(R.layout.uv_text_item, null);
      else if (type == KB_HEADER) view = inflater.inflate(R.layout.uv_header_item_light, null);
      else if (type == TOPIC) view = inflater.inflate(R.layout.uv_text_item, null);
      else if (type == CONTACT) view = inflater.inflate(R.layout.uv_text_item, null);
      else if (type == ARTICLE) view = inflater.inflate(R.layout.uv_text_item, null);
      else if (type == POWERED_BY) view = inflater.inflate(R.layout.uv_powered_by_item, null);
    }

    if (type == FORUM) {
      TextView textView = (TextView) view.findViewById(R.id.uv_text);
      textView.setText(R.string.uv_feedback_forum);
      TextView text2 = (TextView) view.findViewById(R.id.uv_text2);
      text2.setText(
          Utils.getQuantityString(
              text2,
              R.plurals.uv_ideas,
              Session.getInstance().getForum().getNumberOfOpenSuggestions()));
    } else if (type == KB_HEADER) {
      TextView textView = (TextView) view.findViewById(R.id.uv_header_text);
      textView.setText(R.string.uv_knowledge_base);
    } else if (type == TOPIC) {
      Topic topic = (Topic) getItem(position);
      TextView textView = (TextView) view.findViewById(R.id.uv_text);
      textView.setText(topic.getName());
      textView = (TextView) view.findViewById(R.id.uv_text2);
      if (topic.getId() == -1) {
        textView.setVisibility(View.GONE);
      } else {
        textView.setVisibility(View.VISIBLE);
        textView.setText(
            String.format(
                "%d %s",
                topic.getNumberOfArticles(),
                context
                    .getResources()
                    .getQuantityString(R.plurals.uv_articles, topic.getNumberOfArticles())));
      }
    } else if (type == CONTACT) {
      TextView textView = (TextView) view.findViewById(R.id.uv_text);
      textView.setText(R.string.uv_contact_us);
      view.findViewById(R.id.uv_text2).setVisibility(View.GONE);
    } else if (type == ARTICLE) {
      TextView textView = (TextView) view.findViewById(R.id.uv_text);
      Article article = (Article) getItem(position);
      textView.setText(article.getTitle());
    } else if (type == POWERED_BY) {
      TextView textView = (TextView) view.findViewById(R.id.uv_version);
      textView.setText(context.getString(R.string.uv_android_sdk) + " v" + UserVoice.getVersion());
    }

    View divider = view.findViewById(R.id.uv_divider);
    if (divider != null)
      divider.setVisibility(
          (position == getCount() - 2 && getItemViewType(getCount() - 1) == POWERED_BY)
                  || position == getCount() - 1
              ? View.GONE
              : View.VISIBLE);
    if (type == FORUM) divider.setVisibility(View.GONE);

    return view;
  }