Skip to content
Snippets Groups Projects
Commit 9ec619ed authored by Andrej Rasevic's avatar Andrej Rasevic
Browse files

adding fall 2018 student distribution

parents
No related branches found
No related tags found
No related merge requests found
Showing
with 628 additions and 0 deletions
# built application files
*.apk
*.ap_
# files for the dex VM
*.dex
# Java class files
*.class
# generated files
bin/
gen/
# Local configuration file (sdk path, etc)
local.properties
# Eclipse project files
.classpath
.settings
# Proguard folder generated by Eclipse
proguard/
# Intellij project files
*.iml
*.ipr
*.iws
.idea
.idea/workspace.xml
.gradle
build/
captures/
# Mac files
.DS_Store
# Windows thumbnail db
Thumbs.db
File added
File added
File added
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
buildToolsVersion '27.0.3'
defaultConfig {
applicationId "course.labs.fragmentslab"
minSdkVersion 21
targetSdkVersion 26
testApplicationId "course.labs.fragmentslab.test"
testInstrumentationRunner "android.test.InstrumentationTestRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
androidTestImplementation 'com.android.support.test:rules:1.0.2'
androidTestImplementation 'com.jayway.android.robotium:robotium-solo:5.6.3'
}
package course.labs.fragmentslab.test;
import course.labs.fragmentslab.MainActivity;
import com.robotium.solo.*;
import android.test.ActivityInstrumentationTestCase2;
public class PhoneTest extends ActivityInstrumentationTestCase2<MainActivity> {
private Solo solo;
public PhoneTest() {
super(MainActivity.class);
}
public void setUp() throws Exception {
solo = new Solo(getInstrumentation(), getActivity());
}
@Override
public void tearDown() throws Exception {
solo.finishOpenedActivities();
}
public void testRun() {
int delay = 2000;
// Wait for activity: 'course.labs.fragmentslab.MainActivity'
assertTrue("MainActivity not found", solo.waitForActivity(
course.labs.fragmentslab.MainActivity.class, delay));
// Wait for view: 'android.R.id.text1'
assertTrue("text1 not found", solo.waitForView(android.R.id.text1));
// Click on ladygaga
solo.clickOnView(solo.getView(android.R.id.text1));
assertTrue("ladygaga feed_view not found", solo.waitForView(solo
.getView(course.labs.fragmentslab.R.id.feed_view)));
// Assert that: 'the audience cheering!' is shown
assertTrue("'the audience cheering!' is not shown!",
solo.searchText("the audience cheering!"));
// Press menu back key
solo.goBack();
// Wait for view: 'android.R.id.text1'
assertTrue("text1 not found", solo.waitForView(android.R.id.text1));
// Click on msrebeccablack
solo.clickOnView(solo.getView(android.R.id.text1, 1));
// Assert that: feed_view is shown
assertTrue("feed_view! is not shown!", solo.waitForView(solo
.getView(course.labs.fragmentslab.R.id.feed_view)));
// Assert that: 'save me from school' is shown
assertTrue("'save me from school' is not shown!",
solo.searchText("save me from school"));
// Press menu back key
solo.goBack();
// Wait for view: 'android.R.id.text1'
assertTrue("text1 not found", solo.waitForView(android.R.id.text1));
// Click on taylorswift13
solo.clickOnView(solo.getView(android.R.id.text1, 2));
// Assert that: feed_view shown
assertTrue("feed_view not shown", solo.waitForView(solo
.getView(course.labs.fragmentslab.R.id.feed_view)));
// Assert that: 'I love you guys so much' is shown
assertTrue("'I love you guys so much' is not shown!",
solo.searchText("I love you guys so much"));
}
}
\ No newline at end of file
package course.labs.fragmentslab.test;
import course.labs.fragmentslab.MainActivity;
import com.robotium.solo.*;
import android.test.ActivityInstrumentationTestCase2;
public class TabletTest extends ActivityInstrumentationTestCase2<MainActivity> {
private Solo solo;
public TabletTest() {
super(MainActivity.class);
}
public void setUp() throws Exception {
solo = new Solo(getInstrumentation(), getActivity());
}
@Override
public void tearDown() throws Exception {
solo.finishOpenedActivities();
}
public void testRun() {
int delay = 2000;
// Wait for activity: 'course.labs.fragmentslab.MainActivity'
solo.waitForActivity(MainActivity.class, delay);
// Wait for view: 'android.R.id.text1'
assertTrue("text1 not found", solo.waitForView(android.R.id.text1));
// Assert that: feed_view is shown
assertTrue("'feed_view' was not found!", solo.waitForView(solo
.getView(course.labs.fragmentslab.R.id.feed_view)));
// Click on ladygaga
solo.clickOnView(solo.getView(android.R.id.text1));
// Assert that: feed_view is shown
assertTrue("'Select a feed to view!' is not shown!",
solo.waitForView(solo
.getView(course.labs.fragmentslab.R.id.feed_view)));
// Assert that: 'the audience cheering!' is shown
assertTrue("'the audience cheering!' is not shown!",
solo.searchText("the audience cheering!"));
// Click on msrebeccablack
solo.clickOnView(solo.getView(android.R.id.text1, 1));
// Assert that: feed_view is shown
assertTrue("'Select a feed to view!' is not shown!",
solo.waitForView(solo
.getView(course.labs.fragmentslab.R.id.feed_view)));
// Assert that: 'save me from school' is shown
assertTrue("'save me from school' is not shown!",
solo.searchText("save me from school"));
// Click on taylorswift13
solo.clickOnView(solo.getView(android.R.id.text1, 2));
// Assert that: feed_view is shown
assertTrue("'Select a feed to view!' is not shown!",
solo.waitForView(solo
.getView(course.labs.fragmentslab.R.id.feed_view)));
// Assert that: 'I love you guys so much' is shown
assertTrue("'I love you guys so much' is not shown!",
solo.searchText("I love you guys so much"));
}
}
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="course.labs.fragmentslab"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="21"
android:targetSdkVersion="26" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="course.labs.fragmentslab.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
\ No newline at end of file
package course.labs.fragmentslab;
import android.app.Fragment;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
public class FeedFragment extends Fragment {
private static final String TAG = "Lab-Fragments";
private TextView mTextView;
private static FeedFragmentData feedFragmentData;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
return inflater.inflate(R.layout.feed, container, false);
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
// Read in all Twitter feeds
if (null == feedFragmentData) {
feedFragmentData = new FeedFragmentData(getActivity());
}
}
// Display Twitter feed for selected feed
void updateFeedDisplay(int position) {
Log.i(TAG, "Entered updateFeedDisplay()");
mTextView = (TextView) getView().findViewById(R.id.feed_view);
mTextView.setText(feedFragmentData.getFeed(position));
}
}
package course.labs.fragmentslab;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.content.Context;
import android.util.Log;
import android.util.SparseArray;
// Utility class that provides stored Twitter feed data
public class FeedFragmentData {
private static final String TAG = "FeedFragmentData";
private static final int[] IDS = { R.raw.ladygaga, R.raw.rebeccablack,
R.raw.taylorswift };
private SparseArray<String> mFeeds = new SparseArray<String>();
private Context mContext;
public FeedFragmentData(Context context) {
mContext = context;
loadFeeds();
}
// Load all stored Twitter feeds into the mFeeds SparseArray.
private void loadFeeds() {
for (int id : IDS) {
InputStream inputStream = mContext.getResources().openRawResource(
id);
BufferedReader reader = new BufferedReader(new InputStreamReader(
inputStream));
StringBuffer buffer = new StringBuffer("");
// Read raw data from resource file
try {
String line = "";
while ((line = reader.readLine()) != null) {
buffer.append(line);
}
} catch (IOException e) {
Log.i(TAG, "IOException");
}
// Convert raw data into a String
JSONArray feed = null;
try {
feed = new JSONArray(buffer.toString());
} catch (JSONException e) {
Log.i(TAG, "JSONException");
}
mFeeds.put(id, procFeed(feed));
}
}
// Convert JSON formatted data to a String
private String procFeed(JSONArray feed) {
String name = "";
String tweet = "";
// string buffer for twitter feeds
StringBuffer textFeed = new StringBuffer("");
for (int j = 0; j < feed.length(); j++) {
try {
tweet = feed.getJSONObject(j).getString("text");
JSONObject user = (JSONObject) feed.getJSONObject(j)
.get("user");
name = user.getString("name");
} catch (JSONException e) {
Log.i(TAG, "JSONException while processing feed");
}
textFeed.append(name + " - " + tweet + "\n\n");
}
return textFeed.toString();
}
// Return the Twitter feed data for the specified position as a single String
String getFeed (int position) {
return mFeeds.get(IDS[position]);
}
}
\ No newline at end of file
package course.labs.fragmentslab;
import android.app.Activity;
import android.app.ListFragment;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class FriendsFragment extends ListFragment {
private static final String[] FRIENDS = { "ladygaga", "msrebeccablack",
"taylorswift13" };
private static final String TAG = "Lab-Fragments";
public interface SelectionListener {
public void onItemSelected(int position);
}
private SelectionListener mCallback;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// use different layout definition, depending on whether device is pre-
// or post-honeycomb
int layout = Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB ? android.R.layout.simple_list_item_activated_1
: android.R.layout.simple_list_item_1;
// Set the list adapter for this ListFragment
setListAdapter(new ArrayAdapter<String>(getActivity(), layout, FRIENDS));
}
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
// Make sure that the hosting Activity has implemented
// the SelectionListener callback interface. We need this
// because when an item in this ListFragment is selected,
// the hosting Activity's onItemSelected() method will be called.
try {
mCallback = (SelectionListener) activity;
} catch (ClassCastException e) {
throw new ClassCastException(activity.toString()
+ " must implement SelectionListener");
}
}
// Note: ListFragments come with a default onCreateView() method.
// For other Fragments you'll normally implement this method.
// @Override
// public View onCreateView(LayoutInflater inflater, ViewGroup container,
// Bundle savedInstanceState)
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
Log.i(TAG, "Entered onActivityCreated()");
// When using two-pane layout, configure the ListView to highlight the
// selected list item
if (isInTwoPaneMode()) {
getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE);
}
}
@Override
public void onListItemClick(ListView l, View view, int position, long id) {
// Notify the hosting Activity that a selection has been made.
mCallback.onItemSelected(position);
}
// If there is a FeedFragment, then the layout is two-pane
private boolean isInTwoPaneMode() {
return getFragmentManager().findFragmentById(R.id.feed_frag) != null;
}
}
package course.labs.fragmentslab;
import android.app.Activity;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.util.Log;
public class MainActivity extends Activity implements
FriendsFragment.SelectionListener {
private static final String TAG = "Lab-Fragments";
private FriendsFragment mFriendsFragment;
private FeedFragment mFeedFragment;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_activity);
// If the layout is single-pane, create the FriendsFragment
// and add it to the Activity
if (!isInTwoPaneMode()) {
mFriendsFragment = new FriendsFragment();
//TODO 1 - add the FriendsFragment
} else {
// Otherwise, save a reference to the FeedFragment for later use
}
}
// If there is no fragment_container ID, then the application is in
// two-pane mode
private boolean isInTwoPaneMode() {
return findViewById(R.id.fragment_container) == null;
}
// Display selected Twitter feed
public void onItemSelected(int position) {
Log.i(TAG, "Entered onItemSelected(" + position + ")");
// If there is no FeedFragment instance, then create one
if (mFeedFragment == null)
mFeedFragment = new FeedFragment();
// If in single-pane mode, replace single visible Fragment
if (!isInTwoPaneMode()) {
//TODO 2 - replace the fragment_container with the FeedFragment
}
// Update Twitter feed display on FriendFragment
mFeedFragment.updateFeedDisplay(position);
}
}
app/src/main/res/drawable-hdpi/ic_launcher.png

8.02 KiB

app/src/main/res/drawable-ldpi/ic_launcher.png

2.5 KiB

app/src/main/res/drawable-mdpi/ic_launcher.png

3.97 KiB

app/src/main/res/drawable-xhdpi/ic_launcher.png

13.2 KiB

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/frags"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:baselineAligned="false">
<fragment
android:id="@+id/friends_frag"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
class="course.labs.fragmentslab.FriendsFragment" />
<fragment
android:id="@+id/feed_frag"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="3"
class="course.labs.fragmentslab.FeedFragment" />
</LinearLayout>
\ No newline at end of file
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="@+id/feed_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/greeting" />
</ScrollView>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
\ No newline at end of file
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment