Skip to content

Commit

Permalink
Interface cleanup
Browse files Browse the repository at this point in the history
-Improve ToxID dialog in advanced settings
-Improve FAB button
-Small code cleanup
  • Loading branch information
sssemil committed Sep 28, 2014
1 parent 69c5f50 commit a459e1b
Show file tree
Hide file tree
Showing 9 changed files with 117 additions and 105 deletions.
Expand Up @@ -78,11 +78,7 @@ 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();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
return item.getItemId() == R.id.action_settings || super.onOptionsItemSelected(item);
}

public void onClickRegisterIncogAccount(View view) {
Expand Down Expand Up @@ -140,7 +136,11 @@ public void onClickRegisterIncogAccount(View view) {
editor.putString("status_message", getResources().getString(R.string.pref_default_status_message));
editor.putString("tox_id", ID);
editor.putBoolean("loggedin", true);
editor.apply();
if (Build.VERSION.SDK_INT >= 9) {
editor.apply();
} else {
editor.commit();
}

/* Start Tox Service */
Intent startTox = new Intent(getApplicationContext(), ToxDoService.class);
Expand Down Expand Up @@ -260,50 +260,48 @@ public void onClickRegisterAccount(View view) {
int duration = Toast.LENGTH_SHORT;
Toast toast;

switch (jsonPost.getErrorCode()) {
case "0":
// Login and launch
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
SharedPreferences.Editor editor = preferences.edit();
editor.putString("active_account", account);
editor.putString("nickname", account);
editor.putString("status", "1");
editor.putString("status_message", getResources().getString(R.string.pref_default_status_message));
editor.putString("tox_id", ID);
editor.putBoolean("loggedin", true);
String s = jsonPost.getErrorCode();
if (s.equals("0")) {// Login and launch
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
SharedPreferences.Editor editor = preferences.edit();
editor.putString("active_account", account);
editor.putString("nickname", account);
editor.putString("status", "1");
editor.putString("status_message", getResources().getString(R.string.pref_default_status_message));
editor.putString("tox_id", ID);
editor.putBoolean("loggedin", true);
if (Build.VERSION.SDK_INT >= 9) {
editor.apply();
} else {
editor.commit();
}

/* Start Tox Service */
Intent startTox = new Intent(getApplicationContext(), ToxDoService.class);
getApplicationContext().startService(startTox);
Intent startTox = new Intent(getApplicationContext(), ToxDoService.class);
getApplicationContext().startService(startTox);

/* Launch main activity */
Intent main = new Intent(getApplicationContext(), MainActivity.class);
startActivity(main);

setResult(RESULT_OK);
finish();
break;

case "-25": // Name alrady taken
toastMessage = "This name is already taken";
toast = Toast.makeText(context, toastMessage, duration);
toast.show();
break;

case "-26":
// ID already bound to a name
toastMessage = "Internal Antox Error. Please restart and try again";
toast = Toast.makeText(context, toastMessage, duration);
toast.show();
break;

case "-4":
// Rate limited
toastMessage = "You can only register 13 accounts an hour. You have reached this limit";
toast = Toast.makeText(context, toastMessage, duration);
toast.show();
break;
Intent main = new Intent(getApplicationContext(), MainActivity.class);
startActivity(main);

setResult(RESULT_OK);
finish();

} else if (s.equals("-25")) {
toastMessage = "This name is already taken";
toast = Toast.makeText(context, toastMessage, duration);
toast.show();

} else if (s.equals("-26")) {// ID already bound to a name
toastMessage = "Internal Antox Error. Please restart and try again";
toast = Toast.makeText(context, toastMessage, duration);
toast.show();

} else if (s.equals("-4")) {// Rate limited
toastMessage = "You can only register 13 accounts an hour. You have reached this limit";
toast = Toast.makeText(context, toastMessage, duration);
toast.show();

}
}

Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/im/tox/antox/data/UserDB.java
Expand Up @@ -104,7 +104,7 @@ public boolean doUsersExist() {
}

public ArrayList<String> getAllProfiles() {
ArrayList<String> profiles = new ArrayList<>();
ArrayList<String> profiles = new ArrayList<String>();
SQLiteDatabase sqLiteDatabase = this.getReadableDatabase();
String query = "SELECT username FROM users";

Expand Down
41 changes: 28 additions & 13 deletions app/src/main/java/im/tox/antox/fragments/DialogToxID.java
Expand Up @@ -3,6 +3,7 @@
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
Expand All @@ -28,16 +29,16 @@
import im.tox.QR.Contents;
import im.tox.QR.QRCodeEncode;
import im.tox.antox.R;
import im.tox.antox.activities.MainActivity;

public class DialogToxID extends DialogFragment {

public interface DialogToxIDListener {
public void onDialogClick(DialogFragment fragment);
}

DialogToxIDListener mListener;
Context mContext;

public DialogToxID() {}
public DialogToxID(Context context) {
mContext = context;
}

@Override
public void onAttach(Activity activity) {
Expand All @@ -54,35 +55,45 @@ public void onAttach(Activity activity) {
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
LayoutInflater inflater = getActivity().getLayoutInflater();
final View view = (View) inflater.inflate(R.layout.dialog_tox_id, null);
final View view = inflater.inflate(R.layout.dialog_tox_id, null);
builder.setView(view);
builder.setNeutralButton(getString(R.string.button_ok), new Dialog.OnClickListener() {
builder.setPositiveButton(getString(R.string.button_ok), new Dialog.OnClickListener() {
public void onClick(DialogInterface dialogInterface, int ID) {
mListener.onDialogClick(DialogToxID.this);
}
});
builder.setNeutralButton(getString(R.string.dialog_tox_id), new Dialog.OnClickListener() {
public void onClick(DialogInterface dialogInterface, int ID) {
/* Copy ID to clipboard */
SharedPreferences sharedPreferences
= PreferenceManager.getDefaultSharedPreferences(mContext);
android.text.ClipboardManager clipboard = (android.text.ClipboardManager) mContext
.getSystemService(mContext.CLIPBOARD_SERVICE);
clipboard.setText(sharedPreferences.getString("tox_id", ""));
}
});

/* Generate or load QR image of Tox ID */
File file = new File(Environment.getExternalStorageDirectory().getPath()+"/Antox/");
if(!file.exists()){
File file = new File(Environment.getExternalStorageDirectory().getPath() + "/Antox/");
if (!file.exists()) {
file.mkdirs();
}

File noMedia = new File(Environment.getExternalStorageDirectory().getPath()+"/Antox/",".nomedia");
if(!noMedia.exists()){
File noMedia = new File(Environment.getExternalStorageDirectory().getPath() + "/Antox/", ".nomedia");
if (!noMedia.exists()) {
try {
noMedia.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}

file = new File(Environment.getExternalStorageDirectory().getPath()+"/Antox/userkey_qr.png");
file = new File(Environment.getExternalStorageDirectory().getPath() + "/Antox/userkey_qr.png");
SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(getActivity().getApplicationContext());
generateQR(pref.getString("tox_id", ""));
Bitmap bmp = BitmapFactory.decodeFile(file.getAbsolutePath());

ImageButton qrCode = (ImageButton)view.findViewById(R.id.qr_image);
ImageButton qrCode = (ImageButton) view.findViewById(R.id.qr_image);
qrCode.setImageBitmap(bmp);
qrCode.setOnClickListener(new View.OnClickListener() {
@Override
Expand Down Expand Up @@ -119,4 +130,8 @@ private void generateQR(String userKey) {
e.printStackTrace();
}
}

public interface DialogToxIDListener {
public void onDialogClick(DialogFragment fragment);
}
}
Expand Up @@ -79,7 +79,7 @@ public void onCreate(Bundle savedInstanceState) {
toxIDPreference.setOnPreferenceClickListener(new EditTextPreference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
DialogFragment dialog = new DialogToxID();
DialogFragment dialog = new DialogToxID(getActivity());
Bundle bundle = new Bundle();
bundle.putString("Enter Friend's Pin", "Enter Friend's Pin");
dialog.setArguments(bundle);
Expand Down
12 changes: 7 additions & 5 deletions app/src/main/java/im/tox/antox/tox/ToxSingleton.java
Expand Up @@ -89,12 +89,14 @@ public class ToxSingleton {
public Observable rightPaneActiveAndKeyAndIsFriendSubject;
public Observable friendInfoListAndActiveSubject;
public HashMap<Integer, Integer> progressMap = new HashMap<Integer, Integer>();
public HashMap<Integer, ArrayList<Tuple<Integer,Long>>> progressHistoryMap = new HashMap<>();
public HashMap<Integer, ArrayList<Tuple<Integer, Long>>> progressHistoryMap
= new HashMap<Integer, ArrayList<Tuple<Integer, Long>>>();
public HashMap<Integer, FileStatus> fileStatusMap = new HashMap<Integer, FileStatus>();
public HashMap<Integer, Integer> fileSizeMap = new HashMap<>();
public HashMap<Integer, FileOutputStream> fileStreamMap = new HashMap<>();
public HashMap<Integer, File> fileMap = new HashMap<>();
public HashSet<Integer> fileIds = new HashSet<>();
public HashMap<Integer, Integer> fileSizeMap = new HashMap<Integer, Integer>();
public HashMap<Integer, FileOutputStream> fileStreamMap
= new HashMap<Integer, FileOutputStream>();
public HashMap<Integer, File> fileMap = new HashMap<Integer, File>();
public HashSet<Integer> fileIds = new HashSet<Integer>();
public HashMap<String, Boolean> typingMap = new HashMap<String, Boolean>();
public boolean isInited = false;

Expand Down
4 changes: 4 additions & 0 deletions app/src/main/res/color/fab_colors_list.xml
@@ -0,0 +1,4 @@
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@color/fab_pressed" android:state_enabled="true" android:state_pressed="true" />
<item android:color="@color/fab_normal" android:state_enabled="true" android:state_pressed="false" />
</selector>
17 changes: 2 additions & 15 deletions app/src/main/res/layout/dialog_tox_id.xml
@@ -1,25 +1,12 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
android:orientation="vertical">

<ImageButton
android:id="@+id/qr_image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
/>

<Button
android:id="@+id/tox_id_button"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/dialog_tox_id"
android:onClick="copyToxID"
android:paddingBottom="10dp"
android:layout_gravity="center_horizontal"
android:textSize="@dimen/text_small"
/>
android:layout_gravity="center_horizontal" />

</LinearLayout>
53 changes: 28 additions & 25 deletions app/src/main/res/layout/fragment_contacts.xml
Expand Up @@ -7,67 +7,70 @@
android:layout_height="fill_parent"
android:background="@color/white_absolute"
android:orientation="vertical">

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="58dp"
android:background="@color/white_absolute">

<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_action_search"
android:id="@+id/imageView"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="15dp" />
android:layout_centerVertical="true"
android:layout_marginLeft="15dp"
android:src="@drawable/ic_action_search" />

<EditText
android:id="@+id/searchBar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:hint="@string/search_all_contacts"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/imageView"
android:layout_marginLeft="19dp"
android:textColor="@color/black"
android:layout_toRightOf="@+id/imageView"
android:background="@color/white_absolute"
android:hint="@string/search_all_contacts"
android:inputType="text"
android:singleLine="true"
android:textColor="@color/black"
android:typeface="normal"
android:windowSoftInputMode="stateHidden"
android:background="@color/white_absolute"
android:singleLine="true" />
android:windowSoftInputMode="stateHidden" />

</RelativeLayout>


<ImageView
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@drawable/list_divider"/>
android:background="@drawable/list_divider" />

<FrameLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<ListView
android:id="@+id/contacts_list"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:background="@color/white_absolute"
android:cacheColorHint="@android:color/transparent"
android:headerDividersEnabled="true"
android:footerDividersEnabled="false"
android:divider="@drawable/list_divider"
android:dividerHeight="0dp" />

<ListView
android:id="@+id/contacts_list"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:background="@color/white_absolute"
android:cacheColorHint="@android:color/transparent"
android:divider="@drawable/list_divider"
android:dividerHeight="0dp"
android:footerDividersEnabled="false"
android:headerDividersEnabled="true" />
</FrameLayout>

<com.shamanland.fab.FloatingActionButton
android:id="@+id/fab"
android:onClick="onClickAddFriend"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center|bottom"
app:floatingActionButtonColor="#6BC25F"
/>

android:layout_margin="@dimen/margin_medium"
android:onClick="onClickAddFriend"
app:floatingActionButtonColor="@color/fab_colors_list" />

</LinearLayout>

3 changes: 3 additions & 0 deletions app/src/main/res/values/colors.xml
Expand Up @@ -11,4 +11,7 @@
<color name="blue">#4c689d</color>
<color name="grey_light">#EAEAEA</color>
<color name="grey">#dcdcdc</color>

<color name="fab_normal">#6BC25F</color>
<color name="fab_pressed">#509147</color>
</resources>

0 comments on commit a459e1b

Please sign in to comment.