Пример #1
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Bundle args = getArguments();
    if (args != null) {
      if (args.containsKey(Constants.ARG_ACCOUNT_ID)) {
        String accountId = args.getString(Constants.ARG_ACCOUNT_ID);
        pocket = checkNotNull(application.getAccount(accountId));
      }

      if (args.containsKey(Constants.ARG_URI)) {
        try {
          processUri(args.getString(Constants.ARG_URI));
        } catch (CoinURIParseException e) {
          // TODO handle more elegantly
          Toast.makeText(getActivity(), e.getMessage(), Toast.LENGTH_LONG).show();
          ACRA.getErrorReporter().handleException(e);
        }
      }
      if (pocket == null) {
        List<WalletAccount> accounts = application.getAllAccounts();
        if (accounts.size() > 0) pocket = accounts.get(0);
        if (pocket == null) {
          ACRA.getErrorReporter()
              .putCustomData("wallet-exists", application.getWallet() == null ? "no" : "yes");
          Toast.makeText(getActivity(), R.string.no_such_pocket_error, Toast.LENGTH_LONG).show();
          getActivity().finish();
          return;
        }
      }
      checkNotNull(pocket, "No account selected");
    } else {
      throw new RuntimeException("Must provide account ID or a payment URI");
    }

    sendAmountType = pocket.getCoinType();

    messageFactory = pocket.getCoinType().getMessagesFactory();

    if (savedInstanceState != null) {
      address = (Address) savedInstanceState.getSerializable(STATE_ADDRESS);
      addressTypeCanChange = savedInstanceState.getBoolean(STATE_ADDRESS_CAN_CHANGE_TYPE);
      sendAmount = (Value) savedInstanceState.getSerializable(STATE_AMOUNT);
      sendAmountType = (CoinType) savedInstanceState.getSerializable(STATE_AMOUNT_TYPE);
    }

    updateBalance();
    setHasOptionsMenu(true);
    mNavigationDrawerFragment =
        (NavigationDrawerFragment) getFragmentManager().findFragmentById(R.id.navigation_drawer);

    String localSymbol = config.getExchangeCurrencyCode();
    for (ExchangeRatesProvider.ExchangeRate rate : getRates(getActivity(), localSymbol)) {
      localRates.put(rate.currencyCodeId, rate.rate);
    }

    loaderManager.initLoader(ID_RATE_LOADER, null, rateLoaderCallbacks);
    loaderManager.initLoader(ID_RECEIVING_ADDRESS_LOADER, null, receivingAddressLoaderCallbacks);
  }
Пример #2
0
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final MyExpenses ctx = (MyExpenses) getActivity();
    if (mAccount == null) {
      TextView tv = new TextView(ctx);
      tv.setText(
          "Error loading transaction list for account " + getArguments().getLong(KEY_ACCOUNTID));
      return tv;
    }
    mManager = getLoaderManager();
    setGrouping();
    setColors();

    View v = inflater.inflate(R.layout.expenses_list, null, false);
    // TODO check if still needed with Appcompat
    // work around the problem that the view pager does not display its background correctly with
    // Sherlock
    if (Build.VERSION.SDK_INT < 11) {
      v.setBackgroundColor(
          ctx.getResources()
              .getColor(
                  MyApplication.PrefKey.UI_THEME_KEY.value("dark").equals("light")
                      ? android.R.color.white
                      : android.R.color.black));
    }
    mListView = (StickyListHeadersListView) v.findViewById(R.id.list);
    setAdapter();
    mListView.setOnHeaderClickListener(this);
    mListView.setDrawingListUnderStickyHeader(false);
    mManager.initLoader(GROUPING_CURSOR, null, this);
    mManager.initLoader(TRANSACTION_CURSOR, null, this);
    mManager.initLoader(SUM_CURSOR, null, this);
    // Now create a simple cursor adapter and set it to display

    mListView.setEmptyView(v.findViewById(R.id.empty));
    mListView.setOnItemClickListener(
        new OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView<?> a, View v, int position, long id) {
            FragmentManager fm = ctx.getSupportFragmentManager();
            DialogFragment f = (DialogFragment) fm.findFragmentByTag("TRANSACTION_DETAIL");
            if (f == null) {
              FragmentTransaction ft = getFragmentManager().beginTransaction();
              ft.add(TransactionDetailFragment.newInstance(id), "TRANSACTION_DETAIL");
              ft.commitAllowingStateLoss();
            }
          }
        });
    registerForContextualActionBar(mListView.getWrappedList());
    return v;
  }
Пример #3
0
  @Override
  public void onResume() {
    super.onResume();

    activity.registerReceiver(
        broadcastReceiver, new IntentFilter(BlockchainService.ACTION_BLOCKCHAIN_STATE));

    loaderManager.initLoader(ID_BALANCE_LOADER, null, balanceLoaderCallbacks);
    loaderManager.initLoader(ID_RATE_LOADER, null, rateLoaderCallbacks);

    defaultCurrency = prefs.getString(Constants.PREFS_KEY_EXCHANGE_CURRENCY, null);
    prefs.registerOnSharedPreferenceChangeListener(this);

    updateView();
  }
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.apps_fragment, container, false);

    mListView = (ListView) view.findViewById(android.R.id.list);
    mProgressBar = view.findViewById(android.R.id.progress);
    mEmptyView = view.findViewById(android.R.id.empty);
    mErrorReporter = new ErrorReporter(getActivity(), view, AppContract.Apps.CONTENT_URI);

    mListView.setOnItemClickListener(this);

    Bitmap placeHolder = BitmapFactory.decodeResource(getResources(), R.drawable.placeholder);
    mRemoteImageLoader =
        RemoteImageLoader.createUsingDp(getActivity(), placeHolder, IMAGE_SIZE_DP, IMAGE_SIZE_DP);

    mAdapter = new AppsAdapter(getActivity(), mRemoteImageLoader, this);
    mListView.setAdapter(mAdapter);

    mDownloadHelper =
        new DownloadHelper(
            getActivity(), DownloadService.ACTION_SYNC, this, AppContract.Apps.CONTENT_URI);
    LoaderManager lm = getLoaderManager();
    lm.initLoader(LOADER_APPS, null, this);

    setHasOptionsMenu(true);

    return view;
  }
  public synchronized void doFilter(String filterString) {

    mSearchString = filterString;

    if (mContactAdapter == null) {

      mContactAdapter = new ContactAdapter(mContext, R.layout.contact_view);

      ((ListView) mFilterList).setAdapter(mContactAdapter);

      mLoaderCallbacks = new MyLoaderCallbacks();
      mLoaderManager.initLoader(mLoaderId, null, mLoaderCallbacks);
    } else {

      if (!mAwaitingUpdate) {
        mAwaitingUpdate = true;
        mHandler.postDelayed(
            new Runnable() {

              public void run() {

                mLoaderManager.restartLoader(mLoaderId, null, mLoaderCallbacks);
                mAwaitingUpdate = false;
              }
            },
            1000);
      }
    }
  }
 /** Loads initial blog posts. */
 public void loadPosts(boolean reload) {
   LoaderManager loaderManager = getLoaderManager();
   if (reload) {
     loaderManager.restartLoader(BLOG_LOADER_ID, null, this);
   } else {
     loaderManager.initLoader(BLOG_LOADER_ID, null, this);
   }
 }
 @Override
 public void onViewCreated(View view, Bundle savedInstanceState) {
   super.onViewCreated(view, savedInstanceState);
   // 管理cursor
   LoaderManager loaderManager = getLoaderManager();
   // 注册Loader
   loaderManager.initLoader(LOADER_ID, null, this);
 }
  @Override
  public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    LoaderManager mgr = getActivity().getSupportLoaderManager();

    mgr.initLoader(ARRIVALS_LIST_LOADER, getArguments(), this).forceLoad();
  }
Пример #9
0
 @Override
 public void onStart() {
   super.onStart();
   LoaderManager lm = getLoaderManager();
   if (lm.getLoader(1) != null) {
     lm.initLoader(1, null, this);
   }
   getLoaderManager().initLoader(1, null, this);
 }
Пример #10
0
  @Override
  public void onResume() {
    super.onResume();

    activity.registerReceiver(tickReceiver, new IntentFilter(Intent.ACTION_TIME_TICK));

    loaderManager.initLoader(ID_TRANSACTION_LOADER, null, transactionLoaderCallbacks);

    adapter.notifyDataSetChanged();
  }
  @Override
  public void onResume() {
    super.onResume();

    activity.registerReceiver(
        broadcastReceiver, new IntentFilter(BlockchainService.ACTION_BLOCKCHAIN_STATE));

    loaderManager.initLoader(ID_BALANCE_LOADER, null, balanceLoaderCallbacks);

    updateView();
  }
