Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Task.java
- ---------
- package com.example.mohamadpc.backendless;
- import com.backendless.Backendless;
- import com.backendless.async.callback.AsyncCallback;
- import com.backendless.persistence.DataQueryBuilder;
- import java.util.List;
- public class Task {
- private java.util.Date updated;
- private Integer Priorty;
- private String ownerId;
- private java.util.Date closed;
- private java.util.Date target;
- private String name;
- private java.util.Date created;
- private String objectId;
- private boolean done;
- public void setOwnerId(String ownerId) {
- this.ownerId = ownerId;
- }
- public boolean getDone() {
- return done;
- }
- public void setDone(boolean done) {
- this.done = done;
- }
- public java.util.Date getUpdated() {
- return updated;
- }
- public Integer getPriorty() {
- return Priorty;
- }
- public void setPriorty(Integer Priorty) {
- this.Priorty = Priorty;
- }
- public String getOwnerId() {
- return ownerId;
- }
- public java.util.Date getClosed() {
- return closed;
- }
- public void setClosed(java.util.Date closed) {
- this.closed = closed;
- }
- public java.util.Date getTarget() {
- return target;
- }
- public void setTarget(java.util.Date target) {
- this.target = target;
- }
- public String getName() {
- return name;
- }
- public void setName(String name) {
- this.name = name;
- }
- public java.util.Date getCreated() {
- return created;
- }
- public String getObjectId() {
- return objectId;
- }
- public Task save() {
- return Backendless.Data.of(Task.class).save(this);
- }
- public void saveAsync(AsyncCallback<Task> callback) {
- Backendless.Data.of(Task.class).save(this, callback);
- }
- public Long remove() {
- return Backendless.Data.of(Task.class).remove(this);
- }
- public void removeAsync(AsyncCallback<Long> callback) {
- Backendless.Data.of(Task.class).remove(this, callback);
- }
- public static Task findById(String id) {
- return Backendless.Data.of(Task.class).findById(id);
- }
- public static void findByIdAsync(String id, AsyncCallback<Task> callback) {
- Backendless.Data.of(Task.class).findById(id, callback);
- }
- public static Task findFirst() {
- return Backendless.Data.of(Task.class).findFirst();
- }
- public static void findFirstAsync(AsyncCallback<Task> callback) {
- Backendless.Data.of(Task.class).findFirst(callback);
- }
- public static Task findLast() {
- return Backendless.Data.of(Task.class).findLast();
- }
- public static void findLastAsync(AsyncCallback<Task> callback) {
- Backendless.Data.of(Task.class).findLast(callback);
- }
- public static List<Task> find(DataQueryBuilder queryBuilder) {
- return Backendless.Data.of(Task.class).find(queryBuilder);
- }
- public static void findAsync(DataQueryBuilder queryBuilder, AsyncCallback<List<Task>> callback) {
- Backendless.Data.of(Task.class).find(queryBuilder, callback);
- }
- }
- RegisterActivity.java
- ----------------------
- package com.example.mohamadpc.backendless;
- import android.app.Activity;
- import android.app.ProgressDialog;
- import android.content.Context;
- import android.os.Bundle;
- import android.view.View;
- import android.widget.EditText;
- import android.widget.Toast;
- import com.backendless.Backendless;
- import com.backendless.BackendlessUser;
- import com.backendless.async.callback.AsyncCallback;
- import com.backendless.exceptions.BackendlessFault;
- public class RegisterActivity extends Activity implements View.OnClickListener {
- private Context context;
- private EditText etUserEmail, etUserName, etPassword, etReTypePassword;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_register);
- setPointer();
- }
- private void setPointer() {
- this.context = this;
- etUserEmail = (EditText) findViewById(R.id.etRegisterUserEmail);
- etUserName = (EditText) findViewById(R.id.etRegisterUserName);
- etPassword = (EditText) findViewById(R.id.etRegisterPassword);
- etReTypePassword = (EditText) findViewById(R.id.etRegisterReTypePassword);
- findViewById(R.id.btnRegisterRgister).setOnClickListener(this);
- findViewById(R.id.btnRegisterCancel).setOnClickListener(this);
- }
- @Override
- public void onClick(View view) {
- switch (view.getId()) {
- case R.id.btnRegisterCancel:
- cancel();
- break;
- case R.id.btnRegisterRgister:
- String userEmail = etUserEmail.getText().toString();
- String userName = etUserName.getText().toString();
- String password = etPassword.getText().toString();
- String reTypePassword = etReTypePassword.getText().toString();
- if (isValidInput(userEmail, userName, password, reTypePassword))
- register(userEmail, userName, password);
- break;
- default:
- Toast.makeText(this, "Unknown click event on " + view.getId(), Toast.LENGTH_SHORT).show();
- }
- }
- private boolean isValidInput(String userEmail, String userName, String password, String reTypePassword) {
- // no empty fields
- if (userEmail.isEmpty() || userName.isEmpty() ||
- password.isEmpty() ||
- reTypePassword.isEmpty()) {
- Toast.makeText(this, "Please fill all fields", Toast.LENGTH_LONG).show();
- return false;
- }
- // password match
- if (!password.equals(reTypePassword)) {
- Toast.makeText(this, "password fields do not match", Toast.LENGTH_LONG).show();
- return false;
- }
- // minimum password length
- if (password.length() < 3) {
- Toast.makeText(this, "password is too short", Toast.LENGTH_LONG).show();
- return false;
- }
- // valid email address
- if (!android.util.Patterns.EMAIL_ADDRESS.matcher(userEmail).matches()) {
- Toast.makeText(this, "invalid email address", Toast.LENGTH_LONG).show();
- return false;
- }
- return true;
- }
- private void cancel() {
- this.finish();
- }
- private void register(String userEmail, String userName, String password) {
- if (userEmail.isEmpty() || userName.isEmpty() || password.isEmpty()) {
- Toast.makeText(context, "missing data for registrationS", Toast.LENGTH_LONG).show();
- return;
- }
- final ProgressDialog pd = new ProgressDialog(context);
- pd.setMessage("Registering . . .");
- pd.show();
- BackendlessUser user = new BackendlessUser();
- user.setEmail(userEmail);
- user.setProperty("name", userName);
- user.setPassword(password);
- AsyncCallback<BackendlessUser> registerAsyncCallBack = new AsyncCallback<BackendlessUser>() {
- @Override
- public void handleResponse(BackendlessUser response) {
- pd.dismiss();
- finish();
- }
- @Override
- public void handleFault(BackendlessFault fault) {
- pd.cancel();
- Toast.makeText(context, "register faild", Toast.LENGTH_LONG).show();
- finish();
- }
- };
- Backendless.UserService.register(user, registerAsyncCallBack);
- }
- }
- LoginActivity.java
- -------------------
- package com.example.mohamadpc.backendless;
- import android.app.Activity;
- import android.app.ProgressDialog;
- import android.content.Context;
- import android.content.Intent;
- import android.os.Bundle;
- import android.view.View;
- import android.widget.EditText;
- import android.widget.Toast;
- import com.backendless.Backendless;
- import com.backendless.BackendlessUser;
- import com.backendless.async.callback.AsyncCallback;
- import com.backendless.exceptions.BackendlessFault;
- public class LoginActivity extends Activity implements View.OnClickListener {
- private Context context;
- private EditText etUserName, etPassword;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_login);
- setPointer();
- }
- private void setPointer() {
- this.context = this;
- etUserName = (EditText) findViewById(R.id.etLoginUserName);
- etPassword = (EditText) findViewById(R.id.etLoginUserPassword);
- // register button to on click listener
- findViewById(R.id.btnLoginLogin).setOnClickListener(this);
- findViewById(R.id.btnLoginRegister).setOnClickListener(this);
- // initialize connection to BackEndLess database
- String applicationId = context.getResources().getString(R.string.application_Id);
- String apiKey = context.getResources().getString(R.string.api_key);
- Backendless.initApp(getApplicationContext(), applicationId, apiKey);
- }
- @Override
- public void onClick(View view) {
- switch (view.getId()) {
- case R.id.btnLoginLogin:
- login();
- break;
- case R.id.btnLoginRegister:
- register();
- break;
- default:
- Toast.makeText(this, "Unhandled Click on " + view.getId(), Toast.LENGTH_SHORT).show();
- }
- }
- private void register() {
- startActivity(new Intent(context, RegisterActivity.class));
- }
- private void login() {
- final String userName, password;
- userName = etUserName.getText().toString();
- password = etPassword.getText().toString();
- if (userName.isEmpty() || password.isEmpty()) {
- Toast.makeText(context, "Please fill in all your details!", Toast.LENGTH_LONG).show();
- return;
- }
- final ProgressDialog pd = new ProgressDialog(context);
- pd.setMessage("Login in progress . . .");
- pd.show();
- AsyncCallback<BackendlessUser> loginAsyncCallBack = new AsyncCallback<BackendlessUser>() {
- @Override
- public void handleResponse(BackendlessUser response) {
- Intent intent = new Intent(context, TasksActivity.class);
- intent.putExtra("currentUserName", response.getProperty("name") + "");
- intent.putExtra("currentUserId", response.getUserId());
- pd.dismiss();
- finish();
- startActivity(intent);
- }
- @Override
- public void handleFault(BackendlessFault fault) {
- pd.cancel();
- etUserName.setText("");
- etPassword.setText("");
- Toast.makeText(context, "Login failed", Toast.LENGTH_LONG).show();
- }
- };
- Backendless.UserService.login(userName, password, loginAsyncCallBack, true);
- }
- }
- TasksActivity.java
- -------------------
- package com.example.mohamadpc.backendless;
- import android.app.Activity;
- import android.app.AlertDialog;
- import android.app.ProgressDialog;
- import android.content.Context;
- import android.content.DialogInterface;
- import android.content.Intent;
- import android.graphics.Color;
- import android.os.Bundle;
- import android.view.LayoutInflater;
- import android.view.View;
- import android.widget.AdapterView;
- import android.widget.EditText;
- import android.widget.ListView;
- import android.widget.Toast;
- import com.backendless.Backendless;
- import com.backendless.async.callback.AsyncCallback;
- import com.backendless.exceptions.BackendlessFault;
- import com.backendless.persistence.DataQueryBuilder;
- import com.nightonke.boommenu.BoomButtons.OnBMClickListener;
- import com.nightonke.boommenu.BoomButtons.TextOutsideCircleButton;
- import com.nightonke.boommenu.BoomMenuButton;
- import com.nightonke.boommenu.ButtonEnum;
- import java.util.List;
- public class TasksActivity extends Activity {
- private String userName, userId;
- private Context context;
- private List<Task> myTasks;
- private ListView myTaskList;
- private BoomMenuButton bmb;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_tasks);
- setPointer();
- getIntentData();
- getUserTasks();
- }
- private void setPointer() {
- this.context = this;
- myTaskList = (ListView) findViewById(R.id.lstTasks);
- bmb = (BoomMenuButton) findViewById(R.id.btnboomMenu);
- buildBoomMenu();
- myTaskList.setAdapter(new TasksAdapter(myTasks, context));
- myTaskList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
- @Override
- public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
- myTaskList.setItemChecked(position, true);
- }
- });
- myTaskList.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
- @Override
- public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
- myTaskList.setItemChecked(position, true);
- }
- @Override
- public void onNothingSelected(AdapterView<?> parent) {
- }
- });
- }
- private void getUserTasks() {
- final ProgressDialog pd = new ProgressDialog(context);
- pd.show();
- DataQueryBuilder queryBuilder = DataQueryBuilder.create();
- String whereClause = "ownerId='" + Backendless.UserService.loggedInUser() + "'";
- queryBuilder.setWhereClause(whereClause);
- //if we dont tell backendless the size of return records, it will be by defualt 10 result
- queryBuilder.setPageSize(100);
- //get our data from the database......
- Backendless.Data.of(Task.class).find(queryBuilder, new AsyncCallback<List<Task>>() {
- @Override
- public void handleResponse(List<Task> response) {
- myTasks = response;
- myTaskList.setAdapter(new TasksAdapter(myTasks, context));
- pd.dismiss();
- Toast.makeText(context, response.size() + " tasks was loaded from server", Toast.LENGTH_LONG).show();
- }
- @Override
- public void handleFault(BackendlessFault fault) {
- myTasks = null;
- Toast.makeText(context, "Error loading tasks from server !!!", Toast.LENGTH_LONG).show();
- pd.dismiss();
- finish();
- }
- });
- }
- private void buildBoomMenu() {
- bmb.setButtonEnum(ButtonEnum.TextOutsideCircle);
- for (int i = 0; i < bmb.getPiecePlaceEnum().pieceNumber(); i += 1) {
- TextOutsideCircleButton.Builder builder = new TextOutsideCircleButton.Builder();
- builder.textSize(16);
- switch (i) {
- case 0:
- builder.normalColor(Color.RED);
- builder.normalImageRes(R.drawable.add_task);
- builder.normalText("Add");
- builder.listener(new OnBMClickListener() {
- @Override
- public void onBoomButtonClick(int index) {
- final AlertDialog.Builder addNewTask = new AlertDialog.Builder(context);
- final View myDialogView = LayoutInflater.from(context).inflate(R.layout.dialog_new_task_layout, null);
- addNewTask.setView(myDialogView);
- addNewTask.setPositiveButton("Add", new DialogInterface.OnClickListener() {
- @Override
- public void onClick(final DialogInterface dialogInterface, int i) {
- String newTaskName = ((EditText) myDialogView.findViewById(R.id.etNewTaskName)).getText().toString();
- if (newTaskName.isEmpty()) {
- return;
- }
- Task newTask = new Task();
- newTask.setName(newTaskName);
- newTask.setDone(false);
- dialogInterface.dismiss();
- final ProgressDialog pd = new ProgressDialog(context);
- pd.setMessage("adding . . .");
- pd.show();
- Backendless.Persistence.of(Task.class).save(newTask, new AsyncCallback<Task>() {
- @Override
- public void handleResponse(Task response) {
- myTasks.add(response);
- ((TasksAdapter) myTaskList.getAdapter()).notifyDataSetChanged();
- pd.dismiss();
- }
- @Override
- public void handleFault(BackendlessFault fault) {
- pd.dismiss();
- Toast.makeText(context, "Error adding new task !!", Toast.LENGTH_LONG).show();
- }
- });
- }
- });
- addNewTask.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialogInterface, int i) {
- dialogInterface.dismiss();
- }
- });
- addNewTask.show();
- }
- });
- break;
- case 1:
- builder.normalColor(Color.CYAN);
- builder.normalImageRes(R.drawable.delete_task);
- builder.normalText("Delete");
- builder.listener(new OnBMClickListener() {
- @Override
- public void onBoomButtonClick(int index) {
- if (myTaskList.getCheckedItemPosition() > -1) {
- final Task selectedTask = myTasks.get(myTaskList.getCheckedItemPosition());
- final ProgressDialog pd = new ProgressDialog(context);
- pd.setMessage("deleting . . .");
- pd.show();
- Backendless.Persistence.of(Task.class).remove(selectedTask, new AsyncCallback<Long>() {
- @Override
- public void handleResponse(Long response) {
- myTasks.remove(selectedTask);
- ((TasksAdapter) myTaskList.getAdapter()).notifyDataSetChanged();
- pd.dismiss();
- }
- @Override
- public void handleFault(BackendlessFault fault) {
- pd.dismiss();
- Toast.makeText(context, "Error deleteing task !!", Toast.LENGTH_LONG).show();
- }
- });
- } else {
- Toast.makeText(context, "Select a task first !", Toast.LENGTH_SHORT).show();
- }
- }
- });
- break;
- case 2:
- builder.normalColor(Color.GREEN);
- builder.normalImageRes(R.drawable.move_task);
- builder.normalText("Move");
- builder.listener(new OnBMClickListener() {
- @Override
- public void onBoomButtonClick(int index) {
- startActivityForResult(new Intent(context, SelectUserActivity.class), 1010101);
- }
- });
- break;
- case 3:
- builder.normalColor(Color.BLACK);
- builder.normalImageRes(R.drawable.logout);
- builder.normalText("Logout");
- builder.listener(new OnBMClickListener() {
- @Override
- public void onBoomButtonClick(int index) {
- Backendless.UserService.logout(new AsyncCallback<Void>() {
- @Override
- public void handleResponse(Void response) {
- TasksActivity.this.finish();
- startActivity(new Intent(context, LoginActivity.class));
- }
- @Override
- public void handleFault(BackendlessFault fault) {
- Toast.makeText(context, "Error logout ...", Toast.LENGTH_SHORT).show();
- }
- });
- }
- });
- break;
- default:
- builder.normalText("");
- break;
- }
- bmb.addBuilder(builder);
- }
- }
- private void getIntentData() {
- Intent intent = this.getIntent();
- if (!intent.hasExtra("currentUserName") || !intent.hasExtra("currentUserId")) {
- // user should login or register first
- startActivity(new Intent(context, LoginActivity.class));
- this.finish();
- return;
- }
- userName = intent.getStringExtra("currentUserName");
- userId = intent.getStringExtra("currentUserId");
- }
- public void addToList(Task response) {
- myTasks.add(response);
- }
- @Override
- protected void onActivityResult(int requestCode, int resultCode, Intent data) {
- super.onActivityResult(requestCode, resultCode, data);
- if (requestCode == 1010101 && resultCode == RESULT_OK) {
- String userId = data.getStringExtra("result");
- if (myTaskList.getCheckedItemPosition() > -1) {
- Task task = (Task) myTasks.get(myTaskList.getCheckedItemPosition());
- task.setOwnerId(userId);
- final ProgressDialog pd = new ProgressDialog(context);
- pd.setTitle("moving task ...");
- pd.show();
- Backendless.Persistence.of(Task.class).save(task, new AsyncCallback<Task>() {
- @Override
- public void handleResponse(Task response) {
- myTasks.remove(myTaskList.getCheckedItemPosition());
- ((TasksAdapter) myTaskList.getAdapter()).notifyDataSetChanged();
- pd.dismiss();
- }
- @Override
- public void handleFault(BackendlessFault fault) {
- Toast.makeText(TasksActivity.this.context, "Error moving task", Toast.LENGTH_LONG).show();
- pd.dismiss();
- }
- });
- }
- }
- }
- }
- SelectUserActivity.java
- ------------------------
- package com.example.mohamadpc.backendless;
- import android.app.Activity;
- import android.app.ProgressDialog;
- import android.content.Context;
- import android.content.Intent;
- import android.os.Bundle;
- import android.view.View;
- import android.widget.AdapterView;
- import android.widget.ListView;
- import com.backendless.Backendless;
- import com.backendless.BackendlessUser;
- import com.backendless.async.callback.AsyncCallback;
- import com.backendless.exceptions.BackendlessFault;
- import java.util.List;
- public class SelectUserActivity extends Activity implements View.OnClickListener {
- private Context context;
- private ListView usersList;
- private List<BackendlessUser> users;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_select_user);
- setPointer();
- loadUsersList();
- }
- private void setPointer() {
- this.context = this;
- usersList = (ListView) findViewById(R.id.usersList);
- findViewById(R.id.btnCancelSelect).setOnClickListener(this);
- findViewById(R.id.btnSelectUser).setOnClickListener(this);
- usersList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
- @Override
- public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
- usersList.setItemChecked(position, true);
- }
- });
- usersList.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
- @Override
- public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
- usersList.setItemChecked(position, true);
- }
- @Override
- public void onNothingSelected(AdapterView<?> parent) {
- }
- });
- }
- private void loadUsersList() {
- final ProgressDialog pd = new ProgressDialog(context);
- pd.setMessage("Loading users list ...");
- pd.show();
- Backendless.Data.of(BackendlessUser.class).find(new AsyncCallback<List<BackendlessUser>>() {
- @Override
- public void handleResponse(List<BackendlessUser> response) {
- users = response;
- usersList.setAdapter(new UsersAdapter(users, context));
- pd.dismiss();
- }
- @Override
- public void handleFault(BackendlessFault fault) {
- pd.dismiss();
- }
- });
- }
- @Override
- public void onClick(View v) {
- Intent returnIntent = new Intent();
- int resultCode = Activity.RESULT_CANCELED;
- switch (v.getId()) {
- case R.id.btnCancelSelect:
- returnIntent.putExtra("result", "");
- break;
- case R.id.btnSelectUser:
- returnIntent.putExtra("result", users.get(usersList.getCheckedItemPosition()).getObjectId());
- resultCode = Activity.RESULT_OK;
- break;
- }
- setResult(resultCode, returnIntent);
- finish();
- }
- }
- TasksAdapter.java
- ------------------
- package com.example.mohamadpc.backendless;
- import android.app.ProgressDialog;
- import android.content.Context;
- import android.graphics.Color;
- import android.view.LayoutInflater;
- import android.view.View;
- import android.view.ViewGroup;
- import android.widget.BaseAdapter;
- import android.widget.CompoundButton;
- import android.widget.ListView;
- import android.widget.Switch;
- import android.widget.TextView;
- import com.backendless.Backendless;
- import com.backendless.async.callback.AsyncCallback;
- import com.backendless.exceptions.BackendlessFault;
- import java.util.List;
- /**
- * Created by teacher on 10/26/2017.
- */
- public class TasksAdapter extends BaseAdapter {
- private List<Task> myTasks;
- private Context context;
- public TasksAdapter(List<Task> myTasks, Context context) {
- this.myTasks = myTasks;
- this.context = context;
- }
- @Override
- public int getCount() {
- if (myTasks == null) return 0;
- return myTasks.size();
- }
- @Override
- public Task getItem(int i) {
- return myTasks.get(i);
- }
- @Override
- public long getItemId(int i) {
- return i;
- }
- @Override
- public View getView(final int i, View view, final ViewGroup viewGroup) {
- View myView = LayoutInflater.from(context).inflate(R.layout.task_item, null);
- Task task = myTasks.get(i);
- final Switch taskDone = (Switch) myView.findViewById(R.id.taskDone);
- final TextView tvTaskName = (TextView) myView.findViewById(R.id.taskName);
- tvTaskName.setText(myTasks.get(i).getName());
- taskDone.setChecked(myTasks.get(i).getDone());
- tvTaskName.setTextColor(getTaskColor(myTasks.get(i).getDone()));
- // mark selected row
- if (i == ((ListView) viewGroup).getCheckedItemPosition()) {
- myView.setBackgroundColor(Color.CYAN);
- }
- taskDone.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
- @Override
- public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
- myTasks.get(i).setDone(isChecked);
- final ProgressDialog pd = new ProgressDialog(context);
- pd.setMessage("Updating task status ...");
- pd.show();
- Backendless.Persistence.of(Task.class).save(myTasks.get(i), new AsyncCallback<Task>() {
- @Override
- public void handleResponse(Task response) {
- pd.dismiss();
- TasksAdapter.this.notifyDataSetChanged();
- }
- @Override
- public void handleFault(BackendlessFault fault) {
- pd.dismiss();
- TasksAdapter.this.notifyDataSetChanged();
- }
- });
- }
- });
- return myView;
- }
- private int getTaskColor(Boolean switchStatus) {
- return switchStatus ? Color.GREEN : Color.RED;
- }
- }
- UsersAdapter.java
- ------------------
- package com.example.mohamadpc.backendless;
- import android.content.Context;
- import android.graphics.Color;
- import android.view.View;
- import android.view.ViewGroup;
- import android.widget.BaseAdapter;
- import android.widget.ListView;
- import android.widget.TextView;
- import com.backendless.BackendlessUser;
- import java.util.List;
- /**
- * Created by teacher on 10/26/2017.
- */
- public class UsersAdapter extends BaseAdapter {
- Context context;
- List<BackendlessUser> myUsers;
- public UsersAdapter(List<BackendlessUser> myUsers, Context context) {
- this.context = context;
- this.myUsers = myUsers;
- }
- @Override
- public int getCount() {
- if (myUsers == null) return 0;
- return myUsers.size();
- }
- @Override
- public BackendlessUser getItem(int i) {
- return myUsers.get(i);
- }
- @Override
- public long getItemId(int i) {
- return i;
- }
- @Override
- public View getView(final int i, View view, final ViewGroup viewGroup) {
- TextView tv = new TextView(context);
- tv.setTextSize(22);
- tv.setText(myUsers.get(i).getProperty("name") + "");
- if (i == ((ListView) viewGroup).getCheckedItemPosition()) {
- tv.setBackgroundColor(Color.CYAN);
- }
- return tv;
- }
- }
- activity_register.xml
- ---------------------
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="vertical">
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:layout_weight="1"
- android:orientation="vertical">
- <ImageView
- android:id="@+id/imageView"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:layout_weight="1"
- android:src="@drawable/register" />
- </LinearLayout>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:layout_weight="0.80"
- android:orientation="vertical">
- <EditText
- android:id="@+id/etRegisterUserEmail"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_weight="1"
- android:hint="Enter user email"
- android:inputType="textEmailAddress" />
- <EditText
- android:id="@+id/etRegisterUserName"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_weight="1"
- android:hint="Enter user name" />
- <EditText
- android:id="@+id/etRegisterPassword"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_weight="1"
- android:hint="Enter user password"
- android:inputType="textPassword" />
- <EditText
- android:id="@+id/etRegisterReTypePassword"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_weight="1"
- android:hint="ReType user password"
- android:inputType="textPassword" />
- </LinearLayout>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:layout_weight="1"
- android:orientation="horizontal">
- <Button
- android:id="@+id/btnRegisterRgister"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_margin="20dp"
- android:layout_weight="1"
- android:text="Register"
- android:textSize="22sp" />
- <Button
- android:id="@+id/btnRegisterCancel"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_margin="20dp"
- android:layout_weight="1"
- android:text="Cancel"
- android:textSize="22sp" />
- </LinearLayout>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:layout_weight="1"
- android:orientation="vertical">
- <TextView
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_margin="20dp"
- android:text="Bla bla bla"
- android:textSize="22sp" />
- </LinearLayout>
- </LinearLayout>
- activity_login.xml
- ------------------
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:tools="http://schemas.android.com/tools"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="vertical">
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:layout_weight="1"
- android:orientation="vertical">
- <ImageView
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:layout_margin="16dp"
- android:src="@drawable/app_logo_1" />
- </LinearLayout>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:layout_weight="1"
- android:orientation="vertical">
- <EditText
- android:id="@+id/etLoginUserName"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_marginLeft="16dp"
- android:layout_marginRight="16dp"
- android:layout_marginTop="20dp"
- android:hint="@string/hint_user_name"
- android:inputType="textEmailAddress" />
- <EditText
- android:id="@+id/etLoginUserPassword"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_marginLeft="16dp"
- android:layout_marginRight="16dp"
- android:layout_marginTop="20dp"
- android:hint="@string/hint_user_password"
- android:inputType="textPassword" />
- </LinearLayout>
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:layout_weight="1"
- android:orientation="vertical">
- <Button
- android:id="@+id/btnLoginLogin"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_marginLeft="16dp"
- android:layout_marginRight="16dp"
- android:layout_weight="1"
- android:text="@string/cmd_login"
- android:textSize="22sp" />
- <TextView
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_marginLeft="16dp"
- android:layout_marginRight="16dp"
- android:gravity="center"
- android:text="or"
- android:textSize="17sp" />
- <Button
- android:id="@+id/btnLoginRegister"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_marginLeft="16dp"
- android:layout_marginRight="16dp"
- android:text="@string/hint_register"
- android:textSize="12sp" />
- </LinearLayout>
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:layout_weight="1"
- android:orientation="vertical">
- <TextView
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:layout_marginBottom="16dp"
- android:layout_marginLeft="16dp"
- android:layout_marginRight="16dp"
- android:gravity="center|bottom"
- android:text="@string/app_developer"
- android:textSize="22sp" />
- </LinearLayout>
- </LinearLayout>
- activity_tasks.xml
- -------------------
- <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:app="http://schemas.android.com/apk/res-auto"
- android:layout_width="match_parent"
- android:layout_height="match_parent">
- <ListView
- android:id="@+id/lstTasks"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:choiceMode="singleChoice" />
- <com.nightonke.boommenu.BoomMenuButton
- android:id="@+id/btnboomMenu"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_gravity="bottom|end"
- app:bmb_buttonEnum="textOutsideCircle"
- app:bmb_buttonPlaceEnum="buttonPlace_sc_4_1"
- app:bmb_piecePlaceEnum="piecePlace_dot_4_1"
- app:layout_anchor="@id/lstTasks"
- app:layout_anchorGravity="bottom|end" />
- </android.support.design.widget.CoordinatorLayout>
- activity_select_user.xml
- ------------------------
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="vertical">
- xmlns:android="http://schemas.android.com/apk/res/android" />
- <ListView
- android:id="@+id/usersList"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:layout_weight="0.1"
- android:choiceMode="singleChoice" />
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:layout_weight="1"
- android:orientation="horizontal">
- <Button
- android:id="@+id/btnSelectUser"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_weight="1"
- android:text="Select" />
- <Button
- android:id="@+id/btnCancelSelect"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_weight="1"
- android:text="Cancel" />
- </LinearLayout>
- </LinearLayout>
- task_item.xml
- -------------
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:app="http://schemas.android.com/apk/res-auto"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:orientation="horizontal">
- <Switch
- android:id="@+id/taskDone"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_marginBottom="10dp"
- android:layout_marginLeft="16dp"
- android:layout_marginTop="10dp"
- android:focusable="false"
- android:focusableInTouchMode="false" />
- <TextView
- android:id="@+id/taskName"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_gravity="center_vertical"
- android:layout_marginRight="16dp"
- android:text="Sample task data.."
- android:textColor="#ff0000"
- android:textSize="18sp" />
- </LinearLayout>
- dialog_new_task_layout.xml
- --------------------------
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:background="#000000"
- android:orientation="vertical">
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_gravity="center"
- android:layout_marginBottom="20dp"
- android:text="Add new task !!!"
- android:textColor="#ff0000"
- android:textSize="22sp" />
- <EditText
- android:id="@+id/etNewTaskName"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_margin="16dp"
- android:background="#ffffff"
- android:hint="Enter task name here"
- android:text=""
- android:textColor="#000000"
- android:textSize="22sp" />
- </LinearLayout>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement