Permalink
Browse files

Basic code cleanup

Cleans up trailing spaces, @Overrides, some small issues and inaccuracies.
  • Loading branch information...
1 parent f92adfe commit c1525603faccf7dc71eb4e03d41ca992ac3118b8 @pforhan pforhan committed Dec 11, 2012
View
@@ -15,39 +15,31 @@
<include layout="@layout/line" />
<LinearLayout
- android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
- android:layout_marginRight="10dp"
- android:layout_marginBottom="10dp"
- android:layout_marginTop="10dp"
- >
-
- <LinearLayout
+ android:layout_marginRight="10dp"
+ android:layout_marginBottom="10dp"
+ android:layout_marginTop="10dp"
android:orientation="horizontal"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
android:paddingTop="5dp"
>
- <EditText android:id="@+id/subdomain"
- android:layout_width="150dp"
- android:layout_height="wrap_content"
-
- android:inputType="textUri"
- />
-
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_marginLeft="5dp"
-
- android:textSize="17sp"
- android:text=".campfirenow.com"
- />
- </LinearLayout>
+ <EditText android:id="@+id/subdomain"
+ android:layout_width="0dp"
+ android:layout_height="wrap_content"
+ android:layout_weight="1"
+ android:inputType="textUri"
+ />
+ <TextView
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginLeft="5dp"
+ android:singleLine="true"
+ android:textSize="17sp"
+ android:text="@string/campfire_domain"
+ />
</LinearLayout>
<LinearLayout android:id="@+id/regular_input"
@@ -71,30 +63,16 @@
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
-
android:inputType="text"
-
- android:hint="Username"
- />
-
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_marginTop="5dp"
- android:layout_marginLeft="3dp"
-
- android:text="Password"
- android:visibility="gone"
+ android:hint="@string/username"
/>
<EditText android:id="@+id/password"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
-
- android:inputType="text"
- android:password="true"
- android:hint="Password"
+ android:inputType="textPassword"
+ android:hint="@string/password"
/>
<TextView
@@ -118,7 +96,7 @@
android:layout_marginTop="15dp"
android:textSize="20sp"
- android:text="Log in"
+ android:text="@string/log_in"
/>
</LinearLayout>
View
@@ -48,4 +48,8 @@
<string name="image_loading">Loading image…</string>
<string name="image_failed">Couldn\'t load image.</string>
+ <string name="campfire_domain">.campfirenow.com</string>
+ <string name="username">Username</string>
+ <string name="password">Password</string>
+ <string name="log_in">Log in</string>
</resources>
@@ -24,7 +24,7 @@
LoadImageTask loadImageTask;
BitmapDrawable image;
- public void onCreate(Bundle savedInstanceState) {
+ @Override public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.image);
@@ -17,168 +17,168 @@
public class Login extends Activity {
// high number because other activities will use this code in their case statements
public static final int RESULT_LOGIN = 1000;
-
+
public static final int MENU_ABOUT = 1;
public static final int MENU_FEEDBACK = 2;
-
+
private Campfire campfire;
private EditText subdomainView, usernameView, passwordView;
-
+
private LoginTask loginTask;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.login);
-
+
LoginHolder holder = (LoginHolder) getLastNonConfigurationInstance();
if (holder != null) {
campfire = holder.campfire;
loginTask = holder.loginTask;
}
-
+
setupControls();
-
+
if (loginTask != null)
loginTask.onScreenLoad(this);
}
-
+
@Override
public Object onRetainNonConfigurationInstance() {
LoginHolder holder = new LoginHolder();
holder.campfire = this.campfire;
holder.loginTask = this.loginTask;
return holder;
}
-
+
public void login() {
if (loginTask == null)
new LoginTask(this).execute();
}
-
+
public void onLogin(CampfireException exception) {
if (exception == null) {
Utils.saveCampfire(this, campfire);
setResult(RESULT_OK, new Intent());
finish();
- } else
+ } else
Utils.alert(this, exception);
- };
-
+ }
+
public void setupControls() {
Utils.setTitle(this, R.string.app_name);
Utils.setTitleSize(this, 24);
-
+
subdomainView = (EditText) findViewById(R.id.subdomain);
usernameView = (EditText) findViewById(R.id.username);
passwordView = (EditText) findViewById(R.id.password);
-
+
subdomainView.setText(Utils.getCampfireValue(this, "subdomain"));
-
+
findViewById(R.id.login_button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
login();
}
});
}
-
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
+
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
boolean result = super.onCreateOptionsMenu(menu);
-
+
menu.add(0, MENU_FEEDBACK, 1, R.string.menu_feedback).setIcon(R.drawable.ic_menu_send);
menu.add(1, MENU_ABOUT, 2, R.string.menu_about).setIcon(android.R.drawable.ic_menu_help);
-
+
return result;
}
-
+
@Override
public boolean onOptionsItemSelected(MenuItem item) {
- switch(item.getItemId()) {
+ switch(item.getItemId()) {
case MENU_ABOUT:
showDialog(Utils.ABOUT);
break;
case MENU_FEEDBACK:
startActivity(Utils.feedbackIntent(this));
break;
}
-
+
return super.onOptionsItemSelected(item);
}
-
+
@Override
- protected Dialog onCreateDialog(int id) {
+ protected Dialog onCreateDialog(int id) {
return id == Utils.ABOUT ? Utils.aboutDialog(this) : null;
}
-
+
private class LoginTask extends AsyncTask<Void,Void,CampfireException> {
public Login context;
private ProgressDialog dialog;
-
+
public LoginTask(Login context) {
super();
this.context = context;
this.context.loginTask = this;
}
-
+
@Override
protected void onPreExecute() {
loadingDialog();
}
-
+
public void onScreenLoad(Login context) {
this.context = context;
loadingDialog();
}
-
+
@Override
protected CampfireException doInBackground(Void... nothing) {
String subdomain = context.subdomainView.getText().toString().trim().replace(" ", "");
context.campfire = new Campfire(subdomain);
-
+
String username = context.usernameView.getText().toString().trim();
String password = context.passwordView.getText().toString().trim();
context.campfire.username = username;
context.campfire.password = password;
-
+
// save the subdomain and token right away
- Utils.saveCampfire(context, context.campfire);
-
+ Utils.saveCampfire(context, context.campfire);
+
try {
context.campfire.login();
} catch (CampfireException exception) {
return exception;
}
return null;
}
-
+
@Override
protected void onPostExecute(CampfireException exception) {
if (dialog != null && dialog.isShowing())
dialog.dismiss();
context.loginTask = null;
-
+
context.onLogin(exception);
}
-
+
public void loadingDialog() {
dialog = new ProgressDialog(context);
dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
dialog.setMessage("Logging in…");
-
+
dialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
cancel(true);
context.loginTask = null; // so that the button will work again
}
});
-
+
dialog.show();
}
}
-
+
static class LoginHolder {
Campfire campfire;
LoginTask loginTask;
Oops, something went wrong.

0 comments on commit c152560

Please sign in to comment.