Пример #12
0
 private void onResume() {
   Log.d(TAG, "##### onResume #### " + person);
   // context.getContentResolver().registerContentObserver(GeoTrackerProvider.Constants.CONTENT_URI,
   // true, new MyContentObserver(uiHandler));
   // Prefs
   this.sharedPreferences.registerOnSharedPreferenceChangeListener(this);
   // Listener
   context.registerReceiver(mStatusReceiver, mStatusReceiverIntentFilter);
   // Load Data
   loaderManager.initLoader(GEOTRACK_LIST_LOADER, null, geoTrackLoaderCallback);
 }
Пример #13
0
 private void cargarListaDesdeBD() {
   // Se inicializa el cargador.
   gestor.initLoader(IMAGENES_LOADER, null, this);
   // Se crea un adaptador inicial con el cursor nulo.
   String[] from = new String[] {BD.Imagen.USERNAME, BD.Imagen.THUMBNAIL};
   int[] to = new int[] {R.id.lblUsuario, R.id.imgFoto};
   adaptador = new ImagenesCursorAdapter(this.getActivity(), null, from, to);
   // Se visualiza o oculta el relative layout de lista vacía.
   rlListaFotosVacia.setVisibility((adaptador.getCount() > 0) ? View.INVISIBLE : View.VISIBLE);
   lstFotos.setAdapter(adaptador);
 }
Пример #14
0
  @Override
  public View getView(int i, View view, ViewGroup viewGroup) {
    final ViewHolder holder;
    if (view == null) {
      view = View.inflate(context, R.layout.main_pulltorefresh_item, null);
      holder = new ViewHolder();
      holder.iv = (ImageView) view.findViewById(R.id.main_pull_imageView);
      holder.tv_title = (TextView) view.findViewById(R.id.main_pull_item_title);
      holder.tv_sendTime = (TextView) view.findViewById(R.id.main_pull_item_sendtime);
      holder.tv_feedback = (TextView) view.findViewById(R.id.main_pull_item_feedback);
      view.setTag(holder);
    } else {
      holder = (ViewHolder) view.getTag();
    }
    HashMap<String, String> map = data.get(i);
    holder.tv_title.setText(map.get("shorttitle"));

    long senddate = Long.parseLong(map.get("senddate"));
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    String sendtime = sdf.format(senddate);
    holder.tv_sendTime.setText(sendtime);
    holder.tv_feedback.setText(map.get("click"));

    holder.iv.setImageResource(R.drawable.img_default);
    String imgPath = map.get("imgPath");
    Bundle bundle = new Bundle();
    bundle.putString("imgPath", imgPath);
    loaderManager.initLoader(
        loader_index++,
        bundle,
        new LoaderManager.LoaderCallbacks<Bitmap>() {
          @Override
          public Loader<Bitmap> onCreateLoader(int id, Bundle args) {
            return new ImagAsyncLoader(context, args);
          }

          @Override
          public void onLoadFinished(Loader<Bitmap> loader, Bitmap data) {
            if (data != null) {
              holder.iv.setImageBitmap(data);
            } else {
              Toast.makeText(context, "图片加载加载异常", Toast.LENGTH_SHORT).show();
            }
          }

          @Override
          public void onLoaderReset(Loader<Bitmap> loader) {
            holder.iv.setImageBitmap(null);
          }
        });

    return view;
  }
Пример #15
0
 private void restartGroupingLoader() {
   mGroupingCursor = null;
   if (mManager == null) {
     // can happen after an orientation change in ExportDialogFragment, when resetting multiple
     // accounts
     mManager = getLoaderManager();
   }
   if (mManager.getLoader(GROUPING_CURSOR) != null
       && !mManager.getLoader(GROUPING_CURSOR).isReset())
     mManager.restartLoader(GROUPING_CURSOR, null, this);
   else mManager.initLoader(GROUPING_CURSOR, null, this);
 }
Пример #16
0
 @Override
 public View onCreateView(
     LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
   View v = inflater.inflate(R.layout.templates_list, null, false);
   ListView lv = (ListView) v.findViewById(R.id.list);
   mManager = getLoaderManager();
   mManager.initLoader(0, null, this);
   // Create an array to specify the fields we want to display in the list
   String[] from = new String[] {DatabaseConstants.KEY_TITLE, DatabaseConstants.KEY_PLANID};
   // and an array of the fields we want to bind those fields to
   int[] to = new int[] {R.id.title, R.id.plan};
   mAdapter =
       new SimpleCursorAdapter(getActivity(), R.layout.template_row, null, from, to, 0) {
         @Override
         public View getView(int position, View convertView, ViewGroup parent) {
           convertView = super.getView(position, convertView, parent);
           convertView.findViewById(R.id.apply).setTag(getItemId(position));
           Cursor c = getCursor();
           c.moveToPosition(position);
           int color = c.getInt(c.getColumnIndex("color"));
           convertView.findViewById(R.id.colorAccount).setBackgroundColor(color);
           return convertView;
         }
       };
   mAdapter.setViewBinder(
       new SimpleCursorAdapter.ViewBinder() {
         public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
           if (view.getId() == R.id.plan) {
             view.setVisibility(
                 (DbUtils.getLongOrNull(cursor, DatabaseConstants.KEY_PLANID) == null)
                     ? View.INVISIBLE
                     : View.VISIBLE);
             return true;
           }
           return false;
         }
       });
   lv.setAdapter(mAdapter);
   lv.setEmptyView(v.findViewById(R.id.empty));
   // requires using activity (ManageTemplates) to implement OnChildClickListener
   // lv.setOnChildClickListener((OnChildClickListener) getActivity());
   lv.setOnItemClickListener(
       new OnItemClickListener() {
         @Override
         public void onItemClick(AdapterView<?> a, View v, int position, long id) {
           TemplateDetailFragment.newInstance(id)
               .show(getActivity().getSupportFragmentManager(), "TEMPLATE_DETAIL");
         }
       });
   registerForContextMenu(lv);
   return v;
 }
Пример #17
0
  /**
   * Helper method to initialize the loader and callbacks using searchId
   *
   * <p>If the loader doesn't already exist, one is created and (if the activity/fragment is
   * currently started) starts the loader. Otherwise the last created loader with that id is
   * re-used.
   *
   * @param loaderId
   * @param context
   * @param loaderManager
   * @param loaderListener
   * @param searchId
   * @param dataSource
   */
  public static void initLoader(
      @PhotosLoaderId int loaderId,
      Context context,
      LoaderManager loaderManager,
      PhotosLoaderListener loaderListener,
      @NonNull String searchId,
      int dataSource) {
    Bundle args = new Bundle(2);
    args.putInt(ARG_DATASOURCE, dataSource);
    args.putString(ARG_SEARCH_ID, searchId);

    // call loader manager's init loader
    loaderManager.initLoader(loaderId, args, new PhotosLoaderCallbacks(context, loaderListener));
  }
  @Override
  public void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setRetainInstance(true);

    adapter = new ExchangeRatesAdapter(activity);
    setListAdapter(adapter);

    loaderManager.initLoader(ID_RATE_LOADER, null, rateLoaderCallbacks);

    defaultCurrency = config.getExchangeCurrencyCode();
    config.registerOnSharedPreferenceChangeListener(this);
  }
Пример #19
0
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    super.onCreateView(inflater, container, savedInstanceState);
    View view = inflater.inflate(R.layout.fragment_visitor_list, container, false);

    getActivity().setTitle("Last Visitors");
    String[] from = {};
    int[] to = {};
    mLoader.initLoader(0, null, this);
    mAdapter = new VisitorsViewAdapter(getActivity(), R.layout.row_visitor, cur, from, to, this);
    setListAdapter(mAdapter);

    return view;
  }
