-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Accessibility, localization corrections and add new History Activity
- Loading branch information
1 parent
901af4c
commit 764f82b
Showing
15 changed files
with
280 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
app/src/main/java/com/udacity/stockhawk/ui/HistoryActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.udacity.stockhawk.ui; | ||
|
||
import android.os.Bundle; | ||
import android.support.v7.app.AppCompatActivity; | ||
|
||
import com.udacity.stockhawk.R; | ||
|
||
import static com.udacity.stockhawk.ui.HistoryFragment.SYMBOL_URI; | ||
|
||
public class HistoryActivity extends AppCompatActivity { | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_history); | ||
/*Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); | ||
setSupportActionBar(toolbar); | ||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);*/ | ||
if (savedInstanceState == null) { | ||
Bundle args = new Bundle(); | ||
args.putParcelable(SYMBOL_URI, getIntent().getData()); | ||
HistoryFragment historyFragment = new HistoryFragment(); | ||
historyFragment.setArguments(args); | ||
getSupportFragmentManager().beginTransaction() | ||
.add(R.id.hystory_fragment, historyFragment) | ||
.commit(); | ||
|
||
} | ||
} | ||
|
||
} |
105 changes: 105 additions & 0 deletions
105
app/src/main/java/com/udacity/stockhawk/ui/HistoryFragment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
package com.udacity.stockhawk.ui; | ||
|
||
import android.database.Cursor; | ||
import android.net.Uri; | ||
import android.os.Bundle; | ||
import android.support.annotation.Nullable; | ||
import android.support.v4.app.Fragment; | ||
import android.support.v4.app.LoaderManager; | ||
import android.support.v4.content.CursorLoader; | ||
import android.support.v4.content.Loader; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
|
||
import com.github.mikephil.charting.charts.LineChart; | ||
import com.github.mikephil.charting.data.Entry; | ||
import com.github.mikephil.charting.data.LineData; | ||
import com.github.mikephil.charting.data.LineDataSet; | ||
import com.udacity.stockhawk.R; | ||
import com.udacity.stockhawk.data.Contract; | ||
|
||
import java.util.ArrayList; | ||
import java.util.StringTokenizer; | ||
|
||
|
||
public class HistoryFragment extends Fragment implements LoaderManager.LoaderCallbacks<Cursor> { | ||
public static final String SYMBOL_URI = "URI"; | ||
private static final int STOCK_LOADER = 1; | ||
private Uri mSymbolUri; | ||
|
||
LineChart mChart; | ||
|
||
|
||
private static final String[] HISTORY_COLUMNS ={ | ||
Contract.Quote.COLUMN_SYMBOL, | ||
Contract.Quote.COLUMN_HISTORY | ||
}; | ||
static final int COL_SYMBOL_ID = 0; | ||
static final int COL_HISTORY_ID = 1; | ||
|
||
public HistoryFragment() { | ||
} | ||
|
||
@Override | ||
public View onCreateView(LayoutInflater inflater, ViewGroup container, | ||
Bundle savedInstanceState) { | ||
Bundle args = getArguments(); | ||
mSymbolUri = args.getParcelable(SYMBOL_URI); | ||
View rootView = inflater.inflate(R.layout.fragment_history, container, false); | ||
mChart = (LineChart) rootView.findViewById(R.id.chart); | ||
mChart.setDescription(getString(R.string.chart_description)); | ||
|
||
return rootView; | ||
} | ||
|
||
@Override | ||
public void onActivityCreated(@Nullable Bundle savedInstanceState) { | ||
getLoaderManager().initLoader(STOCK_LOADER, null, this); | ||
super.onActivityCreated(savedInstanceState); | ||
} | ||
|
||
@Override | ||
public Loader<Cursor> onCreateLoader(int id, Bundle args) { | ||
if (mSymbolUri != null) { | ||
return new CursorLoader(getActivity(), mSymbolUri, HISTORY_COLUMNS, null, null, null); | ||
} | ||
return null; | ||
} | ||
|
||
@Override | ||
public void onLoadFinished(Loader<Cursor> loader, Cursor data) { | ||
|
||
if (data.moveToFirst()) { | ||
ArrayList<Entry> entries = new ArrayList<>(); | ||
ArrayList<String> xValues = new ArrayList<>(); | ||
String history = data.getString(COL_HISTORY_ID); | ||
String value; | ||
StringTokenizer tokenizer = new StringTokenizer(history, "\n"); | ||
int x = 0; | ||
int count = tokenizer.countTokens() - 1; | ||
while (tokenizer.hasMoreTokens()){ | ||
xValues.add(""+(count-x)); | ||
value = tokenizer.nextToken(); | ||
value = value.split(",")[1]; | ||
entries.add(new Entry(Float.parseFloat(value), x)); | ||
x++; | ||
} | ||
LineDataSet dataSet = new LineDataSet(entries, Contract.Quote.getStockFromUri(mSymbolUri)); | ||
dataSet.setColors(new int[]{R.color.white}, getContext()); | ||
dataSet.setValueTextColor(R.color.white); | ||
|
||
LineData lineData = new LineData(xValues, dataSet); | ||
|
||
mChart.setData(lineData); | ||
|
||
|
||
|
||
} | ||
} | ||
|
||
@Override | ||
public void onLoaderReset(Loader<Cursor> loader) { | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
|
||
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
android:id="@+id/hystory_fragment" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
tools:context=".ui.HistoryActivity"> | ||
|
||
</android.support.design.widget.CoordinatorLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:id="@+id/activity_history" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:paddingBottom="@dimen/activity_vertical_margin" | ||
android:paddingLeft="@dimen/activity_horizontal_margin" | ||
android:paddingRight="@dimen/activity_horizontal_margin" | ||
android:paddingTop="@dimen/activity_vertical_margin" | ||
tools:context="com.udacity.stockhawk.ui.HistoryFragment"> | ||
|
||
<com.github.mikephil.charting.charts.LineChart | ||
android:id="@+id/chart" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
/> | ||
|
||
</RelativeLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<menu xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
tools:context="com.udacity.stockhawk.ui.HistoryActivity"> | ||
<item | ||
android:id="@+id/action_settings" | ||
android:orderInCategory="100" | ||
app:showAsAction="never" | ||
android:title="@string/action_settings" /> | ||
</menu> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<resources> | ||
<!-- Example customization of dimensions originally defined in res/values/dimens.xml | ||
(such as screen margins) for screens with more than 820dp of available width. This | ||
would include 7" and 10" devices in landscape (~960dp and ~1280dp respectively). --> | ||
<dimen name="activity_horizontal_margin">64dp</dimen> | ||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.