From aca483e77784a6ddae595ef492c7a8ce35373e0f Mon Sep 17 00:00:00 2001 From: susaseri Date: Tue, 31 Jan 2017 17:26:36 +0900 Subject: [PATCH] Merge the differences from the files on the dev portal: LoginActivity.java - Remove com.kii.cloud.storage.exception.app.AppException - Add showToast() MainActivity.java - Add android.widget.AdapterView and android.widget.AdapterView.OnItemClickListener - Add showToast() - MainActivity implements OnItemClickListener - Change query.sortByAsc to query.sortByDesc - Change onListItemClick(ListView l, View v, final int position, long id) to onItemClick(AdapterView arg0, View arg1, final int arg2, long arg3) - Add mListView.setOnItemClickListener(this) --- src/com/kii/world/HelloKii.java | 1 - src/com/kii/world/LoginActivity.java | 17 +++++++++------- src/com/kii/world/MainActivity.java | 29 +++++++++++++++++----------- 3 files changed, 28 insertions(+), 19 deletions(-) diff --git a/src/com/kii/world/HelloKii.java b/src/com/kii/world/HelloKii.java index c2d1d93..a40870d 100644 --- a/src/com/kii/world/HelloKii.java +++ b/src/com/kii/world/HelloKii.java @@ -20,7 +20,6 @@ package com.kii.world; import android.app.Application; - import com.kii.cloud.storage.Kii; import com.kii.cloud.storage.Kii.Site; diff --git a/src/com/kii/world/LoginActivity.java b/src/com/kii/world/LoginActivity.java index 41ed58d..be97bd8 100644 --- a/src/com/kii/world/LoginActivity.java +++ b/src/com/kii/world/LoginActivity.java @@ -30,7 +30,6 @@ import com.kii.cloud.storage.KiiUser; import com.kii.cloud.storage.callback.KiiUserCallBack; -import com.kii.cloud.storage.exception.app.AppException; public class LoginActivity extends Activity { @@ -66,7 +65,7 @@ public void onLoginCompleted(int token, KiiUser user, Exception e) { // tell the console and the user it was a success! Log.v(TAG, "Logged in: " + user.toString()); - Toast.makeText(LoginActivity.this, "User authenticated!", Toast.LENGTH_SHORT).show(); + showToast("User authenticated!"); // go to the main screen Intent myIntent = new Intent(LoginActivity.this, MainActivity.class); @@ -78,8 +77,8 @@ public void onLoginCompleted(int token, KiiUser user, Exception e) { else { // tell the console and the user there was a failure - Log.v(TAG, "Error registering: " + e.getLocalizedMessage()); - Toast.makeText(LoginActivity.this, "Error registering: " + e.getLocalizedMessage(), Toast.LENGTH_SHORT).show(); + Log.v(TAG, "Error authenticating: " + e.getLocalizedMessage()); + showToast("Error authenticating: " + e.getLocalizedMessage()); } } @@ -115,7 +114,7 @@ public void onRegisterCompleted(int token, KiiUser user, Exception e) { // tell the console and the user it was a success! Log.v(TAG, "Registered: " + user.toString()); - Toast.makeText(LoginActivity.this, "User registered!", Toast.LENGTH_SHORT).show(); + showToast("User registered!"); // go to the next screen Intent myIntent = new Intent(LoginActivity.this, MainActivity.class); @@ -128,7 +127,7 @@ public void onRegisterCompleted(int token, KiiUser user, Exception e) { // tell the console and the user there was a failure Log.v(TAG, "Error registering: " + e.getLocalizedMessage()); - Toast.makeText(LoginActivity.this, "Error Registering: " + e.getLocalizedMessage(), Toast.LENGTH_SHORT).show(); + showToast("Error registering: " + e.getLocalizedMessage()); } } @@ -137,7 +136,7 @@ public void onRegisterCompleted(int token, KiiUser user, Exception e) { } catch(Exception e) { mProgress.cancel(); - Toast.makeText(this, "Error signing up: " + e.getLocalizedMessage(), Toast.LENGTH_SHORT).show(); + showToast("Error signing up: " + e.getLocalizedMessage()); } } @@ -155,4 +154,8 @@ public void onCreate(Bundle savedInstanceState) { } + private void showToast(String message) { + Toast.makeText(this, message, Toast.LENGTH_SHORT).show(); + } + } diff --git a/src/com/kii/world/MainActivity.java b/src/com/kii/world/MainActivity.java index 96f2db0..4b12e22 100644 --- a/src/com/kii/world/MainActivity.java +++ b/src/com/kii/world/MainActivity.java @@ -35,6 +35,8 @@ import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; +import android.widget.AdapterView; +import android.widget.AdapterView.OnItemClickListener; import android.widget.ArrayAdapter; import android.widget.LinearLayout; import android.widget.ListView; @@ -49,7 +51,7 @@ import com.kii.cloud.storage.query.KiiQuery; import com.kii.cloud.storage.query.KiiQueryResult; -public class MainActivity extends Activity { +public class MainActivity extends Activity implements OnItemClickListener { private static final String TAG = "MainActivity"; @@ -170,8 +172,8 @@ public void onSaveCompleted(int token, KiiObject o, Exception e) { if(e == null) { // tell the console and the user it was a success! - Toast.makeText(MainActivity.this, "Created object", Toast.LENGTH_SHORT).show(); Log.d(TAG, "Created object: " + o.toString()); + showToast("Created object"); // insert this object into the beginning of the list adapter MainActivity.this.mListAdapter.insert(o, 0); @@ -182,8 +184,8 @@ public void onSaveCompleted(int token, KiiObject o, Exception e) { else { // tell the console and the user there was a failure - Toast.makeText(MainActivity.this, "Error creating object", Toast.LENGTH_SHORT).show(); Log.d(TAG, "Error creating object: " + e.getLocalizedMessage()); + showToast("Error creating object" + e.getLocalizedMessage()); } } @@ -203,7 +205,7 @@ private void loadObjects() { // create an empty KiiQuery (will retrieve all results, sorted by creation date) KiiQuery query = new KiiQuery(null); - query.sortByAsc("_created"); + query.sortByDesc("_created"); // define the bucket to query KiiBucket bucket = KiiUser.getCurrentUser().bucket(BUCKET_NAME); @@ -228,7 +230,7 @@ public void onQueryCompleted(int token, KiiQueryResult result, Except // tell the console and the user it was a success! Log.v(TAG, "Objects loaded: " + result.getResult().toString()); - Toast.makeText(MainActivity.this, "Objects loaded", Toast.LENGTH_SHORT).show(); + showToast("Objects loaded"); } @@ -237,7 +239,7 @@ public void onQueryCompleted(int token, KiiQueryResult result, Except // tell the console and the user there was a failure Log.v(TAG, "Error loading objects: " + e.getLocalizedMessage()); - Toast.makeText(MainActivity.this, "Error loading objects: " + e.getLocalizedMessage(), Toast.LENGTH_SHORT).show(); + showToast("Error loading objects: " + e.getLocalizedMessage()); } } }, query); @@ -268,8 +270,8 @@ public void onDeleteCompleted(int token, Exception e) { if(e == null) { // tell the console and the user it was a success! - Toast.makeText(MainActivity.this, "Deleted object", Toast.LENGTH_SHORT).show(); Log.d(TAG, "Deleted object: " + o.toString()); + showToast("Deleted object"); // remove the object from the list adapter MainActivity.this.mListAdapter.remove(o); @@ -280,8 +282,8 @@ public void onDeleteCompleted(int token, Exception e) { else { // tell the console and the user there was a failure - Toast.makeText(MainActivity.this, "Error deleting object", Toast.LENGTH_SHORT).show(); Log.d(TAG, "Error deleting object: " + e.getLocalizedMessage()); + showToast("Error deleting object: " + e.getLocalizedMessage()); } } @@ -292,8 +294,8 @@ public void onDeleteCompleted(int token, Exception e) { // the user has clicked an item on the list. // we use this action to possibly delete the tapped object. // to confirm, we prompt the user with a dialog: - public void onListItemClick(ListView l, View v, final int position, long id) { - + @Override + public void onItemClick(AdapterView arg0, View arg1, final int arg2, long arg3) { // build the alert AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setMessage("Would you like to remove this item?") @@ -304,7 +306,7 @@ public void onListItemClick(ListView l, View v, final int position, long id) { public void onClick(DialogInterface dialog, int id) { // perform the delete action on the tapped object - MainActivity.this.performDelete(position); + MainActivity.this.performDelete(arg2); } }) .setNegativeButton("No", new DialogInterface.OnClickListener() { @@ -335,6 +337,7 @@ public void onCreate(Bundle savedInstanceState) { mListAdapter = new ObjectAdapter(this, R.layout.row, new ArrayList()); mListView = (ListView) this.findViewById(R.id.list); + mListView.setOnItemClickListener(this); // set it to our view's list mListView.setAdapter(mListAdapter); @@ -344,4 +347,8 @@ public void onCreate(Bundle savedInstanceState) { } + private void showToast(String message) { + Toast.makeText(this, message, Toast.LENGTH_SHORT).show(); + } + }