Пример #20
0
  /**
   * Loads and initializes the pager.
   *
   * @param fm FragmentManager for the adapter
   */
  public void show(
      LoaderManager lm, FragmentManager fm, String panelId, PropertyAnimator animator) {
    mLoaded = true;
    mInitialPanelId = panelId;

    // Only animate on post-HC devices, when a non-null animator is given
    final boolean shouldAnimate = (animator != null && Build.VERSION.SDK_INT >= 11);

    final HomeAdapter adapter = new HomeAdapter(mContext, fm);
    adapter.setOnAddPanelListener(mAddPanelListener);
    adapter.setCanLoadHint(!shouldAnimate);
    setAdapter(adapter);

    setVisibility(VISIBLE);

    // Don't show the tabs strip until we have the
    // list of panels in place.
    mTabStrip.setVisibility(View.INVISIBLE);

    // Load list of panels from configuration. Restart the loader if necessary.
    if (mRestartLoader) {
      lm.restartLoader(LOADER_ID_CONFIG, null, mConfigLoaderCallbacks);
      mRestartLoader = false;
    } else {
      lm.initLoader(LOADER_ID_CONFIG, null, mConfigLoaderCallbacks);
    }

    if (shouldAnimate) {
      animator.addPropertyAnimationListener(
          new PropertyAnimator.PropertyAnimationListener() {
            @Override
            public void onPropertyAnimationStart() {
              setLayerType(View.LAYER_TYPE_HARDWARE, null);
            }

            @Override
            public void onPropertyAnimationEnd() {
              setLayerType(View.LAYER_TYPE_NONE, null);
              adapter.setCanLoadHint(true);
            }
          });

      ViewHelper.setAlpha(this, 0.0f);

      animator.attach(this, PropertyAnimator.Property.ALPHA, 1.0f);
    }
  }
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setRetainInstance(true);
    setHasOptionsMenu(true);

    // Check for a Item ID as an argument, and find the item
    Bundle args = getArguments();
    if (args != null) {
      long armorId = args.getLong(ARG_ARMOR_ID, -1);
      if (armorId != -1) {
        LoaderManager lm = getLoaderManager();
        lm.initLoader(R.id.armor_detail_fragment, args, new ArmorLoaderCallbacks());
      }
    }
  }
Пример #22
0
  @Override
  public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    // create and auto start loader
    LoaderManager loaderManager = this.getLoaderManager();
    loaderManager.destroyLoader(0);
    loaderManager.initLoader(0, null, this);

    this.mAdapter = new LocationsAdapter(getActivity(), R.layout.fragment_locations_item_view);

    this.setListAdapter(mAdapter);
    this.isListShown = true;
    this.setListShown(false);

    this.getActivity().invalidateOptionsMenu();
  }
  @Override
  public void onResume() {
    super.onResume();

    amountCalculatorLink.setListener(
        new CurrencyAmountView.Listener() {
          @Override
          public void changed() {
            updateView();
            updateShareIntent();
          }

          @Override
          public void focusChanged(final boolean hasFocus) {}
        });

    addressView.setOnItemSelectedListener(
        new OnItemSelectedListener() {
          @Override
          public void onItemSelected(
              final AdapterView<?> parent, final View view, final int position, final long id) {
            // ignore layout operations
            if (view == null) return;

            updateView();
            //				updateShareIntent();
          }

          @Override
          public void onNothingSelected(final AdapterView<?> parent) {}
        });

    loaderManager.initLoader(ID_RATE_LOADER, null, rateLoaderCallbacks);

    if (ENABLE_BLUETOOTH_LISTENING
        && bluetoothAdapter != null
        && bluetoothAdapter.isEnabled()
        && acceptBluetoothPaymentView.isChecked()) startBluetoothListening();

    updateView();
  }
  /** Called when the activity is first created. */
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    Bundle bundle = new Bundle();
    bundle.putString("path", "this is path");
    LoaderManager manager = getSupportLoaderManager();
    manager.initLoader(
        444,
        bundle,
        new LoaderManager.LoaderCallbacks<String>() {
          public Loader<String> onCreateLoader(int i, Bundle bundle) {
            String path = bundle == null ? null : bundle.getString("path");
            WeatherLoader loader = new WeatherLoader(MyActivity.this, path);
            return loader;
          }

          public void onLoadFinished(Loader<String> loader, String s) {
            Log.d("--------->", "onLoadFinished:" + s);
          }

          public void onLoaderReset(Loader<String> loader) {}
        });
  }
