Android Open Source - My-Wallet-Android Action Bar Fragment






From Project

Back to project page My-Wallet-Android.

License

The source code is released under:

GNU General Public License

If you think the Android project My-Wallet-Android 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 2011-2012 the original author or authors.
 */*ww w.  ja  v a2s.  co  m*/
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program 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
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package piuk.blockchain.android.util;

import android.app.Activity;
import android.content.res.Resources;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.ImageView.ScaleType;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.TextView;
import piuk.blockchain.R;

/**
 * @author Andreas Schildbach
 */
public final class ActionBarFragment extends Fragment
{
  private ViewGroup view;
  private View backButtonView;
  private View backView;
  private ImageView iconView;
  private TextView primaryTitleView;
  private TextView secondaryTitleView;

  private LinearLayout.LayoutParams separatorParams;

  @Override
  public View onCreateView(final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState)
  {
    view = (ViewGroup) inflater.inflate(R.layout.action_bar_fragment, container);
    backButtonView = view.findViewById(R.id.action_bar_back_button);
    backView = view.findViewById(R.id.action_bar_back);
    iconView = (ImageView) view.findViewById(R.id.action_bar_icon);
    primaryTitleView = (TextView) view.findViewById(R.id.action_bar_primary_title);
    secondaryTitleView = (TextView) view.findViewById(R.id.action_bar_secondary_title);

    return view;
  }

  @Override
  public void onAttach(final Activity activity)
  {
    final Resources res = getResources();
    final int separatorWidth = res.getDimensionPixelSize(R.dimen.action_bar_button_separator_width);
    final int separatorMargin = res.getDimensionPixelSize(R.dimen.action_bar_button_separator_margin);

    separatorParams = new LinearLayout.LayoutParams(separatorWidth, android.view.ViewGroup.LayoutParams.FILL_PARENT, 0f);
    separatorParams.setMargins(0, separatorMargin, 0, separatorMargin);

    super.onAttach(activity);
  }

  public void setIcon(final int iconRes)
  {
    iconView.setImageResource(iconRes);
  }

  public void setBack(final OnClickListener onClickListener)
  {
    backButtonView.setOnClickListener(onClickListener);
    backView.setVisibility(View.VISIBLE);
  }

  public TextView getPrimaryTitleView() {
    return primaryTitleView;
  }

  public void setPrimaryTitleView(TextView primaryTitleView) {
    this.primaryTitleView = primaryTitleView;
  }

  public void setPrimaryTitle(final CharSequence title)
  {
    primaryTitleView.setText(title);
  }

  public void setPrimaryTitle(final int titleRes)
  {
    primaryTitleView.setText(titleRes);
  }

  public void setSecondaryTitle(final CharSequence title)
  {
    secondaryTitleView.setText(title);
    secondaryTitleView.setVisibility(title != null ? View.VISIBLE : View.GONE);
    primaryTitleView.setSingleLine(title != null);
  }

  public ImageButton addButton(final int drawableRes)
  {
    final LinearLayout.LayoutParams buttonParams = new LinearLayout.LayoutParams(getResources().getDimensionPixelSize(
        R.dimen.action_bar_button_width), android.view.ViewGroup.LayoutParams.FILL_PARENT, 0f);
    buttonParams.gravity = Gravity.CENTER_VERTICAL;

    final ImageButton button = new ImageButton(getActivity());
    button.setImageResource(drawableRes);
    button.setScaleType(ScaleType.CENTER);
    button.setBackgroundResource(R.drawable.action_bar_background);
    button.setPadding(0, 0, 0, 0);
    view.addView(button, 2, buttonParams);

    final ImageView separator1 = new ImageView(getActivity());
    separator1.setImageDrawable(new ColorDrawable(Color.parseColor("#44ffffff")));
    view.addView(separator1, 2, separatorParams);

    final ImageView separator2 = new ImageView(getActivity());
    separator2.setImageDrawable(new ColorDrawable(Color.parseColor("#44000000")));
    view.addView(separator2, 2, separatorParams);

    return button;
  }

  public boolean removeButton(final ImageButton button)
  {
    final int index = view.indexOfChild(button);
    if (index == -1)
      return false;

    view.removeViews(index - 2, 3);
    return true;
  }
}




Java Source Code List

piuk.BitcoinAddress.java
piuk.BitcoinScript.java
piuk.Hash.java
piuk.MyBlockChain.java
piuk.MyRemoteWallet.java
piuk.MyTransactionConfidence.java
piuk.MyTransactionInput.java
piuk.MyTransactionOutPoint.java
piuk.MyTransactionOutput.java
piuk.MyTransaction.java
piuk.MyWallet.java
piuk.blockchain.android.AddressBookProvider.java
piuk.blockchain.android.BlockchainService.java
piuk.blockchain.android.Constants.java
piuk.blockchain.android.DetermineFirstSeenThread.java
piuk.blockchain.android.ExchangeRatesProvider.java
piuk.blockchain.android.WalletApplication.java
piuk.blockchain.android.WalletBalanceWidgetProvider.java
piuk.blockchain.android.ui.AbstractWalletActivity.java
piuk.blockchain.android.ui.AmountCalculatorFragment.java
piuk.blockchain.android.ui.CurrencyAmountView.java
piuk.blockchain.android.ui.CurrencyCodeDrawable.java
piuk.blockchain.android.ui.EditAddressBookEntryFragment.java
piuk.blockchain.android.ui.ExchangeRatesFragment.java
piuk.blockchain.android.ui.NewAccountFragment.java
piuk.blockchain.android.ui.PairWalletActivity.java
piuk.blockchain.android.ui.PreferencesActivity.java
piuk.blockchain.android.ui.RequestCoinsActivity.java
piuk.blockchain.android.ui.RequestCoinsFragment.java
piuk.blockchain.android.ui.SecondPasswordFragment.java
piuk.blockchain.android.ui.SendCoinsActivity.java
piuk.blockchain.android.ui.SendCoinsFragment.java
piuk.blockchain.android.ui.SendingAddressesFragment.java
piuk.blockchain.android.ui.TransactionActivity.java
piuk.blockchain.android.ui.TransactionFragment.java
piuk.blockchain.android.ui.WalletActivity.java
piuk.blockchain.android.ui.WalletAddressesFragment.java
piuk.blockchain.android.ui.WalletBalanceFragment.java
piuk.blockchain.android.ui.WalletTransactionsFragment.java
piuk.blockchain.android.ui.WelcomeFragment.java
piuk.blockchain.android.util.ActionBarFragment.java
piuk.blockchain.android.util.Base43.java
piuk.blockchain.android.util.CircularProgressView.java
piuk.blockchain.android.util.ErrorReporter.java
piuk.blockchain.android.util.IOUtils.java
piuk.blockchain.android.util.Iso8601Format.java
piuk.blockchain.android.util.NfcTools.java
piuk.blockchain.android.util.QrDialog.java
piuk.blockchain.android.util.ViewPagerTabs.java
piuk.blockchain.android.util.WalletUtils.java