Android Open Source - longhorn Stock Overview Layout






From Project

Back to project page longhorn.

License

The source code is released under:

Apache License

If you think the Android project longhorn 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 (C) 2012 Santiago Valdarrama
 * //from   ww w  .  ja va  2  s  .  c  om
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at 
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 */
package com.svpino.longhorn.layouts;

import android.content.Context;
import android.os.AsyncTask;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.svpino.longhorn.R;
import com.svpino.longhorn.artifacts.Extensions;
import com.svpino.longhorn.artifacts.StockOverviewManager;
import com.svpino.longhorn.model.Stock;

public class StockOverviewLayout extends LinearLayout {

  private final static float STOCK_PRICE_ANIMATION_STEPS = 10;

  private TextView lastTradeDateTextView;
  private TextView targetPriceTextView;
  private StockPriceAnimationAsyncTask stockPriceAnimationAsyncTask;
  private Stock stock;
  private ViewGroup stockOverviewContentLayout;

  private StockOverviewManager stockOverviewManager;

  public StockOverviewLayout(final Context context) {
    super(context);
    this.stock = null;

    LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    inflater.inflate(R.layout.stock_overview, this);

    this.stockOverviewContentLayout = (ViewGroup) findViewById(R.id.stockOverviewContentLayout);

    this.stockOverviewManager = new StockOverviewManager(this.stockOverviewContentLayout);

    this.lastTradeDateTextView = (TextView) findViewById(R.id.lastTradeDateTextView);
    this.targetPriceTextView = (TextView) findViewById(R.id.targetPriceTextView);
  }

  public void setStock(Stock stock) {
    this.stock = stock;

    Extensions.applyPattern(getResources(), this.stockOverviewContentLayout, stock);

    this.stockOverviewManager.setStock(this.stock);

    if (this.lastTradeDateTextView != null) {
      this.lastTradeDateTextView.setText(this.stock.getLastTradeDate());
    }

    if (this.targetPriceTextView != null) {
      this.targetPriceTextView.setText(this.stock.getStringTargetPrice());
    }
  }

  public Stock getStock() {
    return this.stock;
  }

  public void animateContent() {
    if (this.stock != null) {
      if (this.stockPriceAnimationAsyncTask != null) {
        this.stockPriceAnimationAsyncTask.cancel(true);
        this.stockPriceAnimationAsyncTask = null;
      }

      if (this.stock.getPrice() != null && this.stock.getOpen() != null) {
        this.stockOverviewManager.setPrice(this.stock.getStringOpen());

        float increment = (this.stock.getPrice() - this.stock.getOpen()) / STOCK_PRICE_ANIMATION_STEPS;

        this.stockPriceAnimationAsyncTask = new StockPriceAnimationAsyncTask();
        this.stockPriceAnimationAsyncTask.execute(this.stock.getPrice(), this.stock.getOpen(), increment);
      }
    }
  }

  private class StockPriceAnimationAsyncTask extends AsyncTask<Float, Float, Void> {

    private float price;

    @Override
    protected Void doInBackground(Float... params) {
      this.price = params[0];
      float open = params[1];
      float increment = params[2];

      for (int i = 0; i < STOCK_PRICE_ANIMATION_STEPS; i++) {
        if (!this.isCancelled()) {
          try {
            open += increment;
            publishProgress(open);
            Thread.sleep(40);
          }
          catch (InterruptedException e) {
            return null;
          }
        }
      }

      return null;
    }

    @Override
    protected void onProgressUpdate(Float... values) {
      float value = values[0];
      StockOverviewLayout.this.stockOverviewManager.setPrice(Extensions.format(value));
    }

    @Override
    protected void onPostExecute(Void result) {
      StockOverviewLayout.this.stockOverviewManager.setPrice(Extensions.format(this.price));
    }
  }
}




Java Source Code List

com.svpino.longhorn.MarketCollectorService.java
com.svpino.longhorn.activities.DashboardActivity.java
com.svpino.longhorn.artifacts.Constants.java
com.svpino.longhorn.artifacts.Extensions.java
com.svpino.longhorn.artifacts.StockOverviewManager.java
com.svpino.longhorn.artifacts.StockTileProcessor.java
com.svpino.longhorn.artifacts.StockTileViewHolder.java
com.svpino.longhorn.artifacts.TabFragment.java
com.svpino.longhorn.artifacts.back.BackStack.java
com.svpino.longhorn.artifacts.back.StockOverviewBackStackItem.java
com.svpino.longhorn.data.DataProvider.java
com.svpino.longhorn.data.LonghornDatabase.java
com.svpino.longhorn.data.LonghornOpenHelper.java
com.svpino.longhorn.fragments.StockListFragment.java
com.svpino.longhorn.layouts.BorderRelativeLayout.java
com.svpino.longhorn.layouts.StockOverviewLayout.java
com.svpino.longhorn.model.Stock.java
com.svpino.longhorn.providers.SearchContentProvider.java
com.svpino.longhorn.receivers.BatteryBroadcastReceiver.java
com.svpino.longhorn.receivers.ConnectivityBroadcastReceiver.java
com.svpino.longhorn.receivers.MarketCollectionReceiver.java