Пример #25
0
  private void loadImageIntoCatroid(Intent intent) {
    String originalImagePath = "";

    // get path of image - will work for most applications
    Bundle bundle = intent.getExtras();
    if (bundle != null) {
      originalImagePath = bundle.getString(Constants.EXTRA_PICTURE_PATH_POCKET_PAINT);
    }

    if (originalImagePath == null || originalImagePath.equals("")) {
      Bundle arguments = new Bundle();
      arguments.putParcelable(LOADER_ARGUMENTS_IMAGE_URI, intent.getData());

      LoaderManager loaderManager = getLoaderManager();

      if (loaderManager.getLoader(ID_LOADER_MEDIA_IMAGE) == null) {
        loaderManager.initLoader(ID_LOADER_MEDIA_IMAGE, arguments, this);
      } else {
        loaderManager.restartLoader(ID_LOADER_MEDIA_IMAGE, arguments, this);
      }
    } else {
      copyImageToCatroid(originalImagePath);
    }
  }
  @Override
  public void onResume() {
    super.onResume();

    amountCalculatorLink.setListener(
        new CurrencyAmountView.Listener() {
          @Override
          public void changed() {
            updateView();
          }

          @Override
          public void focusChanged(final boolean hasFocus) {}
        });

    loaderManager.initLoader(ID_RATE_LOADER, null, rateLoaderCallbacks);

    if (ENABLE_BLUETOOTH_LISTENING
        && bluetoothAdapter != null
        && bluetoothAdapter.isEnabled()
        && acceptBluetoothPaymentView.isChecked()) startBluetoothListening();

    updateView();
  }
Пример #27
0
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.templates_list, container, false);
    mListView = (ListView) v.findViewById(R.id.list);

    mManager = getLoaderManager();
    mManager.initLoader(SORTABLE_CURSOR, null, this);
    // Create an array to specify the fields we want to display in the list
    String[] from = new String[] {KEY_TITLE, KEY_LABEL_MAIN, KEY_AMOUNT};
    // and an array of the fields we want to bind those fields to
    int[] to = new int[] {R.id.title, R.id.category, R.id.amount};
    mAdapter = new MyAdapter(getActivity(), R.layout.template_row, null, from, to, 0);
    mListView.setAdapter(mAdapter);
    mListView.setEmptyView(v.findViewById(R.id.empty));
    mListView.setOnItemClickListener(
        new OnItemClickListener() {

          @Override
          public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            if (mTemplatesCursor == null || !mTemplatesCursor.moveToPosition(position)) return;
            if (!mTemplatesCursor.isNull(columnIndexPlanId)) {
              if (isCalendarPermissionGranted()) {
                planMonthFragment =
                    PlanMonthFragment.newInstance(
                        mTemplatesCursor.getString(columnIndexTitle),
                        id,
                        mTemplatesCursor.getLong(columnIndexPlanId),
                        mTemplatesCursor.getInt(columnIndexColor),
                        false);
                planMonthFragment.show(getChildFragmentManager(), CALDROID_DIALOG_FRAGMENT_TAG);
              } else {
                ((ProtectedFragmentActivity) getActivity()).requestCalendarPermission();
              }
            } else if (isForeignExchangeTransfer(position)) {
              ((ManageTemplates) getActivity())
                  .dispatchCommand(R.id.CREATE_INSTANCE_EDIT_COMMAND, id);
            } else if (PrefKey.TEMPLATE_CLICK_HINT_SHOWN.getBoolean(false)) {
              if (PrefKey.TEMPLATE_CLICK_DEFAULT.getString("SAVE").equals("SAVE")) {
                dispatchCreateInstanceSave(new Long[] {id});
              } else {
                dispatchCreateInstanceEdit(id);
              }
            } else {
              Bundle b = new Bundle();
              b.putLong(KEY_ROWID, id);
              b.putInt(ConfirmationDialogFragment.KEY_TITLE, R.string.dialog_title_information);
              b.putString(
                  ConfirmationDialogFragment.KEY_MESSAGE, getString(R.string.hint_template_click));
              b.putInt(
                  ConfirmationDialogFragment.KEY_COMMAND_POSITIVE,
                  R.id.CREATE_INSTANCE_SAVE_COMMAND);
              b.putInt(
                  ConfirmationDialogFragment.KEY_COMMAND_NEGATIVE,
                  R.id.CREATE_INSTANCE_EDIT_COMMAND);
              b.putString(
                  ConfirmationDialogFragment.KEY_PREFKEY,
                  PrefKey.TEMPLATE_CLICK_HINT_SHOWN.getKey());
              b.putInt(
                  ConfirmationDialogFragment.KEY_POSITIVE_BUTTON_LABEL,
                  R.string.menu_create_instance_save);
              b.putInt(
                  ConfirmationDialogFragment.KEY_NEGATIVE_BUTTON_LABEL,
                  R.string.menu_create_instance_edit);
              ConfirmationDialogFragment.newInstance(b)
                  .show(getFragmentManager(), "TEMPLATE_CLICK_HINT");
            }
          }
        });
    registerForContextualActionBar(mListView);
    return v;
  }
