Skip to content
Snippets Groups Projects
Commit d20ba22d authored by Vietanh Le Trung's avatar Vietanh Le Trung
Browse files

Initial stuff

i have recycle
parents
Branches
No related tags found
No related merge requests found
Showing
with 377 additions and 0 deletions
package com.ireallydontcare.viet.posseidon;
import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.junit.Assert.*;
/**
* Instrumented test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getTargetContext();
assertEquals("com.ireallydontcare.viet.posseidon", appContext.getPackageName());
}
}
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.ireallydontcare.viet.posseidon">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".SubjectActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar">
<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 com.ireallydontcare.viet.posseidon;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;
import com.ireallydontcare.viet.posseidon.adapter.SubjectAdapter;
import com.ireallydontcare.viet.posseidon.fragments.NewDialogSubjectFragment;
import com.ireallydontcare.viet.posseidon.model.Subject;
import static java.security.AccessController.getContext;
public class SubjectActivity extends AppCompatActivity
implements NewDialogSubjectFragment.NewSubjectDialogListener{
private RecyclerView subjectRecyclerView;
private SubjectAdapter subjectAdapter;
private RecyclerView.LayoutManager subjectLayoutManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_subject);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
new NewDialogSubjectFragment().show(getSupportFragmentManager(), NewDialogSubjectFragment.TAG);
}
});
subjectRecyclerView = (RecyclerView) findViewById(R.id.SubjectRecyclerView);
// use this setting to improve performance if you know that changes
// in content do not change the layout size of the RecyclerView
subjectRecyclerView.setHasFixedSize(true);
// use a linear layout manager
subjectLayoutManager = new LinearLayoutManager(this);
subjectRecyclerView.setLayoutManager(subjectLayoutManager);
// specify an adapter (see also next example)
subjectAdapter = new SubjectAdapter();
subjectRecyclerView.setAdapter(subjectAdapter);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_subject, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
public void onShoppingItemCreated(final Subject newItem) {
new AsyncTask<Void, Void, Subject>() {
@Override
protected Subject doInBackground(Void... voids) {
return newItem;
}
@Override
protected void onPostExecute(Subject shoppingItem) {
subjectAdapter.addItem(shoppingItem);
}
}.execute();
}
}
package com.ireallydontcare.viet.posseidon.adapter;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import com.ireallydontcare.viet.posseidon.R;
import com.ireallydontcare.viet.posseidon.model.Subject;
import java.util.ArrayList;
import java.util.List;
public class SubjectAdapter extends RecyclerView.Adapter<SubjectAdapter.SubjectViewHolder> {
private final List<Subject> subjects;
// Provide a reference to the views for each data item
// Complex data items may need more than one view per item, and
// you provide access to all the views for a data item in a view holder
// Provide a suitable constructor (depends on the kind of dataset)
public SubjectAdapter() {
this.subjects = new ArrayList<>();
}
// Create new views (invoked by the layout manager)
@Override
public SubjectAdapter.SubjectViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
// create a new view
View itemView = LayoutInflater
.from(parent.getContext())
.inflate(R.layout.item_subject, parent, false);
SubjectViewHolder vh = new SubjectViewHolder(itemView);
return vh;
}
// Replace the contents of a view (invoked by the layout manager)
@Override
public void onBindViewHolder(final SubjectViewHolder holder, int position) {
// - get element from your dataset at this position
// - replace the contents of the view with that element
final Subject subject = subjects.get(position);
holder.name.setText(subject.name);
holder.code.setText(subject.code);
holder.subject = subject;
}
@Override
public int getItemCount() {
return subjects.size();
}
public static class SubjectViewHolder extends RecyclerView.ViewHolder {
Subject subject;
TextView name;
TextView code;
public SubjectViewHolder(View itemView) {
super(itemView);
name = itemView.findViewById(R.id.subject_name);
code = itemView.findViewById(R.id.subject_code);
}
}
public void addItem(Subject subject){
subjects.add(subject);
notifyItemInserted(subjects.size() - 1);
}
public interface OnSubjectClickListener {
void onItemClick(Subject item);
}
}
\ No newline at end of file
package com.ireallydontcare.viet.posseidon.fragments;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.FragmentActivity;
import android.support.v7.app.AlertDialog;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
import com.ireallydontcare.viet.posseidon.R;
import com.ireallydontcare.viet.posseidon.model.Subject;
public class NewDialogSubjectFragment extends DialogFragment {
public static final String TAG = "NewSubjectItemDialogFragment";
public interface NewSubjectDialogListener {
void onShoppingItemCreated(Subject newSubject);
}
private NewSubjectDialogListener listener;
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FragmentActivity activity = getActivity();
if (activity instanceof NewSubjectDialogListener) {
listener = (NewSubjectDialogListener) activity;
} else {
throw new RuntimeException("Activity must implement the NewShoppingItemDialogListener interface!");
}
}
private EditText nameEditText;
private EditText codeEditText;
private EditText descriptionEditText;
private EditText creditEditText;
private View getContentView(){
View contentView = LayoutInflater.from(getContext()).inflate(R.layout.dialog_new_subject_item, null);
nameEditText = contentView.findViewById(R.id.SubjectName);
codeEditText = contentView.findViewById(R.id.SubjectCode);
descriptionEditText = contentView.findViewById(R.id.SubjectDescription);
creditEditText = contentView.findViewById(R.id.SubjectCredit);
return contentView;
}
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
super.onCreateDialog(savedInstanceState);
return new AlertDialog.Builder(requireContext())
.setTitle(R.string.new_subject_item)
.setView(getContentView())
.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
listener.onShoppingItemCreated(getNewSubject());
}
})
.create();
}
public Subject getNewSubject(){
Subject subject = new Subject();
subject.name = nameEditText.getText().toString();
subject.code = codeEditText.getText().toString();
subject.description = descriptionEditText.getText().toString();
subject.credit = Integer.parseInt(creditEditText.getText().toString());
return subject;
}
}
package com.ireallydontcare.viet.posseidon.model;
public class Event {
}
package com.ireallydontcare.viet.posseidon.model;
import android.arch.persistence.room.ColumnInfo;
import android.arch.persistence.room.Entity;
import android.arch.persistence.room.PrimaryKey;
import android.arch.persistence.room.TypeConverter;
@Entity(tableName = "subjectitem")
public class Subject {
@ColumnInfo(name = "id")
@PrimaryKey(autoGenerate = true)
public Long id;
@ColumnInfo(name = "name")
public String name;
@ColumnInfo(name = "code")
public String code;
@ColumnInfo(name = "description")
public String description;
@ColumnInfo(name="credit")
public int credit;
}
app/src/main/res/drawable-hdpi/ic_add_white_36dp.png

250 B

app/src/main/res/drawable-hdpi/ic_delete_grey600_48dp.png

341 B

app/src/main/res/drawable-hdpi/ic_pencil_grey600_48dp.png

915 B

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

223 B

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

271 B

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

692 B

app/src/main/res/drawable-nodpi/groceries.png

4.67 KiB

app/src/main/res/drawable-nodpi/lightning.png

1.74 KiB

app/src/main/res/drawable-nodpi/open_book.png

5.29 KiB

<vector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:aapt="http://schemas.android.com/aapt"
android:width="108dp"
android:height="108dp"
android:viewportWidth="108"
android:viewportHeight="108">
<path
android:fillType="evenOdd"
android:pathData="M32,64C32,64 38.39,52.99 44.13,50.95C51.37,48.37 70.14,49.57 70.14,49.57L108.26,87.69L108,109.01L75.97,107.97L32,64Z"
android:strokeWidth="1"
android:strokeColor="#00000000">
<aapt:attr name="android:fillColor">
<gradient
android:endX="78.5885"
android:endY="90.9159"
android:startX="48.7653"
android:startY="61.0927"
android:type="linear">
<item
android:color="#44000000"
android:offset="0.0" />
<item
android:color="#00000000"
android:offset="1.0" />
</gradient>
</aapt:attr>
</path>
<path
android:fillColor="#FFFFFF"
android:fillType="nonZero"
android:pathData="M66.94,46.02L66.94,46.02C72.44,50.07 76,56.61 76,64L32,64C32,56.61 35.56,50.11 40.98,46.06L36.18,41.19C35.45,40.45 35.45,39.3 36.18,38.56C36.91,37.81 38.05,37.81 38.78,38.56L44.25,44.05C47.18,42.57 50.48,41.71 54,41.71C57.48,41.71 60.78,42.57 63.68,44.05L69.11,38.56C69.84,37.81 70.98,37.81 71.71,38.56C72.44,39.3 72.44,40.45 71.71,41.19L66.94,46.02ZM62.94,56.92C64.08,56.92 65,56.01 65,54.88C65,53.76 64.08,52.85 62.94,52.85C61.8,52.85 60.88,53.76 60.88,54.88C60.88,56.01 61.8,56.92 62.94,56.92ZM45.06,56.92C46.2,56.92 47.13,56.01 47.13,54.88C47.13,53.76 46.2,52.85 45.06,52.85C43.92,52.85 43,53.76 43,54.88C43,56.01 43.92,56.92 45.06,56.92Z"
android:strokeWidth="1"
android:strokeColor="#00000000" />
</vector>
app/src/main/res/drawable-xhdpi/ic_add_white_36dp.png

222 B

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

402 B

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

1.1 KiB

0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment