I am having problems with Week 7 of this tutorial, https://web.stanford.edu/class/cs193a/lectures.shtml. On Week 7, There is only the .java files showing which was problematic when I ran the build on Android studio. I am trying to compile the project "Targets".
When I looked through the files on the downloadable zip files I managed to recover the following pieces of code:
TargetsActivity.java:
package com.mycompany.myapplication.; import android.app.Activity; import android.os.Bundle; public class TargetsActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_targets); } } TargetsView.java:
package com.mycompany.myapplication; import android.content.Context; import android.graphics.*; import android.util.AttributeSet; import android.view.View; public class TargetsView extends View { public TargetsView(Context context, AttributeSet attrs) { super(context, attrs); } /* * This method draws the target oval shapes on the view. */ @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); Paint red = new Paint(); red.setARGB(255, 255, 0, 0); Paint white = new Paint(); white.setARGB(255, 255, 255, 255); int w = getWidth(); int h = getHeight(); for (int i = 0; i < 5; i++) { canvas.drawOval(new RectF(w*i/10, h*i/10, w*(10-i)/10, h*(10-i)/10), (i % 2 == 0 ? red : white)); } } } ExampleView.java:
package com.mycompany.myapplication; import android.content.Context; import android.graphics.*; import android.util.AttributeSet; import android.view.View; public class ExampleView extends View { public ExampleView(Context context, AttributeSet attrs) { super(context, attrs); } /* * This method draws some shapes and text on the view. */ @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); canvas.drawARGB(255, 255, 90, 90); Paint aqua = new Paint(); aqua.setARGB(255, 0, 80, 220); canvas.drawRect(new RectF(10, 30, 300, 700), aqua); canvas.drawOval(new RectF(400, 50, getWidth(), getHeight()), aqua); Paint font = new Paint(); font.setARGB(255, 0, 0, 0); font.setTypeface(Typeface.create(Typeface.SERIF, Typeface.BOLD_ITALIC)); font.setTextSize(40); canvas.drawText("CS 193A is great", 80, 200, font); } } activity_targets.xml:
<?xml version="1.0"?> <RelativeLayout tools:context=".TargetsActivity" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingTop="@dimen/activity_vertical_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:layout_height="match_parent" android:layout_width="match_parent" xmlns:tools="http://schemas.android.com/tools" xmlns:android="http://schemas.android.com/apk/res/android"> <com.mycompany.myapplication.TargetsView android:layout_height="match_parent" android:layout_width="match_parent"/> </RelativeLayout> and menu_targets.xml:
<?xml version="1.0"?> <RelativeLayout tools:context=".TargetsActivity" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingTop="@dimen/activity_vertical_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:layout_height="match_parent" android:layout_width="match_parent" xmlns:tools="http://schemas.android.com/tools" xmlns:android="http://schemas.android.com/apk/res/android"> <com.mycompany.myapplication.TargetsView android:layout_height="match_parent" android:layout_width="match_parent"/> </RelativeLayout> These were all the .java and .xml files I could find in the downloadable zip folder. However unlike the other projects it will not compile with all the .java and .xml files known to me. What I am missing? Should there be other .xml files and if so why should I have known a priori that they should have been there?
(I have changed package com.example.stepp.targets; to package com.mycompany.myapplication as this fitted before)
No comments:
Post a Comment