Пример #28
0
        @Override
        public void onServiceConnected(final ComponentName name, final IBinder binder) {
          service = ((BlockchainServiceImpl.LocalBinder) binder).getService();

          loaderManager.initLoader(ID_BLOCK_LOADER, null, blockLoaderCallbacks);
        }
 @Override
 public void loadCities() {
   loaderManager.initLoader(CITIES_LOADER, Bundle.EMPTY, this);
 }
  @Override
  public Dialog onCreateDialog(Bundle savedInstanceState) {
    final MyExpenses ctx = (MyExpenses) getActivity();
    Context wrappedCtx = DialogUtils.wrapContext2(ctx);
    if (mTransaction == null) {
      return new AlertDialog.Builder(wrappedCtx)
          .setMessage("Transaction has been deleted")
          .create();
    }
    final LayoutInflater li = LayoutInflater.from(wrappedCtx);
    View view = li.inflate(R.layout.transaction_detail, null);
    int title;
    boolean type =
        mTransaction.amount.getAmountMinor() > 0 ? ExpenseEdit.INCOME : ExpenseEdit.EXPENSE;
    if (mTransaction instanceof SplitTransaction) {
      // TODO: refactor duplicated code with SplitPartList
      title = R.string.split_transaction;
      View emptyView = view.findViewById(R.id.empty);
      Resources.Theme theme = ctx.getTheme();
      TypedValue color = new TypedValue();
      theme.resolveAttribute(R.attr.colorExpense, color, true);
      final int colorExpense = color.data;
      theme.resolveAttribute(R.attr.colorIncome, color, true);
      final int colorIncome = color.data;

      ListView lv = (ListView) view.findViewById(R.id.list);
      // Create an array to specify the fields we want to display in the list
      String[] from = new String[] {KEY_LABEL_MAIN, KEY_AMOUNT};

      // and an array of the fields we want to bind those fields to
      int[] to = new int[] {R.id.category, R.id.amount};

      final String categorySeparator, commentSeparator;
      categorySeparator = " : ";
      commentSeparator = " / ";
      // Now create a simple cursor adapter and set it to display
      mAdapter =
          new SimpleCursorAdapter(ctx, R.layout.split_part_row, null, from, to, 0) {
            /* (non-Javadoc)
             * calls {@link #convText for formatting the values retrieved from the cursor}
             * @see android.widget.SimpleCursorAdapter#setViewText(android.widget.TextView, java.lang.String)
             */
            @Override
            public void setViewText(TextView v, String text) {
              switch (v.getId()) {
                case R.id.amount:
                  text = Utils.convAmount(text, mTransaction.amount.getCurrency());
              }
              super.setViewText(v, text);
            }
            /* (non-Javadoc)
             * manipulates the view for amount (setting expenses to red) and
             * category (indicate transfer direction with => or <=
             * @see android.widget.CursorAdapter#getView(int, android.view.View, android.view.ViewGroup)
             */
            @Override
            public View getView(int position, View convertView, ViewGroup parent) {
              View row = super.getView(position, convertView, parent);
              TextView tv1 = (TextView) row.findViewById(R.id.amount);
              Cursor c = getCursor();
              c.moveToPosition(position);
              int col = c.getColumnIndex(KEY_AMOUNT);
              long amount = c.getLong(col);
              if (amount < 0) {
                tv1.setTextColor(colorExpense);
                // Set the background color of the text.
              } else {
                tv1.setTextColor(colorIncome);
              }
              TextView tv2 = (TextView) row.findViewById(R.id.category);
              if (Build.VERSION.SDK_INT < 11) tv2.setTextColor(Color.WHITE);
              String catText = tv2.getText().toString();
              if (DbUtils.getLongOrNull(c, KEY_TRANSFER_PEER) != null) {
                catText = ((amount < 0) ? "=&gt; " : "&lt;= ") + catText;
              } else {
                Long catId = DbUtils.getLongOrNull(c, KEY_CATID);
                if (catId == null) {
                  catText = getString(R.string.no_category_assigned);
                } else {
                  col = c.getColumnIndex(KEY_LABEL_SUB);
                  String label_sub = c.getString(col);
                  if (label_sub != null && label_sub.length() > 0) {
                    catText += categorySeparator + label_sub;
                  }
                }
              }
              col = c.getColumnIndex(KEY_COMMENT);
              String comment = c.getString(col);
              if (comment != null && comment.length() > 0) {
                catText += (catText.equals("") ? "" : commentSeparator) + "<i>" + comment + "</i>";
              }
              tv2.setText(Html.fromHtml(catText));
              return row;
            }
          };
      lv.setAdapter(mAdapter);
      lv.setEmptyView(emptyView);
      LoaderManager manager = ctx.getSupportLoaderManager();
      if (manager.getLoader(MyExpenses.SPLIT_PART_CURSOR) != null
          && !manager.getLoader(MyExpenses.SPLIT_PART_CURSOR).isReset())
        manager.restartLoader(MyExpenses.SPLIT_PART_CURSOR, null, this);
      else manager.initLoader(MyExpenses.SPLIT_PART_CURSOR, null, this);
    } else {
      view.findViewById(R.id.SplitContainer).setVisibility(View.GONE);
      if (mTransaction instanceof Transfer) {
        title = R.string.transfer;
        ((TextView) view.findViewById(R.id.AccountLabel)).setText(R.string.transfer_from_account);
        ((TextView) view.findViewById(R.id.CategoryLabel)).setText(R.string.transfer_to_account);
      } else title = type ? R.string.income : R.string.expense;
    }
    String accountLabel = Account.getInstanceFromDb(mTransaction.accountId).label;
    if (mTransaction instanceof Transfer) {
      ((TextView) view.findViewById(R.id.Account))
          .setText(type ? mTransaction.label : accountLabel);
      ((TextView) view.findViewById(R.id.Category))
          .setText(type ? accountLabel : mTransaction.label);
    } else {
      ((TextView) view.findViewById(R.id.Account)).setText(accountLabel);
      if ((mTransaction.catId != null && mTransaction.catId > 0)) {
        ((TextView) view.findViewById(R.id.Category)).setText(mTransaction.label);
      } else {
        view.findViewById(R.id.CategoryRow).setVisibility(View.GONE);
      }
    }
    ((TextView) view.findViewById(R.id.Date))
        .setText(
            DateFormat.getDateInstance(DateFormat.FULL).format(mTransaction.getDate())
                + " "
                + DateFormat.getTimeInstance(DateFormat.SHORT).format(mTransaction.getDate()));
    ((TextView) view.findViewById(R.id.Amount))
        .setText(
            Utils.formatCurrency(
                new Money(
                    mTransaction.amount.getCurrency(),
                    Math.abs(mTransaction.amount.getAmountMinor()))));
    if (!mTransaction.comment.equals(""))
      ((TextView) view.findViewById(R.id.Comment)).setText(mTransaction.comment);
    else view.findViewById(R.id.CommentRow).setVisibility(View.GONE);
    if (!mTransaction.referenceNumber.equals(""))
      ((TextView) view.findViewById(R.id.Number)).setText(mTransaction.referenceNumber);
    else view.findViewById(R.id.NumberRow).setVisibility(View.GONE);
    if (!mTransaction.payee.equals(""))
      ((TextView) view.findViewById(R.id.Payee)).setText(mTransaction.payee);
    else view.findViewById(R.id.PayeeRow).setVisibility(View.GONE);
    if (mTransaction.methodId != null)
      ((TextView) view.findViewById(R.id.Method))
          .setText(PaymentMethod.getInstanceFromDb(mTransaction.methodId).getDisplayLabel());
    else view.findViewById(R.id.MethodRow).setVisibility(View.GONE);
    if (Account.getInstanceFromDb(mTransaction.accountId).type.equals(Type.CASH))
      view.findViewById(R.id.StatusRow).setVisibility(View.GONE);
    else {
      TextView tv = (TextView) view.findViewById(R.id.Status);
      tv.setBackgroundColor(mTransaction.crStatus.color);
      tv.setText(mTransaction.crStatus.toString());
    }
    return new AlertDialog.Builder(getActivity())
        .setTitle(title)
        .setView(view)
        .setNegativeButton(android.R.string.ok, this)
        .setPositiveButton(R.string.menu_edit, this)
        .create();
  }