Skip to content

Commit

Permalink
Androidstudio cleanup+adding color to title view
Browse files Browse the repository at this point in the history
  • Loading branch information
wizmer committed Feb 25, 2016
1 parent f1be02a commit df55a52
Show file tree
Hide file tree
Showing 31 changed files with 153 additions and 371 deletions.
Binary file removed MobileOrg/libs/httpcore-4.0.1.jar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import android.text.TextUtils;
import android.text.style.ForegroundColorSpan;
import android.text.style.StyleSpan;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.widget.Button;
Expand All @@ -39,8 +40,7 @@ public class OutlineItem extends RecyclerView.ViewHolder {
private TextView tagsView;
private Button todoButton;
public TextView levelView;
private boolean levelFormatting = true;


public OutlineItem(View view) {
super(view);
mView = view;
Expand All @@ -60,192 +60,5 @@ public OutlineItem(View view) {
public String toString() {
return super.toString() + " '" + levelView.getText() + "'";
}

// private OnClickListener todoClick = new OnClickListener() {
// @Override
// public void onClick(View v) {
// createTodoDialog().show();
// }
// };

private Dialog createTodoDialog() {
// ArrayList<String> todos = PreferenceUtils.getSelectedTodos();
//
// if (todos.size() == 0)
// todos = OrgProviderUtils.getTodos(getContext()
// .getContentResolver());
//
// final ArrayList<String> todoList = todos;
// AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
// builder.setTitle(getResources().getString(R.string.todo_state))
// .setItems(todoList.toArray(new CharSequence[todoList.size()]),
// new DialogInterface.OnClickListener() {
// @Override
// public void onClick(DialogInterface dialog,
// int which) {
// String selectedTodo = todoList.get(which);
// setNewTodo(selectedTodo);
// }
// });
// return builder.create();
return null;
}

private void setNewTodo(String selectedTodo) {
// if (selectedTodo.equals(node.todo))
// return;
//
// ContentResolver resolver = getContext().getContentResolver();
//
// OrgNode newNode;
// try {
// newNode = new OrgNode(node.id, resolver);
// } catch (OrgNodeNotFoundException e) {
// e.printStackTrace();
// return;
// }
// newNode.todo = selectedTodo;
// node.generateApplyWriteEdits(newNode, null, resolver);
// node.write(resolver);
// OrgUtils.announceSyncDone(getContext());
}

private OrgNode node;

public void setLevelFormating(boolean enabled) {
this.levelFormatting = enabled;
}

public void setup(OrgNode node, boolean expanded, DefaultTheme theme, ContentResolver resolver) {
this.node = node;
setupTags(node.tags, node.tags_inherited, theme);

SpannableStringBuilder titleSpan = new SpannableStringBuilder(node.name);

if(node.name.startsWith(OrgFileParser.BLOCK_SEPARATOR_PREFIX)) {
setupAgendaBlock(titleSpan, theme);
return;
}

if (levelFormatting)
applyLevelFormating(theme, node.level, titleSpan);
setupTitle(node.name, theme, titleSpan);
setupPriority(node.priority, theme, titleSpan);
setupTodo(node.todo, theme, resolver);

if (levelFormatting)
applyLevelIndentation(node.level, titleSpan);

if(!expanded)
setupChildrenIndicator(node, resolver, theme, titleSpan);

titleSpan.setSpan(new StyleSpan(Typeface.NORMAL), 0, titleSpan.length(), 0);
titleView.setText(titleSpan);
}

public void setupChildrenIndicator(OrgNode node, ContentResolver resolver,
DefaultTheme theme, SpannableStringBuilder titleSpan) {
if (node.hasChildren(resolver)) {
titleSpan.append("...");
titleSpan.setSpan(new ForegroundColorSpan(theme.defaultForeground),
titleSpan.length() - "...".length(), titleSpan.length(), 0);
}
}

public void setupTodo(String todo, DefaultTheme theme, ContentResolver resolver) {
if(!TextUtils.isEmpty(todo)) {
Spannable todoSpan = new SpannableString(todo + " ");

boolean active = OrgProviderUtils.isTodoActive(todo, resolver);

todoSpan.setSpan(new ForegroundColorSpan(active ? theme.c1Red : theme.caLGreen), 0,
todo.length(), 0);
todoButton.setText(todoSpan);
todoButton.setVisibility(View.VISIBLE);
} else {
todoButton.setVisibility(View.GONE);
}
}

public static void setupPriority(String priority, DefaultTheme theme, SpannableStringBuilder titleSpan) {
if (priority != null && !TextUtils.isEmpty(priority)) {
Spannable prioritySpan = new SpannableString(priority + " ");
prioritySpan.setSpan(new ForegroundColorSpan(theme.c3Yellow), 0,
priority.length(), 0);
titleSpan.insert(0, prioritySpan);
}
}

public void applyLevelIndentation(long level, SpannableStringBuilder item) {
String indentString = "";
for(int i = 0; i < level; i++)
indentString += " ";

this.levelView.setText(indentString);
}

public static void applyLevelFormating(DefaultTheme theme, long level, SpannableStringBuilder item) {
item.setSpan(
new ForegroundColorSpan(theme.levelColors[(int) Math
.abs((level) % theme.levelColors.length)]), 0, item
.length(), 0);
}

public void setupTitle(String name, DefaultTheme theme, SpannableStringBuilder titleSpan) {
titleView.setGravity(Gravity.LEFT);
titleView.setTextSize(PreferenceUtils.getFontSize());

if (name.startsWith("COMMENT"))
titleSpan.setSpan(new ForegroundColorSpan(theme.gray), 0,
"COMMENT".length(), 0);
else if (name.equals("Archive"))
titleSpan.setSpan(new ForegroundColorSpan(theme.gray), 0,
"Archive".length(), 0);

formatLinks(theme, titleSpan);
}

public void setupAgendaBlock(SpannableStringBuilder titleSpan, DefaultTheme theme) {
titleSpan.delete(0, OrgFileParser.BLOCK_SEPARATOR_PREFIX.length());

titleSpan.setSpan(new ForegroundColorSpan(theme.defaultForeground), 0,
titleSpan.length(), 0);
titleSpan.setSpan(new StyleSpan(Typeface.BOLD), 0,
titleSpan.length(), 0);

titleView.setTextSize(PreferenceUtils.getFontSize() + 4);
//titleView.setBackgroundColor(theme.c4Blue);
titleView.setGravity(Gravity.CENTER_VERTICAL
| Gravity.CENTER_HORIZONTAL);

titleView.setText(titleSpan);
}

public static final Pattern urlPattern = Pattern.compile("\\[\\[[^\\]]*\\]\\[([^\\]]*)\\]\\]");
private static void formatLinks(DefaultTheme theme, SpannableStringBuilder titleSpan) {
Matcher matcher = urlPattern.matcher(titleSpan);
while(matcher.find()) {
titleSpan.delete(matcher.start(), matcher.end());
titleSpan.insert(matcher.start(), matcher.group(1));

titleSpan.setSpan(new ForegroundColorSpan(theme.c4Blue),
matcher.start(), matcher.start() + matcher.group(1).length(), 0);

matcher = urlPattern.matcher(titleSpan);
}
}

public void setupTags(String tags, String tagsInherited, DefaultTheme theme) {
if(!TextUtils.isEmpty(tags) || !TextUtils.isEmpty(tagsInherited)) {
if (!TextUtils.isEmpty(tagsInherited))
tagsView.setText(tags + "::" + tagsInherited);
else
tagsView.setText(tags);

tagsView.setTextColor(theme.gray);
tagsView.setVisibility(View.VISIBLE);
} else
tagsView.setVisibility(View.GONE);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ protected void onMeasure(int w, int h) {
int height = MeasureSpec.getSize(h);
// and its children
for (int i = 0; i < getChildCount(); i++) {
View page = (View) getChildAt(i);
View page = getChildAt(i);
// page.measure(screenWidth,hs);
ViewGroup.LayoutParams lp = page.getLayoutParams();
lp.width = screenWidth;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ public void onCreate(Bundle savedInstanceState) {
syncGroup.clearCheck();
syncGroup.setOnCheckedChangeListener(this);

syncWebDav = ((RadioButton) findViewById(R.id.sync_webdav)).getId();
syncDropBox = ((RadioButton) findViewById(R.id.sync_dropbox)).getId();
syncUbuntuOne = ((RadioButton) findViewById(R.id.sync_ubuntuone))
syncWebDav = findViewById(R.id.sync_webdav).getId();
syncDropBox = findViewById(R.id.sync_dropbox).getId();
syncUbuntuOne = findViewById(R.id.sync_ubuntuone)
.getId();
syncSdCard = ((RadioButton) findViewById(R.id.sync_sdcard)).getId();
syncNull = ((RadioButton) findViewById(R.id.sync_null)).getId();
syncSSH = ((RadioButton) findViewById(R.id.sync_ssh)).getId();
syncSdCard = findViewById(R.id.sync_sdcard).getId();
syncNull = findViewById(R.id.sync_null).getId();
syncSSH = findViewById(R.id.sync_ssh).getId();

ViewTreeObserver observer = wizardView.getViewTreeObserver();
if (observer.isAlive()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public void disableAllNextActions(int page) {
if (container != null)
for (int i = page; i < container.getChildCount(); i++) {
// get the pageview container
View pageContainer = (View) container.getChildAt(i);
View pageContainer = container.getChildAt(i);
// last page doesn't have a next button
View nextButton = pageContainer
.findViewById(R.id.wizard_next_button);
Expand All @@ -98,7 +98,7 @@ public void disableAllNextActions(int page) {
// disable/enable all buttons for given page
public void setNavButtonStateOnPage(int page, boolean state, int page_type) {
// get the pageview container
View pageContainer = (View) container.getChildAt(page);
View pageContainer = container.getChildAt(page);
Button prevButton = (Button) pageContainer
.findViewById(R.id.wizard_previous_button);
Button nextButton = (Button) pageContainer
Expand Down Expand Up @@ -256,7 +256,7 @@ public void onClick(View v) {

// hide keyboard if showing
private void hideKeyboard() {
InputMethodManager imm = (InputMethodManager) ((Activity) getContext())
InputMethodManager imm = (InputMethodManager) getContext()
.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(getWindowToken(), 0);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public void onClick(View v) {

private void loginUbuntuOne() {
final UbuntuOneSynchronizer uos = new UbuntuOneSynchronizer(
(Context) context);
context);
uos.username = ubuntuoneEmail.getText().toString();
uos.password = ubuntuonePass.getText().toString();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public void showToastRemote(String message) {

public enum TYPE {
WebDAV, Dropbox, Ubuntu, SDCard, SSH, Null
};
}

public static Wizard getWizard(TYPE type, WizardView wizardView,
Context context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ public enum TYPE {
ARCHIVE_SIBLING,
DELETE,
ADDHEADING
};
}

public TYPE type = null;
public String nodeId = "";
public String title = "";
Expand Down
16 changes: 4 additions & 12 deletions MobileOrg/src/main/java/com/matburt/mobileorg/OrgData/OrgFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,8 @@ public boolean doesFileExist(ContentResolver resolver) {
Files.DEFAULT_COLUMNS, null, null, null);
int count = cursor.getCount();
cursor.close();

if(count > 0)
return true;
else
return false;

return count > 0;
}

public OrgNode getOrgNode(ContentResolver resolver) {
Expand Down Expand Up @@ -165,16 +162,11 @@ public boolean isEncrypted() {
public boolean generateEditsForFile() {
if(filename.equals(CAPTURE_FILE))
return false;
if(filename.equals(AGENDA_FILE))
return false;
return true;
return !filename.equals(AGENDA_FILE);
}

public boolean equals(OrgFile file) {
if (filename.equals(file.filename) && name.equals(file.name))
return true;
else
return false;
return filename.equals(file.filename) && name.equals(file.name);
}

public String toString(ContentResolver resolver) {
Expand Down
14 changes: 4 additions & 10 deletions MobileOrg/src/main/java/com/matburt/mobileorg/OrgData/OrgNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -269,11 +269,8 @@ public boolean hasChildren(ContentResolver resolver) {

int childCount = childCursor.getCount();
childCursor.close();

if(childCount > 0)
return true;
else
return false;

return childCount > 0;
}

public static boolean hasChildren (long node_id, ContentResolver resolver) {
Expand Down Expand Up @@ -562,12 +559,9 @@ public String toString() {
}

public boolean equals(OrgNode node) {
if (name.equals(node.name) && tags.equals(node.tags)
return name.equals(node.name) && tags.equals(node.tags)
&& priority.equals(node.priority) && todo.equals(node.todo)
&& payload.equals(node.payload))
return true;
else
return false;
&& payload.equals(node.payload);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public enum TYPE {
Deadline,
Timestamp,
InactiveTimestamp
};
}

public OrgNodeTimeDate(TYPE type) {
this.type = type;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,11 +315,8 @@ public static boolean isTodoActive(String todo, ContentResolver resolver) {
cursor.moveToFirst();
int isdone = cursor.getInt(cursor.getColumnIndex(Todos.ISDONE));
cursor.close();

if(isdone == 0)
return true;
else
return false;

return isdone == 0;
}

return false;
Expand Down
Loading

0 comments on commit df55a52

Please sign in to comment.